Chameleon

Chameleon Svn Source Tree

Root/branches/meklort/i386/modules/GUI/gui.c

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

Archive Download this file

Revision: 574