Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 509