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

Archive Download this file

Revision: 2341