Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 789