1 | /*␊ |
2 | * gui.c␊ |
3 | * ␊ |
4 | *␊ |
5 | * Created by Jasmin Fazlic on 18.12.08.␊ |
6 | * Copyright 2008/09 Jasmin Fazlic All rights reserved.␊ |
7 | * Copyright 2008/09 iNDi All rights reserved.␊ |
8 | *␊ |
9 | */␊ |
10 | ␊ |
11 | /*␊ |
12 | * cparm : cleaned␊ |
13 | */␊ |
14 | ␊ |
15 | /*␊ |
16 | * cparm : add volume version detection␊ |
17 | */␊ |
18 | #include "platform.h"␊ |
19 | #include "gui.h"␊ |
20 | #include "GUI_appleboot.h"␊ |
21 | #include "vers.h"␊ |
22 | #include "modules.h"␊ |
23 | #include "sl.h"␊ |
24 | ␊ |
25 | #ifndef DEBUG_GUI␊ |
26 | #define DEBUG_GUI 0␊ |
27 | #endif␊ |
28 | ␊ |
29 | #if DEBUG_GUI==2␊ |
30 | #define DBG(x...)␉printf(x);sleep(2)␊ |
31 | #elif DEBUG_GUI==1␊ |
32 | #define DBG(x...)␉printf(x)␊ |
33 | #else␊ |
34 | #define DBG(x...)␊ |
35 | #endif␊ |
36 | ␊ |
37 | enum {␊ |
38 | ␉kBackspaceKey␉= 0x08,␊ |
39 | ␉kTabKey␉␉␉= 0x09,␊ |
40 | ␉kReturnKey␉␉= 0x0d,␊ |
41 | ␉kEscapeKey␉␉= 0x1b,␊ |
42 | ␉kUpArrowkey␉␉= 0x4800, ␊ |
43 | ␉kDownArrowkey␉= 0x5000,␊ |
44 | ␉kASCIIKeyMask␉= 0x7f,␊ |
45 | ␉kF5Key␉␉␉= 0x3f00,␊ |
46 | ␉kF10Key␉␉␉= 0x4400␊ |
47 | };␊ |
48 | ␊ |
49 | static config_file_t themeConfig;␉␉␉␉ // theme.plist␊ |
50 | ␊ |
51 | jmp_buf uterror;␊ |
52 | ␊ |
53 | // CoreHash Declarations␊ |
54 | __CHNewStrVar(themeList_t)␊ |
55 | CHUnInit(themeList_t)␊ |
56 | ␊ |
57 | static void (*showHelp)(void) = NULL;␊ |
58 | static char *(*getMemoryInfoString)(void) = NULL;␊ |
59 | ␊ |
60 | ␊ |
61 | gui_t gui;␉␉␉␉␉// gui structure␊ |
62 | font_t font_small;␊ |
63 | font_t font_console;␊ |
64 | ␊ |
65 | ␊ |
66 | #define IMG_REQUIRED -1␊ |
67 | #define THEME_NAME_DEFAULT␉"Default"␊ |
68 | const char* theme_name = THEME_NAME_DEFAULT;␊ |
69 | ␊ |
70 | #define MAX_THEMES 255␊ |
71 | ␊ |
72 | struct themeList_t *gthemeList = NULL;␊ |
73 | static char tmp_theme[64]; // should be engouth ␊ |
74 | ␊ |
75 | char dirsrc[22];␊ |
76 | ␊ |
77 | #ifdef EMBED_THEME␊ |
78 | #include "art.h"␊ |
79 | #endif␊ |
80 | ␊ |
81 | ␊ |
82 | static int loadThemeImage(char *src, const char *image, int alt_image);␊ |
83 | static void loadBootGraphics(char *src);␊ |
84 | static void drawInfoMenuItems();␊ |
85 | static void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress);␊ |
86 | static void animateProgressBar();␊ |
87 | static void makeRoundedCorners(pixmap_t *p);␊ |
88 | static void colorFont(font_t *font, uint32_t color);␊ |
89 | static int initFont(font_t *font, image_t *data);␊ |
90 | static void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p);␊ |
91 | static position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p);␊ |
92 | static void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p);␊ |
93 | #if DEBUG_GUI␊ |
94 | static int dprintf( window_t * window, const char * fmt, ...);␊ |
95 | #endif␊ |
96 | ␊ |
97 | static inline␊ |
98 | void vramwrite (void *data, int width);␊ |
99 | ␊ |
100 | static void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected);␊ |
101 | static int startGUI(void);␊ |
102 | static void free_theme_list();␊ |
103 | static void add_theme(const char* theme, uint8_t nb);␊ |
104 | static int randomTheme(char *dirspec, const char **theme);␊ |
105 | static void loadThemeValues(config_file_t *theme);␊ |
106 | static void setupDeviceList(config_file_t *theme);␊ |
107 | static void fillPixmapWithColor(pixmap_t *pm, uint32_t color);␊ |
108 | static int freeWindowBuffer( window_t *window );␊ |
109 | static int createWindowBuffer( window_t *window );␊ |
110 | static int createBackBuffer( window_t *window );␊ |
111 | static int loadGraphics(char *src);␊ |
112 | #ifdef EMBED_THEME␊ |
113 | static int getEmbeddedImageIndexByName(const char *name);␊ |
114 | #endif␊ |
115 | static int getImageIndexByName(const char *name);␊ |
116 | ␊ |
117 | static int destroyFont(font_t *font);␊ |
118 | static int unloadGraphics(void);␊ |
119 | static int freeBackBuffer( window_t *window );␊ |
120 | static bool is_image_loaded(int i);␊ |
121 | static bool GUI_getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size );␊ |
122 | static bool GUI_getColorForKey( const char *key, unsigned int *value, config_file_t *config );␊ |
123 | ␊ |
124 | #define LOADPNG(src, img, alt_img) if (loadThemeImage(src, #img, alt_img) != 0) { return 1; }␊ |
125 | ␊ |
126 | #ifndef MIN␊ |
127 | #define MIN(x, y) ((x) < (y) ? (x) : (y))␊ |
128 | #endif␊ |
129 | ␊ |
130 | #ifndef MAX␊ |
131 | #define MAX(x, y) ((x) > (y) ? (x) : (y))␊ |
132 | #endif␊ |
133 | ␊ |
134 | #define VIDEO(x) (((boot_args*)getBootArgs())->Video.v_ ## x)␊ |
135 | ␊ |
136 | #define vram VIDEO(baseAddr)␊ |
137 | ␊ |
138 | #define TAB_PIXELS_WIDTH (font->chars[0]->width * 4) // tab = 4 spaces␊ |
139 | ␊ |
140 | int lasttime = 0; // we need this for animating maybe␊ |
141 | ␊ |
142 | /*␊ |
143 | * ATTENTION: the enum and the following array images[] MUST match !!!␊ |
144 | */␊ |
145 | enum {␊ |
146 | iBackground = 0,␊ |
147 | iLogo,␊ |
148 | ␉␊ |
149 | iDeviceGeneric,␊ |
150 | iDeviceGeneric_o,␊ |
151 | iDeviceHFS,␊ |
152 | iDeviceHFS_o,␊ |
153 | iDeviceHFS_ML,␊ |
154 | iDeviceHFS_ML_o,␊ |
155 | ␉iDeviceHFS_Lion,␊ |
156 | iDeviceHFS_Lion_o,␊ |
157 | ␉iDeviceHFS_SL,␊ |
158 | iDeviceHFS_SL_o,␊ |
159 | ␉iDeviceHFS_Leo,␊ |
160 | iDeviceHFS_Leo_o,␊ |
161 | ␉iDeviceHFS_Tiger,␊ |
162 | iDeviceHFS_Tiger_o,␊ |
163 | iDeviceHFSRAID,␊ |
164 | iDeviceHFSRAID_o,␊ |
165 | iDeviceHFSRAID_ML,␊ |
166 | iDeviceHFSRAID_ML_o,␊ |
167 | ␉iDeviceHFSRAID_Lion,␊ |
168 | iDeviceHFSRAID_Lion_o,␊ |
169 | ␉iDeviceHFSRAID_SL,␊ |
170 | iDeviceHFSRAID_SL_o,␊ |
171 | ␉iDeviceHFSRAID_Leo,␊ |
172 | iDeviceHFSRAID_Leo_o,␊ |
173 | ␉iDeviceHFSRAID_Tiger,␊ |
174 | iDeviceHFSRAID_Tiger_o,␊ |
175 | iDeviceEXT3,␊ |
176 | iDeviceEXT3_o,␉␊ |
177 | ␉iDeviceFreeBSD,␊ |
178 | iDeviceFreeBSD_o,␊ |
179 | iDeviceOpenBSD,␊ |
180 | iDeviceOpenBSD_o,␊ |
181 | ␉iDeviceBEFS, /* Haiku detection and Icon credits to scorpius */␊ |
182 | ␉iDeviceBEFS_o, /* Haiku detection and Icon credits to scorpius */␊ |
183 | iDeviceFAT,␊ |
184 | iDeviceFAT_o,␊ |
185 | iDeviceFAT16,␊ |
186 | iDeviceFAT16_o,␊ |
187 | iDeviceFAT32,␊ |
188 | iDeviceFAT32_o,␊ |
189 | iDeviceNTFS,␊ |
190 | iDeviceNTFS_o,␊ |
191 | iDeviceCDROM,␊ |
192 | iDeviceCDROM_o,␊ |
193 | ␉␊ |
194 | iSelection,␊ |
195 | iDeviceScrollPrev,␊ |
196 | iDeviceScrollNext,␊ |
197 | ␉␊ |
198 | iMenuBoot,␊ |
199 | iMenuVerbose,␊ |
200 | iMenuIgnoreCaches,␊ |
201 | iMenuSingleUser,␊ |
202 | iMenuMemoryInfo,␊ |
203 | iMenuVideoInfo,␊ |
204 | iMenuHelp,␊ |
205 | iMenuVerboseDisabled,␊ |
206 | iMenuIgnoreCachesDisabled,␊ |
207 | iMenuSingleUserDisabled,␊ |
208 | iMenuSelection,␊ |
209 | ␉␊ |
210 | iProgressBar,␊ |
211 | iProgressBarBackground,␊ |
212 | ␉␊ |
213 | iTextScrollPrev,␊ |
214 | iTextScrollNext,␊ |
215 | ␉␊ |
216 | iFontConsole,␊ |
217 | iFontSmall,␊ |
218 | };␊ |
219 | ␊ |
220 | image_t images[] = {␊ |
221 | {.name = "background", .image = NULL},␊ |
222 | {.name = "logo", .image = NULL},␊ |
223 | ␊ |
224 | {.name = "device_generic", .image = NULL},␊ |
225 | {.name = "device_generic_o", .image = NULL},␊ |
226 | ␊ |
227 | ␉{.name = "device_hfsplus", .image = NULL},␊ |
228 | {.name = "device_hfsplus_o", .image = NULL},␊ |
229 | ␉{.name = "device_hfsplus_ml", .image = NULL},␊ |
230 | {.name = "device_hfsplus_ml_o", .image = NULL},␊ |
231 | ␉{.name = "device_hfsplus_lion", .image = NULL},␊ |
232 | {.name = "device_hfsplus_lion_o", .image = NULL},␊ |
233 | ␉{.name = "device_hfsplus_sl", .image = NULL},␊ |
234 | {.name = "device_hfsplus_sl_o", .image = NULL},␊ |
235 | ␉{.name = "device_hfsplus_leo", .image = NULL},␊ |
236 | {.name = "device_hfsplus_leo_o", .image = NULL},␊ |
237 | ␉{.name = "device_hfsplus_tiger", .image = NULL},␊ |
238 | {.name = "device_hfsplus_tiger_o", .image = NULL},␊ |
239 | ␉␊ |
240 | {.name = "device_hfsraid", .image = NULL},␊ |
241 | {.name = "device_hfsraid_o", .image = NULL},␊ |
242 | {.name = "device_hfsraid_ml", .image = NULL},␊ |
243 | {.name = "device_hfsraid_ml_o", .image = NULL},␊ |
244 | ␉{.name = "device_hfsraid_lion", .image = NULL},␊ |
245 | {.name = "device_hfsraid_lion_o", .image = NULL},␊ |
246 | ␉{.name = "device_hfsraid_sl", .image = NULL},␊ |
247 | {.name = "device_hfsraid_sl_o", .image = NULL},␊ |
248 | ␉{.name = "device_hfsraid_leo", .image = NULL},␊ |
249 | {.name = "device_hfsraid_leo_o", .image = NULL},␊ |
250 | ␉{.name = "device_hfsraid_tiger", .image = NULL},␊ |
251 | {.name = "device_hfsraid_tiger_o", .image = NULL},␊ |
252 | ␉␊ |
253 | {.name = "device_ext3", .image = NULL},␊ |
254 | {.name = "device_ext3_o", .image = NULL},␊ |
255 | ␉{.name = "device_freebsd", .image = NULL},␊ |
256 | {.name = "device_freebsd_o", .image = NULL},␊ |
257 | {.name = "device_openbsd", .image = NULL},␊ |
258 | {.name = "device_openbsd_o", .image = NULL},␊ |
259 | ␉{.name = "device_befs", .image = NULL}, /* Haiku detection and Icon credits to scorpius */␊ |
260 | ␉{.name = "device_befs_o", .image = NULL}, /* Haiku detection and Icon credits to scorpius */␊ |
261 | {.name = "device_fat", .image = NULL},␊ |
262 | {.name = "device_fat_o", .image = NULL},␊ |
263 | {.name = "device_fat16", .image = NULL},␊ |
264 | {.name = "device_fat16_o", .image = NULL},␊ |
265 | {.name = "device_fat32", .image = NULL},␊ |
266 | {.name = "device_fat32_o", .image = NULL},␊ |
267 | {.name = "device_ntfs", .image = NULL},␊ |
268 | {.name = "device_ntfs_o", .image = NULL},␊ |
269 | {.name = "device_cdrom", .image = NULL},␊ |
270 | {.name = "device_cdrom_o", .image = NULL},␊ |
271 | ␉␊ |
272 | {.name = "device_selection", .image = NULL},␊ |
273 | {.name = "device_scroll_prev", .image = NULL},␊ |
274 | {.name = "device_scroll_next", .image = NULL},␊ |
275 | ␊ |
276 | {.name = "menu_boot", .image = NULL},␊ |
277 | {.name = "menu_verbose", .image = NULL},␊ |
278 | {.name = "menu_ignore_caches", .image = NULL},␊ |
279 | {.name = "menu_single_user", .image = NULL},␊ |
280 | {.name = "menu_memory_info", .image = NULL},␊ |
281 | {.name = "menu_video_info", .image = NULL},␊ |
282 | {.name = "menu_help", .image = NULL},␊ |
283 | {.name = "menu_verbose_disabled", .image = NULL},␊ |
284 | {.name = "menu_ignore_caches_disabled", .image = NULL},␊ |
285 | {.name = "menu_single_user_disabled", .image = NULL},␊ |
286 | {.name = "menu_selection", .image = NULL},␊ |
287 | ␊ |
288 | {.name = "progress_bar", .image = NULL},␊ |
289 | {.name = "progress_bar_background", .image = NULL},␊ |
290 | ␊ |
291 | {.name = "text_scroll_prev", .image = NULL},␊ |
292 | {.name = "text_scroll_next", .image = NULL},␊ |
293 | ␊ |
294 | {.name = "font_console", .image = NULL},␊ |
295 | {.name = "font_small", .image = NULL},␊ |
296 | };␊ |
297 | ␊ |
298 | //int imageCnt = 0;␊ |
299 | ␊ |
300 | char prompt[BOOT_STRING_LEN];␊ |
301 | ␊ |
302 | int prompt_pos=0;␊ |
303 | ␊ |
304 | char prompt_text[] = "boot: ";␊ |
305 | ␊ |
306 | menuitem_t infoMenuItems[] =␊ |
307 | {␊ |
308 | ␉{ .text = "Boot" },␊ |
309 | ␉{ .text = "Boot Verbose" },␊ |
310 | ␉{ .text = "Boot Ignore Caches" },␊ |
311 | ␉{ .text = "Boot Single User" },␊ |
312 | ␉{ .text = "Memory Info" },␊ |
313 | ␉{ .text = "Video Info" },␊ |
314 | ␉{ .text = "Help" }␊ |
315 | };␊ |
316 | ␊ |
317 | int infoMenuSelection = 0;␊ |
318 | int infoMenuItemsCount = sizeof(infoMenuItems)/sizeof(infoMenuItems[0]);␊ |
319 | ␊ |
320 | bool infoMenuNativeBoot = false;␊ |
321 | ␊ |
322 | unsigned long screen_params[4] = {DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 32, 0};␉// here we store the used screen resolution␊ |
323 | ␊ |
324 | static void moveCursor( int col, int row )␊ |
325 | {␊ |
326 | setCursorPosition( col, row, 0 );␊ |
327 | }␊ |
328 | ␊ |
329 | /*␊ |
330 | *␊ |
331 | */␊ |
332 | ␊ |
333 | static bool GUI_getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size )␊ |
334 | {␊ |
335 | ␉const char *val;␊ |
336 | ␉␊ |
337 | int size = 0;␊ |
338 | ␉int sum = 0;␊ |
339 | ␊ |
340 | ␉bool negative = false;␊ |
341 | ␉bool percentage = false;␊ |
342 | ␊ |
343 | config = resolveConfig(config);␊ |
344 | ␉␊ |
345 | if (getValueForKey(key, &val, &size, config))␊ |
346 | ␉{␊ |
347 | ␉␉if ( size )␊ |
348 | ␉␉{␊ |
349 | ␉␉␉if (*val == '-')␊ |
350 | ␉␉␉{␊ |
351 | ␉␉␉␉negative = true;␊ |
352 | ␉␉␉␉val++;␊ |
353 | ␉␉␉␉size--;␊ |
354 | ␉␉␉}␊ |
355 | ␉␉␉␊ |
356 | ␉␉␉if (val[size-1] == '%')␊ |
357 | ␉␉␉{␊ |
358 | ␉␉␉␉percentage = true;␊ |
359 | ␉␉␉␉size--;␊ |
360 | ␉␉␉}␊ |
361 | ␉␉␉␊ |
362 | ␉␉␉// convert string to integer␊ |
363 | ␉␉␉for (sum = 0; size > 0; size--)␊ |
364 | ␉␉␉{␊ |
365 | ␉␉␉␉if (*val < '0' || *val > '9')␊ |
366 | ␉␉␉␉␉return false;␊ |
367 | ␉␉␉␉␊ |
368 | ␉␉␉␉sum = (sum * 10) + (*val++ - '0');␊ |
369 | ␉␉␉}␊ |
370 | ␉␉␉␊ |
371 | ␉␉␉if (percentage)␊ |
372 | ␉␉␉␉sum = ( dimension_max * sum ) / 100;␊ |
373 | ␉␉␉␊ |
374 | ␉␉␉// calculate offset from opposite origin␊ |
375 | ␉␉␉if (negative)␊ |
376 | ␉␉␉␉sum = ( ( dimension_max - object_size ) - sum );␊ |
377 | ␉␉␉␊ |
378 | ␉␉} else {␊ |
379 | ␉␉␉␊ |
380 | ␉␉␉// null value calculate center␊ |
381 | ␉␉␉sum = ( dimension_max - object_size ) / 2;␊ |
382 | ␉␉␉␊ |
383 | ␉␉}␊ |
384 | ␉␉␊ |
385 | ␉␉*value = (uint16_t) sum;␊ |
386 | ␉␉return true;␊ |
387 | ␉}␊ |
388 | ␉␊ |
389 | ␉// key not found␊ |
390 | return false;␊ |
391 | }␊ |
392 | ␊ |
393 | static bool GUI_getColorForKey( const char *key, unsigned int *value, config_file_t *config )␊ |
394 | {␊ |
395 | const char *val;␊ |
396 | int size;␊ |
397 | ␊ |
398 | config = resolveConfig(config);␊ |
399 | ␊ |
400 | if (getValueForKey(key, &val, &size, config))␊ |
401 | ␉{␊ |
402 | ␉␉if (*val == '#')␊ |
403 | ␉␉{␊ |
404 | val++;␊ |
405 | ␉␉␉*value = strtol(val, NULL, 16);␊ |
406 | ␉␉␉return true;␊ |
407 | }␊ |
408 | }␊ |
409 | return false;␊ |
410 | }␊ |
411 | //==========================================================================␊ |
412 | ␊ |
413 | /* Flush keyboard buffer; returns TRUE if any of the flushed␊ |
414 | * characters was F8.␊ |
415 | */␊ |
416 | ␊ |
417 | static bool flushKeyboardBuffer(void)␊ |
418 | {␊ |
419 | bool status = false;␊ |
420 | ␉␊ |
421 | while ( readKeyboardStatus() ) {␊ |
422 | if (bgetc() == 0x4200) status = true;␊ |
423 | }␊ |
424 | return status;␊ |
425 | }␊ |
426 | ␊ |
427 | static int getImageIndexByName(const char *name)␊ |
428 | {␊ |
429 | int i;␊ |
430 | ␉for (i = 0; (unsigned)i < sizeof(images) / sizeof(images[0]); i++)␊ |
431 | ␉{␊ |
432 | ␉ if (strncmp(name, images[i].name, sizeof(images[i].name)) == 0)␊ |
433 | ␉ return i; // found the name␊ |
434 | ␉}␊ |
435 | ␉return -1;␊ |
436 | }␊ |
437 | ␊ |
438 | #ifdef EMBED_THEME␊ |
439 | static int getEmbeddedImageIndexByName(const char *name)␊ |
440 | {␊ |
441 | ␉int upperLimit = sizeof(embeddedImages) / sizeof(embeddedImages[0]) - 1;␊ |
442 | ␉int lowerLimit = 0;␊ |
443 | ␉int compareIndex = (upperLimit - lowerLimit) >> 1; // Midpoint␊ |
444 | ␉int result;␊ |
445 | ␉␊ |
446 | ␉// NOTE: This algorithm assumes that the embeddedImages is sorted.␊ |
447 | ␉// This is currently done using the make file. If the array is every ␊ |
448 | ␉// manualy generated, this *will* fail to work properly.␊ |
449 | ␉while((result = strncmp(name, embeddedImages[compareIndex].name, sizeof(embeddedImages[compareIndex].name))) != 0)␊ |
450 | ␉{␊ |
451 | ␉␉if(result > 0)␉// We need to search a HIGHER index␊ |
452 | ␉␉{␊ |
453 | ␉␉␉if(compareIndex != lowerLimit)␊ |
454 | ␉␉␉{␊ |
455 | ␉␉␉␉lowerLimit = compareIndex;␊ |
456 | ␉␉␉}␊ |
457 | ␉␉␉else␊ |
458 | ␉␉␉{␊ |
459 | ␉␉␉␉return -1;␊ |
460 | ␉␉␉}␊ |
461 | ␉␉␉compareIndex = (upperLimit + lowerLimit + 1) >> 1;␉// Midpoint, round up␊ |
462 | ␉␉}␊ |
463 | ␉␉else // We Need to search a LOWER index␊ |
464 | ␉␉{␊ |
465 | ␉␉␉if(compareIndex != upperLimit)␊ |
466 | ␉␉␉{␊ |
467 | ␉␉␉␉upperLimit = compareIndex;␊ |
468 | ␉␉␉}␊ |
469 | ␉␉␉else␊ |
470 | ␉␉␉{␊ |
471 | ␉␉␉␉return -1;␊ |
472 | ␉␉␉}␊ |
473 | ␉␉␉compareIndex = (upperLimit + lowerLimit) >> 1;␉// Midpoint, round down␊ |
474 | ␉␉}␊ |
475 | ␉}␊ |
476 | ␉return compareIndex;␊ |
477 | }␊ |
478 | #endif␊ |
479 | ␊ |
480 | static int loadThemeImage(char* src, const char *image, int alt_image)␊ |
481 | {␊ |
482 | ␉char␉␉dirspec[256];␊ |
483 | ␉int ␉␉i;␊ |
484 | #ifdef EMBED_THEME␊ |
485 | ␉int ␉␉e;␊ |
486 | #endif␊ |
487 | ␉uint16_t␉width;␊ |
488 | ␉uint16_t␉height;␊ |
489 | ␉uint8_t␉␉*imagedata;␊ |
490 | ␉if ((unsigned)(strlen(image) + strlen(theme_name) + strlen(src) + (6+1) ) > sizeof(dirspec)) {␊ |
491 | ␉␉␊ |
492 | ␉␉DBG("Path of %s/%s/%s.png to long\n", src, theme_name, image);␊ |
493 | ␉␉␊ |
494 | ␉␉return 1;␊ |
495 | ␉}␊ |
496 | ␉␊ |
497 | if ((i = getImageIndexByName(image)) >= 0)␊ |
498 | { ␊ |
499 | ␉␉if (images[i].image == NULL) {␊ |
500 | ␉␉␉images[i].image = malloc(sizeof(pixmap_t));␊ |
501 | ␉␉␉if (images[i].image == NULL) {␊ |
502 | ␉␉␉␉␊ |
503 | ␉␉␉␉DBG("Unable to allocate memory for %s.png\n", image);␊ |
504 | ␉␉␉␉␊ |
505 | ␉␉␉␉return 1;␊ |
506 | ␉␉␉}␊ |
507 | ␉␉}␊ |
508 | snprintf(dirspec, sizeof(dirspec),"%s/%s/%s.png", src, theme_name, image);␊ |
509 | ␉␉␊ |
510 | width = 0;␊ |
511 | height = 0;␊ |
512 | imagedata = NULL;␊ |
513 | if ((strlen(theme_name) > 0) && (loadPngImage(dirspec, &width, &height, &imagedata) != -1 ))␊ |
514 | {␊ |
515 | images[i].image->width = width;␊ |
516 | images[i].image->height = height;␊ |
517 | images[i].image->pixels = (pixel_t *)imagedata;␊ |
518 | flipRB(images[i].image);␊ |
519 | ␉␉␉␊ |
520 | ␉␉␉DBG("[ %s ] succesfully loaded and registred !!\n", dirspec);␊ |
521 | ␉␉␉DBG("width = %d : height = %d !!\n",images[i].image->width,images[i].image->height);␊ |
522 | ␉␉␉␊ |
523 | return 0;␊ |
524 | }␊ |
525 | #ifdef EMBED_THEME␊ |
526 | else if ((e = getEmbeddedImageIndexByName(image)) >= 0)␊ |
527 | {␊ |
528 | unsigned char *embed_data;␊ |
529 | unsigned int embed_size;␊ |
530 | embed_data = embeddedImages[e].pngdata;␊ |
531 | embed_size = *embeddedImages[e].length;␊ |
532 | ␉␉␉␊ |
533 | if (loadEmbeddedPngImage(embed_data, embed_size, &width, &height, &imagedata) != -1)␊ |
534 | {␊ |
535 | images[i].image->width = width;␊ |
536 | images[i].image->height = height;␊ |
537 | images[i].image->pixels = (pixel_t *)imagedata;␊ |
538 | flipRB(images[i].image);␊ |
539 | return 0;␊ |
540 | }␊ |
541 | ␉␉␉␊ |
542 | return 0;␊ |
543 | }␊ |
544 | #endif␊ |
545 | else if (alt_image != IMG_REQUIRED)␊ |
546 | {␊ |
547 | ␉␉␉if (images[alt_image].image->pixels != NULL) {␊ |
548 | ␉␉␉␉␊ |
549 | ␉␉␉␉// Using the passed alternate image for non-mandatory images.␊ |
550 | ␉␉␉␉// We don't clone the already existing pixmap, but using its properties instead!␊ |
551 | ␉␉␉␉images[i].image->width = images[alt_image].image->width;␊ |
552 | ␉␉␉␉images[i].image->height = images[alt_image].image->height;␊ |
553 | ␉␉␉␉images[i].image->pixels = images[alt_image].image->pixels;␊ |
554 | ␉␉␉␉␊ |
555 | ␉␉␉␉DBG("Passing to alt_image !!\n");␊ |
556 | ␉␉␉␉DBG("width = %d : height = %d !!\n",images[alt_image].image->width,images[alt_image].image->height);␊ |
557 | ␉␉␉␉␊ |
558 | ␉␉␉} else {␊ |
559 | ␉␉␉␉␊ |
560 | ␉␉␉␉DBG("Unable to load %s, this image not vital anyway, reseting and returning success !!\n", dirspec);␊ |
561 | ␉␉␉␉␊ |
562 | ␉␉␉␉free(images[i].image);␊ |
563 | ␉␉␉␉images[i].image = NULL;␊ |
564 | ␉␉␉} ␊ |
565 | ␉␉␉␊ |
566 | return 0;␊ |
567 | }␊ |
568 | else␊ |
569 | {␊ |
570 | #if DEBUG_GUI␊ |
571 | printf("ERROR: GUI: could not open '%s/%s.png'!\n", theme_name, image);␊ |
572 | ␉␉␉sleep(2);␊ |
573 | #else␊ |
574 | #ifndef CONFIG_EMBED_THEME␊ |
575 | printf("ERROR: GUI: could not open '%s/%s.png'!\n", theme_name, image);␊ |
576 | ␉␉␉sleep(2);␊ |
577 | #endif␊ |
578 | #endif␊ |
579 | ␉␉␉free(images[i].image);␊ |
580 | ␉␉␉images[i].image = NULL;␊ |
581 | ␉␉␉return 1;␊ |
582 | ␉␉␉␊ |
583 | }␊ |
584 | ␉␉␊ |
585 | }␊ |
586 | ␉␊ |
587 | #if DEBUG_GUI␊ |
588 | ␉printf("[ %s/%s/%s.png ] not used in this version, skipped !!\n",src, theme_name, image);␊ |
589 | ␉sleep(2);␊ |
590 | #endif␊ |
591 | ␉return 0;␊ |
592 | }␊ |
593 | ␊ |
594 | static int loadGraphics(char *src)␊ |
595 | {␊ |
596 | ␉DBG("Loading image into memory....\n",theme_name);␊ |
597 | ␉␊ |
598 | ␉LOADPNG(src, background, IMG_REQUIRED);␊ |
599 | ␉␊ |
600 | ␉LOADPNG(src, logo, IMG_REQUIRED);␊ |
601 | ␉␊ |
602 | ␉LOADPNG(src, device_generic, IMG_REQUIRED);␊ |
603 | ␉LOADPNG(src, device_generic_o, iDeviceGeneric);␊ |
604 | ␉␊ |
605 | ␉LOADPNG(src, device_hfsplus, iDeviceGeneric);␊ |
606 | ␉LOADPNG(src, device_hfsplus_o, iDeviceHFS);␊ |
607 | LOADPNG(src, device_hfsplus_ml, iDeviceHFS_ML);␊ |
608 | LOADPNG(src, device_hfsplus_ml_o, iDeviceHFS_ML_o);␊ |
609 | ␉LOADPNG(src, device_hfsplus_lion, iDeviceHFS_Lion);␊ |
610 | ␉LOADPNG(src, device_hfsplus_lion_o, iDeviceHFS_Lion_o);␊ |
611 | ␉LOADPNG(src, device_hfsplus_sl, iDeviceHFS_SL);␊ |
612 | ␉LOADPNG(src, device_hfsplus_sl_o, iDeviceHFS_SL_o);␊ |
613 | ␉LOADPNG(src, device_hfsplus_leo, iDeviceHFS_Leo);␊ |
614 | ␉LOADPNG(src, device_hfsplus_leo_o, iDeviceHFS_Leo_o);␊ |
615 | ␉LOADPNG(src, device_hfsplus_tiger, iDeviceHFS_Tiger);␊ |
616 | ␉LOADPNG(src, device_hfsplus_tiger_o, iDeviceHFS_Tiger_o);␊ |
617 | ␉␊ |
618 | ␉LOADPNG(src, device_hfsraid, iDeviceGeneric);␊ |
619 | ␉LOADPNG(src, device_hfsraid_o, iDeviceHFSRAID);␊ |
620 | LOADPNG(src, device_hfsraid_ml, iDeviceHFSRAID_ML);␊ |
621 | LOADPNG(src, device_hfsraid_ml_o, iDeviceHFSRAID_ML_o);␊ |
622 | ␉LOADPNG(src, device_hfsraid_lion, iDeviceHFSRAID_Lion);␊ |
623 | ␉LOADPNG(src, device_hfsraid_lion_o, iDeviceHFSRAID_Lion_o);␊ |
624 | ␉LOADPNG(src, device_hfsraid_sl, iDeviceHFSRAID_SL);␊ |
625 | ␉LOADPNG(src, device_hfsraid_sl_o, iDeviceHFSRAID_SL_o);␊ |
626 | ␉LOADPNG(src, device_hfsraid_leo, iDeviceHFSRAID_Leo);␊ |
627 | ␉LOADPNG(src, device_hfsraid_leo_o, iDeviceHFSRAID_Leo_o);␊ |
628 | ␉LOADPNG(src, device_hfsraid_tiger, iDeviceHFSRAID_Tiger);␊ |
629 | ␉LOADPNG(src, device_hfsraid_tiger_o, iDeviceHFSRAID_Tiger_o);␊ |
630 | ␉␊ |
631 | ␉LOADPNG(src, device_ext3, iDeviceGeneric);␊ |
632 | ␉LOADPNG(src, device_ext3_o, iDeviceEXT3);␊ |
633 | ␉LOADPNG(src, device_freebsd, iDeviceGeneric);␊ |
634 | ␉LOADPNG(src, device_freebsd_o, iDeviceFreeBSD);␊ |
635 | ␉LOADPNG(src, device_openbsd, iDeviceGeneric);␊ |
636 | ␉LOADPNG(src, device_openbsd_o, iDeviceOpenBSD);␊ |
637 | ␉LOADPNG(src, device_befs,␉␉␉␉␉ iDeviceGeneric); /* Haiku detection and Icon credits to scorpius */␊ |
638 | ␉LOADPNG(src, device_befs_o,␉␉␉␉␉ iDeviceBEFS); /* Haiku detection and Icon credits to scorpius */␊ |
639 | ␉LOADPNG(src, device_fat, iDeviceGeneric);␊ |
640 | ␉LOADPNG(src, device_fat_o, iDeviceFAT);␊ |
641 | ␉LOADPNG(src, device_fat16, iDeviceFAT);␊ |
642 | ␉LOADPNG(src, device_fat16_o, iDeviceFAT_o);␊ |
643 | ␉LOADPNG(src, device_fat32, iDeviceFAT);␊ |
644 | ␉LOADPNG(src, device_fat32_o, iDeviceFAT_o);␊ |
645 | ␉LOADPNG(src, device_ntfs, iDeviceGeneric);␊ |
646 | ␉LOADPNG(src, device_ntfs_o, iDeviceNTFS);␊ |
647 | ␉LOADPNG(src, device_cdrom, iDeviceGeneric);␊ |
648 | ␉LOADPNG(src, device_cdrom_o, iDeviceCDROM);␊ |
649 | ␉␊ |
650 | ␉LOADPNG(src, device_selection, IMG_REQUIRED);␊ |
651 | ␉LOADPNG(src, device_scroll_prev, IMG_REQUIRED);␊ |
652 | ␉LOADPNG(src, device_scroll_next, IMG_REQUIRED);␊ |
653 | ␉␊ |
654 | ␉LOADPNG(src, menu_boot, IMG_REQUIRED);␊ |
655 | ␉LOADPNG(src, menu_verbose, IMG_REQUIRED);␊ |
656 | ␉LOADPNG(src, menu_ignore_caches, IMG_REQUIRED);␊ |
657 | ␉LOADPNG(src, menu_single_user, IMG_REQUIRED);␊ |
658 | ␉LOADPNG(src, menu_memory_info, IMG_REQUIRED);␊ |
659 | ␉LOADPNG(src, menu_video_info, IMG_REQUIRED);␊ |
660 | ␉LOADPNG(src, menu_help, IMG_REQUIRED);␊ |
661 | ␉LOADPNG(src, menu_verbose_disabled, IMG_REQUIRED);␊ |
662 | ␉LOADPNG(src, menu_ignore_caches_disabled, IMG_REQUIRED);␊ |
663 | ␉LOADPNG(src, menu_single_user_disabled, IMG_REQUIRED);␊ |
664 | ␉LOADPNG(src, menu_selection, IMG_REQUIRED);␊ |
665 | ␉␊ |
666 | ␉LOADPNG(src, progress_bar, IMG_REQUIRED);␊ |
667 | ␉LOADPNG(src, progress_bar_background, IMG_REQUIRED);␊ |
668 | ␉␊ |
669 | ␉LOADPNG(src, text_scroll_prev, IMG_REQUIRED);␊ |
670 | ␉LOADPNG(src, text_scroll_next, IMG_REQUIRED);␊ |
671 | ␉␊ |
672 | ␉LOADPNG(src, font_console, IMG_REQUIRED);␊ |
673 | ␉LOADPNG(src, font_small, IMG_REQUIRED);␊ |
674 | ␉␊ |
675 | ␉DBG("Initializing font....\n",theme_name);␊ |
676 | ␉␊ |
677 | ␉initFont( &font_console, &images[iFontConsole]);␊ |
678 | ␉initFont( &font_small, &images[iFontSmall]);␊ |
679 | ␉␊ |
680 | ␉DBG("Graphic objects successfully loaded !!\n",theme_name);␊ |
681 | ␉␊ |
682 | ␉return 0;␊ |
683 | }␊ |
684 | ␊ |
685 | static int unloadGraphics(void)␊ |
686 | {␊ |
687 | int i;␊ |
688 | ␉␊ |
689 | destroyFont(&font_console);␊ |
690 | destroyFont(&font_small);␊ |
691 | ␉for (i = 0; i < sizeof(images) / sizeof(images[0]); i++)␊ |
692 | ␉{␊ |
693 | ␉ if (images[i].image)␊ |
694 | ␉ {␊ |
695 | ␉ ␉if (images[i].image->pixels) free(images[i].image->pixels);␊ |
696 | ␉ ␉free (images[i].image);␊ |
697 | ␉ ␉images[i].image = 0;␊ |
698 | ␉ }␊ |
699 | ␉}␊ |
700 | ␉return 0;␊ |
701 | }␊ |
702 | ␊ |
703 | static int freeBackBuffer( window_t *window )␊ |
704 | {␊ |
705 | ␉if (gui.backbuffer && gui.backbuffer->pixels)␊ |
706 | {␊ |
707 | ␉␉free(gui.backbuffer->pixels);␊ |
708 | ␉␉free(gui.backbuffer);␊ |
709 | ␉␉gui.backbuffer = 0;␊ |
710 | ␉␉return 0;␊ |
711 | ␉}␊ |
712 | ␊ |
713 | ␉return 1;␊ |
714 | }␊ |
715 | ␊ |
716 | #if UNUSED␊ |
717 | pixmap_t *getCroppedPixmapAtPosition( pixmap_t *from, position_t pos, uint16_t width, uint16_t height )␊ |
718 | {␊ |
719 | ␉␊ |
720 | ␉pixmap_t *cropped = malloc( sizeof( pixmap_t ) );␊ |
721 | ␉if( !cropped )␊ |
722 | ␉␉return 0;␊ |
723 | ␉cropped->pixels = malloc( width * height * 4 );␊ |
724 | ␉if ( !cropped->pixels )␊ |
725 | ␉␉return 0;␊ |
726 | ␉␊ |
727 | ␉cropped->width = width;␊ |
728 | ␉cropped->height = height;␊ |
729 | ␉␊ |
730 | ␉int destx = 0, desty = 0;␊ |
731 | ␉int srcx = pos.x, srcy = pos.y;␊ |
732 | ␉␊ |
733 | ␉for( ; desty < height; desty++, srcy++)␊ |
734 | ␉{␊ |
735 | ␉␉for( destx = 0, srcx = pos.x; destx < width; destx++, srcx++ )␊ |
736 | ␉␉{␊ |
737 | ␉␉␉pixel( cropped, destx, desty ).value = pixel( from, srcx, srcy ).value;␊ |
738 | ␉␉}␊ |
739 | ␉}␊ |
740 | ␉return cropped;␊ |
741 | }␊ |
742 | #endif␊ |
743 | ␊ |
744 | static int createBackBuffer( window_t *window )␊ |
745 | {␊ |
746 | ␉gui.backbuffer = malloc(sizeof(pixmap_t));␊ |
747 | ␉if(!gui.backbuffer)␊ |
748 | ␉{␊ |
749 | ␉␉DBG("Unable to allocate memory for gui.backbuffer");␊ |
750 | ␉␉return 1;␊ |
751 | ␉}␊ |
752 | ␉␊ |
753 | ␉gui.backbuffer->pixels = malloc( window->width * window->height * 4 );␊ |
754 | ␉if(!gui.backbuffer->pixels)␊ |
755 | ␉{␊ |
756 | ␉␉free(gui.backbuffer);␊ |
757 | ␉␉gui.backbuffer = 0;␊ |
758 | ␉␉DBG("Unable to allocate memory for gui.backbuffer->pixels");␊ |
759 | ␉␉return 1;␊ |
760 | ␉}␊ |
761 | ␉␊ |
762 | ␉gui.backbuffer->width = gui.screen.width;␊ |
763 | ␉gui.backbuffer->height = gui.screen.height;␊ |
764 | ␉␊ |
765 | ␉return 0;␊ |
766 | }␊ |
767 | ␊ |
768 | static int createWindowBuffer( window_t *window )␊ |
769 | {␊ |
770 | ␉window->pixmap = malloc(sizeof(pixmap_t));␊ |
771 | ␉if(!window->pixmap)␊ |
772 | ␉{␊ |
773 | ␉␉DBG("Unable to allocate memory for window->pixmap");␊ |
774 | ␉␉return 1;␊ |
775 | ␉}␊ |
776 | ␉␊ |
777 | ␉window->pixmap->pixels = malloc( window->width * window->height * 4 );␊ |
778 | ␉if(!window->pixmap->pixels)␊ |
779 | ␉{␊ |
780 | ␉␉free(window->pixmap);␊ |
781 | ␉␉window->pixmap = 0;␊ |
782 | ␉␉DBG("Unable to allocate memory for window->pixmap->pixels");␊ |
783 | ␉␉return 1;␊ |
784 | ␉}␊ |
785 | ␉␊ |
786 | ␉window->pixmap->width = window->width;␊ |
787 | ␉window->pixmap->height = window->height;␊ |
788 | ␉␊ |
789 | ␉return 0;␊ |
790 | }␊ |
791 | ␊ |
792 | static int freeWindowBuffer( window_t *window )␊ |
793 | {␊ |
794 | ␉if (window->pixmap && window->pixmap->pixels)␊ |
795 | {␊ |
796 | ␉␉free(window->pixmap->pixels);␊ |
797 | ␉␉free(window->pixmap);␊ |
798 | ␉␉return 0;␊ |
799 | ␉}␊ |
800 | ␉␊ |
801 | ␉return 1;␊ |
802 | }␊ |
803 | ␊ |
804 | static void fillPixmapWithColor(pixmap_t *pm, uint32_t color)␊ |
805 | {␊ |
806 | ␉int x,y;␊ |
807 | ␉␊ |
808 | ␉// fill with given color AARRGGBB␊ |
809 | ␉for( x=0; x < pm->width; x++ )␊ |
810 | ␉␉for( y=0; y< pm->height; y++)␊ |
811 | ␉␉␉pixel(pm,x,y).value = color;␊ |
812 | }␊ |
813 | ␊ |
814 | void drawBackground()␊ |
815 | {␊ |
816 | ␉// reset text cursor␊ |
817 | ␉gui.screen.cursor.x = gui.screen.hborder;␊ |
818 | ␉gui.screen.cursor.y = gui.screen.vborder;␊ |
819 | ␉␊ |
820 | ␉fillPixmapWithColor( gui.screen.pixmap, gui.screen.bgcolor);␊ |
821 | ␉␊ |
822 | ␉// draw background.png into background buffer␊ |
823 | ␉blend( images[iBackground].image, gui.screen.pixmap, gui.background.pos );␊ |
824 | ␉␊ |
825 | ␉// draw logo.png into background buffer␊ |
826 | ␉if (gui.logo.draw)␊ |
827 | ␉{␊ |
828 | ␉blend( images[iLogo].image, gui.screen.pixmap, gui.logo.pos);␊ |
829 | ␉}␊ |
830 | ␉␊ |
831 | ␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
832 | }␊ |
833 | ␊ |
834 | static void setupDeviceList(config_file_t *theme)␊ |
835 | {␊ |
836 | ␉unsigned int pixel;␊ |
837 | ␉int␉alpha;␉␉␉␉// transparency level 0 (obligue) - 255 (transparent)␊ |
838 | ␉uint32_t color;␉␉␉// color value formatted RRGGBB␊ |
839 | ␉int val, len;␊ |
840 | ␉const char *string;␉␊ |
841 | int devcnt = (int)get_env(envgDeviceCount);␊ |
842 | ␊ |
843 | ␉if(getIntForKey("devices_max_visible", &val, theme ))␊ |
844 | ␉␉gui.maxdevices = MIN( val, devcnt );␊ |
845 | ␉␊ |
846 | ␉if(getIntForKey("devices_iconspacing", &val, theme ))␊ |
847 | ␉␉gui.devicelist.iconspacing = val;␊ |
848 | ␉␊ |
849 | ␉// check layout for horizontal or vertical␊ |
850 | ␉gui.layout = HorizontalLayout;␊ |
851 | ␉if(getValueForKey( "devices_layout", &string, &len, theme)) {␊ |
852 | ␉␉if (!strncmp (string, "vertical",sizeof("vertical"))) {␊ |
853 | ␉␉␉gui.layout = VerticalLayout;␊ |
854 | ␉␉}␊ |
855 | ␉}␊ |
856 | ␉␊ |
857 | ␉switch (gui.layout) {␊ |
858 | ␉␉case VerticalLayout:␊ |
859 | ␉␉␉gui.devicelist.height = ((images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing) * MIN(gui.maxdevices, devcnt) + (images[iDeviceScrollPrev].image->height + images[iDeviceScrollNext].image->height) + gui.devicelist.iconspacing);␊ |
860 | ␉␉␉gui.devicelist.width = (images[iSelection].image->width + gui.devicelist.iconspacing);␊ |
861 | ␉␉␉␊ |
862 | ␉␉␉if(GUI_getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , images[iSelection].image->width ) )␊ |
863 | ␉␉␉␉gui.devicelist.pos.x = pixel;␊ |
864 | ␉␉␉␊ |
865 | ␉␉␉if(GUI_getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , gui.devicelist.height ) )␊ |
866 | ␉␉␉␉gui.devicelist.pos.y = pixel;␊ |
867 | ␉␉␉break;␊ |
868 | ␉␉␉␊ |
869 | ␉␉case HorizontalLayout:␊ |
870 | ␉␉default:␊ |
871 | ␉␉␉gui.devicelist.width = ((images[iSelection].image->width + gui.devicelist.iconspacing) * MIN(gui.maxdevices, devcnt) + (images[iDeviceScrollPrev].image->width + images[iDeviceScrollNext].image->width) + gui.devicelist.iconspacing);␊ |
872 | ␉␉␉gui.devicelist.height = (images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing);␊ |
873 | ␉␉␉␊ |
874 | ␉␉␉if(GUI_getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , gui.devicelist.width ) )␊ |
875 | ␉␉␉␉gui.devicelist.pos.x = pixel;␊ |
876 | ␉␉␉else␊ |
877 | ␉␉␉␉gui.devicelist.pos.x = ( gui.screen.width - gui.devicelist.width ) / 2;␊ |
878 | ␉␉␉␊ |
879 | ␉␉␉if(GUI_getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , images[iSelection].image->height ) )␊ |
880 | ␉␉␉␉gui.devicelist.pos.y = pixel;␊ |
881 | ␉␉␉else␊ |
882 | ␉␉␉␉gui.devicelist.pos.y = ( gui.screen.height - gui.devicelist.height ) / 2;␊ |
883 | ␉␉␉break;␊ |
884 | ␉}␊ |
885 | ␉␊ |
886 | ␉if(GUI_getColorForKey("devices_bgcolor", &color, theme))␊ |
887 | ␉␉gui.devicelist.bgcolor = (color & 0x00FFFFFF);␊ |
888 | ␉␊ |
889 | ␉if(getIntForKey("devices_transparency", &alpha, theme))␊ |
890 | ␉␉gui.devicelist.bgcolor = gui.devicelist.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␊ |
891 | ␉␊ |
892 | ␉if (gui.devicelist.pixmap)␊ |
893 | ␉{␊ |
894 | ␉ freeWindowBuffer(&gui.devicelist);␊ |
895 | createWindowBuffer(&gui.devicelist);␊ |
896 | }␊ |
897 | }␊ |
898 | ␊ |
899 | static void loadThemeValues(config_file_t *theme)␊ |
900 | {␊ |
901 | ␉unsigned int screen_width = gui.screen.width;␊ |
902 | ␉unsigned int screen_height = gui.screen.height;␊ |
903 | ␉unsigned int pixel;␊ |
904 | ␉int␉alpha;␉␉␉␉// transparency level 0 (obligue) - 255 (transparent)␊ |
905 | ␉uint32_t color;␉␉␉// color value formatted RRGGBB␊ |
906 | ␉int val;␊ |
907 | ␉␊ |
908 | ␉/*␊ |
909 | ␉ * Parse screen parameters␊ |
910 | ␉ */␊ |
911 | ␉if(GUI_getColorForKey("screen_bgcolor", &color, theme ))␊ |
912 | ␉␉gui.screen.bgcolor = (color & 0x00FFFFFF);␊ |
913 | ␉␊ |
914 | ␉if(getIntForKey("screen_textmargin_h", &val, theme))␊ |
915 | ␉␉gui.screen.hborder = MIN( gui.screen.width , val );␊ |
916 | ␉␊ |
917 | ␉if(getIntForKey("screen_textmargin_v", &val, theme))␊ |
918 | ␉␉gui.screen.vborder = MIN( gui.screen.height , val );␊ |
919 | ␉␊ |
920 | ␉/*␊ |
921 | ␉ * Parse background parameters␊ |
922 | ␉ */␊ |
923 | ␉if(GUI_getDimensionForKey("background_pos_x", &pixel, theme, screen_width , images[iBackground].image->width ) )␊ |
924 | ␉␉gui.background.pos.x = pixel;␊ |
925 | ␉␊ |
926 | ␉if(GUI_getDimensionForKey("background_pos_y", &pixel, theme, screen_height , images[iBackground].image->height ) )␊ |
927 | ␉␉gui.background.pos.y = pixel;␊ |
928 | ␉␊ |
929 | ␉/*␊ |
930 | ␉ * Parse logo parameters␊ |
931 | ␉ */␊ |
932 | ␉if(GUI_getDimensionForKey("logo_pos_x", &pixel, theme, screen_width , images[iLogo].image->width ) )␊ |
933 | ␉␉gui.logo.pos.x = pixel;␊ |
934 | ␉␊ |
935 | ␉if(GUI_getDimensionForKey("logo_pos_y", &pixel, theme, screen_height , images[iLogo].image->height ) )␊ |
936 | ␉␉gui.logo.pos.y = pixel;␊ |
937 | ␉␊ |
938 | ␉/*␊ |
939 | ␉ * Parse progress bar parameters␊ |
940 | ␉ */␊ |
941 | ␉if(GUI_getDimensionForKey("progressbar_pos_x", &pixel, theme, screen_width , 0 ) )␊ |
942 | ␉␉gui.progressbar.pos.x = pixel;␊ |
943 | ␉␊ |
944 | ␉if(GUI_getDimensionForKey("progressbar_pos_y", &pixel, theme, screen_height , 0 ) )␊ |
945 | ␉␉gui.progressbar.pos.y = pixel;␊ |
946 | ␉␊ |
947 | ␉/*␊ |
948 | ␉ * Parse countdown text parameters␊ |
949 | ␉ */␊ |
950 | ␉if(GUI_getDimensionForKey("countdown_pos_x", &pixel, theme, screen_width , 0 ) )␊ |
951 | ␉␉gui.countdown.pos.x = pixel;␊ |
952 | ␉␊ |
953 | ␉if(GUI_getDimensionForKey("countdown_pos_y", &pixel, theme, screen_height , 0 ) )␊ |
954 | ␉␉gui.countdown.pos.y = pixel;␊ |
955 | ␉␊ |
956 | /*␊ |
957 | ␉ * Parse devicelist parameters␊ |
958 | ␉ */␊ |
959 | ␉setupDeviceList(theme);␊ |
960 | ␉␊ |
961 | ␉/*␊ |
962 | ␉ * Parse infobox parameters␊ |
963 | ␉ */␊ |
964 | ␉if(getIntForKey("infobox_width", &val, theme) && val >= 0)␊ |
965 | ␉␉gui.infobox.width = MIN( screen_width ,(unsigned) val );␊ |
966 | ␉␊ |
967 | ␉if(getIntForKey("infobox_height", &val, theme) && val >= 0)␊ |
968 | ␉␉gui.infobox.height = MIN( screen_height , (unsigned)val );␊ |
969 | ␉␊ |
970 | ␉if(GUI_getDimensionForKey("infobox_pos_x", &pixel, theme, screen_width , gui.infobox.width ) )␊ |
971 | ␉␉gui.infobox.pos.x = pixel;␊ |
972 | ␉␊ |
973 | ␉if(GUI_getDimensionForKey("infobox_pos_y", &pixel, theme, screen_height , gui.infobox.height ) )␊ |
974 | ␉␉gui.infobox.pos.y = pixel;␊ |
975 | ␉␊ |
976 | ␉if(getIntForKey("infobox_textmargin_h", &val, theme))␊ |
977 | ␉␉gui.infobox.hborder = MIN( gui.infobox.width , val );␊ |
978 | ␉␊ |
979 | ␉if(getIntForKey("infobox_textmargin_v", &val, theme))␊ |
980 | ␉␉gui.infobox.vborder = MIN( gui.infobox.height , val );␊ |
981 | ␉␊ |
982 | ␉if(GUI_getColorForKey("infobox_bgcolor", &color, theme))␊ |
983 | ␉␉gui.infobox.bgcolor = (color & 0x00FFFFFF);␊ |
984 | ␉␊ |
985 | ␉if(getIntForKey("infobox_transparency", &alpha, theme))␊ |
986 | ␉␉gui.infobox.bgcolor = gui.infobox.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␊ |
987 | ␉␊ |
988 | ␉/*␊ |
989 | ␉ * Parse menu parameters␊ |
990 | ␉ */␊ |
991 | ␉if(GUI_getDimensionForKey("menu_width", &pixel, theme, gui.screen.width , 0 ) )␊ |
992 | ␉␉gui.menu.width = pixel;␊ |
993 | ␉else␊ |
994 | ␉␉gui.menu.width = images[iMenuSelection].image->width;␊ |
995 | ␉␊ |
996 | ␉if(GUI_getDimensionForKey("menu_height", &pixel, theme, gui.screen.height , 0 ) )␊ |
997 | ␉␉gui.menu.height = pixel;␊ |
998 | ␉else␊ |
999 | ␉␉gui.menu.height = infoMenuItemsCount * images[iMenuSelection].image->height;␊ |
1000 | ␉␊ |
1001 | ␉if(GUI_getDimensionForKey("menu_pos_x", &pixel, theme, screen_width , gui.menu.width ) )␊ |
1002 | ␉␉gui.menu.pos.x = pixel;␊ |
1003 | ␉␊ |
1004 | ␉if(GUI_getDimensionForKey("menu_pos_y", &pixel, theme, screen_height , gui.menu.height ) )␊ |
1005 | ␉␉gui.menu.pos.y = pixel;␊ |
1006 | ␉␊ |
1007 | ␉if(getIntForKey("menu_textmargin_h", &val, theme))␊ |
1008 | ␉␉gui.menu.hborder = MIN( gui.menu.width , val );␊ |
1009 | ␉␊ |
1010 | ␉if(getIntForKey("menu_textmargin_v", &val, theme))␊ |
1011 | ␉␉gui.menu.vborder = MIN( gui.menu.height , val );␊ |
1012 | ␉␊ |
1013 | ␉if(GUI_getColorForKey("menu_bgcolor", &color, theme))␊ |
1014 | ␉␉gui.menu.bgcolor = (color & 0x00FFFFFF);␊ |
1015 | ␉␊ |
1016 | ␉if(getIntForKey("menu_transparency", &alpha, theme))␊ |
1017 | ␉␉gui.menu.bgcolor = gui.menu.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␉␉␊ |
1018 | ␉␊ |
1019 | ␉/*␊ |
1020 | ␉ * Parse bootprompt parameters␊ |
1021 | ␉ */␊ |
1022 | ␉if(GUI_getDimensionForKey("bootprompt_width", &pixel, theme, screen_width , 0 ) )␊ |
1023 | ␉␉gui.bootprompt.width = pixel;␊ |
1024 | ␉␊ |
1025 | ␉if(getIntForKey("bootprompt_height", &val, theme) && val >= 0)␊ |
1026 | ␉␉gui.bootprompt.height = MIN( screen_height , (unsigned)val );␊ |
1027 | ␉␊ |
1028 | ␉if(GUI_getDimensionForKey("bootprompt_pos_x", &pixel, theme, screen_width , gui.bootprompt.width ) )␊ |
1029 | ␉␉gui.bootprompt.pos.x = pixel;␊ |
1030 | ␉␊ |
1031 | ␉if(GUI_getDimensionForKey("bootprompt_pos_y", &pixel, theme, screen_height , gui.bootprompt.height ) )␊ |
1032 | ␉␉gui.bootprompt.pos.y = pixel;␊ |
1033 | ␉␊ |
1034 | ␉if(getIntForKey("bootprompt_textmargin_h", &val, theme) && val >= 0)␊ |
1035 | ␉␉gui.bootprompt.hborder = MIN( gui.bootprompt.width , (unsigned)val );␊ |
1036 | ␉␊ |
1037 | ␉if(getIntForKey("bootprompt_textmargin_v", &val, theme) && val >= 0)␊ |
1038 | ␉␉gui.bootprompt.vborder = MIN( gui.bootprompt.height , (unsigned)val );␊ |
1039 | ␉␊ |
1040 | ␉if(GUI_getColorForKey("bootprompt_bgcolor", &color, theme))␊ |
1041 | ␉␉gui.bootprompt.bgcolor = (color & 0x00FFFFFF);␊ |
1042 | ␉␊ |
1043 | ␉if(getIntForKey("bootprompt_transparency", &alpha, theme))␊ |
1044 | ␉␉gui.bootprompt.bgcolor = gui.bootprompt.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␊ |
1045 | ␉␊ |
1046 | ␉if(GUI_getColorForKey("font_small_color", &color, theme))␊ |
1047 | ␉␉gui.screen.font_small_color = (color & 0x00FFFFFF);␊ |
1048 | ␉␊ |
1049 | ␉if(GUI_getColorForKey("font_console_color", &color, theme))␊ |
1050 | ␉␉gui.screen.font_console_color = (color & 0x00FFFFFF);␊ |
1051 | }␊ |
1052 | ␊ |
1053 | static void add_theme(const char *theme, uint8_t nb) ␊ |
1054 | {␊ |
1055 | struct themeList_t *new_theme;␊ |
1056 | ␊ |
1057 | new_theme = themeList_t_NewStrVar(theme, >hemeList);␊ |
1058 | ␉if (!new_theme) ␊ |
1059 | ␉{␊ |
1060 | ␉␉return;␊ |
1061 | ␉} ␊ |
1062 | new_theme->nb = nb; ␊ |
1063 | }␊ |
1064 | ␊ |
1065 | static char *get_theme_by_index(uint8_t i)␊ |
1066 | {␊ |
1067 | struct themeList_t *current_theme;␊ |
1068 | for(current_theme=gthemeList;current_theme;current_theme=(struct themeList_t*)(current_theme->hh.next)) ␊ |
1069 | { ␊ |
1070 | if (current_theme->nb == i)␊ |
1071 | return current_theme->name; ␊ |
1072 | }␊ |
1073 | return NULL;␊ |
1074 | }␊ |
1075 | ␊ |
1076 | static void free_theme_list(void) ␊ |
1077 | {␊ |
1078 | themeList_t_DeleteAll(gthemeList); ␊ |
1079 | }␊ |
1080 | ␊ |
1081 | static int randomTheme(char *dirspec, const char **theme) {␊ |
1082 | ␉␊ |
1083 | ␉long ret, flags, time;␊ |
1084 | ␉long long␉ index;␊ |
1085 | ␉int sta = 1;␊ |
1086 | ␉const char * name;␉␉ ␊ |
1087 | ␉index = 0;␉␉ ␊ |
1088 | ␉uint8_t i=0;␊ |
1089 | ␉␊ |
1090 | #ifdef EMBED_THEME␊ |
1091 | ␉add_theme("", i);␊ |
1092 | ␉i++;␊ |
1093 | #endif␊ |
1094 | ␉␊ |
1095 | ␉while (i < MAX_THEMES) {␊ |
1096 | ␉␉ret = GetDirEntry(dirspec, &index, &name, &flags, &time);␊ |
1097 | ␉␉if (ret == -1) break;␊ |
1098 | ␉␉␊ |
1099 | ␉␉// Make sure this is a directory.␊ |
1100 | ␉␉if ((flags & kFileTypeMask) != kFileTypeDirectory) continue;␊ |
1101 | ␉␉␊ |
1102 | ␉␉add_theme(name, i);␉␉␉␊ |
1103 | ␉␉␊ |
1104 | ␉␉i++;␊ |
1105 | ␉␉␊ |
1106 | ␉}␊ |
1107 | ␊ |
1108 | #if DEBUG_GUI␊ |
1109 | ␉printf("theme list: \n");␉␉␊ |
1110 | ␉printf("\n");␉␊ |
1111 | ␉struct themeList_t *current_theme;␊ |
1112 | for(current_theme=gthemeList;current_theme;current_theme=(struct themeList_t*)(current_theme->hh.next)) ␊ |
1113 | { ␊ |
1114 | ␉␉printf("* %s (nb = %d)\n", current_theme->name, current_theme->nb);␉␉␊ |
1115 | ␊ |
1116 | }␊ |
1117 | ␉␊ |
1118 | #endif␊ |
1119 | ␊ |
1120 | ␉if (i) {␉␉␉␊ |
1121 | ␉␉␊ |
1122 | ␉␉uint8_t choosen = arc4random_uniform(i);␊ |
1123 | #if DEBUG_GUI␊ |
1124 | ␉␉printf("choosen number (nb = %d), i = %d \n", choosen, i);␊ |
1125 | #endif␉␉␊ |
1126 | ␉␉␊ |
1127 | ␉␉char *tmp = get_theme_by_index(choosen);␊ |
1128 | ␉␉␊ |
1129 | ␉␉if (tmp) ␊ |
1130 | ␉␉{␊ |
1131 | ␉␉␉bzero(tmp_theme,sizeof(tmp_theme));␊ |
1132 | ␉␉␉strlcpy(tmp_theme, tmp, sizeof(tmp_theme));␊ |
1133 | ␉␉}␉␉␊ |
1134 | ␉␉␊ |
1135 | ␉␉free_theme_list();␊ |
1136 | ␉␉␊ |
1137 | ␉␉if (tmp_theme[0]) ␊ |
1138 | ␉␉{␊ |
1139 | ␉␉␉*theme = tmp_theme;␉␉␉␊ |
1140 | ␉␉␉␊ |
1141 | ␉␉␉sta = startGUI();␊ |
1142 | ␉␉}␉␉␊ |
1143 | ␉} ␊ |
1144 | ␉else ␊ |
1145 | ␉{␊ |
1146 | #if DEBUG_GUI␊ |
1147 | ␉␉printf("No theme found !!\n");␊ |
1148 | ␉␉sleep(1);␊ |
1149 | #endif␊ |
1150 | ␉␉free_theme_list();␊ |
1151 | ␊ |
1152 | ␉}␉␊ |
1153 | ␉return sta;␉␊ |
1154 | }␊ |
1155 | ␊ |
1156 | int initGUI(void)␊ |
1157 | {␉␊ |
1158 | ␉bool dummybool = true;␊ |
1159 | ␉int ret = 1;␉␊ |
1160 | ␉bool theme_ran= false;␊ |
1161 | ␉bool theme_name_set= false;␊ |
1162 | ␉␊ |
1163 | ␉getBoolForKey(kGUIKey, &dummybool, DEFAULT_BOOT_CONFIG);␊ |
1164 | ␉if (!dummybool) {␊ |
1165 | ␉␉return 1;␊ |
1166 | ␉}␊ |
1167 | getMemoryInfoString = (void*)lookup_all_symbols(SYMBOLS_BUNDLE,"_getMemoryInfoString");␊ |
1168 | showHelp = (void*)lookup_all_symbols(SYMBOLS_BUNDLE,"_showHelp");␊ |
1169 | ␊ |
1170 | ␉␊ |
1171 | ␉getBoolForKey("RandomTheme", &theme_ran, DEFAULT_BOOT_CONFIG);␊ |
1172 | ␉␊ |
1173 | ␉{␊ |
1174 | ␉␉long flags;␊ |
1175 | ␉␉long time;␊ |
1176 | ␉␉long ret = -1;␊ |
1177 | ␉␉int len;␊ |
1178 | ␉␉␊ |
1179 | ␉␉theme_name_set = getValueForKey( "Theme", &theme_name, &len, DEFAULT_BOOT_CONFIG );␊ |
1180 | ␉␉␊ |
1181 | ␉␉if (theme_ran) ␊ |
1182 | ␉␉{␉␉␊ |
1183 | ␉␉retry:␊ |
1184 | ␉␉␉ret = GetFileInfo("rd(0,0)/Extra/", "Themes", &flags, &time);␊ |
1185 | ␉␉␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) {␊ |
1186 | ␉␉␉␉snprintf(dirsrc,sizeof(dirsrc), "rd(0,0)/Extra/Themes");␊ |
1187 | ␉␉␉␉␊ |
1188 | ␉␉␉} else {␊ |
1189 | ␉␉␉␉ret = GetFileInfo("/Extra/", "Themes", &flags, &time);␊ |
1190 | ␉␉␉␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) {␊ |
1191 | ␉␉␉␉␉snprintf(dirsrc,sizeof(dirsrc), "/Extra/Themes");␊ |
1192 | ␉␉␉␉␉␊ |
1193 | ␉␉␉␉} else {␊ |
1194 | ␉␉␉␉␉ret = GetFileInfo("bt(0,0)/Extra/", "Themes", &flags, &time);␊ |
1195 | ␉␉␉␉␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) {␊ |
1196 | ␉␉␉␉␉␉snprintf(dirsrc,sizeof(dirsrc), "bt(0,0)/Extra/Themes");␊ |
1197 | ␉␉␉␉␉␉␊ |
1198 | ␉␉␉␉␉} else {␊ |
1199 | ␉␉␉␉␉␉printf("Failed to find the /extra/Themes folder\n");␊ |
1200 | ␉␉␉␉␉␉return 1;␊ |
1201 | ␉␉␉␉␉}␊ |
1202 | ␉␉␉␉}␊ |
1203 | ␉␉␉␉␊ |
1204 | ␉␉␉}␉␉␊ |
1205 | ␉␉} ␊ |
1206 | ␉␉else if (theme_name_set)␊ |
1207 | ␉␉{␉␉␊ |
1208 | ␉␉␉ret = GetFileInfo("rd(0,0)/Extra/Themes/", theme_name, &flags, &time);␊ |
1209 | ␉␉␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) {␊ |
1210 | ␉␉␉␉snprintf(dirsrc,sizeof(dirsrc), "rd(0,0)/Extra/Themes");␊ |
1211 | ␉␉␉␉␊ |
1212 | ␉␉␉} else {␊ |
1213 | ␉␉␉␉ret = GetFileInfo("/Extra/Themes/", theme_name, &flags, &time);␊ |
1214 | ␉␉␉␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) {␊ |
1215 | ␉␉␉␉␉snprintf(dirsrc,sizeof(dirsrc), "/Extra/Themes");␊ |
1216 | ␉␉␉␉␉␊ |
1217 | ␉␉␉␉} else {␊ |
1218 | ␉␉␉␉␉ret = GetFileInfo("bt(0,0)/Extra/Themes/", theme_name, &flags, &time);␊ |
1219 | ␉␉␉␉␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) {␊ |
1220 | ␉␉␉␉␉␉snprintf(dirsrc,sizeof(dirsrc), "bt(0,0)/Extra/Themes");␊ |
1221 | ␉␉␉␉␉␉␊ |
1222 | ␉␉␉␉␉} else {␊ |
1223 | ␉␉␉␉␉␉printf("Failed to find the /extra/Themes/%s folder\n",theme_name);␊ |
1224 | ␉␉␉␉␉␉theme_name_set = false;␊ |
1225 | ␉␉␉␉␉␉goto retry;␊ |
1226 | ␉␉␉␉␉}␊ |
1227 | ␉␉␉␉}␊ |
1228 | ␉␉␉␉␊ |
1229 | ␉␉␉}␊ |
1230 | ␉␉}␉␊ |
1231 | ␉}␉␊ |
1232 | ␉␊ |
1233 | ␉if (theme_ran)␊ |
1234 | ␉{␊ |
1235 | ␉␉␊ |
1236 | ␉␉ret = randomTheme(dirsrc, &theme_name);␊ |
1237 | ␉␉␊ |
1238 | ␉␉if (ret) {␊ |
1239 | ␉␉␉printf("randomTheme Failed !! \n");␊ |
1240 | //#if DEBUG_GUI␊ |
1241 | ␉␉␉getc();␊ |
1242 | //#endif␊ |
1243 | ␉␉}␊ |
1244 | #if DEBUG_GUI␊ |
1245 | ␉␉else␊ |
1246 | {␊ |
1247 | DBG("Theme successfuly Choosen randomly !! \n"); ␊ |
1248 | }␊ |
1249 | #endif␊ |
1250 | ␉} ␊ |
1251 | ␉␊ |
1252 | ␉if (ret)␊ |
1253 | ␉{␉␉␉␊ |
1254 | ␉␉if (theme_name_set == true)␊ |
1255 | ␉␉{␊ |
1256 | ␉␉␉ret = startGUI();␊ |
1257 | ␉␉␉␊ |
1258 | ␉␉␉if (ret) printf("Failed to load Theme : %s !! \n", theme_name);␊ |
1259 | ␉␉␉␊ |
1260 | ␉␉} ␊ |
1261 | #ifdef EMBED_THEME␉␊ |
1262 | ␉␉if (ret) {␊ |
1263 | ␉␉␉theme_name = "";␉␉␉␉␊ |
1264 | ␉␉␉ret = startGUI();␊ |
1265 | ␉␉␉␊ |
1266 | ␉␉␉if (ret) printf("Failed to load Embed Theme !! \n");␊ |
1267 | ␉␉␉␊ |
1268 | ␉␉}␉␉␊ |
1269 | #endif␉␉␊ |
1270 | ␉␉if (ret && (strncmp(theme_name, THEME_NAME_DEFAULT,sizeof(THEME_NAME_DEFAULT)) != 0)) {␊ |
1271 | ␉␉␉theme_name = THEME_NAME_DEFAULT;␊ |
1272 | ␉␉␉ret = startGUI();␊ |
1273 | ␉␉␉␊ |
1274 | ␉␉␉if (ret) printf("Failed to load Default Theme : %s !! \n", THEME_NAME_DEFAULT);␊ |
1275 | ␉␉}␊ |
1276 | ␉} ␊ |
1277 | ␉return ret;␊ |
1278 | }␊ |
1279 | ␊ |
1280 | static int startGUI(void)␊ |
1281 | {␊ |
1282 | ␉int val;␉␊ |
1283 | ␉char dirspec[256];␊ |
1284 | ␉␊ |
1285 | ␉␊ |
1286 | ␉if ((unsigned)(strlen(theme_name) + strlen(dirsrc) + strlen("theme.plist") + 2 ) > sizeof(dirspec)) {␊ |
1287 | ␉␉␊ |
1288 | ␉␉DBG("Path of %s/%s/theme.plist to long\n", dirsrc, theme_name);␉␉␊ |
1289 | ␉␉return 1;␊ |
1290 | ␉}␊ |
1291 | ␉␊ |
1292 | ␉snprintf(dirspec, sizeof(dirspec), "%s/%s/theme.plist", dirsrc ,theme_name);␊ |
1293 | ␉␊ |
1294 | ␉if (loadConfigFile(dirspec, &themeConfig) != 0) {␊ |
1295 | ␉␉␊ |
1296 | #ifdef EMBED_THEME␊ |
1297 | ␉␉if (strlen(theme_name) == 0) {␊ |
1298 | ␉␉␉config_file_t *config;␊ |
1299 | ␉␉␉␊ |
1300 | ␉␉␉config = &themeConfig;␊ |
1301 | ␉␉␉if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) {␊ |
1302 | ␉␉␉␉␊ |
1303 | ␉␉␉␉DBG("Unable to load embed theme plist datas.\n");␊ |
1304 | ␉␉␉␉␊ |
1305 | ␉␉␉␉return 1;␊ |
1306 | ␉␉␉}␊ |
1307 | ␉␉}␉␉␉␊ |
1308 | #else␊ |
1309 | ␉␉␊ |
1310 | ␉␉DBG("Unable to load %s theme plist.\n",theme_name);␊ |
1311 | ␉␉␊ |
1312 | ␉␉return 1;␊ |
1313 | ␉␉␊ |
1314 | #endif␉␉␊ |
1315 | }␊ |
1316 | ␉␊ |
1317 | ␉if (execute_hook("getResolution_hook", &screen_params[0], &screen_params[1], &screen_params[2], NULL, NULL, NULL) != EFI_SUCCESS)␉␉␊ |
1318 | ␉{␉␉␊ |
1319 | ␉␉// parse display size parameters␊ |
1320 | ␉␉if (getIntForKey("screen_width", &val, &themeConfig) && val > 0) {␊ |
1321 | ␉␉␉screen_params[0] = val;␊ |
1322 | ␉␉}␊ |
1323 | ␉␉if (getIntForKey("screen_height", &val, &themeConfig) && val > 0) {␊ |
1324 | ␉␉␉screen_params[1] = val;␊ |
1325 | ␉␉}␉␉␊ |
1326 | ␉}␊ |
1327 | #if DEBUG_GUI␊ |
1328 | ␉else␊ |
1329 | ␉{␊ |
1330 | ␉␉printf("No getResolution function hook installed, using default resolution.\n",theme_name);␊ |
1331 | ␉␉␊ |
1332 | ␉}␊ |
1333 | #endif␊ |
1334 | ␉␊ |
1335 | ␉␊ |
1336 | ␉// Initalizing GUI strucutre.␊ |
1337 | ␉bzero(&gui, sizeof(gui_t));␊ |
1338 | ␉␊ |
1339 | ␉// find best matching vesa mode for our requested width & height␊ |
1340 | ␉getGraphicModeParams(screen_params);␊ |
1341 | ␉␊ |
1342 | ␉// set our screen structure with the mode width & height␊ |
1343 | ␉gui.screen.width = screen_params[0];␉␊ |
1344 | ␉gui.screen.height = screen_params[1];␊ |
1345 | ␉␊ |
1346 | ␉// load graphics otherwise fail and return␊ |
1347 | ␉if (loadGraphics(dirsrc) == 0) {␊ |
1348 | ␉␉loadThemeValues(&themeConfig);␊ |
1349 | ␉␉colorFont(&font_small, gui.screen.font_small_color);␊ |
1350 | ␉␉colorFont(&font_console, gui.screen.font_console_color);␊ |
1351 | ␉␉␊ |
1352 | ␉␉// create the screen & window buffers␊ |
1353 | ␉␉if (createBackBuffer(&gui.screen) == 0)␊ |
1354 | ␉␉{␊ |
1355 | ␉␉␉if (createWindowBuffer(&gui.screen) == 0)␊ |
1356 | ␉␉␉{␊ |
1357 | ␉␉␉␉if (createWindowBuffer(&gui.devicelist) == 0)␊ |
1358 | ␉␉␉␉{␊ |
1359 | ␉␉␉␉␉if (createWindowBuffer(&gui.bootprompt) == 0)␊ |
1360 | ␉␉␉␉␉{␊ |
1361 | ␉␉␉␉␉␉if (createWindowBuffer(&gui.infobox) == 0)␊ |
1362 | ␉␉␉␉␉␉{␊ |
1363 | ␉␉␉␉␉␉␉if (createWindowBuffer(&gui.menu) == 0)␊ |
1364 | ␉␉␉␉␉␉␉{␊ |
1365 | ␉␉␉␉␉␉␉ gui.logo.draw = true;␊ |
1366 | ␉␉␉␉␉␉␉␉drawBackground();␊ |
1367 | ␉␉␉␉␉␉␉␉// lets copy the screen into the back buffer␊ |
1368 | memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
1369 | ␊ |
1370 | ␉␉␉␉␉␉␉␉setVideoMode( GRAPHICS_MODE );␊ |
1371 | ␊ |
1372 | ␉␉␉␉␉␉␉␉gui.initialised = true;␉␉␉␉␉␉␉␉␊ |
1373 | ␉␉␉␉␉␉␉␉return 0;␊ |
1374 | ␉␉␉␉␉␉␉}␊ |
1375 | ␉␉␉␉␉␉}␊ |
1376 | ␉␉␉␉␉}␊ |
1377 | ␉␉␉␉}␊ |
1378 | ␉␉␉}␊ |
1379 | ␉␉}␊ |
1380 | ␉}␊ |
1381 | ␉␊ |
1382 | ␉DBG("Loading error occurred, reseting...\n",theme_name);␉␉␊ |
1383 | ␉␊ |
1384 | ␉// Loading error occurred, freeing resources␊ |
1385 | freeWindowBuffer(&gui.menu);␊ |
1386 | freeWindowBuffer(&gui.infobox);␊ |
1387 | freeWindowBuffer(&gui.bootprompt);␊ |
1388 | freeWindowBuffer(&gui.devicelist);␊ |
1389 | freeWindowBuffer(&gui.screen);␊ |
1390 | freeBackBuffer(&gui.screen);␊ |
1391 | unloadGraphics();␉␊ |
1392 | ␉␊ |
1393 | ␉return 1;␊ |
1394 | }␊ |
1395 | ␊ |
1396 | static bool is_image_loaded(int i)␊ |
1397 | {␉␊ |
1398 | ␉return (images[i].image != NULL) ? true : false;␊ |
1399 | }␊ |
1400 | ␊ |
1401 | static void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected)␊ |
1402 | {␊ |
1403 | ␉int devicetype;␊ |
1404 | ␉␊ |
1405 | ␉if( diskIsCDROM(device) )␊ |
1406 | ␉␉devicetype = iDeviceCDROM;␉␉␉␉// Use CDROM icon␊ |
1407 | ␉else␊ |
1408 | ␉{␉␊ |
1409 | ␉␉switch (device->part_type)␊ |
1410 | ␉␉{␊ |
1411 | ␉␉␉case kPartitionTypeHFS:␊ |
1412 | ␉␉␉{␉␉␉␉␊ |
1413 | #ifdef BOOT_HELPER_SUPPORT␉␊ |
1414 | ␉␉␉␉// Use HFS or HFSRAID icon depending on bvr flags.␊ |
1415 | ␉␉␉␉if (device->flags & kBVFlagBooter) {␊ |
1416 | ␊ |
1417 | ␉␉␉␉␉switch (device->OSVersion[3]) {␊ |
1418 | case '8':␊ |
1419 | devicetype = is_image_loaded(iDeviceHFSRAID_ML) ? iDeviceHFSRAID_ML : is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;␊ |
1420 | break;␊ |
1421 | ␉␉␉␉␉␉case '7':␊ |
1422 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFSRAID_Lion) ? iDeviceHFSRAID_Lion : is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;␊ |
1423 | ␉␉␉␉␉␉␉break;␊ |
1424 | ␉␉␉␉␉␉case '6':␊ |
1425 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFSRAID_SL) ? iDeviceHFSRAID_SL : is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;␊ |
1426 | ␉␉␉␉␉␉␉break;␊ |
1427 | ␉␉␉␉␉␉case '5':␊ |
1428 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFSRAID_Leo) ? iDeviceHFSRAID_Leo : is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;␊ |
1429 | ␉␉␉␉␉␉␉break;␊ |
1430 | ␉␉␉␉␉␉case '4':␊ |
1431 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFSRAID_Tiger) ? iDeviceHFSRAID_Tiger : is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;␊ |
1432 | ␉␉␉␉␉␉␉break;␊ |
1433 | ␉␉␉␉␉␉default:␊ |
1434 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;␊ |
1435 | ␉␉␉␉␉␉␉break;␊ |
1436 | ␉␉␉␉␉}␊ |
1437 | ␉␉␉␉␉␊ |
1438 | ␉␉␉␉} else␉␉␉␉␊ |
1439 | #endif␊ |
1440 | ␉␉␉␉{␉␉␉␉␉␊ |
1441 | ␉␉␉␉␉␊ |
1442 | ␉␉␉␉␉switch (device->OSVersion[3]) {␊ |
1443 | case '8':␊ |
1444 | devicetype = is_image_loaded(iDeviceHFS_ML) ? iDeviceHFS_ML : is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;␊ |
1445 | break;␊ |
1446 | ␉␉␉␉␉␉case '7':␊ |
1447 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFS_Lion) ? iDeviceHFS_Lion : is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;␊ |
1448 | ␉␉␉␉␉␉␉break;␊ |
1449 | ␉␉␉␉␉␉case '6':␊ |
1450 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFS_SL) ? iDeviceHFS_SL : is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;␊ |
1451 | ␉␉␉␉␉␉␉break;␊ |
1452 | ␉␉␉␉␉␉case '5':␊ |
1453 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFS_Leo) ? iDeviceHFS_Leo : is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;␊ |
1454 | ␉␉␉␉␉␉␉break;␊ |
1455 | ␉␉␉␉␉␉case '4':␊ |
1456 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFS_Tiger) ? iDeviceHFS_Tiger : is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;␊ |
1457 | ␉␉␉␉␉␉␉break;␊ |
1458 | ␉␉␉␉␉␉default:␊ |
1459 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;␊ |
1460 | ␉␉␉␉␉␉␉break;␊ |
1461 | ␉␉␉␉␉}␉␉␉␉␉␉␊ |
1462 | ␉␉␉␉␉␊ |
1463 | ␉␉␉␉}␊ |
1464 | ␉␉␉␉␊ |
1465 | ␉␉␉␉break;␊ |
1466 | ␉␉␉␉␊ |
1467 | ␉␉␉}␉␉␉␉␊ |
1468 | ␉␉␉case kPartitionTypeHPFS:␊ |
1469 | ␉␉␉␉devicetype = is_image_loaded(iDeviceNTFS) ? iDeviceNTFS : iDeviceGeneric;␉␉// Use HPFS / NTFS icon␊ |
1470 | ␉␉␉␉break;␊ |
1471 | ␉␉␉␉␊ |
1472 | ␉␉␉case kPartitionTypeFAT16:␊ |
1473 | ␉␉␉␉devicetype = is_image_loaded(iDeviceFAT16) ? iDeviceFAT16 : iDeviceGeneric;␉␉// Use FAT16 icon␊ |
1474 | ␉␉␉␉break;␊ |
1475 | ␉␉␉␉␊ |
1476 | ␉␉␉case kPartitionTypeFAT32:␊ |
1477 | ␉␉␉␉devicetype = is_image_loaded(iDeviceFAT32) ? iDeviceFAT32 : iDeviceGeneric;␉␉// Use FAT32 icon␊ |
1478 | ␉␉␉␉break;␊ |
1479 | ␉␉␉␉␊ |
1480 | ␉␉␉case kPartitionTypeEXT3:␊ |
1481 | ␉␉␉␉devicetype = is_image_loaded(iDeviceEXT3) ? iDeviceEXT3 : iDeviceGeneric;␉␉// Use EXT2/3 icon␊ |
1482 | ␉␉␉␉break;␊ |
1483 | ␉␉␉␉␊ |
1484 | ␉␉␉case kPartitionTypeFreeBSD:␊ |
1485 | ␉␉␉␉devicetype = is_image_loaded(iDeviceFreeBSD) ? iDeviceFreeBSD : iDeviceGeneric;␉␉// Use FreeBSD icon␊ |
1486 | ␉␉␉␉break;␊ |
1487 | ␉␉␉␉␊ |
1488 | ␉␉␉case kPartitionTypeOpenBSD:␊ |
1489 | ␉␉␉␉devicetype = is_image_loaded(iDeviceOpenBSD) ? iDeviceOpenBSD : iDeviceGeneric;␉␉// Use OpenBSD icon␊ |
1490 | ␉␉␉␉break;␊ |
1491 | ␉␉␉␉␊ |
1492 | ␉␉␉case kPartitionTypeBEFS: /* Haiku detection and Icon credits to scorpius */␊ |
1493 | ␉␉␉␉devicetype = is_image_loaded(iDeviceBEFS) ? iDeviceBEFS : iDeviceGeneric;// Use BEFS / Haiku icon␊ |
1494 | ␉␉␉␉break;␊ |
1495 | ␉␉␉␉␊ |
1496 | ␉␉␉default:␊ |
1497 | ␉␉␉␉devicetype = iDeviceGeneric;␉// Use Generic icon␊ |
1498 | ␉␉␉␉break;␊ |
1499 | ␉␉}␊ |
1500 | ␉}␊ |
1501 | ␉␊ |
1502 | ␉// Draw the selection image and use the next (device_*_o) image for the selected item.␊ |
1503 | if (isSelected)␊ |
1504 | ␉{␊ |
1505 | ␉␉blend(images[iSelection].image, buffer, centeredAt(images[iSelection].image, p));␊ |
1506 | ␉␉devicetype++; // selec override image ␊ |
1507 | ␉}␊ |
1508 | ␉␊ |
1509 | ␉// draw icon␊ |
1510 | ␉blend( images[devicetype].image, buffer, centeredAt( images[devicetype].image, p ));␊ |
1511 | ␉␊ |
1512 | ␉p.y += (images[iSelection].image->height / 2) + font_console.chars[0]->height;␊ |
1513 | ␉␊ |
1514 | ␉// draw volume label ␊ |
1515 | ␉drawStrCenteredAt( device->label, &font_small, buffer, p);␉␊ |
1516 | ␉␊ |
1517 | }␊ |
1518 | ␊ |
1519 | void drawDeviceList (int start, int end, int selection, MenuItem * menuItems)␊ |
1520 | {␊ |
1521 | ␉int i;␊ |
1522 | ␉position_t p, p_prev, p_next;␊ |
1523 | ␉␊ |
1524 | ␉//uint8_t␉maxDevices = MIN( gui.maxdevices, menucount );␊ |
1525 | ␉␊ |
1526 | ␉fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);␊ |
1527 | ␉␊ |
1528 | ␉makeRoundedCorners( gui.devicelist.pixmap);␊ |
1529 | ␊ |
1530 | int devcnt = (int)get_env(envgDeviceCount);␊ |
1531 | ␊ |
1532 | ␉switch (gui.layout)␊ |
1533 | ␉{␊ |
1534 | ␉␉␉␊ |
1535 | ␉␉case VerticalLayout:␊ |
1536 | ␉␉␉p.x = (gui.devicelist.width /2);␊ |
1537 | ␉␉␉p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );␊ |
1538 | ␉␉␉␊ |
1539 | ␉␉␉// place scroll indicators at top & bottom edges␊ |
1540 | ␉␉␉p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );␊ |
1541 | ␉␉␉p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );␊ |
1542 | ␉␉␉␊ |
1543 | ␉␉␉break;␊ |
1544 | ␉␉␉␊ |
1545 | ␉␉default:␉// use Horizontal layout as the default␊ |
1546 | ␉␉␉␊ |
1547 | ␉␉case HorizontalLayout:␊ |
1548 | ␉␉␉p.x = (gui.devicelist.width - ( gui.devicelist.width / gui.maxdevices ) * gui.maxdevices ) / 2 + ( images[iSelection].image->width / 2) + images[iDeviceScrollPrev].image->width + gui.devicelist.iconspacing;␊ |
1549 | ␉␉␉p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );␊ |
1550 | ␉␉␉␊ |
1551 | ␉␉␉// place scroll indicators at left & right edges␊ |
1552 | ␉␉␉p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );␊ |
1553 | ␉␉␉p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );␊ |
1554 | ␉␉␉␊ |
1555 | ␉␉␉break;␊ |
1556 | ␉␉␉␊ |
1557 | ␉}␊ |
1558 | ␉␊ |
1559 | ␉// draw visible device icons␊ |
1560 | ␉for (i = 0; i < gui.maxdevices; i++)␊ |
1561 | ␉{␊ |
1562 | ␉␉BVRef param = menuItems[start + i].param;␊ |
1563 | ␉␉␊ |
1564 | bool isSelected = ((start + i) == selection) ? true : false;␊ |
1565 | ␉␉if (isSelected)␊ |
1566 | ␉␉{␊ |
1567 | if (param->flags & kBVFlagNativeBoot)␊ |
1568 | {␊ |
1569 | infoMenuNativeBoot = true;␊ |
1570 | }␊ |
1571 | else␊ |
1572 | {␊ |
1573 | infoMenuNativeBoot = false;␊ |
1574 | if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)␊ |
1575 | ␉␉␉␉␉infoMenuSelection = 0;␊ |
1576 | }␊ |
1577 | ␉␉␉␊ |
1578 | ␉␉␉if(gui.menu.draw)␊ |
1579 | ␉␉␉␉drawInfoMenuItems();␊ |
1580 | ␉␉␉␊ |
1581 | #if DEBUG_GUI␊ |
1582 | gui.debug.cursor = pos( 10, 100);␊ |
1583 | dprintf( &gui.screen, "label %s\n", param->label );␊ |
1584 | dprintf( &gui.screen, "biosdev 0x%x\n", param->biosdev );␊ |
1585 | dprintf( &gui.screen, "width %d\n", gui.screen.width);␊ |
1586 | dprintf( &gui.screen, "height %d\n", gui.screen.height);␊ |
1587 | dprintf( &gui.screen, "type 0x%x\n", param->type );␊ |
1588 | dprintf( &gui.screen, "flags 0x%x\n", param->flags );␊ |
1589 | dprintf( &gui.screen, "part_no %d\n", param->part_no );␊ |
1590 | dprintf( &gui.screen, "part_boff 0x%x\n", param->part_boff );␊ |
1591 | dprintf( &gui.screen, "part_type 0x%x\n", param->part_type );␊ |
1592 | dprintf( &gui.screen, "bps 0x%x\n", param->bps );␊ |
1593 | dprintf( &gui.screen, "name %s\n", param->name );␊ |
1594 | dprintf( &gui.screen, "type_name %s\n", param->type_name );␊ |
1595 | dprintf( &gui.screen, "modtime %d\n", param->modTime );␊ |
1596 | #endif␊ |
1597 | ␉␉}␊ |
1598 | ␉␉␊ |
1599 | ␉␉drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);␊ |
1600 | ␉␉␊ |
1601 | ␉␉if (gui.layout == HorizontalLayout)␊ |
1602 | ␉␉{␊ |
1603 | ␉␉␉p.x += images[iSelection].image->width + gui.devicelist.iconspacing; ␊ |
1604 | ␉␉}␊ |
1605 | ␉␉if (gui.layout == VerticalLayout)␊ |
1606 | ␉␉{␊ |
1607 | ␉␉␉p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing ); ␊ |
1608 | ␉␉}␊ |
1609 | ␉}␊ |
1610 | ␉␊ |
1611 | ␉// draw prev indicator␊ |
1612 | ␉if(start)␊ |
1613 | ␉␉blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );␊ |
1614 | ␉␊ |
1615 | ␉// draw next indicator␊ |
1616 | ␉if( end < devcnt - 1 )␊ |
1617 | ␉␉blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );␊ |
1618 | ␉␊ |
1619 | ␉gui.redraw = true;␊ |
1620 | ␉␊ |
1621 | ␉updateVRAM();␊ |
1622 | ␉␊ |
1623 | }␊ |
1624 | ␊ |
1625 | void clearGraphicBootPrompt()␊ |
1626 | {␊ |
1627 | ␉// clear text buffer␊ |
1628 | ␉prompt[0] = '\0';␊ |
1629 | ␉prompt_pos=0;␊ |
1630 | ␉␊ |
1631 | ␉␊ |
1632 | ␉if(␉gui.bootprompt.draw == true )␊ |
1633 | ␉{␊ |
1634 | ␉␉gui.bootprompt.draw = false;␊ |
1635 | ␉␉gui.redraw = true;␊ |
1636 | ␉␉// this causes extra frames to be drawn␊ |
1637 | ␉␉//updateVRAM();␊ |
1638 | ␉}␊ |
1639 | ␉␊ |
1640 | ␉return;␊ |
1641 | }␊ |
1642 | ␊ |
1643 | void updateGraphicBootPrompt(int key)␊ |
1644 | {␊ |
1645 | ␉if ( key == kBackspaceKey )␊ |
1646 | ␉␉prompt[--prompt_pos] = '\0';␊ |
1647 | ␉else ␊ |
1648 | ␉{␊ |
1649 | ␉␉prompt[prompt_pos] = key;␊ |
1650 | ␉␉prompt_pos++;␊ |
1651 | ␉␉prompt[prompt_pos] = '\0';␊ |
1652 | ␉}␊ |
1653 | ␉␊ |
1654 | ␉fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);␊ |
1655 | ␉␊ |
1656 | ␉makeRoundedCorners( gui.bootprompt.pixmap);␊ |
1657 | ␉␊ |
1658 | ␉position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );␊ |
1659 | ␉␊ |
1660 | ␉// print the boot prompt text␊ |
1661 | ␉drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);␊ |
1662 | ␉␊ |
1663 | ␉// get the position of the end of the boot prompt text to display user input␊ |
1664 | ␉position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );␊ |
1665 | ␉␊ |
1666 | ␉// calculate the position of the cursor␊ |
1667 | ␉int␉offset = ( prompt_pos - ( ( gui.bootprompt.width / font_console.chars[0]->width ) - strlen(prompt_text) - 2 ) );␉␊ |
1668 | ␉␊ |
1669 | ␉if ( offset < 0)␊ |
1670 | ␉␉offset = 0;␊ |
1671 | ␉␊ |
1672 | ␉drawStr( prompt+offset, &font_console, gui.bootprompt.pixmap, p_prompt);␊ |
1673 | ␉␊ |
1674 | ␉gui.menu.draw = false;␊ |
1675 | ␉gui.bootprompt.draw = true;␊ |
1676 | ␉gui.redraw = true;␊ |
1677 | ␉␊ |
1678 | ␉updateVRAM();␊ |
1679 | ␉␊ |
1680 | ␉return;␊ |
1681 | }␊ |
1682 | ␊ |
1683 | ␊ |
1684 | static inline␊ |
1685 | void vramwrite (void *data, int width)␊ |
1686 | {␊ |
1687 | ␉if (VIDEO (depth) == 0x20 /*32*/ && VIDEO (rowBytes) == (unsigned long)gui.backbuffer->width * 4)␊ |
1688 | ␉␉memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));␊ |
1689 | ␉else␊ |
1690 | ␉{␊ |
1691 | ␉␉uint32_t r, g, b;␊ |
1692 | ␉␉uint32_t i, j;␊ |
1693 | ␉␉for (i = 0; i < VIDEO (height); i++)␊ |
1694 | ␉␉␉for (j = 0; j < VIDEO (width); j++)␊ |
1695 | ␉␉␉{␊ |
1696 | ␉␉␉␉b = ((uint8_t *) data)[4*i*width + 4*j];␊ |
1697 | ␉␉␉␉g = ((uint8_t *) data)[4*i*width + 4*j + 1];␊ |
1698 | ␉␉␉␉r = ((uint8_t *) data)[4*i*width + 4*j + 2];␊ |
1699 | ␉␉␉␉switch (VIDEO (depth))␊ |
1700 | ␉␉␉␉{␊ |
1701 | ␉␉␉␉␉case 32:␊ |
1702 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
1703 | ␉␉␉␉␉␉break;␊ |
1704 | ␉␉␉␉␉case 24:␊ |
1705 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)␊ |
1706 | ␉␉␉␉␉␉| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
1707 | ␉␉␉␉␉␉break;␊ |
1708 | ␉␉␉␉␉case 16:␊ |
1709 | ␉␉␉␉␉␉// Somehow 16-bit is always 15-bits really␊ |
1710 | ␉␉␉␉␉␉//␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);␊ |
1711 | ␉␉␉␉␉␉//␉␉␉␉␉␉break;␉␉␉␉␉␉␉␊ |
1712 | ␉␉␉␉␉case 15:␊ |
1713 | ␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);␊ |
1714 | ␉␉␉␉␉␉break;␉␊ |
1715 | ␉␉␉␉␉default:␊ |
1716 | ␉␉␉␉␉␉break;␊ |
1717 | ␉␉␉␉}␊ |
1718 | ␉␉␉}␊ |
1719 | ␉}␊ |
1720 | }␊ |
1721 | ␊ |
1722 | void updateVRAM()␊ |
1723 | {␊ |
1724 | ␉if (gui.redraw)␊ |
1725 | ␉{␊ |
1726 | ␉␉if (gui.devicelist.draw)␊ |
1727 | ␉␉␉blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );␊ |
1728 | ␉␉␊ |
1729 | ␉␉if (gui.bootprompt.draw)␊ |
1730 | ␉␉␉blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );␊ |
1731 | ␉␉␊ |
1732 | ␉␉if (gui.menu.draw)␊ |
1733 | ␉␉␉blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );␊ |
1734 | ␉␉␊ |
1735 | ␉␉if (gui.infobox.draw)␊ |
1736 | ␉␉␉blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );␊ |
1737 | ␉}␊ |
1738 | ␊ |
1739 | ␉vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width );␊ |
1740 | ␊ |
1741 | ␉if (gui.redraw)␊ |
1742 | ␉{␊ |
1743 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
1744 | ␉␉gui.redraw = false;␊ |
1745 | ␉}␊ |
1746 | }␊ |
1747 | ␊ |
1748 | struct putc_info {␊ |
1749 | ␉char * str;␊ |
1750 | ␉char * last_str;␊ |
1751 | };␊ |
1752 | static void␊ |
1753 | sputc(int c, void * pi)␊ |
1754 | {␊ |
1755 | ␉if (((struct putc_info*)pi)->last_str)␊ |
1756 | ␉␉if (((struct putc_info*)pi)->str == ((struct putc_info*)pi)->last_str) {␊ |
1757 | ␉␉␉*(((struct putc_info*)pi)->str) = '\0';␊ |
1758 | ␉␉␉return;␊ |
1759 | ␉␉}␊ |
1760 | ␉*(((struct putc_info*)pi)->str)++ = c;␊ |
1761 | }␊ |
1762 | ␊ |
1763 | int gprintf( window_t * window, const char * fmt, ...)␊ |
1764 | {␊ |
1765 | ␉char *formattedtext;␊ |
1766 | ␉struct putc_info pi;␊ |
1767 | ␊ |
1768 | ␉va_list ap;␊ |
1769 | ␉␉␊ |
1770 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1771 | ␉␉␊ |
1772 | ␉␉␊ |
1773 | ␉␉position_t␉origin, cursor, bounds;␊ |
1774 | ␉␉␊ |
1775 | ␉␉int i;␊ |
1776 | ␉␉int character;␊ |
1777 | ␉␉␊ |
1778 | ␉␉va_start(ap, fmt);␊ |
1779 | ␉␉␊ |
1780 | ␉␉localVPrintf(fmt, ap, 0);␊ |
1781 | ␊ |
1782 | ␉␉// format the text␊ |
1783 | ␉␉pi.str = formattedtext;␊ |
1784 | ␉␉pi.last_str = 0;␊ |
1785 | ␉␉__doprnt(fmt, ap, sputc, &pi, 10);␊ |
1786 | ␉␉*pi.str = '\0';␊ |
1787 | ␉␉␊ |
1788 | ␉␉va_end(ap);␊ |
1789 | ␉␉␊ |
1790 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1791 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1792 | ␉␉␊ |
1793 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1794 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1795 | ␉␉␊ |
1796 | ␉␉cursor = origin;␊ |
1797 | ␉␉␊ |
1798 | ␉␉font_t *font = &font_console;␊ |
1799 | ␉␉␊ |
1800 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1801 | ␉␉{␊ |
1802 | ␉␉␉character = formattedtext[i];␊ |
1803 | ␉␉␉␊ |
1804 | ␉␉␉character -= 32;␊ |
1805 | ␉␉␉␊ |
1806 | ␉␉␉// newline ?␊ |
1807 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1808 | ␉␉␉{␊ |
1809 | ␉␉␉␉cursor.x = window->hborder;␊ |
1810 | ␉␉␉␉cursor.y += font->height;␊ |
1811 | ␉␉␉␉␊ |
1812 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1813 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1814 | ␉␉␉␉␊ |
1815 | ␉␉␉␉continue;␊ |
1816 | ␉␉␉}␊ |
1817 | ␉␉␉␊ |
1818 | ␉␉␉// tab ?␊ |
1819 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1820 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1821 | ␉␉␉␊ |
1822 | ␉␉␉// draw the character␊ |
1823 | ␉␉␉if( font->chars[character])␊ |
1824 | ␉␉␉␉blend(font->chars[character], window->pixmap, cursor);␊ |
1825 | ␉␉␉␊ |
1826 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1827 | ␉␉␉␊ |
1828 | ␉␉␉// check x pos and do newline␊ |
1829 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1830 | ␉␉␉{␊ |
1831 | ␉␉␉␉cursor.x = origin.x;␊ |
1832 | ␉␉␉␉cursor.y += font->height;␊ |
1833 | ␉␉␉}␊ |
1834 | ␉␉␉␊ |
1835 | ␉␉␉// check y pos and reset to origin.y␊ |
1836 | ␉␉␉if ( cursor.y > bounds.y )␊ |
1837 | ␉␉␉␉cursor.y = origin.y;␊ |
1838 | ␉␉}␊ |
1839 | ␉␉␊ |
1840 | ␉␉// update cursor postition␊ |
1841 | ␉␉window->cursor = cursor;␊ |
1842 | ␉␉␊ |
1843 | ␉␉free(formattedtext);␊ |
1844 | ␉␉␊ |
1845 | ␉␉return 0;␊ |
1846 | ␉␉␊ |
1847 | ␉}␊ |
1848 | ␉return 1;␊ |
1849 | }␊ |
1850 | #if DEBUG_GUI␊ |
1851 | static int dprintf( window_t * window, const char * fmt, ...)␊ |
1852 | {␊ |
1853 | ␉char *formattedtext;␊ |
1854 | ␉␊ |
1855 | ␉va_list ap;␊ |
1856 | ␉struct putc_info pi;␊ |
1857 | ␊ |
1858 | ␊ |
1859 | ␉//window = &gui.debug;␊ |
1860 | ␉␊ |
1861 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1862 | ␉␉␉␉␊ |
1863 | ␉␉position_t␉origin, cursor, bounds;␊ |
1864 | ␉␉␊ |
1865 | ␉␉int i;␊ |
1866 | ␉␉int character;␊ |
1867 | ␉␉␊ |
1868 | ␉␉va_start(ap, fmt);␊ |
1869 | ␉␉␊ |
1870 | ␉␉// format the text␊ |
1871 | ␉␉pi.str = formattedtext;␊ |
1872 | ␉␉pi.last_str = 0;␊ |
1873 | ␉␉__doprnt(fmt, ap, sputc, &pi, 10);␊ |
1874 | ␉␉*pi.str = '\0';␊ |
1875 | ␉␉␊ |
1876 | ␉␉va_end(ap);␊ |
1877 | ␉␉␊ |
1878 | ␉␉origin.x = MAX( gui.debug.cursor.x, window->hborder );␊ |
1879 | ␉␉origin.y = MAX( gui.debug.cursor.y, window->vborder );␊ |
1880 | ␉␉␊ |
1881 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1882 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1883 | ␉␉␊ |
1884 | ␉␉cursor = origin;␊ |
1885 | ␉␉␊ |
1886 | ␉␉font_t *font = &font_console;␊ |
1887 | ␉␉␊ |
1888 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1889 | ␉␉{␊ |
1890 | ␉␉␉character = formattedtext[i];␊ |
1891 | ␉␉␉␊ |
1892 | ␉␉␉character -= 32;␊ |
1893 | ␉␉␉␊ |
1894 | ␉␉␉// newline ?␊ |
1895 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1896 | ␉␉␉{␊ |
1897 | ␉␉␉␉cursor.x = window->hborder;␊ |
1898 | ␉␉␉␉cursor.y += font->height;␊ |
1899 | ␉␉␉␉␊ |
1900 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1901 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1902 | ␉␉␉␉␊ |
1903 | ␉␉␉␉continue;␊ |
1904 | ␉␉␉}␊ |
1905 | ␉␉␉␊ |
1906 | ␉␉␉// tab ?␊ |
1907 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1908 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1909 | ␉␉␉␊ |
1910 | ␉␉␉// draw the character␊ |
1911 | ␉␉␉if( font->chars[character])␊ |
1912 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1913 | ␉␉␉␊ |
1914 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1915 | ␉␉␉␊ |
1916 | ␉␉␉// check x pos and do newline␊ |
1917 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1918 | ␉␉␉{␊ |
1919 | ␉␉␉␉cursor.x = origin.x;␊ |
1920 | ␉␉␉␉cursor.y += font->height;␊ |
1921 | ␉␉␉}␊ |
1922 | ␉␉␉␊ |
1923 | ␉␉␉// check y pos and reset to origin.y␊ |
1924 | ␉␉␉if ( cursor.y > bounds.y )␊ |
1925 | ␉␉␉␉cursor.y = origin.y;␊ |
1926 | ␉␉}␊ |
1927 | ␉␉␊ |
1928 | ␉␉// update cursor postition␊ |
1929 | ␉␉gui.debug.cursor = cursor;␊ |
1930 | ␉␉␊ |
1931 | ␉␉free(formattedtext);␊ |
1932 | ␉␉␊ |
1933 | ␉␉return 0;␊ |
1934 | ␉␉␊ |
1935 | ␉}␊ |
1936 | ␉return 1;␊ |
1937 | }␊ |
1938 | #endif␊ |
1939 | ␊ |
1940 | int vprf(const char * fmt, va_list ap)␊ |
1941 | {␊ |
1942 | ␉int i;␊ |
1943 | ␉int character;␊ |
1944 | ␉struct putc_info pi;␊ |
1945 | ␉␊ |
1946 | ␉char *formattedtext;␊ |
1947 | ␉window_t *window = &gui.screen;␊ |
1948 | ␉␊ |
1949 | ␉position_t␉origin, cursor, bounds;␊ |
1950 | ␉font_t *font = &font_console;␊ |
1951 | ␉␊ |
1952 | ␉if ((formattedtext = malloc(1024)) != NULL){␊ |
1953 | ␉␉␊ |
1954 | ␉␉// format the text␊ |
1955 | ␉␉␉pi.str = formattedtext;␊ |
1956 | ␉␉␉pi.last_str = 0;␊ |
1957 | ␉␉␉__doprnt(fmt, ap, sputc, &pi, 10);␊ |
1958 | ␉␉␉*pi.str = '\0';␊ |
1959 | ␉␉␊ |
1960 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1961 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1962 | ␉␉bounds.x = ( window->width - ( window->hborder * 2 ) );␊ |
1963 | ␉␉bounds.y = ( window->height - ( window->vborder * 2 ) );␊ |
1964 | ␉␉cursor = origin;␊ |
1965 | ␉␉␊ |
1966 | ␉␉for( i=0; i< strlen(formattedtext) ; i++ )␊ |
1967 | ␉␉{␊ |
1968 | ␉␉␉character = formattedtext[i];␊ |
1969 | ␉␉␉character -= 32;␊ |
1970 | ␉␉␉␊ |
1971 | ␉␉␉// newline ?␊ |
1972 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1973 | ␉␉␉{␊ |
1974 | ␉␉␉␉cursor.x = window->hborder;␊ |
1975 | ␉␉␉␉cursor.y += font->height;␊ |
1976 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1977 | ␉␉␉␉{␊ |
1978 | ␉␉␉␉␉gui.redraw = true;␊ |
1979 | ␉␉␉␉␉updateVRAM();␊ |
1980 | ␉␉␉␉␉cursor.y = window->vborder;␊ |
1981 | ␉␉␉␉}␊ |
1982 | ␉␉␉␉window->cursor.y = cursor.y;␊ |
1983 | ␉␉␉␉continue;␊ |
1984 | ␉␉␉}␊ |
1985 | ␉␉␉␊ |
1986 | ␉␉␉// tab ?␊ |
1987 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1988 | ␉␉␉{␊ |
1989 | ␉␉␉␉cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );␊ |
1990 | ␉␉␉␉continue;␊ |
1991 | ␉␉␉}␊ |
1992 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1993 | ␉␉␉␊ |
1994 | ␉␉␉// check x pos and do newline␊ |
1995 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1996 | ␉␉␉{␊ |
1997 | ␉␉␉␉cursor.x = origin.x;␊ |
1998 | ␉␉␉␉cursor.y += font->height;␊ |
1999 | ␉␉␉}␊ |
2000 | ␉␉␉␊ |
2001 | ␉␉␉// check y pos and reset to origin.y␊ |
2002 | ␉␉␉if ( cursor.y > ( bounds.y + font->chars[0]->height) )␊ |
2003 | ␉␉␉{␊ |
2004 | ␉␉␉␉gui.redraw = true;␊ |
2005 | ␉␉␉␉updateVRAM();␊ |
2006 | ␉␉␉␉cursor.y = window->vborder;␊ |
2007 | ␉␉␉}␊ |
2008 | ␉␉␉// draw the character␊ |
2009 | ␉␉␉if( font->chars[character])␊ |
2010 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
2011 | ␉␉}␊ |
2012 | ␉␉// save cursor postition␊ |
2013 | ␉␉window->cursor.x = cursor.x;␊ |
2014 | ␉␉updateVRAM();␊ |
2015 | ␉␉free(formattedtext);␊ |
2016 | ␉␉return 0;␊ |
2017 | ␉}␊ |
2018 | ␉return 1;␊ |
2019 | }␊ |
2020 | ␊ |
2021 | pixmap_t* charToPixmap(unsigned char ch, font_t *font) {␊ |
2022 | ␉unsigned int cha = (unsigned int)ch - 32;␊ |
2023 | ␉if (cha >= font->count)␊ |
2024 | ␉␉// return ? if the font for the char doesn't exists␊ |
2025 | ␉␉cha = '?' - 32;␊ |
2026 | ␉return font->chars[cha] ? font->chars[cha] : NULL;␊ |
2027 | }␊ |
2028 | ␊ |
2029 | static position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) {␊ |
2030 | ␉pixmap_t* pm = charToPixmap(ch, font);␊ |
2031 | ␉if (pm && ((p.x + pm->width) < blendInto->width))␊ |
2032 | ␉{␊ |
2033 | ␉␉blend(pm, blendInto, p);␊ |
2034 | ␉␉return pos(p.x + pm->width, p.y);␊ |
2035 | ␉}␊ |
2036 | ␉else␊ |
2037 | ␉␉return p;␊ |
2038 | }␊ |
2039 | ␊ |
2040 | static void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)␊ |
2041 | {␊ |
2042 | ␉int i=0;␊ |
2043 | ␉position_t current_pos = pos(p.x, p.y);␊ |
2044 | ␉␊ |
2045 | ␉for (i=0; i < strlen(ch); i++)␊ |
2046 | ␉{␉␉␊ |
2047 | ␉␉// newline ?␊ |
2048 | ␉␉if ( ch[i] == '\n' )␊ |
2049 | ␉␉{␊ |
2050 | ␉␉␉current_pos.x = p.x;␊ |
2051 | ␉␉␉current_pos.y += font->height;␊ |
2052 | ␉␉␉continue;␊ |
2053 | ␉␉}␊ |
2054 | ␉␉␊ |
2055 | ␉␉// tab ?␊ |
2056 | ␉␉if ( ch[i] == '\t' )␊ |
2057 | ␉␉{␊ |
2058 | ␉␉␉current_pos.x += TAB_PIXELS_WIDTH;␊ |
2059 | ␉␉␉continue;␊ |
2060 | ␉␉}␉␉␉␊ |
2061 | ␉␉␊ |
2062 | ␉␉current_pos = drawChar(ch[i], font, blendInto, current_pos);␊ |
2063 | ␉}␊ |
2064 | }␊ |
2065 | ␊ |
2066 | static void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)␊ |
2067 | {␊ |
2068 | ␉int i = 0;␊ |
2069 | ␉int width = 0;␊ |
2070 | ␉int max_width = 0;␊ |
2071 | ␉int height = font->height;␊ |
2072 | ␉␊ |
2073 | ␉// calculate the width in pixels␊ |
2074 | ␉for (i=0; i < strlen(text); i++) {␊ |
2075 | ␉␉if (text[i] == '\n')␊ |
2076 | ␉␉{␊ |
2077 | ␉␉␉width = 0;␊ |
2078 | ␉␉␉height += font->height;␊ |
2079 | ␉␉}␊ |
2080 | ␉␉else if (text[i] == '\t')␊ |
2081 | ␉␉␉width += TAB_PIXELS_WIDTH;␊ |
2082 | ␉␉else␊ |
2083 | ␉␉{␊ |
2084 | ␉␉␉pixmap_t* pm = charToPixmap(text[i], font);␊ |
2085 | ␉␉␉if (pm)␊ |
2086 | ␉␉␉␉width += pm->width;␊ |
2087 | ␉␉}␊ |
2088 | ␉␉if (width > max_width)␊ |
2089 | ␉␉␉max_width = width;␊ |
2090 | ␉}␊ |
2091 | ␉␊ |
2092 | ␉p.x = ( p.x - ( max_width / 2 ) );␊ |
2093 | ␉p.y = ( p.y - ( height / 2 ) );␊ |
2094 | ␉␊ |
2095 | ␉drawStr(text, font, blendInto, p);␉␊ |
2096 | }␊ |
2097 | ␊ |
2098 | static int destroyFont(font_t *font)␊ |
2099 | {␊ |
2100 | ␉int i;␊ |
2101 | for (i = 0; i < CHARACTERS_COUNT; i++)␊ |
2102 | {␊ |
2103 | ␉␉if (font->chars[i])␊ |
2104 | ␉␉{␊ |
2105 | ␉␉␉if (font->chars[i]->pixels) free (font->chars[i]->pixels);␊ |
2106 | ␉␉␉free (font->chars[i]);␊ |
2107 | ␉␉␉font->chars[i] = 0;␊ |
2108 | ␉␉}␊ |
2109 | }␊ |
2110 | return 0;␊ |
2111 | }␊ |
2112 | ␊ |
2113 | static int initFont(font_t *font, image_t *data)␊ |
2114 | {␊ |
2115 | ␉unsigned int x = 0, y = 0, x2 = 0, x3 = 0;␊ |
2116 | ␉␊ |
2117 | ␉int start = 0, end = 0, count = 0, space = 0;␊ |
2118 | ␉␊ |
2119 | ␉bool monospaced = false;␊ |
2120 | ␉␊ |
2121 | ␉font->height = data->image->height;␉␊ |
2122 | ␉␊ |
2123 | ␉for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++)␊ |
2124 | ␉{␊ |
2125 | ␉␉start = end;␊ |
2126 | ␉␉␊ |
2127 | ␉␉// if the pixel is red we've reached the end of the char␊ |
2128 | ␉␉if( pixel( data->image, x, 0 ).value == 0xFFFF0000)␊ |
2129 | ␉␉{␊ |
2130 | ␉␉␉end = x + 1;␊ |
2131 | ␉␉␉␊ |
2132 | ␉␉␉if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )␊ |
2133 | ␉␉␉{␊ |
2134 | ␉␉␉␉font->chars[count]->width = ( end - start) - 1;␊ |
2135 | ␉␉␉␉font->chars[count]->height = font->height;␊ |
2136 | ␉␉␉␉{␊ |
2137 | int pixels_size = (font->chars[count]->width * data->image->height * 4);␊ |
2138 | ␊ |
2139 | if (!(pixels_size > 0))␊ |
2140 | {␊ |
2141 | continue;␊ |
2142 | }␊ |
2143 | ␊ |
2144 | if ( !( font->chars[count]->pixels = malloc( pixels_size ) ) )␊ |
2145 | {␊ |
2146 | continue;␊ |
2147 | } ␊ |
2148 | ␊ |
2149 | ␉␉␉␉␉space += pixels_size;␊ |
2150 | }␊ |
2151 | ␉␉␉␉// we skip the first line because there are just the red pixels for the char width␊ |
2152 | for( y = 1; y< (font->height); y++)␊ |
2153 | {␊ |
2154 | for( x2 = (unsigned)start, x3 = 0; x2 < (unsigned)end; x2++, x3++)␊ |
2155 | {␊ |
2156 | pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );␊ |
2157 | }␉␊ |
2158 | }␊ |
2159 | ␊ |
2160 | // check if font is monospaced␊ |
2161 | if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )␊ |
2162 | monospaced = true;␊ |
2163 | ␊ |
2164 | font->width = font->chars[count]->width;␊ |
2165 | ␊ |
2166 | count++;␉␊ |
2167 | ␉␉␉␉␊ |
2168 | ␉␉␉}␊ |
2169 | ␉␉}␊ |
2170 | ␉}␊ |
2171 | ␉␊ |
2172 | ␉for (x = count; x < CHARACTERS_COUNT; x++)␊ |
2173 | ␉␉font->chars[x] = NULL;␊ |
2174 | ␉␊ |
2175 | ␉if(monospaced)␊ |
2176 | ␉␉font->width = 0;␊ |
2177 | ␉␊ |
2178 | ␉font->count = count;␊ |
2179 | ␉␊ |
2180 | ␉return 0;␊ |
2181 | }␊ |
2182 | ␊ |
2183 | static void colorFont(font_t *font, uint32_t color)␊ |
2184 | {␊ |
2185 | ␉if( !color )␊ |
2186 | ␉␉return;␊ |
2187 | ␉␊ |
2188 | ␉int x, y, width, height;␊ |
2189 | ␉int count = 0;␊ |
2190 | ␉pixel_t *buff;␊ |
2191 | ␉␊ |
2192 | ␉while( font->chars[count++] )␊ |
2193 | ␉{␊ |
2194 | ␉␉width = font->chars[count-1]->width;␊ |
2195 | ␉␉height = font->chars[count-1]->height;␊ |
2196 | ␉␉for( y = 0; y < height; y++ )␊ |
2197 | ␉␉{␊ |
2198 | ␉␉␉for( x = 0; x < width; x++ )␊ |
2199 | ␉␉␉{␊ |
2200 | ␉␉␉␉buff = &(pixel( font->chars[count-1], x, y ));␊ |
2201 | ␉␉␉␉if( buff->ch.a )␊ |
2202 | ␉␉␉␉{␊ |
2203 | ␉␉␉␉␉buff->ch.r = (color & 0xFFFF0000) >> 16;␊ |
2204 | ␉␉␉␉␉buff->ch.g = (color & 0xFF00FF00) >> 8;␊ |
2205 | ␉␉␉␉␉buff->ch.b = (color & 0xFF0000FF);␊ |
2206 | ␉␉␉␉}␊ |
2207 | ␉␉␉}␊ |
2208 | ␉␉}␊ |
2209 | ␉}␊ |
2210 | }␊ |
2211 | ␊ |
2212 | static void makeRoundedCorners(pixmap_t *p)␊ |
2213 | {␊ |
2214 | ␉int x,y;␊ |
2215 | ␉int width=p->width-1;␊ |
2216 | ␉int height=p->height-1;␊ |
2217 | ␉␊ |
2218 | ␉// 10px rounded corner alpha values␊ |
2219 | ␉uint8_t roundedCorner[10][10] =␊ |
2220 | ␉{␊ |
2221 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},␊ |
2222 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
2223 | ␉␉{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
2224 | ␉␉{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
2225 | ␉␉{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
2226 | ␉␉{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
2227 | ␉␉{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
2228 | ␉␉{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
2229 | ␉␉{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
2230 | ␉␉{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}␊ |
2231 | ␉};␊ |
2232 | ␉␊ |
2233 | ␉uint8_t alpha=0;␊ |
2234 | ␉␊ |
2235 | ␉for( y=0; y<10; y++)␊ |
2236 | ␉{␊ |
2237 | ␉␉for( x=0; x<10; x++)␊ |
2238 | ␉␉{␊ |
2239 | ␉␉␉// skip if the pixel should be visible␊ |
2240 | ␉␉␉if(roundedCorner[y][x] != 0xFF) ␊ |
2241 | ␉␉␉{ ␊ |
2242 | ␉␉␉␉alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );␊ |
2243 | ␉␉␉␉// Upper left corner␊ |
2244 | ␉␉␉␉pixel(p, x, y).ch.a = alpha;␊ |
2245 | ␉␉␉␉␊ |
2246 | ␉␉␉␉// upper right corner␊ |
2247 | ␉␉␉␉pixel(p, width-x,y).ch.a = alpha;␊ |
2248 | ␉␉␉␉␊ |
2249 | ␉␉␉␉// lower left corner␊ |
2250 | ␉␉␉␉pixel(p, x, height-y).ch.a = alpha;␊ |
2251 | ␉␉␉␉␊ |
2252 | ␉␉␉␉// lower right corner␊ |
2253 | ␉␉␉␉pixel(p, width-x, height-y).ch.a = alpha;␊ |
2254 | ␉␉␉}␊ |
2255 | ␉␉}␊ |
2256 | ␉}␊ |
2257 | }␊ |
2258 | ␊ |
2259 | void showInfoBox(char *title, char *text)␊ |
2260 | {␊ |
2261 | ␉int i, key, lines, visiblelines;␊ |
2262 | ␉␊ |
2263 | ␉int currentline=0;␊ |
2264 | ␉int cnt=0;␊ |
2265 | ␉int offset=0;␊ |
2266 | ␉␊ |
2267 | ␉if( !title || !text )␊ |
2268 | ␉␉return;␊ |
2269 | ␉␊ |
2270 | ␉position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );␊ |
2271 | ␉␊ |
2272 | ␉// calculate number of lines in the title␊ |
2273 | ␉for ( i = 0, lines = 1; i<strlen(title); i++ )␊ |
2274 | ␉␉if( title[i] == '\n')␊ |
2275 | ␉␉␉lines++;␊ |
2276 | ␉␊ |
2277 | ␉// y position of text is lines in title * height of font␊ |
2278 | ␉position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));␊ |
2279 | ␉␊ |
2280 | ␉// calculate number of lines in the text␊ |
2281 | ␉for ( i=0, lines = 1; i<strlen(text); i++ )␊ |
2282 | ␉␉if( text[i] == '\n')␊ |
2283 | ␉␉␉lines++;␊ |
2284 | ␉␊ |
2285 | ␉// if text ends with \n strip off␊ |
2286 | ␉if( text[i] == '\n' || text[i] == '\0')␊ |
2287 | ␉␉lines--;␊ |
2288 | ␉␊ |
2289 | ␉visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;␊ |
2290 | ␉␊ |
2291 | ␉// lets display the text and allow scroll thru using up down / arrows␊ |
2292 | ␉while(1)␊ |
2293 | ␉{␊ |
2294 | ␉␉// move to current line in text␊ |
2295 | ␉␉for( offset = 0, i = 0; offset < strlen(text); offset++ )␊ |
2296 | ␉␉{␊ |
2297 | ␉␉␉if( currentline == i)␊ |
2298 | ␉␉␉␉break;␊ |
2299 | ␉␉␉if( text[offset] =='\n')␊ |
2300 | ␉␉␉␉i++;␊ |
2301 | ␉␉}␊ |
2302 | ␉␉␊ |
2303 | ␉␉// find last visible line in text and place \0␊ |
2304 | ␉␉for( i = offset, cnt = 0; i < strlen(text); i++)␊ |
2305 | ␉␉{␊ |
2306 | ␉␉␉if(text[i]=='\n')␊ |
2307 | ␉␉␉␉cnt++;␊ |
2308 | ␉␉␉if ( cnt == visiblelines )␊ |
2309 | ␉␉␉{␊ |
2310 | ␉␉␉␉text[i]='\0';␊ |
2311 | ␉␉␉␉break;␊ |
2312 | ␉␉␉}␊ |
2313 | ␉␉}␊ |
2314 | ␉␉␊ |
2315 | ␉␉fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);␊ |
2316 | ␉␉␊ |
2317 | ␉␉makeRoundedCorners( gui.infobox.pixmap);␊ |
2318 | ␉␉␊ |
2319 | ␉␉// print the title if present␊ |
2320 | ␉␉if( title )␊ |
2321 | ␉␉␉drawStr(title, &font_console, gui.infobox.pixmap, pos_title);␊ |
2322 | ␉␉␊ |
2323 | ␉␉// print the text␊ |
2324 | ␉␉drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);␊ |
2325 | ␉␉␊ |
2326 | ␉␉// restore \n in text␊ |
2327 | ␉␉if ( cnt == visiblelines )␊ |
2328 | ␉␉␉text[i] = '\n';␊ |
2329 | ␉␉␊ |
2330 | ␉␉position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );␊ |
2331 | ␉␉␊ |
2332 | ␉␉// draw prev indicator␊ |
2333 | ␉␉if(offset)␊ |
2334 | ␉␉{␊ |
2335 | ␉␉␉blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));␊ |
2336 | ␉␉}␊ |
2337 | ␉␉␊ |
2338 | ␉␉// draw next indicator␊ |
2339 | ␉␉if( lines > ( currentline + visiblelines ) )␊ |
2340 | ␉␉{␊ |
2341 | ␉␉␉pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );␊ |
2342 | ␉␉␉blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );␊ |
2343 | ␉␉}␊ |
2344 | ␉␉␊ |
2345 | ␉␉gui.bootprompt.draw = false;␊ |
2346 | ␉␉gui.infobox.draw = true;␊ |
2347 | ␉␉gui.redraw = true;␊ |
2348 | ␉␉␊ |
2349 | ␉␉updateVRAM();␊ |
2350 | ␉␉␊ |
2351 | ␉␉key = getc();␊ |
2352 | ␉␉␊ |
2353 | ␉␉if( key == kUpArrowkey )␊ |
2354 | ␉␉␉if( currentline > 0 )␊ |
2355 | ␉␉␉␉currentline--;␊ |
2356 | ␉␉␊ |
2357 | ␉␉if( key == kDownArrowkey )␊ |
2358 | ␉␉␉if( lines > ( currentline + visiblelines ) )␊ |
2359 | ␉␉␉␉currentline++;␊ |
2360 | ␉␉␊ |
2361 | ␉␉if( key == kEscapeKey || key == 'q' || key == 'Q')␊ |
2362 | ␉␉{␊ |
2363 | ␉␉␉gui.infobox.draw = false;␊ |
2364 | ␉␉␉gui.redraw = true;␊ |
2365 | ␉␉␉updateVRAM();␊ |
2366 | ␉␉␉break;␊ |
2367 | ␉␉}␊ |
2368 | ␉}␊ |
2369 | }␊ |
2370 | ␊ |
2371 | static void animateProgressBar()␊ |
2372 | {␊ |
2373 | ␉int y;␊ |
2374 | ␉␊ |
2375 | ␉if( time18() > (unsigned) lasttime)␊ |
2376 | ␉{␊ |
2377 | ␉␉lasttime = time18();␊ |
2378 | ␉␉␊ |
2379 | ␉␉pixmap_t *buffBar = images[iProgressBar].image;␊ |
2380 | ␉␉␊ |
2381 | ␉␉uint32_t buff = buffBar->pixels[0].value;␊ |
2382 | ␉␉␊ |
2383 | ␉␉memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );␊ |
2384 | ␉␉␊ |
2385 | ␉␉for( y = buffBar->height - 1; y > 0; y--)␊ |
2386 | ␉␉␉pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);␊ |
2387 | ␉␉␊ |
2388 | ␉␉pixel(buffBar, buffBar->width-1, 0).value = buff;␊ |
2389 | ␉}␊ |
2390 | }␊ |
2391 | ␊ |
2392 | static void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)␊ |
2393 | {␊ |
2394 | ␉if(progress>100)␊ |
2395 | ␉␉return;␊ |
2396 | ␉␊ |
2397 | ␉p.x = ( p.x - ( width / 2 ) );␊ |
2398 | ␉␊ |
2399 | ␉int todraw = (width * progress) / 100;␊ |
2400 | ␉␊ |
2401 | ␉pixmap_t *buff = images[iProgressBar].image;␊ |
2402 | ␉pixmap_t *buffBG = images[iProgressBarBackground].image;␊ |
2403 | ␉if(!buff || !buffBG)␊ |
2404 | ␉␉return;␊ |
2405 | ␉␊ |
2406 | ␉pixmap_t progressbar;␊ |
2407 | ␉progressbar.pixels=malloc(width * 4 * buff->height);␊ |
2408 | ␉if(!progressbar.pixels)␊ |
2409 | ␉␉return; ␊ |
2410 | ␉␊ |
2411 | ␉progressbar.width = width;␊ |
2412 | ␉progressbar.height = buff->height;␊ |
2413 | ␉␊ |
2414 | ␉int x,x2,y;␊ |
2415 | ␉␊ |
2416 | ␉for(y=0; y<buff->height; y++)␊ |
2417 | ␉{␊ |
2418 | ␉␉for(x=0,x2=0; x<todraw; x++, x2++)␊ |
2419 | ␉␉{␊ |
2420 | ␉␉␉if(x2 == (buff->width-1)) x2=0;␊ |
2421 | ␉␉␉pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;␊ |
2422 | ␉␉}␊ |
2423 | ␉}␊ |
2424 | ␉␊ |
2425 | ␉for(y=0; y<buff->height; y++)␊ |
2426 | ␉{␊ |
2427 | ␉␉for(x=todraw, x2 = 0; x < width - 1; x++, x2++)␊ |
2428 | ␉␉{␊ |
2429 | ␉␉␉if(x2 == (buffBG->width -2 )) x2 = 0;␊ |
2430 | ␉␉␉pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;␊ |
2431 | ␉␉}␊ |
2432 | ␉␉if(progress < 100)␊ |
2433 | ␉␉␉pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
2434 | ␉␉if(progress == 0)␊ |
2435 | ␉␉␉pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
2436 | ␉}␊ |
2437 | ␉␊ |
2438 | ␉blend(&progressbar, blendInto, p);␊ |
2439 | ␉animateProgressBar();␊ |
2440 | ␉free(progressbar.pixels);␊ |
2441 | }␊ |
2442 | ␊ |
2443 | static void drawInfoMenuItems()␊ |
2444 | {␊ |
2445 | ␉int i,n;␊ |
2446 | ␉␊ |
2447 | ␉position_t position;␊ |
2448 | ␉␊ |
2449 | ␉pixmap_t *selection = images[iMenuSelection].image;␊ |
2450 | ␉␊ |
2451 | ␉pixmap_t *pbuff;␊ |
2452 | ␉␊ |
2453 | ␉fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);␊ |
2454 | ␉␊ |
2455 | ␉makeRoundedCorners(gui.menu.pixmap);␊ |
2456 | ␉␊ |
2457 | ␉uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;␊ |
2458 | ␉␊ |
2459 | ␉position = pos(0,0);␊ |
2460 | ␉␊ |
2461 | ␉for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)␊ |
2462 | ␉{␊ |
2463 | ␉␉if (i == infoMenuSelection)␊ |
2464 | ␉␉{␊ |
2465 | ␉␉␉blend(selection, gui.menu.pixmap, position);␊ |
2466 | ␉␉}␊ |
2467 | ␉␉␊ |
2468 | ␉␉pbuff = images[n].image;␊ |
2469 | ␉␉if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)␊ |
2470 | ␉␉{␊ |
2471 | ␉␉␉blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap, ␊ |
2472 | ␉␉␉␉ pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
2473 | ␉␉}␊ |
2474 | ␉␉else␊ |
2475 | ␉␉{␊ |
2476 | ␉␉␉blend( pbuff, gui.menu.pixmap, ␊ |
2477 | ␉␉␉␉ pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
2478 | ␉␉}␊ |
2479 | ␉␉␊ |
2480 | ␉␉drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap, ␊ |
2481 | ␉␉␉␉pos(position.x + (pbuff->width + gui.menu.hborder), ␊ |
2482 | ␉␉␉␉␉position.y + ((selection->height - font_console.height) / 2)));␊ |
2483 | ␉␉position.y += images[iMenuSelection].image->height;␊ |
2484 | ␉␉␊ |
2485 | ␉}␊ |
2486 | ␉␊ |
2487 | ␉gui.redraw = true;␊ |
2488 | }␊ |
2489 | ␊ |
2490 | int drawInfoMenu()␊ |
2491 | {␊ |
2492 | ␉drawInfoMenuItems();␊ |
2493 | ␉␊ |
2494 | ␉gui.menu.draw = true;␊ |
2495 | ␉␊ |
2496 | ␉updateVRAM();␊ |
2497 | ␉␊ |
2498 | ␉return 1;␊ |
2499 | }␊ |
2500 | ␊ |
2501 | int updateInfoMenu(int key)␊ |
2502 | {␊ |
2503 | ␉switch (key)␊ |
2504 | ␉{␊ |
2505 | ␉␉␉␊ |
2506 | ␉␉case kUpArrowkey:␉// up arrow␊ |
2507 | ␉␉␉if (infoMenuSelection > 0)␊ |
2508 | ␉␉␉{␊ |
2509 | ␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)␊ |
2510 | ␉␉␉␉{␊ |
2511 | ␉␉␉␉␉infoMenuSelection -= 4;␊ |
2512 | ␉␉␉␉}␊ |
2513 | ␉␉␉␉else␊ |
2514 | ␉␉␉␉{␊ |
2515 | ␉␉␉␉␉infoMenuSelection--;␊ |
2516 | ␉␉␉␉}␊ |
2517 | ␉␉␉␉drawInfoMenuItems();␊ |
2518 | ␉␉␉␉updateVRAM();␊ |
2519 | ␉␉␉␉␊ |
2520 | ␉␉␉} ␊ |
2521 | ␉␉␉else ␊ |
2522 | ␉␉␉{␊ |
2523 | ␉␉␉␉␊ |
2524 | ␉␉␉␉gui.menu.draw = false;␊ |
2525 | ␉␉␉␉gui.redraw = true;␊ |
2526 | ␉␉␉␉␊ |
2527 | ␉␉␉␉updateVRAM();␊ |
2528 | ␉␉␉␉␊ |
2529 | ␉␉␉␉return CLOSE_INFO_MENU;␊ |
2530 | ␉␉␉}␊ |
2531 | ␉␉␉break;␊ |
2532 | ␉␉␉␊ |
2533 | ␉␉case kDownArrowkey:␉// down arrow␊ |
2534 | ␉␉␉if (infoMenuSelection < infoMenuItemsCount - 1)␊ |
2535 | ␉␉␉{␊ |
2536 | ␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)␊ |
2537 | ␉␉␉␉␉infoMenuSelection += 4;␊ |
2538 | ␉␉␉␉else␊ |
2539 | ␉␉␉␉␉infoMenuSelection++;␊ |
2540 | ␉␉␉␉drawInfoMenuItems();␊ |
2541 | ␉␉␉␉updateVRAM();␊ |
2542 | ␉␉␉}␊ |
2543 | ␉␉␉break;␊ |
2544 | ␉␉␉␊ |
2545 | ␉␉case kReturnKey:␊ |
2546 | ␉␉␉if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )␊ |
2547 | ␉␉␉␉showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());␊ |
2548 | ␉␉␉␊ |
2549 | ␉␉␉else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )␊ |
2550 | ␉␉␉␉showInfoBox( getVBEInfoString(), getVBEModeInfoString() );␊ |
2551 | ␉␉␉␊ |
2552 | ␉␉␉else if( infoMenuSelection == MENU_SHOW_HELP )␊ |
2553 | ␉␉␉␉showHelp();␊ |
2554 | ␉␉␉␊ |
2555 | ␉␉␉else␊ |
2556 | ␉␉␉{␊ |
2557 | ␉␉␉␉int buff = infoMenuSelection;␊ |
2558 | ␉␉␉␉infoMenuSelection = 0;␊ |
2559 | ␉␉␉␉return buff;␊ |
2560 | ␉␉␉}␊ |
2561 | ␉␉␉break;␊ |
2562 | ␉␉default:␊ |
2563 | ␉␉␉break;␊ |
2564 | ␉}␊ |
2565 | ␉return DO_NOT_BOOT;␊ |
2566 | }␊ |
2567 | ␊ |
2568 | uint16_t bootImageWidth = 0; ␊ |
2569 | uint16_t bootImageHeight = 0; ␊ |
2570 | uint8_t *bootImageData = NULL; ␊ |
2571 | static bool usePngImage = false;␊ |
2572 | ␊ |
2573 | //==========================================================================␊ |
2574 | // loadBootGraphics␊ |
2575 | static void loadBootGraphics(char *src)␊ |
2576 | {␊ |
2577 | ␉if (bootImageData != NULL) {␊ |
2578 | ␉␉return;␊ |
2579 | ␉}␊ |
2580 | ␉␊ |
2581 | ␉char dirspec[256];␊ |
2582 | ␉␊ |
2583 | ␉if ((unsigned)(strlen(theme_name) + 34) > sizeof(dirspec)) {␊ |
2584 | ␉␉usePngImage = false; ␊ |
2585 | ␉␉return;␊ |
2586 | ␉}␊ |
2587 | ␉snprintf(dirspec, sizeof(dirspec), "%s/%s/boot.png", src, theme_name);␊ |
2588 | ␉if ((strlen(theme_name) == 0) || (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) == -1)) {␊ |
2589 | #ifdef EMBED_THEME␊ |
2590 | ␉␉if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) == -1)␊ |
2591 | #endif␊ |
2592 | ␉␉␉usePngImage = false; ␊ |
2593 | ␉}␊ |
2594 | }␊ |
2595 | ␊ |
2596 | //==========================================================================␊ |
2597 | // drawBootGraphics␊ |
2598 | void drawBootGraphics(void)␊ |
2599 | {␊ |
2600 | ␉int pos;␊ |
2601 | ␉int length;␊ |
2602 | ␉const char *dummyVal;␊ |
2603 | ␉int oldScreenWidth, oldScreenHeight;␊ |
2604 | ␉uint16_t x, y; ␊ |
2605 | ␉bool legacy_logo = false;␊ |
2606 | ␉getBoolForKey("Legacy Logo", &legacy_logo, DEFAULT_BOOT_CONFIG);␉␊ |
2607 | ␉if (legacy_logo == false) {␊ |
2608 | ␉␉usePngImage = true;␊ |
2609 | ␉␉␊ |
2610 | ␉␉if (bootImageData == NULL)␊ |
2611 | ␉␉␉loadBootGraphics(dirsrc);␊ |
2612 | ␉␉␊ |
2613 | ␉}␉␉␊ |
2614 | ␉␊ |
2615 | ␉␊ |
2616 | ␉if (execute_hook("getResolution_hook", &screen_params[0], &screen_params[1], &screen_params[2], NULL, NULL, NULL) != EFI_SUCCESS)␉␉␊ |
2617 | ␉{␉␉␊ |
2618 | ␉␉// parse screen size parameters␊ |
2619 | ␉␉if (getIntForKey("boot_width", &pos, &themeConfig) && pos > 0) {␊ |
2620 | ␉␉␉screen_params[0] = pos;␊ |
2621 | ␉␉} else {␊ |
2622 | ␉␉␉screen_params[0] = DEFAULT_SCREEN_WIDTH;␊ |
2623 | ␉␉}␊ |
2624 | ␉␉if (getIntForKey("boot_height", &pos, &themeConfig) && pos > 0) {␊ |
2625 | ␉␉␉screen_params[1] = pos;␊ |
2626 | ␉␉} else {␊ |
2627 | ␉␉␉screen_params[1] = DEFAULT_SCREEN_HEIGHT;␊ |
2628 | ␉␉}␊ |
2629 | ␉}␉␊ |
2630 | ␉␊ |
2631 | // Save current screen resolution.␊ |
2632 | ␉oldScreenWidth = gui.screen.width;␊ |
2633 | ␉oldScreenHeight = gui.screen.height;␊ |
2634 | ␉␊ |
2635 | ␉gui.screen.width = screen_params[0];␊ |
2636 | ␉gui.screen.height = screen_params[1];␊ |
2637 | ␉␊ |
2638 | ␉// find best matching vesa mode for our requested width & height␊ |
2639 | ␉getGraphicModeParams(screen_params);␊ |
2640 | ␉␊ |
2641 | // Set graphics mode if the booter was in text mode or the screen resolution has changed.␊ |
2642 | ␉if (getVideoMode() == VGA_TEXT_MODE␊ |
2643 | ␉␉|| (screen_params[0] != (uint32_t)oldScreenWidth && screen_params[1] != (uint32_t)oldScreenHeight) )␊ |
2644 | ␉{␊ |
2645 | ␊ |
2646 | ␉␉setVideoMode(GRAPHICS_MODE);␊ |
2647 | ␊ |
2648 | ␉}␊ |
2649 | ␉␊ |
2650 | ␉if (getValueForKey("-checkers", &dummyVal, &length, DEFAULT_BOOT_CONFIG)) {␊ |
2651 | ␉␉drawCheckerBoard();␊ |
2652 | ␉} else {␊ |
2653 | ␉␉// Fill the background to 75% grey (same as BootX). ␊ |
2654 | ␉␉drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01); ␊ |
2655 | ␉}␊ |
2656 | ␉if ((bootImageData) && (usePngImage)) { ␊ |
2657 | ␉␉x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2; ␊ |
2658 | ␉␉y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2; ␊ |
2659 | ␉␉␊ |
2660 | ␉␉// Draw the image in the center of the display. ␊ |
2661 | ␉␉blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData); ␊ |
2662 | ␉} else { ␊ |
2663 | ␉␉uint8_t *appleBootPict; ␊ |
2664 | ␉␉bootImageData = NULL; ␊ |
2665 | ␉␉bootImageWidth = kAppleBootWidth; ␊ |
2666 | ␉␉bootImageHeight = kAppleBootHeight; ␊ |
2667 | ␉␉␊ |
2668 | ␉␉// Prepare the data for the default Apple boot image. ␊ |
2669 | ␉␉appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight); ␊ |
2670 | ␉␉if (appleBootPict) { ␊ |
2671 | ␉␉␉if (convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData) == 0)␊ |
2672 | {␊ |
2673 | if (bootImageData) {␉␊ |
2674 | x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2; ␊ |
2675 | y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2; ␊ |
2676 | drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);␊ |
2677 | free(bootImageData);␊ |
2678 | }␊ |
2679 | }␉␉␉␊ |
2680 | ␉␉␉free(appleBootPict); ␊ |
2681 | ␉␉} ␊ |
2682 | ␉} ␊ |
2683 | }␊ |
2684 | ␊ |
2685 | int GUI_initGraphicsMode (void)␊ |
2686 | {␊ |
2687 | ␉unsigned long params[4];␊ |
2688 | ␉int count;␊ |
2689 | ␉␊ |
2690 | ␉params[3] = 0;␊ |
2691 | ␉count = getNumberArrayFromProperty( kGraphicsModeKey, params, 4 );␊ |
2692 | ␉␊ |
2693 | ␉// Try to find a resolution if "Graphics Mode" setting is not available.␊ |
2694 | ␉if ( count < 3 )␊ |
2695 | ␉{␊ |
2696 | ␉␉// Use the default resolution if we don't have an initialized GUI.␊ |
2697 | ␉␉if (gui.screen.width == 0 || gui.screen.height == 0)␊ |
2698 | ␉␉{␊ |
2699 | ␉␉␉gui.screen.width = DEFAULT_SCREEN_WIDTH;␉␊ |
2700 | ␉␉␉gui.screen.height = DEFAULT_SCREEN_HEIGHT;␊ |
2701 | ␉␉}␊ |
2702 | ␉␉␊ |
2703 | ␉␉params[0] = gui.screen.width;␊ |
2704 | ␉␉params[1] = gui.screen.height;␊ |
2705 | ␉␉params[2] = 32;␊ |
2706 | ␉}␊ |
2707 | ␉␊ |
2708 | ␉// Map from pixel format to bits per pixel.␊ |
2709 | ␉␊ |
2710 | ␉if ( params[2] == 256 ) params[2] = 8;␊ |
2711 | ␉if ( params[2] == 555 ) params[2] = 16;␊ |
2712 | ␉if ( params[2] == 888 ) params[2] = 32;␊ |
2713 | ␉␊ |
2714 | ␉return setVESAGraphicsMode( params[0], params[1], params[2] );␊ |
2715 | ␊ |
2716 | }␊ |
2717 | ␊ |
2718 | ␊ |
2719 | int GUI_countdown( const char * msg, register int row, register int timeout , int *optionKey)␊ |
2720 | {␊ |
2721 | register unsigned long time;␊ |
2722 | int ch = 0;␊ |
2723 | register int col = strlen(msg) + 1;␊ |
2724 | ␉␊ |
2725 | flushKeyboardBuffer();␊ |
2726 | ␉␊ |
2727 | ␉if( getVideoMode() == VGA_TEXT_MODE )␊ |
2728 | ␉{␊ |
2729 | ␉␉moveCursor( 0, row );␊ |
2730 | ␉␉printf(msg);␊ |
2731 | ␉␉␊ |
2732 | ␉} else {␊ |
2733 | ␉␉␊ |
2734 | ␉␉position_t p = pos( gui.screen.width / 2 + 1 , ( gui.devicelist.pos.y + 3 ) + ( ( gui.devicelist.height - gui.devicelist.iconspacing ) / 2 ) );␊ |
2735 | ␉␉␊ |
2736 | ␉␉char dummy[80];␊ |
2737 | ␉␉getBootVolumeDescription( ((BVRef)(uint32_t)get_env(envgBootVolume)), dummy, sizeof(dummy) - 1, true );␊ |
2738 | ␉␉drawDeviceIcon( ((BVRef)(uint32_t)get_env(envgBootVolume)), gui.screen.pixmap, p, true );␊ |
2739 | ␉␉drawStrCenteredAt( (char *) msg, &font_small, gui.screen.pixmap, gui.countdown.pos );␊ |
2740 | ␉␉␊ |
2741 | ␉␉// make this screen the new background␊ |
2742 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
2743 | ␉␉␊ |
2744 | ␉}␊ |
2745 | ␉␊ |
2746 | ␉int multi_buff = 18 * (timeout);␊ |
2747 | int multi = ++multi_buff;␊ |
2748 | ␉␊ |
2749 | int lasttime=0;␊ |
2750 | ␉␊ |
2751 | for ( time = time18(), timeout++; timeout > 0; )␊ |
2752 | {␊ |
2753 | ␉␉␊ |
2754 | ␉␉if( time18() > (unsigned)lasttime)␊ |
2755 | ␉␉{␊ |
2756 | ␉␉␉multi--; ␊ |
2757 | ␉␉␉lasttime=time18();␊ |
2758 | ␉␉}␉␉␊ |
2759 | ␉␉␊ |
2760 | if ((ch = readKeyboardStatus())){␊ |
2761 | *optionKey = ch; ␊ |
2762 | break;␊ |
2763 | ␉␉}␊ |
2764 | ␉␉␊ |
2765 | // Count can be interrupted by holding down shift,␊ |
2766 | // control or alt key␊ |
2767 | if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 )␊ |
2768 | ␉␉{␊ |
2769 | ch = 1;␊ |
2770 | break;␊ |
2771 | }␊ |
2772 | ␉␉␊ |
2773 | if ( time18() >= time )␊ |
2774 | {␊ |
2775 | time += 18;␊ |
2776 | timeout--;␊ |
2777 | ␉␉␉␊ |
2778 | ␉␉␉if( getVideoMode() == VGA_TEXT_MODE )␊ |
2779 | ␉␉␉{␊ |
2780 | ␉␉␉␉moveCursor( col, row );␊ |
2781 | ␉␉␉␉printf("(%d) ", timeout);␊ |
2782 | ␉␉␉}␊ |
2783 | }␊ |
2784 | ␉␉␊ |
2785 | ␉␉if( getVideoMode() == GRAPHICS_MODE )␊ |
2786 | ␉␉{␊ |
2787 | ␉␉␉drawProgressBar( gui.screen.pixmap, 100, gui.progressbar.pos , ( multi * 100 / multi_buff ) );␊ |
2788 | ␉␉␉gui.redraw = true;␊ |
2789 | ␉␉␉updateVRAM();␊ |
2790 | ␉␉}␊ |
2791 | ␉␉␊ |
2792 | }␊ |
2793 | ␉␊ |
2794 | flushKeyboardBuffer();␊ |
2795 | ␉␊ |
2796 | return ch;␊ |
2797 | }␊ |
2798 | |