Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 1540