Chameleon

Chameleon Svn Source Tree

Root/branches/zenith432/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++) {
269if (strcmp(name, images[i].name) == 0) {
270return i; // found the name
271}
272}
273return -1;
274}
275
276#ifdef CONFIG_EMBED_THEME
277static int getEmbeddedImageIndexByName(const char *name)
278{
279int upperLimit = sizeof(embeddedImages) / sizeof(embeddedImages[0]) - 1;
280int lowerLimit = 0;
281int compareIndex = (upperLimit - lowerLimit) >> 1; // Midpoint
282int result;
283
284// NOTE: This algorithm assumes that the embedded images are sorted.
285// This is currently done using the make file. If the array is
286// generated manualy, this *will* fail to work properly.
287while((result = strcmp(name, embeddedImages[compareIndex].name)) != 0)
288{
289if (result > 0){ // We need to search a HIGHER index
290if (compareIndex != lowerLimit) {
291lowerLimit = compareIndex;
292} else {
293return -1;
294}
295compareIndex = (upperLimit + lowerLimit + 1) >> 1;// Midpoint, round up
296}
297else { // We Need to search a LOWER index
298if (compareIndex != upperLimit) {
299upperLimit = compareIndex;
300} else {
301return -1;
302}
303compareIndex = (upperLimit + lowerLimit) >> 1;// Midpoint, round down
304}
305}
306return compareIndex;
307}
308#endif
309
310static int loadThemeImage(const char *image, int alt_image)
311{
312chardirspec[256];
313int i;
314#ifdef CONFIG_EMBED_THEME
315int e;
316#endif
317uint16_twidth;
318uint16_theight;
319uint8_t*imagedata;
320
321if ((strlen(image) + strlen(theme_name) + 20) > sizeof(dirspec)) {
322return 1;
323}
324if ((i = getImageIndexByName(image)) < 0) {
325return 1;
326}
327if (!images[i].image && !(images[i].image = malloc(sizeof(pixmap_t)))) {
328return 1;
329}
330sprintf(dirspec, "/Extra/Themes/%s/%s.png", theme_name, image);
331width = 0;
332height = 0;
333imagedata = NULL;
334if ((loadPngImage(dirspec, &width, &height, &imagedata)) == 0) {
335images[i].image->width = width;
336images[i].image->height = height;
337images[i].image->pixels = (pixel_t *)imagedata;
338flipRB(images[i].image);
339return 0;
340}
341#ifdef CONFIG_EMBED_THEME
342else if ((e = getEmbeddedImageIndexByName(image)) >= 0) {
343unsigned char *embed_data;
344unsigned int embed_size;
345embed_data = embeddedImages[e].pngdata;
346embed_size = *embeddedImages[e].length;
347
348if (loadEmbeddedPngImage(embed_data, embed_size, &width, &height, &imagedata) == 0) {
349images[i].image->width = width;
350images[i].image->height = height;
351images[i].image->pixels = (pixel_t *)imagedata;
352flipRB(images[i].image);
353return 0;
354 }
355 }
356#endif
357 else if (alt_image != IMG_REQUIRED && is_image_loaded(alt_image)) {
358 // Using the passed alternate image for non-mandatory images.
359 // We don't clone the already existing pixmap, but using its properties instead!
360 images[i].image->width = images[alt_image].image->width;
361 images[i].image->height = images[alt_image].image->height;
362 images[i].image->pixels = images[alt_image].image->pixels;
363 return 0;
364 }
365
366// If we got here it's an error
367#ifndef CONFIG_EMBED_THEME
368printf("ERROR: GUI: could not open '%s/%s.png'!\n", theme_name, image);
369sleep(2);
370#endif
371free(images[i].image);
372images[i].image = NULL;
373return 1;
374}
375
376// ====================================================================
377
378static int loadGraphics(void)
379{
380LOADPNG(background, IMG_REQUIRED);
381LOADPNG(logo, IMG_REQUIRED);
382
383LOADPNG(device_generic, IMG_REQUIRED);
384LOADPNG(device_generic_o, iDeviceGeneric);
385LOADPNG(device_hfsplus, iDeviceGeneric);
386LOADPNG(device_hfsplus_o, iDeviceHFS);
387LOADPNG(device_hfsplus_yos, iDeviceHFS);
388LOADPNG(device_hfsplus_yos_o, iDeviceHFS_yos);
389LOADPNG(device_hfsplus_mav, iDeviceHFS);
390LOADPNG(device_hfsplus_mav_o, iDeviceHFS_mav);
391LOADPNG(device_hfsplus_ml, iDeviceHFS);
392LOADPNG(device_hfsplus_ml_o, iDeviceHFS_ML);
393LOADPNG(device_hfsplus_lion, iDeviceHFS);
394LOADPNG(device_hfsplus_lion_o, iDeviceHFS_Lion);
395LOADPNG(device_hfsplus_sl, iDeviceHFS);
396LOADPNG(device_hfsplus_sl_o, iDeviceHFS_SL);
397LOADPNG(device_hfsplus_leo, iDeviceHFS);
398LOADPNG(device_hfsplus_leo_o, iDeviceHFS_Leo);
399LOADPNG(device_hfsplus_tiger, iDeviceHFS);
400LOADPNG(device_hfsplus_tiger_o, iDeviceHFS_Tiger);
401
402LOADPNG(device_hfsraid, iDeviceHFS);
403LOADPNG(device_hfsraid_o, iDeviceHFSRAID);
404LOADPNG(device_hfsraid_yos, iDeviceHFSRAID);
405LOADPNG(device_hfsraid_yos_o, iDeviceHFSRAID_yos);
406LOADPNG(device_hfsraid_mav, iDeviceHFSRAID);
407LOADPNG(device_hfsraid_mav_o, iDeviceHFSRAID_mav);
408LOADPNG(device_hfsraid_ml, iDeviceHFSRAID);
409LOADPNG(device_hfsraid_ml_o, iDeviceHFSRAID_ML);
410LOADPNG(device_hfsraid_lion, iDeviceHFSRAID);
411LOADPNG(device_hfsraid_lion_o, iDeviceHFSRAID_Lion);
412LOADPNG(device_hfsraid_sl, iDeviceHFSRAID);
413LOADPNG(device_hfsraid_sl_o, iDeviceHFSRAID_SL);
414LOADPNG(device_hfsraid_leo, iDeviceHFSRAID);
415LOADPNG(device_hfsraid_leo_o, iDeviceHFSRAID_Leo);
416LOADPNG(device_hfsraid_tiger, iDeviceHFSRAID);
417LOADPNG(device_hfsraid_tiger_o, iDeviceHFSRAID_Tiger);
418
419LOADPNG(device_hfsplus_recovery, iDeviceHFS);
420LOADPNG(device_hfsplus_recovery_o, iDeviceHFSRECOVERY);
421
422LOADPNG(device_ext3, iDeviceGeneric);
423LOADPNG(device_ext3_o, iDeviceEXT3);
424LOADPNG(device_freebsd, iDeviceGeneric); /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */
425LOADPNG(device_freebsd_o, iDeviceFreeBSD); /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */
426LOADPNG(device_openbsd, iDeviceGeneric); /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */
427LOADPNG(device_openbsd_o, iDeviceOpenBSD); /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */
428LOADPNG(device_befs, iDeviceGeneric); /* Haiku detection and Icon credits to scorpius */
429LOADPNG(device_befs_o, iDeviceBEFS); /* Haiku detection and Icon credits to scorpius */
430LOADPNG(device_fat, iDeviceGeneric);
431LOADPNG(device_fat_o, iDeviceFAT);
432LOADPNG(device_fat16, iDeviceFAT);
433LOADPNG(device_fat16_o, iDeviceFAT16);
434LOADPNG(device_fat32, iDeviceFAT);
435LOADPNG(device_fat32_o, iDeviceFAT32);
436LOADPNG(device_ntfs, iDeviceGeneric);
437LOADPNG(device_ntfs_o, iDeviceNTFS);
438LOADPNG(device_cdrom, iDeviceGeneric);
439LOADPNG(device_cdrom_o, iDeviceCDROM);
440
441LOADPNG(device_selection, IMG_REQUIRED);
442LOADPNG(device_scroll_prev, IMG_REQUIRED);
443LOADPNG(device_scroll_next, IMG_REQUIRED);
444
445LOADPNG(menu_boot, IMG_REQUIRED);
446LOADPNG(menu_verbose, IMG_REQUIRED);
447LOADPNG(menu_ignore_caches, IMG_REQUIRED);
448LOADPNG(menu_single_user, IMG_REQUIRED);
449LOADPNG(menu_memory_info, IMG_REQUIRED);
450LOADPNG(menu_video_info, IMG_REQUIRED);
451LOADPNG(menu_help, IMG_REQUIRED);
452LOADPNG(menu_verbose_disabled, IMG_REQUIRED);
453LOADPNG(menu_ignore_caches_disabled, IMG_REQUIRED);
454LOADPNG(menu_single_user_disabled, IMG_REQUIRED);
455LOADPNG(menu_selection, IMG_REQUIRED);
456
457LOADPNG(progress_bar, IMG_REQUIRED);
458LOADPNG(progress_bar_background, IMG_REQUIRED);
459
460LOADPNG(text_scroll_prev, IMG_REQUIRED);
461LOADPNG(text_scroll_next, IMG_REQUIRED);
462
463LOADPNG(font_console, IMG_REQUIRED);
464LOADPNG(font_small, IMG_REQUIRED);
465
466initFont( &font_console, &images[iFontConsole]);
467initFont( &font_small, &images[iFontSmall]);
468
469//DBG("Graphic objects successfully loaded !!\n",theme_name);
470
471return 0;
472}
473
474// ====================================================================
475
476static int unloadGraphics(void)
477{
478int i;
479
480destroyFont(&font_console);
481destroyFont(&font_small);
482for (i = 0; i < sizeof(images) / sizeof(images[0]); i++) {
483if (images[i].image) {
484if (images[i].image->pixels) {
485free(images[i].image->pixels);
486}
487free (images[i].image);
488images[i].image = 0;
489 }
490}
491return 0;
492}
493
494// ====================================================================
495
496int freeBackBuffer( window_t *window )
497{
498if (gui.backbuffer && gui.backbuffer->pixels) {
499free(gui.backbuffer->pixels);
500free(gui.backbuffer);
501gui.backbuffer = 0;
502return 0;
503}
504
505return 1;
506}
507
508// ====================================================================
509
510pixmap_t *getCroppedPixmapAtPosition( pixmap_t *from, position_t pos, uint16_t width, uint16_t height )
511{
512pixmap_t *cropped = malloc( sizeof( pixmap_t ) );
513if( !cropped ) {
514return 0;
515}
516cropped->pixels = malloc( width * height * 4 );
517if ( !cropped->pixels ) {
518return 0;
519}
520cropped->width = width;
521cropped->height = height;
522
523int destx = 0, desty = 0;
524int srcx = pos.x, srcy = pos.y;
525
526for( ; desty < height; desty++, srcy++) {
527for( destx = 0, srcx = pos.x; destx < width; destx++, srcx++ ) {
528pixel( cropped, destx, desty ).value = pixel( from, srcx, srcy ).value;
529}
530}
531return cropped;
532}
533
534// ====================================================================
535
536int createBackBuffer( window_t *window )
537{
538gui.backbuffer = malloc(sizeof(pixmap_t));
539if(!gui.backbuffer)
540{
541DBG("Unable to allocate memory for gui.backbuffer");
542return 1;
543}
544
545gui.backbuffer->pixels = malloc( window->width * window->height * 4 );
546if(!gui.backbuffer->pixels)
547{
548free(gui.backbuffer);
549gui.backbuffer = 0;
550DBG("Unable to allocate memory for gui.backbuffer->pixels");
551return 1;
552}
553
554gui.backbuffer->width = gui.screen.width;
555gui.backbuffer->height = gui.screen.height;
556
557return 0;
558}
559
560// ====================================================================
561
562int createWindowBuffer( window_t *window )
563{
564window->pixmap = malloc(sizeof(pixmap_t));
565if(!window->pixmap)
566{
567DBG("Unable to allocate memory for window->pixmap");
568return 1;
569}
570
571window->pixmap->pixels = malloc( window->width * window->height * 4 );
572if(!window->pixmap->pixels)
573{
574free(window->pixmap);
575window->pixmap = 0;
576DBG("Unable to allocate memory for window->pixmap->pixels");
577return 1;
578}
579
580window->pixmap->width = window->width;
581window->pixmap->height = window->height;
582
583return 0;
584}
585
586// ====================================================================
587
588int freeWindowBuffer( window_t *window )
589{
590if (window->pixmap && window->pixmap->pixels)
591{
592free(window->pixmap->pixels);
593free(window->pixmap);
594return 0;
595}
596
597return 1;
598}
599
600// ====================================================================
601
602void fillPixmapWithColor(pixmap_t *pm, uint32_t color)
603{
604int x,y;
605
606// fill with given color AARRGGBB
607for( x=0; x < pm->width; x++ ) {
608for( y=0; y< pm->height; y++) {
609pixel(pm,x,y).value = color;
610}
611}
612}
613
614// ====================================================================
615
616void drawBackground()
617{
618// reset text cursor
619gui.screen.cursor.x = gui.screen.hborder;
620gui.screen.cursor.y = gui.screen.vborder;
621
622fillPixmapWithColor( gui.screen.pixmap, gui.screen.bgcolor);
623
624// draw background.png into background buffer
625blend( images[iBackground].image, gui.screen.pixmap, gui.background.pos );
626
627// draw logo.png into background buffer
628if (gui.logo.draw)
629{
630blend( images[iLogo].image, gui.screen.pixmap, gui.logo.pos);
631}
632
633memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
634}
635
636// ====================================================================
637
638void setupDeviceList(config_file_t *theme)
639{
640unsigned int pixel;
641intalpha;// transparency level 0 (obligue) - 255 (transparent)
642uint32_t color;// color value formatted RRGGBB
643int val, len;
644const char *string;
645
646if(getIntForKey("devices_max_visible", &val, theme ))
647{
648gui.maxdevices = MIN( val, gDeviceCount );
649}
650
651if(getIntForKey("devices_iconspacing", &val, theme ))
652{
653gui.devicelist.iconspacing = val;
654}
655
656// check layout for horizontal or vertical
657gui.layout = HorizontalLayout;
658if(getValueForKey( "devices_layout", &string, &len, theme))
659{
660if (!strcmp (string, "vertical"))
661{
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
937
938DBG("Unable to load %s theme plist.\n",theme_name);
939
940return 1;
941
942#endif
943}
944// parse display size parameters
945if (getIntForKey("screen_width", &val, &bootInfo->themeConfig) && (val > 0))
946{
947screen_params[0] = val;
948}
949if (getIntForKey("screen_height", &val, &bootInfo->themeConfig) && (val > 0))
950{
951screen_params[1] = val;
952}
953
954// Initalizing GUI strucutre.
955bzero(&gui, sizeof(gui_t));
956
957// find best matching vesa mode for our requested width & height
958getGraphicModeParams(screen_params);
959
960// set our screen structure with the mode width & height
961gui.screen.width = screen_params[0];
962gui.screen.height = screen_params[1];
963
964// load graphics otherwise fail and return
965if (loadGraphics() == 0)
966{
967loadThemeValues(&bootInfo->themeConfig);
968colorFont(&font_small, gui.screen.font_small_color);
969colorFont(&font_console, gui.screen.font_console_color);
970
971// create the screen & window buffers
972if (createBackBuffer(&gui.screen) == 0)
973{
974if (createWindowBuffer(&gui.screen) == 0)
975{
976if (createWindowBuffer(&gui.devicelist) == 0)
977{
978if (createWindowBuffer(&gui.bootprompt) == 0)
979{
980if (createWindowBuffer(&gui.infobox) == 0)
981{
982if (createWindowBuffer(&gui.menu) == 0)
983{
984gui.logo.draw = true;
985drawBackground();
986// lets copy the screen into the back buffer
987memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
988
989setVideoMode( GRAPHICS_MODE, 0 );
990
991gui.initialised = true;
992return 0;
993}
994}
995}
996}
997}
998}
999}
1000
1001DBG("Loading error occurred, reseting...\n",theme_name);
1002
1003// Loading error occurred, freeing resources
1004freeWindowBuffer(&gui.menu);
1005freeWindowBuffer(&gui.infobox);
1006freeWindowBuffer(&gui.bootprompt);
1007freeWindowBuffer(&gui.devicelist);
1008freeWindowBuffer(&gui.screen);
1009freeBackBuffer(&gui.screen);
1010unloadGraphics();
1011
1012return 1;
1013}
1014
1015// ====================================================================
1016
1017bool is_image_loaded(int i)
1018{
1019return (images[i].image != NULL) ? true : false;
1020}
1021
1022// ====================================================================
1023
1024void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected)
1025{
1026int devicetype;
1027
1028if( diskIsCDROM(device) ) {
1029devicetype = iDeviceCDROM;// Use CDROM icon
1030} else {
1031switch (device->part_type)
1032{
1033case kPartitionTypeHFS:
1034{
1035// ErmaC : TODO test needed for recovery icon
1036// Use HFSRECOVERY icon.
1037if (device->flags & kBVFlagBooter)
1038{
1039devicetype = iDeviceHFSRECOVERY;
1040}
1041else
1042{
1043
1044// Use HFS or HFSRAID icon depending on bvr flags. Fallbacks are handled by alt_image above.
1045switch (device->OSVersion[3]) {
1046case '9':
1047devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_mav : iDeviceHFS_mav);
1048break;
1049case '8':
1050devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_ML : iDeviceHFS_ML);
1051break;
1052case '7':
1053devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_Lion : iDeviceHFS_Lion);
1054break;
1055case '6':
1056devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_SL : iDeviceHFS_SL);
1057break;
1058case '5':
1059devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_Leo : iDeviceHFS_Leo);
1060break;
1061case '4':
1062devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_Tiger : iDeviceHFS_Tiger);
1063break;
1064case '1':
1065if (device->OSVersion[4] == '0') { // 10.10
1066devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_yos : iDeviceHFS_yos);
1067break;
1068}
1069//if (device->OSVersion[4] == '1') { // 10.11
1070//devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_??? : iDeviceHFS_???);
1071//break;
1072//}
1073default:
1074devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID : iDeviceHFS);
1075break;
1076}
1077}
1078
1079break;
1080
1081}
1082case kPartitionTypeHPFS:
1083devicetype = iDeviceNTFS;// Use HPFS / NTFS icon
1084break;
1085
1086case kPartitionTypeFAT16:
1087devicetype = iDeviceFAT16;// Use FAT16 icon
1088break;
1089
1090case kPartitionTypeFAT32:
1091devicetype = iDeviceFAT32;// Use FAT32 icon
1092break;
1093
1094case kPartitionTypeEXT3:
1095devicetype = iDeviceEXT3;// Use EXT2/3 icon
1096break;
1097
1098case kPartitionTypeFreeBSD: /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */
1099devicetype = iDeviceFreeBSD;// Use FreeBSD icon
1100break;
1101
1102case kPartitionTypeOpenBSD: /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */
1103devicetype = iDeviceOpenBSD;// Use OpenBSD icon
1104break;
1105
1106case kPartitionTypeBEFS: /* Haiku detection and Icon credits to scorpius */
1107devicetype = iDeviceBEFS;// Use BEFS / Haiku icon
1108break;
1109
1110default:
1111devicetype = iDeviceGeneric;// Use Generic icon
1112break;
1113}
1114}
1115
1116// Draw the selection image and use the next (device_*_o) image for the selected item.
1117if (isSelected)
1118{
1119blend(images[iSelection].image, buffer, centeredAt(images[iSelection].image, p));
1120devicetype++; // select override image
1121}
1122
1123// draw icon
1124blend(images[devicetype].image, buffer, centeredAt(images[devicetype].image, p));
1125
1126p.y += (images[iSelection].image->height / 2) + font_console.chars[0]->height;
1127
1128// draw volume label
1129drawStrCenteredAt( device->label, &font_small, buffer, p);
1130
1131}
1132
1133// ====================================================================
1134
1135void drawDeviceList (int start, int end, int selection)
1136{
1137inti;
1138boolshoWinfo = false;
1139extern bool showBootBanner;
1140position_tp, p_prev, p_next;
1141
1142//uint8_tmaxDevices = MIN( gui.maxdevices, menucount );
1143
1144fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);
1145
1146makeRoundedCorners( gui.devicelist.pixmap);
1147
1148switch (gui.layout) {
1149
1150case VerticalLayout:
1151p.x = (gui.devicelist.width /2);
1152p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );
1153
1154// place scroll indicators at top & bottom edges
1155p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );
1156p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );
1157
1158break;
1159
1160default:// use Horizontal layout as the default
1161
1162case HorizontalLayout:
1163p.x = (gui.devicelist.width - ( gui.devicelist.width / gui.maxdevices ) * gui.maxdevices ) / 2 + ( images[iSelection].image->width / 2) + images[iDeviceScrollPrev].image->width + gui.devicelist.iconspacing;
1164p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );
1165
1166// place scroll indicators at left & right edges
1167p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );
1168p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );
1169
1170break;
1171
1172}
1173
1174// draw visible device icons
1175for (i = 0; i < gui.maxdevices; i++)
1176{
1177BVRef param = menuItems[start + i].param;
1178
1179bool isSelected = ((start + i) == selection) ? true : false;
1180if (isSelected) {
1181if (param->flags & kBVFlagNativeBoot) {
1182infoMenuNativeBoot = true;
1183} else {
1184infoMenuNativeBoot = false;
1185if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END) {
1186infoMenuSelection = 0;
1187}
1188}
1189
1190if (gui.menu.draw) {
1191drawInfoMenuItems();
1192}
1193getBoolForKey(kShowInfoKey, &shoWinfo, &bootInfo->chameleonConfig);
1194
1195if (shoWinfo && showBootBanner) {
1196gui.debug.cursor = pos( 10, 100);
1197dprintf( &gui.screen, "label: %s\n", param->label );
1198dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev );
1199dprintf( &gui.screen, "type: 0x%x\n", param->type );
1200dprintf( &gui.screen, "flags: 0x%x\n", param->flags );
1201dprintf( &gui.screen, "part_no: %d\n", param->part_no );
1202dprintf( &gui.screen, "part_boff: 0x%x\n", param->part_boff );
1203dprintf( &gui.screen, "part_type: 0x%x\n", param->part_type );
1204dprintf( &gui.screen, "bps: 0x%x\n", param->bps );
1205dprintf( &gui.screen, "name: %s\n", param->name );
1206dprintf( &gui.screen, "type_name: %s\n", param->type_name );
1207dprintf( &gui.screen, "modtime: %d\n", param->modTime );
1208//// res
1209dprintf( &gui.screen, "width: %d\n", gui.screen.width );
1210dprintf( &gui.screen, "height: %d\n", gui.screen.height );
1211//dprintf( &gui.screen, "attr: 0x%x\n", gui.screen.attr ); //Azi: reminder
1212//dprintf( &gui.screen, "mm: %d\n", gui.screen.mm );
1213}
1214}
1215
1216drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);
1217
1218if (gui.layout == HorizontalLayout)
1219{
1220p.x += images[iSelection].image->width + gui.devicelist.iconspacing;
1221}
1222if (gui.layout == VerticalLayout)
1223{
1224p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing );
1225}
1226}
1227
1228// draw prev indicator
1229if (start) {
1230blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );
1231}
1232// draw next indicator
1233if ( end < gDeviceCount - 1 ) {
1234blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );
1235}
1236gui.redraw = true;
1237
1238updateVRAM();
1239
1240}
1241
1242// ====================================================================
1243
1244void clearGraphicBootPrompt()
1245{
1246// clear text buffer
1247//prompt[0] = '\0';
1248//prompt_pos=0;
1249
1250
1251if(gui.bootprompt.draw == true )
1252{
1253gui.bootprompt.draw = false;
1254gui.redraw = true;
1255// this causes extra frames to be drawn
1256//updateVRAM();
1257}
1258
1259return;
1260}
1261
1262// ====================================================================
1263
1264void updateGraphicBootPrompt()
1265{
1266fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);
1267
1268makeRoundedCorners( gui.bootprompt.pixmap);
1269
1270position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );
1271
1272// print the boot prompt text
1273drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);
1274
1275// get the position of the end of the boot prompt text to display user input
1276position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );
1277
1278drawStr( gBootArgs, &font_console, gui.bootprompt.pixmap, p_prompt);
1279
1280gui.menu.draw = false;
1281gui.bootprompt.draw = true;
1282gui.redraw = true;
1283
1284updateVRAM();
1285
1286return;
1287}
1288
1289// ====================================================================
1290
1291static inline
1292void vramwrite (void *data, int width, int height)
1293{
1294if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)
1295{
1296memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
1297}
1298else
1299{
1300uint32_t r;
1301uint32_t g;
1302uint32_t b;
1303int i, j;
1304for (i = 0; i < VIDEO (height); i++)
1305{
1306for (j = 0; j < VIDEO (width); j++)
1307{
1308b = ((uint8_t *) data)[4*i*width + 4*j];
1309g = ((uint8_t *) data)[4*i*width + 4*j + 1];
1310r = ((uint8_t *) data)[4*i*width + 4*j + 2];
1311switch (VIDEO (depth))
1312{
1313case 32:
1314*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1315break;
1316case 24:
1317*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)
1318| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1319break;
1320case 16:
1321// Somehow 16-bit is always 15-bits really
1322//*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);
1323//break;
1324case 15:
1325*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);
1326break;
1327default:
1328break;
1329}
1330}
1331}
1332}
1333}
1334
1335// ====================================================================
1336
1337void updateVRAM()
1338{
1339if (gui.redraw)
1340{
1341if (gui.devicelist.draw)
1342{
1343blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
1344}
1345if (gui.bootprompt.draw)
1346{
1347blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
1348}
1349if (gui.menu.draw)
1350{
1351blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
1352}
1353if (gui.infobox.draw)
1354{
1355blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
1356}
1357}
1358
1359vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
1360
1361if (gui.redraw)
1362{
1363memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
1364gui.redraw = false;
1365}
1366}
1367
1368// ====================================================================
1369
1370struct putc_info //Azi: exists on console.c & printf.c
1371{
1372char * str;
1373char * last_str;
1374};
1375
1376// ====================================================================
1377
1378static int
1379sputc(int c, struct putc_info * pi) //Azi: same as above
1380{
1381if (pi->last_str)
1382{
1383if (pi->str == pi->last_str)
1384{
1385*(pi->str) = '\0';
1386return 0;
1387}
1388}
1389*(pi->str)++ = c;
1390return c;
1391}
1392
1393// ====================================================================
1394
1395int gprintf( window_t * window, const char * fmt, ...)
1396{
1397char *formattedtext;
1398
1399va_list ap;
1400
1401struct putc_info pi;
1402
1403if ((formattedtext = malloc(1024)) != NULL)
1404{
1405// format the text
1406va_start(ap, fmt);
1407pi.str = formattedtext;
1408pi.last_str = 0;
1409prf(fmt, ap, sputc, &pi);
1410*pi.str = '\0';
1411va_end(ap);
1412
1413position_torigin, cursor, bounds;
1414
1415int i;
1416int character;
1417
1418origin.x = MAX( window->cursor.x, window->hborder );
1419origin.y = MAX( window->cursor.y, window->vborder );
1420
1421bounds.x = ( window->width - window->hborder );
1422bounds.y = ( window->height - window->vborder );
1423
1424cursor = origin;
1425
1426font_t *font = &font_console;
1427
1428for( i=0; i< strlen(formattedtext); i++ )
1429{
1430character = formattedtext[i];
1431
1432character -= 32;
1433
1434// newline ?
1435if( formattedtext[i] == '\n' )
1436{
1437cursor.x = window->hborder;
1438cursor.y += font->height;
1439
1440if ( cursor.y > bounds.y )
1441{
1442cursor.y = origin.y;
1443}
1444continue;
1445}
1446
1447// tab ?
1448if( formattedtext[i] == '\t' )
1449{
1450cursor.x += ( font->chars[0]->width * 5 );
1451}
1452
1453// draw the character
1454if( font->chars[character])
1455{
1456blend(font->chars[character], window->pixmap, cursor);
1457}
1458
1459cursor.x += font->chars[character]->width;
1460
1461// check x pos and do newline
1462if ( cursor.x > bounds.x )
1463{
1464cursor.x = origin.x;
1465cursor.y += font->height;
1466}
1467
1468// check y pos and reset to origin.y
1469if ( cursor.y > bounds.y )
1470{
1471cursor.y = origin.y;
1472}
1473}
1474
1475// update cursor postition
1476window->cursor = cursor;
1477
1478free(formattedtext);
1479
1480return 0;
1481}
1482return 1;
1483}
1484
1485// ====================================================================
1486
1487int dprintf( window_t * window, const char * fmt, ...)
1488{
1489char *formattedtext;
1490
1491va_list ap;
1492
1493//window = &gui.debug;
1494
1495struct putc_info pi;
1496
1497if ((formattedtext = malloc(1024)) != NULL)
1498{
1499// format the text
1500va_start(ap, fmt);
1501pi.str = formattedtext;
1502pi.last_str = 0;
1503prf(fmt, ap, sputc, &pi);
1504*pi.str = '\0';
1505va_end(ap);
1506
1507position_torigin, cursor, bounds;
1508
1509int i;
1510int character;
1511
1512origin.x = MAX( gui.debug.cursor.x, window->hborder );
1513origin.y = MAX( gui.debug.cursor.y, window->vborder );
1514
1515bounds.x = ( window->width - window->hborder );
1516bounds.y = ( window->height - window->vborder );
1517
1518cursor = origin;
1519
1520font_t *font = &font_console;
1521
1522for( i=0; i< strlen(formattedtext); i++ )
1523{
1524character = formattedtext[i];
1525
1526character -= 32;
1527
1528// newline ?
1529if( formattedtext[i] == '\n' )
1530{
1531cursor.x = window->hborder;
1532cursor.y += font->height;
1533
1534if ( cursor.y > bounds.y )
1535{
1536cursor.y = origin.y;
1537}
1538continue;
1539}
1540
1541// tab ?
1542if( formattedtext[i] == '\t' )
1543{
1544cursor.x += ( font->chars[0]->width * 5 );
1545}
1546// draw the character
1547if( font->chars[character])
1548{
1549blend(font->chars[character], gui.backbuffer, cursor);
1550}
1551cursor.x += font->chars[character]->width;
1552
1553// check x pos and do newline
1554if ( cursor.x > bounds.x )
1555{
1556cursor.x = origin.x;
1557cursor.y += font->height;
1558}
1559
1560// check y pos and reset to origin.y
1561if ( cursor.y > bounds.y )
1562{
1563cursor.y = origin.y;
1564}
1565}
1566
1567// update cursor postition
1568gui.debug.cursor = cursor;
1569
1570free(formattedtext);
1571
1572return 0;
1573
1574}
1575return 1;
1576}
1577
1578// ====================================================================
1579
1580int vprf(const char * fmt, va_list ap)
1581{
1582int i;
1583int character;
1584
1585char *formattedtext;
1586window_t *window = &gui.screen;
1587struct putc_info pi;
1588
1589position_torigin, cursor, bounds;
1590font_t *font = &font_console;
1591
1592if ((formattedtext = malloc(1024)) != NULL)
1593{
1594// format the text
1595pi.str = formattedtext;
1596pi.last_str = 0;
1597prf(fmt, ap, sputc, &pi);
1598*pi.str = '\0';
1599
1600origin.x = MAX( window->cursor.x, window->hborder );
1601origin.y = MAX( window->cursor.y, window->vborder );
1602bounds.x = ( window->width - ( window->hborder * 2 ) );
1603bounds.y = ( window->height - ( window->vborder * 2 ) );
1604cursor = origin;
1605
1606for( i=0; i< strlen(formattedtext) ; i++ )
1607{
1608character = formattedtext[i];
1609character -= 32;
1610
1611// newline ?
1612if( formattedtext[i] == '\n' )
1613{
1614cursor.x = window->hborder;
1615cursor.y += font->height;
1616if ( cursor.y > bounds.y )
1617{
1618gui.redraw = true;
1619updateVRAM();
1620cursor.y = window->vborder;
1621}
1622window->cursor.y = cursor.y;
1623continue;
1624}
1625
1626// tab ?
1627if( formattedtext[i] == '\t' )
1628{
1629cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
1630continue;
1631}
1632cursor.x += font->chars[character]->width;
1633
1634// check x pos and do newline
1635if ( cursor.x > bounds.x )
1636{
1637cursor.x = origin.x;
1638cursor.y += font->height;
1639}
1640
1641// check y pos and reset to origin.y
1642if ( cursor.y > ( bounds.y + font->chars[0]->height) )
1643{
1644gui.redraw = true;
1645updateVRAM();
1646cursor.y = window->vborder;
1647}
1648// draw the character
1649if( font->chars[character])
1650{
1651blend(font->chars[character], gui.backbuffer, cursor);
1652}
1653}
1654// save cursor postition
1655window->cursor.x = cursor.x;
1656updateVRAM();
1657free(formattedtext);
1658return 0;
1659}
1660return 1;
1661}
1662
1663// ====================================================================
1664
1665pixmap_t *charToPixmap(unsigned char ch, font_t *font)
1666{
1667unsigned int cha = (unsigned int)ch - 32;
1668if (cha >= font->count)
1669{
1670// return ? if the font for the char doesn't exists
1671cha = '?' - 32;
1672}
1673return font->chars[cha] ? font->chars[cha] : NULL;
1674}
1675
1676// ====================================================================
1677
1678position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p)
1679{
1680pixmap_t* pm = charToPixmap(ch, font);
1681if (pm && ((p.x + pm->width) < blendInto->width))
1682{
1683blend(pm, blendInto, p);
1684return pos(p.x + pm->width, p.y);
1685}
1686else
1687{
1688return p;
1689}
1690}
1691
1692// ====================================================================
1693
1694void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)
1695{
1696int i=0;
1697position_t current_pos = pos(p.x, p.y);
1698
1699for (i=0; i < strlen(ch); i++)
1700{
1701// newline ?
1702if ( ch[i] == '\n' )
1703{
1704current_pos.x = p.x;
1705current_pos.y += font->height;
1706continue;
1707}
1708
1709// tab ?
1710if ( ch[i] == '\t' )
1711{
1712current_pos.x += TAB_PIXELS_WIDTH;
1713continue;
1714}
1715
1716current_pos = drawChar(ch[i], font, blendInto, current_pos);
1717}
1718}
1719
1720// ====================================================================
1721
1722void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)
1723{
1724int i = 0;
1725int width = 0;
1726int max_width = 0;
1727int height = font->height;
1728
1729// calculate the width in pixels
1730for (i=0; i < strlen(text); i++)
1731{
1732if (text[i] == '\n')
1733{
1734width = 0;
1735height += font->height;
1736}
1737else if (text[i] == '\t')
1738{
1739width += TAB_PIXELS_WIDTH;
1740}
1741else
1742{
1743pixmap_t* pm = charToPixmap(text[i], font);
1744if (pm)
1745{
1746width += pm->width;
1747}
1748}
1749if (width > max_width)
1750{
1751max_width = width;
1752}
1753}
1754
1755p.x = ( p.x - ( max_width / 2 ) );
1756p.y = ( p.y - ( height / 2 ) );
1757
1758drawStr(text, font, blendInto, p);
1759}
1760
1761// ====================================================================
1762
1763int destroyFont(font_t *font)
1764{
1765int i;
1766for (i = 0; i < CHARACTERS_COUNT; i++)
1767{
1768if (font->chars[i])
1769{
1770if (font->chars[i]->pixels)
1771{
1772free (font->chars[i]->pixels);
1773}
1774free (font->chars[i]);
1775font->chars[i] = 0;
1776}
1777}
1778return 0;
1779}
1780
1781// ====================================================================
1782
1783int initFont(font_t *font, image_t *data)
1784{
1785unsigned int x = 0, y = 0, x2 = 0, x3 = 0;
1786
1787int start = 0, end = 0, count = 0, space = 0;
1788
1789bool monospaced = false;
1790
1791font->height = data->image->height;
1792
1793for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++)
1794{
1795start = end;
1796
1797// if the pixel is red we've reached the end of the char
1798if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
1799{
1800end = x + 1;
1801
1802if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
1803{
1804font->chars[count]->width = ( end - start) - 1;
1805font->chars[count]->height = font->height;
1806
1807if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
1808{
1809space += ( font->chars[count]->width * data->image->height * 4 );
1810// we skip the first line because there are just the red pixels for the char width
1811for( y = 1; y< (font->height); y++)
1812{
1813for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
1814{
1815pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
1816}
1817}
1818
1819// check if font is monospaced
1820if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
1821{
1822monospaced = true;
1823}
1824
1825font->width = font->chars[count]->width;
1826
1827count++;
1828}
1829}
1830}
1831}
1832
1833for (x = count; x < CHARACTERS_COUNT; x++)
1834{
1835font->chars[x] = NULL;
1836}
1837
1838if(monospaced)
1839{
1840font->width = 0;
1841}
1842
1843font->count = count;
1844
1845return 0;
1846}
1847
1848// ====================================================================
1849
1850void colorFont(font_t *font, uint32_t color)
1851{
1852if( !color )
1853{
1854return;
1855}
1856
1857int x, y, width, height;
1858int count = 0;
1859pixel_t *buff;
1860
1861while( font->chars[count++] )
1862{
1863width = font->chars[count-1]->width;
1864height = font->chars[count-1]->height;
1865for( y = 0; y < height; y++ )
1866{
1867for( x = 0; x < width; x++ )
1868{
1869buff = &(pixel( font->chars[count-1], x, y ));
1870if( buff->ch.a )
1871{
1872buff->ch.r = (color & 0xFFFF0000) >> 16;
1873buff->ch.g = (color & 0xFF00FF00) >> 8;
1874buff->ch.b = (color & 0xFF0000FF);
1875}
1876}
1877}
1878}
1879}
1880
1881// ====================================================================
1882
1883void makeRoundedCorners(pixmap_t *p)
1884{
1885int x,y;
1886int width=p->width-1;
1887int height=p->height-1;
1888
1889// 10px rounded corner alpha values
1890uint8_t roundedCorner[10][10] =
1891{
1892{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},
1893{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},
1894{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1895{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1896{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1897{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1898{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1899{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1900{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1901{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
1902};
1903
1904uint8_t alpha=0;
1905
1906for( y=0; y<10; y++)
1907{
1908for( x=0; x<10; x++)
1909{
1910// skip if the pixel should be visible
1911if(roundedCorner[y][x] != 0xFF)
1912{
1913alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
1914// Upper left corner
1915pixel(p, x, y).ch.a = alpha;
1916
1917// upper right corner
1918pixel(p, width-x,y).ch.a = alpha;
1919
1920// lower left corner
1921pixel(p, x, height-y).ch.a = alpha;
1922
1923// lower right corner
1924pixel(p, width-x, height-y).ch.a = alpha;
1925}
1926}
1927}
1928}
1929
1930// ====================================================================
1931
1932void showInfoBox(char *title, char *text_orig)
1933{
1934char* text;
1935int i, key, lines, visiblelines;
1936
1937int currentline=0;
1938int cnt=0;
1939int offset=0;
1940
1941if( !title || !text_orig ) {
1942return;
1943}
1944
1945// Create a copy so that we don't mangle the original
1946text = malloc(strlen(text_orig) + 1);
1947strcpy(text, text_orig);
1948
1949position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );
1950
1951// calculate number of lines in the title
1952for ( i = 0, lines = 1; i<strlen(title); i++ ) {
1953if( title[i] == '\n') {
1954lines++;
1955}
1956}
1957// y position of text is lines in title * height of font
1958position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));
1959
1960// calculate number of lines in the text
1961for ( i=0, lines = 1; i<strlen(text); i++ ) {
1962if( text[i] == '\n') {
1963lines++;
1964}
1965}
1966// if text ends with \n strip off
1967if( text[i] == '\n' || text[i] == '\0') {
1968lines--;
1969}
1970visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
1971
1972// lets display the text and allow scroll thru using up down / arrows
1973while(1)
1974{
1975// move to current line in text
1976for( offset = 0, i = 0; offset < strlen(text); offset++ )
1977{
1978if( currentline == i)
1979{
1980break;
1981}
1982
1983if( text[offset] =='\n')
1984{
1985i++;
1986}
1987}
1988
1989// find last visible line in text and place \0
1990for( i = offset, cnt = 0; i < strlen(text); i++)
1991{
1992if(text[i]=='\n')
1993{
1994cnt++;
1995}
1996
1997if ( cnt == visiblelines )
1998{
1999text[i]='\0';
2000break;
2001}
2002}
2003
2004fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);
2005
2006makeRoundedCorners( gui.infobox.pixmap);
2007
2008// print the title if present
2009if( title ) {
2010drawStr(title, &font_console, gui.infobox.pixmap, pos_title);
2011}
2012// print the text
2013drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);
2014
2015// restore \n in text
2016if ( cnt == visiblelines ) {
2017text[i] = '\n';
2018}
2019position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
2020
2021// draw prev indicator
2022if(offset)
2023{
2024blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
2025}
2026
2027// draw next indicator
2028if( lines > ( currentline + visiblelines ) )
2029{
2030pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
2031blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
2032}
2033
2034gui.bootprompt.draw = false;
2035gui.infobox.draw = true;
2036gui.redraw = true;
2037
2038updateVRAM();
2039
2040key = getchar();
2041
2042if( key == KEY_UP ) {
2043if( currentline > 0 ) {
2044currentline--;
2045}
2046}
2047
2048if( key == KEY_DOWN ) {
2049if( lines > ( currentline + visiblelines ) ) {
2050currentline++;
2051}
2052}
2053
2054if( key == KEY_ESC || key == 'q' || key == 'Q') {
2055gui.infobox.draw = false;
2056gui.redraw = true;
2057updateVRAM();
2058break;
2059}
2060
2061if(key == ' ') { // spacebar = next page
2062if( lines > ( currentline + visiblelines ) ) {
2063currentline += visiblelines;
2064}
2065if(lines < (currentline + visiblelines)) {
2066currentline = lines - visiblelines;
2067}
2068}
2069}
2070free(text);
2071}
2072
2073// ====================================================================
2074
2075#if UNUSED
2076void animateProgressBar()
2077{
2078int y;
2079
2080if( time18() > lasttime)
2081{
2082lasttime = time18();
2083
2084pixmap_t *buffBar = images[iProgressBar].image;
2085
2086uint32_t buff = buffBar->pixels[0].value;
2087
2088memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );
2089
2090for( y = buffBar->height - 1; y > 0; y--) {
2091pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);
2092}
2093pixel(buffBar, buffBar->width-1, 0).value = buff;
2094}
2095}
2096#endif
2097
2098// ====================================================================
2099
2100void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)
2101{
2102if(progress>100) {
2103return;
2104}
2105
2106p.x = ( p.x - ( width / 2 ) );
2107
2108int todraw = (width * progress) / 100;
2109
2110pixmap_t *buff = images[iProgressBar].image;
2111pixmap_t *buffBG = images[iProgressBarBackground].image;
2112if(!buff || !buffBG) {
2113return;
2114}
2115
2116pixmap_t progressbar;
2117progressbar.pixels=malloc(width * 4 * buff->height);
2118if(!progressbar.pixels) {
2119return;
2120}
2121
2122progressbar.width = width;
2123progressbar.height = buff->height;
2124
2125int x=0,x2=0,y=0;
2126
2127for(y=0; y<buff->height; y++) {
2128for(x=0; x<todraw; x++, x2++) {
2129if(x2 == (buff->width-1)) {
2130x2=0;
2131}
2132pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;
2133}
2134x2=0;
2135}
2136
2137for(y=0; y<buff->height; y++) {
2138for(x=todraw, x2 = 0; x < width - 1; x++, x2++) {
2139if(x2 == (buffBG->width -2 )) {
2140x2 = 0;
2141}
2142pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;
2143}
2144if(progress < 100) {
2145pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;
2146}
2147
2148if(progress == 0) {
2149pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;
2150}
2151
2152x2=0;
2153}
2154
2155blend(&progressbar, blendInto, p);
2156#if 0
2157animateProgressBar();
2158#endif
2159free(progressbar.pixels);
2160}
2161
2162// ====================================================================
2163
2164void drawInfoMenuItems()
2165{
2166int i,n;
2167
2168position_t position;
2169
2170pixmap_t *selection = images[iMenuSelection].image;
2171
2172pixmap_t *pbuff;
2173
2174fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);
2175
2176makeRoundedCorners(gui.menu.pixmap);
2177
2178uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;
2179
2180position = pos(0,0);
2181
2182for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++) {
2183if (i == infoMenuSelection) {
2184blend(selection, gui.menu.pixmap, position);
2185}
2186
2187pbuff = images[n].image;
2188if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END) {
2189blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
2190pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
2191} else {
2192blend( pbuff, gui.menu.pixmap,
2193pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
2194}
2195
2196drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap,
2197pos(position.x + (pbuff->width + gui.menu.hborder),
2198position.y + ((selection->height - font_console.height) / 2)));
2199position.y += images[iMenuSelection].image->height;
2200
2201}
2202
2203gui.redraw = true;
2204}
2205
2206// ====================================================================
2207
2208int drawInfoMenu()
2209{
2210drawInfoMenuItems();
2211
2212gui.menu.draw = true;
2213
2214updateVRAM();
2215
2216return 1;
2217}
2218
2219// ====================================================================
2220
2221int updateInfoMenu(int key)
2222{
2223switch (key)
2224{
2225
2226case KEY_UP:// up arrow
2227if (infoMenuSelection > 0) {
2228if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1) {
2229infoMenuSelection -= 4;
2230} else {
2231infoMenuSelection--;
2232}
2233drawInfoMenuItems();
2234updateVRAM();
2235
2236} else {
2237
2238gui.menu.draw = false;
2239gui.redraw = true;
2240
2241updateVRAM();
2242
2243return CLOSE_INFO_MENU;
2244}
2245break;
2246
2247case KEY_DOWN:// down arrow
2248if (infoMenuSelection < infoMenuItemsCount - 1) {
2249if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
2250{
2251infoMenuSelection += 4;
2252} else {
2253infoMenuSelection++;
2254}
2255drawInfoMenuItems();
2256updateVRAM();
2257}
2258break;
2259
2260case KEY_ENTER:
2261key = 0;
2262if( infoMenuSelection == MENU_SHOW_MEMORY_INFO ) {
2263showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
2264} else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO ) {
2265showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
2266} else if( infoMenuSelection == MENU_SHOW_HELP ) {
2267showHelp();
2268} else {
2269int buff = infoMenuSelection;
2270infoMenuSelection = 0;
2271return buff;
2272}
2273break;
2274default:
2275break;
2276}
2277return DO_NOT_BOOT;
2278}
2279
2280// ====================================================================
2281
2282uint16_t bootImageWidth = 0;
2283uint16_t bootImageHeight = 0;
2284uint8_t *bootImageData = NULL;
2285static bool usePngImage = true;
2286
2287//==========================================================================
2288// loadBootGraphics
2289static void loadBootGraphics(void)
2290{
2291if (bootImageData != NULL) {
2292return;
2293}
2294
2295char dirspec[256];
2296
2297if ((strlen(theme_name) + 24) > sizeof(dirspec))
2298{
2299usePngImage = false;
2300return;
2301}
2302sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);
2303if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {
2304#ifdef CONFIG_EMBED_THEME
2305if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
2306#endif
2307usePngImage = false;
2308}
2309}
2310
2311//==========================================================================
2312// drawBootGraphics
2313void drawBootGraphics(void)
2314{
2315int pos;
2316int length;
2317const char *dummyVal;
2318int oldScreenWidth, oldScreenHeight;
2319bool legacy_logo;
2320uint16_t x, y;
2321
2322if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->chameleonConfig) && legacy_logo) {
2323usePngImage = false;
2324} else if (bootImageData == NULL) {
2325loadBootGraphics();
2326}
2327
2328// parse screen size parameters
2329if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0) {
2330screen_params[0] = pos;
2331} else {
2332screen_params[0] = DEFAULT_SCREEN_WIDTH;
2333}
2334if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0) {
2335screen_params[1] = pos;
2336} else {
2337screen_params[1] = DEFAULT_SCREEN_HEIGHT;
2338}
2339
2340// Save current screen resolution.
2341oldScreenWidth = gui.screen.width;
2342oldScreenHeight = gui.screen.height;
2343
2344gui.screen.width = screen_params[0];
2345gui.screen.height = screen_params[1];
2346
2347// find best matching vesa mode for our requested width & height
2348getGraphicModeParams(screen_params);
2349
2350// Set graphics mode if the booter was in text mode or the screen resolution has changed.
2351if (bootArgs->Video.v_display == VGA_TEXT_MODE || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) ) {
2352setVideoMode(GRAPHICS_MODE, 0);
2353}
2354
2355if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->chameleonConfig)) {
2356drawCheckerBoard();
2357} else {
2358// Fill the background to 75% grey (same as BootX).
2359drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
2360}
2361if ((bootImageData) && (usePngImage)) {
2362x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
2363y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
2364
2365// Draw the image in the center of the display.
2366blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
2367} else {
2368uint8_t *appleBootPict;
2369bootImageData = NULL;
2370bootImageWidth = kAppleBootWidth;
2371bootImageHeight = kAppleBootHeight;
2372
2373// Prepare the data for the default Apple boot image.
2374appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
2375if (appleBootPict) {
2376convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
2377if (bootImageData) {
2378x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
2379y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
2380drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
2381free(bootImageData);
2382}
2383free(appleBootPict);
2384}
2385}
2386}
2387// ====================================================================
2388

Archive Download this file

Revision: 2594