Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/boot2/gui.c

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

Archive Download this file

Revision: 1021