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

Archive Download this file

Revision: 463