Prusa MINI Firmware overview
guitypes.h
Go to the documentation of this file.
1 // guitypes.h
2 #ifndef _GUITYPES_H
3 #define _GUITYPES_H
4 
5 #include <inttypes.h>
6 #include <stdio.h>
7 #include <string.h>
8 
9 //alignment constants
10 #define ALIGN_LEFT 0x00
11 #define ALIGN_HCENTER 0x01
12 #define ALIGN_RIGHT 0x02
13 #define ALIGN_HMASK 0x03
14 #define ALIGN_TOP 0x00
15 #define ALIGN_VCENTER 0x10
16 #define ALIGN_BOTTOM 0x20
17 #define ALIGN_VMASK 0x30
18 #define ALIGN_MASK 0x33
19 #define ALIGN_CENTER (ALIGN_HCENTER | ALIGN_VCENTER)
20 #define ALIGN_LEFT_TOP (ALIGN_LEFT | ALIGN_TOP)
21 #define ALIGN_LEFT_CENTER (ALIGN_LEFT | ALIGN_VCENTER)
22 #define ALIGN_LEFT_BOTTOM (ALIGN_LEFT | ALIGN_BOTTOM)
23 #define ALIGN_RIGHT_TOP (ALIGN_RIGHT | ALIGN_TOP)
24 #define ALIGN_RIGHT_CENTER (ALIGN_RIGHT | ALIGN_VCENTER)
25 #define ALIGN_RIGHT_BOTTOM (ALIGN_RIGHT | ALIGN_BOTTOM)
26 #define ALIGN_CENTER_TOP (ALIGN_HCENTER | ALIGN_TOP)
27 #define ALIGN_CENTER_BOTTOM (ALIGN_HCENTER | ALIGN_BOTTOM)
28 
29 //raster operation function constants
30 #define ROPFN_COPY 0x00 //copy (no operation)
31 #define ROPFN_INVERT 0x01 //invert
32 #define ROPFN_SWAPBW 0x02 //swap black-white
33 #define ROPFN_DISABLE 0x04 //disables (darker colors)
34 
35 //font flags
36 #define FONT_FLG_SWAP 0x00000001 // swap low/high byte
37 #define FONT_FLG_LSBF 0x00000002 // LSB first
38 
39 //color constants
40 #define COLOR_BLACK 0x00000000L
41 #define COLOR_WHITE 0x00ffffffL
42 #define COLOR_RED 0x000000ffL
43 #define COLOR_RED_ALERT 0x002646e7L
44 #define COLOR_LIME 0x0000ff00L
45 #define COLOR_BLUE 0x00ff0000L
46 #define COLOR_YELLOW 0x0000ffffL
47 #define COLOR_CYAN 0x00ffff00L
48 #define COLOR_MAGENTA 0x00ff00ffL
49 #define COLOR_SILVER 0x00c0c0c0L
50 #define COLOR_GRAY 0x00808080L
51 #define COLOR_MAROON 0x00000080L
52 #define COLOR_OLIVE 0x00008080L
53 #define COLOR_GREEN 0x00008000L
54 #define COLOR_PURPLE 0x00800080L
55 #define COLOR_TEAL 0x00808000L
56 #define COLOR_NAVY 0x00800000L
57 #define COLOR_ORANGE 0x001B65F8L
58 
59 #pragma pack(push)
60 #pragma pack(1)
61 
62 typedef uint32_t color_t;
63 
64 typedef struct _point_ui16_t {
65  uint16_t x;
66  uint16_t y;
67 } point_ui16_t;
68 
69 typedef struct _rect_ui16_t {
70  uint16_t x;
71  uint16_t y;
72  uint16_t w;
73  uint16_t h;
74 } rect_ui16_t;
75 
76 typedef struct _font_t {
77  uint8_t w; //char width [pixels]
78  uint8_t h; //char height [pixels]
79  uint8_t bpr; //bytes per row
80  uint32_t flg; //flags
81  void *pcs; //charset data pointer
82  char asc_min; //min ascii code (first character)
83  char asc_max; //max ascii code (last character)
84 } font_t;
85 
86 typedef struct _padding_ui8_t {
92 
93 typedef struct _bitmap_t {
94  uint16_t w; //bitmap width [pixels]
95  uint16_t h; //bitmap height [pixels]
96  uint8_t bpp; //bits per pixel
97  uint8_t bpr; //bytes per row
98  void *ppx; //pixel data pointer
99 } bitmap_t;
100 
101 typedef struct _resource_entry_t {
102  const uint8_t *ptr; // 4 bytes - pointer
103  const uint16_t size; // 2 bytes - data size
105 
106 typedef struct _gui_defaults_t {
117 
118 #pragma pack(pop)
119 
120 static inline uint16_t swap_ui16(uint16_t val) {
121  return (val >> 8) | ((val & 0xff) << 8);
122 }
123 
124 static inline uint16_t swap_ui32(uint32_t val) {
125  return (val >> 16) | ((val & 0xffff) << 16);
126 }
127 
128 static inline color_t color_rgb(uint8_t r, uint8_t g, uint8_t b) {
129  return r | ((uint32_t)g << 8) | ((uint32_t)b << 16);
130 }
131 
132 static inline uint16_t color_to_565(color_t clr) {
133  return swap_ui16(((clr >> 19) & 0x001f) | ((clr >> 5) & 0x07e0) | ((clr << 8) & 0xf800));
134 }
135 
136 static inline color_t color_from_565(uint16_t clr565) {
137  //TODO
138  return 0;
139 }
140 
141 static inline color_t color_alpha(color_t clr0, color_t clr1, uint8_t alpha) {
142  uint8_t r0 = clr0 & 0xff;
143  uint8_t g0 = (clr0 >> 8) & 0xff;
144  uint8_t b0 = (clr0 >> 16) & 0xff;
145  uint8_t r1 = clr1 & 0xff;
146  uint8_t g1 = (clr1 >> 8) & 0xff;
147  uint8_t b1 = (clr1 >> 16) & 0xff;
148  uint8_t r = ((255 - alpha) * r0 + alpha * r1) / 255;
149  uint8_t g = ((255 - alpha) * g0 + alpha * g1) / 255;
150  uint8_t b = ((255 - alpha) * b0 + alpha * b1) / 255;
151  return color_rgb(r, g, b);
152 }
153 
154 static inline point_ui16_t point_ui16(uint16_t x, uint16_t y) {
155  point_ui16_t point = { x, y };
156  return point;
157 }
158 
159 static inline rect_ui16_t rect_ui16(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
160  rect_ui16_t rect = { x, y, w, h };
161  return rect;
162 }
163 
165  padding_ui8_t padding = { l, t, r, b };
166  return padding;
167 }
168 
169 static inline int point_in_rect_ui16(point_ui16_t pt, rect_ui16_t rc) {
170  return ((pt.x >= rc.x) && (pt.x < (rc.x + rc.w)) && (pt.y >= rc.y) && (pt.y < (rc.y + rc.h))) ? 1 : 0;
171 }
172 
173 static inline int rect_in_rect_ui16(rect_ui16_t rc, rect_ui16_t rc1) {
174  return ((rc.x >= rc1.x) && ((rc.x + rc.w) <= (rc1.x + rc1.w)) && (rc.y >= rc1.y) && ((rc.y + rc.h) <= (rc1.y + rc1.h))) ? 1 : 0;
175 }
176 
177 static inline int rect_empty_ui16(rect_ui16_t rc) {
178  return ((rc.w == 0) || (rc.h == 0)) ? 1 : 0;
179 }
180 
181 #ifdef __cplusplus
182 extern "C" {
183 #endif //__cplusplus
184 
186 
188 
190 
192 
193 extern point_ui16_t font_meas_text(font_t *pf, const char *str);
194 
195 extern int font_line_chars(font_t *pf, const char *str, uint16_t line_width);
196 
197 extern point_ui16_t icon_meas(const uint8_t *pi);
198 
199 extern const uint8_t *resource_ptr(uint16_t id);
200 
201 extern uint16_t resource_size(uint16_t id);
202 
203 extern FILE *resource_fopen(uint16_t id, const char *opentype);
204 
205 extern font_t *resource_font(uint16_t id);
206 
207 #ifdef __cplusplus
208 }
209 #endif //__cplusplus
210 
211 //resource type definition
212 #define RESOURCE_TYPE_RAW 0 //raw binary resource
213 #define RESOURCE_TYPE_TXT 1 //text resource
214 #define RESOURCE_TYPE_FNT 2 //font resource
215 #define RESOURCE_TYPE_BMP 3 //bitmap picture resource
216 #define RESOURCE_TYPE_PNG 4 //png picture resource
217 
218 //resource table macros
219 #define RESOURCE_TABLE_BEGIN const resource_entry_t resource_table[] = {
220 #define RESOURCE_TABLE_END \
221  } \
222  ; \
223  const uint16_t resource_table_size = sizeof(resource_table); \
224  const uint16_t resource_count = sizeof(resource_table) / sizeof(resource_entry_t);
225 
226 #define RESOURCE_ENTRY_NUL() { 0, 0 },
227 #define RESOURCE_ENTRY_PNG(v) { v, sizeof(v) },
228 #define RESOURCE_ENTRY_FNT(v) { (uint8_t *)&v, sizeof(font_t) },
229 
230 #endif //_GUITYPES_H
_gui_defaults_t
Definition: guitypes.h:106
_rect_ui16_t::y
uint16_t y
Definition: guitypes.h:71
_font_t::h
uint8_t h
Definition: guitypes.h:78
_rect_ui16_t::w
uint16_t w
Definition: guitypes.h:72
_bitmap_t::h
uint16_t h
Definition: guitypes.h:95
color_alpha
static color_t color_alpha(color_t clr0, color_t clr1, uint8_t alpha)
Definition: guitypes.h:141
_font_t
Definition: guitypes.h:76
_padding_ui8_t::bottom
uint8_t bottom
Definition: guitypes.h:90
_gui_defaults_t::color_text
color_t color_text
Definition: guitypes.h:108
_padding_ui8_t::top
uint8_t top
Definition: guitypes.h:88
_padding_ui8_t::right
uint8_t right
Definition: guitypes.h:89
_font_t::pcs
void * pcs
Definition: guitypes.h:81
resource_fopen
FILE * resource_fopen(uint16_t id, const char *opentype)
Definition: guitypes.c:180
rect_ui16
static rect_ui16_t rect_ui16(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
Definition: guitypes.h:159
_point_ui16_t::x
uint16_t x
Definition: guitypes.h:65
rect_ui16_add_padding_ui8
rect_ui16_t rect_ui16_add_padding_ui8(rect_ui16_t rc, padding_ui8_t pad)
Definition: guitypes.c:46
_gui_defaults_t::font
font_t * font
Definition: guitypes.h:110
_bitmap_t::bpp
uint8_t bpp
Definition: guitypes.h:96
padding_ui8
static padding_ui8_t padding_ui8(uint8_t l, uint8_t t, uint8_t r, uint8_t b)
Definition: guitypes.h:164
swap_ui32
static uint16_t swap_ui32(uint32_t val)
Definition: guitypes.h:124
_resource_entry_t::ptr
const uint8_t * ptr
Definition: guitypes.h:102
_gui_defaults_t::msg_box_sz
rect_ui16_t msg_box_sz
Definition: guitypes.h:114
_bitmap_t::bpr
uint8_t bpr
Definition: guitypes.h:97
bitmap_t
struct _bitmap_t bitmap_t
rect_in_rect_ui16
static int rect_in_rect_ui16(rect_ui16_t rc, rect_ui16_t rc1)
Definition: guitypes.h:173
_gui_defaults_t::color_disabled
color_t color_disabled
Definition: guitypes.h:109
font_t
struct _font_t font_t
_point_ui16_t
Definition: guitypes.h:64
font_line_chars
int font_line_chars(font_t *pf, const char *str, uint16_t line_width)
Definition: guitypes.c:122
rect_ui16_sub_padding_ui8
rect_ui16_t rect_ui16_sub_padding_ui8(rect_ui16_t rc, padding_ui8_t pad)
Definition: guitypes.c:55
_padding_ui8_t::left
uint8_t left
Definition: guitypes.h:87
color_from_565
static color_t color_from_565(uint16_t clr565)
Definition: guitypes.h:136
_gui_defaults_t::padding
padding_ui8_t padding
Definition: guitypes.h:112
rect_ui16_t
struct _rect_ui16_t rect_ui16_t
padding_ui8_t
struct _padding_ui8_t padding_ui8_t
swap_ui16
static uint16_t swap_ui16(uint16_t val)
Definition: guitypes.h:120
_bitmap_t::ppx
void * ppx
Definition: guitypes.h:98
resource_size
uint16_t resource_size(uint16_t id)
Definition: guitypes.c:174
resource_entry_t
struct _resource_entry_t resource_entry_t
_point_ui16_t::y
uint16_t y
Definition: guitypes.h:66
rect_empty_ui16
static int rect_empty_ui16(rect_ui16_t rc)
Definition: guitypes.h:177
rect_intersect_ui16
rect_ui16_t rect_intersect_ui16(rect_ui16_t rc, rect_ui16_t rc1)
Definition: guitypes.c:37
_font_t::asc_max
char asc_max
Definition: guitypes.h:83
_font_t::bpr
uint8_t bpr
Definition: guitypes.h:79
_bitmap_t
Definition: guitypes.h:93
_gui_defaults_t::color_back
color_t color_back
Definition: guitypes.h:107
_font_t::w
uint8_t w
Definition: guitypes.h:77
gui_defaults_t
struct _gui_defaults_t gui_defaults_t
icon_meas
point_ui16_t icon_meas(const uint8_t *pi)
Definition: guitypes.c:155
_gui_defaults_t::btn_spacing
uint8_t btn_spacing
Definition: guitypes.h:115
_padding_ui8_t
Definition: guitypes.h:86
_rect_ui16_t
Definition: guitypes.h:69
uint8_t
const uint8_t[]
Definition: 404_html.c:3
resource_ptr
const uint8_t * resource_ptr(uint16_t id)
Definition: guitypes.c:168
color_to_565
static uint16_t color_to_565(color_t clr)
Definition: guitypes.h:132
_rect_ui16_t::h
uint16_t h
Definition: guitypes.h:73
resource_font
font_t * resource_font(uint16_t id)
Definition: guitypes.c:186
_bitmap_t::w
uint16_t w
Definition: guitypes.h:94
_resource_entry_t::size
const uint16_t size
Definition: guitypes.h:103
_font_t::flg
uint32_t flg
Definition: guitypes.h:80
_resource_entry_t
Definition: guitypes.h:101
_rect_ui16_t::x
uint16_t x
Definition: guitypes.h:70
color_rgb
static color_t color_rgb(uint8_t r, uint8_t g, uint8_t b)
Definition: guitypes.h:128
color_t
uint32_t color_t
Definition: guitypes.h:62
_gui_defaults_t::font_big
font_t * font_big
Definition: guitypes.h:111
font_meas_text
point_ui16_t font_meas_text(font_t *pf, const char *str)
Definition: guitypes.c:97
_font_t::asc_min
char asc_min
Definition: guitypes.h:82
_gui_defaults_t::alignment
uint8_t alignment
Definition: guitypes.h:113
point_in_rect_ui16
static int point_in_rect_ui16(point_ui16_t pt, rect_ui16_t rc)
Definition: guitypes.h:169
createSpeedLookupTable.b
list b
Definition: createSpeedLookupTable.py:30
point_ui16_t
struct _point_ui16_t point_ui16_t
point_ui16
static point_ui16_t point_ui16(uint16_t x, uint16_t y)
Definition: guitypes.h:154
rect_align_ui16
rect_ui16_t rect_align_ui16(rect_ui16_t rc, rect_ui16_t rc1, uint8_t align)
Definition: guitypes.c:64