Chameleon

Chameleon Svn Source Tree

Root/branches/zef/i386/boot2/gui.c

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

Archive Download this file

Revision: 241