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

Archive Download this file

Revision: 237