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

Archive Download this file

Revision: 2457