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

Archive Download this file

Revision: 2476