Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/boot2/gui.c

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

Archive Download this file

Revision: 2538