Chameleon

Chameleon Svn Source Tree

Root/tags/2.3/i386/boot2/gui.c

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

Archive Download this file

Revision: 2862