Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/trunkGraphicsEnablerModules/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->bootConfig );
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];
715
716// load graphics otherwise fail and return
717if (loadGraphics() == 0) {
718loadThemeValues(&bootInfo->themeConfig);
719colorFont(&font_small, gui.screen.font_small_color);
720colorFont(&font_console, gui.screen.font_console_color);
721
722// create the screen & window buffers
723if (createBackBuffer(&gui.screen) == 0) {
724if (createWindowBuffer(&gui.screen) == 0) {
725if (createWindowBuffer(&gui.devicelist) == 0) {
726if (createWindowBuffer(&gui.bootprompt) == 0) {
727if (createWindowBuffer(&gui.infobox) == 0) {
728if (createWindowBuffer(&gui.menu) == 0) {
729 gui.logo.draw = true;
730drawBackground();
731// lets copy the screen into the back buffer
732memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
733setVideoMode( GRAPHICS_MODE, 0 );
734gui.initialised = true;
735return 0;
736}
737}
738}
739}
740}
741}
742}
743return 1;
744}
745
746void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected)
747{
748int devicetype;
749
750if( diskIsCDROM(device) )
751devicetype = iDeviceCDROM;// Use CDROM icon
752else
753{
754switch (device->part_type)
755{
756case kPartitionTypeHFS:
757
758// Use HFS or HFSRAID icon depending on bvr flags.
759devicetype = (device->flags & kBVFlagBooter) ? iDeviceHFSRAID : iDeviceHFS;
760break;
761
762case kPartitionTypeHPFS:
763devicetype = iDeviceNTFS;// Use HPFS / NTFS icon
764break;
765
766case kPartitionTypeFAT16:
767devicetype = iDeviceFAT16;// Use FAT16 icon
768break;
769
770case kPartitionTypeFAT32:
771devicetype = iDeviceFAT32;// Use FAT32 icon
772break;
773
774case kPartitionTypeEXT3:
775devicetype = iDeviceEXT3;// Use EXT2/3 icon
776break;
777
778default:
779devicetype = iDeviceGeneric;// Use Generic icon
780break;
781}
782}
783
784// Draw the selection image and use the next (device_*_o) image for the selected item.
785 if (isSelected)
786{
787blend(images[iSelection].image, buffer, centeredAt(images[iSelection].image, p));
788devicetype++;
789}
790
791// draw icon
792blend( images[devicetype].image, buffer, centeredAt( images[devicetype].image, p ));
793
794p.y += (images[iSelection].image->height / 2) + font_console.chars[0]->height;
795
796// draw volume label
797drawStrCenteredAt( device->label, &font_small, buffer, p);
798
799}
800
801void drawDeviceList (int start, int end, int selection)
802{
803int i;
804position_t p, p_prev, p_next;
805
806//uint8_tmaxDevices = MIN( gui.maxdevices, menucount );
807
808fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);
809
810makeRoundedCorners( gui.devicelist.pixmap);
811
812switch (gui.layout)
813{
814
815case VerticalLayout:
816p.x = (gui.devicelist.width /2);
817p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );
818
819// place scroll indicators at top & bottom edges
820p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );
821p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );
822
823break;
824
825default:// use Horizontal layout as the default
826
827case HorizontalLayout:
828p.x = (gui.devicelist.width - ( gui.devicelist.width / gui.maxdevices ) * gui.maxdevices ) / 2 + ( images[iSelection].image->width / 2) + images[iDeviceScrollPrev].image->width + gui.devicelist.iconspacing;
829p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );
830
831// place scroll indicators at left & right edges
832p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );
833p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );
834
835break;
836
837}
838
839// draw visible device icons
840for (i = 0; i < gui.maxdevices; i++)
841{
842BVRef param = menuItems[start + i].param;
843
844 bool isSelected = ((start + i) == selection) ? true : false;
845if (isSelected)
846{
847 if (param->flags & kBVFlagNativeBoot)
848 {
849 infoMenuNativeBoot = true;
850 }
851 else
852 {
853 infoMenuNativeBoot = false;
854 if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)
855 infoMenuSelection = 0;
856 }
857
858if(gui.menu.draw)
859drawInfoMenuItems();
860
861#if DEBUG
862 gui.debug.cursor = pos( 10, 100);
863 dprintf( &gui.screen, "label %s\n", param->label );
864 dprintf( &gui.screen, "biosdev 0x%x\n", param->biosdev );
865 dprintf(&gui.screen, "width %d\n", gui.screen.width);
866 dprintf(&gui.screen, "height %d\n", gui.screen.height);
867 dprintf( &gui.screen, "type 0x%x\n", param->type );
868 dprintf( &gui.screen, "flags 0x%x\n", param->flags );
869 dprintf( &gui.screen, "part_no %d\n", param->part_no );
870 dprintf( &gui.screen, "part_boff 0x%x\n", param->part_boff );
871 dprintf( &gui.screen, "part_type 0x%x\n", param->part_type );
872 dprintf( &gui.screen, "bps 0x%x\n", param->bps );
873 dprintf( &gui.screen, "name %s\n", param->name );
874 dprintf( &gui.screen, "type_name %s\n", param->type_name );
875 dprintf( &gui.screen, "modtime %d\n", param->modTime );
876#endif
877}
878
879drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);
880
881if (gui.layout == HorizontalLayout)
882{
883p.x += images[iSelection].image->width + gui.devicelist.iconspacing;
884}
885if (gui.layout == VerticalLayout)
886{
887p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing );
888}
889}
890
891// draw prev indicator
892if(start)
893blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );
894
895// draw next indicator
896if( end < gDeviceCount - 1 )
897blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );
898
899gui.redraw = true;
900
901updateVRAM();
902
903}
904
905void clearGraphicBootPrompt()
906{
907// clear text buffer
908//prompt[0] = '\0';
909//prompt_pos=0;
910
911
912if(gui.bootprompt.draw == true )
913{
914gui.bootprompt.draw = false;
915gui.redraw = true;
916// this causes extra frames to be drawn
917//updateVRAM();
918}
919
920return;
921}
922
923void updateGraphicBootPrompt()
924{
925fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);
926
927makeRoundedCorners( gui.bootprompt.pixmap);
928
929position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );
930
931// print the boot prompt text
932drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);
933
934// get the position of the end of the boot prompt text to display user input
935position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );
936
937drawStr( gBootArgs, &font_console, gui.bootprompt.pixmap, p_prompt);
938
939gui.menu.draw = false;
940gui.bootprompt.draw = true;
941gui.redraw = true;
942
943updateVRAM();
944
945return;
946}
947
948inline
949void vramwrite (void *data, int width, int height)
950{
951if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)
952memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
953else
954{
955uint32_t r, g, b;
956int i, j;
957for (i = 0; i < VIDEO (height); i++)
958for (j = 0; j < VIDEO (width); j++)
959{
960b = ((uint8_t *) data)[4*i*width + 4*j];
961g = ((uint8_t *) data)[4*i*width + 4*j + 1];
962r = ((uint8_t *) data)[4*i*width + 4*j + 2];
963switch (VIDEO (depth))
964{
965case 32:
966*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
967break;
968case 24:
969*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)
970| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
971break;
972case 16:
973// Somehow 16-bit is always 15-bits really
974//*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);
975//break;
976case 15:
977*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);
978break;
979}
980}
981}
982}
983
984void updateVRAM()
985{
986if (gui.redraw)
987{
988if (gui.devicelist.draw)
989blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
990
991if (gui.bootprompt.draw)
992blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
993
994if (gui.menu.draw)
995blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
996
997if (gui.infobox.draw)
998blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
999}
1000
1001vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
1002
1003if (gui.redraw)
1004{
1005memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
1006gui.redraw = false;
1007}
1008}
1009
1010struct putc_info //Azi: exists on console.c & printf.c
1011{
1012 char * str;
1013 char * last_str;
1014};
1015
1016static int
1017sputc(int c, struct putc_info * pi) //Azi: same as above
1018{
1019 if (pi->last_str)
1020 if (pi->str == pi->last_str) {
1021 *(pi->str) = '\0';
1022 return 0;
1023 }
1024 *(pi->str)++ = c;
1025 return c;
1026}
1027
1028int gprintf( window_t * window, const char * fmt, ...)
1029{
1030char *formattedtext;
1031
1032va_list ap;
1033
1034struct putc_info pi;
1035
1036if ((formattedtext = malloc(1024)) != NULL) {
1037// format the text
1038va_start(ap, fmt);
1039pi.str = formattedtext;
1040pi.last_str = 0;
1041prf(fmt, ap, sputc, &pi);
1042*pi.str = '\0';
1043va_end(ap);
1044
1045position_torigin, cursor, bounds;
1046
1047int i;
1048int character;
1049
1050origin.x = MAX( window->cursor.x, window->hborder );
1051origin.y = MAX( window->cursor.y, window->vborder );
1052
1053bounds.x = ( window->width - window->hborder );
1054bounds.y = ( window->height - window->vborder );
1055
1056cursor = origin;
1057
1058font_t *font = &font_console;
1059
1060for( i=0; i< strlen(formattedtext); i++ )
1061{
1062character = formattedtext[i];
1063
1064character -= 32;
1065
1066// newline ?
1067if( formattedtext[i] == '\n' )
1068{
1069cursor.x = window->hborder;
1070cursor.y += font->height;
1071
1072if ( cursor.y > bounds.y )
1073cursor.y = origin.y;
1074
1075continue;
1076}
1077
1078// tab ?
1079if( formattedtext[i] == '\t' )
1080cursor.x += ( font->chars[0]->width * 5 );
1081
1082// draw the character
1083if( font->chars[character])
1084blend(font->chars[character], window->pixmap, cursor);
1085
1086cursor.x += font->chars[character]->width;
1087
1088// check x pos and do newline
1089if ( cursor.x > bounds.x )
1090{
1091cursor.x = origin.x;
1092cursor.y += font->height;
1093}
1094
1095// check y pos and reset to origin.y
1096if ( cursor.y > bounds.y )
1097cursor.y = origin.y;
1098}
1099
1100// update cursor postition
1101window->cursor = cursor;
1102
1103free(formattedtext);
1104
1105return 0;
1106
1107}
1108return 1;
1109}
1110
1111int dprintf( window_t * window, const char * fmt, ...)
1112{
1113char *formattedtext;
1114
1115va_list ap;
1116
1117//window = &gui.debug;
1118
1119struct putc_info pi;
1120
1121if ((formattedtext = malloc(1024)) != NULL) {
1122// format the text
1123va_start(ap, fmt);
1124pi.str = formattedtext;
1125pi.last_str = 0;
1126prf(fmt, ap, sputc, &pi);
1127*pi.str = '\0';
1128va_end(ap);
1129
1130position_torigin, cursor, bounds;
1131
1132int i;
1133int character;
1134
1135origin.x = MAX( gui.debug.cursor.x, window->hborder );
1136origin.y = MAX( gui.debug.cursor.y, window->vborder );
1137
1138bounds.x = ( window->width - window->hborder );
1139bounds.y = ( window->height - window->vborder );
1140
1141cursor = origin;
1142
1143font_t *font = &font_console;
1144
1145for( i=0; i< strlen(formattedtext); i++ )
1146{
1147character = formattedtext[i];
1148
1149character -= 32;
1150
1151// newline ?
1152if( formattedtext[i] == '\n' )
1153{
1154cursor.x = window->hborder;
1155cursor.y += font->height;
1156
1157if ( cursor.y > bounds.y )
1158cursor.y = origin.y;
1159
1160continue;
1161}
1162
1163// tab ?
1164if( formattedtext[i] == '\t' )
1165cursor.x += ( font->chars[0]->width * 5 );
1166
1167// draw the character
1168if( font->chars[character])
1169blend(font->chars[character], gui.backbuffer, cursor);
1170
1171cursor.x += font->chars[character]->width;
1172
1173// check x pos and do newline
1174if ( cursor.x > bounds.x )
1175{
1176cursor.x = origin.x;
1177cursor.y += font->height;
1178}
1179
1180// check y pos and reset to origin.y
1181if ( cursor.y > bounds.y )
1182cursor.y = origin.y;
1183}
1184
1185// update cursor postition
1186gui.debug.cursor = cursor;
1187
1188free(formattedtext);
1189
1190return 0;
1191
1192}
1193return 1;
1194}
1195
1196int vprf(const char * fmt, va_list ap)
1197{
1198int i;
1199int character;
1200
1201char *formattedtext;
1202window_t *window = &gui.screen;
1203struct putc_info pi;
1204
1205position_torigin, cursor, bounds;
1206font_t *font = &font_console;
1207
1208if ((formattedtext = malloc(1024)) != NULL) {
1209// format the text
1210pi.str = formattedtext;
1211pi.last_str = 0;
1212prf(fmt, ap, sputc, &pi);
1213*pi.str = '\0';
1214
1215origin.x = MAX( window->cursor.x, window->hborder );
1216origin.y = MAX( window->cursor.y, window->vborder );
1217bounds.x = ( window->width - ( window->hborder * 2 ) );
1218bounds.y = ( window->height - ( window->vborder * 2 ) );
1219cursor = origin;
1220
1221for( i=0; i< strlen(formattedtext); i++ )
1222{
1223character = formattedtext[i];
1224character -= 32;
1225
1226// newline ?
1227if( formattedtext[i] == '\n' )
1228{
1229cursor.x = window->hborder;
1230cursor.y += font->height;
1231if ( cursor.y > bounds.y )
1232{
1233gui.redraw = true;
1234updateVRAM();
1235cursor.y = window->vborder;
1236}
1237window->cursor.y = cursor.y;
1238continue;
1239}
1240
1241// tab ?
1242if( formattedtext[i] == '\t' )
1243{
1244cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
1245continue;
1246}
1247cursor.x += font->chars[character]->width;
1248
1249// check x pos and do newline
1250if ( cursor.x > bounds.x )
1251{
1252cursor.x = origin.x;
1253cursor.y += font->height;
1254}
1255
1256// check y pos and reset to origin.y
1257if ( cursor.y > ( bounds.y + font->chars[0]->height) )
1258{
1259gui.redraw = true;
1260updateVRAM();
1261cursor.y = window->vborder;
1262}
1263// draw the character
1264if( font->chars[character])
1265blend(font->chars[character], gui.backbuffer, cursor);
1266}
1267// save cursor postition
1268window->cursor.x = cursor.x;
1269updateVRAM();
1270free(formattedtext);
1271return 0;
1272}
1273return 1;
1274}
1275
1276void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)
1277{
1278int i=0;
1279int y=0; // we need this to support multilines '\n'
1280int x=0;
1281
1282for(i=0;i<strlen(ch);i++)
1283{
1284int cha=(int)ch[i];
1285
1286cha-=32;
1287
1288// newline ?
1289if( ch[i] == '\n' )
1290{
1291x = 0;
1292y += font->height;
1293continue;
1294}
1295
1296// tab ?
1297if( ch[i] == '\t' )
1298x+=(font->chars[0]->width*5);
1299
1300if(font->chars[cha])
1301blend(font->chars[cha], blendInto, pos(p.x+x, p.y+y));
1302
1303x += font->chars[cha]->width;
1304}
1305}
1306
1307void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)
1308{
1309int i = 0;
1310int width = 0;
1311
1312// calculate the width in pixels
1313for(i=0;i<strlen(text);i++)
1314width += font->chars[text[i]-32]->width;
1315
1316p.x = ( p.x - ( width / 2 ) );
1317p.y = ( p.y - ( font->height / 2 ) );
1318
1319if ( p.x == -6 )
1320{
1321p.x = 0;
1322}
1323
1324for(i=0;i<strlen(text);i++)
1325{
1326int cha=(int)text[i];
1327
1328cha-=32;
1329
1330if(font->chars[cha])
1331{
1332blend(font->chars[cha], blendInto, p);
1333p.x += font->chars[cha]->width;
1334}
1335}
1336
1337}
1338
1339int initFont(font_t *font, image_t *data)
1340{
1341unsigned int x = 0, y = 0, x2 = 0, x3 = 0;
1342
1343int start = 0, end = 0, count = 0, space = 0;
1344
1345bool monospaced = false;
1346
1347font->height = data->image->height;
1348
1349for( x = 0; x < data->image->width; x++)
1350{
1351start = end;
1352
1353// if the pixel is red we've reached the end of the char
1354if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
1355{
1356end = x + 1;
1357
1358if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
1359{
1360font->chars[count]->width = ( end - start) - 1;
1361font->chars[count]->height = font->height;
1362
1363if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
1364{
1365space += ( font->chars[count]->width * data->image->height * 4 );
1366// we skip the first line because there are just the red pixels for the char width
1367for( y = 1; y< (font->height); y++)
1368{
1369for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
1370{
1371pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
1372}
1373}
1374
1375// check if font is monospaced
1376if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
1377monospaced = true;
1378
1379font->width = font->chars[count]->width;
1380
1381count++;
1382}
1383}
1384}
1385}
1386
1387if(monospaced)
1388font->width = 0;
1389
1390return 0;
1391}
1392
1393void colorFont(font_t *font, uint32_t color)
1394{
1395if( !color )
1396return;
1397
1398int x, y, width, height;
1399int count = 0;
1400pixel_t *buff;
1401
1402while( font->chars[count++] )
1403{
1404width = font->chars[count-1]->width;
1405height = font->chars[count-1]->height;
1406for( y = 0; y < height; y++ )
1407{
1408for( x = 0; x < width; x++ )
1409{
1410buff = &(pixel( font->chars[count-1], x, y ));
1411if( buff->ch.a )
1412{
1413buff->ch.r = (color & 0xFFFF0000) >> 16;
1414buff->ch.g = (color & 0xFF00FF00) >> 8;
1415buff->ch.b = (color & 0xFF0000FF);
1416}
1417}
1418}
1419}
1420}
1421
1422void makeRoundedCorners(pixmap_t *p)
1423{
1424int x,y;
1425int width=p->width-1;
1426int height=p->height-1;
1427
1428// 10px rounded corner alpha values
1429uint8_t roundedCorner[10][10] =
1430{
1431{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},
1432{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},
1433{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1434{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1435{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1436{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1437{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1438{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1439{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1440{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
1441};
1442
1443uint8_t alpha=0;
1444
1445for( y=0; y<10; y++)
1446{
1447for( x=0; x<10; x++)
1448{
1449// skip if the pixel should be visible
1450if(roundedCorner[y][x] != 0xFF)
1451{
1452alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
1453// Upper left corner
1454pixel(p, x, y).ch.a = alpha;
1455
1456// upper right corner
1457pixel(p, width-x,y).ch.a = alpha;
1458
1459// lower left corner
1460pixel(p, x, height-y).ch.a = alpha;
1461
1462// lower right corner
1463pixel(p, width-x, height-y).ch.a = alpha;
1464}
1465}
1466}
1467}
1468
1469void showInfoBox(char *title, char *text)
1470{
1471int i, key, lines, visiblelines;
1472
1473int currentline=0;
1474int cnt=0;
1475int offset=0;
1476
1477if( !title || !text )
1478return;
1479
1480position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );
1481
1482// calculate number of lines in the title
1483for ( i = 0, lines = 1; i<strlen(title); i++ )
1484if( title[i] == '\n')
1485lines++;
1486
1487// y position of text is lines in title * height of font
1488position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));
1489
1490// calculate number of lines in the text
1491for ( i=0, lines = 1; i<strlen(text); i++ )
1492if( text[i] == '\n')
1493lines++;
1494
1495// if text ends with \n strip off
1496if( text[i] == '\n' || text[i] == '\0')
1497lines--;
1498
1499visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
1500
1501// lets display the text and allow scroll thru using up down / arrows
1502while(1)
1503{
1504// move to current line in text
1505for( offset = 0, i = 0; offset < strlen(text); offset++ )
1506{
1507if( currentline == i)
1508break;
1509if( text[offset] =='\n')
1510i++;
1511}
1512
1513// find last visible line in text and place \0
1514for( i = offset, cnt = 0; i < strlen(text); i++)
1515{
1516if(text[i]=='\n')
1517cnt++;
1518if ( cnt == visiblelines )
1519{
1520text[i]='\0';
1521break;
1522}
1523}
1524
1525fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);
1526
1527makeRoundedCorners( gui.infobox.pixmap);
1528
1529// print the title if present
1530if( title )
1531drawStr(title, &font_console, gui.infobox.pixmap, pos_title);
1532
1533// print the text
1534drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);
1535
1536// restore \n in text
1537if ( cnt == visiblelines )
1538text[i] = '\n';
1539
1540position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
1541
1542// draw prev indicator
1543if(offset)
1544{
1545blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
1546}
1547
1548// draw next indicator
1549if( lines > ( currentline + visiblelines ) )
1550{
1551pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
1552blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
1553}
1554
1555gui.bootprompt.draw = false;
1556gui.infobox.draw = true;
1557gui.redraw = true;
1558
1559updateVRAM();
1560
1561key = getchar();
1562
1563if( key == kUpArrowkey )
1564if( currentline > 0 )
1565currentline--;
1566
1567if( key == kDownArrowkey )
1568if( lines > ( currentline + visiblelines ) )
1569currentline++;
1570
1571if( key == kEscapeKey || key == 'q' || key == 'Q')
1572{
1573gui.infobox.draw = false;
1574gui.redraw = true;
1575updateVRAM();
1576break;
1577}
1578}
1579}
1580
1581void animateProgressBar()
1582{
1583int y;
1584
1585if( time18() > lasttime)
1586{
1587lasttime = time18();
1588
1589pixmap_t *buffBar = images[iProgressBar].image;
1590
1591uint32_t buff = buffBar->pixels[0].value;
1592
1593memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );
1594
1595for( y = buffBar->height - 1; y > 0; y--)
1596pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);
1597
1598pixel(buffBar, buffBar->width-1, 0).value = buff;
1599}
1600}
1601
1602void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)
1603{
1604if(progress>100)
1605return;
1606
1607p.x = ( p.x - ( width / 2 ) );
1608
1609int todraw = (width * progress) / 100;
1610
1611pixmap_t *buff = images[iProgressBar].image;
1612pixmap_t *buffBG = images[iProgressBarBackground].image;
1613if(!buff || !buffBG)
1614return;
1615
1616pixmap_t progressbar;
1617progressbar.pixels=malloc(width * 4 * buff->height);
1618if(!progressbar.pixels)
1619return;
1620
1621progressbar.width = width;
1622progressbar.height = buff->height;
1623
1624int x=0,x2=0,y=0;
1625
1626for(y=0; y<buff->height; y++)
1627{
1628for(x=0; x<todraw; x++, x2++)
1629{
1630if(x2 == (buff->width-1)) x2=0;
1631pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;
1632}
1633x2=0;
1634}
1635
1636for(y=0; y<buff->height; y++)
1637{
1638for(x=todraw, x2 = 0; x < width - 1; x++, x2++)
1639{
1640if(x2 == (buffBG->width -2 )) x2 = 0;
1641pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;
1642}
1643if(progress < 100)
1644pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1645if(progress == 0)
1646pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1647x2=0;
1648}
1649
1650blend(&progressbar, blendInto, p);
1651animateProgressBar();
1652free(progressbar.pixels);
1653}
1654
1655void drawInfoMenuItems()
1656{
1657int i,n;
1658
1659position_t position;
1660
1661pixmap_t *selection = images[iMenuSelection].image;
1662
1663pixmap_t *pbuff;
1664
1665fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);
1666
1667makeRoundedCorners(gui.menu.pixmap);
1668
1669uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;
1670
1671position = pos(0,0);
1672
1673for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)
1674{
1675if (i == infoMenuSelection)
1676blend(selection, gui.menu.pixmap, position);
1677
1678pbuff = images[n].image;
1679if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)
1680blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
1681pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1682else
1683blend( pbuff, gui.menu.pixmap,
1684pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1685
1686drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap,
1687pos(position.x + (pbuff->width + gui.menu.hborder),
1688position.y + ((selection->height - font_console.height) / 2)));
1689position.y += images[iMenuSelection].image->height;
1690
1691}
1692
1693gui.redraw = true;
1694}
1695
1696int drawInfoMenu()
1697{
1698drawInfoMenuItems();
1699
1700gui.menu.draw = true;
1701
1702updateVRAM();
1703
1704return 1;
1705}
1706
1707int updateInfoMenu(int key)
1708{
1709switch (key)
1710{
1711
1712case kUpArrowkey:// up arrow
1713if (infoMenuSelection > 0)
1714{
1715if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)
1716infoMenuSelection -= 4;
1717
1718else
1719infoMenuSelection--;
1720drawInfoMenuItems();
1721updateVRAM();
1722
1723} else {
1724
1725gui.menu.draw = false;
1726gui.redraw = true;
1727
1728updateVRAM();
1729
1730return CLOSE_INFO_MENU;
1731}
1732break;
1733
1734case kDownArrowkey:// down arrow
1735if (infoMenuSelection < infoMenuItemsCount - 1)
1736{
1737if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
1738infoMenuSelection += 4;
1739else
1740infoMenuSelection++;
1741drawInfoMenuItems();
1742updateVRAM();
1743}
1744break;
1745
1746case kReturnKey:
1747key = 0;
1748if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )
1749showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
1750
1751else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )
1752showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
1753
1754else if( infoMenuSelection == MENU_SHOW_HELP )
1755showHelp();
1756
1757else
1758{
1759int buff = infoMenuSelection;
1760infoMenuSelection = 0;
1761return buff;
1762}
1763break;
1764}
1765return DO_NOT_BOOT;
1766}
1767
1768uint16_t bootImageWidth = 0;
1769uint16_t bootImageHeight = 0;
1770uint8_t *bootImageData = NULL;
1771static bool usePngImage = true;
1772
1773//==========================================================================
1774// loadBootGraphics
1775static void loadBootGraphics(void)
1776{
1777if (bootImageData != NULL) {
1778return;
1779}
1780
1781char dirspec[256];
1782
1783if ((strlen(theme_name) + 24) > sizeof(dirspec)) {
1784usePngImage = false;
1785return;
1786}
1787sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);
1788if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {
1789#ifdef CONFIG_EMBED_THEME
1790 if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
1791#endif
1792usePngImage = false;
1793}
1794}
1795
1796//==========================================================================
1797// drawBootGraphics
1798void drawBootGraphics(void)
1799{
1800int pos;
1801int length;
1802const char *dummyVal;
1803int oldScreenWidth, oldScreenHeight;
1804bool legacy_logo;
1805uint16_t x, y;
1806
1807if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->bootConfig) && legacy_logo) {
1808usePngImage = false;
1809} else if (bootImageData == NULL) {
1810loadBootGraphics();
1811}
1812
1813// parse screen size parameters
1814if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0) {
1815screen_params[0] = pos;
1816} else {
1817screen_params[0] = DEFAULT_SCREEN_WIDTH;
1818}
1819if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0) {
1820screen_params[1] = pos;
1821} else {
1822screen_params[1] = DEFAULT_SCREEN_HEIGHT;
1823}
1824
1825 // Save current screen resolution.
1826oldScreenWidth = gui.screen.width;
1827oldScreenHeight = gui.screen.height;
1828
1829gui.screen.width = screen_params[0];
1830gui.screen.height = screen_params[1];
1831
1832// find best matching vesa mode for our requested width & height
1833getGraphicModeParams(screen_params);
1834
1835 // Set graphics mode if the booter was in text mode or the screen resolution has changed.
1836if (bootArgs->Video.v_display == VGA_TEXT_MODE
1837|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )
1838{
1839setVideoMode(GRAPHICS_MODE, 0);
1840}
1841
1842if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) {
1843drawCheckerBoard();
1844} else {
1845// Fill the background to 75% grey (same as BootX).
1846drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
1847}
1848if ((bootImageData) && (usePngImage)) {
1849x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
1850y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
1851
1852// Draw the image in the center of the display.
1853blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
1854} else {
1855uint8_t *appleBootPict;
1856bootImageData = NULL;
1857bootImageWidth = kAppleBootWidth;
1858bootImageHeight = kAppleBootHeight;
1859
1860// Prepare the data for the default Apple boot image.
1861appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
1862if (appleBootPict) {
1863convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
1864if (bootImageData) {
1865x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
1866y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
1867drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
1868free(bootImageData);
1869}
1870free(appleBootPict);
1871}
1872}
1873}
1874

Archive Download this file

Revision: 1054