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

Archive Download this file

Revision: 1039