Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2531