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