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

Archive Download this file

Revision: 1744