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