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

Archive Download this file

Revision: 1147