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
1307void vramwrite (void *data, int width, int height)
1308{
1309if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)
1310{
1311memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
1312}
1313else
1314{
1315uint32_t r;
1316uint32_t g;
1317uint32_t b;
1318int i, j;
1319for (i = 0; i < VIDEO (height); i++)
1320{
1321for (j = 0; j < VIDEO (width); j++)
1322{
1323b = ((uint8_t *) data)[4*i*width + 4*j];
1324g = ((uint8_t *) data)[4*i*width + 4*j + 1];
1325r = ((uint8_t *) data)[4*i*width + 4*j + 2];
1326switch (VIDEO (depth))
1327{
1328case 32:
1329*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1330break;
1331case 24:
1332*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)
1333| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1334break;
1335case 16:
1336// Somehow 16-bit is always 15-bits really
1337//*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);
1338//break;
1339case 15:
1340*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);
1341break;
1342default:
1343break;
1344}
1345}
1346}
1347}
1348}
1349
1350// ====================================================================
1351
1352void updateVRAM()
1353{
1354if (gui.redraw)
1355{
1356if (gui.devicelist.draw)
1357{
1358blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
1359}
1360if (gui.bootprompt.draw)
1361{
1362blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
1363}
1364if (gui.menu.draw)
1365{
1366blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
1367}
1368if (gui.infobox.draw)
1369{
1370blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
1371}
1372}
1373
1374vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
1375
1376if (gui.redraw)
1377{
1378memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
1379gui.redraw = false;
1380}
1381}
1382
1383// ====================================================================
1384
1385struct putc_info //Azi: exists on console.c & printf.c
1386{
1387char * str;
1388char * last_str;
1389};
1390
1391// ====================================================================
1392
1393static int
1394sputc(int c, struct putc_info * pi) //Azi: same as above
1395{
1396if (pi->last_str)
1397{
1398if (pi->str == pi->last_str)
1399{
1400*(pi->str) = '\0';
1401return 0;
1402}
1403}
1404*(pi->str)++ = c;
1405return c;
1406}
1407
1408// ====================================================================
1409
1410int gprintf( window_t * window, const char * fmt, ...)
1411{
1412char *formattedtext;
1413
1414va_list ap;
1415
1416struct putc_info pi;
1417
1418if ((formattedtext = malloc(1024)) != NULL)
1419{
1420// format the text
1421va_start(ap, fmt);
1422pi.str = formattedtext;
1423pi.last_str = 0;
1424prf(fmt, ap, sputc, &pi);
1425*pi.str = '\0';
1426va_end(ap);
1427
1428position_torigin, cursor, bounds;
1429
1430int i;
1431int character;
1432
1433origin.x = MAX( window->cursor.x, window->hborder );
1434origin.y = MAX( window->cursor.y, window->vborder );
1435
1436bounds.x = ( window->width - window->hborder );
1437bounds.y = ( window->height - window->vborder );
1438
1439cursor = origin;
1440
1441font_t *font = &font_console;
1442
1443for( i=0; i< strlen(formattedtext); i++ )
1444{
1445character = formattedtext[i];
1446
1447character -= 32;
1448
1449// newline ?
1450if( formattedtext[i] == '\n' )
1451{
1452cursor.x = window->hborder;
1453cursor.y += font->height;
1454
1455if ( cursor.y > bounds.y )
1456{
1457cursor.y = origin.y;
1458}
1459continue;
1460}
1461
1462// tab ?
1463if( formattedtext[i] == '\t' )
1464{
1465cursor.x += ( font->chars[0]->width * 5 );
1466}
1467
1468// draw the character
1469if( font->chars[character])
1470{
1471blend(font->chars[character], window->pixmap, cursor);
1472}
1473
1474cursor.x += font->chars[character]->width;
1475
1476// check x pos and do newline
1477if ( cursor.x > bounds.x )
1478{
1479cursor.x = origin.x;
1480cursor.y += font->height;
1481}
1482
1483// check y pos and reset to origin.y
1484if ( cursor.y > bounds.y )
1485{
1486cursor.y = origin.y;
1487}
1488}
1489
1490// update cursor postition
1491window->cursor = cursor;
1492
1493free(formattedtext);
1494
1495return 0;
1496}
1497return 1;
1498}
1499
1500// ====================================================================
1501
1502int dprintf( window_t * window, const char * fmt, ...)
1503{
1504char *formattedtext;
1505
1506va_list ap;
1507
1508//window = &gui.debug;
1509
1510struct putc_info pi;
1511
1512if ((formattedtext = malloc(1024)) != NULL)
1513{
1514// format the text
1515va_start(ap, fmt);
1516pi.str = formattedtext;
1517pi.last_str = 0;
1518prf(fmt, ap, sputc, &pi);
1519*pi.str = '\0';
1520va_end(ap);
1521
1522position_torigin, cursor, bounds;
1523
1524int i;
1525int character;
1526
1527origin.x = MAX( gui.debug.cursor.x, window->hborder );
1528origin.y = MAX( gui.debug.cursor.y, window->vborder );
1529
1530bounds.x = ( window->width - window->hborder );
1531bounds.y = ( window->height - window->vborder );
1532
1533cursor = origin;
1534
1535font_t *font = &font_console;
1536
1537for( i=0; i< strlen(formattedtext); i++ )
1538{
1539character = formattedtext[i];
1540
1541character -= 32;
1542
1543// newline ?
1544if( formattedtext[i] == '\n' )
1545{
1546cursor.x = window->hborder;
1547cursor.y += font->height;
1548
1549if ( cursor.y > bounds.y )
1550{
1551cursor.y = origin.y;
1552}
1553continue;
1554}
1555
1556// tab ?
1557if( formattedtext[i] == '\t' )
1558{
1559cursor.x += ( font->chars[0]->width * 5 );
1560}
1561// draw the character
1562if( font->chars[character])
1563{
1564blend(font->chars[character], gui.backbuffer, cursor);
1565}
1566cursor.x += font->chars[character]->width;
1567
1568// check x pos and do newline
1569if ( cursor.x > bounds.x )
1570{
1571cursor.x = origin.x;
1572cursor.y += font->height;
1573}
1574
1575// check y pos and reset to origin.y
1576if ( cursor.y > bounds.y )
1577{
1578cursor.y = origin.y;
1579}
1580}
1581
1582// update cursor postition
1583gui.debug.cursor = cursor;
1584
1585free(formattedtext);
1586
1587return 0;
1588
1589}
1590return 1;
1591}
1592
1593// ====================================================================
1594
1595int vprf(const char * fmt, va_list ap)
1596{
1597int i;
1598int character;
1599
1600char *formattedtext;
1601window_t *window = &gui.screen;
1602struct putc_info pi;
1603
1604position_torigin, cursor, bounds;
1605font_t *font = &font_console;
1606
1607if ((formattedtext = malloc(1024)) != NULL)
1608{
1609// format the text
1610pi.str = formattedtext;
1611pi.last_str = 0;
1612prf(fmt, ap, sputc, &pi);
1613*pi.str = '\0';
1614
1615origin.x = MAX( window->cursor.x, window->hborder );
1616origin.y = MAX( window->cursor.y, window->vborder );
1617bounds.x = ( window->width - ( window->hborder * 2 ) );
1618bounds.y = ( window->height - ( window->vborder * 2 ) );
1619cursor = origin;
1620
1621for( i=0; i< strlen(formattedtext) ; i++ )
1622{
1623character = formattedtext[i];
1624character -= 32;
1625
1626// newline ?
1627if( formattedtext[i] == '\n' )
1628{
1629cursor.x = window->hborder;
1630cursor.y += font->height;
1631if ( cursor.y > bounds.y )
1632{
1633gui.redraw = true;
1634updateVRAM();
1635cursor.y = window->vborder;
1636}
1637window->cursor.y = cursor.y;
1638continue;
1639}
1640
1641// tab ?
1642if( formattedtext[i] == '\t' )
1643{
1644cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
1645continue;
1646}
1647cursor.x += font->chars[character]->width;
1648
1649// check x pos and do newline
1650if ( cursor.x > bounds.x )
1651{
1652cursor.x = origin.x;
1653cursor.y += font->height;
1654}
1655
1656// check y pos and reset to origin.y
1657if ( cursor.y > ( bounds.y + font->chars[0]->height) )
1658{
1659gui.redraw = true;
1660updateVRAM();
1661cursor.y = window->vborder;
1662}
1663// draw the character
1664if( font->chars[character])
1665{
1666blend(font->chars[character], gui.backbuffer, cursor);
1667}
1668}
1669// save cursor postition
1670window->cursor.x = cursor.x;
1671updateVRAM();
1672free(formattedtext);
1673return 0;
1674}
1675return 1;
1676}
1677
1678// ====================================================================
1679
1680pixmap_t *charToPixmap(unsigned char ch, font_t *font)
1681{
1682unsigned int cha = (unsigned int)ch - 32;
1683if (cha >= font->count)
1684{
1685// return ? if the font for the char doesn't exists
1686cha = '?' - 32;
1687}
1688return font->chars[cha] ? font->chars[cha] : NULL;
1689}
1690
1691// ====================================================================
1692
1693position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p)
1694{
1695pixmap_t* pm = charToPixmap(ch, font);
1696if (pm && ((p.x + pm->width) < blendInto->width))
1697{
1698blend(pm, blendInto, p);
1699return pos(p.x + pm->width, p.y);
1700}
1701else
1702{
1703return p;
1704}
1705}
1706
1707// ====================================================================
1708
1709void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)
1710{
1711int i=0;
1712position_t current_pos = pos(p.x, p.y);
1713
1714for (i=0; i < strlen(ch); i++)
1715{
1716// newline ?
1717if ( ch[i] == '\n' )
1718{
1719current_pos.x = p.x;
1720current_pos.y += font->height;
1721continue;
1722}
1723
1724// tab ?
1725if ( ch[i] == '\t' )
1726{
1727current_pos.x += TAB_PIXELS_WIDTH;
1728continue;
1729}
1730
1731current_pos = drawChar(ch[i], font, blendInto, current_pos);
1732}
1733}
1734
1735// ====================================================================
1736
1737void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)
1738{
1739int i = 0;
1740int width = 0;
1741int max_width = 0;
1742int height = font->height;
1743
1744// calculate the width in pixels
1745for (i=0; i < strlen(text); i++)
1746{
1747if (text[i] == '\n')
1748{
1749width = 0;
1750height += font->height;
1751}
1752else if (text[i] == '\t')
1753{
1754width += TAB_PIXELS_WIDTH;
1755}
1756else
1757{
1758pixmap_t* pm = charToPixmap(text[i], font);
1759if (pm)
1760{
1761width += pm->width;
1762}
1763}
1764if (width > max_width)
1765{
1766max_width = width;
1767}
1768}
1769
1770p.x = ( p.x - ( max_width / 2 ) );
1771p.y = ( p.y - ( height / 2 ) );
1772
1773drawStr(text, font, blendInto, p);
1774}
1775
1776// ====================================================================
1777
1778int destroyFont(font_t *font)
1779{
1780int i;
1781for (i = 0; i < CHARACTERS_COUNT; i++)
1782{
1783if (font->chars[i])
1784{
1785if (font->chars[i]->pixels)
1786{
1787free (font->chars[i]->pixels);
1788}
1789free (font->chars[i]);
1790font->chars[i] = 0;
1791}
1792}
1793return 0;
1794}
1795
1796// ====================================================================
1797
1798int initFont(font_t *font, image_t *data)
1799{
1800unsigned int x = 0, y = 0, x2 = 0, x3 = 0;
1801
1802int start = 0, end = 0, count = 0, space = 0;
1803
1804bool monospaced = false;
1805
1806font->height = data->image->height;
1807
1808for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++)
1809{
1810start = end;
1811
1812// if the pixel is red we've reached the end of the char
1813if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
1814{
1815end = x + 1;
1816
1817if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
1818{
1819font->chars[count]->width = ( end - start) - 1;
1820font->chars[count]->height = font->height;
1821
1822if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
1823{
1824space += ( font->chars[count]->width * data->image->height * 4 );
1825// we skip the first line because there are just the red pixels for the char width
1826for( y = 1; y< (font->height); y++)
1827{
1828for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
1829{
1830pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
1831}
1832}
1833
1834// check if font is monospaced
1835if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
1836{
1837monospaced = true;
1838}
1839
1840font->width = font->chars[count]->width;
1841
1842count++;
1843}
1844}
1845}
1846}
1847
1848for (x = count; x < CHARACTERS_COUNT; x++)
1849{
1850font->chars[x] = NULL;
1851}
1852
1853if(monospaced)
1854{
1855font->width = 0;
1856}
1857
1858font->count = count;
1859
1860return 0;
1861}
1862
1863// ====================================================================
1864
1865void colorFont(font_t *font, uint32_t color)
1866{
1867if( !color )
1868{
1869return;
1870}
1871
1872int x, y, width, height;
1873int count = 0;
1874pixel_t *buff;
1875
1876while( font->chars[count++] )
1877{
1878width = font->chars[count-1]->width;
1879height = font->chars[count-1]->height;
1880for( y = 0; y < height; y++ )
1881{
1882for( x = 0; x < width; x++ )
1883{
1884buff = &(pixel( font->chars[count-1], x, y ));
1885if( buff->ch.a )
1886{
1887buff->ch.r = (color & 0xFFFF0000) >> 16;
1888buff->ch.g = (color & 0xFF00FF00) >> 8;
1889buff->ch.b = (color & 0xFF0000FF);
1890}
1891}
1892}
1893}
1894}
1895
1896// ====================================================================
1897
1898void makeRoundedCorners(pixmap_t *p)
1899{
1900int x,y;
1901int width=p->width-1;
1902int height=p->height-1;
1903
1904// 10px rounded corner alpha values
1905uint8_t roundedCorner[10][10] =
1906{
1907{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},
1908{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},
1909{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1910{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1911{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1912{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1913{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1914{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1915{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1916{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
1917};
1918
1919uint8_t alpha=0;
1920
1921for( y=0; y<10; y++)
1922{
1923for( x=0; x<10; x++)
1924{
1925// skip if the pixel should be visible
1926if(roundedCorner[y][x] != 0xFF)
1927{
1928alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
1929// Upper left corner
1930pixel(p, x, y).ch.a = alpha;
1931
1932// upper right corner
1933pixel(p, width-x,y).ch.a = alpha;
1934
1935// lower left corner
1936pixel(p, x, height-y).ch.a = alpha;
1937
1938// lower right corner
1939pixel(p, width-x, height-y).ch.a = alpha;
1940}
1941}
1942}
1943}
1944
1945// ====================================================================
1946
1947void showInfoBox(char *title, char *text_orig)
1948{
1949char* text;
1950int i, key, lines, visiblelines;
1951
1952int currentline=0;
1953int cnt=0;
1954int offset=0;
1955
1956if( !title || !text_orig ) {
1957return;
1958}
1959
1960// Create a copy so that we don't mangle the original
1961text = malloc(strlen(text_orig) + 1);
1962strcpy(text, text_orig);
1963
1964position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );
1965
1966// calculate number of lines in the title
1967for ( i = 0, lines = 1; i<strlen(title); i++ ) {
1968if( title[i] == '\n') {
1969lines++;
1970}
1971}
1972// y position of text is lines in title * height of font
1973position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));
1974
1975// calculate number of lines in the text
1976for ( i=0, lines = 1; i<strlen(text); i++ ) {
1977if( text[i] == '\n') {
1978lines++;
1979}
1980}
1981// if text ends with \n strip off
1982if( text[i] == '\n' || text[i] == '\0') {
1983lines--;
1984}
1985visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
1986
1987// lets display the text and allow scroll thru using up down / arrows
1988while(1)
1989{
1990// move to current line in text
1991for( offset = 0, i = 0; offset < strlen(text); offset++ )
1992{
1993if( currentline == i)
1994{
1995break;
1996}
1997
1998if( text[offset] =='\n')
1999{
2000i++;
2001}
2002}
2003
2004// find last visible line in text and place \0
2005for( i = offset, cnt = 0; i < strlen(text); i++)
2006{
2007if(text[i]=='\n')
2008{
2009cnt++;
2010}
2011
2012if ( cnt == visiblelines )
2013{
2014text[i]='\0';
2015break;
2016}
2017}
2018
2019fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);
2020
2021makeRoundedCorners( gui.infobox.pixmap);
2022
2023// print the title if present
2024if( title ) {
2025drawStr(title, &font_console, gui.infobox.pixmap, pos_title);
2026}
2027// print the text
2028drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);
2029
2030// restore \n in text
2031if ( cnt == visiblelines ) {
2032text[i] = '\n';
2033}
2034position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
2035
2036// draw prev indicator
2037if(offset)
2038{
2039blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
2040}
2041
2042// draw next indicator
2043if( lines > ( currentline + visiblelines ) )
2044{
2045pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
2046blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
2047}
2048
2049gui.bootprompt.draw = false;
2050gui.infobox.draw = true;
2051gui.redraw = true;
2052
2053updateVRAM();
2054
2055key = getchar();
2056
2057if( key == KEY_UP ) {
2058if( currentline > 0 ) {
2059currentline--;
2060}
2061}
2062
2063if( key == KEY_DOWN ) {
2064if( lines > ( currentline + visiblelines ) ) {
2065currentline++;
2066}
2067}
2068
2069if( key == KEY_ESC || key == 'q' || key == 'Q') {
2070gui.infobox.draw = false;
2071gui.redraw = true;
2072updateVRAM();
2073break;
2074}
2075
2076if(key == ' ') { // spacebar = next page
2077if( lines > ( currentline + visiblelines ) ) {
2078currentline += visiblelines;
2079}
2080if(lines < (currentline + visiblelines)) {
2081currentline = lines - visiblelines;
2082}
2083}
2084}
2085free(text);
2086}
2087
2088// ====================================================================
2089
2090#if UNUSED
2091void animateProgressBar()
2092{
2093int y;
2094
2095if( time18() > lasttime)
2096{
2097lasttime = time18();
2098
2099pixmap_t *buffBar = images[iProgressBar].image;
2100
2101uint32_t buff = buffBar->pixels[0].value;
2102
2103memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );
2104
2105for( y = buffBar->height - 1; y > 0; y--) {
2106pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);
2107}
2108pixel(buffBar, buffBar->width-1, 0).value = buff;
2109}
2110}
2111#endif
2112
2113// ====================================================================
2114
2115void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)
2116{
2117if(progress>100) {
2118return;
2119}
2120
2121p.x = ( p.x - ( width / 2 ) );
2122
2123int todraw = (width * progress) / 100;
2124
2125pixmap_t *buff = images[iProgressBar].image;
2126pixmap_t *buffBG = images[iProgressBarBackground].image;
2127if(!buff || !buffBG) {
2128return;
2129}
2130
2131pixmap_t progressbar;
2132progressbar.pixels=malloc(width * 4 * buff->height);
2133if(!progressbar.pixels) {
2134return;
2135}
2136
2137progressbar.width = width;
2138progressbar.height = buff->height;
2139
2140int x=0,x2=0,y=0;
2141
2142for(y=0; y<buff->height; y++) {
2143for(x=0; x<todraw; x++, x2++) {
2144if(x2 == (buff->width-1)) {
2145x2=0;
2146}
2147pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;
2148}
2149x2=0;
2150}
2151
2152for(y=0; y<buff->height; y++) {
2153for(x=todraw, x2 = 0; x < width - 1; x++, x2++) {
2154if(x2 == (buffBG->width -2 )) {
2155x2 = 0;
2156}
2157pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;
2158}
2159if(progress < 100) {
2160pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;
2161}
2162
2163if(progress == 0) {
2164pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;
2165}
2166
2167x2=0;
2168}
2169
2170blend(&progressbar, blendInto, p);
2171#if 0
2172animateProgressBar();
2173#endif
2174free(progressbar.pixels);
2175}
2176
2177// ====================================================================
2178
2179void drawInfoMenuItems()
2180{
2181int i,n;
2182
2183position_t position;
2184
2185pixmap_t *selection = images[iMenuSelection].image;
2186
2187pixmap_t *pbuff;
2188
2189fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);
2190
2191makeRoundedCorners(gui.menu.pixmap);
2192
2193uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;
2194
2195position = pos(0,0);
2196
2197for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++) {
2198if (i == infoMenuSelection) {
2199blend(selection, gui.menu.pixmap, position);
2200}
2201
2202pbuff = images[n].image;
2203if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END) {
2204blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
2205pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
2206} else {
2207blend( pbuff, gui.menu.pixmap,
2208pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
2209}
2210
2211drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap,
2212pos(position.x + (pbuff->width + gui.menu.hborder),
2213position.y + ((selection->height - font_console.height) / 2)));
2214position.y += images[iMenuSelection].image->height;
2215
2216}
2217
2218gui.redraw = true;
2219}
2220
2221// ====================================================================
2222
2223int drawInfoMenu()
2224{
2225drawInfoMenuItems();
2226
2227gui.menu.draw = true;
2228
2229updateVRAM();
2230
2231return 1;
2232}
2233
2234// ====================================================================
2235
2236int updateInfoMenu(int key)
2237{
2238switch (key)
2239{
2240
2241case KEY_UP:// up arrow
2242if (infoMenuSelection > 0) {
2243if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1) {
2244infoMenuSelection -= 4;
2245} else {
2246infoMenuSelection--;
2247}
2248drawInfoMenuItems();
2249updateVRAM();
2250
2251} else {
2252
2253gui.menu.draw = false;
2254gui.redraw = true;
2255
2256updateVRAM();
2257
2258return CLOSE_INFO_MENU;
2259}
2260break;
2261
2262case KEY_DOWN:// down arrow
2263if (infoMenuSelection < infoMenuItemsCount - 1) {
2264if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
2265{
2266infoMenuSelection += 4;
2267} else {
2268infoMenuSelection++;
2269}
2270drawInfoMenuItems();
2271updateVRAM();
2272}
2273break;
2274
2275case KEY_ENTER:
2276key = 0;
2277if( infoMenuSelection == MENU_SHOW_MEMORY_INFO ) {
2278showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
2279} else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO ) {
2280showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
2281} else if( infoMenuSelection == MENU_SHOW_HELP ) {
2282showHelp();
2283} else {
2284int buff = infoMenuSelection;
2285infoMenuSelection = 0;
2286return buff;
2287}
2288break;
2289default:
2290break;
2291}
2292return DO_NOT_BOOT;
2293}
2294
2295// ====================================================================
2296
2297uint16_t bootImageWidth = 0;
2298uint16_t bootImageHeight = 0;
2299uint8_t *bootImageData = NULL;
2300static bool usePngImage = true;
2301
2302//==========================================================================
2303// loadBootGraphics
2304static void loadBootGraphics(void)
2305{
2306if (bootImageData != NULL) {
2307return;
2308}
2309
2310char dirspec[256];
2311
2312if ((strlen(theme_name) + 24) > sizeof(dirspec))
2313{
2314usePngImage = false;
2315return;
2316}
2317sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);
2318if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {
2319#ifdef CONFIG_EMBED_THEME
2320if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
2321#endif
2322usePngImage = false;
2323}
2324}
2325
2326//==========================================================================
2327// drawBootGraphics
2328void drawBootGraphics(void)
2329{
2330int pos;
2331int length;
2332const char *dummyVal;
2333int oldScreenWidth, oldScreenHeight;
2334bool legacy_logo;
2335uint16_t x, y;
2336
2337if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->chameleonConfig) && legacy_logo)
2338{
2339usePngImage = false;
2340}
2341else if (bootImageData == NULL)
2342{
2343loadBootGraphics();
2344}
2345
2346// parse screen size parameters
2347if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0)
2348{
2349screen_params[0] = pos;
2350}
2351else
2352{
2353screen_params[0] = DEFAULT_SCREEN_WIDTH;
2354}
2355
2356if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0)
2357{
2358screen_params[1] = pos;
2359}
2360else
2361{
2362screen_params[1] = DEFAULT_SCREEN_HEIGHT;
2363}
2364
2365// Save current screen resolution.
2366oldScreenWidth = gui.screen.width;
2367oldScreenHeight = gui.screen.height;
2368
2369gui.screen.width = screen_params[0];
2370gui.screen.height = screen_params[1];
2371
2372// find best matching vesa mode for our requested width & height
2373getGraphicModeParams(screen_params);
2374
2375// Set graphics mode if the booter was in text mode or the screen resolution has changed.
2376if (bootArgs->Video.v_display == VGA_TEXT_MODE || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )
2377{
2378setVideoMode(GRAPHICS_MODE, 0);
2379}
2380
2381if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->chameleonConfig))
2382{
2383drawCheckerBoard();
2384}
2385else
2386{
2387// Fill the background to 75% grey (same as BootX).
2388drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
2389}
2390
2391if ((bootImageData) && (usePngImage))
2392{
2393x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
2394y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
2395
2396// Draw the image in the center of the display.
2397blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
2398}
2399else
2400{
2401uint8_t *appleBootPict;
2402bootImageData = NULL;
2403bootImageWidth = kAppleBootWidth;
2404bootImageHeight = kAppleBootHeight;
2405
2406// Prepare the data for the default Apple boot image.
2407appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
2408if (appleBootPict)
2409{
2410convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
2411if (bootImageData)
2412{
2413x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
2414y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
2415drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
2416free(bootImageData);
2417}
2418free(appleBootPict);
2419}
2420}
2421}
2422// ====================================================================
2423

Archive Download this file

Revision: 2734