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

Archive Download this file

Revision: 1048