Prusa MINI Firmware overview
window_msgbox.c File Reference
#include "window_msgbox.h"
#include "gui.h"
#include "resource.h"
#include "button_draw.h"

Functions

void window_msgbox_draw_buttons (window_msgbox_t *window)
 
void window_msgbox_step (window_msgbox_t *window, int step)
 
void window_msgbox_click (window_msgbox_t *window)
 
void window_msgbox_init (window_msgbox_t *window)
 
void window_msgbox_done (window_msgbox_t *window)
 
void window_msgbox_draw (window_msgbox_t *window)
 
void window_msgbox_event (window_msgbox_t *window, uint8_t event, void *param)
 

Variables

const char * window_msgbox_title_text []
 
const uint8_t window_msgbox_button_count []
 
const uint8_t window_msgbox_buttons [][3]
 
const char * window_msgbox_button_text []
 
uint16_t window_msgbox_id_icon [5]
 
const window_class_msgbox_t window_class_msgbox
 

Function Documentation

◆ window_msgbox_draw_buttons()

void window_msgbox_draw_buttons ( window_msgbox_t window)
70  {
71  rect_ui16_t rc_btn = window->win.rect;
72  rc_btn.y += (rc_btn.h - 40); // 30pixels for buttons + 10pix for grey frame
73  rc_btn.h = 30;
74  int btn = ((window->flags & MSGBOX_MSK_BTN) >> MSGBOX_SHI_BTN); // button config
75  if (btn > MSGBOX_BTN_MAX)
76  return; //invalid config - exit
77  int count = window_msgbox_button_count[btn]; // get number of buttons from table
78  const uint8_t *buttons = window_msgbox_buttons[btn]; // get pointer to 3 element button array
79  int idx = ((window->flags & MSGBOX_MSK_IDX) >> MSGBOX_SHI_IDX); // selected button index
80  int chg = ((window->flags & MSGBOX_MSK_CHG) >> MSGBOX_SHI_CHG); // change mask
81  if (chg == 7) //clear background if all buttons changed
82  display->fill_rect(rc_btn, window->color_back);
83  int spacing2 = gui_defaults.btn_spacing; // 12 pixels spacing between buttons, 6 from margins
84  int btn_w = (rc_btn.w - (count * 2 * spacing2)) / count; // avg width of button
85  int i;
86  font_t *pf = window->font_title;
87  float chars = 0;
88  const char *text;
89  for (i = 0; i < count; i++) {
90  uint8_t b = buttons[i];
91  text = window->buttons[i];
92  if (text == 0)
94  chars += strlen(text);
95  }
96  chars /= count; //avg chars for button
97  rc_btn.x += spacing2;
98  for (i = 0; i < count; i++) {
99  uint8_t b = buttons[i];
100  text = window->buttons[i];
101  if (text == 0)
103  rc_btn.w = btn_w + pf->w * ((float)strlen(text) - chars);
104  if (chg & (1 << i)) {
105  int is_selected = (i == idx) ? 1 : 0; //state of button (1=selected)
106  button_draw(rc_btn, text, pf, is_selected);
107  }
108  rc_btn.x += rc_btn.w + 2 * spacing2;
109  }
110  window->flags &= ~MSGBOX_MSK_CHG;
111 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ window_msgbox_step()

void window_msgbox_step ( window_msgbox_t window,
int  step 
)
113  {
114  int btn = ((window->flags & MSGBOX_MSK_BTN) >> MSGBOX_SHI_BTN); // button config
115  int count = window_msgbox_button_count[btn]; // get number of buttons from table
116  int idx = ((window->flags & MSGBOX_MSK_IDX) >> MSGBOX_SHI_IDX); // selected button index
117  int chg = (1 << idx); // change mask - old button
118  idx += step; // increment index
119  if (idx < 0)
120  idx = 0; // check min
121  if (idx >= count)
122  idx = count - 1; // check max
123  chg |= (1 << idx); // change mask - new button
124  window->flags = (window->flags & ~MSGBOX_MSK_IDX) | // clear index bits
125  ((idx << MSGBOX_SHI_IDX) & MSGBOX_MSK_IDX) | // set new index bits
126  ((chg << MSGBOX_SHI_CHG) & MSGBOX_MSK_CHG); // set change flags
127  gui_invalidate();
128 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ window_msgbox_click()

void window_msgbox_click ( window_msgbox_t window)
130  {
131  int btn = ((window->flags & MSGBOX_MSK_BTN) >> MSGBOX_SHI_BTN); // button config
132  //int count = window_msgbox_button_count[btn]; // get number of buttons from table
133  int idx = ((window->flags & MSGBOX_MSK_IDX) >> MSGBOX_SHI_IDX); // selected button index
134  window->res = window_msgbox_buttons[btn][idx];
135  window_destroy(window->win.id);
136 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ window_msgbox_init()

void window_msgbox_init ( window_msgbox_t window)
138  {
139  if (rect_empty_ui16(window->win.rect)) //use display rect if current rect is empty
140  window->win.rect = rect_ui16(0, 0, display->w, display->h);
141  window->win.flg |= WINDOW_FLG_ENABLED; //enabled by default
144  window->font = gui_defaults.font;
145  window->font_title = gui_defaults.font_big;
146  window->padding = padding_ui8(8, 2, 8, 2);
147  window->alignment = ALIGN_CENTER;
148  window->title = 0;
149  window->id_icon = 0;
150  window->text = 0;
151  window->flags = MSGBOX_BTN_OK | MSGBOX_ICO_INFO;
152  window->res = 0;
153 }
Here is the call graph for this function:

◆ window_msgbox_done()

void window_msgbox_done ( window_msgbox_t window)
155  {
156 }

◆ window_msgbox_draw()

void window_msgbox_draw ( window_msgbox_t window)
158  {
160  rect_ui16_t rc_tit = window->win.rect;
161 
162  uint8_t red_line_offset = 0;
163  int ico = ((window->flags & MSGBOX_MSK_ICO) >> MSGBOX_SHI_ICO);
164  const char *title = window->title; // get title from window member
165  if (title == 0) // if null, set defaut title (info, warning, error...)
166  title = window_msgbox_title_text[ico];
167  int title_h = 0; // title hight in pixels
168  int title_n = strlen(title); // number of chars in title
169  if (title_n) // if not empty, set title hight from font
170  title_h = window->font_title->h;
171  uint16_t id_icon = window->id_icon; // get icon id from window member
172  if (ico < 1) { // for error, warning, info and question -> disable icon
173  if (id_icon == 0)
174  id_icon = window_msgbox_id_icon[ico];
175  }
176  const uint8_t *picon = 0; // icon resource pointer
177  point_ui16_t icon_wh = point_ui16(0, 0); // icon width-height - default (0,0)
178  if ((id_icon) && (picon = resource_ptr(id_icon))) { // id_icon is set and resource pointer is not null
179  icon_wh = icon_meas(picon); // get icon dimensions
180  if (title_h < icon_wh.y)
181  title_h = icon_wh.y; // adjust title height
182  }
183  if (title_h) // calculated title height != 0 means title will be rendered
184  {
185  title_h += window->padding.top + window->padding.bottom; // add padding
186  rc_tit.h = title_h; // xxx pixels for title
187  if (title_n && picon) // text not empty and icon resource not null
188  { // icon and text will be aligned left
189  int icon_w = icon_wh.x + window->padding.left + window->padding.right;
190  int title_w = rc_tit.w - icon_w;
191  rc_tit.w = icon_w;
192  render_icon_align(rc_tit, id_icon, window->color_back, ALIGN_CENTER);
193  rc_tit.x = icon_w;
194  rc_tit.w = title_w;
195  render_text_align(rc_tit, title, window->font_title, window->color_back, window->color_text, window->padding, ALIGN_LEFT_CENTER);
196  } else if (title_n) // text not empty and icon resource is null
197  { // text will be aligned left
198  render_text_align(rc_tit, title, window->font_title, window->color_back, window->color_text, window->padding, ALIGN_LEFT_CENTER);
199  display->draw_line(point_ui16(rc_tit.x + window->padding.left, rc_tit.y + rc_tit.h),
200  point_ui16(rc_tit.x + rc_tit.w - (window->padding.left + window->padding.right), rc_tit.y + rc_tit.h),
202  red_line_offset = 1;
203  } else // text is empty, icon resource not null
204  { // icon will be aligned to center
205  render_icon_align(rc_tit, id_icon, window->color_back, ALIGN_CENTER);
206  }
207  }
208 
209  rect_ui16_t rc_txt = window->win.rect;
210  rc_txt.h -= (30 + title_h + red_line_offset); // 30pixels for buttons
211  rc_txt.y += title_h + red_line_offset;
212 
213  render_text_align(rc_txt, window->text, window->font, window->color_back, window->color_text, window->padding, window->alignment | RENDER_FLG_WORDB);
214  window->flags |= MSGBOX_MSK_CHG;
215 
216  rect_ui16_t rc_btn_bg = window->win.rect;
217  rc_btn_bg.y += (rc_btn_bg.h - 40);
218  rc_btn_bg.h = 53; //This should be 40 but, there is 13px shortage of gui_defaults.msg_box_sz.h
219  display->fill_rect(rc_btn_bg, COLOR_BLACK);
220 
222  window->win.flg &= ~WINDOW_FLG_INVALID;
223  } else if (window->flags & MSGBOX_MSK_CHG)
225 
226  if (window->flags & MSGBOX_GREY_FRAME) { //draw frame
227  rect_ui16_t rc = window->win.rect;
228  display->draw_line(point_ui16(rc.x, rc.y), point_ui16(239, rc.y), COLOR_GRAY);
229  display->draw_line(point_ui16(rc.x, rc.y), point_ui16(rc.x, 320 - 67), COLOR_GRAY);
230  display->draw_line(point_ui16(239, rc.y), point_ui16(239, 320 - 67), COLOR_GRAY);
231  display->draw_line(point_ui16(rc.x, 320 - 67), point_ui16(239, 320 - 67), COLOR_GRAY);
232  }
233 }
Here is the call graph for this function:

◆ window_msgbox_event()

void window_msgbox_event ( window_msgbox_t window,
uint8_t  event,
void param 
)
235  {
236  switch (event) {
237  case WINDOW_EVENT_BTN_DN:
238  window_msgbox_click(window);
239  break;
240  case WINDOW_EVENT_ENC_DN:
241  window_msgbox_step(window, -1);
242  break;
243  case WINDOW_EVENT_ENC_UP:
244  window_msgbox_step(window, +1);
245  break;
246  }
247 }
Here is the call graph for this function:

Variable Documentation

◆ window_msgbox_title_text

const char* window_msgbox_title_text[]
Initial value:
= {
"",
"Error",
"Question",
"Warning",
"Information",
}

◆ window_msgbox_button_count

const uint8_t window_msgbox_button_count[]
Initial value:
= {
1,
2,
3,
3,
2,
2,
1,
2,
3,
}

◆ window_msgbox_buttons

◆ window_msgbox_button_text

const char* window_msgbox_button_text[]
Initial value:
= {
"",
"",
"CANCEL",
"ABORT",
"RETRY",
"IGNORE",
"YES",
"NO",
"OK",
"",
"TRY AGAIN",
"CONTINUE",
"CUSTOM0",
"CUSTOM1",
"CUSTOM2",
}

◆ window_msgbox_id_icon

uint16_t window_msgbox_id_icon[5]
Initial value:
= {
0,
0,
0,
0,
0,
}

◆ window_class_msgbox

window_draw_t
void() window_draw_t(void *window)
Definition: window.h:57
MSGBOX_RES_CANCEL
#define MSGBOX_RES_CANCEL
Definition: window_msgbox.h:40
window_msgbox_done
void window_msgbox_done(window_msgbox_t *window)
Definition: window_msgbox.c:155
_rect_ui16_t::y
uint16_t y
Definition: guitypes.h:71
_font_t::h
uint8_t h
Definition: guitypes.h:78
_display_t::h
uint16_t h
Definition: display.h:26
_rect_ui16_t::w
uint16_t w
Definition: guitypes.h:72
_font_t
Definition: guitypes.h:76
_padding_ui8_t::bottom
uint8_t bottom
Definition: guitypes.h:90
MSGBOX_GREY_FRAME
#define MSGBOX_GREY_FRAME
Definition: window_msgbox.h:58
MSGBOX_SHI_CHG
#define MSGBOX_SHI_CHG
Definition: window_msgbox.h:17
window_msgbox_draw_buttons
void window_msgbox_draw_buttons(window_msgbox_t *window)
Definition: window_msgbox.c:70
MSGBOX_MSK_BTN
#define MSGBOX_MSK_BTN
Definition: window_msgbox.h:9
MSGBOX_SHI_BTN
#define MSGBOX_SHI_BTN
Definition: window_msgbox.h:15
_window_msgbox_t::padding
padding_ui8_t padding
Definition: window_msgbox.h:73
_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
_window_msgbox_t::font_title
font_t * font_title
Definition: window_msgbox.h:72
MSGBOX_SHI_ICO
#define MSGBOX_SHI_ICO
Definition: window_msgbox.h:14
MSGBOX_RES_CUSTOM1
#define MSGBOX_RES_CUSTOM1
Definition: window_msgbox.h:50
WINDOW_EVENT_ENC_UP
#define WINDOW_EVENT_ENC_UP
Definition: window.h:41
ALIGN_CENTER
#define ALIGN_CENTER
Definition: guitypes.h:19
MSGBOX_RES_NO
#define MSGBOX_RES_NO
Definition: window_msgbox.h:45
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
_gui_defaults_t::font
font_t * font
Definition: guitypes.h:110
window_msgbox_title_text
const char * window_msgbox_title_text[]
Definition: window_msgbox.c:8
_window_msgbox_t::title
const char * title
Definition: window_msgbox.h:75
window_destroy
void window_destroy(int16_t id)
Definition: window.c:132
RENDER_FLG_WORDB
#define RENDER_FLG_WORDB
Definition: display_helper.h:9
padding_ui8
static padding_ui8_t padding_ui8(uint8_t l, uint8_t t, uint8_t r, uint8_t b)
Definition: guitypes.h:164
i
uint8_t i
Definition: screen_test_graph.c:72
WINDOW_FLG_VISIBLE
#define WINDOW_FLG_VISIBLE
Definition: window.h:24
window_msgbox_button_text
const char * window_msgbox_button_text[]
Definition: window_msgbox.c:43
_window_msgbox_t::color_text
color_t color_text
Definition: window_msgbox.h:70
MSGBOX_BTN_MAX
#define MSGBOX_BTN_MAX
Definition: window_msgbox.h:29
MSGBOX_ICO_INFO
#define MSGBOX_ICO_INFO
Definition: window_msgbox.h:36
window_msgbox_buttons
const uint8_t window_msgbox_buttons[][3]
Definition: window_msgbox.c:30
_point_ui16_t
Definition: guitypes.h:64
MSGBOX_BTN_OK
#define MSGBOX_BTN_OK
Definition: window_msgbox.h:20
_display_t::fill_rect
display_fill_rect_t * fill_rect
Definition: display.h:33
_window_t::id
int16_t id
Definition: window.h:79
_padding_ui8_t::left
uint8_t left
Definition: guitypes.h:87
COLOR_GRAY
#define COLOR_GRAY
Definition: guitypes.h:50
_window_msgbox_t::win
window_t win
Definition: window_msgbox.h:68
_window_msgbox_t::color_back
color_t color_back
Definition: window_msgbox.h:69
MSGBOX_SHI_IDX
#define MSGBOX_SHI_IDX
Definition: window_msgbox.h:16
button_draw
void button_draw(rect_ui16_t rc_btn, const char *text, font_t *pf, int is_selected)
Definition: button_draw.c:5
window_done_t
void() window_done_t(void *window)
Definition: window.h:56
gui_invalidate
void gui_invalidate(void)
Definition: gui.c:66
MSGBOX_RES_ABORT
#define MSGBOX_RES_ABORT
Definition: window_msgbox.h:41
MSGBOX_RES_CUSTOM2
#define MSGBOX_RES_CUSTOM2
Definition: window_msgbox.h:51
_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
MSGBOX_MSK_CHG
#define MSGBOX_MSK_CHG
Definition: window_msgbox.h:11
MSGBOX_RES_YES
#define MSGBOX_RES_YES
Definition: window_msgbox.h:44
window_msgbox_init
void window_msgbox_init(window_msgbox_t *window)
Definition: window_msgbox.c:138
_window_msgbox_t::alignment
uint8_t alignment
Definition: window_msgbox.h:74
MSGBOX_MSK_IDX
#define MSGBOX_MSK_IDX
Definition: window_msgbox.h:10
window_msgbox_t
struct _window_msgbox_t window_msgbox_t
_gui_defaults_t::color_back
color_t color_back
Definition: guitypes.h:107
window_msgbox_step
void window_msgbox_step(window_msgbox_t *window, int step)
Definition: window_msgbox.c:113
_font_t::w
uint8_t w
Definition: guitypes.h:77
_window_msgbox_t::font
font_t * font
Definition: window_msgbox.h:71
window_msgbox_event
void window_msgbox_event(window_msgbox_t *window, uint8_t event, void *param)
Definition: window_msgbox.c:235
icon_meas
point_ui16_t icon_meas(const uint8_t *pi)
Definition: guitypes.c:155
MSGBOX_RES_CUSTOM0
#define MSGBOX_RES_CUSTOM0
Definition: window_msgbox.h:49
_gui_defaults_t::btn_spacing
uint8_t btn_spacing
Definition: guitypes.h:115
WINDOW_CLS_MSGBOX
#define WINDOW_CLS_MSGBOX
Definition: window.h:19
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
render_text_align
void render_text_align(rect_ui16_t rc, const char *text, font_t *font, color_t clr0, color_t clr1, padding_ui8_t padding, uint16_t flags)
Definition: display_helper.c:6
uint8_t
const uint8_t[]
Definition: 404_html.c:3
resource_ptr
const uint8_t * resource_ptr(uint16_t id)
Definition: guitypes.c:168
display
display_t * display
Definition: display.c:6
_rect_ui16_t::h
uint16_t h
Definition: guitypes.h:73
_window_t::rect
rect_ui16_t rect
Definition: window.h:101
MSGBOX_RES_OK
#define MSGBOX_RES_OK
Definition: window_msgbox.h:46
_window_msgbox_t::id_icon
uint16_t id_icon
Definition: window_msgbox.h:76
MSGBOX_RES_RETRY
#define MSGBOX_RES_RETRY
Definition: window_msgbox.h:42
COLOR_BLACK
#define COLOR_BLACK
Definition: guitypes.h:40
COLOR_RED_ALERT
#define COLOR_RED_ALERT
Definition: guitypes.h:43
_window_msgbox_t::text
const char * text
Definition: window_msgbox.h:77
_window_msgbox_t::res
int res
Definition: window_msgbox.h:80
_rect_ui16_t::x
uint16_t x
Definition: guitypes.h:70
_display_t::w
uint16_t w
Definition: display.h:25
_window_msgbox_t::buttons
const char * buttons[3]
Definition: window_msgbox.h:78
window_msgbox_id_icon
uint16_t window_msgbox_id_icon[5]
Definition: window_msgbox.c:62
MSGBOX_RES_IGNORE
#define MSGBOX_RES_IGNORE
Definition: window_msgbox.h:43
_gui_defaults_t::font_big
font_t * font_big
Definition: guitypes.h:111
window_init_t
void() window_init_t(void *window)
Definition: window.h:55
gui_defaults
gui_defaults_t gui_defaults
Definition: gui.c:20
render_icon_align
void render_icon_align(rect_ui16_t rc, uint16_t id_res, color_t clr0, uint16_t flags)
Definition: display_helper.c:55
WINDOW_EVENT_BTN_DN
#define WINDOW_EVENT_BTN_DN
Definition: window.h:38
_window_msgbox_t::flags
uint16_t flags
Definition: window_msgbox.h:79
window_msgbox_click
void window_msgbox_click(window_msgbox_t *window)
Definition: window_msgbox.c:130
MSGBOX_MSK_ICO
#define MSGBOX_MSK_ICO
Definition: window_msgbox.h:8
_window_t::flg
uint32_t flg
Definition: window.h:81
createSpeedLookupTable.b
list b
Definition: createSpeedLookupTable.py:30
window_msgbox_button_count
const uint8_t window_msgbox_button_count[]
Definition: window_msgbox.c:17
_display_t::draw_line
display_draw_line_t * draw_line
Definition: display.h:31
WINDOW_FLG_INVALID
#define WINDOW_FLG_INVALID
Definition: window.h:26
WINDOW_FLG_ENABLED
#define WINDOW_FLG_ENABLED
Definition: window.h:25
WINDOW_EVENT_ENC_DN
#define WINDOW_EVENT_ENC_DN
Definition: window.h:40
point_ui16
static point_ui16_t point_ui16(uint16_t x, uint16_t y)
Definition: guitypes.h:154
window_msgbox_draw
void window_msgbox_draw(window_msgbox_t *window)
Definition: window_msgbox.c:158
ALIGN_LEFT_CENTER
#define ALIGN_LEFT_CENTER
Definition: guitypes.h:21