Chameleon

Chameleon Svn Source Tree

Root/branches/meklort/i386/modules/GUI/gui.c

Source at commit 521 created 13 years 7 months ago.
By meklort, Modules, Modules everywhere
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
16
17gui_t gui;// gui structure
18font_t font_small;
19font_t font_console;
20
21
22#define IMG_REQUIRED -1
23#define THEME_NAME_DEFAULT"Default"
24static const char *theme_name = THEME_NAME_DEFAULT;
25
26#ifdef EMBED_THEME
27#include "art.h"
28#endif
29
30#define LOADPNG(img, alt_img) if (loadThemeImage(#img, alt_img) != 0) { return 1; }
31
32#define MIN(x, y) ((x) < (y) ? (x) : (y))
33#define MAX(x, y) ((x) > (y) ? (x) : (y))
34
35#define VIDEO(x) (bootArgs->Video.v_ ## x)
36
37#define vram VIDEO(baseAddr)
38
39int lasttime = 0; // we need this for animating maybe
40
41extern int gDeviceCount;
42
43
44/*
45 * ATTENTION: the enum and the following array images[] MUST match !!!
46 */
47enum {
48 iBackground = 0,
49 iLogo,
50
51 iDeviceGeneric,
52 iDeviceGeneric_o,
53 iDeviceHFS,
54 iDeviceHFS_o,
55 iDeviceHFSRAID,
56 iDeviceHFSRAID_o,
57 iDeviceEXT3,
58 iDeviceEXT3_o,
59 iDeviceFAT,
60 iDeviceFAT_o,
61 iDeviceFAT16,
62 iDeviceFAT16_o,
63 iDeviceFAT32,
64 iDeviceFAT32_o,
65 iDeviceNTFS,
66 iDeviceNTFS_o,
67 iDeviceCDROM,
68 iDeviceCDROM_o,
69
70 iSelection,
71 iDeviceScrollPrev,
72 iDeviceScrollNext,
73
74 iMenuBoot,
75 iMenuVerbose,
76 iMenuIgnoreCaches,
77 iMenuSingleUser,
78 iMenuMemoryInfo,
79 iMenuVideoInfo,
80 iMenuHelp,
81 iMenuVerboseDisabled,
82 iMenuIgnoreCachesDisabled,
83 iMenuSingleUserDisabled,
84 iMenuSelection,
85
86 iProgressBar,
87 iProgressBarBackground,
88
89 iTextScrollPrev,
90 iTextScrollNext,
91
92 iFontConsole,
93 iFontSmall,
94};
95
96image_t images[] = {
97 {.name = "background", .image = NULL},
98 {.name = "logo", .image = NULL},
99
100 {.name = "device_generic", .image = NULL},
101 {.name = "device_generic_o", .image = NULL},
102 {.name = "device_hfsplus", .image = NULL},
103 {.name = "device_hfsplus_o", .image = NULL},
104 {.name = "device_hfsraid", .image = NULL},
105 {.name = "device_hfsraid_o", .image = NULL},
106 {.name = "device_ext3", .image = NULL},
107 {.name = "device_ext3_o", .image = NULL},
108 {.name = "device_fat", .image = NULL},
109 {.name = "device_fat_o", .image = NULL},
110 {.name = "device_fat16", .image = NULL},
111 {.name = "device_fat16_o", .image = NULL},
112 {.name = "device_fat32", .image = NULL},
113 {.name = "device_fat32_o", .image = NULL},
114 {.name = "device_ntfs", .image = NULL},
115 {.name = "device_ntfs_o", .image = NULL},
116 {.name = "device_cdrom", .image = NULL},
117 {.name = "device_cdrom_o", .image = NULL},
118
119 {.name = "device_selection", .image = NULL},
120 {.name = "device_scroll_prev", .image = NULL},
121 {.name = "device_scroll_next", .image = NULL},
122
123 {.name = "menu_boot", .image = NULL},
124 {.name = "menu_verbose", .image = NULL},
125 {.name = "menu_ignore_caches", .image = NULL},
126 {.name = "menu_single_user", .image = NULL},
127 {.name = "menu_memory_info", .image = NULL},
128 {.name = "menu_video_info", .image = NULL},
129 {.name = "menu_help", .image = NULL},
130 {.name = "menu_verbose_disabled", .image = NULL},
131 {.name = "menu_ignore_caches_disabled", .image = NULL},
132 {.name = "menu_single_user_disabled", .image = NULL},
133 {.name = "menu_selection", .image = NULL},
134
135 {.name = "progress_bar", .image = NULL},
136 {.name = "progress_bar_background", .image = NULL},
137
138 {.name = "text_scroll_prev", .image = NULL},
139 {.name = "text_scroll_next", .image = NULL},
140
141 {.name = "font_console", .image = NULL},
142 {.name = "font_small", .image = NULL},
143};
144
145int imageCnt = 0;
146
147extern intgDeviceCount;
148extern intselectIndex;
149
150char prompt[BOOT_STRING_LEN];
151
152int prompt_pos=0;
153
154char prompt_text[] = "boot: ";
155
156menuitem_t infoMenuItems[] =
157{
158{ .text = "Boot" },
159{ .text = "Boot Verbose" },
160{ .text = "Boot Ignore Caches" },
161{ .text = "Boot Single User" },
162{ .text = "Memory Info" },
163{ .text = "Video Info" },
164{ .text = "Help" }
165};
166
167int initFont(font_t *font, image_t *image);
168void colorFont(font_t *font, uint32_t color);
169void makeRoundedCorners(pixmap_t *p);
170
171static int infoMenuSelection = 0;
172static int infoMenuItemsCount = sizeof(infoMenuItems)/sizeof(infoMenuItems[0]);
173
174static bool infoMenuNativeBoot = false;
175
176static unsigned long screen_params[4] = {DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 32, 0};// here we store the used screen resolution
177
178static int getImageIndexByName(const char *name)
179{
180 int i;
181for (i = 0; i < sizeof(images) / sizeof(images[0]); i++)
182{
183 if (strcmp(name, images[i].name) == 0)
184 return i; // found the name
185}
186return -1;
187}
188
189#ifdef EMBED_THEME
190static int getEmbeddedImageIndexByName(const char *name)
191{
192int upperLimit = sizeof(embeddedImages) / sizeof(embeddedImages[0]) - 1;
193int lowerLimit = 0;
194int compareIndex = (upperLimit - lowerLimit) >> 1; // Midpoint
195int result;
196
197// NOTE: This algorithm assumes that the embeddedImages is sorted.
198// This is currently done using the make file. If the array is every
199// manualy generated, this *will* fail to work properly.
200while((result = strcmp(name, embeddedImages[compareIndex].name)) != 0)
201{
202if(result > 0)// We need to search a HIGHER index
203{
204if(compareIndex != lowerLimit)
205{
206lowerLimit = compareIndex;
207}
208else
209{
210return -1;
211}
212compareIndex = (upperLimit + lowerLimit + 1) >> 1;// Midpoint, round up
213}
214else // We Need to search a LOWER index
215{
216if(compareIndex != upperLimit)
217{
218upperLimit = compareIndex;
219}
220else
221{
222return -1;
223}
224compareIndex = (upperLimit + lowerLimit) >> 1;// Midpoint, round down
225}
226}
227return compareIndex;
228}
229#endif
230
231static int loadThemeImage(const char *image, int alt_image)
232{
233chardirspec[256];
234int i;
235#ifdef EMBED_THEME
236int e;
237#endif
238uint16_twidth;
239uint16_theight;
240uint8_t*imagedata;
241
242if ((strlen(image) + strlen(theme_name) + 20 ) > sizeof(dirspec)) {
243return 1;
244}
245
246 if ((i = getImageIndexByName(image)) >= 0)
247 {
248 if (images[i].image == NULL) {
249 images[i].image = malloc(sizeof(pixmap_t));
250 }
251 sprintf(dirspec, "/Extra/Themes/%s/%s.png", theme_name, image);
252 width = 0;
253 height = 0;
254 imagedata = NULL;
255 if ((loadPngImage(dirspec, &width, &height, &imagedata)) == 0)
256 {
257 images[i].image->width = width;
258 images[i].image->height = height;
259 images[i].image->pixels = (pixel_t *)imagedata;
260 flipRB(images[i].image);
261 return 0;
262 }
263#ifdef EMBED_THEME
264 else if ((e = getEmbeddedImageIndexByName(image)) >= 0)
265 {
266 unsigned char *embed_data;
267 unsigned int embed_size;
268 embed_data = embeddedImages[e].pngdata;
269 embed_size = *embeddedImages[e].length;
270
271 if (loadEmbeddedPngImage(embed_data, embed_size, &width, &height, &imagedata) == 0)
272 {
273 images[i].image->width = width;
274 images[i].image->height = height;
275 images[i].image->pixels = (pixel_t *)imagedata;
276 flipRB(images[i].image);
277 return 0;
278 }
279
280 return 0;
281 }
282#endif
283 else if (alt_image != IMG_REQUIRED && images[alt_image].image->pixels != NULL)
284 {
285 // Using the passed alternate image for non-mandatory images.
286 // We don't clone the already existing pixmap, but using its properties instead!
287 images[i].image->width = images[alt_image].image->width;
288 images[i].image->height = images[alt_image].image->height;
289 images[i].image->pixels = images[alt_image].image->pixels;
290 return 0;
291 }
292 else
293 {
294#ifndef EMBED_THEME
295 printf("ERROR: GUI: could not open '%s/%s.png'!\n", theme_name, image);
296sleep(2);
297#endif
298 return 1;
299 }
300 }
301return 1;
302}
303
304static int loadGraphics(void)
305{
306LOADPNG(background, IMG_REQUIRED);
307LOADPNG(logo, IMG_REQUIRED);
308
309LOADPNG(device_generic, IMG_REQUIRED);
310LOADPNG(device_generic_o, iDeviceGeneric);
311LOADPNG(device_hfsplus, iDeviceGeneric);
312LOADPNG(device_hfsplus_o, iDeviceHFS);
313LOADPNG(device_hfsraid, iDeviceGeneric);
314LOADPNG(device_hfsraid_o, iDeviceHFSRAID);
315LOADPNG(device_ext3, iDeviceGeneric);
316LOADPNG(device_ext3_o, iDeviceEXT3);
317LOADPNG(device_fat, iDeviceGeneric);
318LOADPNG(device_fat_o, iDeviceFAT);
319LOADPNG(device_fat16, iDeviceFAT);
320LOADPNG(device_fat16_o, iDeviceFAT_o);
321LOADPNG(device_fat32, iDeviceFAT);
322LOADPNG(device_fat32_o, iDeviceFAT_o);
323LOADPNG(device_ntfs, iDeviceGeneric);
324LOADPNG(device_ntfs_o, iDeviceNTFS);
325LOADPNG(device_cdrom, iDeviceGeneric);
326LOADPNG(device_cdrom_o, iDeviceCDROM);
327
328LOADPNG(device_selection, IMG_REQUIRED);
329LOADPNG(device_scroll_prev, IMG_REQUIRED);
330LOADPNG(device_scroll_next, IMG_REQUIRED);
331
332LOADPNG(menu_boot, IMG_REQUIRED);
333LOADPNG(menu_verbose, IMG_REQUIRED);
334LOADPNG(menu_ignore_caches, IMG_REQUIRED);
335LOADPNG(menu_single_user, IMG_REQUIRED);
336LOADPNG(menu_memory_info, IMG_REQUIRED);
337LOADPNG(menu_video_info, IMG_REQUIRED);
338LOADPNG(menu_help, IMG_REQUIRED);
339LOADPNG(menu_verbose_disabled, IMG_REQUIRED);
340LOADPNG(menu_ignore_caches_disabled, IMG_REQUIRED);
341LOADPNG(menu_single_user_disabled, IMG_REQUIRED);
342LOADPNG(menu_selection, IMG_REQUIRED);
343
344LOADPNG(progress_bar, IMG_REQUIRED);
345LOADPNG(progress_bar_background, IMG_REQUIRED);
346
347LOADPNG(text_scroll_prev, IMG_REQUIRED);
348LOADPNG(text_scroll_next, IMG_REQUIRED);
349
350LOADPNG(font_console, IMG_REQUIRED);
351LOADPNG(font_small, IMG_REQUIRED);
352
353initFont( &font_console, &images[iFontConsole]);
354initFont( &font_small, &images[iFontSmall]);
355
356return 0;
357}
358
359pixmap_t *getCroppedPixmapAtPosition( pixmap_t *from, position_t pos, uint16_t width, uint16_t height )
360{
361
362pixmap_t *cropped = malloc( sizeof( pixmap_t ) );
363if( !cropped )
364return 0;
365cropped->pixels = malloc( width * height * 4 );
366if ( !cropped->pixels )
367return 0;
368
369cropped->width = width;
370cropped->height = height;
371
372int destx = 0, desty = 0;
373int srcx = pos.x, srcy = pos.y;
374
375for( ; desty < height; desty++, srcy++)
376{
377for( destx = 0, srcx = pos.x; destx < width; destx++, srcx++ )
378{
379pixel( cropped, destx, desty ).value = pixel( from, srcx, srcy ).value;
380}
381}
382return cropped;
383}
384
385int createBackBuffer( window_t *window )
386{
387gui.backbuffer = malloc(sizeof(pixmap_t));
388if(!gui.backbuffer)
389return 1;
390
391gui.backbuffer->pixels = malloc( window->width * window->height * 4 );
392if(!gui.backbuffer->pixels)
393{
394free(gui.backbuffer);
395gui.backbuffer = 0;
396return 1;
397}
398
399gui.backbuffer->width = gui.screen.width;
400gui.backbuffer->height = gui.screen.height;
401
402return 0;
403}
404
405int createWindowBuffer( window_t *window )
406{
407window->pixmap = malloc(sizeof(pixmap_t));
408if(!window->pixmap)
409return 1;
410
411window->pixmap->pixels = malloc( window->width * window->height * 4 );
412if(!window->pixmap->pixels)
413{
414free(window->pixmap);
415window->pixmap = 0;
416return 1;
417}
418
419window->pixmap->width = window->width;
420window->pixmap->height = window->height;
421
422return 0;
423}
424
425int freeWindowBuffer( window_t *window )
426{
427if (window->pixmap && window->pixmap->pixels)
428 {
429free(window->pixmap->pixels);
430free(window->pixmap);
431return 0;
432}
433
434return 1;
435}
436
437void fillPixmapWithColor(pixmap_t *pm, uint32_t color)
438{
439int x,y;
440
441// fill with given color AARRGGBB
442for( x=0; x < pm->width; x++ )
443for( y=0; y< pm->height; y++)
444pixel(pm,x,y).value = color;
445}
446
447void drawBackground()
448{
449// reset text cursor
450gui.screen.cursor.x = gui.screen.hborder;
451gui.screen.cursor.y = gui.screen.vborder;
452
453fillPixmapWithColor( gui.screen.pixmap, gui.screen.bgcolor);
454
455// draw background.png into background buffer
456blend( images[iBackground].image, gui.screen.pixmap, gui.background.pos );
457
458// draw logo.png into background buffer
459if (gui.logo.draw)
460{
461 blend( images[iLogo].image, gui.screen.pixmap, gui.logo.pos);
462}
463
464memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
465}
466
467void setupDeviceList(config_file_t *theme)
468{
469unsigned int pixel;
470intalpha;// transparency level 0 (obligue) - 255 (transparent)
471uint32_t color;// color value formatted RRGGBB
472int val, len;
473const char *string;
474
475if(getIntForKey("devices_max_visible", &val, theme ))
476gui.maxdevices = MIN( val, gDeviceCount );
477
478if(getIntForKey("devices_iconspacing", &val, theme ))
479gui.devicelist.iconspacing = val;
480
481// check layout for horizontal or vertical
482gui.layout = HorizontalLayout;
483if(getValueForKey( "devices_layout", &string, &len, theme)) {
484if (!strcmp (string, "vertical")) {
485gui.layout = VerticalLayout;
486}
487}
488
489switch (gui.layout) {
490case VerticalLayout:
491gui.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);
492gui.devicelist.width = (images[iSelection].image->width + gui.devicelist.iconspacing);
493
494if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , images[iSelection].image->width ) )
495gui.devicelist.pos.x = pixel;
496
497if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , gui.devicelist.height ) )
498gui.devicelist.pos.y = pixel;
499break;
500
501case HorizontalLayout:
502default:
503gui.devicelist.width = ((images[iSelection].image->width + gui.devicelist.iconspacing) * MIN(gui.maxdevices, gDeviceCount) + (images[iDeviceScrollPrev].image->width + images[iDeviceScrollNext].image->width) + gui.devicelist.iconspacing);
504gui.devicelist.height = (images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing);
505
506if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , gui.devicelist.width ) )
507gui.devicelist.pos.x = pixel;
508else
509gui.devicelist.pos.x = ( gui.screen.width - gui.devicelist.width ) / 2;
510
511if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , images[iSelection].image->height ) )
512gui.devicelist.pos.y = pixel;
513else
514gui.devicelist.pos.y = ( gui.screen.height - gui.devicelist.height ) / 2;
515break;
516}
517
518if(getColorForKey("devices_bgcolor", &color, theme))
519gui.devicelist.bgcolor = (color & 0x00FFFFFF);
520
521if(getIntForKey("devices_transparency", &alpha, theme))
522gui.devicelist.bgcolor = gui.devicelist.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
523
524if (gui.devicelist.pixmap)
525{
526 freeWindowBuffer(&gui.devicelist);
527 createWindowBuffer(&gui.devicelist);
528 }
529}
530
531void loadThemeValues(config_file_t *theme)
532{
533unsigned int screen_width = gui.screen.width;
534unsigned int screen_height = gui.screen.height;
535unsigned int pixel;
536intalpha;// transparency level 0 (obligue) - 255 (transparent)
537uint32_t color;// color value formatted RRGGBB
538int val;
539
540/*
541 * Parse screen parameters
542 */
543if(getColorForKey("screen_bgcolor", &color, theme ))
544gui.screen.bgcolor = (color & 0x00FFFFFF);
545
546if(getIntForKey("screen_textmargin_h", &val, theme))
547gui.screen.hborder = MIN( gui.screen.width , val );
548
549if(getIntForKey("screen_textmargin_v", &val, theme))
550gui.screen.vborder = MIN( gui.screen.height , val );
551
552/*
553 * Parse background parameters
554 */
555if(getDimensionForKey("background_pos_x", &pixel, theme, screen_width , images[iBackground].image->width ) )
556gui.background.pos.x = pixel;
557
558if(getDimensionForKey("background_pos_y", &pixel, theme, screen_height , images[iBackground].image->height ) )
559gui.background.pos.y = pixel;
560
561/*
562 * Parse logo parameters
563 */
564if(getDimensionForKey("logo_pos_x", &pixel, theme, screen_width , images[iLogo].image->width ) )
565gui.logo.pos.x = pixel;
566
567if(getDimensionForKey("logo_pos_y", &pixel, theme, screen_height , images[iLogo].image->height ) )
568gui.logo.pos.y = pixel;
569
570/*
571 * Parse progress bar parameters
572 */
573if(getDimensionForKey("progressbar_pos_x", &pixel, theme, screen_width , 0 ) )
574gui.progressbar.pos.x = pixel;
575
576if(getDimensionForKey("progressbar_pos_y", &pixel, theme, screen_height , 0 ) )
577gui.progressbar.pos.y = pixel;
578
579/*
580 * Parse countdown text parameters
581 */
582if(getDimensionForKey("countdown_pos_x", &pixel, theme, screen_width , 0 ) )
583gui.countdown.pos.x = pixel;
584
585if(getDimensionForKey("countdown_pos_y", &pixel, theme, screen_height , 0 ) )
586gui.countdown.pos.y = pixel;
587
588 /*
589 * Parse devicelist parameters
590 */
591setupDeviceList(theme);
592
593/*
594 * Parse infobox parameters
595 */
596if(getIntForKey("infobox_width", &val, theme))
597gui.infobox.width = MIN( screen_width , val );
598
599if(getIntForKey("infobox_height", &val, theme))
600gui.infobox.height = MIN( screen_height , val );
601
602if(getDimensionForKey("infobox_pos_x", &pixel, theme, screen_width , gui.infobox.width ) )
603gui.infobox.pos.x = pixel;
604
605if(getDimensionForKey("infobox_pos_y", &pixel, theme, screen_height , gui.infobox.height ) )
606gui.infobox.pos.y = pixel;
607
608if(getIntForKey("infobox_textmargin_h", &val, theme))
609gui.infobox.hborder = MIN( gui.infobox.width , val );
610
611if(getIntForKey("infobox_textmargin_v", &val, theme))
612gui.infobox.vborder = MIN( gui.infobox.height , val );
613
614if(getColorForKey("infobox_bgcolor", &color, theme))
615gui.infobox.bgcolor = (color & 0x00FFFFFF);
616
617if(getIntForKey("infobox_transparency", &alpha, theme))
618gui.infobox.bgcolor = gui.infobox.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
619
620/*
621 * Parse menu parameters
622 */
623if(getDimensionForKey("menu_width", &pixel, theme, gui.screen.width , 0 ) )
624gui.menu.width = pixel;
625else
626gui.menu.width = images[iMenuSelection].image->width;
627
628if(getDimensionForKey("menu_height", &pixel, theme, gui.screen.height , 0 ) )
629gui.menu.height = pixel;
630else
631gui.menu.height = (infoMenuItemsCount) * images[iMenuSelection].image->height;
632
633if(getDimensionForKey("menu_pos_x", &pixel, theme, screen_width , gui.menu.width ) )
634gui.menu.pos.x = pixel;
635
636if(getDimensionForKey("menu_pos_y", &pixel, theme, screen_height , gui.menu.height ) )
637gui.menu.pos.y = pixel;
638
639if(getIntForKey("menu_textmargin_h", &val, theme))
640gui.menu.hborder = MIN( gui.menu.width , val );
641
642if(getIntForKey("menu_textmargin_v", &val, theme))
643gui.menu.vborder = MIN( gui.menu.height , val );
644
645if(getColorForKey("menu_bgcolor", &color, theme))
646gui.menu.bgcolor = (color & 0x00FFFFFF);
647
648if(getIntForKey("menu_transparency", &alpha, theme))
649gui.menu.bgcolor = gui.menu.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
650
651/*
652 * Parse bootprompt parameters
653 */
654if(getDimensionForKey("bootprompt_width", &pixel, theme, screen_width , 0 ) )
655gui.bootprompt.width = pixel;
656
657if(getIntForKey("bootprompt_height", &val, theme))
658gui.bootprompt.height = MIN( screen_height , val );
659
660if(getDimensionForKey("bootprompt_pos_x", &pixel, theme, screen_width , gui.bootprompt.width ) )
661gui.bootprompt.pos.x = pixel;
662
663if(getDimensionForKey("bootprompt_pos_y", &pixel, theme, screen_height , gui.bootprompt.height ) )
664gui.bootprompt.pos.y = pixel;
665
666if(getIntForKey("bootprompt_textmargin_h", &val, theme))
667gui.bootprompt.hborder = MIN( gui.bootprompt.width , val );
668
669if(getIntForKey("bootprompt_textmargin_v", &val, theme))
670gui.bootprompt.vborder = MIN( gui.bootprompt.height , val );
671
672if(getColorForKey("bootprompt_bgcolor", &color, theme))
673gui.bootprompt.bgcolor = (color & 0x00FFFFFF);
674
675if(getIntForKey("bootprompt_transparency", &alpha, theme))
676gui.bootprompt.bgcolor = gui.bootprompt.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
677
678if(getColorForKey("font_small_color", &color, theme))
679gui.screen.font_small_color = (color & 0x00FFFFFF);
680
681if(getColorForKey("font_console_color", &color, theme))
682gui.screen.font_console_color = (color & 0x00FFFFFF);
683}
684
685int initGUI(void)
686{
687//intval;
688intlen;
689chardirspec[256];
690
691getValueForKey( "Theme", &theme_name, &len, &bootInfo->bootConfig );
692if ((strlen(theme_name) + 27) > sizeof(dirspec)) {
693return 1;
694}
695sprintf(dirspec, "/Extra/Themes/%s/theme.plist", theme_name);
696if (loadConfigFile(dirspec, &bootInfo->themeConfig) != 0) {
697#ifdef EMBED_THEME
698config_file_t*config;
699
700config = &bootInfo->themeConfig;
701if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) {
702return 1;
703}
704#else
705return 1;
706#endif
707}
708/*
709 // parse display size parameters
710 if (getIntForKey("screen_width", &val, &bootInfo->themeConfig) && val > 0) {
711 screen_params[0] = val;
712 }
713 if (getIntForKey("screen_height", &val, &bootInfo->themeConfig) && val > 0) {
714 screen_params[1] = val;
715 }
716 */
717void(*res)(UInt32*, UInt32*, UInt32*) = (void*)lookup_all_symbols("_getResolution");
718if(res && res != (void*)0xFFFFFFFF) res(&screen_params[0], &screen_params[1], &screen_params[2]);
719
720
721
722// Initalizing GUI strucutre.
723bzero(&gui, sizeof(gui_t));
724
725// find best matching vesa mode for our requested width & height
726getGraphicModeParams(screen_params);
727
728// set our screen structure with the mode width & height
729gui.screen.width = screen_params[0];
730gui.screen.height = screen_params[1];
731
732// load graphics otherwise fail and return
733if (loadGraphics() == 0) {
734loadThemeValues(&bootInfo->themeConfig);
735colorFont(&font_small, gui.screen.font_small_color);
736colorFont(&font_console, gui.screen.font_console_color);
737
738// create the screen & window buffers
739if (createBackBuffer(&gui.screen) == 0)
740{
741if (createWindowBuffer(&gui.screen) == 0)
742{
743if (createWindowBuffer(&gui.devicelist) == 0)
744{
745if (createWindowBuffer(&gui.bootprompt) == 0)
746{
747if (createWindowBuffer(&gui.infobox) == 0)
748{
749if (createWindowBuffer(&gui.menu) == 0)
750{
751 gui.logo.draw = true;
752drawBackground();
753// lets copy the screen into the back buffer
754memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
755setVideoMode( GRAPHICS_MODE, 0 );
756gui.initialised = true;
757return 0;
758}
759}
760}
761}
762}
763}
764}
765return 1;
766}
767
768void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected)
769{
770int devicetype;
771
772if( diskIsCDROM(device) )
773devicetype = iDeviceCDROM;// Use CDROM icon
774else
775{
776switch (device->part_type)
777{
778case kPartitionTypeHFS:
779
780// Use HFS or HFSRAID icon depending on bvr flags.
781devicetype = (device->flags & kBVFlagBooter) ? iDeviceHFSRAID : iDeviceHFS;
782break;
783
784case kPartitionTypeHPFS:
785devicetype = iDeviceNTFS;// Use HPFS / NTFS icon
786break;
787
788case kPartitionTypeFAT16:
789devicetype = iDeviceFAT16;// Use FAT16 icon
790break;
791
792case kPartitionTypeFAT32:
793devicetype = iDeviceFAT32;// Use FAT32 icon
794break;
795
796case kPartitionTypeEXT3:
797devicetype = iDeviceEXT3;// Use EXT2/3 icon
798break;
799
800default:
801devicetype = iDeviceGeneric;// Use Generic icon
802break;
803}
804}
805
806// Draw the selection image and use the next (device_*_o) image for the selected item.
807 if (isSelected)
808{
809blend(images[iSelection].image, buffer, centeredAt(images[iSelection].image, p));
810devicetype++;
811}
812
813// draw icon
814blend( images[devicetype].image, buffer, centeredAt( images[devicetype].image, p ));
815
816p.y += (images[iSelection].image->height / 2) + font_console.chars[0]->height;
817
818// draw volume label
819drawStrCenteredAt( device->label, &font_small, buffer, p);
820
821}
822
823void drawDeviceList (int start, int end, int selection)
824{
825int i;
826position_t p, p_prev, p_next;
827
828//uint8_tmaxDevices = MIN( gui.maxdevices, menucount );
829
830fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);
831
832makeRoundedCorners( gui.devicelist.pixmap);
833
834switch (gui.layout)
835{
836
837case VerticalLayout:
838p.x = (gui.devicelist.width /2);
839p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );
840
841// place scroll indicators at top & bottom edges
842p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );
843p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );
844
845break;
846
847default:// use Horizontal layout as the default
848
849case HorizontalLayout:
850p.x = (gui.devicelist.width - ( gui.devicelist.width / gui.maxdevices ) * gui.maxdevices ) / 2 + ( images[iSelection].image->width / 2) + images[iDeviceScrollPrev].image->width + gui.devicelist.iconspacing;
851p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );
852
853// place scroll indicators at left & right edges
854p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );
855p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );
856
857break;
858
859}
860
861// draw visible device icons
862for (i = 0; i < gui.maxdevices; i++)
863{
864BVRef param = menuItems[start + i].param;
865
866 bool isSelected = ((start + i) == selection) ? true : false;
867if (isSelected)
868{
869 if (param->flags & kBVFlagNativeBoot)
870 {
871 infoMenuNativeBoot = true;
872 }
873 else
874 {
875 infoMenuNativeBoot = false;
876 if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)
877infoMenuSelection = 0;
878 }
879
880if(gui.menu.draw)
881drawInfoMenuItems();
882
883#if DEBUG
884 gui.debug.cursor = pos( 10, 100);
885 dprintf( &gui.screen, "label %s\n", param->label );
886 dprintf( &gui.screen, "biosdev 0x%x\n", param->biosdev );
887 dprintf(&gui.screen, "width %d\n", gui.screen.width);
888 dprintf(&gui.screen, "height %d\n", gui.screen.height);
889 dprintf( &gui.screen, "type 0x%x\n", param->type );
890 dprintf( &gui.screen, "flags 0x%x\n", param->flags );
891 dprintf( &gui.screen, "part_no %d\n", param->part_no );
892 dprintf( &gui.screen, "part_boff 0x%x\n", param->part_boff );
893 dprintf( &gui.screen, "part_type 0x%x\n", param->part_type );
894 dprintf( &gui.screen, "bps 0x%x\n", param->bps );
895 dprintf( &gui.screen, "name %s\n", param->name );
896 dprintf( &gui.screen, "type_name %s\n", param->type_name );
897 dprintf( &gui.screen, "modtime %d\n", param->modTime );
898#endif
899}
900
901drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);
902
903if (gui.layout == HorizontalLayout)
904{
905p.x += images[iSelection].image->width + gui.devicelist.iconspacing;
906}
907if (gui.layout == VerticalLayout)
908{
909p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing );
910}
911}
912
913// draw prev indicator
914if(start)
915blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );
916
917// draw next indicator
918if( end < gDeviceCount - 1 )
919blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );
920
921gui.redraw = true;
922
923updateVRAM();
924
925}
926
927void clearGraphicBootPrompt()
928{
929// clear text buffer
930prompt[0] = '\0';
931prompt_pos=0;
932
933
934if(gui.bootprompt.draw == true )
935{
936gui.bootprompt.draw = false;
937gui.redraw = true;
938// this causes extra frames to be drawn
939//updateVRAM();
940}
941
942return;
943}
944
945void updateGraphicBootPrompt(int key)
946{
947if ( key == kBackspaceKey )
948prompt[--prompt_pos] = '\0';
949else
950{
951prompt[prompt_pos] = key;
952prompt_pos++;
953prompt[prompt_pos] = '\0';
954}
955
956fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);
957
958makeRoundedCorners( gui.bootprompt.pixmap);
959
960position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );
961
962// print the boot prompt text
963drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);
964
965// get the position of the end of the boot prompt text to display user input
966position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );
967
968// calculate the position of the cursor
969intoffset = ( prompt_pos - ( ( gui.bootprompt.width / font_console.chars[0]->width ) - strlen(prompt_text) - 2 ) );
970
971if ( offset < 0)
972offset = 0;
973
974drawStr( prompt+offset, &font_console, gui.bootprompt.pixmap, p_prompt);
975
976gui.menu.draw = false;
977gui.bootprompt.draw = true;
978gui.redraw = true;
979
980updateVRAM();
981
982return;
983}
984
985inline
986void vramwrite (void *data, int width, int height)
987{
988if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)
989memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
990else
991{
992uint32_t r, g, b;
993int i, j;
994for (i = 0; i < VIDEO (height); i++)
995for (j = 0; j < VIDEO (width); j++)
996{
997b = ((uint8_t *) data)[4*i*width + 4*j];
998g = ((uint8_t *) data)[4*i*width + 4*j + 1];
999r = ((uint8_t *) data)[4*i*width + 4*j + 2];
1000switch (VIDEO (depth))
1001{
1002case 32:
1003*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1004break;
1005case 24:
1006*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)
1007| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1008break;
1009case 16:
1010// Somehow 16-bit is always 15-bits really
1011//*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);
1012//break;
1013case 15:
1014*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);
1015break;
1016}
1017}
1018}
1019}
1020
1021void updateVRAM()
1022{
1023if (gui.redraw)
1024{
1025if (gui.devicelist.draw)
1026blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
1027
1028if (gui.bootprompt.draw)
1029blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
1030
1031if (gui.menu.draw)
1032blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
1033
1034if (gui.infobox.draw)
1035blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
1036}
1037
1038vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
1039
1040if (gui.redraw)
1041{
1042memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
1043gui.redraw = false;
1044}
1045}
1046
1047struct putc_info {
1048 char * str;
1049 char * last_str;
1050};
1051
1052static void
1053sputc(int c, struct putc_info * pi)
1054{
1055 if (pi->last_str)
1056 if (pi->str == pi->last_str) {
1057 *(pi->str) = '\0';
1058 return;
1059 }
1060 *(pi->str)++ = 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 = getc();
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,
1716 pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1717else
1718blend( pbuff, gui.menu.pixmap,
1719 pos((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 EMBED_THEME
1825if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
1826#endif
1827usePngImage = false;
1828}
1829}
1830
1831//==========================================================================
1832// drawBootGraphics
1833void drawBootGraphics(void)
1834{
1835//int 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/*
1849 // parse screen size parameters
1850 if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0) {
1851 screen_params[0] = pos;
1852 } else {
1853 screen_params[0] = DEFAULT_SCREEN_WIDTH;
1854 }
1855 if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0) {
1856 screen_params[1] = pos;
1857 } else {
1858 screen_params[1] = DEFAULT_SCREEN_HEIGHT;
1859 }
1860 */
1861
1862void(*res)(UInt32*, UInt32*, UInt32*) = (void*)lookup_all_symbols("_getResolution");
1863if(res && res != (void*)0xFFFFFFFF) res(&screen_params[0], &screen_params[1], &screen_params[2]);
1864
1865 // Save current screen resolution.
1866oldScreenWidth = gui.screen.width;
1867oldScreenHeight = gui.screen.height;
1868
1869gui.screen.width = screen_params[0];
1870gui.screen.height = screen_params[1];
1871
1872// find best matching vesa mode for our requested width & height
1873getGraphicModeParams(screen_params);
1874
1875 // Set graphics mode if the booter was in text mode or the screen resolution has changed.
1876if (bootArgs->Video.v_display == VGA_TEXT_MODE
1877|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )
1878{
1879setVideoMode(GRAPHICS_MODE, 0);
1880}
1881
1882if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) {
1883drawCheckerBoard();
1884} else {
1885// Fill the background to 75% grey (same as BootX).
1886drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
1887}
1888if ((bootImageData) && (usePngImage)) {
1889x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
1890y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
1891
1892// Draw the image in the center of the display.
1893blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
1894} else {
1895uint8_t *appleBootPict;
1896bootImageData = NULL;
1897bootImageWidth = kAppleBootWidth;
1898bootImageHeight = kAppleBootHeight;
1899
1900// Prepare the data for the default Apple boot image.
1901appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
1902if (appleBootPict) {
1903convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
1904if (bootImageData) {
1905x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
1906y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
1907drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
1908free(bootImageData);
1909}
1910free(appleBootPict);
1911}
1912}
1913}
1914
1915int GUI_initGraphicsMode ()
1916{
1917unsigned long params[4];
1918int count;
1919
1920params[3] = 0;
1921count = getNumberArrayFromProperty( kGraphicsModeKey, params, 4 );
1922
1923// Try to find a resolution if "Graphics Mode" setting is not available.
1924if ( count < 3 )
1925{
1926// Use the default resolution if we don't have an initialized GUI.
1927if (gui.screen.width == 0 || gui.screen.height == 0)
1928{
1929gui.screen.width = DEFAULT_SCREEN_WIDTH;
1930gui.screen.height = DEFAULT_SCREEN_HEIGHT;
1931}
1932
1933params[0] = gui.screen.width;
1934params[1] = gui.screen.height;
1935params[2] = 32;
1936}
1937
1938// Map from pixel format to bits per pixel.
1939
1940if ( params[2] == 256 ) params[2] = 8;
1941if ( params[2] == 555 ) params[2] = 16;
1942if ( params[2] == 888 ) params[2] = 32;
1943
1944return setVESAGraphicsMode( params[0], params[1], params[2], params[3] );
1945}
1946
1947
1948int GUI_countdown( const char * msg, int row, int timeout )
1949{
1950 unsigned long time;
1951 int ch = 0;
1952 int col = strlen(msg) + 1;
1953
1954 flushKeyboardBuffer();
1955
1956if( bootArgs->Video.v_display == VGA_TEXT_MODE )
1957{
1958moveCursor( 0, row );
1959printf(msg);
1960
1961} else {
1962
1963position_t p = pos( gui.screen.width / 2 + 1 , ( gui.devicelist.pos.y + 3 ) + ( ( gui.devicelist.height - gui.devicelist.iconspacing ) / 2 ) );
1964
1965char dummy[80];
1966getBootVolumeDescription( gBootVolume, dummy, sizeof(dummy) - 1, true );
1967drawDeviceIcon( gBootVolume, gui.screen.pixmap, p, true );
1968drawStrCenteredAt( (char *) msg, &font_small, gui.screen.pixmap, gui.countdown.pos );
1969
1970// make this screen the new background
1971memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
1972
1973}
1974
1975int multi_buff = 18 * (timeout);
1976 int multi = ++multi_buff;
1977
1978 int lasttime=0;
1979
1980 for ( time = time18(), timeout++; timeout > 0; )
1981 {
1982if( time18() > lasttime)
1983{
1984multi--;
1985lasttime=time18();
1986}
1987
1988 if (ch = readKeyboardStatus())
1989 break;
1990
1991 // Count can be interrupted by holding down shift,
1992 // control or alt key
1993 if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 )
1994{
1995 ch = 1;
1996 break;
1997 }
1998
1999 if ( time18() >= time )
2000 {
2001 time += 18;
2002 timeout--;
2003
2004if( bootArgs->Video.v_display == VGA_TEXT_MODE )
2005{
2006moveCursor( col, row );
2007printf("(%d) ", timeout);
2008}
2009 }
2010
2011if( bootArgs->Video.v_display == GRAPHICS_MODE )
2012{
2013drawProgressBar( gui.screen.pixmap, 100, gui.progressbar.pos , ( multi * 100 / multi_buff ) );
2014gui.redraw = true;
2015updateVRAM();
2016}
2017
2018 }
2019
2020 flushKeyboardBuffer();
2021
2022 return ch;
2023}
2024
2025

Archive Download this file

Revision: 521