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

Archive Download this file

Revision: 1031