Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 1716