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

Archive Download this file

Revision: 2831