This source file includes following definitions.
- gui_mbox_init
- gui_mbox_draw
- gui_mbox_kbd_process
- gui_mbox_touch_handler
- gui_browser_progress_show
1 #include "camera_info.h"
2 #include "lang.h"
3 #include "modes.h"
4 #include "keyboard.h"
5 #include "gui.h"
6 #include "gui_draw.h"
7 #include "gui_lang.h"
8 #include "gui_mbox.h"
9
10
11 void gui_mbox_draw();
12 int gui_mbox_kbd_process();
13 int gui_mbox_touch_handler(int,int);
14
15 static gui_handler mboxGuiHandler = { GUI_MODE_MBOX, gui_mbox_draw, gui_mbox_kbd_process, 0, gui_mbox_touch_handler, GUI_MODE_FLAG_NORESTORE_ON_SWITCH };
16
17 static gui_handler *gui_mbox_mode_old;
18 static const char* mbox_title;
19 static const char* mbox_msg;
20 static char mbox_to_draw;
21 static unsigned int mbox_flags;
22 #define MAX_LINES 8
23 #define MAX_WIDTH 35
24 #define SPACING_TITLE 4
25 #define SPACING_BTN 4
26 static struct {
27 unsigned int flag;
28 int text;
29 } buttons[] = {
30 { MBOX_BTN_OK, LANG_MBOX_BTN_OK },
31 { MBOX_BTN_YES, LANG_MBOX_BTN_YES },
32 { MBOX_BTN_NO, LANG_MBOX_BTN_NO },
33 { MBOX_BTN_CANCEL, LANG_MBOX_BTN_CANCEL}
34 };
35 #define BUTTON_SIZE 6
36 #define BUTTONSNUM (int)(sizeof(buttons)/sizeof(buttons[0]))
37 #define MAX_BUTTONS 3
38 static int mbox_buttons[MAX_BUTTONS], mbox_buttons_num, mbox_button_active;
39 static coord mbox_buttons_x, mbox_buttons_y;
40 #define BUTTON_SEP 18
41 static void (*mbox_on_select)(unsigned int btn);
42
43
44 void gui_mbox_init(int title, int msg, const unsigned int flags, void (*on_select)(unsigned int btn))
45 {
46 int i;
47
48 mbox_buttons_num = 0;
49 for (i=0; i<BUTTONSNUM && mbox_buttons_num<MAX_BUTTONS; ++i)
50 {
51 if (flags & MBOX_BTN_MASK & buttons[i].flag)
52 mbox_buttons[mbox_buttons_num++] = i;
53 }
54 if (mbox_buttons_num == 0)
55 mbox_buttons[mbox_buttons_num++] = 0;
56
57 switch (flags & MBOX_DEF_MASK)
58 {
59 case MBOX_DEF_BTN2:
60 mbox_button_active = 1;
61 break;
62 case MBOX_DEF_BTN3:
63 mbox_button_active = 2;
64 break;
65 case MBOX_DEF_BTN1:
66 default:
67 mbox_button_active = 0;
68 break;
69 }
70
71 mbox_title = lang_str(title);
72 mbox_msg = lang_str(msg);
73 mbox_to_draw = 3;
74 mbox_flags = flags;
75 mbox_on_select = on_select;
76
77 gui_mbox_mode_old = gui_set_mode(&mboxGuiHandler);
78 }
79
80
81 void gui_mbox_draw()
82 {
83 if (mbox_to_draw & 1)
84 {
85 int bw=(mbox_buttons_num*BUTTON_SIZE*FONT_WIDTH+(mbox_buttons_num-1)*BUTTON_SEP);
86
87 int h = MAX_LINES;
88 int w = text_dimensions(mbox_msg, strlen(mbox_title), MAX_WIDTH, &h) + 2;
89
90 if (bw+BUTTON_SEP > w*FONT_WIDTH)
91 w = (bw+BUTTON_SEP)/FONT_WIDTH+1;
92
93 coord x = (camera_screen.width - w * FONT_WIDTH) >> 1;
94 coord y = (camera_screen.height - (h+2) * FONT_HEIGHT) >> 1;
95 draw_rectangle(x-4, y-4, x+w*FONT_WIDTH+4, y+(h+2)*FONT_HEIGHT+SPACING_BTN+2+SPACING_TITLE+7,
96 MAKE_COLOR(COLOR_GREY, COLOR_WHITE), RECT_BORDER3|DRAW_FILLED|RECT_SHADOW3);
97 draw_rectangle(x-2, y-2, x+w*FONT_WIDTH+2, y+FONT_HEIGHT+2, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE), RECT_BORDER1|DRAW_FILLED);
98
99 draw_string_justified(x, y, mbox_title, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE), 0, w*FONT_WIDTH, TEXT_CENTER);
100 y += FONT_HEIGHT+2+SPACING_TITLE;
101
102 int justification = TEXT_LEFT;
103 switch (mbox_flags & MBOX_TEXT_MASK)
104 {
105 case MBOX_TEXT_CENTER: justification = TEXT_CENTER; break;
106 case MBOX_TEXT_RIGHT: justification = TEXT_RIGHT; break;
107 }
108 draw_text_justified(x+FONT_WIDTH, y, mbox_msg, MAKE_COLOR(COLOR_GREY, COLOR_WHITE), w-1, MAX_LINES, justification);
109
110 mbox_buttons_x = x+((w*FONT_WIDTH-bw)>>1);
111 mbox_buttons_y = y+h*FONT_HEIGHT+SPACING_BTN;
112 }
113
114 if (mbox_to_draw & 2)
115 {
116 int i;
117 for (i=0; i<mbox_buttons_num; ++i)
118 {
119 draw_button(mbox_buttons_x + i * (BUTTON_SIZE*FONT_WIDTH+BUTTON_SEP), mbox_buttons_y, BUTTON_SIZE, buttons[mbox_buttons[i]].text, (mbox_button_active == i));
120 }
121 }
122
123 mbox_to_draw = 0;
124 }
125
126
127 int gui_mbox_kbd_process()
128 {
129 switch (kbd_get_clicked_key() | get_jogdial_direction())
130 {
131 case JOGDIAL_LEFT:
132 case KEY_LEFT:
133 if (--mbox_button_active < 0) mbox_button_active = mbox_buttons_num - 1;
134 mbox_to_draw = 2;
135 break;
136 case JOGDIAL_RIGHT:
137 case KEY_RIGHT:
138 if (++mbox_button_active >= mbox_buttons_num) mbox_button_active = 0;
139 mbox_to_draw = 2;
140 break;
141 case KEY_SET:
142 gui_set_mode(gui_mbox_mode_old);
143 if (mbox_flags & MBOX_FUNC_RESTORE)
144 gui_set_need_restore();
145 if (mbox_on_select)
146 mbox_on_select(buttons[mbox_buttons[mbox_button_active]].flag);
147 break;
148 }
149 return 0;
150 }
151
152 int gui_mbox_touch_handler(int sx, int sy)
153 {
154 int i;
155 coord x = mbox_buttons_x;
156
157 if ((sy >= mbox_buttons_y-2) && (sy <= mbox_buttons_y+FONT_HEIGHT+2))
158 {
159 for (i=0; i<mbox_buttons_num; ++i)
160 {
161 if ((sx >= x) && (sx <= x+BUTTON_SIZE*FONT_WIDTH+3))
162 {
163 if (mbox_button_active != i)
164 {
165 mbox_to_draw = 2;
166 mbox_button_active = i;
167 }
168 return KEY_SET;
169 }
170 x += BUTTON_SIZE*FONT_WIDTH+BUTTON_SEP;
171 }
172 }
173 return 0;
174 }
175
176
177
178 void gui_browser_progress_show(const char* msg, const unsigned int perc)
179 {
180 coord x=60, y=100;
181 unsigned int w=240, h=40;
182
183 draw_rectangle(x, y, x+w, y+h, MAKE_COLOR(COLOR_GREY, COLOR_WHITE), RECT_BORDER1|DRAW_FILLED|RECT_SHADOW3);
184 draw_string_justified(x, y+2, msg, MAKE_COLOR(COLOR_GREY, COLOR_WHITE), 0, w, TEXT_CENTER);
185 draw_rectangle(x+10, y+4+FONT_HEIGHT, x+w-10, y+h-10, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE), RECT_BORDER1|DRAW_FILLED);
186 draw_rectangle(x+11, y+5+FONT_HEIGHT, x+11+(w-22)*perc/100, y+h-11, MAKE_COLOR(COLOR_RED, COLOR_RED), RECT_BORDER0|DRAW_FILLED);
187 }