Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 749