Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 2587