Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/boot2/gui.c

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

Archive Download this file

Revision: 2832