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 THEME_NAME_DEFAULT"Default"
17static const char *theme_name = THEME_NAME_DEFAULT;
18
19#ifdef EMBED_THEME
20#include "art.h"
21#endif
22
23#define LOADPNG(img, alt_img) if (loadThemeImage(#img, alt_img) != 0) { return 1; }
24
25#define MIN(x, y) ((x) < (y) ? (x) : (y)) //Azi: take care of this in the process.***
26#define MAX(x, y) ((x) > (y) ? (x) : (y))
27
28#define VIDEO(x) (bootArgs->Video.v_ ## x)
29
30#define vram VIDEO(baseAddr)
31
32int lasttime = 0; // we need this for animating maybe
33
34extern int gDeviceCount;
35
36
37/*
38 * ATTENTION: the enum and the following array images[] MUST match !!!
39 */
40enum {
41 iBackground = 0,
42 iLogo,
43
44 iDeviceGeneric,
45 iDeviceGeneric_o,
46 iDeviceHFS,
47 iDeviceHFS_o,
48 iDeviceHFSRAID,
49 iDeviceHFSRAID_o,
50 iDeviceEXT3,
51 iDeviceEXT3_o,
52 iDeviceFAT,
53 iDeviceFAT_o,
54 iDeviceFAT16,
55 iDeviceFAT16_o,
56 iDeviceFAT32,
57 iDeviceFAT32_o,
58 iDeviceNTFS,
59 iDeviceNTFS_o,
60 iDeviceCDROM,
61 iDeviceCDROM_o,
62
63 iSelection,
64 iDeviceScrollPrev,
65 iDeviceScrollNext,
66
67 iMenuBoot,
68 iMenuVerbose,
69 iMenuIgnoreCaches,
70 iMenuSingleUser,
71 iMenuMemoryInfo,
72 iMenuVideoInfo,
73 iMenuHelp,
74 iMenuVerboseDisabled,
75 iMenuIgnoreCachesDisabled,
76 iMenuSingleUserDisabled,
77 iMenuSelection,
78
79 iProgressBar,
80 iProgressBarBackground,
81
82 iTextScrollPrev,
83 iTextScrollNext,
84
85 iFontConsole,
86 iFontSmall,
87};
88
89image_t images[] = {
90 {.name = "background", .image = NULL},
91 {.name = "logo", .image = NULL},
92
93 {.name = "device_generic", .image = NULL},
94 {.name = "device_generic_o", .image = NULL},
95 {.name = "device_hfsplus", .image = NULL},
96 {.name = "device_hfsplus_o", .image = NULL},
97 {.name = "device_hfsraid", .image = NULL},
98 {.name = "device_hfsraid_o", .image = NULL},
99 {.name = "device_ext3", .image = NULL},
100 {.name = "device_ext3_o", .image = NULL},
101 {.name = "device_fat", .image = NULL},
102 {.name = "device_fat_o", .image = NULL},
103 {.name = "device_fat16", .image = NULL},
104 {.name = "device_fat16_o", .image = NULL},
105 {.name = "device_fat32", .image = NULL},
106 {.name = "device_fat32_o", .image = NULL},
107 {.name = "device_ntfs", .image = NULL},
108 {.name = "device_ntfs_o", .image = NULL},
109 {.name = "device_cdrom", .image = NULL},
110 {.name = "device_cdrom_o", .image = NULL},
111
112 {.name = "device_selection", .image = NULL},
113 {.name = "device_scroll_prev", .image = NULL},
114 {.name = "device_scroll_next", .image = NULL},
115
116 {.name = "menu_boot", .image = NULL},
117 {.name = "menu_verbose", .image = NULL},
118 {.name = "menu_ignore_caches", .image = NULL},
119 {.name = "menu_single_user", .image = NULL},
120 {.name = "menu_memory_info", .image = NULL},
121 {.name = "menu_video_info", .image = NULL},
122 {.name = "menu_help", .image = NULL},
123 {.name = "menu_verbose_disabled", .image = NULL},
124 {.name = "menu_ignore_caches_disabled", .image = NULL},
125 {.name = "menu_single_user_disabled", .image = NULL},
126 {.name = "menu_selection", .image = NULL},
127
128 {.name = "progress_bar", .image = NULL},
129 {.name = "progress_bar_background", .image = NULL},
130
131 {.name = "text_scroll_prev", .image = NULL},
132 {.name = "text_scroll_next", .image = NULL},
133
134 {.name = "font_console", .image = NULL},
135 {.name = "font_small", .image = NULL},
136};
137
138int imageCnt = 0;
139
140extern intgDeviceCount;
141extern intselectIndex;
142
143extern MenuItem *menuItems;
144
145char prompt[BOOT_STRING_LEN];
146
147int prompt_pos=0;
148
149char prompt_text[] = "boot: ";
150
151menuitem_t infoMenuItems[] =
152{
153{ .text = "Boot" },
154{ .text = "Boot Verbose" },
155{ .text = "Boot Ignore Caches" },
156{ .text = "Boot Single User" },
157{ .text = "Memory Info" },
158{ .text = "Video Info" },
159{ .text = "Help" }
160};
161
162int initFont(font_t *font, image_t *image);
163void colorFont(font_t *font, uint32_t color);
164void makeRoundedCorners(pixmap_t *p);
165
166static int infoMenuSelection = 0;
167static int infoMenuItemsCount = sizeof(infoMenuItems)/sizeof(infoMenuItems[0]);
168
169static bool infoMenuNativeBoot = false;
170
171// here we store the used screen resolution
172static unsigned long screen_params[4] = {DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 32, 0};
173
174static int getImageIndexByName(const char *name)
175{
176 int i;
177for (i = 0; i < sizeof(images) / sizeof(images[0]); i++)
178{
179 if (strcmp(name, images[i].name) == 0)
180 return i; // found the name
181}
182return -1;
183}
184
185#ifdef EMBED_THEME
186static int getEmbeddedImageIndexByName(const char *name)
187{
188int upperLimit = sizeof(embeddedImages) / sizeof(embeddedImages[0]) - 1;
189int lowerLimit = 0;
190int compareIndex = (upperLimit - lowerLimit) >> 1; // Midpoint
191int result;
192
193// NOTE: This algorithm assumes that the embedded images are sorted.
194// This is currently done using the make file. If the array is ever
195// manualy generated, this *will* fail to work properly.
196while((result = strcmp(name, embeddedImages[compareIndex].name)) != 0)
197{
198if(result > 0)// We need to search a HIGHER index
199{
200if(compareIndex != lowerLimit)
201{
202lowerLimit = compareIndex;
203}
204else
205{
206return -1;
207}
208compareIndex = (upperLimit + lowerLimit + 1) >> 1;// Midpoint, round up
209}
210else // We Need to search a LOWER index
211{
212if(compareIndex != upperLimit)
213{
214upperLimit = compareIndex;
215}
216else
217{
218return -1;
219}
220compareIndex = (upperLimit + lowerLimit) >> 1;// Midpoint, round down
221}
222}
223return compareIndex;
224}
225#endif
226
227static int loadThemeImage(const char *image, int alt_image)
228{
229chardirspec[256];
230int i;
231#ifdef EMBED_THEME
232int e;
233#endif
234uint16_twidth;
235uint16_theight;
236uint8_t*imagedata;
237
238if ((strlen(image) + strlen(theme_name) + 20 ) > sizeof(dirspec)) {
239return 1;
240}
241
242 if ((i = getImageIndexByName(image)) >= 0)
243 {
244 if (images[i].image == NULL) {
245 images[i].image = malloc(sizeof(pixmap_t));
246 }
247 sprintf(dirspec, "/Extra/Themes/%s/%s.png", theme_name, image);
248 width = 0;
249 height = 0;
250 imagedata = NULL;
251 if ((loadPngImage(dirspec, &width, &height, &imagedata)) == 0)
252 {
253 images[i].image->width = width;
254 images[i].image->height = height;
255 images[i].image->pixels = (pixel_t *)imagedata;
256 flipRB(images[i].image);
257 return 0;
258 }
259#ifdef EMBED_THEME
260 else if ((e = getEmbeddedImageIndexByName(image)) >= 0)
261 {
262 unsigned char *embed_data;
263 unsigned int embed_size;
264 embed_data = embeddedImages[e].pngdata;
265 embed_size = *embeddedImages[e].length;
266
267 if (loadEmbeddedPngImage(embed_data, embed_size, &width, &height, &imagedata) == 0)
268 {
269 images[i].image->width = width;
270 images[i].image->height = height;
271 images[i].image->pixels = (pixel_t *)imagedata;
272 flipRB(images[i].image);
273 return 0;
274 }
275
276 return 0;
277 }
278#endif
279 else if (alt_image != IMG_REQUIRED && images[alt_image].image->pixels != NULL)
280 {
281 // Using the passed alternate image for non-mandatory images.
282 // We don't clone the already existing pixmap, but using its properties instead!
283 images[i].image->width = images[alt_image].image->width;
284 images[i].image->height = images[alt_image].image->height;
285 images[i].image->pixels = images[alt_image].image->pixels;
286 return 0;
287 }
288 else
289 {
290#ifndef EMBED_THEME
291 printf("ERROR: GUI: could not open '%s/%s.png'!\n", theme_name, image);
292sleep(2);
293#endif
294 return 1;
295 }
296 }
297return 1;
298}
299
300static int loadGraphics(void)
301{
302LOADPNG(background, IMG_REQUIRED);
303LOADPNG(logo, IMG_REQUIRED);
304
305LOADPNG(device_generic, IMG_REQUIRED);
306LOADPNG(device_generic_o, iDeviceGeneric);
307LOADPNG(device_hfsplus, iDeviceGeneric);
308LOADPNG(device_hfsplus_o, iDeviceHFS);
309LOADPNG(device_hfsraid, iDeviceGeneric);
310LOADPNG(device_hfsraid_o, iDeviceHFSRAID);
311LOADPNG(device_ext3, iDeviceGeneric);
312LOADPNG(device_ext3_o, iDeviceEXT3);
313LOADPNG(device_fat, iDeviceGeneric);
314LOADPNG(device_fat_o, iDeviceFAT);
315LOADPNG(device_fat16, iDeviceFAT);
316LOADPNG(device_fat16_o, iDeviceFAT_o);
317LOADPNG(device_fat32, iDeviceFAT);
318LOADPNG(device_fat32_o, iDeviceFAT_o);
319LOADPNG(device_ntfs, iDeviceGeneric);
320LOADPNG(device_ntfs_o, iDeviceNTFS);
321LOADPNG(device_cdrom, iDeviceGeneric);
322LOADPNG(device_cdrom_o, iDeviceCDROM);
323
324LOADPNG(device_selection, IMG_REQUIRED);
325LOADPNG(device_scroll_prev, IMG_REQUIRED);
326LOADPNG(device_scroll_next, IMG_REQUIRED);
327
328LOADPNG(menu_boot, IMG_REQUIRED);
329LOADPNG(menu_verbose, IMG_REQUIRED);
330LOADPNG(menu_ignore_caches, IMG_REQUIRED);
331LOADPNG(menu_single_user, IMG_REQUIRED);
332LOADPNG(menu_memory_info, IMG_REQUIRED);
333LOADPNG(menu_video_info, IMG_REQUIRED);
334LOADPNG(menu_help, IMG_REQUIRED);
335LOADPNG(menu_verbose_disabled, IMG_REQUIRED);
336LOADPNG(menu_ignore_caches_disabled, IMG_REQUIRED);
337LOADPNG(menu_single_user_disabled, IMG_REQUIRED);
338LOADPNG(menu_selection, IMG_REQUIRED);
339
340LOADPNG(progress_bar, IMG_REQUIRED);
341LOADPNG(progress_bar_background, IMG_REQUIRED);
342
343LOADPNG(text_scroll_prev, IMG_REQUIRED);
344LOADPNG(text_scroll_next, IMG_REQUIRED);
345
346LOADPNG(font_console, IMG_REQUIRED);
347LOADPNG(font_small, IMG_REQUIRED);
348
349initFont( &font_console, &images[iFontConsole]);
350initFont( &font_small, &images[iFontSmall]);
351
352return 0;
353}
354
355pixmap_t *getCroppedPixmapAtPosition( pixmap_t *from, position_t pos, uint16_t width, uint16_t height )
356{
357
358pixmap_t *cropped = malloc( sizeof( pixmap_t ) );
359if( !cropped )
360return 0;
361cropped->pixels = malloc( width * height * 4 );
362if ( !cropped->pixels )
363return 0;
364
365cropped->width = width;
366cropped->height = height;
367
368int destx = 0, desty = 0;
369int srcx = pos.x, srcy = pos.y;
370
371for( ; desty < height; desty++, srcy++)
372{
373for( destx = 0, srcx = pos.x; destx < width; destx++, srcx++ )
374{
375pixel( cropped, destx, desty ).value = pixel( from, srcx, srcy ).value;
376}
377}
378return cropped;
379}
380
381int createBackBuffer( window_t *window )
382{
383gui.backbuffer = malloc(sizeof(pixmap_t));
384if(!gui.backbuffer)
385return 1;
386
387gui.backbuffer->pixels = malloc( window->width * window->height * 4 );
388if(!gui.backbuffer->pixels)
389{
390free(gui.backbuffer);
391gui.backbuffer = 0;
392return 1;
393}
394
395gui.backbuffer->width = gui.screen.width;
396gui.backbuffer->height = gui.screen.height;
397
398return 0;
399}
400
401int createWindowBuffer( window_t *window )
402{
403window->pixmap = malloc(sizeof(pixmap_t));
404if(!window->pixmap)
405return 1;
406
407window->pixmap->pixels = malloc( window->width * window->height * 4 );
408if(!window->pixmap->pixels)
409{
410free(window->pixmap);
411window->pixmap = 0;
412return 1;
413}
414
415window->pixmap->width = window->width;
416window->pixmap->height = window->height;
417
418return 0;
419}
420
421int freeWindowBuffer( window_t *window )
422{
423if (window->pixmap && window->pixmap->pixels)
424 {
425free(window->pixmap->pixels);
426free(window->pixmap);
427return 0;
428}
429
430return 1;
431}
432
433void fillPixmapWithColor(pixmap_t *pm, uint32_t color)
434{
435int x,y;
436
437// fill with given color AARRGGBB
438for( x=0; x < pm->width; x++ )
439for( y=0; y< pm->height; y++)
440pixel(pm,x,y).value = color;
441}
442
443void drawBackground()
444{
445// reset text cursor
446gui.screen.cursor.x = gui.screen.hborder;
447gui.screen.cursor.y = gui.screen.vborder;
448
449fillPixmapWithColor( gui.screen.pixmap, gui.screen.bgcolor);
450
451// draw background.png into background buffer
452blend( images[iBackground].image, gui.screen.pixmap, gui.background.pos );
453
454// draw logo.png into background buffer
455if (gui.logo.draw)
456{
457 blend( images[iLogo].image, gui.screen.pixmap, gui.logo.pos);
458}
459
460memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
461}
462
463void setupDeviceList(config_file_t *theme)
464{
465unsigned int pixel;
466intalpha;// transparency level 0 (obligue) - 255 (transparent)
467uint32_t color;// color value formatted RRGGBB
468int val, len;
469const char *string;
470
471if(getIntForKey("devices_max_visible", &val, theme ))
472gui.maxdevices = MIN( val, gDeviceCount );
473
474if(getIntForKey("devices_iconspacing", &val, theme ))
475gui.devicelist.iconspacing = val;
476
477// check layout for horizontal or vertical
478gui.layout = HorizontalLayout;
479if(getValueForKey( "devices_layout", &string, &len, theme)) {
480if (!strcmp (string, "vertical")) {
481gui.layout = VerticalLayout;
482}
483}
484
485switch (gui.layout) {
486case VerticalLayout:
487gui.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);
488gui.devicelist.width = (images[iSelection].image->width + gui.devicelist.iconspacing);
489
490if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , images[iSelection].image->width ) )
491gui.devicelist.pos.x = pixel;
492
493if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , gui.devicelist.height ) )
494gui.devicelist.pos.y = pixel;
495break;
496
497case HorizontalLayout:
498default:
499gui.devicelist.width = ((images[iSelection].image->width + gui.devicelist.iconspacing) * MIN(gui.maxdevices, gDeviceCount) + (images[iDeviceScrollPrev].image->width + images[iDeviceScrollNext].image->width) + gui.devicelist.iconspacing);
500gui.devicelist.height = (images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing);
501
502if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , gui.devicelist.width ) )
503gui.devicelist.pos.x = pixel;
504else
505gui.devicelist.pos.x = ( gui.screen.width - gui.devicelist.width ) / 2;
506
507if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , images[iSelection].image->height ) )
508gui.devicelist.pos.y = pixel;
509else
510gui.devicelist.pos.y = ( gui.screen.height - gui.devicelist.height ) / 2;
511break;
512}
513
514if(getColorForKey("devices_bgcolor", &color, theme))
515gui.devicelist.bgcolor = (color & 0x00FFFFFF);
516
517if(getIntForKey("devices_transparency", &alpha, theme))
518gui.devicelist.bgcolor = gui.devicelist.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
519
520if (gui.devicelist.pixmap)
521{
522 freeWindowBuffer(&gui.devicelist);
523 createWindowBuffer(&gui.devicelist);
524 }
525}
526
527void loadThemeValues(config_file_t *theme)
528{
529unsigned int screen_width = gui.screen.width;
530unsigned int screen_height = gui.screen.height;
531unsigned int pixel;
532intalpha;// transparency level 0 (obligue) - 255 (transparent)
533uint32_t color;// color value formatted RRGGBB
534int val;
535
536/*
537 * Parse screen parameters
538 */
539if(getColorForKey("screen_bgcolor", &color, theme ))
540gui.screen.bgcolor = (color & 0x00FFFFFF);
541
542if(getIntForKey("screen_textmargin_h", &val, theme))
543gui.screen.hborder = MIN( gui.screen.width , val );
544
545if(getIntForKey("screen_textmargin_v", &val, theme))
546gui.screen.vborder = MIN( gui.screen.height , val );
547
548/*
549 * Parse background parameters
550 */
551if(getDimensionForKey("background_pos_x", &pixel, theme, screen_width , images[iBackground].image->width ) )
552gui.background.pos.x = pixel;
553
554if(getDimensionForKey("background_pos_y", &pixel, theme, screen_height , images[iBackground].image->height ) )
555gui.background.pos.y = pixel;
556
557/*
558 * Parse logo parameters
559 */
560if(getDimensionForKey("logo_pos_x", &pixel, theme, screen_width , images[iLogo].image->width ) )
561gui.logo.pos.x = pixel;
562
563if(getDimensionForKey("logo_pos_y", &pixel, theme, screen_height , images[iLogo].image->height ) )
564gui.logo.pos.y = pixel;
565
566/*
567 * Parse progress bar parameters
568 */
569if(getDimensionForKey("progressbar_pos_x", &pixel, theme, screen_width , 0 ) )
570gui.progressbar.pos.x = pixel;
571
572if(getDimensionForKey("progressbar_pos_y", &pixel, theme, screen_height , 0 ) )
573gui.progressbar.pos.y = pixel;
574
575/*
576 * Parse countdown text parameters
577 */
578if(getDimensionForKey("countdown_pos_x", &pixel, theme, screen_width , 0 ) )
579gui.countdown.pos.x = pixel;
580
581if(getDimensionForKey("countdown_pos_y", &pixel, theme, screen_height , 0 ) )
582gui.countdown.pos.y = pixel;
583
584/*
585 * Parse devicelist parameters
586 */
587setupDeviceList(theme);
588
589/*
590 * Parse infobox parameters
591 */
592if(getIntForKey("infobox_width", &val, theme))
593gui.infobox.width = MIN( screen_width , val );
594
595if(getIntForKey("infobox_height", &val, theme))
596gui.infobox.height = MIN( screen_height , val );
597
598if(getDimensionForKey("infobox_pos_x", &pixel, theme, screen_width , gui.infobox.width ) )
599gui.infobox.pos.x = pixel;
600
601if(getDimensionForKey("infobox_pos_y", &pixel, theme, screen_height , gui.infobox.height ) )
602gui.infobox.pos.y = pixel;
603
604if(getIntForKey("infobox_textmargin_h", &val, theme))
605gui.infobox.hborder = MIN( gui.infobox.width , val );
606
607if(getIntForKey("infobox_textmargin_v", &val, theme))
608gui.infobox.vborder = MIN( gui.infobox.height , val );
609
610if(getColorForKey("infobox_bgcolor", &color, theme))
611gui.infobox.bgcolor = (color & 0x00FFFFFF);
612
613if(getIntForKey("infobox_transparency", &alpha, theme))
614gui.infobox.bgcolor = gui.infobox.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
615
616/*
617 * Parse menu parameters
618 */
619if(getDimensionForKey("menu_width", &pixel, theme, gui.screen.width , 0 ) )
620gui.menu.width = pixel;
621else
622gui.menu.width = images[iMenuSelection].image->width;
623
624if(getDimensionForKey("menu_height", &pixel, theme, gui.screen.height , 0 ) )
625gui.menu.height = pixel;
626else
627gui.menu.height = (infoMenuItemsCount) * images[iMenuSelection].image->height;
628
629if(getDimensionForKey("menu_pos_x", &pixel, theme, screen_width , gui.menu.width ) )
630gui.menu.pos.x = pixel;
631
632if(getDimensionForKey("menu_pos_y", &pixel, theme, screen_height , gui.menu.height ) )
633gui.menu.pos.y = pixel;
634
635if(getIntForKey("menu_textmargin_h", &val, theme))
636gui.menu.hborder = MIN( gui.menu.width , val );
637
638if(getIntForKey("menu_textmargin_v", &val, theme))
639gui.menu.vborder = MIN( gui.menu.height , val );
640
641if(getColorForKey("menu_bgcolor", &color, theme))
642gui.menu.bgcolor = (color & 0x00FFFFFF);
643
644if(getIntForKey("menu_transparency", &alpha, theme))
645gui.menu.bgcolor = gui.menu.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
646
647/*
648 * Parse bootprompt parameters
649 */
650if(getDimensionForKey("bootprompt_width", &pixel, theme, screen_width , 0 ) )
651gui.bootprompt.width = pixel;
652
653if(getIntForKey("bootprompt_height", &val, theme))
654gui.bootprompt.height = MIN( screen_height , val );
655
656if(getDimensionForKey("bootprompt_pos_x", &pixel, theme, screen_width , gui.bootprompt.width ) )
657gui.bootprompt.pos.x = pixel;
658
659if(getDimensionForKey("bootprompt_pos_y", &pixel, theme, screen_height , gui.bootprompt.height ) )
660gui.bootprompt.pos.y = pixel;
661
662if(getIntForKey("bootprompt_textmargin_h", &val, theme))
663gui.bootprompt.hborder = MIN( gui.bootprompt.width , val );
664
665if(getIntForKey("bootprompt_textmargin_v", &val, theme))
666gui.bootprompt.vborder = MIN( gui.bootprompt.height , val );
667
668if(getColorForKey("bootprompt_bgcolor", &color, theme))
669gui.bootprompt.bgcolor = (color & 0x00FFFFFF);
670
671if(getIntForKey("bootprompt_transparency", &alpha, theme))
672gui.bootprompt.bgcolor = gui.bootprompt.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
673
674if(getColorForKey("font_small_color", &color, theme))
675gui.screen.font_small_color = (color & 0x00FFFFFF);
676
677if(getColorForKey("font_console_color", &color, theme))
678gui.screen.font_console_color = (color & 0x00FFFFFF);
679}
680
681int initGUI(void)
682{
683intval, len, count;
684chardirspec[128]; //Azi: a bit of testing***
685
686getValueForKey( "Theme", &theme_name, &len, &bootInfo->bootConfig );
687if ((strlen(theme_name) + 27) > sizeof(dirspec)) {
688return 1;
689}
690sprintf(dirspec, "/Extra/Themes/%s/theme.plist", theme_name);
691if (loadConfigFile(dirspec, &bootInfo->themeConfig) != 0) {
692#ifdef EMBED_THEME
693 config_file_t*config;
694
695 config = &bootInfo->themeConfig;
696 if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) {
697 return 1;
698 }
699#else
700return 1;
701#endif
702}
703
704/*
705 * AutoResolution
706 */
707if (gAutoResolution == true)
708{
709// Get Resolution from Graphics Mode key
710count = getNumberArrayFromProperty(kGraphicsModeKey, screen_params, 4);
711
712// If no Graphics Mode key, get it from EDID
713if ( count < 3 )
714{
715getResolution(screen_params);
716
717PRINT("Resolution : %dx%d (EDID)\n",screen_params[0], screen_params[1]);
718}
719else
720{
721PRINT("Resolution : %dx%d (Graphics Mode key)\n",screen_params[0], screen_params[1]);
722}
723 }
724else
725{
726 // parse display size parameters
727 if (getIntForKey("screen_width", &val, &bootInfo->themeConfig) && val > 0)
728{
729screen_params[0] = val;
730}
731
732 if (getIntForKey("screen_height", &val, &bootInfo->themeConfig) && val > 0)
733{
734screen_params[1] = val;
735}
736}
737
738// Initalizing GUI strucutre.
739bzero(&gui, sizeof(gui_t));
740
741// find best matching vesa mode for our requested width & height
742loadConfigFile(dirspec, &bootInfo->themeConfig); //Azi: check this later.
743getGraphicModeParams(screen_params);
744
745// set our screen structure with the mode width & height
746gui.screen.width = screen_params[0];
747gui.screen.height = screen_params[1];
748PRINT("Found mode %dx%d in VESA Table\n", gui.screen.width, gui.screen.height);
749
750// load graphics otherwise fail and return
751if (loadGraphics() == 0) {
752loadThemeValues(&bootInfo->themeConfig);
753colorFont(&font_small, gui.screen.font_small_color);
754colorFont(&font_console, gui.screen.font_console_color);
755
756// create the screen & window buffers
757if (createBackBuffer(&gui.screen) == 0) {
758if (createWindowBuffer(&gui.screen) == 0) {
759if (createWindowBuffer(&gui.devicelist) == 0) {
760if (createWindowBuffer(&gui.bootprompt) == 0) {
761if (createWindowBuffer(&gui.infobox) == 0) {
762if (createWindowBuffer(&gui.menu) == 0) {
763
764#ifdef AUTORES_DEBUG
765printf("Press Any Key...\n");
766getc();
767#endif
768gui.logo.draw = true;
769drawBackground();
770// lets copy the screen into the back buffer
771memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
772setVideoMode( GRAPHICS_MODE, 0 );
773gui.initialised = true;
774return 0;
775} else printf("createWindowBuffer(&gui.menu) Failed\n");
776} else printf("createWindowBuffer(&gui.infobox) Failed\n");
777} else printf("createWindowBuffer(&gui.bootprompt) Failed\n");
778} else printf("createWindowBuffer(&gui.devicelist) Failed\n");
779} else printf("createWindowBuffer(&gui.screen) Failed\n");
780} else printf("createBackBuffer(&gui.screen) Failed\n");
781} else printf("loadGraphics() Failed\n");
782
783return 1;
784}
785
786void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected)
787{
788int devicetype;
789
790if( diskIsCDROM(device) )
791devicetype = iDeviceCDROM;// Use CDROM icon
792else
793{
794switch (device->part_type)
795{
796case kPartitionTypeHFS:
797
798// Use HFS or HFSRAID icon depending on bvr flags.
799devicetype = (device->flags & kBVFlagBooter) ? iDeviceHFSRAID : iDeviceHFS;
800break;
801
802case kPartitionTypeHPFS:
803devicetype = iDeviceNTFS;// Use HPFS / NTFS icon
804break;
805
806case kPartitionTypeFAT16:
807devicetype = iDeviceFAT16;// Use FAT16 icon
808break;
809
810case kPartitionTypeFAT32:
811devicetype = iDeviceFAT32;// Use FAT32 icon
812break;
813
814case kPartitionTypeEXT3:
815devicetype = iDeviceEXT3;// Use EXT2/3 icon
816break;
817
818default:
819devicetype = iDeviceGeneric;// Use Generic icon
820break;
821}
822}
823
824// Draw the selection image and use the next (device_*_o) image for the selected item.
825 if (isSelected)
826{
827blend(images[iSelection].image, buffer, centeredAt(images[iSelection].image, p));
828devicetype++;
829}
830
831// draw icon
832blend( images[devicetype].image, buffer, centeredAt( images[devicetype].image, p ));
833
834p.y += (images[iSelection].image->height / 2) + font_console.chars[0]->height;
835
836// draw volume label
837drawStrCenteredAt( device->label, &font_small, buffer, p);
838
839}
840
841void drawDeviceList (int start, int end, int selection)
842{
843inti;
844booldebugInfo = false; //Azi:debuginfo
845extern bool showBootBanner; //||
846position_tp, p_prev, p_next;
847
848//uint8_tmaxDevices = MIN( gui.maxdevices, menucount );
849
850fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);
851
852makeRoundedCorners( gui.devicelist.pixmap);
853
854switch (gui.layout)
855{
856
857case VerticalLayout:
858p.x = (gui.devicelist.width /2);
859p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );
860
861// place scroll indicators at top & bottom edges
862p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );
863p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );
864
865break;
866
867default:// use Horizontal layout as the default
868
869case HorizontalLayout:
870p.x = (gui.devicelist.width - ( gui.devicelist.width / gui.maxdevices ) * gui.maxdevices ) / 2 + ( images[iSelection].image->width / 2) + images[iDeviceScrollPrev].image->width + gui.devicelist.iconspacing;
871p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );
872
873// place scroll indicators at left & right edges
874p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );
875p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );
876
877break;
878
879}
880
881// draw visible device icons
882for (i = 0; i < gui.maxdevices; i++)
883{
884BVRef param = menuItems[start + i].param;
885
886 bool isSelected = ((start + i) == selection) ? true : false;
887if (isSelected)
888{
889 if (param->flags & kBVFlagNativeBoot)
890 {
891 infoMenuNativeBoot = true;
892 }
893 else
894 {
895 infoMenuNativeBoot = false;
896 if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)
897 infoMenuSelection = 0;
898 }
899
900if(gui.menu.draw)
901drawInfoMenuItems();
902
903//Azi: make this info more accessible.
904getBoolForKey(kDebugInfoKey, &debugInfo, &bootInfo->bootConfig);
905
906if (debugInfo && showBootBanner)
907{
908gui.debug.cursor = pos( 10, 100);
909dprintf( &gui.screen, "label: %s\n", param->label );
910dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev );
911dprintf( &gui.screen, "type: 0x%x\n", param->type );
912dprintf( &gui.screen, "flags: 0x%x\n", param->flags );
913dprintf( &gui.screen, "part_no: %d\n", param->part_no );
914dprintf( &gui.screen, "part_boff: 0x%x\n", param->part_boff );
915dprintf( &gui.screen, "part_type: 0x%x\n", param->part_type );
916dprintf( &gui.screen, "bps: 0x%x\n", param->bps );
917dprintf( &gui.screen, "name: %s\n", param->name );
918dprintf( &gui.screen, "type_name: %s\n", param->type_name );
919dprintf( &gui.screen, "modtime: %d\n", param->modTime );
920dprintf( &gui.screen, "width: %d\n", gui.screen.width );
921dprintf( &gui.screen, "height: %d\n", gui.screen.height );
922dprintf( &gui.screen, "attr: 0x%x\n", gui.screen.attr );
923dprintf( &gui.screen, "mm: %d\n", gui.screen.mm );
924}
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)
1737blend(selection, gui.menu.pixmap, position);
1738
1739pbuff = images[n].image;
1740if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)
1741blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
1742pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1743else
1744blend( pbuff, gui.menu.pixmap,
1745pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1746
1747drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap,
1748pos(position.x + (pbuff->width + gui.menu.hborder),
1749position.y + ((selection->height - font_console.height) / 2)));
1750position.y += images[iMenuSelection].image->height;
1751
1752}
1753
1754gui.redraw = true;
1755}
1756
1757int drawInfoMenu()
1758{
1759drawInfoMenuItems();
1760
1761gui.menu.draw = true;
1762
1763updateVRAM();
1764
1765return 1;
1766}
1767
1768int updateInfoMenu(int key)
1769{
1770switch (key)
1771{
1772
1773case kUpArrowkey:// up arrow
1774if (infoMenuSelection > 0)
1775{
1776if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)
1777infoMenuSelection -= 4;
1778
1779else
1780infoMenuSelection--;
1781drawInfoMenuItems();
1782updateVRAM();
1783
1784} else {
1785
1786gui.menu.draw = false;
1787gui.redraw = true;
1788
1789updateVRAM();
1790
1791return CLOSE_INFO_MENU;
1792}
1793break;
1794
1795case kDownArrowkey:// down arrow
1796if (infoMenuSelection < infoMenuItemsCount - 1)
1797{
1798if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
1799infoMenuSelection += 4;
1800else
1801infoMenuSelection++;
1802drawInfoMenuItems();
1803updateVRAM();
1804}
1805break;
1806
1807case kReturnKey:
1808key = 0;
1809if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )
1810showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
1811
1812else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )
1813showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
1814
1815else if( infoMenuSelection == MENU_SHOW_HELP )
1816showHelp();
1817
1818else
1819{
1820int buff = infoMenuSelection;
1821infoMenuSelection = 0;
1822return buff;
1823}
1824break;
1825}
1826return DO_NOT_BOOT;
1827}
1828
1829uint16_t bootImageWidth = 0;
1830uint16_t bootImageHeight = 0;
1831uint8_t *bootImageData = NULL;
1832static bool usePngImage = true;
1833
1834//==========================================================================
1835// loadBootGraphics
1836static void loadBootGraphics(void)
1837{
1838if (bootImageData != NULL) {
1839return;
1840}
1841
1842char dirspec[256];
1843
1844if ((strlen(theme_name) + 24) > sizeof(dirspec)) {
1845usePngImage = false;
1846return;
1847}
1848sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);
1849if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {
1850#ifdef EMBED_THEME
1851 if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
1852#endif
1853usePngImage = false;
1854}
1855}
1856
1857//==========================================================================
1858// drawBootGraphics
1859void drawBootGraphics(void)
1860{
1861int pos;
1862int length, count;
1863const char *dummyVal;
1864int oldScreenWidth, oldScreenHeight;
1865bool legacy_logo;
1866uint16_t x, y;
1867
1868if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->bootConfig) && legacy_logo) {
1869usePngImage = false;
1870} else if (bootImageData == NULL) {
1871loadBootGraphics();
1872}
1873
1874/*
1875 * AutoResolution - Azi: review this stuff...***
1876 */
1877if (gAutoResolution == true)
1878{
1879// Get Resolution from Graphics Mode key
1880count = getNumberArrayFromProperty(kGraphicsModeKey, screen_params, 4);
1881
1882// If no Graphics Mode key, get it from EDID
1883if ( count < 3 )
1884{
1885getResolution(screen_params);
1886}
1887 }
1888else
1889{
1890 // parse display size parameters
1891if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0)
1892{
1893screen_params[0] = pos;
1894}
1895/*else
1896{
1897screen_params[0] = DEFAULT_SCREEN_WIDTH;
1898}*/
1899
1900if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0)
1901{
1902screen_params[1] = pos;
1903}
1904/*else
1905{
1906screen_params[1] = DEFAULT_SCREEN_HEIGHT;
1907}*/
1908}
1909
1910 // Save current screen resolution. Azi: ... and this too.***
1911oldScreenWidth = gui.screen.width;
1912oldScreenHeight = gui.screen.height;
1913
1914gui.screen.width = screen_params[0];
1915gui.screen.height = screen_params[1];
1916
1917// find best matching vesa mode for our requested width & height
1918getGraphicModeParams(screen_params);
1919
1920 // Set graphics mode if the booter was in text mode or the screen resolution has changed.
1921if (bootArgs->Video.v_display == VGA_TEXT_MODE
1922|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )
1923{
1924setVideoMode(GRAPHICS_MODE, 0);
1925}
1926
1927if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) {
1928drawCheckerBoard();
1929} else {
1930// Fill the background to 75% grey (same as BootX).
1931drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
1932}
1933if ((bootImageData) && (usePngImage)) {
1934x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
1935y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
1936
1937// Draw the image in the center of the display.
1938blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
1939} else {
1940uint8_t *appleBootPict;
1941bootImageData = NULL;
1942bootImageWidth = kAppleBootWidth;
1943bootImageHeight = kAppleBootHeight;
1944
1945// Prepare the data for the default Apple boot image.
1946appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
1947if (appleBootPict) {
1948convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
1949if (bootImageData) {
1950x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
1951y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
1952drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
1953free(bootImageData);
1954}
1955free(appleBootPict);
1956}
1957}
1958}
1959

Archive Download this file

Revision: 470