Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Modules/i386/boot2/gui.c

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

Archive Download this file

Revision: 1751