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

Archive Download this file

Revision: 2711