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{
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 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 {
1088 char * str;
1089 char * last_str;
1090};
1091
1092static void
1093sputc(int c, struct putc_info * pi)
1094{
1095 if (pi->last_str)
1096 if (pi->str == pi->last_str) {
1097 *(pi->str) = '\0';
1098 return;
1099 }
1100 *(pi->str)++ = c;
1101}
1102
1103int gprintf( window_t * window, const char * fmt, ...)
1104{
1105char *formattedtext;
1106
1107va_list ap;
1108
1109struct putc_info pi;
1110
1111if ((formattedtext = malloc(1024)) != NULL) {
1112// format the text
1113va_start(ap, fmt);
1114pi.str = formattedtext;
1115pi.last_str = 0;
1116prf(fmt, ap, sputc, &pi);
1117*pi.str = '\0';
1118va_end(ap);
1119
1120position_torigin, cursor, bounds;
1121
1122int i;
1123int character;
1124
1125origin.x = MAX( window->cursor.x, window->hborder );
1126origin.y = MAX( window->cursor.y, window->vborder );
1127
1128bounds.x = ( window->width - window->hborder );
1129bounds.y = ( window->height - window->vborder );
1130
1131cursor = origin;
1132
1133font_t *font = &font_console;
1134
1135for( i=0; i< strlen(formattedtext); i++ )
1136{
1137character = formattedtext[i];
1138
1139character -= 32;
1140
1141// newline ?
1142if( formattedtext[i] == '\n' )
1143{
1144cursor.x = window->hborder;
1145cursor.y += font->height;
1146
1147if ( cursor.y > bounds.y )
1148cursor.y = origin.y;
1149
1150continue;
1151}
1152
1153// tab ?
1154if( formattedtext[i] == '\t' )
1155cursor.x += ( font->chars[0]->width * 5 );
1156
1157// draw the character
1158if( font->chars[character])
1159blend(font->chars[character], window->pixmap, cursor);
1160
1161cursor.x += font->chars[character]->width;
1162
1163// check x pos and do newline
1164if ( cursor.x > bounds.x )
1165{
1166cursor.x = origin.x;
1167cursor.y += font->height;
1168}
1169
1170// check y pos and reset to origin.y
1171if ( cursor.y > bounds.y )
1172cursor.y = origin.y;
1173}
1174
1175// update cursor postition
1176window->cursor = cursor;
1177
1178free(formattedtext);
1179
1180return 0;
1181
1182}
1183return 1;
1184}
1185
1186int dprintf( window_t * window, const char * fmt, ...)
1187{
1188char *formattedtext;
1189
1190va_list ap;
1191
1192//window = &gui.debug;
1193
1194struct putc_info pi;
1195
1196if ((formattedtext = malloc(1024)) != NULL) {
1197// format the text
1198va_start(ap, fmt);
1199pi.str = formattedtext;
1200pi.last_str = 0;
1201prf(fmt, ap, sputc, &pi);
1202*pi.str = '\0';
1203va_end(ap);
1204
1205position_torigin, cursor, bounds;
1206
1207int i;
1208int character;
1209
1210origin.x = MAX( gui.debug.cursor.x, window->hborder );
1211origin.y = MAX( gui.debug.cursor.y, window->vborder );
1212
1213bounds.x = ( window->width - window->hborder );
1214bounds.y = ( window->height - window->vborder );
1215
1216cursor = origin;
1217
1218font_t *font = &font_console;
1219
1220for( i=0; i< strlen(formattedtext); i++ )
1221{
1222character = formattedtext[i];
1223
1224character -= 32;
1225
1226// newline ?
1227if( formattedtext[i] == '\n' )
1228{
1229cursor.x = window->hborder;
1230cursor.y += font->height;
1231
1232if ( cursor.y > bounds.y )
1233cursor.y = origin.y;
1234
1235continue;
1236}
1237
1238// tab ?
1239if( formattedtext[i] == '\t' )
1240cursor.x += ( font->chars[0]->width * 5 );
1241
1242// draw the character
1243if( font->chars[character])
1244blend(font->chars[character], gui.backbuffer, cursor);
1245
1246cursor.x += font->chars[character]->width;
1247
1248// check x pos and do newline
1249if ( cursor.x > bounds.x )
1250{
1251cursor.x = origin.x;
1252cursor.y += font->height;
1253}
1254
1255// check y pos and reset to origin.y
1256if ( cursor.y > bounds.y )
1257cursor.y = origin.y;
1258}
1259
1260// update cursor postition
1261gui.debug.cursor = cursor;
1262
1263free(formattedtext);
1264
1265return 0;
1266
1267}
1268return 1;
1269}
1270
1271int vprf(const char * fmt, va_list ap)
1272{
1273int i;
1274int character;
1275
1276char *formattedtext;
1277window_t *window = &gui.screen;
1278struct putc_info pi;
1279
1280position_torigin, cursor, bounds;
1281font_t *font = &font_console;
1282
1283if ((formattedtext = malloc(1024)) != NULL) {
1284// format the text
1285pi.str = formattedtext;
1286pi.last_str = 0;
1287prf(fmt, ap, sputc, &pi);
1288*pi.str = '\0';
1289
1290origin.x = MAX( window->cursor.x, window->hborder );
1291origin.y = MAX( window->cursor.y, window->vborder );
1292bounds.x = ( window->width - ( window->hborder * 2 ) );
1293bounds.y = ( window->height - ( window->vborder * 2 ) );
1294cursor = origin;
1295
1296for( i=0; i< strlen(formattedtext); i++ )
1297{
1298character = formattedtext[i];
1299character -= 32;
1300
1301// newline ?
1302if( formattedtext[i] == '\n' )
1303{
1304cursor.x = window->hborder;
1305cursor.y += font->height;
1306if ( cursor.y > bounds.y )
1307{
1308gui.redraw = true;
1309updateVRAM();
1310cursor.y = window->vborder;
1311}
1312window->cursor.y = cursor.y;
1313continue;
1314}
1315
1316// tab ?
1317if( formattedtext[i] == '\t' )
1318{
1319cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
1320continue;
1321}
1322cursor.x += font->chars[character]->width;
1323
1324// check x pos and do newline
1325if ( cursor.x > bounds.x )
1326{
1327cursor.x = origin.x;
1328cursor.y += font->height;
1329}
1330
1331// check y pos and reset to origin.y
1332if ( cursor.y > ( bounds.y + font->chars[0]->height) )
1333{
1334gui.redraw = true;
1335updateVRAM();
1336cursor.y = window->vborder;
1337}
1338// draw the character
1339if( font->chars[character])
1340blend(font->chars[character], gui.backbuffer, cursor);
1341}
1342// save cursor postition
1343window->cursor.x = cursor.x;
1344updateVRAM();
1345free(formattedtext);
1346return 0;
1347}
1348return 1;
1349}
1350
1351void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)
1352{
1353int i=0;
1354int y=0; // we need this to support multilines '\n'
1355int x=0;
1356
1357for(i=0;i<strlen(ch);i++)
1358{
1359int cha=(int)ch[i];
1360
1361cha-=32;
1362
1363// newline ?
1364if( ch[i] == '\n' )
1365{
1366x = 0;
1367y += font->height;
1368continue;
1369}
1370
1371// tab ?
1372if( ch[i] == '\t' )
1373x+=(font->chars[0]->width*5);
1374
1375if(font->chars[cha])
1376blend(font->chars[cha], blendInto, pos(p.x+x, p.y+y));
1377
1378x += font->chars[cha]->width;
1379}
1380}
1381
1382void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)
1383{
1384int i = 0;
1385int width = 0;
1386
1387// calculate the width in pixels
1388for(i=0;i<strlen(text);i++)
1389width += font->chars[text[i]-32]->width;
1390
1391p.x = ( p.x - ( width / 2 ) );
1392p.y = ( p.y - ( font->height / 2 ) );
1393
1394if ( p.x == -6 )
1395{
1396p.x = 0;
1397}
1398
1399for(i=0;i<strlen(text);i++)
1400{
1401int cha=(int)text[i];
1402
1403cha-=32;
1404
1405if(font->chars[cha])
1406{
1407blend(font->chars[cha], blendInto, p);
1408p.x += font->chars[cha]->width;
1409}
1410}
1411
1412}
1413
1414int initFont(font_t *font, image_t *data)
1415{
1416unsigned int x = 0, y = 0, x2 = 0, x3 = 0;
1417
1418int start = 0, end = 0, count = 0, space = 0;
1419
1420bool monospaced = false;
1421
1422font->height = data->image->height;
1423
1424for( x = 0; x < data->image->width; x++)
1425{
1426start = end;
1427
1428// if the pixel is red we've reached the end of the char
1429if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
1430{
1431end = x + 1;
1432
1433if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
1434{
1435font->chars[count]->width = ( end - start) - 1;
1436font->chars[count]->height = font->height;
1437
1438if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
1439{
1440space += ( font->chars[count]->width * data->image->height * 4 );
1441// we skip the first line because there are just the red pixels for the char width
1442for( y = 1; y< (font->height); y++)
1443{
1444for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
1445{
1446pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
1447}
1448}
1449
1450// check if font is monospaced
1451if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
1452monospaced = true;
1453
1454font->width = font->chars[count]->width;
1455
1456count++;
1457}
1458}
1459}
1460}
1461
1462if(monospaced)
1463font->width = 0;
1464
1465return 0;
1466}
1467
1468void colorFont(font_t *font, uint32_t color)
1469{
1470if( !color )
1471return;
1472
1473int x, y, width, height;
1474int count = 0;
1475pixel_t *buff;
1476
1477while( font->chars[count++] )
1478{
1479width = font->chars[count-1]->width;
1480height = font->chars[count-1]->height;
1481for( y = 0; y < height; y++ )
1482{
1483for( x = 0; x < width; x++ )
1484{
1485buff = &(pixel( font->chars[count-1], x, y ));
1486if( buff->ch.a )
1487{
1488buff->ch.r = (color & 0xFFFF0000) >> 16;
1489buff->ch.g = (color & 0xFF00FF00) >> 8;
1490buff->ch.b = (color & 0xFF0000FF);
1491}
1492}
1493}
1494}
1495}
1496
1497void makeRoundedCorners(pixmap_t *p)
1498{
1499int x,y;
1500int width=p->width-1;
1501int height=p->height-1;
1502
1503// 10px rounded corner alpha values
1504uint8_t roundedCorner[10][10] =
1505{
1506{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},
1507{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},
1508{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1509{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1510{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1511{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1512{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1513{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1514{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1515{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
1516};
1517
1518uint8_t alpha=0;
1519
1520for( y=0; y<10; y++)
1521{
1522for( x=0; x<10; x++)
1523{
1524// skip if the pixel should be visible
1525if(roundedCorner[y][x] != 0xFF)
1526{
1527alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
1528// Upper left corner
1529pixel(p, x, y).ch.a = alpha;
1530
1531// upper right corner
1532pixel(p, width-x,y).ch.a = alpha;
1533
1534// lower left corner
1535pixel(p, x, height-y).ch.a = alpha;
1536
1537// lower right corner
1538pixel(p, width-x, height-y).ch.a = alpha;
1539}
1540}
1541}
1542}
1543
1544void showInfoBox(char *title, char *text)
1545{
1546int i, key, lines, visiblelines;
1547
1548int currentline=0;
1549int cnt=0;
1550int offset=0;
1551
1552if( !title || !text )
1553return;
1554
1555position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );
1556
1557// calculate number of lines in the title
1558for ( i = 0, lines = 1; i<strlen(title); i++ )
1559if( title[i] == '\n')
1560lines++;
1561
1562// y position of text is lines in title * height of font
1563position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));
1564
1565// calculate number of lines in the text
1566for ( i=0, lines = 1; i<strlen(text); i++ )
1567if( text[i] == '\n')
1568lines++;
1569
1570// if text ends with \n strip off
1571if( text[i] == '\n' || text[i] == '\0')
1572lines--;
1573
1574visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
1575
1576// lets display the text and allow scroll thru using up down / arrows
1577while(1)
1578{
1579// move to current line in text
1580for( offset = 0, i = 0; offset < strlen(text); offset++ )
1581{
1582if( currentline == i)
1583break;
1584if( text[offset] =='\n')
1585i++;
1586}
1587
1588// find last visible line in text and place \0
1589for( i = offset, cnt = 0; i < strlen(text); i++)
1590{
1591if(text[i]=='\n')
1592cnt++;
1593if ( cnt == visiblelines )
1594{
1595text[i]='\0';
1596break;
1597}
1598}
1599
1600fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);
1601
1602makeRoundedCorners( gui.infobox.pixmap);
1603
1604// print the title if present
1605if( title )
1606drawStr(title, &font_console, gui.infobox.pixmap, pos_title);
1607
1608// print the text
1609drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);
1610
1611// restore \n in text
1612if ( cnt == visiblelines )
1613text[i] = '\n';
1614
1615position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
1616
1617// draw prev indicator
1618if(offset)
1619{
1620blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
1621}
1622
1623// draw next indicator
1624if( lines > ( currentline + visiblelines ) )
1625{
1626pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
1627blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
1628}
1629
1630gui.bootprompt.draw = false;
1631gui.infobox.draw = true;
1632gui.redraw = true;
1633
1634updateVRAM();
1635
1636key = getc();
1637
1638if( key == kUpArrowkey )
1639if( currentline > 0 )
1640currentline--;
1641
1642if( key == kDownArrowkey )
1643if( lines > ( currentline + visiblelines ) )
1644currentline++;
1645
1646if( key == kEscapeKey || key == 'q' || key == 'Q')
1647{
1648gui.infobox.draw = false;
1649gui.redraw = true;
1650updateVRAM();
1651break;
1652}
1653}
1654}
1655
1656void animateProgressBar()
1657{
1658int y;
1659
1660if( time18() > lasttime)
1661{
1662lasttime = time18();
1663
1664pixmap_t *buffBar = images[iProgressBar].image;
1665
1666uint32_t buff = buffBar->pixels[0].value;
1667
1668memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );
1669
1670for( y = buffBar->height - 1; y > 0; y--)
1671pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);
1672
1673pixel(buffBar, buffBar->width-1, 0).value = buff;
1674}
1675}
1676
1677void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)
1678{
1679if(progress>100)
1680return;
1681
1682p.x = ( p.x - ( width / 2 ) );
1683
1684int todraw = (width * progress) / 100;
1685
1686pixmap_t *buff = images[iProgressBar].image;
1687pixmap_t *buffBG = images[iProgressBarBackground].image;
1688if(!buff || !buffBG)
1689return;
1690
1691pixmap_t progressbar;
1692progressbar.pixels=malloc(width * 4 * buff->height);
1693if(!progressbar.pixels)
1694return;
1695
1696progressbar.width = width;
1697progressbar.height = buff->height;
1698
1699int x=0,x2=0,y=0;
1700
1701for(y=0; y<buff->height; y++)
1702{
1703for(x=0; x<todraw; x++, x2++)
1704{
1705if(x2 == (buff->width-1)) x2=0;
1706pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;
1707}
1708x2=0;
1709}
1710
1711for(y=0; y<buff->height; y++)
1712{
1713for(x=todraw, x2 = 0; x < width - 1; x++, x2++)
1714{
1715if(x2 == (buffBG->width -2 )) x2 = 0;
1716pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;
1717}
1718if(progress < 100)
1719pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1720if(progress == 0)
1721pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1722x2=0;
1723}
1724
1725blend(&progressbar, blendInto, p);
1726animateProgressBar();
1727free(progressbar.pixels);
1728}
1729
1730void drawInfoMenuItems()
1731{
1732int i,n;
1733
1734position_t position;
1735
1736pixmap_t *selection = images[iMenuSelection].image;
1737
1738pixmap_t *pbuff;
1739
1740fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);
1741
1742makeRoundedCorners(gui.menu.pixmap);
1743
1744uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;
1745
1746position = pos(0,0);
1747
1748for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)
1749{
1750if (i == infoMenuSelection)
1751blend(selection, gui.menu.pixmap, position);
1752
1753pbuff = images[n].image;
1754if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)
1755blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
1756pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1757else
1758blend( pbuff, gui.menu.pixmap,
1759pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1760
1761drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap,
1762pos(position.x + (pbuff->width + gui.menu.hborder),
1763position.y + ((selection->height - font_console.height) / 2)));
1764position.y += images[iMenuSelection].image->height;
1765
1766}
1767
1768gui.redraw = true;
1769}
1770
1771int drawInfoMenu()
1772{
1773drawInfoMenuItems();
1774
1775gui.menu.draw = true;
1776
1777updateVRAM();
1778
1779return 1;
1780}
1781
1782int updateInfoMenu(int key)
1783{
1784switch (key)
1785{
1786
1787case kUpArrowkey:// up arrow
1788if (infoMenuSelection > 0)
1789{
1790if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)
1791infoMenuSelection -= 4;
1792
1793else
1794infoMenuSelection--;
1795drawInfoMenuItems();
1796updateVRAM();
1797
1798} else {
1799
1800gui.menu.draw = false;
1801gui.redraw = true;
1802
1803updateVRAM();
1804
1805return CLOSE_INFO_MENU;
1806}
1807break;
1808
1809case kDownArrowkey:// down arrow
1810if (infoMenuSelection < infoMenuItemsCount - 1)
1811{
1812if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
1813infoMenuSelection += 4;
1814else
1815infoMenuSelection++;
1816drawInfoMenuItems();
1817updateVRAM();
1818}
1819break;
1820
1821case kReturnKey:
1822key = 0;
1823if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )
1824showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
1825
1826else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )
1827showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
1828
1829else if( infoMenuSelection == MENU_SHOW_HELP )
1830showHelp();
1831
1832else
1833{
1834int buff = infoMenuSelection;
1835infoMenuSelection = 0;
1836return buff;
1837}
1838break;
1839}
1840return DO_NOT_BOOT;
1841}
1842
1843uint16_t bootImageWidth = 0;
1844uint16_t bootImageHeight = 0;
1845uint8_t *bootImageData = NULL;
1846static bool usePngImage = true;
1847
1848//==========================================================================
1849// loadBootGraphics
1850static void loadBootGraphics(void)
1851{
1852if (bootImageData != NULL)
1853{
1854return;
1855}
1856
1857char dirspec[128]; //Azi: testing
1858
1859if ((strlen(theme_name) + 24) > sizeof(dirspec))
1860{
1861usePngImage = false;
1862return;
1863}
1864
1865sprintf(dirspec, "bt(0,0)/Extra/Themes/%s/boot.png", theme_name);
1866
1867if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0)
1868{
1869
1870#ifdef EMBED_THEME
1871if ((loadEmbeddedPngImage(__boot_png, __boot_png_len,
1872&bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
1873#endif
1874
1875usePngImage = false;
1876}
1877}
1878
1879//==========================================================================
1880// drawBootGraphics
1881void drawBootGraphics(void)
1882{
1883bool legacy_logo;
1884const char *dummyVal;
1885int pos, length, oldScreenWidth, oldScreenHeight;
1886uint16_t x, y;
1887
1888if (getBoolForKey(kLegacyLogoKey, &legacy_logo, &bootInfo->bootConfig) && legacy_logo)
1889{
1890usePngImage = false;
1891}
1892else if (bootImageData == NULL)
1893{
1894loadBootGraphics();
1895}
1896
1897// Save current screen resolution.
1898oldScreenWidth = gui.screen.width;
1899oldScreenHeight = gui.screen.height;
1900//printf("Res: %dx%d (drawbg: current/old)\n", oldScreenWidth, oldScreenHeight);
1901
1902// AutoResolution
1903if (gAutoResolution == true)
1904{
1905screen_params[0] = paramsAR[0];
1906screen_params[1] = paramsAR[1];
1907//printf("Res: %dx%d (drawbg: AR)\n", screen_params[0], screen_params[1]);
1908}
1909else
1910{
1911// parse boot screen size parameters
1912if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0)
1913{
1914screen_params[0] = pos;
1915}
1916else
1917{
1918screen_params[0] = DEFAULT_SCREEN_WIDTH;
1919}
1920
1921if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0)
1922{
1923screen_params[1] = pos;
1924}
1925else
1926{
1927screen_params[1] = DEFAULT_SCREEN_HEIGHT;
1928}
1929//Azi: and how about not using default values here? like on initGUI...
1930}
1931
1932gui.screen.width = screen_params[0];
1933gui.screen.height = screen_params[1];
1934//printf("Res: %dx%d (drawbg: gsw/h new)\n", gui.screen.width, gui.screen.height);
1935
1936// find best matching vesa mode for our requested width & height
1937getGraphicModeParams(screen_params);
1938
1939//Azi: isn't this sort of done on ExecKernel() ??
1940 // Set graphics mode if the booter was in text mode or the screen resolution has changed.
1941if (bootArgs->Video.v_display == VGA_TEXT_MODE
1942|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight))
1943{
1944setVideoMode(GRAPHICS_MODE, 0);
1945}
1946
1947if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) {
1948drawCheckerBoard();
1949} else {
1950// Fill the background to 75% grey (same as BootX).
1951drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
1952}
1953if ((bootImageData) && (usePngImage)) {
1954x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
1955y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
1956
1957// Draw the image in the center of the display.
1958blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
1959} else {
1960uint8_t *appleBootPict;
1961bootImageData = NULL;
1962bootImageWidth = kAppleBootWidth;
1963bootImageHeight = kAppleBootHeight;
1964
1965// Prepare the data for the default Apple boot image.
1966appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
1967if (appleBootPict) {
1968convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
1969if (bootImageData) {
1970x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
1971y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
1972drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
1973free(bootImageData);
1974}
1975free(appleBootPict);
1976}
1977}
1978}
1979

Archive Download this file

Revision: 815