Chameleon

Chameleon Svn Source Tree

Root/branches/meklort/i386/modules/GUI/gui.c

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

Archive Download this file

Revision: 531