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

Archive Download this file

Revision: 2853