1
+ #include <gui/gui.h>
2
+
3
+ #define WIDTH 128
4
+ #define HEIGHT 64
5
+
6
+ void draw_centered_boxed_str (Canvas * canvas , int x , int y , int height , int pad , const char * text ) {
7
+ // get width of text
8
+ int w = canvas_string_width (canvas , text );
9
+ canvas_draw_rframe (canvas , x , y , w + pad , height , 2 );
10
+ canvas_draw_str_aligned (canvas , x + pad / 2 , y + height / 2 , AlignLeft , AlignCenter , text );
11
+ }
12
+
13
+ void draw_corner_aligned (Canvas * canvas , int width , int height , Align horizontal , Align vertical ) {
14
+ canvas_set_color (canvas , ColorBlack );
15
+ switch (horizontal ) {
16
+ case AlignLeft :
17
+ switch (vertical ) {
18
+ case AlignTop :
19
+ canvas_draw_rbox (canvas , 0 , 0 , width , height , 3 );
20
+ canvas_draw_box (canvas , 0 , 0 , width , 3 );
21
+ canvas_draw_box (canvas , 0 , 0 , 3 , height );
22
+ break ;
23
+ case AlignCenter :
24
+ canvas_draw_rbox (canvas , 0 , HEIGHT - height / 2 , width , height , 3 );
25
+ canvas_draw_box (canvas , 0 , HEIGHT - height / 2 , 3 , height );
26
+ break ;
27
+ case AlignBottom :
28
+ canvas_draw_rbox (canvas , 0 , HEIGHT - height , width , height , 3 );
29
+ canvas_draw_box (canvas , 0 , HEIGHT - height , 3 , height );
30
+ canvas_draw_box (canvas , 0 , HEIGHT - 3 , width , 3 );
31
+ break ;
32
+ default :
33
+ break ;
34
+ }
35
+ break ;
36
+ case AlignRight :
37
+ switch (vertical ) {
38
+ case AlignTop :
39
+ canvas_draw_rbox (canvas , WIDTH - width , 0 , width , height , 3 );
40
+ canvas_draw_box (canvas , WIDTH - width , 0 , width , 3 ); // bottom corner
41
+ canvas_draw_box (canvas , WIDTH - 3 , 0 , 3 , height ); // right corner
42
+ break ;
43
+ case AlignCenter :
44
+ canvas_draw_rbox (canvas , WIDTH - width , HEIGHT / 2 - height / 2 , width , height , 3 );
45
+ canvas_draw_box (canvas , WIDTH - 3 , HEIGHT / 2 - height / 2 , 3 , height ); // right corner
46
+ break ;
47
+ case AlignBottom :
48
+ canvas_draw_rbox (canvas , WIDTH - width , HEIGHT - height , width , height , 3 );
49
+ canvas_draw_box (canvas , WIDTH - 3 , HEIGHT - height , 3 , height ); // right corner
50
+ canvas_draw_box (canvas , WIDTH - width , HEIGHT - 3 , width , 3 ); // bottom corner
51
+ break ;
52
+ default :
53
+ break ;
54
+ }
55
+ break ;
56
+ case AlignCenter :
57
+ switch (vertical ) {
58
+ case AlignTop :
59
+ canvas_draw_rbox (canvas , WIDTH / 2 - width / 2 , 0 , width , height , 3 );
60
+ canvas_draw_box (canvas , WIDTH / 2 - width / 2 , 0 , width , 3 ); // bottom corner
61
+ canvas_draw_box (canvas , WIDTH / 2 - 3 , 0 , 3 , height ); // right corner
62
+ break ;
63
+ case AlignCenter :
64
+ canvas_draw_rbox (
65
+ canvas , WIDTH / 2 - width / 2 , HEIGHT / 2 - height / 2 , width , height , 3 );
66
+ canvas_draw_box (
67
+ canvas , WIDTH / 2 - 3 , HEIGHT / 2 - height / 2 , 3 , height ); // right corner
68
+ break ;
69
+ case AlignBottom :
70
+ canvas_draw_rbox (canvas , WIDTH / 2 - width / 2 , HEIGHT - height , width , height , 3 );
71
+ canvas_draw_box (canvas , WIDTH / 2 - 3 , HEIGHT - height , 3 , height ); // right corner
72
+ canvas_draw_box (canvas , WIDTH / 2 - width / 2 , HEIGHT - 3 , width , 3 ); // bottom corner
73
+ break ;
74
+ default :
75
+ break ;
76
+ }
77
+ break ;
78
+ default :
79
+ break ;
80
+ }
81
+ }
0 commit comments