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