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

Archive Download this file

Revision: 2839