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

Archive Download this file

Revision: 2782