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

Archive Download this file

Revision: 1034