Chameleon

Chameleon Svn Source Tree

Root/branches/blackosx/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;
1368int height = font->height;
1369
1370// calculate the width in pixels
1371for (i=0; i < strlen(text); i++) {
1372if (text[i] == '\n')
1373{
1374width = 0;
1375height += font->height;
1376}
1377else if (text[i] == '\t')
1378width += TAB_PIXELS_WIDTH;
1379else
1380{
1381pixmap_t* pm = charToPixmap(text[i], font);
1382if (pm)
1383width += pm->width;
1384}
1385if (width > max_width)
1386max_width = width;
1387}
1388
1389p.x = ( p.x - ( max_width / 2 ) );
1390p.y = ( p.y - ( height / 2 ) );
1391
1392drawStr(text, font, blendInto, p);
1393}
1394
1395int initFont(font_t *font, image_t *data)
1396{
1397unsigned int x = 0, y = 0, x2 = 0, x3 = 0;
1398
1399int start = 0, end = 0, count = 0, space = 0;
1400
1401bool monospaced = false;
1402
1403font->height = data->image->height;
1404
1405for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++)
1406{
1407start = end;
1408
1409// if the pixel is red we've reached the end of the char
1410if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
1411{
1412end = x + 1;
1413
1414if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
1415{
1416font->chars[count]->width = ( end - start) - 1;
1417font->chars[count]->height = font->height;
1418
1419if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
1420{
1421space += ( font->chars[count]->width * data->image->height * 4 );
1422// we skip the first line because there are just the red pixels for the char width
1423for( y = 1; y< (font->height); y++)
1424{
1425for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
1426{
1427pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
1428}
1429}
1430
1431// check if font is monospaced
1432if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
1433monospaced = true;
1434
1435font->width = font->chars[count]->width;
1436
1437count++;
1438}
1439}
1440}
1441}
1442
1443for (x = count; x < CHARACTERS_COUNT; x++)
1444font->chars[x] = NULL;
1445
1446if(monospaced)
1447font->width = 0;
1448
1449font->count = count;
1450
1451return 0;
1452}
1453
1454void colorFont(font_t *font, uint32_t color)
1455{
1456if( !color )
1457return;
1458
1459int x, y, width, height;
1460int count = 0;
1461pixel_t *buff;
1462
1463while( font->chars[count++] )
1464{
1465width = font->chars[count-1]->width;
1466height = font->chars[count-1]->height;
1467for( y = 0; y < height; y++ )
1468{
1469for( x = 0; x < width; x++ )
1470{
1471buff = &(pixel( font->chars[count-1], x, y ));
1472if( buff->ch.a )
1473{
1474buff->ch.r = (color & 0xFFFF0000) >> 16;
1475buff->ch.g = (color & 0xFF00FF00) >> 8;
1476buff->ch.b = (color & 0xFF0000FF);
1477}
1478}
1479}
1480}
1481}
1482
1483void makeRoundedCorners(pixmap_t *p)
1484{
1485int x,y;
1486int width=p->width-1;
1487int height=p->height-1;
1488
1489// 10px rounded corner alpha values
1490uint8_t roundedCorner[10][10] =
1491{
1492{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},
1493{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},
1494{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1495{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1496{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1497{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1498{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1499{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1500{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1501{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
1502};
1503
1504uint8_t alpha=0;
1505
1506for( y=0; y<10; y++)
1507{
1508for( x=0; x<10; x++)
1509{
1510// skip if the pixel should be visible
1511if(roundedCorner[y][x] != 0xFF)
1512{
1513alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
1514// Upper left corner
1515pixel(p, x, y).ch.a = alpha;
1516
1517// upper right corner
1518pixel(p, width-x,y).ch.a = alpha;
1519
1520// lower left corner
1521pixel(p, x, height-y).ch.a = alpha;
1522
1523// lower right corner
1524pixel(p, width-x, height-y).ch.a = alpha;
1525}
1526}
1527}
1528}
1529
1530void showInfoBox(char *title, char *text_orig)
1531{
1532char* text;
1533int i, key, lines, visiblelines;
1534
1535int currentline=0;
1536int cnt=0;
1537int offset=0;
1538
1539if( !title || !text_orig )
1540return;
1541
1542// Create a copy so that we don't mangle the original
1543text = malloc(strlen(text_orig) + 1);
1544strcpy(text, text_orig);
1545
1546
1547position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );
1548
1549// calculate number of lines in the title
1550for ( i = 0, lines = 1; i<strlen(title); i++ )
1551if( title[i] == '\n')
1552lines++;
1553
1554// y position of text is lines in title * height of font
1555position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));
1556
1557// calculate number of lines in the text
1558for ( i=0, lines = 1; i<strlen(text); i++ )
1559if( text[i] == '\n')
1560lines++;
1561
1562// if text ends with \n strip off
1563if( text[i] == '\n' || text[i] == '\0')
1564lines--;
1565
1566visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
1567
1568// lets display the text and allow scroll thru using up down / arrows
1569while(1)
1570{
1571// move to current line in text
1572for( offset = 0, i = 0; offset < strlen(text); offset++ )
1573{
1574if( currentline == i)
1575break;
1576if( text[offset] =='\n')
1577i++;
1578}
1579
1580// find last visible line in text and place \0
1581for( i = offset, cnt = 0; i < strlen(text); i++)
1582{
1583if(text[i]=='\n')
1584cnt++;
1585if ( cnt == visiblelines )
1586{
1587text[i]='\0';
1588break;
1589}
1590}
1591
1592fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);
1593
1594makeRoundedCorners( gui.infobox.pixmap);
1595
1596// print the title if present
1597if( title )
1598drawStr(title, &font_console, gui.infobox.pixmap, pos_title);
1599
1600// print the text
1601drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);
1602
1603// restore \n in text
1604if ( cnt == visiblelines )
1605text[i] = '\n';
1606
1607position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
1608
1609// draw prev indicator
1610if(offset)
1611{
1612blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
1613}
1614
1615// draw next indicator
1616if( lines > ( currentline + visiblelines ) )
1617{
1618pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
1619blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
1620}
1621
1622gui.bootprompt.draw = false;
1623gui.infobox.draw = true;
1624gui.redraw = true;
1625
1626updateVRAM();
1627
1628key = getchar();
1629
1630if( key == KEY_UP )
1631if( currentline > 0 )
1632currentline--;
1633
1634if( key == KEY_DOWN )
1635if( lines > ( currentline + visiblelines ) )
1636currentline++;
1637
1638if( key == KEY_ESC || key == 'q' || key == 'Q')
1639{
1640gui.infobox.draw = false;
1641gui.redraw = true;
1642updateVRAM();
1643break;
1644}
1645
1646if(key == ' ') // spacebar = next page
1647{
1648if( lines > ( currentline + visiblelines ) )
1649currentline += visiblelines;
1650
1651if(lines < (currentline + visiblelines))
1652currentline = lines - visiblelines;
1653}
1654}
1655}
1656
1657void animateProgressBar()
1658{
1659int y;
1660
1661if( time18() > lasttime)
1662{
1663lasttime = time18();
1664
1665pixmap_t *buffBar = images[iProgressBar].image;
1666
1667uint32_t buff = buffBar->pixels[0].value;
1668
1669memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );
1670
1671for( y = buffBar->height - 1; y > 0; y--)
1672pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);
1673
1674pixel(buffBar, buffBar->width-1, 0).value = buff;
1675}
1676}
1677
1678void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)
1679{
1680if(progress>100)
1681return;
1682
1683p.x = ( p.x - ( width / 2 ) );
1684
1685int todraw = (width * progress) / 100;
1686
1687pixmap_t *buff = images[iProgressBar].image;
1688pixmap_t *buffBG = images[iProgressBarBackground].image;
1689if(!buff || !buffBG)
1690return;
1691
1692pixmap_t progressbar;
1693progressbar.pixels=malloc(width * 4 * buff->height);
1694if(!progressbar.pixels)
1695return;
1696
1697progressbar.width = width;
1698progressbar.height = buff->height;
1699
1700int x=0,x2=0,y=0;
1701
1702for(y=0; y<buff->height; y++)
1703{
1704for(x=0; x<todraw; x++, x2++)
1705{
1706if(x2 == (buff->width-1)) x2=0;
1707pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;
1708}
1709x2=0;
1710}
1711
1712for(y=0; y<buff->height; y++)
1713{
1714for(x=todraw, x2 = 0; x < width - 1; x++, x2++)
1715{
1716if(x2 == (buffBG->width -2 )) x2 = 0;
1717pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;
1718}
1719if(progress < 100)
1720pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1721if(progress == 0)
1722pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1723x2=0;
1724}
1725
1726blend(&progressbar, blendInto, p);
1727animateProgressBar();
1728free(progressbar.pixels);
1729}
1730
1731void drawInfoMenuItems()
1732{
1733int i,n;
1734
1735position_t position;
1736
1737pixmap_t *selection = images[iMenuSelection].image;
1738
1739pixmap_t *pbuff;
1740
1741fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);
1742
1743makeRoundedCorners(gui.menu.pixmap);
1744
1745uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;
1746
1747position = pos(0,0);
1748
1749for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)
1750{
1751if (i == infoMenuSelection)
1752blend(selection, gui.menu.pixmap, position);
1753
1754pbuff = images[n].image;
1755if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)
1756blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
1757pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1758else
1759blend( pbuff, gui.menu.pixmap,
1760pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1761
1762drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap,
1763pos(position.x + (pbuff->width + gui.menu.hborder),
1764position.y + ((selection->height - font_console.height) / 2)));
1765position.y += images[iMenuSelection].image->height;
1766
1767}
1768
1769gui.redraw = true;
1770}
1771
1772int drawInfoMenu()
1773{
1774drawInfoMenuItems();
1775
1776gui.menu.draw = true;
1777
1778updateVRAM();
1779
1780return 1;
1781}
1782
1783int updateInfoMenu(int key)
1784{
1785switch (key)
1786{
1787
1788case KEY_UP:// up arrow
1789if (infoMenuSelection > 0)
1790{
1791if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)
1792infoMenuSelection -= 4;
1793
1794else
1795infoMenuSelection--;
1796drawInfoMenuItems();
1797updateVRAM();
1798
1799} else {
1800
1801gui.menu.draw = false;
1802gui.redraw = true;
1803
1804updateVRAM();
1805
1806return CLOSE_INFO_MENU;
1807}
1808break;
1809
1810case KEY_DOWN:// down arrow
1811if (infoMenuSelection < infoMenuItemsCount - 1)
1812{
1813if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
1814infoMenuSelection += 4;
1815else
1816infoMenuSelection++;
1817drawInfoMenuItems();
1818updateVRAM();
1819}
1820break;
1821
1822case KEY_ENTER:
1823key = 0;
1824if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )
1825showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
1826
1827else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )
1828showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
1829
1830else if( infoMenuSelection == MENU_SHOW_HELP )
1831showHelp();
1832
1833else
1834{
1835int buff = infoMenuSelection;
1836infoMenuSelection = 0;
1837return buff;
1838}
1839break;
1840}
1841return DO_NOT_BOOT;
1842}
1843
1844uint16_t bootImageWidth = 0;
1845uint16_t bootImageHeight = 0;
1846uint8_t *bootImageData = NULL;
1847static bool usePngImage = true;
1848
1849//==========================================================================
1850// loadBootGraphics
1851static void loadBootGraphics(void)
1852{
1853if (bootImageData != NULL) {
1854return;
1855}
1856
1857char dirspec[256];
1858
1859if ((strlen(theme_name) + 24) > sizeof(dirspec)) {
1860usePngImage = false;
1861return;
1862}
1863sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);
1864if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {
1865#ifdef CONFIG_EMBED_THEME
1866 if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
1867#endif
1868usePngImage = false;
1869}
1870}
1871
1872//==========================================================================
1873// drawBootGraphics
1874void drawBootGraphics(void)
1875{
1876int pos;
1877int length;
1878const char *dummyVal;
1879int oldScreenWidth, oldScreenHeight;
1880bool legacy_logo;
1881uint16_t x, y;
1882
1883if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->chameleonConfig) && legacy_logo) {
1884usePngImage = false;
1885} else if (bootImageData == NULL) {
1886loadBootGraphics();
1887}
1888
1889// parse screen size parameters
1890if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0) {
1891screen_params[0] = pos;
1892} else {
1893screen_params[0] = DEFAULT_SCREEN_WIDTH;
1894}
1895if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0) {
1896screen_params[1] = pos;
1897} else {
1898screen_params[1] = DEFAULT_SCREEN_HEIGHT;
1899}
1900
1901 // Save current screen resolution.
1902oldScreenWidth = gui.screen.width;
1903oldScreenHeight = gui.screen.height;
1904
1905gui.screen.width = screen_params[0];
1906gui.screen.height = screen_params[1];
1907
1908// find best matching vesa mode for our requested width & height
1909getGraphicModeParams(screen_params);
1910
1911 // Set graphics mode if the booter was in text mode or the screen resolution has changed.
1912if (bootArgs->Video.v_display == VGA_TEXT_MODE
1913|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )
1914{
1915setVideoMode(GRAPHICS_MODE, 0);
1916}
1917
1918if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->chameleonConfig)) {
1919drawCheckerBoard();
1920} else {
1921// Fill the background to 75% grey (same as BootX).
1922drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
1923}
1924if ((bootImageData) && (usePngImage)) {
1925x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
1926y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
1927
1928// Draw the image in the center of the display.
1929blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
1930} else {
1931uint8_t *appleBootPict;
1932bootImageData = NULL;
1933bootImageWidth = kAppleBootWidth;
1934bootImageHeight = kAppleBootHeight;
1935
1936// Prepare the data for the default Apple boot image.
1937appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
1938if (appleBootPict) {
1939convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
1940if (bootImageData) {
1941x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
1942y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
1943drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
1944free(bootImageData);
1945}
1946free(appleBootPict);
1947}
1948}
1949}
1950

Archive Download this file

Revision: 1728