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

Archive Download this file

Revision: 2045