Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/boot2/gui.c

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

Archive Download this file

Revision: 2766