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