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

Archive Download this file

Revision: 234