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->bootConfig );
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{
824int i;
825position_t p, p_prev, p_next;
826
827//uint8_tmaxDevices = MIN( gui.maxdevices, menucount );
828
829fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);
830
831makeRoundedCorners( gui.devicelist.pixmap);
832
833switch (gui.layout)
834{
835
836case VerticalLayout:
837p.x = (gui.devicelist.width /2);
838p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );
839
840// place scroll indicators at top & bottom edges
841p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );
842p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );
843
844break;
845
846default:// use Horizontal layout as the default
847
848case HorizontalLayout:
849p.x = (gui.devicelist.width - ( gui.devicelist.width / gui.maxdevices ) * gui.maxdevices ) / 2 + ( images[iSelection].image->width / 2) + images[iDeviceScrollPrev].image->width + gui.devicelist.iconspacing;
850p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );
851
852// place scroll indicators at left & right edges
853p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );
854p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );
855
856break;
857
858}
859
860// draw visible device icons
861for (i = 0; i < gui.maxdevices; i++)
862{
863BVRef param = menuItems[start + i].param;
864
865 bool isSelected = ((start + i) == selection) ? true : false;
866if (isSelected)
867{
868 if (param->flags & kBVFlagNativeBoot)
869 {
870 infoMenuNativeBoot = true;
871 }
872 else
873 {
874 infoMenuNativeBoot = false;
875 if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)
876 infoMenuSelection = 0;
877 }
878
879if (gui.menu.draw)
880drawInfoMenuItems();
881#ifdef AUTORES_DEBUG //Azi: update diff
882#define DEBUG
883#endif
884
885#ifdef DEBUG //Azi: changed from if to ifdef
886 gui.debug.cursor = pos( 10, 100);
887dprintf( &gui.screen, "label: %s\n", param->label );
888dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev );
889dprintf( &gui.screen, "type: 0x%x\n", param->type );
890dprintf( &gui.screen, "flags: 0x%x\n", param->flags );
891dprintf( &gui.screen, "part_no: %d\n", param->part_no );
892dprintf( &gui.screen, "part_boff: 0x%x\n", param->part_boff );
893dprintf( &gui.screen, "part_type: 0x%x\n", param->part_type );
894dprintf( &gui.screen, "bps: 0x%x\n", param->bps );
895dprintf( &gui.screen, "name: %s\n", param->name );
896dprintf( &gui.screen, "type_name: %s\n", param->type_name );
897dprintf( &gui.screen, "modtime: %d\n", param->modTime );
898dprintf( &gui.screen, "width: %d\n", gui.screen.width );
899dprintf( &gui.screen, "height: %d\n", gui.screen.height );
900dprintf( &gui.screen, "attr: 0x%x\n", gui.screen.attr );
901dprintf( &gui.screen, "mm: %d\n", gui.screen.mm );
902#endif
903
904#ifdef AUTORES_DEBUG
905#undef DEBUG
906#endif
907}
908
909drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);
910
911if (gui.layout == HorizontalLayout)
912{
913p.x += images[iSelection].image->width + gui.devicelist.iconspacing;
914}
915if (gui.layout == VerticalLayout)
916{
917p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing );
918}
919}
920
921// draw prev indicator
922if(start)
923blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );
924
925// draw next indicator
926if( end < gDeviceCount - 1 )
927blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );
928
929gui.redraw = true;
930
931updateVRAM();
932
933}
934
935void clearGraphicBootPrompt()
936{
937// clear text buffer
938//prompt[0] = '\0';
939//prompt_pos=0;
940
941
942if(gui.bootprompt.draw == true )
943{
944gui.bootprompt.draw = false;
945gui.redraw = true;
946// this causes extra frames to be drawn
947//updateVRAM();
948}
949
950return;
951}
952
953void updateGraphicBootPrompt()
954{
955fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);
956
957makeRoundedCorners( gui.bootprompt.pixmap);
958
959position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );
960
961// print the boot prompt text
962drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);
963
964// get the position of the end of the boot prompt text to display user input
965position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );
966
967drawStr( gBootArgs, &font_console, gui.bootprompt.pixmap, p_prompt);
968
969gui.menu.draw = false;
970gui.bootprompt.draw = true;
971gui.redraw = true;
972
973updateVRAM();
974
975return;
976}
977
978inline
979void vramwrite (void *data, int width, int height)
980{
981if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)
982memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
983else
984{
985uint32_t r, g, b;
986int i, j;
987for (i = 0; i < VIDEO (height); i++)
988for (j = 0; j < VIDEO (width); j++)
989{
990b = ((uint8_t *) data)[4*i*width + 4*j];
991g = ((uint8_t *) data)[4*i*width + 4*j + 1];
992r = ((uint8_t *) data)[4*i*width + 4*j + 2];
993switch (VIDEO (depth))
994{
995case 32:
996*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
997break;
998case 24:
999*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)
1000| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1001break;
1002case 16:
1003// Somehow 16-bit is always 15-bits really
1004//*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);
1005//break;
1006case 15:
1007*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);
1008break;
1009}
1010}
1011}
1012}
1013
1014void updateVRAM()
1015{
1016if (gui.redraw)
1017{
1018if (gui.devicelist.draw)
1019blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
1020
1021if (gui.bootprompt.draw)
1022blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
1023
1024if (gui.menu.draw)
1025blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
1026
1027if (gui.infobox.draw)
1028blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
1029}
1030
1031vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
1032
1033if (gui.redraw)
1034{
1035memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
1036gui.redraw = false;
1037}
1038}
1039
1040struct putc_info //Azi: exists on console.c & printf.c
1041{
1042 char * str;
1043 char * last_str;
1044};
1045
1046static int
1047sputc(int c, struct putc_info * pi) //Azi: same as above
1048{
1049 if (pi->last_str)
1050 if (pi->str == pi->last_str) {
1051 *(pi->str) = '\0';
1052 return 0;
1053 }
1054 *(pi->str)++ = c;
1055 return c;
1056}
1057
1058int gprintf( window_t * window, const char * fmt, ...)
1059{
1060char *formattedtext;
1061
1062va_list ap;
1063
1064struct putc_info pi;
1065
1066if ((formattedtext = malloc(1024)) != NULL) {
1067// format the text
1068va_start(ap, fmt);
1069pi.str = formattedtext;
1070pi.last_str = 0;
1071prf(fmt, ap, sputc, &pi);
1072*pi.str = '\0';
1073va_end(ap);
1074
1075position_torigin, cursor, bounds;
1076
1077int i;
1078int character;
1079
1080origin.x = MAX( window->cursor.x, window->hborder );
1081origin.y = MAX( window->cursor.y, window->vborder );
1082
1083bounds.x = ( window->width - window->hborder );
1084bounds.y = ( window->height - window->vborder );
1085
1086cursor = origin;
1087
1088font_t *font = &font_console;
1089
1090for( i=0; i< strlen(formattedtext); i++ )
1091{
1092character = formattedtext[i];
1093
1094character -= 32;
1095
1096// newline ?
1097if( formattedtext[i] == '\n' )
1098{
1099cursor.x = window->hborder;
1100cursor.y += font->height;
1101
1102if ( cursor.y > bounds.y )
1103cursor.y = origin.y;
1104
1105continue;
1106}
1107
1108// tab ?
1109if( formattedtext[i] == '\t' )
1110cursor.x += ( font->chars[0]->width * 5 );
1111
1112// draw the character
1113if( font->chars[character])
1114blend(font->chars[character], window->pixmap, cursor);
1115
1116cursor.x += font->chars[character]->width;
1117
1118// check x pos and do newline
1119if ( cursor.x > bounds.x )
1120{
1121cursor.x = origin.x;
1122cursor.y += font->height;
1123}
1124
1125// check y pos and reset to origin.y
1126if ( cursor.y > bounds.y )
1127cursor.y = origin.y;
1128}
1129
1130// update cursor postition
1131window->cursor = cursor;
1132
1133free(formattedtext);
1134
1135return 0;
1136
1137}
1138return 1;
1139}
1140
1141int dprintf( window_t * window, const char * fmt, ...)
1142{
1143char *formattedtext;
1144
1145va_list ap;
1146
1147//window = &gui.debug;
1148
1149struct putc_info pi;
1150
1151if ((formattedtext = malloc(1024)) != NULL) {
1152// format the text
1153va_start(ap, fmt);
1154pi.str = formattedtext;
1155pi.last_str = 0;
1156prf(fmt, ap, sputc, &pi);
1157*pi.str = '\0';
1158va_end(ap);
1159
1160position_torigin, cursor, bounds;
1161
1162int i;
1163int character;
1164
1165origin.x = MAX( gui.debug.cursor.x, window->hborder );
1166origin.y = MAX( gui.debug.cursor.y, window->vborder );
1167
1168bounds.x = ( window->width - window->hborder );
1169bounds.y = ( window->height - window->vborder );
1170
1171cursor = origin;
1172
1173font_t *font = &font_console;
1174
1175for( i=0; i< strlen(formattedtext); i++ )
1176{
1177character = formattedtext[i];
1178
1179character -= 32;
1180
1181// newline ?
1182if( formattedtext[i] == '\n' )
1183{
1184cursor.x = window->hborder;
1185cursor.y += font->height;
1186
1187if ( cursor.y > bounds.y )
1188cursor.y = origin.y;
1189
1190continue;
1191}
1192
1193// tab ?
1194if( formattedtext[i] == '\t' )
1195cursor.x += ( font->chars[0]->width * 5 );
1196
1197// draw the character
1198if( font->chars[character])
1199blend(font->chars[character], gui.backbuffer, cursor);
1200
1201cursor.x += font->chars[character]->width;
1202
1203// check x pos and do newline
1204if ( cursor.x > bounds.x )
1205{
1206cursor.x = origin.x;
1207cursor.y += font->height;
1208}
1209
1210// check y pos and reset to origin.y
1211if ( cursor.y > bounds.y )
1212cursor.y = origin.y;
1213}
1214
1215// update cursor postition
1216gui.debug.cursor = cursor;
1217
1218free(formattedtext);
1219
1220return 0;
1221
1222}
1223return 1;
1224}
1225
1226int vprf(const char * fmt, va_list ap)
1227{
1228int i;
1229int character;
1230
1231char *formattedtext;
1232window_t *window = &gui.screen;
1233struct putc_info pi;
1234
1235position_torigin, cursor, bounds;
1236font_t *font = &font_console;
1237
1238if ((formattedtext = malloc(1024)) != NULL) {
1239// format the text
1240pi.str = formattedtext;
1241pi.last_str = 0;
1242prf(fmt, ap, sputc, &pi);
1243*pi.str = '\0';
1244
1245origin.x = MAX( window->cursor.x, window->hborder );
1246origin.y = MAX( window->cursor.y, window->vborder );
1247bounds.x = ( window->width - ( window->hborder * 2 ) );
1248bounds.y = ( window->height - ( window->vborder * 2 ) );
1249cursor = origin;
1250
1251for( i=0; i< strlen(formattedtext); i++ )
1252{
1253character = formattedtext[i];
1254character -= 32;
1255
1256// newline ?
1257if( formattedtext[i] == '\n' )
1258{
1259cursor.x = window->hborder;
1260cursor.y += font->height;
1261if ( cursor.y > bounds.y )
1262{
1263gui.redraw = true;
1264updateVRAM();
1265cursor.y = window->vborder;
1266}
1267window->cursor.y = cursor.y;
1268continue;
1269}
1270
1271// tab ?
1272if( formattedtext[i] == '\t' )
1273{
1274cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
1275continue;
1276}
1277cursor.x += font->chars[character]->width;
1278
1279// check x pos and do newline
1280if ( cursor.x > bounds.x )
1281{
1282cursor.x = origin.x;
1283cursor.y += font->height;
1284}
1285
1286// check y pos and reset to origin.y
1287if ( cursor.y > ( bounds.y + font->chars[0]->height) )
1288{
1289gui.redraw = true;
1290updateVRAM();
1291cursor.y = window->vborder;
1292}
1293// draw the character
1294if( font->chars[character])
1295blend(font->chars[character], gui.backbuffer, cursor);
1296}
1297// save cursor postition
1298window->cursor.x = cursor.x;
1299updateVRAM();
1300free(formattedtext);
1301return 0;
1302}
1303return 1;
1304}
1305
1306void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)
1307{
1308int i=0;
1309int y=0; // we need this to support multilines '\n'
1310int x=0;
1311
1312for(i=0;i<strlen(ch);i++)
1313{
1314int cha=(int)ch[i];
1315
1316cha-=32;
1317
1318// newline ?
1319if( ch[i] == '\n' )
1320{
1321x = 0;
1322y += font->height;
1323continue;
1324}
1325
1326// tab ?
1327if( ch[i] == '\t' )
1328x+=(font->chars[0]->width*5);
1329
1330if(font->chars[cha])
1331blend(font->chars[cha], blendInto, pos(p.x+x, p.y+y));
1332
1333x += font->chars[cha]->width;
1334}
1335}
1336
1337void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)
1338{
1339int i = 0;
1340int width = 0;
1341
1342// calculate the width in pixels
1343for(i=0;i<strlen(text);i++)
1344width += font->chars[text[i]-32]->width;
1345
1346p.x = ( p.x - ( width / 2 ) );
1347p.y = ( p.y - ( font->height / 2 ) );
1348
1349if ( p.x == -6 )
1350{
1351p.x = 0;
1352}
1353
1354for(i=0;i<strlen(text);i++)
1355{
1356int cha=(int)text[i];
1357
1358cha-=32;
1359
1360if(font->chars[cha])
1361{
1362blend(font->chars[cha], blendInto, p);
1363p.x += font->chars[cha]->width;
1364}
1365}
1366
1367}
1368
1369int initFont(font_t *font, image_t *data)
1370{
1371unsigned int x = 0, y = 0, x2 = 0, x3 = 0;
1372
1373int start = 0, end = 0, count = 0, space = 0;
1374
1375bool monospaced = false;
1376
1377font->height = data->image->height;
1378
1379for( x = 0; x < data->image->width; x++)
1380{
1381start = end;
1382
1383// if the pixel is red we've reached the end of the char
1384if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
1385{
1386end = x + 1;
1387
1388if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
1389{
1390font->chars[count]->width = ( end - start) - 1;
1391font->chars[count]->height = font->height;
1392
1393if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
1394{
1395space += ( font->chars[count]->width * data->image->height * 4 );
1396// we skip the first line because there are just the red pixels for the char width
1397for( y = 1; y< (font->height); y++)
1398{
1399for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
1400{
1401pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
1402}
1403}
1404
1405// check if font is monospaced
1406if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
1407monospaced = true;
1408
1409font->width = font->chars[count]->width;
1410
1411count++;
1412}
1413}
1414}
1415}
1416
1417if(monospaced)
1418font->width = 0;
1419
1420return 0;
1421}
1422
1423void colorFont(font_t *font, uint32_t color)
1424{
1425if( !color )
1426return;
1427
1428int x, y, width, height;
1429int count = 0;
1430pixel_t *buff;
1431
1432while( font->chars[count++] )
1433{
1434width = font->chars[count-1]->width;
1435height = font->chars[count-1]->height;
1436for( y = 0; y < height; y++ )
1437{
1438for( x = 0; x < width; x++ )
1439{
1440buff = &(pixel( font->chars[count-1], x, y ));
1441if( buff->ch.a )
1442{
1443buff->ch.r = (color & 0xFFFF0000) >> 16;
1444buff->ch.g = (color & 0xFF00FF00) >> 8;
1445buff->ch.b = (color & 0xFF0000FF);
1446}
1447}
1448}
1449}
1450}
1451
1452void makeRoundedCorners(pixmap_t *p)
1453{
1454int x,y;
1455int width=p->width-1;
1456int height=p->height-1;
1457
1458// 10px rounded corner alpha values
1459uint8_t roundedCorner[10][10] =
1460{
1461{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},
1462{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},
1463{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1464{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1465{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1466{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1467{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1468{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1469{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1470{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
1471};
1472
1473uint8_t alpha=0;
1474
1475for( y=0; y<10; y++)
1476{
1477for( x=0; x<10; x++)
1478{
1479// skip if the pixel should be visible
1480if(roundedCorner[y][x] != 0xFF)
1481{
1482alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
1483// Upper left corner
1484pixel(p, x, y).ch.a = alpha;
1485
1486// upper right corner
1487pixel(p, width-x,y).ch.a = alpha;
1488
1489// lower left corner
1490pixel(p, x, height-y).ch.a = alpha;
1491
1492// lower right corner
1493pixel(p, width-x, height-y).ch.a = alpha;
1494}
1495}
1496}
1497}
1498
1499void showInfoBox(char *title, char *text)
1500{
1501int i, key, lines, visiblelines;
1502
1503int currentline=0;
1504int cnt=0;
1505int offset=0;
1506
1507if( !title || !text )
1508return;
1509
1510position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );
1511
1512// calculate number of lines in the title
1513for ( i = 0, lines = 1; i<strlen(title); i++ )
1514if( title[i] == '\n')
1515lines++;
1516
1517// y position of text is lines in title * height of font
1518position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));
1519
1520// calculate number of lines in the text
1521for ( i=0, lines = 1; i<strlen(text); i++ )
1522if( text[i] == '\n')
1523lines++;
1524
1525// if text ends with \n strip off
1526if( text[i] == '\n' || text[i] == '\0')
1527lines--;
1528
1529visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
1530
1531// lets display the text and allow scroll thru using up down / arrows
1532while(1)
1533{
1534// move to current line in text
1535for( offset = 0, i = 0; offset < strlen(text); offset++ )
1536{
1537if( currentline == i)
1538break;
1539if( text[offset] =='\n')
1540i++;
1541}
1542
1543// find last visible line in text and place \0
1544for( i = offset, cnt = 0; i < strlen(text); i++)
1545{
1546if(text[i]=='\n')
1547cnt++;
1548if ( cnt == visiblelines )
1549{
1550text[i]='\0';
1551break;
1552}
1553}
1554
1555fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);
1556
1557makeRoundedCorners( gui.infobox.pixmap);
1558
1559// print the title if present
1560if( title )
1561drawStr(title, &font_console, gui.infobox.pixmap, pos_title);
1562
1563// print the text
1564drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);
1565
1566// restore \n in text
1567if ( cnt == visiblelines )
1568text[i] = '\n';
1569
1570position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
1571
1572// draw prev indicator
1573if(offset)
1574{
1575blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
1576}
1577
1578// draw next indicator
1579if( lines > ( currentline + visiblelines ) )
1580{
1581pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
1582blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
1583}
1584
1585gui.bootprompt.draw = false;
1586gui.infobox.draw = true;
1587gui.redraw = true;
1588
1589updateVRAM();
1590
1591key = getchar();
1592
1593if( key == kUpArrowkey )
1594if( currentline > 0 )
1595currentline--;
1596
1597if( key == kDownArrowkey )
1598if( lines > ( currentline + visiblelines ) )
1599currentline++;
1600
1601if( key == kEscapeKey || key == 'q' || key == 'Q')
1602{
1603gui.infobox.draw = false;
1604gui.redraw = true;
1605updateVRAM();
1606break;
1607}
1608}
1609}
1610
1611void animateProgressBar()
1612{
1613int y;
1614
1615if( time18() > lasttime)
1616{
1617lasttime = time18();
1618
1619pixmap_t *buffBar = images[iProgressBar].image;
1620
1621uint32_t buff = buffBar->pixels[0].value;
1622
1623memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );
1624
1625for( y = buffBar->height - 1; y > 0; y--)
1626pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);
1627
1628pixel(buffBar, buffBar->width-1, 0).value = buff;
1629}
1630}
1631
1632void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)
1633{
1634if(progress>100)
1635return;
1636
1637p.x = ( p.x - ( width / 2 ) );
1638
1639int todraw = (width * progress) / 100;
1640
1641pixmap_t *buff = images[iProgressBar].image;
1642pixmap_t *buffBG = images[iProgressBarBackground].image;
1643if(!buff || !buffBG)
1644return;
1645
1646pixmap_t progressbar;
1647progressbar.pixels=malloc(width * 4 * buff->height);
1648if(!progressbar.pixels)
1649return;
1650
1651progressbar.width = width;
1652progressbar.height = buff->height;
1653
1654int x=0,x2=0,y=0;
1655
1656for(y=0; y<buff->height; y++)
1657{
1658for(x=0; x<todraw; x++, x2++)
1659{
1660if(x2 == (buff->width-1)) x2=0;
1661pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;
1662}
1663x2=0;
1664}
1665
1666for(y=0; y<buff->height; y++)
1667{
1668for(x=todraw, x2 = 0; x < width - 1; x++, x2++)
1669{
1670if(x2 == (buffBG->width -2 )) x2 = 0;
1671pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;
1672}
1673if(progress < 100)
1674pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1675if(progress == 0)
1676pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1677x2=0;
1678}
1679
1680blend(&progressbar, blendInto, p);
1681animateProgressBar();
1682free(progressbar.pixels);
1683}
1684
1685void drawInfoMenuItems()
1686{
1687int i,n;
1688
1689position_t position;
1690
1691pixmap_t *selection = images[iMenuSelection].image;
1692
1693pixmap_t *pbuff;
1694
1695fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);
1696
1697makeRoundedCorners(gui.menu.pixmap);
1698
1699uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;
1700
1701position = pos(0,0);
1702
1703for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)
1704{
1705if (i == infoMenuSelection)
1706blend(selection, gui.menu.pixmap, position);
1707
1708pbuff = images[n].image;
1709if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)
1710blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
1711pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1712else
1713blend( pbuff, gui.menu.pixmap,
1714pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1715
1716drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap,
1717pos(position.x + (pbuff->width + gui.menu.hborder),
1718position.y + ((selection->height - font_console.height) / 2)));
1719position.y += images[iMenuSelection].image->height;
1720
1721}
1722
1723gui.redraw = true;
1724}
1725
1726int drawInfoMenu()
1727{
1728drawInfoMenuItems();
1729
1730gui.menu.draw = true;
1731
1732updateVRAM();
1733
1734return 1;
1735}
1736
1737int updateInfoMenu(int key)
1738{
1739switch (key)
1740{
1741
1742case kUpArrowkey:// up arrow
1743if (infoMenuSelection > 0)
1744{
1745if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)
1746infoMenuSelection -= 4;
1747
1748else
1749infoMenuSelection--;
1750drawInfoMenuItems();
1751updateVRAM();
1752
1753} else {
1754
1755gui.menu.draw = false;
1756gui.redraw = true;
1757
1758updateVRAM();
1759
1760return CLOSE_INFO_MENU;
1761}
1762break;
1763
1764case kDownArrowkey:// down arrow
1765if (infoMenuSelection < infoMenuItemsCount - 1)
1766{
1767if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
1768infoMenuSelection += 4;
1769else
1770infoMenuSelection++;
1771drawInfoMenuItems();
1772updateVRAM();
1773}
1774break;
1775
1776case kReturnKey:
1777key = 0;
1778if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )
1779showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
1780
1781else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )
1782showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
1783
1784else if( infoMenuSelection == MENU_SHOW_HELP )
1785showHelp();
1786
1787else
1788{
1789int buff = infoMenuSelection;
1790infoMenuSelection = 0;
1791return buff;
1792}
1793break;
1794}
1795return DO_NOT_BOOT;
1796}
1797
1798uint16_t bootImageWidth = 0;
1799uint16_t bootImageHeight = 0;
1800uint8_t *bootImageData = NULL;
1801static bool usePngImage = true;
1802
1803//==========================================================================
1804// loadBootGraphics
1805static void loadBootGraphics(void)
1806{
1807if (bootImageData != NULL) {
1808return;
1809}
1810
1811char dirspec[256];
1812
1813if ((strlen(theme_name) + 24) > sizeof(dirspec)) {
1814usePngImage = false;
1815return;
1816}
1817sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);
1818if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {
1819#ifdef CONFIG_EMBED_THEME
1820 if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
1821#endif
1822usePngImage = false;
1823}
1824}
1825
1826//==========================================================================
1827// drawBootGraphics
1828void drawBootGraphics(void)
1829{
1830int pos;
1831int length;
1832const char *dummyVal;
1833int oldScreenWidth, oldScreenHeight;
1834bool legacy_logo;
1835uint16_t x, y;
1836
1837if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->bootConfig) && legacy_logo) {
1838usePngImage = false;
1839} else if (bootImageData == NULL) {
1840loadBootGraphics();
1841}
1842
1843// Save current screen resolution.
1844oldScreenWidth = gui.screen.width;
1845oldScreenHeight = gui.screen.height;
1846//printf("Res: %dx%d (drawbg: current/old)\n", oldScreenWidth, oldScreenHeight);
1847
1848//Azi:autoresolution
1849if (gAutoResolution == true)
1850{
1851screen_params[0] = paramsAR[0];
1852screen_params[1] = paramsAR[1];
1853//printf("Res: %dx%d (drawbg: AR)\n", screen_params[0], screen_params[1]);
1854}
1855else
1856{
1857// parse boot screen size parameters
1858if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0)
1859{
1860screen_params[0] = pos;
1861}
1862else
1863{
1864screen_params[0] = DEFAULT_SCREEN_WIDTH;
1865}
1866
1867if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0)
1868{
1869screen_params[1] = pos;
1870}
1871else
1872{
1873screen_params[1] = DEFAULT_SCREEN_HEIGHT;
1874}
1875}
1876
1877gui.screen.width = screen_params[0];
1878gui.screen.height = screen_params[1];
1879//printf("Res: %dx%d (drawbg: gsw/h new)\n", gui.screen.width, gui.screen.height);
1880
1881// find best matching vesa mode for our requested width & height
1882getGraphicModeParams(screen_params);
1883
1884 // Set graphics mode if the booter was in text mode or the screen resolution has changed.
1885if (bootArgs->Video.v_display == VGA_TEXT_MODE
1886|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )
1887{
1888setVideoMode(GRAPHICS_MODE, 0);
1889}
1890
1891if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) {
1892drawCheckerBoard();
1893} else {
1894// Fill the background to 75% grey (same as BootX).
1895drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
1896}
1897if ((bootImageData) && (usePngImage)) {
1898x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
1899y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
1900
1901// Draw the image in the center of the display.
1902blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
1903} else {
1904uint8_t *appleBootPict;
1905bootImageData = NULL;
1906bootImageWidth = kAppleBootWidth;
1907bootImageHeight = kAppleBootHeight;
1908
1909// Prepare the data for the default Apple boot image.
1910appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
1911if (appleBootPict) {
1912convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
1913if (bootImageData) {
1914x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
1915y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
1916drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
1917free(bootImageData);
1918}
1919free(appleBootPict);
1920}
1921}
1922}
1923

Archive Download this file

Revision: 1055