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