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

Archive Download this file

Revision: 2658