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

Archive Download this file

Revision: 2430