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

Archive Download this file

Revision: 2467