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

Archive Download this file

Revision: 2825