Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch/i386/boot2/gui.c

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

Archive Download this file

Revision: 2773