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

Archive Download this file

Revision: 1949