Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 246