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