Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/boot2/gui.c

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

Archive Download this file

Revision: 2083