Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 369