Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 2743