Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/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];
848gDualLink =((screen_params[0] * screen_params[1]) > (1<<20))?1:0;
849
850// load graphics otherwise fail and return
851if (loadGraphics() == 0) {
852loadThemeValues(&bootInfo->themeConfig);
853colorFont(&font_small, gui.screen.font_small_color);
854colorFont(&font_console, gui.screen.font_console_color);
855
856// create the screen & window buffers
857if (createBackBuffer(&gui.screen) == 0) {
858if (createWindowBuffer(&gui.screen) == 0) {
859if (createWindowBuffer(&gui.devicelist) == 0) {
860if (createWindowBuffer(&gui.bootprompt) == 0) {
861if (createWindowBuffer(&gui.infobox) == 0) {
862if (createWindowBuffer(&gui.menu) == 0) {
863 gui.logo.draw = true;
864drawBackground();
865// lets copy the screen into the back buffer
866memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
867setVideoMode( GRAPHICS_MODE, 0 );
868gui.initialised = true;
869return 0;
870}
871}
872}
873}
874}
875}
876}
877
878 // not available memory, freeing resources
879 freeWindowBuffer(&gui.menu);
880 freeWindowBuffer(&gui.infobox);
881 freeWindowBuffer(&gui.bootprompt);
882 freeWindowBuffer(&gui.devicelist);
883 freeWindowBuffer(&gui.screen);
884 freeBackBuffer(&gui.screen);
885 unloadGraphics();
886
887return 1;
888}
889
890bool is_image_loaded(int i)
891{
892return (images[i].image != NULL) ? true : false;
893}
894
895void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected)
896{
897int devicetype;
898
899if( diskIsCDROM(device) )
900devicetype = iDeviceCDROM;// Use CDROM icon
901else
902{
903switch (device->part_type)
904{
905case kPartitionTypeHFS:
906{
907
908// Use HFS or HFSRAID icon depending on bvr flags.
909if (device->flags & kBVFlagBooter)
910{
911
912switch (device->OSVersion[3]) {
913case '8':
914devicetype = is_image_loaded(iDeviceHFSRAID_ML) ? iDeviceHFSRAID_ML : is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;
915break;
916case '7':
917devicetype = is_image_loaded(iDeviceHFSRAID_Lion) ? iDeviceHFSRAID_Lion : is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;
918break;
919case '6':
920devicetype = is_image_loaded(iDeviceHFSRAID_SL) ? iDeviceHFSRAID_SL : is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;
921break;
922case '5':
923devicetype = is_image_loaded(iDeviceHFSRAID_Leo) ? iDeviceHFSRAID_Leo : is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;
924break;
925case '4':
926devicetype = is_image_loaded(iDeviceHFSRAID_Tiger) ? iDeviceHFSRAID_Tiger : is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;
927break;
928default:
929devicetype = is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;
930break;
931}
932
933} else {
934
935switch (device->OSVersion[3]) {
936case '8':
937devicetype = is_image_loaded(iDeviceHFS_ML) ? iDeviceHFS_ML : is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;
938break;
939case '7':
940devicetype = is_image_loaded(iDeviceHFS_Lion) ? iDeviceHFS_Lion : is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;
941break;
942case '6':
943devicetype = is_image_loaded(iDeviceHFS_SL) ? iDeviceHFS_SL : is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;
944break;
945case '5':
946devicetype = is_image_loaded(iDeviceHFS_Leo) ? iDeviceHFS_Leo : is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;
947break;
948case '4':
949devicetype = is_image_loaded(iDeviceHFS_Tiger) ? iDeviceHFS_Tiger : is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;
950break;
951default:
952devicetype = is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;
953break;
954}
955
956}
957
958break;
959
960}
961case kPartitionTypeHPFS:
962devicetype = is_image_loaded(iDeviceNTFS) ? iDeviceNTFS : iDeviceGeneric;// Use HPFS / NTFS icon
963break;
964
965case kPartitionTypeFAT16:
966devicetype = is_image_loaded(iDeviceFAT16) ? iDeviceFAT16 : iDeviceGeneric;// Use FAT16 icon
967break;
968
969case kPartitionTypeFAT32:
970devicetype = is_image_loaded(iDeviceFAT32) ? iDeviceFAT32 : iDeviceGeneric;// Use FAT32 icon
971break;
972
973case kPartitionTypeEXT3:
974devicetype = is_image_loaded(iDeviceEXT3) ? iDeviceEXT3 : iDeviceGeneric;// Use EXT2/3 icon
975break;
976
977case kPartitionTypeFreeBSD: /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */
978devicetype = is_image_loaded(iDeviceFreeBSD) ? iDeviceFreeBSD : iDeviceGeneric;// Use FreeBSD icon
979break;
980
981case kPartitionTypeOpenBSD: /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */
982devicetype = is_image_loaded(iDeviceOpenBSD) ? iDeviceOpenBSD : iDeviceGeneric;// Use OpenBSD icon
983break;
984
985case kPartitionTypeBEFS: /* Haiku detection and Icon credits to scorpius */
986devicetype = is_image_loaded(iDeviceBEFS) ? iDeviceBEFS : iDeviceGeneric;// Use BEFS / Haiku icon
987break;
988
989default:
990devicetype = iDeviceGeneric;// Use Generic icon
991break;
992}
993}
994
995// Draw the selection image and use the next (device_*_o) image for the selected item.
996 if (isSelected)
997{
998blend(images[iSelection].image, buffer, centeredAt(images[iSelection].image, p));
999devicetype++; // selec override image
1000}
1001
1002// draw icon
1003blend( images[devicetype].image, buffer, centeredAt( images[devicetype].image, p ));
1004
1005p.y += (images[iSelection].image->height / 2) + font_console.chars[0]->height;
1006
1007// draw volume label
1008drawStrCenteredAt( device->label, &font_small, buffer, p);
1009
1010}
1011
1012void drawDeviceList (int start, int end, int selection)
1013{
1014inti;
1015boolshoWinfo = false;
1016extern bool showBootBanner;
1017position_tp, p_prev, p_next;
1018
1019//uint8_tmaxDevices = MIN( gui.maxdevices, menucount );
1020
1021fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);
1022
1023makeRoundedCorners( gui.devicelist.pixmap);
1024
1025switch (gui.layout)
1026{
1027
1028case VerticalLayout:
1029p.x = (gui.devicelist.width /2);
1030p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );
1031
1032// place scroll indicators at top & bottom edges
1033p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );
1034p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );
1035
1036break;
1037
1038default:// use Horizontal layout as the default
1039
1040case HorizontalLayout:
1041p.x = (gui.devicelist.width - ( gui.devicelist.width / gui.maxdevices ) * gui.maxdevices ) / 2 + ( images[iSelection].image->width / 2) + images[iDeviceScrollPrev].image->width + gui.devicelist.iconspacing;
1042p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );
1043
1044// place scroll indicators at left & right edges
1045p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );
1046p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );
1047
1048break;
1049
1050}
1051
1052// draw visible device icons
1053for (i = 0; i < gui.maxdevices; i++)
1054{
1055BVRef param = menuItems[start + i].param;
1056
1057 bool isSelected = ((start + i) == selection) ? true : false;
1058if (isSelected)
1059{
1060 if (param->flags & kBVFlagNativeBoot)
1061 {
1062 infoMenuNativeBoot = true;
1063 }
1064 else
1065 {
1066 infoMenuNativeBoot = false;
1067 if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)
1068 infoMenuSelection = 0;
1069 }
1070
1071if (gui.menu.draw)
1072drawInfoMenuItems();
1073
1074getBoolForKey(kShowInfoKey, &shoWinfo, &bootInfo->chameleonConfig);
1075
1076if (shoWinfo && showBootBanner)
1077{
1078gui.debug.cursor = pos( 10, 100);
1079dprintf( &gui.screen, "label: %s\n", param->label );
1080dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev );
1081dprintf( &gui.screen, "type: 0x%x\n", param->type );
1082dprintf( &gui.screen, "flags: 0x%x\n", param->flags );
1083dprintf( &gui.screen, "part_no: %d\n", param->part_no );
1084dprintf( &gui.screen, "part_boff: 0x%x\n", param->part_boff );
1085dprintf( &gui.screen, "part_type: 0x%x\n", param->part_type );
1086dprintf( &gui.screen, "bps: 0x%x\n", param->bps );
1087dprintf( &gui.screen, "name: %s\n", param->name );
1088dprintf( &gui.screen, "type_name: %s\n", param->type_name );
1089dprintf( &gui.screen, "modtime: %d\n", param->modTime );
1090//// res
1091dprintf( &gui.screen, "width: %d\n", gui.screen.width );
1092dprintf( &gui.screen, "height: %d\n", gui.screen.height );
1093//dprintf( &gui.screen, "attr: 0x%x\n", gui.screen.attr ); //Azi: reminder
1094//dprintf( &gui.screen, "mm: %d\n", gui.screen.mm );
1095}
1096}
1097
1098drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);
1099
1100if (gui.layout == HorizontalLayout)
1101{
1102p.x += images[iSelection].image->width + gui.devicelist.iconspacing;
1103}
1104if (gui.layout == VerticalLayout)
1105{
1106p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing );
1107}
1108}
1109
1110// draw prev indicator
1111if (start)
1112blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );
1113
1114// draw next indicator
1115if ( end < gDeviceCount - 1 )
1116blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );
1117
1118gui.redraw = true;
1119
1120updateVRAM();
1121
1122}
1123
1124void clearGraphicBootPrompt()
1125{
1126// clear text buffer
1127//prompt[0] = '\0';
1128//prompt_pos=0;
1129
1130
1131if(gui.bootprompt.draw == true )
1132{
1133gui.bootprompt.draw = false;
1134gui.redraw = true;
1135// this causes extra frames to be drawn
1136//updateVRAM();
1137}
1138
1139return;
1140}
1141
1142void updateGraphicBootPrompt()
1143{
1144fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);
1145
1146makeRoundedCorners( gui.bootprompt.pixmap);
1147
1148position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );
1149
1150// print the boot prompt text
1151drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);
1152
1153// get the position of the end of the boot prompt text to display user input
1154position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );
1155
1156drawStr( gBootArgs, &font_console, gui.bootprompt.pixmap, p_prompt);
1157
1158gui.menu.draw = false;
1159gui.bootprompt.draw = true;
1160gui.redraw = true;
1161
1162updateVRAM();
1163
1164return;
1165}
1166
1167inline
1168void vramwrite (void *data, int width, int height)
1169{
1170if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)
1171memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
1172else
1173{
1174uint32_t r, g, b;
1175int i, j;
1176for (i = 0; i < VIDEO (height); i++)
1177for (j = 0; j < VIDEO (width); j++)
1178{
1179b = ((uint8_t *) data)[4*i*width + 4*j];
1180g = ((uint8_t *) data)[4*i*width + 4*j + 1];
1181r = ((uint8_t *) data)[4*i*width + 4*j + 2];
1182switch (VIDEO (depth))
1183{
1184case 32:
1185*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1186break;
1187case 24:
1188*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)
1189| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1190break;
1191case 16:
1192// Somehow 16-bit is always 15-bits really
1193//*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);
1194//break;
1195case 15:
1196*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);
1197break;
1198}
1199}
1200}
1201}
1202
1203void updateVRAM()
1204{
1205if (gui.redraw)
1206{
1207if (gui.devicelist.draw)
1208blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
1209
1210if (gui.bootprompt.draw)
1211blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
1212
1213if (gui.menu.draw)
1214blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
1215
1216if (gui.infobox.draw)
1217blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
1218}
1219
1220vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
1221
1222if (gui.redraw)
1223{
1224memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
1225gui.redraw = false;
1226}
1227}
1228
1229struct putc_info //Azi: exists on console.c & printf.c
1230{
1231 char * str;
1232 char * last_str;
1233};
1234
1235static int
1236sputc(int c, struct putc_info * pi) //Azi: same as above
1237{
1238 if (pi->last_str)
1239 if (pi->str == pi->last_str) {
1240 *(pi->str) = '\0';
1241 return 0;
1242 }
1243 *(pi->str)++ = c;
1244 return c;
1245}
1246
1247int gprintf( window_t * window, const char * fmt, ...)
1248{
1249char *formattedtext;
1250
1251va_list ap;
1252
1253struct putc_info pi;
1254
1255if ((formattedtext = malloc(1024)) != NULL) {
1256// format the text
1257va_start(ap, fmt);
1258pi.str = formattedtext;
1259pi.last_str = 0;
1260prf(fmt, ap, sputc, &pi);
1261*pi.str = '\0';
1262va_end(ap);
1263
1264position_torigin, cursor, bounds;
1265
1266int i;
1267int character;
1268
1269origin.x = MAX( window->cursor.x, window->hborder );
1270origin.y = MAX( window->cursor.y, window->vborder );
1271
1272bounds.x = ( window->width - window->hborder );
1273bounds.y = ( window->height - window->vborder );
1274
1275cursor = origin;
1276
1277font_t *font = &font_console;
1278
1279for( i=0; i< strlen(formattedtext); i++ )
1280{
1281character = formattedtext[i];
1282
1283character -= 32;
1284
1285// newline ?
1286if( formattedtext[i] == '\n' )
1287{
1288cursor.x = window->hborder;
1289cursor.y += font->height;
1290
1291if ( cursor.y > bounds.y )
1292cursor.y = origin.y;
1293
1294continue;
1295}
1296
1297// tab ?
1298if( formattedtext[i] == '\t' )
1299cursor.x += ( font->chars[0]->width * 5 );
1300
1301// draw the character
1302if( font->chars[character])
1303blend(font->chars[character], window->pixmap, cursor);
1304
1305cursor.x += font->chars[character]->width;
1306
1307// check x pos and do newline
1308if ( cursor.x > bounds.x )
1309{
1310cursor.x = origin.x;
1311cursor.y += font->height;
1312}
1313
1314// check y pos and reset to origin.y
1315if ( cursor.y > bounds.y )
1316cursor.y = origin.y;
1317}
1318
1319// update cursor postition
1320window->cursor = cursor;
1321
1322free(formattedtext);
1323
1324return 0;
1325
1326}
1327return 1;
1328}
1329
1330int dprintf( window_t * window, const char * fmt, ...)
1331{
1332char *formattedtext;
1333
1334va_list ap;
1335
1336//window = &gui.debug;
1337
1338struct putc_info pi;
1339
1340if ((formattedtext = malloc(1024)) != NULL) {
1341// format the text
1342va_start(ap, fmt);
1343pi.str = formattedtext;
1344pi.last_str = 0;
1345prf(fmt, ap, sputc, &pi);
1346*pi.str = '\0';
1347va_end(ap);
1348
1349position_torigin, cursor, bounds;
1350
1351int i;
1352int character;
1353
1354origin.x = MAX( gui.debug.cursor.x, window->hborder );
1355origin.y = MAX( gui.debug.cursor.y, window->vborder );
1356
1357bounds.x = ( window->width - window->hborder );
1358bounds.y = ( window->height - window->vborder );
1359
1360cursor = origin;
1361
1362font_t *font = &font_console;
1363
1364for( i=0; i< strlen(formattedtext); i++ )
1365{
1366character = formattedtext[i];
1367
1368character -= 32;
1369
1370// newline ?
1371if( formattedtext[i] == '\n' )
1372{
1373cursor.x = window->hborder;
1374cursor.y += font->height;
1375
1376if ( cursor.y > bounds.y )
1377cursor.y = origin.y;
1378
1379continue;
1380}
1381
1382// tab ?
1383if( formattedtext[i] == '\t' )
1384cursor.x += ( font->chars[0]->width * 5 );
1385
1386// draw the character
1387if( font->chars[character])
1388blend(font->chars[character], gui.backbuffer, cursor);
1389
1390cursor.x += font->chars[character]->width;
1391
1392// check x pos and do newline
1393if ( cursor.x > bounds.x )
1394{
1395cursor.x = origin.x;
1396cursor.y += font->height;
1397}
1398
1399// check y pos and reset to origin.y
1400if ( cursor.y > bounds.y )
1401cursor.y = origin.y;
1402}
1403
1404// update cursor postition
1405gui.debug.cursor = cursor;
1406
1407free(formattedtext);
1408
1409return 0;
1410
1411}
1412return 1;
1413}
1414
1415int vprf(const char * fmt, va_list ap)
1416{
1417int i;
1418int character;
1419
1420char *formattedtext;
1421window_t *window = &gui.screen;
1422struct putc_info pi;
1423
1424position_torigin, cursor, bounds;
1425font_t *font = &font_console;
1426
1427if ((formattedtext = malloc(1024)) != NULL) {
1428// format the text
1429pi.str = formattedtext;
1430pi.last_str = 0;
1431prf(fmt, ap, sputc, &pi);
1432*pi.str = '\0';
1433
1434origin.x = MAX( window->cursor.x, window->hborder );
1435origin.y = MAX( window->cursor.y, window->vborder );
1436bounds.x = ( window->width - ( window->hborder * 2 ) );
1437bounds.y = ( window->height - ( window->vborder * 2 ) );
1438cursor = origin;
1439
1440for( i=0; i< strlen(formattedtext); i++ )
1441{
1442character = formattedtext[i];
1443character -= 32;
1444
1445// newline ?
1446if( formattedtext[i] == '\n' )
1447{
1448cursor.x = window->hborder;
1449cursor.y += font->height;
1450if ( cursor.y > bounds.y )
1451{
1452gui.redraw = true;
1453updateVRAM();
1454cursor.y = window->vborder;
1455}
1456window->cursor.y = cursor.y;
1457continue;
1458}
1459
1460// tab ?
1461if( formattedtext[i] == '\t' )
1462{
1463cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
1464continue;
1465}
1466cursor.x += font->chars[character]->width;
1467
1468// check x pos and do newline
1469if ( cursor.x > bounds.x )
1470{
1471cursor.x = origin.x;
1472cursor.y += font->height;
1473}
1474
1475// check y pos and reset to origin.y
1476if ( cursor.y > ( bounds.y + font->chars[0]->height) )
1477{
1478gui.redraw = true;
1479updateVRAM();
1480cursor.y = window->vborder;
1481}
1482// draw the character
1483if( font->chars[character])
1484blend(font->chars[character], gui.backbuffer, cursor);
1485}
1486// save cursor postition
1487window->cursor.x = cursor.x;
1488updateVRAM();
1489free(formattedtext);
1490return 0;
1491}
1492return 1;
1493}
1494
1495pixmap_t* charToPixmap(unsigned char ch, font_t *font) {
1496unsigned int cha = (unsigned int)ch - 32;
1497if (cha >= font->count)
1498// return ? if the font for the char doesn't exists
1499cha = '?' - 32;
1500
1501return font->chars[cha] ? font->chars[cha] : NULL;
1502}
1503
1504position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) {
1505pixmap_t* pm = charToPixmap(ch, font);
1506if (pm && ((p.x + pm->width) < blendInto->width))
1507{
1508blend(pm, blendInto, p);
1509return pos(p.x + pm->width, p.y);
1510}
1511else
1512return p;
1513}
1514
1515void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)
1516{
1517int i=0;
1518position_t current_pos = pos(p.x, p.y);
1519
1520for (i=0; i < strlen(ch); i++)
1521{
1522// newline ?
1523if ( ch[i] == '\n' )
1524{
1525current_pos.x = p.x;
1526current_pos.y += font->height;
1527continue;
1528}
1529
1530// tab ?
1531if ( ch[i] == '\t' )
1532{
1533current_pos.x += TAB_PIXELS_WIDTH;
1534continue;
1535}
1536
1537current_pos = drawChar(ch[i], font, blendInto, current_pos);
1538}
1539}
1540
1541void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)
1542{
1543int i = 0;
1544int width = 0;
1545int max_width = 0;
1546int height = font->height;
1547
1548// calculate the width in pixels
1549for (i=0; i < strlen(text); i++) {
1550if (text[i] == '\n')
1551{
1552width = 0;
1553height += font->height;
1554}
1555else if (text[i] == '\t')
1556width += TAB_PIXELS_WIDTH;
1557else
1558{
1559pixmap_t* pm = charToPixmap(text[i], font);
1560if (pm)
1561width += pm->width;
1562}
1563if (width > max_width)
1564max_width = width;
1565}
1566
1567p.x = ( p.x - ( max_width / 2 ) );
1568p.y = ( p.y - ( height / 2 ) );
1569
1570drawStr(text, font, blendInto, p);
1571}
1572
1573int destroyFont(font_t *font)
1574{
1575 int i;
1576 for (i = 0; i < CHARACTERS_COUNT; i++)
1577 {
1578 if (font->chars[i])
1579 {
1580 if (font->chars[i]->pixels) free (font->chars[i]->pixels);
1581 free (font->chars[i]);
1582 font->chars[i] = 0;
1583 }
1584 }
1585 return 0;
1586}
1587
1588int initFont(font_t *font, image_t *data)
1589{
1590unsigned int x = 0, y = 0, x2 = 0, x3 = 0;
1591
1592int start = 0, end = 0, count = 0, space = 0;
1593
1594bool monospaced = false;
1595
1596font->height = data->image->height;
1597
1598for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++)
1599{
1600start = end;
1601
1602// if the pixel is red we've reached the end of the char
1603if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
1604{
1605end = x + 1;
1606
1607if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
1608{
1609font->chars[count]->width = ( end - start) - 1;
1610font->chars[count]->height = font->height;
1611
1612if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
1613{
1614space += ( font->chars[count]->width * data->image->height * 4 );
1615// we skip the first line because there are just the red pixels for the char width
1616for( y = 1; y< (font->height); y++)
1617{
1618for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
1619{
1620pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
1621}
1622}
1623
1624// check if font is monospaced
1625if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
1626monospaced = true;
1627
1628font->width = font->chars[count]->width;
1629
1630count++;
1631}
1632}
1633}
1634}
1635
1636for (x = count; x < CHARACTERS_COUNT; x++)
1637font->chars[x] = NULL;
1638
1639if(monospaced)
1640font->width = 0;
1641
1642font->count = count;
1643
1644return 0;
1645}
1646
1647void colorFont(font_t *font, uint32_t color)
1648{
1649if( !color )
1650return;
1651
1652int x, y, width, height;
1653int count = 0;
1654pixel_t *buff;
1655
1656while( font->chars[count++] )
1657{
1658width = font->chars[count-1]->width;
1659height = font->chars[count-1]->height;
1660for( y = 0; y < height; y++ )
1661{
1662for( x = 0; x < width; x++ )
1663{
1664buff = &(pixel( font->chars[count-1], x, y ));
1665if( buff->ch.a )
1666{
1667buff->ch.r = (color & 0xFFFF0000) >> 16;
1668buff->ch.g = (color & 0xFF00FF00) >> 8;
1669buff->ch.b = (color & 0xFF0000FF);
1670}
1671}
1672}
1673}
1674}
1675
1676void makeRoundedCorners(pixmap_t *p)
1677{
1678int x,y;
1679int width=p->width-1;
1680int height=p->height-1;
1681
1682// 10px rounded corner alpha values
1683uint8_t roundedCorner[10][10] =
1684{
1685{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},
1686{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},
1687{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1688{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1689{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1690{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1691{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1692{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1693{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1694{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
1695};
1696
1697uint8_t alpha=0;
1698
1699for( y=0; y<10; y++)
1700{
1701for( x=0; x<10; x++)
1702{
1703// skip if the pixel should be visible
1704if(roundedCorner[y][x] != 0xFF)
1705{
1706alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
1707// Upper left corner
1708pixel(p, x, y).ch.a = alpha;
1709
1710// upper right corner
1711pixel(p, width-x,y).ch.a = alpha;
1712
1713// lower left corner
1714pixel(p, x, height-y).ch.a = alpha;
1715
1716// lower right corner
1717pixel(p, width-x, height-y).ch.a = alpha;
1718}
1719}
1720}
1721}
1722
1723void showInfoBox(char *title, char *text_orig)
1724{
1725char* text;
1726int i, key, lines, visiblelines;
1727
1728int currentline=0;
1729int cnt=0;
1730int offset=0;
1731
1732if( !title || !text_orig )
1733return;
1734
1735// Create a copy so that we don't mangle the original
1736text = malloc(strlen(text_orig) + 1);
1737strcpy(text, text_orig);
1738
1739
1740position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );
1741
1742// calculate number of lines in the title
1743for ( i = 0, lines = 1; i<strlen(title); i++ )
1744if( title[i] == '\n')
1745lines++;
1746
1747// y position of text is lines in title * height of font
1748position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));
1749
1750// calculate number of lines in the text
1751for ( i=0, lines = 1; i<strlen(text); i++ )
1752if( text[i] == '\n')
1753lines++;
1754
1755// if text ends with \n strip off
1756if( text[i] == '\n' || text[i] == '\0')
1757lines--;
1758
1759visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
1760
1761// lets display the text and allow scroll thru using up down / arrows
1762while(1)
1763{
1764// move to current line in text
1765for( offset = 0, i = 0; offset < strlen(text); offset++ )
1766{
1767if( currentline == i)
1768break;
1769if( text[offset] =='\n')
1770i++;
1771}
1772
1773// find last visible line in text and place \0
1774for( i = offset, cnt = 0; i < strlen(text); i++)
1775{
1776if(text[i]=='\n')
1777cnt++;
1778if ( cnt == visiblelines )
1779{
1780text[i]='\0';
1781break;
1782}
1783}
1784
1785fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);
1786
1787makeRoundedCorners( gui.infobox.pixmap);
1788
1789// print the title if present
1790if( title )
1791drawStr(title, &font_console, gui.infobox.pixmap, pos_title);
1792
1793// print the text
1794drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);
1795
1796// restore \n in text
1797if ( cnt == visiblelines )
1798text[i] = '\n';
1799
1800position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
1801
1802// draw prev indicator
1803if(offset)
1804{
1805blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
1806}
1807
1808// draw next indicator
1809if( lines > ( currentline + visiblelines ) )
1810{
1811pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
1812blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
1813}
1814
1815gui.bootprompt.draw = false;
1816gui.infobox.draw = true;
1817gui.redraw = true;
1818
1819updateVRAM();
1820
1821key = getchar();
1822
1823if( key == KEY_UP )
1824if( currentline > 0 )
1825currentline--;
1826
1827if( key == KEY_DOWN )
1828if( lines > ( currentline + visiblelines ) )
1829currentline++;
1830
1831if( key == KEY_ESC || key == 'q' || key == 'Q')
1832{
1833gui.infobox.draw = false;
1834gui.redraw = true;
1835updateVRAM();
1836break;
1837}
1838
1839if(key == ' ') // spacebar = next page
1840{
1841if( lines > ( currentline + visiblelines ) )
1842currentline += visiblelines;
1843
1844if(lines < (currentline + visiblelines))
1845currentline = lines - visiblelines;
1846}
1847}
1848}
1849
1850void animateProgressBar()
1851{
1852int y;
1853
1854if( time18() > lasttime)
1855{
1856lasttime = time18();
1857
1858pixmap_t *buffBar = images[iProgressBar].image;
1859
1860uint32_t buff = buffBar->pixels[0].value;
1861
1862memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );
1863
1864for( y = buffBar->height - 1; y > 0; y--)
1865pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);
1866
1867pixel(buffBar, buffBar->width-1, 0).value = buff;
1868}
1869}
1870
1871void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)
1872{
1873if(progress>100)
1874return;
1875
1876p.x = ( p.x - ( width / 2 ) );
1877
1878int todraw = (width * progress) / 100;
1879
1880pixmap_t *buff = images[iProgressBar].image;
1881pixmap_t *buffBG = images[iProgressBarBackground].image;
1882if(!buff || !buffBG)
1883return;
1884
1885pixmap_t progressbar;
1886progressbar.pixels=malloc(width * 4 * buff->height);
1887if(!progressbar.pixels)
1888return;
1889
1890progressbar.width = width;
1891progressbar.height = buff->height;
1892
1893int x=0,x2=0,y=0;
1894
1895for(y=0; y<buff->height; y++)
1896{
1897for(x=0; x<todraw; x++, x2++)
1898{
1899if(x2 == (buff->width-1)) x2=0;
1900pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;
1901}
1902x2=0;
1903}
1904
1905for(y=0; y<buff->height; y++)
1906{
1907for(x=todraw, x2 = 0; x < width - 1; x++, x2++)
1908{
1909if(x2 == (buffBG->width -2 )) x2 = 0;
1910pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;
1911}
1912if(progress < 100)
1913pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1914if(progress == 0)
1915pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1916x2=0;
1917}
1918
1919blend(&progressbar, blendInto, p);
1920animateProgressBar();
1921free(progressbar.pixels);
1922}
1923
1924void drawInfoMenuItems()
1925{
1926int i,n;
1927
1928position_t position;
1929
1930pixmap_t *selection = images[iMenuSelection].image;
1931
1932pixmap_t *pbuff;
1933
1934fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);
1935
1936makeRoundedCorners(gui.menu.pixmap);
1937
1938uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;
1939
1940position = pos(0,0);
1941
1942for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)
1943{
1944if (i == infoMenuSelection)
1945{
1946blend(selection, gui.menu.pixmap, position);
1947}
1948
1949pbuff = images[n].image;
1950if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)
1951{
1952blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
1953pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1954}
1955else
1956{
1957blend( pbuff, gui.menu.pixmap,
1958pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1959}
1960
1961drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap,
1962pos(position.x + (pbuff->width + gui.menu.hborder),
1963position.y + ((selection->height - font_console.height) / 2)));
1964position.y += images[iMenuSelection].image->height;
1965
1966}
1967
1968gui.redraw = true;
1969}
1970
1971int drawInfoMenu()
1972{
1973drawInfoMenuItems();
1974
1975gui.menu.draw = true;
1976
1977updateVRAM();
1978
1979return 1;
1980}
1981
1982int updateInfoMenu(int key)
1983{
1984switch (key)
1985{
1986
1987case KEY_UP:// up arrow
1988if (infoMenuSelection > 0)
1989{
1990if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)
1991{
1992infoMenuSelection -= 4;
1993}
1994else
1995{
1996infoMenuSelection--;
1997}
1998drawInfoMenuItems();
1999updateVRAM();
2000
2001}
2002else
2003{
2004
2005gui.menu.draw = false;
2006gui.redraw = true;
2007
2008updateVRAM();
2009
2010return CLOSE_INFO_MENU;
2011}
2012break;
2013
2014case KEY_DOWN:// down arrow
2015if (infoMenuSelection < infoMenuItemsCount - 1)
2016{
2017if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
2018infoMenuSelection += 4;
2019else
2020infoMenuSelection++;
2021drawInfoMenuItems();
2022updateVRAM();
2023}
2024break;
2025
2026case KEY_ENTER:
2027key = 0;
2028if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )
2029showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
2030
2031else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )
2032showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
2033
2034else if( infoMenuSelection == MENU_SHOW_HELP )
2035showHelp();
2036
2037else
2038{
2039int buff = infoMenuSelection;
2040infoMenuSelection = 0;
2041return buff;
2042}
2043break;
2044}
2045return DO_NOT_BOOT;
2046}
2047
2048uint16_t bootImageWidth = 0;
2049uint16_t bootImageHeight = 0;
2050uint8_t *bootImageData = NULL;
2051static bool usePngImage = true;
2052
2053//==========================================================================
2054// loadBootGraphics
2055static void loadBootGraphics(void)
2056{
2057if (bootImageData != NULL) {
2058return;
2059}
2060
2061char dirspec[256];
2062
2063if ((strlen(theme_name) + 24) > sizeof(dirspec)) {
2064usePngImage = false;
2065return;
2066}
2067sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);
2068if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {
2069#ifdef CONFIG_EMBED_THEME
2070 if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
2071#endif
2072usePngImage = false;
2073}
2074}
2075
2076//==========================================================================
2077// drawBootGraphics
2078void drawBootGraphics(void)
2079{
2080int pos;
2081int length;
2082const char *dummyVal;
2083int oldScreenWidth, oldScreenHeight;
2084bool legacy_logo;
2085uint16_t x, y;
2086
2087if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->chameleonConfig) && legacy_logo) {
2088usePngImage = false;
2089} else if (bootImageData == NULL) {
2090loadBootGraphics();
2091}
2092
2093// parse screen size parameters
2094if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0) {
2095screen_params[0] = pos;
2096} else {
2097screen_params[0] = DEFAULT_SCREEN_WIDTH;
2098}
2099if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0) {
2100screen_params[1] = pos;
2101} else {
2102screen_params[1] = DEFAULT_SCREEN_HEIGHT;
2103}
2104
2105 // Save current screen resolution.
2106oldScreenWidth = gui.screen.width;
2107oldScreenHeight = gui.screen.height;
2108
2109gui.screen.width = screen_params[0];
2110gui.screen.height = screen_params[1];
2111
2112// find best matching vesa mode for our requested width & height
2113getGraphicModeParams(screen_params);
2114
2115 // Set graphics mode if the booter was in text mode or the screen resolution has changed.
2116if (bootArgs->Video.v_display == VGA_TEXT_MODE
2117|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )
2118{
2119setVideoMode(GRAPHICS_MODE, 0);
2120}
2121
2122if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->chameleonConfig)) {
2123drawCheckerBoard();
2124} else {
2125// Fill the background to 75% grey (same as BootX).
2126drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
2127}
2128if ((bootImageData) && (usePngImage)) {
2129x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
2130y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
2131
2132// Draw the image in the center of the display.
2133blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
2134} else {
2135uint8_t *appleBootPict;
2136bootImageData = NULL;
2137bootImageWidth = kAppleBootWidth;
2138bootImageHeight = kAppleBootHeight;
2139
2140// Prepare the data for the default Apple boot image.
2141appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
2142if (appleBootPict) {
2143convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
2144if (bootImageData) {
2145x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
2146y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
2147drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
2148free(bootImageData);
2149}
2150free(appleBootPict);
2151}
2152}
2153}
2154

Archive Download this file

Revision: 1987