Chameleon Applications

Chameleon Applications Svn Source Tree

Root/branches/iFabio/Chameleon/i386/boot2/gui.c

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

Archive Download this file

Revision: 296