Ethan Yonker | a59da09 | 2015-10-13 19:35:05 -0500 | [diff] [blame] | 1 | #include <stdbool.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | #include <unistd.h> |
| 5 | |
| 6 | #include <fcntl.h> |
| 7 | #include <stdio.h> |
| 8 | |
| 9 | #include <sys/ioctl.h> |
| 10 | #include <sys/mman.h> |
| 11 | #include <sys/types.h> |
| 12 | |
| 13 | #include <linux/fb.h> |
| 14 | #include <linux/kd.h> |
| 15 | |
| 16 | #include <time.h> |
| 17 | |
| 18 | #include "minui.h" |
| 19 | #include "graphics.h" |
| 20 | |
| 21 | int main() { |
| 22 | // It might be a good idea to add some blending tests. |
| 23 | // The only blending done currently is around the font / text |
| 24 | int i = 0; |
| 25 | printf("Initializing graphics.\n"); |
| 26 | if (gr_init() != 0) { |
| 27 | printf("Error initializing graphics.\n"); |
| 28 | return -1; |
| 29 | } |
| 30 | printf("Starting tests\n"); |
| 31 | printf("Red\n"); |
| 32 | gr_color(255, 0, 0, 255); |
| 33 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 34 | gr_flip(); |
| 35 | sleep(1); |
| 36 | printf("Green\n"); |
| 37 | gr_color(0, 225, 0, 255); |
| 38 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 39 | gr_flip(); |
| 40 | sleep(1); |
| 41 | printf("Blue\n"); |
| 42 | gr_color(0, 0, 255, 255); |
| 43 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 44 | gr_flip(); |
| 45 | sleep(1); |
| 46 | printf("White\n"); |
| 47 | gr_color(255, 255, 255, 255); |
| 48 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 49 | gr_flip(); |
| 50 | sleep(1); |
| 51 | printf("4 colors, 1 in each corner\n"); |
| 52 | gr_color(255, 0, 0, 255); |
| 53 | gr_fill(0, 0, gr_fb_width() / 2, gr_fb_height() / 2); |
| 54 | gr_color(0, 255, 0, 255); |
| 55 | gr_fill(0, gr_fb_height() / 2, gr_fb_width() / 2, gr_fb_height()); |
| 56 | gr_color(0, 0, 255, 255); |
| 57 | gr_fill(gr_fb_width() / 2, 0, gr_fb_width(), gr_fb_height() / 2); |
| 58 | gr_color(255, 255, 255, 255); |
| 59 | gr_fill(gr_fb_width() / 2, gr_fb_height() / 2, gr_fb_width(), gr_fb_height()); |
| 60 | gr_flip(); |
| 61 | sleep(3); |
| 62 | printf("4 colors, vertical stripes\n"); |
| 63 | gr_color(255, 0, 0, 255); |
| 64 | gr_fill(0, 0, gr_fb_width() / 4, gr_fb_height()); |
| 65 | gr_color(0, 255, 0, 255); |
| 66 | gr_fill(gr_fb_width() / 4, 0, gr_fb_width() / 2, gr_fb_height()); |
| 67 | gr_color(0, 0, 255, 255); |
| 68 | gr_fill(gr_fb_width() / 2, 0, gr_fb_width() * 3 / 4, gr_fb_height()); |
| 69 | gr_color(255, 255, 255, 255); |
| 70 | gr_fill(gr_fb_width() * 3 / 4, 0, gr_fb_width(), gr_fb_height()); |
| 71 | gr_flip(); |
| 72 | sleep(3); |
| 73 | printf("Gradients, 1 in each corner\n"); |
| 74 | gr_color(0, 0, 0, 255); |
| 75 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 76 | for (i = 0; i < 255; i++) { |
| 77 | gr_color(i, 0, 0, 255); |
| 78 | gr_fill(i, 0, i+1, gr_fb_height() / 2); |
| 79 | gr_color(0, i, 0, 255); |
| 80 | gr_fill(i, gr_fb_height() / 2, i+1, gr_fb_height()); |
| 81 | gr_color(0, 0, i, 255); |
| 82 | gr_fill(i + (gr_fb_width() / 2), 0, i + (gr_fb_width() / 2) + 1, gr_fb_height() / 2); |
| 83 | gr_color(i, i, i, 255); |
| 84 | gr_fill(i + (gr_fb_width() / 2), gr_fb_height() / 2, i + (gr_fb_width() / 2) + 1, gr_fb_height()); |
| 85 | } |
| 86 | gr_flip(); |
| 87 | sleep(3); |
| 88 | printf("White with RGB text\n"); |
| 89 | gr_color(255, 255, 255, 255); |
| 90 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 91 | gr_color(255, 0, 0, 255); |
| 92 | gr_text(10, 10, "RED red RED", false); |
| 93 | gr_color(0, 255, 0, 255); |
| 94 | gr_text(10, 50, "GREEN green GREEN", false); |
| 95 | gr_color(0, 0, 255, 255); |
| 96 | gr_text(10, 90, "BLUE blue BLUE", false); |
| 97 | gr_flip(); |
| 98 | sleep(3); |
| 99 | printf("PNG test with /res/images/test.png\n"); |
| 100 | GRSurface* icon[2]; |
| 101 | gr_color(0, 0, 0, 255); |
| 102 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 103 | res_create_display_surface("test", icon); |
| 104 | GRSurface* surface = icon[0]; |
| 105 | gr_blit(surface, 0, 0, gr_get_width(surface), gr_get_height(surface), 10, 10); |
| 106 | gr_flip(); |
| 107 | res_free_surface(surface); |
| 108 | sleep(3); |
| 109 | printf("Exit graphics.\n"); |
| 110 | gr_exit(); |
| 111 | printf("Done.\n"); |
| 112 | return 0; |
| 113 | } |