Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/boot2/gui.c

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

Archive Download this file

Revision: 2621