Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/Chazi/i386/boot2/gui.c

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

Archive Download this file

Revision: 602