Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 312