Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2403