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

Archive Download this file

Revision: 248