Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 381