Chameleon

Chameleon Svn Source Tree

Root/branches/slice/trunkM/i386/boot2/gui.c

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

Archive Download this file

Revision: 1184