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
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 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 ever
186// manualy generated, 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 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 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 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;
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{
674intval, len;
675chardirspec[128]; //Azi: testing
676
677getValueForKey( kThemeNameKey, &theme_name, &len, &bootInfo->bootConfig );
678if ((strlen(theme_name) + 27) > sizeof(dirspec)) {
679return 1;
680}
681sprintf(dirspec, "bt(0,0)/Extra/Themes/%s/theme.plist", theme_name);
682if (loadConfigFile(dirspec, &bootInfo->themeConfig) != 0) {
683#ifdef EMBED_THEME
684 config_file_t*config;
685
686 config = &bootInfo->themeConfig;
687 if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) {
688 return 1;
689 }
690#else
691return 1;
692#endif
693}
694
695// AutoResolution
696if (gAutoResolution == true)
697{
698screen_params[0] = paramsAR[0];
699screen_params[1] = paramsAR[1];
700 }
701else
702{
703// parse screen size parameters
704 if (getIntForKey("screen_width", &val, &bootInfo->themeConfig) && val > 0)
705{
706screen_params[0] = val;
707}
708
709 if (getIntForKey("screen_height", &val, &bootInfo->themeConfig) && val > 0)
710{
711screen_params[1] = val;
712}
713//Azi: how about using default values?
714}
715
716// Initalizing GUI strucutre.
717bzero(&gui, sizeof(gui_t));
718
719// find best matching vesa mode for our requested width & height
720//loadConfigFile(dirspec, &bootInfo->themeConfig); //Azi: check this later.
721getGraphicModeParams(screen_params);
722
723// set our screen structure with the mode width & height
724gui.screen.width = screen_params[0];
725gui.screen.height = screen_params[1];
726PRINT("Found mode %dx%d in VESA Table\n", gui.screen.width, gui.screen.height);
727//Azi: check why is this printing... (reloadAutoRes/debug)
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: 621