Prusa MINI Firmware overview
window.h
Go to the documentation of this file.
1 //window.h
2 #ifndef _WINDOW_H
3 #define _WINDOW_H
4 
5 #include <inttypes.h>
6 #include "guitypes.h"
7 
8 //window class identifiers
9 #define WINDOW_CLS_FRAME 0 // FRAME - basic container class
10 #define WINDOW_CLS_TEXT 1 // TEXT - aligned singlecolor text
11 #define WINDOW_CLS_NUMB 2 // NUMB - aligned singlecolor formated number
12 #define WINDOW_CLS_ICON 3 // ICON - small image with left-top offset
13 #define WINDOW_CLS_LIST 4 // LIST - vertical or horizontal list (text-icon pairs)
14 #define WINDOW_CLS_EDIT 5 // EDIT - text editor (editable 'TEXT') - minor
15 #define WINDOW_CLS_SPIN 6 // SPIN - numeric editor (editable 'NUMB')
16 #define WINDOW_CLS_TXIC 7 // TXIC - text + icon
17 #define WINDOW_CLS_TERM 8 // TERM - terminal
18 #define WINDOW_CLS_MENU 9 // MENU - menu
19 #define WINDOW_CLS_MSGBOX 10 // MSGBOX - messagebox with configurable buttons and icon
20 #define WINDOW_CLS_PROGRESS 11 // PROGRESS - progress bar with text
21 #define WINDOW_CLS_USER 128 // USER - user defined window classes (WINDOW_CLS_USER+n)
22 
23 //window flags
24 #define WINDOW_FLG_VISIBLE 0x00000001 // is visible
25 #define WINDOW_FLG_ENABLED 0x00000002 // is enabled (can be focused)
26 #define WINDOW_FLG_INVALID 0x00000004 // content is invalid
27 #define WINDOW_FLG_FOCUSED 0x00000008 // has focus
28 #define WINDOW_FLG_CHECKED 0x00000010 // is checked/selected
29 #define WINDOW_FLG_CAPTURE 0x00000020 // capture jog events
30 #define WINDOW_FLG_DISABLED 0x00000040 // window is disabled (shadowed)
31 #define WINDOW_FLG_FREEMEM 0x00004000 // free memory when destroy
32 #define WINDOW_FLG_PARENT 0x00008000 // is parent window
33 #define WINDOW_FLG_USER 0x00010000 // user flags (WINDOW_FLG_USER<<n)
34 //top 1 byte cannot be used
35 //flag is stored there
36 
37 //window events
38 #define WINDOW_EVENT_BTN_DN 0x01 //button down
39 #define WINDOW_EVENT_BTN_UP 0x02 //button up
40 #define WINDOW_EVENT_ENC_DN 0x03 //encoder minus
41 #define WINDOW_EVENT_ENC_UP 0x04 //encoder plus
42 #define WINDOW_EVENT_FOCUS0 0x05 //focus lost
43 #define WINDOW_EVENT_FOCUS1 0x06 //focus set
44 #define WINDOW_EVENT_CAPT_0 0x07 //capture lost
45 #define WINDOW_EVENT_CAPT_1 0x08 //capture set
46 #define WINDOW_EVENT_CLICK 0x09 //clicked (tag > 0)
47 #define WINDOW_EVENT_CHANGE 0x0a //value/index changed (tag > 0)
48 #define WINDOW_EVENT_CHANGING 0x0b //value/index changing (tag > 0)
49 #define WINDOW_EVENT_LOOP 0x0c //gui loop (every 50ms)
50 #define WINDOW_EVENT_TIMER 0x0d //gui timer
51 #define WINDOW_EVENT_MESSAGE 0x0e //onStatusChange() message notification
52 
53 typedef struct _window_t window_t;
54 
55 typedef void(window_init_t)(void *window);
56 typedef void(window_done_t)(void *window);
57 typedef void(window_draw_t)(void *window);
58 typedef void(window_event_t)(void *window, uint8_t event, void *param);
59 
61 typedef void(window_list_item_t)(window_list_t *pwindow_list,
62  uint16_t index, const char **pptext, uint16_t *pid_icon);
63 
64 #pragma pack(push)
65 #pragma pack(1)
66 
67 typedef struct _window_class_t {
68  int16_t cls_id; // (2 bytes) window class id
69  uint16_t size; // (2 bytes) window structure size
70  window_init_t *init; // (4 bytes) done callback
71  window_done_t *done; // (4 bytes) done callback
72  window_draw_t *draw; // (4 bytes) draw callback
73  window_event_t *event; // (4 bytes) event callback
74 } window_class_t; // (20 bytes total)
75 
76 typedef struct _window_t {
77  window_class_t *cls; // (4 bytes) window class pointer
78  int16_t id_parent; // (2 bytes) parent window identifier (2bytes)
79  int16_t id; // (2 bytes) window identifier (2bytes)
80  union {
81  uint32_t flg; // (3 bytes) flags (visibility, invalid...),
82  // (1 byte) top byte is window tag (user defined id)
83  struct
84  {
85  uint32_t f_visible : 1; // WINDOW_FLG_VISIBLE 0x00000001
86  uint32_t f_enabled : 1; // WINDOW_FLG_ENABLED 0x00000002
87  uint32_t f_invalid : 1; // WINDOW_FLG_INVALID 0x00000004
88  uint32_t f_focused : 1; // WINDOW_FLG_FOCUSED 0x00000008
89  uint32_t f_checked : 1; // WINDOW_FLG_CHECKED 0x00000010
90  uint32_t f_capture : 1; // WINDOW_FLG_CAPTURE 0x00000020
91  uint32_t f_disabled : 1; // WINDOW_FLG_DISABLED 0x00000040
92  uint32_t f_reserv0 : 6; // reserved 7 bits
93  uint32_t f_freemem : 1; // WINDOW_FLG_FREEMEM 0x00002000
94  uint32_t f_timer : 1; // WINDOW_FLG_TIMER 0x00004000
95  uint32_t f_parent : 1; // WINDOW_FLG_PARENT 0x00008000
96  uint32_t f_user : 1; // WINDOW_FLG_USER 0x00010000
97  uint32_t f_reserv1 : 7; // reserved 7 bits
98  uint32_t f_tag : 8; // (1 byte) window tag (user defined id)
99  };
100  };
101  rect_ui16_t rect; // (8 bytes) display rectangle
102  window_event_t *event; // (4 bytes) event callback
103 } window_t; // (24 bytes total)
104 
105 #pragma pack(pop)
106 
107 #ifdef __cplusplus
108 extern "C" {
109 #endif //__cplusplus
110 
111 extern window_t *window_focused_ptr; //current focused window
112 
113 extern window_t *window_capture_ptr; //current capture window
114 
115 extern window_t *window_ptr(int16_t id);
116 
117 extern int16_t window_id(window_t *ptr);
118 
119 extern int16_t window_register_class(window_class_t *cls);
120 
121 extern int16_t window_create(int16_t cls_id, int16_t id_parent, rect_ui16_t rect);
122 
123 extern int16_t window_create_ptr(int16_t cls_id, int16_t id_parent, rect_ui16_t rect, void *ptr);
124 
125 extern void window_destroy(int16_t id);
126 
127 extern void window_destroy_children(int16_t id);
128 
129 extern int16_t window_focused(void);
130 
131 extern int16_t window_capture(void);
132 
133 extern int16_t window_parent(int16_t id);
134 
135 extern int16_t window_prev(int16_t id);
136 
137 extern int16_t window_next(int16_t id);
138 
139 extern int16_t window_prev_enabled(int16_t id);
140 
141 extern int16_t window_next_enabled(int16_t id);
142 
143 extern int16_t window_first_child(int16_t id);
144 
145 extern int window_child_count(int16_t id);
146 
147 extern int window_enabled_child_count(int16_t id);
148 
149 extern int window_is_visible(int16_t id);
150 
151 extern int window_is_enabled(int16_t id);
152 
153 extern int window_is_invalid(int16_t id);
154 
155 extern int window_is_focused(int16_t id);
156 
157 extern int window_is_capture(int16_t id);
158 
159 extern void window_draw(int16_t id);
160 
161 extern void window_draw_children(int16_t id);
162 
163 extern void window_validate(int16_t id);
164 
165 extern void window_invalidate(int16_t id);
166 
167 extern void window_validate_children(int16_t id);
168 
169 extern void window_invalidate_children(int16_t id);
170 
171 extern void window_set_tag(int16_t id, uint8_t tag);
172 
173 extern void _window_set_tag(window_t *wnd, uint8_t tg);
174 
175 extern uint8_t window_get_tag(int16_t id);
176 
177 extern int _window_get_tag(window_t *wnd);
178 
179 extern void window_set_text(int16_t id, const char *text);
180 
181 extern char *window_get_text(int16_t id);
182 
183 extern void window_set_value(int16_t id, float value);
184 
185 extern float window_get_value(int16_t id);
186 
187 extern void window_set_format(int16_t id, const char *format);
188 
189 extern char *window_get_format(int16_t id);
190 
191 extern void window_set_color_back(int16_t id, color_t clr);
192 
193 extern color_t window_get_color_back(int16_t id);
194 
195 extern void window_set_color_text(int16_t id, color_t clr);
196 
197 extern color_t window_get_color_text(int16_t id);
198 
199 extern void window_set_focus(int16_t id);
200 
201 extern void window_set_capture(int16_t id);
202 
203 extern void window_enable(int16_t id);
204 
205 extern void window_disable(int16_t id);
206 
207 extern void window_show(int16_t id);
208 
209 extern void window_hide(int16_t id);
210 
211 extern void window_set_padding(int16_t id, padding_ui8_t padding);
212 
213 extern void window_set_alignment(int16_t id, uint8_t alignment);
214 
215 extern void window_set_item_count(int16_t id, int count);
216 
217 extern int window_get_item_count(int16_t id);
218 
219 extern void window_set_item_index(int16_t id, int index);
220 
221 extern int window_get_item_index(int16_t id);
222 
223 extern void window_set_top_index(int16_t id, int index);
224 
225 extern int window_get_top_index(int16_t id);
226 
227 extern void window_set_icon_id(int16_t id, uint16_t id_res);
228 
229 extern uint16_t window_get_icon_id(int16_t id);
230 
231 extern void window_set_min(int16_t id, float min);
232 
233 extern float window_get_min(int16_t id);
234 
235 extern void window_set_max(int16_t id, float max);
236 
237 extern float window_get_max(int16_t id);
238 
239 extern void window_set_step(int16_t id, float step);
240 
241 extern float window_get_step(int16_t id);
242 
243 extern void window_set_min_max(int16_t id, float min, float max);
244 
245 extern void window_set_min_max_step(int16_t id, float min, float max, float step);
246 
247 extern void window_dispatch_event(window_t *window, uint8_t event, void *param);
248 
249 extern void window_set_item_callback(int16_t id, window_list_item_t *fnc);
250 
251 extern void gui_invalidate(void);
252 
253 #ifdef __cplusplus
254 }
255 #endif //__cplusplus
256 
257 static inline void _window_invalidate(window_t *window) {
258  if (window) {
259  window->flg |= WINDOW_FLG_INVALID;
260  gui_invalidate();
261  }
262 }
263 
264 #endif //_WINDOW_H
window_set_alignment
void window_set_alignment(int16_t id, uint8_t alignment)
Definition: window.c:561
window_prev
int16_t window_prev(int16_t id)
Definition: window.c:180
window_draw_t
void() window_draw_t(void *window)
Definition: window.h:57
window_get_item_index
int window_get_item_index(int16_t id)
Definition: window.c:623
_window_t::f_reserv1
uint32_t f_reserv1
Definition: window.h:97
window_register_class
int16_t window_register_class(window_class_t *cls)
Definition: window.c:90
window_set_max
void window_set_max(int16_t id, float max)
Definition: window.c:704
window_capture
int16_t window_capture(void)
Definition: window.c:169
_window_class_t::size
uint16_t size
Definition: window.h:69
window_get_max
float window_get_max(int16_t id)
Definition: window.c:716
window_class_t
struct _window_class_t window_class_t
_window_t::id_parent
int16_t id_parent
Definition: window.h:78
_window_class_t::cls_id
int16_t cls_id
Definition: window.h:68
window_set_padding
void window_set_padding(int16_t id, padding_ui8_t padding)
Definition: window.c:549
window_is_capture
int window_is_capture(int16_t id)
Definition: window.c:272
_window_t::f_enabled
uint32_t f_enabled
Definition: window.h:86
window_get_min
float window_get_min(int16_t id)
Definition: window.c:694
window_get_step
float window_get_step(int16_t id)
Definition: window.c:738
window_next
int16_t window_next(int16_t id)
Definition: window.c:192
window_get_value
float window_get_value(int16_t id)
Definition: window.c:390
window_get_format
char * window_get_format(int16_t id)
Definition: window.c:418
window_get_top_index
int window_get_top_index(int16_t id)
Definition: window.c:648
window_set_color_back
void window_set_color_back(int16_t id, color_t clr)
Definition: window.c:431
_window_t::f_timer
uint32_t f_timer
Definition: window.h:94
window_set_top_index
void window_set_top_index(int16_t id, int index)
Definition: window.c:636
window_destroy_children
void window_destroy_children(int16_t id)
Definition: window.c:157
window_set_format
void window_set_format(int16_t id, const char *format)
Definition: window.c:403
window_invalidate
void window_invalidate(int16_t id)
Definition: window.c:304
window_destroy
void window_destroy(int16_t id)
Definition: window.c:132
window_get_tag
uint8_t window_get_tag(int16_t id)
Definition: window.c:335
max
#define max(a, b)
Definition: wiring_constants.h:40
_window_class_t::draw
window_draw_t * draw
Definition: window.h:72
window_create
int16_t window_create(int16_t cls_id, int16_t id_parent, rect_ui16_t rect)
Definition: window.c:98
window_set_icon_id
void window_set_icon_id(int16_t id, uint16_t id_res)
Definition: window.c:659
window_id
int16_t window_id(window_t *ptr)
Definition: window.c:86
_window_t::f_disabled
uint32_t f_disabled
Definition: window.h:91
window_show
void window_show(int16_t id)
Definition: window.c:529
_window_class_t::done
window_done_t * done
Definition: window.h:71
_window_t::id
int16_t id
Definition: window.h:79
_window_t::f_reserv0
uint32_t f_reserv0
Definition: window.h:92
window_is_invalid
int window_is_invalid(int16_t id)
Definition: window.c:262
window_first_child
int16_t window_first_child(int16_t id)
Definition: window.c:218
_window_t::f_invalid
uint32_t f_invalid
Definition: window.h:87
window_ptr
window_t * window_ptr(int16_t id)
Definition: window.c:82
guitypes.h
window_done_t
void() window_done_t(void *window)
Definition: window.h:56
_window_t::f_parent
uint32_t f_parent
Definition: window.h:95
window_disable
void window_disable(int16_t id)
Definition: window.c:523
window_set_text
void window_set_text(int16_t id, const char *text)
Definition: window.c:340
min
#define min(a, b)
Definition: wiring_constants.h:36
_window_t::f_checked
uint32_t f_checked
Definition: window.h:89
window_enabled_child_count
int window_enabled_child_count(int16_t id)
Definition: window.c:240
_window_t
Definition: window.h:76
_window_class_t::event
window_event_t * event
Definition: window.h:73
void
void
Definition: png.h:1083
window_set_value
void window_set_value(int16_t id, float value)
Definition: window.c:363
_window_t::f_user
uint32_t f_user
Definition: window.h:96
window_is_visible
int window_is_visible(int16_t id)
Definition: window.c:252
window_draw_children
void window_draw_children(int16_t id)
Definition: window.c:284
window_set_focus
void window_set_focus(int16_t id)
Definition: window.c:480
window_t
struct _window_t window_t
Definition: window.h:53
window_dispatch_event
void window_dispatch_event(window_t *window, uint8_t event, void *param)
Definition: window.c:797
_window_class_t::init
window_init_t * init
Definition: window.h:70
_padding_ui8_t
Definition: guitypes.h:86
window_is_focused
int window_is_focused(int16_t id)
Definition: window.c:267
window_set_tag
void window_set_tag(int16_t id, uint8_t tag)
Definition: window.c:329
gui_invalidate
void gui_invalidate(void)
Definition: gui.c:66
window_set_min_max
void window_set_min_max(int16_t id, float min, float max)
Definition: window.c:748
window_focused_ptr
window_t * window_focused_ptr
Definition: window.c:19
window_get_icon_id
uint16_t window_get_icon_id(int16_t id)
Definition: window.c:671
window_event_t
void() window_event_t(void *window, uint8_t event, void *param)
Definition: window.h:58
_rect_ui16_t
Definition: guitypes.h:69
window_child_count
int window_child_count(int16_t id)
Definition: window.c:230
uint8_t
const uint8_t[]
Definition: 404_html.c:3
_window_class_t
Definition: window.h:67
window_hide
void window_hide(int16_t id)
Definition: window.c:539
_window_t::rect
rect_ui16_t rect
Definition: window.h:101
_window_get_tag
int _window_get_tag(window_t *wnd)
_window_t::f_capture
uint32_t f_capture
Definition: window.h:90
window_invalidate_children
void window_invalidate_children(int16_t id)
Definition: window.c:320
_window_t::f_visible
uint32_t f_visible
Definition: window.h:85
window_set_min
void window_set_min(int16_t id, float min)
Definition: window.c:682
window_validate_children
void window_validate_children(int16_t id)
Definition: window.c:312
_window_t::event
window_event_t * event
Definition: window.h:102
window_create_ptr
int16_t window_create_ptr(int16_t cls_id, int16_t id_parent, rect_ui16_t rect, void *ptr)
Definition: window.c:102
window_enable
void window_enable(int16_t id)
Definition: window.c:517
window_next_enabled
int16_t window_next_enabled(int16_t id)
Definition: window.c:211
_window_list_t::index
int index
Definition: window_list.h:24
_window_set_tag
void _window_set_tag(window_t *wnd, uint8_t tg)
_window_t::f_focused
uint32_t f_focused
Definition: window.h:88
window_set_min_max_step
void window_set_min_max_step(int16_t id, float min, float max, float step)
Definition: window.c:767
window_get_color_text
color_t window_get_color_text(int16_t id)
Definition: window.c:469
window_is_enabled
int window_is_enabled(int16_t id)
Definition: window.c:257
window_validate
void window_validate(int16_t id)
Definition: window.c:298
window_capture_ptr
window_t * window_capture_ptr
Definition: window.c:21
window_draw
void window_draw(int16_t id)
Definition: window.c:277
color_t
uint32_t color_t
Definition: guitypes.h:62
window_init_t
void() window_init_t(void *window)
Definition: window.h:55
window_set_item_count
void window_set_item_count(int16_t id, int count)
Definition: window.c:573
window_list_item_t
void() window_list_item_t(window_list_t *pwindow_list, uint16_t index, const char **pptext, uint16_t *pid_icon)
Definition: window.h:61
_window_list_t
Definition: window_list.h:15
window_focused
int16_t window_focused(void)
Definition: window.c:165
window_get_text
char * window_get_text(int16_t id)
Definition: window.c:352
window_set_step
void window_set_step(int16_t id, float step)
Definition: window.c:726
_window_t::flg
uint32_t flg
Definition: window.h:81
window_set_item_callback
void window_set_item_callback(int16_t id, window_list_item_t *fnc)
Definition: window.c:787
window_parent
int16_t window_parent(int16_t id)
Definition: window.c:173
window_set_item_index
void window_set_item_index(int16_t id, int index)
Definition: window.c:598
_window_t::cls
window_class_t * cls
Definition: window.h:77
window_get_color_back
color_t window_get_color_back(int16_t id)
Definition: window.c:446
WINDOW_FLG_INVALID
#define WINDOW_FLG_INVALID
Definition: window.h:26
window_set_color_text
void window_set_color_text(int16_t id, color_t clr)
Definition: window.c:457
_window_t::f_tag
uint32_t f_tag
Definition: window.h:98
_window_invalidate
static void _window_invalidate(window_t *window)
Definition: window.h:257
window_prev_enabled
int16_t window_prev_enabled(int16_t id)
Definition: window.c:204
window_get_item_count
int window_get_item_count(int16_t id)
Definition: window.c:585
window_set_capture
void window_set_capture(int16_t id)
Definition: window.c:500
_window_t::f_freemem
uint32_t f_freemem
Definition: window.h:93