summaryrefslogtreecommitdiffstats
path: root/minui/main.cpp
blob: 13fee8746cf19e3c70a7876e9c0d4252b764dc61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <fcntl.h>
#include <stdio.h>

#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/types.h>

#include <linux/fb.h>
#include <linux/kd.h>

#include <time.h>

#include <minui/minui.h>
#include "graphics.h"

int main() {
	// It might be a good idea to add some blending tests.
	// The only blending done currently is around the font / text
	int i = 0;
    printf("Initializing graphics.\n");
	if (gr_init() != 0) {
	    printf("Error initializing graphics.\n");
	    return -1;
	}
	printf("Starting tests\n");
	printf("Red\n");
	gr_color(255, 0, 0, 255);
	gr_fill(0, 0, gr_fb_width(), gr_fb_height());
	gr_flip();
	sleep(1);
	printf("Green\n");
	gr_color(0, 225, 0, 255);
	gr_fill(0, 0, gr_fb_width(), gr_fb_height());
	gr_flip();
	sleep(1);
	printf("Blue\n");
	gr_color(0, 0, 255, 255);
	gr_fill(0, 0, gr_fb_width(), gr_fb_height());
	gr_flip();
	sleep(1);
	printf("White\n");
	gr_color(255, 255, 255, 255);
	gr_fill(0, 0, gr_fb_width(), gr_fb_height());
	gr_flip();
	sleep(1);
	printf("4 colors, 1 in each corner\n");
	gr_color(255, 0, 0, 255);
	gr_fill(0, 0, gr_fb_width() / 2, gr_fb_height() / 2);
	gr_color(0, 255, 0, 255);
	gr_fill(0, gr_fb_height() / 2, gr_fb_width() / 2, gr_fb_height());
	gr_color(0, 0, 255, 255);
	gr_fill(gr_fb_width() / 2, 0, gr_fb_width(), gr_fb_height() / 2);
	gr_color(255, 255, 255, 255);
	gr_fill(gr_fb_width() / 2, gr_fb_height() / 2, gr_fb_width(), gr_fb_height());
	gr_flip();
	sleep(3);
	printf("4 colors, vertical stripes\n");
	gr_color(255, 0, 0, 255);
	gr_fill(0, 0, gr_fb_width() / 4, gr_fb_height());
	gr_color(0, 255, 0, 255);
	gr_fill(gr_fb_width() / 4, 0, gr_fb_width() / 2, gr_fb_height());
	gr_color(0, 0, 255, 255);
	gr_fill(gr_fb_width() / 2, 0, gr_fb_width() * 3 / 4, gr_fb_height());
	gr_color(255, 255, 255, 255);
	gr_fill(gr_fb_width() * 3 / 4, 0, gr_fb_width(), gr_fb_height());
	gr_flip();
	sleep(3);
	printf("Gradients, 1 in each corner\n");
	gr_color(0, 0, 0, 255);
	gr_fill(0, 0, gr_fb_width(), gr_fb_height());
	for (i = 0; i < 255; i++) {
		gr_color(i, 0, 0, 255);
		gr_fill(i, 0, i+1, gr_fb_height() / 2);
		gr_color(0, i, 0, 255);
		gr_fill(i, gr_fb_height() / 2, i+1, gr_fb_height());
		gr_color(0, 0, i, 255);
		gr_fill(i + (gr_fb_width() / 2), 0, i + (gr_fb_width() / 2) + 1, gr_fb_height() / 2);
		gr_color(i, i, i, 255);
		gr_fill(i + (gr_fb_width() / 2), gr_fb_height() / 2, i + (gr_fb_width() / 2) + 1, gr_fb_height());
	}
	gr_flip();
	sleep(3);
	printf("White with RGB text\n");
	gr_color(255, 255, 255, 255);
	gr_fill(0, 0, gr_fb_width(), gr_fb_height());
	gr_color(255, 0, 0, 255);
	gr_text(10, 10, "RED red RED", false);
	gr_color(0, 255, 0, 255);
	gr_text(10, 50, "GREEN green GREEN", false);
	gr_color(0, 0, 255, 255);
	gr_text(10, 90, "BLUE blue BLUE", false);
	gr_flip();
	sleep(3);
	printf("PNG test with /res/images/test.png\n");
	GRSurface* icon[2];
	gr_color(0, 0, 0, 255);
	gr_fill(0, 0, gr_fb_width(), gr_fb_height());
	res_create_display_surface("test", icon);
	GRSurface* surface = icon[0];
	gr_blit(surface, 0, 0, gr_get_width(surface), gr_get_height(surface), 10, 10);
	gr_flip();
	res_free_surface(surface);
	sleep(3);
	printf("Exit graphics.\n");
	gr_exit();
	printf("Done.\n");
	return 0;
}