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

Archive Download this file

Revision: 2824