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

Archive Download this file

Revision: 310