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

Archive Download this file

Revision: 225