Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 2238