Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2323