Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/CleanCut/i386/boot2/gui.c

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

Archive Download this file

Revision: 321