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))
942{
943screen_params[0] = val;
944}
945if (getIntForKey("screen_height", &val, &bootInfo->themeConfig) && (val > 0))
946{
947screen_params[1] = val;
948}
949
950// Initalizing GUI strucutre.
951bzero(&gui, sizeof(gui_t));
952
953// find best matching vesa mode for our requested width & height
954getGraphicModeParams(screen_params);
955
956// set our screen structure with the mode width & height
957gui.screen.width = screen_params[0];
958gui.screen.height = screen_params[1];
959
960// load graphics otherwise fail and return
961if (loadGraphics() == 0) {
962loadThemeValues(&bootInfo->themeConfig);
963colorFont(&font_small, gui.screen.font_small_color);
964colorFont(&font_console, gui.screen.font_console_color);
965
966// create the screen & window buffers
967if (createBackBuffer(&gui.screen) == 0) {
968if (createWindowBuffer(&gui.screen) == 0) {
969if (createWindowBuffer(&gui.devicelist) == 0) {
970if (createWindowBuffer(&gui.bootprompt) == 0) {
971if (createWindowBuffer(&gui.infobox) == 0) {
972if (createWindowBuffer(&gui.menu) == 0) {
973gui.logo.draw = true;
974drawBackground();
975// lets copy the screen into the back buffer
976memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
977setVideoMode( GRAPHICS_MODE, 0 );
978gui.initialised = true;
979return 0;
980}
981}
982}
983}
984}
985}
986}
987
988 // not available memory, freeing resources
989 freeWindowBuffer(&gui.menu);
990 freeWindowBuffer(&gui.infobox);
991 freeWindowBuffer(&gui.bootprompt);
992 freeWindowBuffer(&gui.devicelist);
993 freeWindowBuffer(&gui.screen);
994 freeBackBuffer(&gui.screen);
995 unloadGraphics();
996
997return 1;
998}
999
1000// ====================================================================
1001
1002bool is_image_loaded(int i)
1003{
1004return (images[i].image != NULL) ? true : false;
1005}
1006
1007// ====================================================================
1008
1009void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected)
1010{
1011int devicetype;
1012
1013if( diskIsCDROM(device) ) {
1014devicetype = iDeviceCDROM;// Use CDROM icon
1015} else {
1016switch (device->part_type)
1017{
1018case kPartitionTypeHFS:
1019{
1020// ErmaC : TODO test needed for recovery icon
1021// Use HFSRECOVERY icon.
1022if (device->flags & kBVFlagBooter)
1023{
1024devicetype = iDeviceHFSRECOVERY;
1025}
1026else
1027{
1028
1029// Use HFS or HFSRAID icon depending on bvr flags. Fallbacks are handled by alt_image above.
1030switch (device->OSVersion[3]) {
1031case '9':
1032devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_mav : iDeviceHFS_mav);
1033break;
1034case '8':
1035devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_ML : iDeviceHFS_ML);
1036break;
1037case '7':
1038devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_Lion : iDeviceHFS_Lion);
1039break;
1040case '6':
1041devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_SL : iDeviceHFS_SL);
1042break;
1043case '5':
1044devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_Leo : iDeviceHFS_Leo);
1045break;
1046case '4':
1047devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_Tiger : iDeviceHFS_Tiger);
1048break;
1049case '1':
1050if (device->OSVersion[4] == '0') { // 10.10
1051devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_yos : iDeviceHFS_yos);
1052break;
1053}
1054//if (device->OSVersion[4] == '1') { // 10.11
1055//devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_??? : iDeviceHFS_???);
1056//break;
1057//}
1058default:
1059devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID : iDeviceHFS);
1060break;
1061}
1062}
1063
1064break;
1065
1066}
1067//case kPartitionTypeOSXBoot:
1068//devicetype = iDeviceHFSRECOVERY;// Use Recovery icon
1069//break;
1070
1071case kPartitionTypeHPFS:
1072devicetype = iDeviceNTFS;// Use HPFS / NTFS icon
1073break;
1074
1075case kPartitionTypeFAT16:
1076devicetype = iDeviceFAT16;// Use FAT16 icon
1077break;
1078
1079case kPartitionTypeFAT32:
1080devicetype = iDeviceFAT32;// Use FAT32 icon
1081break;
1082
1083case kPartitionTypeEXT3:
1084devicetype = iDeviceEXT3;// Use EXT2/3 icon
1085break;
1086
1087case kPartitionTypeFreeBSD: /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */
1088devicetype = iDeviceFreeBSD;// Use FreeBSD icon
1089break;
1090
1091case kPartitionTypeOpenBSD: /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */
1092devicetype = iDeviceOpenBSD;// Use OpenBSD icon
1093break;
1094
1095case kPartitionTypeBEFS: /* Haiku detection and Icon credits to scorpius */
1096devicetype = iDeviceBEFS;// Use BEFS / Haiku icon
1097break;
1098
1099default:
1100devicetype = iDeviceGeneric;// Use Generic icon
1101break;
1102}
1103}
1104
1105// Draw the selection image and use the next (device_*_o) image for the selected item.
1106if (isSelected)
1107{
1108blend(images[iSelection].image, buffer, centeredAt(images[iSelection].image, p));
1109devicetype++; // select override image
1110}
1111
1112// draw icon
1113blend(images[devicetype].image, buffer, centeredAt(images[devicetype].image, p));
1114
1115p.y += (images[iSelection].image->height / 2) + font_console.chars[0]->height;
1116
1117// draw volume label
1118drawStrCenteredAt( device->label, &font_small, buffer, p);
1119
1120}
1121
1122// ====================================================================
1123
1124void drawDeviceList (int start, int end, int selection)
1125{
1126inti;
1127boolshoWinfo = false;
1128extern bool showBootBanner;
1129position_tp, p_prev, p_next;
1130
1131//uint8_tmaxDevices = MIN( gui.maxdevices, menucount );
1132
1133fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);
1134
1135makeRoundedCorners( gui.devicelist.pixmap);
1136
1137switch (gui.layout) {
1138
1139case VerticalLayout:
1140p.x = (gui.devicelist.width /2);
1141p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );
1142
1143// place scroll indicators at top & bottom edges
1144p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );
1145p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );
1146
1147break;
1148
1149default:// use Horizontal layout as the default
1150
1151case HorizontalLayout:
1152p.x = (gui.devicelist.width - ( gui.devicelist.width / gui.maxdevices ) * gui.maxdevices ) / 2 + ( images[iSelection].image->width / 2) + images[iDeviceScrollPrev].image->width + gui.devicelist.iconspacing;
1153p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );
1154
1155// place scroll indicators at left & right edges
1156p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );
1157p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );
1158
1159break;
1160
1161}
1162
1163// draw visible device icons
1164for (i = 0; i < gui.maxdevices; i++) {
1165BVRef param = menuItems[start + i].param;
1166
1167bool isSelected = ((start + i) == selection) ? true : false;
1168if (isSelected) {
1169if (param->flags & kBVFlagNativeBoot) {
1170infoMenuNativeBoot = true;
1171} else {
1172infoMenuNativeBoot = false;
1173if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END) {
1174infoMenuSelection = 0;
1175}
1176}
1177
1178if (gui.menu.draw) {
1179drawInfoMenuItems();
1180}
1181getBoolForKey(kShowInfoKey, &shoWinfo, &bootInfo->chameleonConfig);
1182
1183if (shoWinfo && showBootBanner) {
1184gui.debug.cursor = pos( 10, 100);
1185dprintf( &gui.screen, "label: %s\n", param->label );
1186dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev );
1187dprintf( &gui.screen, "type: 0x%x\n", param->type );
1188dprintf( &gui.screen, "flags: 0x%x\n", param->flags );
1189dprintf( &gui.screen, "part_no: %d\n", param->part_no );
1190dprintf( &gui.screen, "part_boff: 0x%x\n", param->part_boff );
1191dprintf( &gui.screen, "part_type: 0x%x\n", param->part_type );
1192dprintf( &gui.screen, "bps: 0x%x\n", param->bps );
1193dprintf( &gui.screen, "name: %s\n", param->name );
1194dprintf( &gui.screen, "type_name: %s\n", param->type_name );
1195dprintf( &gui.screen, "modtime: %d\n", param->modTime );
1196//// res
1197dprintf( &gui.screen, "width: %d\n", gui.screen.width );
1198dprintf( &gui.screen, "height: %d\n", gui.screen.height );
1199//dprintf( &gui.screen, "attr: 0x%x\n", gui.screen.attr ); //Azi: reminder
1200//dprintf( &gui.screen, "mm: %d\n", gui.screen.mm );
1201}
1202}
1203
1204drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);
1205
1206if (gui.layout == HorizontalLayout) {
1207p.x += images[iSelection].image->width + gui.devicelist.iconspacing;
1208}
1209if (gui.layout == VerticalLayout) {
1210p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing );
1211}
1212}
1213
1214// draw prev indicator
1215if (start) {
1216blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );
1217}
1218// draw next indicator
1219if ( end < gDeviceCount - 1 ) {
1220blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );
1221}
1222gui.redraw = true;
1223
1224updateVRAM();
1225
1226}
1227
1228// ====================================================================
1229
1230void clearGraphicBootPrompt()
1231{
1232// clear text buffer
1233//prompt[0] = '\0';
1234//prompt_pos=0;
1235
1236
1237if( gui.bootprompt.draw == true ) {
1238gui.bootprompt.draw = false;
1239gui.redraw = true;
1240// this causes extra frames to be drawn
1241//updateVRAM();
1242}
1243
1244return;
1245}
1246
1247// ====================================================================
1248
1249void updateGraphicBootPrompt()
1250{
1251fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);
1252
1253makeRoundedCorners( gui.bootprompt.pixmap);
1254
1255position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );
1256
1257// print the boot prompt text
1258drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);
1259
1260// get the position of the end of the boot prompt text to display user input
1261position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );
1262
1263drawStr( gBootArgs, &font_console, gui.bootprompt.pixmap, p_prompt);
1264
1265gui.menu.draw = false;
1266gui.bootprompt.draw = true;
1267gui.redraw = true;
1268
1269updateVRAM();
1270
1271return;
1272}
1273
1274// ====================================================================
1275
1276static inline
1277void vramwrite (void *data, int width, int height)
1278{
1279if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4) {
1280memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
1281} else {
1282uint32_t r, g, b;
1283int i, j;
1284for (i = 0; i < VIDEO (height); i++) {
1285for (j = 0; j < VIDEO (width); j++) {
1286b = ((uint8_t *) data)[4*i*width + 4*j];
1287g = ((uint8_t *) data)[4*i*width + 4*j + 1];
1288r = ((uint8_t *) data)[4*i*width + 4*j + 2];
1289switch (VIDEO (depth)) {
1290case 32:
1291*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1292break;
1293case 24:
1294*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)
1295| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1296break;
1297case 16:
1298// Somehow 16-bit is always 15-bits really
1299//*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);
1300//break;
1301case 15:
1302*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);
1303break;
1304}
1305}
1306}
1307}
1308}
1309
1310// ====================================================================
1311
1312void updateVRAM()
1313{
1314if (gui.redraw) {
1315if (gui.devicelist.draw) {
1316blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
1317}
1318if (gui.bootprompt.draw) {
1319blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
1320}
1321if (gui.menu.draw) {
1322blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
1323}
1324if (gui.infobox.draw) {
1325blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
1326}
1327}
1328
1329vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
1330
1331if (gui.redraw) {
1332memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
1333gui.redraw = false;
1334}
1335}
1336
1337// ====================================================================
1338
1339struct putc_info //Azi: exists on console.c & printf.c
1340{
1341char * str;
1342char * last_str;
1343};
1344
1345// ====================================================================
1346
1347static int
1348sputc(int c, struct putc_info * pi) //Azi: same as above
1349{
1350if (pi->last_str) {
1351if (pi->str == pi->last_str) {
1352*(pi->str) = '\0';
1353return 0;
1354}
1355}
1356*(pi->str)++ = c;
1357return c;
1358}
1359
1360// ====================================================================
1361
1362int gprintf( window_t * window, const char * fmt, ...)
1363{
1364char *formattedtext;
1365
1366va_list ap;
1367
1368struct putc_info pi;
1369
1370if ((formattedtext = malloc(1024)) != NULL) {
1371// format the text
1372va_start(ap, fmt);
1373pi.str = formattedtext;
1374pi.last_str = 0;
1375prf(fmt, ap, sputc, &pi);
1376*pi.str = '\0';
1377va_end(ap);
1378
1379position_torigin, cursor, bounds;
1380
1381int i;
1382int character;
1383
1384origin.x = MAX( window->cursor.x, window->hborder );
1385origin.y = MAX( window->cursor.y, window->vborder );
1386
1387bounds.x = ( window->width - window->hborder );
1388bounds.y = ( window->height - window->vborder );
1389
1390cursor = origin;
1391
1392font_t *font = &font_console;
1393
1394for( i=0; i< strlen(formattedtext); i++ ) {
1395character = formattedtext[i];
1396
1397character -= 32;
1398
1399// newline ?
1400if( formattedtext[i] == '\n' ) {
1401cursor.x = window->hborder;
1402cursor.y += font->height;
1403
1404if ( cursor.y > bounds.y ) {
1405cursor.y = origin.y;
1406}
1407continue;
1408}
1409
1410// tab ?
1411if( formattedtext[i] == '\t' ) {
1412cursor.x += ( font->chars[0]->width * 5 );
1413}
1414
1415// draw the character
1416if( font->chars[character]) {
1417blend(font->chars[character], window->pixmap, cursor);
1418}
1419
1420cursor.x += font->chars[character]->width;
1421
1422// check x pos and do newline
1423if ( cursor.x > bounds.x ) {
1424cursor.x = origin.x;
1425cursor.y += font->height;
1426}
1427
1428// check y pos and reset to origin.y
1429if ( cursor.y > bounds.y ) {
1430cursor.y = origin.y;
1431}
1432}
1433
1434// update cursor postition
1435window->cursor = cursor;
1436
1437free(formattedtext);
1438
1439return 0;
1440}
1441return 1;
1442}
1443
1444// ====================================================================
1445
1446int dprintf( window_t * window, const char * fmt, ...)
1447{
1448char *formattedtext;
1449
1450va_list ap;
1451
1452//window = &gui.debug;
1453
1454struct putc_info pi;
1455
1456if ((formattedtext = malloc(1024)) != NULL) {
1457// format the text
1458va_start(ap, fmt);
1459pi.str = formattedtext;
1460pi.last_str = 0;
1461prf(fmt, ap, sputc, &pi);
1462*pi.str = '\0';
1463va_end(ap);
1464
1465position_torigin, cursor, bounds;
1466
1467int i;
1468int character;
1469
1470origin.x = MAX( gui.debug.cursor.x, window->hborder );
1471origin.y = MAX( gui.debug.cursor.y, window->vborder );
1472
1473bounds.x = ( window->width - window->hborder );
1474bounds.y = ( window->height - window->vborder );
1475
1476cursor = origin;
1477
1478font_t *font = &font_console;
1479
1480for( i=0; i< strlen(formattedtext); i++ ) {
1481character = formattedtext[i];
1482
1483character -= 32;
1484
1485// newline ?
1486if( formattedtext[i] == '\n' ) {
1487cursor.x = window->hborder;
1488cursor.y += font->height;
1489
1490if ( cursor.y > bounds.y ) {
1491cursor.y = origin.y;
1492}
1493continue;
1494}
1495
1496// tab ?
1497if( formattedtext[i] == '\t' ) {
1498cursor.x += ( font->chars[0]->width * 5 );
1499}
1500// draw the character
1501if( font->chars[character]) {
1502blend(font->chars[character], gui.backbuffer, cursor);
1503}
1504cursor.x += font->chars[character]->width;
1505
1506// check x pos and do newline
1507if ( cursor.x > bounds.x ) {
1508cursor.x = origin.x;
1509cursor.y += font->height;
1510}
1511
1512// check y pos and reset to origin.y
1513if ( cursor.y > bounds.y ) {
1514cursor.y = origin.y;
1515}
1516}
1517
1518// update cursor postition
1519gui.debug.cursor = cursor;
1520
1521free(formattedtext);
1522
1523return 0;
1524
1525}
1526return 1;
1527}
1528
1529// ====================================================================
1530
1531int vprf(const char * fmt, va_list ap)
1532{
1533int i;
1534int character;
1535
1536char *formattedtext;
1537window_t *window = &gui.screen;
1538struct putc_info pi;
1539
1540position_torigin, cursor, bounds;
1541font_t *font = &font_console;
1542
1543if ((formattedtext = malloc(1024)) != NULL) {
1544// format the text
1545pi.str = formattedtext;
1546pi.last_str = 0;
1547prf(fmt, ap, sputc, &pi);
1548*pi.str = '\0';
1549
1550origin.x = MAX( window->cursor.x, window->hborder );
1551origin.y = MAX( window->cursor.y, window->vborder );
1552bounds.x = ( window->width - ( window->hborder * 2 ) );
1553bounds.y = ( window->height - ( window->vborder * 2 ) );
1554cursor = origin;
1555
1556for( i=0; i< strlen(formattedtext); i++ ) {
1557character = formattedtext[i];
1558character -= 32;
1559
1560// newline ?
1561if( formattedtext[i] == '\n' ) {
1562cursor.x = window->hborder;
1563cursor.y += font->height;
1564if ( cursor.y > bounds.y ) {
1565gui.redraw = true;
1566updateVRAM();
1567cursor.y = window->vborder;
1568}
1569window->cursor.y = cursor.y;
1570continue;
1571}
1572
1573// tab ?
1574if( formattedtext[i] == '\t' ) {
1575cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
1576continue;
1577}
1578cursor.x += font->chars[character]->width;
1579
1580// check x pos and do newline
1581if ( cursor.x > bounds.x ) {
1582cursor.x = origin.x;
1583cursor.y += font->height;
1584}
1585
1586// check y pos and reset to origin.y
1587if ( cursor.y > ( bounds.y + font->chars[0]->height) ) {
1588gui.redraw = true;
1589updateVRAM();
1590cursor.y = window->vborder;
1591}
1592// draw the character
1593if( font->chars[character]) {
1594blend(font->chars[character], gui.backbuffer, cursor);
1595}
1596}
1597// save cursor postition
1598window->cursor.x = cursor.x;
1599updateVRAM();
1600free(formattedtext);
1601return 0;
1602}
1603return 1;
1604}
1605
1606// ====================================================================
1607
1608pixmap_t* charToPixmap(unsigned char ch, font_t *font) {
1609unsigned int cha = (unsigned int)ch - 32;
1610if (cha >= font->count) {
1611// return ? if the font for the char doesn't exists
1612cha = '?' - 32;
1613}
1614return font->chars[cha] ? font->chars[cha] : NULL;
1615}
1616
1617// ====================================================================
1618
1619position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) {
1620pixmap_t* pm = charToPixmap(ch, font);
1621if (pm && ((p.x + pm->width) < blendInto->width)) {
1622blend(pm, blendInto, p);
1623return pos(p.x + pm->width, p.y);
1624} else {
1625return p;
1626}
1627}
1628
1629// ====================================================================
1630
1631void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)
1632{
1633int i=0;
1634position_t current_pos = pos(p.x, p.y);
1635
1636for (i=0; i < strlen(ch); i++) {
1637// newline ?
1638if ( ch[i] == '\n' ) {
1639current_pos.x = p.x;
1640current_pos.y += font->height;
1641continue;
1642}
1643
1644// tab ?
1645if ( ch[i] == '\t' ) {
1646current_pos.x += TAB_PIXELS_WIDTH;
1647continue;
1648}
1649
1650current_pos = drawChar(ch[i], font, blendInto, current_pos);
1651}
1652}
1653
1654// ====================================================================
1655
1656void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)
1657{
1658int i = 0;
1659int width = 0;
1660int max_width = 0;
1661int height = font->height;
1662
1663// calculate the width in pixels
1664for (i=0; i < strlen(text); i++) {
1665if (text[i] == '\n') {
1666width = 0;
1667height += font->height;
1668} else if (text[i] == '\t') {
1669width += TAB_PIXELS_WIDTH;
1670} else {
1671pixmap_t* pm = charToPixmap(text[i], font);
1672if (pm){
1673width += pm->width;
1674}
1675}
1676if (width > max_width) {
1677max_width = width;
1678}
1679}
1680
1681p.x = ( p.x - ( max_width / 2 ) );
1682p.y = ( p.y - ( height / 2 ) );
1683
1684drawStr(text, font, blendInto, p);
1685}
1686
1687// ====================================================================
1688
1689int destroyFont(font_t *font)
1690{
1691int i;
1692for (i = 0; i < CHARACTERS_COUNT; i++) {
1693if (font->chars[i]) {
1694if (font->chars[i]->pixels) {
1695free (font->chars[i]->pixels);
1696}
1697free (font->chars[i]);
1698font->chars[i] = 0;
1699}
1700}
1701return 0;
1702}
1703
1704// ====================================================================
1705
1706int initFont(font_t *font, image_t *data)
1707{
1708unsigned int x = 0, y = 0, x2 = 0, x3 = 0;
1709
1710int start = 0, end = 0, count = 0, space = 0;
1711
1712bool monospaced = false;
1713
1714font->height = data->image->height;
1715
1716for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++) {
1717start = end;
1718
1719// if the pixel is red we've reached the end of the char
1720if( pixel( data->image, x, 0 ).value == 0xFFFF0000) {
1721end = x + 1;
1722
1723if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) ) {
1724font->chars[count]->width = ( end - start) - 1;
1725font->chars[count]->height = font->height;
1726
1727if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) ) {
1728space += ( font->chars[count]->width * data->image->height * 4 );
1729// we skip the first line because there are just the red pixels for the char width
1730for( y = 1; y< (font->height); y++) {
1731for( x2 = start, x3 = 0; x2 < end; x2++, x3++) {
1732pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
1733}
1734}
1735
1736// check if font is monospaced
1737if( ( count > 0 ) && ( font->width != font->chars[count]->width ) ) {
1738monospaced = true;
1739}
1740
1741font->width = font->chars[count]->width;
1742
1743count++;
1744}
1745}
1746}
1747}
1748
1749for (x = count; x < CHARACTERS_COUNT; x++) {
1750font->chars[x] = NULL;
1751}
1752
1753if(monospaced) {
1754font->width = 0;
1755}
1756
1757font->count = count;
1758
1759return 0;
1760}
1761
1762// ====================================================================
1763
1764void colorFont(font_t *font, uint32_t color)
1765{
1766if( !color ) {
1767return;
1768}
1769
1770int x, y, width, height;
1771int count = 0;
1772pixel_t *buff;
1773
1774while( font->chars[count++] ) {
1775width = font->chars[count-1]->width;
1776height = font->chars[count-1]->height;
1777for( y = 0; y < height; y++ ) {
1778for( x = 0; x < width; x++ ) {
1779buff = &(pixel( font->chars[count-1], x, y ));
1780if( buff->ch.a ) {
1781buff->ch.r = (color & 0xFFFF0000) >> 16;
1782buff->ch.g = (color & 0xFF00FF00) >> 8;
1783buff->ch.b = (color & 0xFF0000FF);
1784}
1785}
1786}
1787}
1788}
1789
1790// ====================================================================
1791
1792void makeRoundedCorners(pixmap_t *p)
1793{
1794int x,y;
1795int width=p->width-1;
1796int height=p->height-1;
1797
1798// 10px rounded corner alpha values
1799uint8_t roundedCorner[10][10] =
1800{
1801{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},
1802{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},
1803{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1804{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1805{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1806{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1807{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1808{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1809{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1810{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
1811};
1812
1813uint8_t alpha=0;
1814
1815for( y=0; y<10; y++) {
1816for( x=0; x<10; x++) {
1817// skip if the pixel should be visible
1818if(roundedCorner[y][x] != 0xFF){
1819alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
1820// Upper left corner
1821pixel(p, x, y).ch.a = alpha;
1822
1823// upper right corner
1824pixel(p, width-x,y).ch.a = alpha;
1825
1826// lower left corner
1827pixel(p, x, height-y).ch.a = alpha;
1828
1829// lower right corner
1830pixel(p, width-x, height-y).ch.a = alpha;
1831}
1832}
1833}
1834}
1835
1836// ====================================================================
1837
1838void showInfoBox(char *title, char *text_orig)
1839{
1840char* text;
1841int i, key, lines, visiblelines;
1842
1843int currentline=0;
1844int cnt=0;
1845int offset=0;
1846
1847if( !title || !text_orig ) {
1848return;
1849}
1850
1851// Create a copy so that we don't mangle the original
1852text = malloc(strlen(text_orig) + 1);
1853strcpy(text, text_orig);
1854
1855position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );
1856
1857// calculate number of lines in the title
1858for ( i = 0, lines = 1; i<strlen(title); i++ ) {
1859if( title[i] == '\n') {
1860lines++;
1861}
1862}
1863// y position of text is lines in title * height of font
1864position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));
1865
1866// calculate number of lines in the text
1867for ( i=0, lines = 1; i<strlen(text); i++ ) {
1868if( text[i] == '\n') {
1869lines++;
1870}
1871}
1872// if text ends with \n strip off
1873if( text[i] == '\n' || text[i] == '\0') {
1874lines--;
1875}
1876visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
1877
1878// lets display the text and allow scroll thru using up down / arrows
1879while(1) {
1880// move to current line in text
1881for( offset = 0, i = 0; offset < strlen(text); offset++ ) {
1882if( currentline == i) {
1883break;
1884}
1885if( text[offset] =='\n') {
1886i++;
1887}
1888}
1889
1890// find last visible line in text and place \0
1891for( i = offset, cnt = 0; i < strlen(text); i++) {
1892if(text[i]=='\n') {
1893cnt++;
1894}
1895if ( cnt == visiblelines ) {
1896text[i]='\0';
1897break;
1898}
1899}
1900
1901fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);
1902
1903makeRoundedCorners( gui.infobox.pixmap);
1904
1905// print the title if present
1906if( title ) {
1907drawStr(title, &font_console, gui.infobox.pixmap, pos_title);
1908}
1909// print the text
1910drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);
1911
1912// restore \n in text
1913if ( cnt == visiblelines ) {
1914text[i] = '\n';
1915}
1916position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
1917
1918// draw prev indicator
1919if(offset) {
1920blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
1921}
1922
1923// draw next indicator
1924if( lines > ( currentline + visiblelines ) ) {
1925pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
1926blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
1927}
1928
1929gui.bootprompt.draw = false;
1930gui.infobox.draw = true;
1931gui.redraw = true;
1932
1933updateVRAM();
1934
1935key = getchar();
1936
1937if( key == KEY_UP ) {
1938if( currentline > 0 ) {
1939currentline--;
1940}
1941}
1942
1943if( key == KEY_DOWN ) {
1944if( lines > ( currentline + visiblelines ) ) {
1945currentline++;
1946}
1947}
1948
1949if( key == KEY_ESC || key == 'q' || key == 'Q') {
1950gui.infobox.draw = false;
1951gui.redraw = true;
1952updateVRAM();
1953break;
1954}
1955
1956if(key == ' ') { // spacebar = next page
1957if( lines > ( currentline + visiblelines ) ) {
1958currentline += visiblelines;
1959}
1960if(lines < (currentline + visiblelines)) {
1961currentline = lines - visiblelines;
1962}
1963}
1964}
1965free(text);
1966}
1967
1968// ====================================================================
1969
1970void animateProgressBar()
1971{
1972int y;
1973
1974if( time18() > lasttime) {
1975lasttime = time18();
1976
1977pixmap_t *buffBar = images[iProgressBar].image;
1978
1979uint32_t buff = buffBar->pixels[0].value;
1980
1981memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );
1982
1983for( y = buffBar->height - 1; y > 0; y--) {
1984pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);
1985}
1986pixel(buffBar, buffBar->width-1, 0).value = buff;
1987}
1988}
1989
1990// ====================================================================
1991
1992void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)
1993{
1994if(progress>100) {
1995return;
1996}
1997
1998p.x = ( p.x - ( width / 2 ) );
1999
2000int todraw = (width * progress) / 100;
2001
2002pixmap_t *buff = images[iProgressBar].image;
2003pixmap_t *buffBG = images[iProgressBarBackground].image;
2004if(!buff || !buffBG) {
2005return;
2006}
2007
2008pixmap_t progressbar;
2009progressbar.pixels=malloc(width * 4 * buff->height);
2010if(!progressbar.pixels) {
2011return;
2012}
2013
2014progressbar.width = width;
2015progressbar.height = buff->height;
2016
2017int x=0,x2=0,y=0;
2018
2019for(y=0; y<buff->height; y++) {
2020for(x=0; x<todraw; x++, x2++) {
2021if(x2 == (buff->width-1)) {
2022x2=0;
2023}
2024pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;
2025}
2026x2=0;
2027}
2028
2029for(y=0; y<buff->height; y++) {
2030for(x=todraw, x2 = 0; x < width - 1; x++, x2++) {
2031if(x2 == (buffBG->width -2 )) {
2032x2 = 0;
2033}
2034pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;
2035}
2036if(progress < 100) {
2037pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;
2038}
2039
2040if(progress == 0) {
2041pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;
2042}
2043
2044x2=0;
2045}
2046
2047blend(&progressbar, blendInto, p);
2048animateProgressBar();
2049free(progressbar.pixels);
2050}
2051
2052// ====================================================================
2053
2054void drawInfoMenuItems()
2055{
2056int i,n;
2057
2058position_t position;
2059
2060pixmap_t *selection = images[iMenuSelection].image;
2061
2062pixmap_t *pbuff;
2063
2064fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);
2065
2066makeRoundedCorners(gui.menu.pixmap);
2067
2068uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;
2069
2070position = pos(0,0);
2071
2072for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++) {
2073if (i == infoMenuSelection) {
2074blend(selection, gui.menu.pixmap, position);
2075}
2076
2077pbuff = images[n].image;
2078if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END) {
2079blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
2080pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
2081} else {
2082blend( pbuff, gui.menu.pixmap,
2083pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
2084}
2085
2086drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap,
2087pos(position.x + (pbuff->width + gui.menu.hborder),
2088position.y + ((selection->height - font_console.height) / 2)));
2089position.y += images[iMenuSelection].image->height;
2090
2091}
2092
2093gui.redraw = true;
2094}
2095
2096// ====================================================================
2097
2098int drawInfoMenu()
2099{
2100drawInfoMenuItems();
2101
2102gui.menu.draw = true;
2103
2104updateVRAM();
2105
2106return 1;
2107}
2108
2109// ====================================================================
2110
2111int updateInfoMenu(int key)
2112{
2113switch (key)
2114{
2115
2116case KEY_UP:// up arrow
2117if (infoMenuSelection > 0) {
2118if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1) {
2119infoMenuSelection -= 4;
2120} else {
2121infoMenuSelection--;
2122}
2123drawInfoMenuItems();
2124updateVRAM();
2125
2126} else {
2127
2128gui.menu.draw = false;
2129gui.redraw = true;
2130
2131updateVRAM();
2132
2133return CLOSE_INFO_MENU;
2134}
2135break;
2136
2137case KEY_DOWN:// down arrow
2138if (infoMenuSelection < infoMenuItemsCount - 1) {
2139if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
2140{
2141infoMenuSelection += 4;
2142} else {
2143infoMenuSelection++;
2144}
2145drawInfoMenuItems();
2146updateVRAM();
2147}
2148break;
2149
2150case KEY_ENTER:
2151key = 0;
2152if( infoMenuSelection == MENU_SHOW_MEMORY_INFO ) {
2153showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
2154} else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO ) {
2155showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
2156} else if( infoMenuSelection == MENU_SHOW_HELP ) {
2157showHelp();
2158} else {
2159int buff = infoMenuSelection;
2160infoMenuSelection = 0;
2161return buff;
2162}
2163break;
2164}
2165return DO_NOT_BOOT;
2166}
2167
2168// ====================================================================
2169
2170uint16_t bootImageWidth = 0;
2171uint16_t bootImageHeight = 0;
2172uint8_t *bootImageData = NULL;
2173static bool usePngImage = true;
2174
2175//==========================================================================
2176// loadBootGraphics
2177static void loadBootGraphics(void)
2178{
2179if (bootImageData != NULL) {
2180return;
2181}
2182
2183char dirspec[256];
2184
2185if ((strlen(theme_name) + 24) > sizeof(dirspec)) {
2186usePngImage = false;
2187return;
2188}
2189sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);
2190if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {
2191#ifdef CONFIG_EMBED_THEME
2192if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
2193#endif
2194usePngImage = false;
2195}
2196}
2197
2198//==========================================================================
2199// drawBootGraphics
2200void drawBootGraphics(void)
2201{
2202int pos;
2203int length;
2204const char *dummyVal;
2205int oldScreenWidth, oldScreenHeight;
2206bool legacy_logo;
2207uint16_t x, y;
2208
2209if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->chameleonConfig) && legacy_logo) {
2210usePngImage = false;
2211} else if (bootImageData == NULL) {
2212loadBootGraphics();
2213}
2214
2215// parse screen size parameters
2216if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0) {
2217screen_params[0] = pos;
2218} else {
2219screen_params[0] = DEFAULT_SCREEN_WIDTH;
2220}
2221if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0) {
2222screen_params[1] = pos;
2223} else {
2224screen_params[1] = DEFAULT_SCREEN_HEIGHT;
2225}
2226
2227// Save current screen resolution.
2228oldScreenWidth = gui.screen.width;
2229oldScreenHeight = gui.screen.height;
2230
2231gui.screen.width = screen_params[0];
2232gui.screen.height = screen_params[1];
2233
2234// find best matching vesa mode for our requested width & height
2235getGraphicModeParams(screen_params);
2236
2237// Set graphics mode if the booter was in text mode or the screen resolution has changed.
2238if (bootArgs->Video.v_display == VGA_TEXT_MODE || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) ) {
2239setVideoMode(GRAPHICS_MODE, 0);
2240}
2241
2242if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->chameleonConfig)) {
2243drawCheckerBoard();
2244} else {
2245// Fill the background to 75% grey (same as BootX).
2246drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
2247}
2248if ((bootImageData) && (usePngImage)) {
2249x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
2250y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
2251
2252// Draw the image in the center of the display.
2253blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
2254} else {
2255uint8_t *appleBootPict;
2256bootImageData = NULL;
2257bootImageWidth = kAppleBootWidth;
2258bootImageHeight = kAppleBootHeight;
2259
2260// Prepare the data for the default Apple boot image.
2261appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
2262if (appleBootPict) {
2263convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
2264if (bootImageData) {
2265x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
2266y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
2267drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
2268free(bootImageData);
2269}
2270free(appleBootPict);
2271}
2272}
2273}
2274// ====================================================================
2275

Archive Download this file

Revision: 2542