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

Archive Download this file

Revision: 232