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

Archive Download this file

Revision: 1823