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

Archive Download this file

Revision: 2459