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
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 display 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{
816inti;
817booldebugInfo = false; //Azi:displayinfo
818extern boolshowBootBanner;
819position_tp, p_prev, p_next;
820
821//uint8_tmaxDevices = MIN( gui.maxdevices, menucount );
822
823fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);
824
825makeRoundedCorners( gui.devicelist.pixmap);
826
827switch (gui.layout)
828{
829
830case VerticalLayout:
831p.x = (gui.devicelist.width /2);
832p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );
833
834// place scroll indicators at top & bottom edges
835p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );
836p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );
837
838break;
839
840default:// use Horizontal layout as the default
841
842case HorizontalLayout:
843p.x = (gui.devicelist.width - ( gui.devicelist.width / gui.maxdevices ) * gui.maxdevices ) / 2 + ( images[iSelection].image->width / 2) + images[iDeviceScrollPrev].image->width + gui.devicelist.iconspacing;
844p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );
845
846// place scroll indicators at left & right edges
847p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );
848p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );
849
850break;
851
852}
853
854// draw visible device icons
855for (i = 0; i < gui.maxdevices; i++)
856{
857BVRef param = menuItems[start + i].param;
858
859 bool isSelected = ((start + i) == selection) ? true : false;
860if (isSelected)
861{
862 if (param->flags & kBVFlagNativeBoot)
863 {
864 infoMenuNativeBoot = true;
865 }
866 else
867 {
868 infoMenuNativeBoot = false;
869 if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)
870 infoMenuSelection = 0;
871 }
872
873if (gui.menu.draw)
874drawInfoMenuItems();
875
876//Azi: making this info more accessible. TODO: remove the stuff on graphics.c!
877getBoolForKey(kDebugInfoKey, &debugInfo, &bootInfo->bootConfig);
878
879#ifdef AUTORES_DEBUG //Azi:autoresolution
880debugInfo = true;
881#endif
882
883if (debugInfo && showBootBanner)
884{
885gui.debug.cursor = pos( 10, 100);
886dprintf( &gui.screen, "label: %s\n", param->label );
887dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev );
888dprintf( &gui.screen, "type: 0x%x\n", param->type );
889dprintf( &gui.screen, "flags: 0x%x\n", param->flags );
890dprintf( &gui.screen, "part_no: %d\n", param->part_no );
891dprintf( &gui.screen, "part_boff: 0x%x\n", param->part_boff );
892dprintf( &gui.screen, "part_type: 0x%x\n", param->part_type );
893dprintf( &gui.screen, "bps: 0x%x\n", param->bps );
894dprintf( &gui.screen, "name: %s\n", param->name );
895dprintf( &gui.screen, "type_name: %s\n", param->type_name );
896dprintf( &gui.screen, "modtime: %d\n", param->modTime );
897dprintf( &gui.screen, "width: %d\n", gui.screen.width );
898dprintf( &gui.screen, "height: %d\n", gui.screen.height );
899dprintf( &gui.screen, "attr: 0x%x\n", gui.screen.attr );
900dprintf( &gui.screen, "mm: %d\n", gui.screen.mm );
901}
902}
903
904drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);
905
906if (gui.layout == HorizontalLayout)
907{
908p.x += images[iSelection].image->width + gui.devicelist.iconspacing;
909}
910if (gui.layout == VerticalLayout)
911{
912p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing );
913}
914}
915
916// draw prev indicator
917if(start)
918blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );
919
920// draw next indicator
921if( end < gDeviceCount - 1 )
922blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );
923
924gui.redraw = true;
925
926updateVRAM();
927
928}
929
930void clearGraphicBootPrompt()
931{
932// clear text buffer
933prompt[0] = '\0';
934prompt_pos=0;
935
936
937if(gui.bootprompt.draw == true )
938{
939gui.bootprompt.draw = false;
940gui.redraw = true;
941// this causes extra frames to be drawn
942//updateVRAM();
943}
944
945return;
946}
947
948void updateGraphicBootPrompt(int key)
949{
950if ( key == kBackspaceKey )
951prompt[--prompt_pos] = '\0';
952else
953{
954prompt[prompt_pos] = key;
955prompt_pos++;
956prompt[prompt_pos] = '\0';
957}
958
959fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);
960
961makeRoundedCorners( gui.bootprompt.pixmap);
962
963position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );
964
965// print the boot prompt text
966drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);
967
968// get the position of the end of the boot prompt text to display user input
969position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );
970
971// calculate the position of the cursor
972intoffset = ( prompt_pos - ( ( gui.bootprompt.width / font_console.chars[0]->width ) - strlen(prompt_text) - 2 ) );
973
974if ( offset < 0)
975offset = 0;
976
977drawStr( prompt+offset, &font_console, gui.bootprompt.pixmap, p_prompt);
978
979gui.menu.draw = false;
980gui.bootprompt.draw = true;
981gui.redraw = true;
982
983updateVRAM();
984
985return;
986}
987
988inline
989void vramwrite (void *data, int width, int height)
990{
991if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)
992memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
993else
994{
995uint32_t r, g, b;
996int i, j;
997for (i = 0; i < VIDEO (height); i++)
998for (j = 0; j < VIDEO (width); j++)
999{
1000b = ((uint8_t *) data)[4*i*width + 4*j];
1001g = ((uint8_t *) data)[4*i*width + 4*j + 1];
1002r = ((uint8_t *) data)[4*i*width + 4*j + 2];
1003switch (VIDEO (depth))
1004{
1005case 32:
1006*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1007break;
1008case 24:
1009*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)
1010| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1011break;
1012case 16:
1013// Somehow 16-bit is always 15-bits really
1014//*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);
1015//break;
1016case 15:
1017*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);
1018break;
1019}
1020}
1021}
1022}
1023
1024void updateVRAM()
1025{
1026if (gui.redraw)
1027{
1028if (gui.devicelist.draw)
1029blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
1030
1031if (gui.bootprompt.draw)
1032blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
1033
1034if (gui.menu.draw)
1035blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
1036
1037if (gui.infobox.draw)
1038blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
1039}
1040
1041vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
1042
1043if (gui.redraw)
1044{
1045memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
1046gui.redraw = false;
1047}
1048}
1049
1050struct putc_info {
1051 char * str;
1052 char * last_str;
1053};
1054
1055static void
1056sputc(int c, struct putc_info * pi)
1057{
1058 if (pi->last_str)
1059 if (pi->str == pi->last_str) {
1060 *(pi->str) = '\0';
1061 return;
1062 }
1063 *(pi->str)++ = c;
1064}
1065
1066int gprintf( window_t * window, const char * fmt, ...)
1067{
1068char *formattedtext;
1069
1070va_list ap;
1071
1072struct putc_info pi;
1073
1074if ((formattedtext = malloc(1024)) != NULL) {
1075// format the text
1076va_start(ap, fmt);
1077pi.str = formattedtext;
1078pi.last_str = 0;
1079prf(fmt, ap, sputc, &pi);
1080*pi.str = '\0';
1081va_end(ap);
1082
1083position_torigin, cursor, bounds;
1084
1085int i;
1086int character;
1087
1088origin.x = MAX( window->cursor.x, window->hborder );
1089origin.y = MAX( window->cursor.y, window->vborder );
1090
1091bounds.x = ( window->width - window->hborder );
1092bounds.y = ( window->height - window->vborder );
1093
1094cursor = origin;
1095
1096font_t *font = &font_console;
1097
1098for( i=0; i< strlen(formattedtext); i++ )
1099{
1100character = formattedtext[i];
1101
1102character -= 32;
1103
1104// newline ?
1105if( formattedtext[i] == '\n' )
1106{
1107cursor.x = window->hborder;
1108cursor.y += font->height;
1109
1110if ( cursor.y > bounds.y )
1111cursor.y = origin.y;
1112
1113continue;
1114}
1115
1116// tab ?
1117if( formattedtext[i] == '\t' )
1118cursor.x += ( font->chars[0]->width * 5 );
1119
1120// draw the character
1121if( font->chars[character])
1122blend(font->chars[character], window->pixmap, cursor);
1123
1124cursor.x += font->chars[character]->width;
1125
1126// check x pos and do newline
1127if ( cursor.x > bounds.x )
1128{
1129cursor.x = origin.x;
1130cursor.y += font->height;
1131}
1132
1133// check y pos and reset to origin.y
1134if ( cursor.y > bounds.y )
1135cursor.y = origin.y;
1136}
1137
1138// update cursor postition
1139window->cursor = cursor;
1140
1141free(formattedtext);
1142
1143return 0;
1144
1145}
1146return 1;
1147}
1148
1149int dprintf( window_t * window, const char * fmt, ...)
1150{
1151char *formattedtext;
1152
1153va_list ap;
1154
1155//window = &gui.debug;
1156
1157struct putc_info pi;
1158
1159if ((formattedtext = malloc(1024)) != NULL) {
1160// format the text
1161va_start(ap, fmt);
1162pi.str = formattedtext;
1163pi.last_str = 0;
1164prf(fmt, ap, sputc, &pi);
1165*pi.str = '\0';
1166va_end(ap);
1167
1168position_torigin, cursor, bounds;
1169
1170int i;
1171int character;
1172
1173origin.x = MAX( gui.debug.cursor.x, window->hborder );
1174origin.y = MAX( gui.debug.cursor.y, window->vborder );
1175
1176bounds.x = ( window->width - window->hborder );
1177bounds.y = ( window->height - window->vborder );
1178
1179cursor = origin;
1180
1181font_t *font = &font_console;
1182
1183for( i=0; i< strlen(formattedtext); i++ )
1184{
1185character = formattedtext[i];
1186
1187character -= 32;
1188
1189// newline ?
1190if( formattedtext[i] == '\n' )
1191{
1192cursor.x = window->hborder;
1193cursor.y += font->height;
1194
1195if ( cursor.y > bounds.y )
1196cursor.y = origin.y;
1197
1198continue;
1199}
1200
1201// tab ?
1202if( formattedtext[i] == '\t' )
1203cursor.x += ( font->chars[0]->width * 5 );
1204
1205// draw the character
1206if( font->chars[character])
1207blend(font->chars[character], gui.backbuffer, cursor);
1208
1209cursor.x += font->chars[character]->width;
1210
1211// check x pos and do newline
1212if ( cursor.x > bounds.x )
1213{
1214cursor.x = origin.x;
1215cursor.y += font->height;
1216}
1217
1218// check y pos and reset to origin.y
1219if ( cursor.y > bounds.y )
1220cursor.y = origin.y;
1221}
1222
1223// update cursor postition
1224gui.debug.cursor = cursor;
1225
1226free(formattedtext);
1227
1228return 0;
1229
1230}
1231return 1;
1232}
1233
1234int vprf(const char * fmt, va_list ap)
1235{
1236int i;
1237int character;
1238
1239char *formattedtext;
1240window_t *window = &gui.screen;
1241struct putc_info pi;
1242
1243position_torigin, cursor, bounds;
1244font_t *font = &font_console;
1245
1246if ((formattedtext = malloc(1024)) != NULL) {
1247// format the text
1248pi.str = formattedtext;
1249pi.last_str = 0;
1250prf(fmt, ap, sputc, &pi);
1251*pi.str = '\0';
1252
1253origin.x = MAX( window->cursor.x, window->hborder );
1254origin.y = MAX( window->cursor.y, window->vborder );
1255bounds.x = ( window->width - ( window->hborder * 2 ) );
1256bounds.y = ( window->height - ( window->vborder * 2 ) );
1257cursor = origin;
1258
1259for( i=0; i< strlen(formattedtext); i++ )
1260{
1261character = formattedtext[i];
1262character -= 32;
1263
1264// newline ?
1265if( formattedtext[i] == '\n' )
1266{
1267cursor.x = window->hborder;
1268cursor.y += font->height;
1269if ( cursor.y > bounds.y )
1270{
1271gui.redraw = true;
1272updateVRAM();
1273cursor.y = window->vborder;
1274}
1275window->cursor.y = cursor.y;
1276continue;
1277}
1278
1279// tab ?
1280if( formattedtext[i] == '\t' )
1281{
1282cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
1283continue;
1284}
1285cursor.x += font->chars[character]->width;
1286
1287// check x pos and do newline
1288if ( cursor.x > bounds.x )
1289{
1290cursor.x = origin.x;
1291cursor.y += font->height;
1292}
1293
1294// check y pos and reset to origin.y
1295if ( cursor.y > ( bounds.y + font->chars[0]->height) )
1296{
1297gui.redraw = true;
1298updateVRAM();
1299cursor.y = window->vborder;
1300}
1301// draw the character
1302if( font->chars[character])
1303blend(font->chars[character], gui.backbuffer, cursor);
1304}
1305// save cursor postition
1306window->cursor.x = cursor.x;
1307updateVRAM();
1308free(formattedtext);
1309return 0;
1310}
1311return 1;
1312}
1313
1314void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)
1315{
1316int i=0;
1317int y=0; // we need this to support multilines '\n'
1318int x=0;
1319
1320for(i=0;i<strlen(ch);i++)
1321{
1322int cha=(int)ch[i];
1323
1324cha-=32;
1325
1326// newline ?
1327if( ch[i] == '\n' )
1328{
1329x = 0;
1330y += font->height;
1331continue;
1332}
1333
1334// tab ?
1335if( ch[i] == '\t' )
1336x+=(font->chars[0]->width*5);
1337
1338if(font->chars[cha])
1339blend(font->chars[cha], blendInto, pos(p.x+x, p.y+y));
1340
1341x += font->chars[cha]->width;
1342}
1343}
1344
1345void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)
1346{
1347int i = 0;
1348int width = 0;
1349
1350// calculate the width in pixels
1351for(i=0;i<strlen(text);i++)
1352width += font->chars[text[i]-32]->width;
1353
1354p.x = ( p.x - ( width / 2 ) );
1355p.y = ( p.y - ( font->height / 2 ) );
1356
1357if ( p.x == -6 )
1358{
1359p.x = 0;
1360}
1361
1362for(i=0;i<strlen(text);i++)
1363{
1364int cha=(int)text[i];
1365
1366cha-=32;
1367
1368if(font->chars[cha])
1369{
1370blend(font->chars[cha], blendInto, p);
1371p.x += font->chars[cha]->width;
1372}
1373}
1374
1375}
1376
1377int initFont(font_t *font, image_t *data)
1378{
1379unsigned int x = 0, y = 0, x2 = 0, x3 = 0;
1380
1381int start = 0, end = 0, count = 0, space = 0;
1382
1383bool monospaced = false;
1384
1385font->height = data->image->height;
1386
1387for( x = 0; x < data->image->width; x++)
1388{
1389start = end;
1390
1391// if the pixel is red we've reached the end of the char
1392if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
1393{
1394end = x + 1;
1395
1396if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
1397{
1398font->chars[count]->width = ( end - start) - 1;
1399font->chars[count]->height = font->height;
1400
1401if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
1402{
1403space += ( font->chars[count]->width * data->image->height * 4 );
1404// we skip the first line because there are just the red pixels for the char width
1405for( y = 1; y< (font->height); y++)
1406{
1407for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
1408{
1409pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
1410}
1411}
1412
1413// check if font is monospaced
1414if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
1415monospaced = true;
1416
1417font->width = font->chars[count]->width;
1418
1419count++;
1420}
1421}
1422}
1423}
1424
1425if(monospaced)
1426font->width = 0;
1427
1428return 0;
1429}
1430
1431void colorFont(font_t *font, uint32_t color)
1432{
1433if( !color )
1434return;
1435
1436int x, y, width, height;
1437int count = 0;
1438pixel_t *buff;
1439
1440while( font->chars[count++] )
1441{
1442width = font->chars[count-1]->width;
1443height = font->chars[count-1]->height;
1444for( y = 0; y < height; y++ )
1445{
1446for( x = 0; x < width; x++ )
1447{
1448buff = &(pixel( font->chars[count-1], x, y ));
1449if( buff->ch.a )
1450{
1451buff->ch.r = (color & 0xFFFF0000) >> 16;
1452buff->ch.g = (color & 0xFF00FF00) >> 8;
1453buff->ch.b = (color & 0xFF0000FF);
1454}
1455}
1456}
1457}
1458}
1459
1460void makeRoundedCorners(pixmap_t *p)
1461{
1462int x,y;
1463int width=p->width-1;
1464int height=p->height-1;
1465
1466// 10px rounded corner alpha values
1467uint8_t roundedCorner[10][10] =
1468{
1469{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},
1470{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},
1471{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1472{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1473{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1474{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1475{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1476{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1477{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1478{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
1479};
1480
1481uint8_t alpha=0;
1482
1483for( y=0; y<10; y++)
1484{
1485for( x=0; x<10; x++)
1486{
1487// skip if the pixel should be visible
1488if(roundedCorner[y][x] != 0xFF)
1489{
1490alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
1491// Upper left corner
1492pixel(p, x, y).ch.a = alpha;
1493
1494// upper right corner
1495pixel(p, width-x,y).ch.a = alpha;
1496
1497// lower left corner
1498pixel(p, x, height-y).ch.a = alpha;
1499
1500// lower right corner
1501pixel(p, width-x, height-y).ch.a = alpha;
1502}
1503}
1504}
1505}
1506
1507void showInfoBox(char *title, char *text)
1508{
1509int i, key, lines, visiblelines;
1510
1511int currentline=0;
1512int cnt=0;
1513int offset=0;
1514
1515if( !title || !text )
1516return;
1517
1518position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );
1519
1520// calculate number of lines in the title
1521for ( i = 0, lines = 1; i<strlen(title); i++ )
1522if( title[i] == '\n')
1523lines++;
1524
1525// y position of text is lines in title * height of font
1526position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));
1527
1528// calculate number of lines in the text
1529for ( i=0, lines = 1; i<strlen(text); i++ )
1530if( text[i] == '\n')
1531lines++;
1532
1533// if text ends with \n strip off
1534if( text[i] == '\n' || text[i] == '\0')
1535lines--;
1536
1537visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
1538
1539// lets display the text and allow scroll thru using up down / arrows
1540while(1)
1541{
1542// move to current line in text
1543for( offset = 0, i = 0; offset < strlen(text); offset++ )
1544{
1545if( currentline == i)
1546break;
1547if( text[offset] =='\n')
1548i++;
1549}
1550
1551// find last visible line in text and place \0
1552for( i = offset, cnt = 0; i < strlen(text); i++)
1553{
1554if(text[i]=='\n')
1555cnt++;
1556if ( cnt == visiblelines )
1557{
1558text[i]='\0';
1559break;
1560}
1561}
1562
1563fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);
1564
1565makeRoundedCorners( gui.infobox.pixmap);
1566
1567// print the title if present
1568if( title )
1569drawStr(title, &font_console, gui.infobox.pixmap, pos_title);
1570
1571// print the text
1572drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);
1573
1574// restore \n in text
1575if ( cnt == visiblelines )
1576text[i] = '\n';
1577
1578position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
1579
1580// draw prev indicator
1581if(offset)
1582{
1583blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
1584}
1585
1586// draw next indicator
1587if( lines > ( currentline + visiblelines ) )
1588{
1589pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
1590blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
1591}
1592
1593gui.bootprompt.draw = false;
1594gui.infobox.draw = true;
1595gui.redraw = true;
1596
1597updateVRAM();
1598
1599key = getc();
1600
1601if( key == kUpArrowkey )
1602if( currentline > 0 )
1603currentline--;
1604
1605if( key == kDownArrowkey )
1606if( lines > ( currentline + visiblelines ) )
1607currentline++;
1608
1609if( key == kEscapeKey || key == 'q' || key == 'Q')
1610{
1611gui.infobox.draw = false;
1612gui.redraw = true;
1613updateVRAM();
1614break;
1615}
1616}
1617}
1618
1619void animateProgressBar()
1620{
1621int y;
1622
1623if( time18() > lasttime)
1624{
1625lasttime = time18();
1626
1627pixmap_t *buffBar = images[iProgressBar].image;
1628
1629uint32_t buff = buffBar->pixels[0].value;
1630
1631memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );
1632
1633for( y = buffBar->height - 1; y > 0; y--)
1634pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);
1635
1636pixel(buffBar, buffBar->width-1, 0).value = buff;
1637}
1638}
1639
1640void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)
1641{
1642if(progress>100)
1643return;
1644
1645p.x = ( p.x - ( width / 2 ) );
1646
1647int todraw = (width * progress) / 100;
1648
1649pixmap_t *buff = images[iProgressBar].image;
1650pixmap_t *buffBG = images[iProgressBarBackground].image;
1651if(!buff || !buffBG)
1652return;
1653
1654pixmap_t progressbar;
1655progressbar.pixels=malloc(width * 4 * buff->height);
1656if(!progressbar.pixels)
1657return;
1658
1659progressbar.width = width;
1660progressbar.height = buff->height;
1661
1662int x=0,x2=0,y=0;
1663
1664for(y=0; y<buff->height; y++)
1665{
1666for(x=0; x<todraw; x++, x2++)
1667{
1668if(x2 == (buff->width-1)) x2=0;
1669pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;
1670}
1671x2=0;
1672}
1673
1674for(y=0; y<buff->height; y++)
1675{
1676for(x=todraw, x2 = 0; x < width - 1; x++, x2++)
1677{
1678if(x2 == (buffBG->width -2 )) x2 = 0;
1679pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;
1680}
1681if(progress < 100)
1682pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1683if(progress == 0)
1684pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1685x2=0;
1686}
1687
1688blend(&progressbar, blendInto, p);
1689animateProgressBar();
1690free(progressbar.pixels);
1691}
1692
1693void drawInfoMenuItems()
1694{
1695int i,n;
1696
1697position_t position;
1698
1699pixmap_t *selection = images[iMenuSelection].image;
1700
1701pixmap_t *pbuff;
1702
1703fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);
1704
1705makeRoundedCorners(gui.menu.pixmap);
1706
1707uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;
1708
1709position = pos(0,0);
1710
1711for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)
1712{
1713if (i == infoMenuSelection)
1714blend(selection, gui.menu.pixmap, position);
1715
1716pbuff = images[n].image;
1717if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)
1718blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
1719pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1720else
1721blend( pbuff, gui.menu.pixmap,
1722pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1723
1724drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap,
1725pos(position.x + (pbuff->width + gui.menu.hborder),
1726position.y + ((selection->height - font_console.height) / 2)));
1727position.y += images[iMenuSelection].image->height;
1728
1729}
1730
1731gui.redraw = true;
1732}
1733
1734int drawInfoMenu()
1735{
1736drawInfoMenuItems();
1737
1738gui.menu.draw = true;
1739
1740updateVRAM();
1741
1742return 1;
1743}
1744
1745int updateInfoMenu(int key)
1746{
1747switch (key)
1748{
1749
1750case kUpArrowkey:// up arrow
1751if (infoMenuSelection > 0)
1752{
1753if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)
1754infoMenuSelection -= 4;
1755
1756else
1757infoMenuSelection--;
1758drawInfoMenuItems();
1759updateVRAM();
1760
1761} else {
1762
1763gui.menu.draw = false;
1764gui.redraw = true;
1765
1766updateVRAM();
1767
1768return CLOSE_INFO_MENU;
1769}
1770break;
1771
1772case kDownArrowkey:// down arrow
1773if (infoMenuSelection < infoMenuItemsCount - 1)
1774{
1775if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
1776infoMenuSelection += 4;
1777else
1778infoMenuSelection++;
1779drawInfoMenuItems();
1780updateVRAM();
1781}
1782break;
1783
1784case kReturnKey:
1785key = 0;
1786if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )
1787showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
1788
1789else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )
1790showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
1791
1792else if( infoMenuSelection == MENU_SHOW_HELP )
1793showHelp();
1794
1795else
1796{
1797int buff = infoMenuSelection;
1798infoMenuSelection = 0;
1799return buff;
1800}
1801break;
1802}
1803return DO_NOT_BOOT;
1804}
1805
1806uint16_t bootImageWidth = 0;
1807uint16_t bootImageHeight = 0;
1808uint8_t *bootImageData = NULL;
1809static bool usePngImage = true;
1810
1811//==========================================================================
1812// loadBootGraphics Azi: loading "boot logo"
1813static void loadBootGraphics(void)
1814{
1815if (bootImageData != NULL) {
1816return;
1817}
1818
1819char dirspec[256];
1820
1821if ((strlen(theme_name) + 24) > sizeof(dirspec)) {
1822usePngImage = false;
1823return;
1824}
1825//Azi: Should this be bt(0,0)!?
1826sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);
1827if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {
1828#ifdef EMBED_THEME
1829 if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
1830#endif
1831usePngImage = false;
1832}
1833}
1834
1835//==========================================================================
1836// drawBootGraphics Azi: drawing graphics for the boot process (after pressing Enter to boot)
1837void drawBootGraphics(void)
1838{
1839int pos;
1840int length, count;
1841const char *dummyVal;
1842int oldScreenWidth, oldScreenHeight;
1843bool legacy_logo;
1844uint16_t x, y;
1845
1846if (getBoolForKey(kLegacyLogoKey, &legacy_logo, &bootInfo->bootConfig) && legacy_logo) {
1847usePngImage = false;
1848} else if (bootImageData == NULL) {
1849loadBootGraphics();
1850}
1851
1852/*
1853 * AutoResolution
1854 */
1855if (gAutoResolution == true)
1856{
1857// Get Resolution from Graphics Mode key
1858count = getNumberArrayFromProperty(kGraphicsModeKey, screen_params, 4);
1859
1860// If no Graphics Mode key, get it from EDID
1861if ( count < 3 )
1862{
1863getResolution(screen_params);
1864}
1865 }
1866else
1867{
1868 // parse display size parameters //Azi: check this stuff!!!...
1869if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0)
1870{
1871screen_params[0] = pos;
1872}
1873
1874if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0)
1875{
1876screen_params[1] = pos;
1877}
1878}
1879
1880// Save current screen resolution.
1881oldScreenWidth = gui.screen.width; //Azi: ... and this stuff too!!!
1882oldScreenHeight = gui.screen.height;
1883
1884gui.screen.width = screen_params[0];
1885gui.screen.height = screen_params[1];
1886
1887// find best matching vesa mode for our requested width & height
1888getGraphicModeParams(screen_params);
1889
1890 // Set graphics mode if the booter was in text mode or the screen resolution has changed.
1891if (bootArgs->Video.v_display == VGA_TEXT_MODE
1892|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )
1893{
1894setVideoMode(GRAPHICS_MODE, 0);
1895}
1896
1897if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) {
1898drawCheckerBoard();
1899} else {
1900// Fill the background to 75% grey (same as BootX).
1901drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
1902}
1903if ((bootImageData) && (usePngImage)) {
1904x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
1905y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
1906
1907// Draw the image in the center of the display.
1908blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
1909} else {
1910uint8_t *appleBootPict;
1911bootImageData = NULL;
1912bootImageWidth = kAppleBootWidth;
1913bootImageHeight = kAppleBootHeight;
1914
1915// Prepare the data for the default Apple boot image.
1916appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
1917if (appleBootPict) {
1918convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
1919if (bootImageData) {
1920x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
1921y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
1922drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
1923free(bootImageData);
1924}
1925free(appleBootPict);
1926}
1927}
1928}
1929

Archive Download this file

Revision: 380