-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgtk_driver.c
More file actions
61 lines (49 loc) · 1.7 KB
/
gtk_driver.c
File metadata and controls
61 lines (49 loc) · 1.7 KB
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
#include <math.h>
#include "gtk_driver.h"
#include "lcd_UI.c"
cairo_t *cr;
cairo_text_extents_t extents;
void draw_with_gtk(cairo_t *cr2)
{
cr = cr2;
draw_to_screen();
}
void draw_rectangle(uint8_t stroke_wdth, uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color_r, uint8_t color_g, uint8_t color_b, float opacity)
{
cairo_set_line_width(cr, stroke_wdth);
cairo_set_source_rgb(cr, color_r, color_g, color_b);
cairo_rectangle(cr, x, y, width, height);
cairo_stroke_preserve(cr);
cairo_set_source_rgba(cr, color_r, color_g, color_b, opacity);
cairo_fill(cr);
}
void draw_circle(uint8_t stroke_wdth, uint8_t x, uint8_t y, uint8_t radius, uint8_t color_r, uint8_t color_g, uint8_t color_b, float opacity)
{
cairo_set_line_width(cr, stroke_wdth);
cairo_set_source_rgb(cr, color_r, color_g, color_b);
cairo_arc(cr, x, y, radius, 0, 2 * M_PI);
cairo_stroke_preserve(cr);
cairo_set_source_rgba(cr, color_r, color_g, color_b, opacity);
cairo_fill(cr);
}
void draw_string(char text[], uint8_t size, uint8_t align, uint8_t x, uint8_t y, uint8_t color_r, uint8_t color_g, uint8_t color_b, float opacity)
{
cairo_set_source_rgba(cr, color_r, color_g, color_b, opacity);
cairo_select_font_face(cr, "Courier", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size(cr, size);
switch (align)
{
case 0:
cairo_text_extents(cr, text, &extents);
cairo_move_to(cr, x - extents.width/2, y);
break;
case 1:
cairo_move_to(cr, x, y);
break;
case 2:
cairo_text_extents(cr, text, &extents);
cairo_move_to(cr, x - extents.width, y);
break;
}
cairo_show_text(cr, text);
}