Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 676