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

Archive Download this file

Revision: 713