Chameleon Applications

Chameleon Applications Svn Source Tree

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

Source at commit 310 created 12 years 10 months ago.
By ifabio, Some update and directory changes.
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
157//char prompt[BOOT_STRING_LEN];
158extern char gBootArgs[BOOT_STRING_LEN];
159
160char prompt_text[] = "boot: ";
161
162menuitem_t infoMenuItems[] =
163{
164{ .text = "Boot" },
165{ .text = "Boot Verbose" },
166{ .text = "Boot Ignore Caches" },
167{ .text = "Boot Single User" },
168{ .text = "Memory Info" },
169{ .text = "Video Info" },
170{ .text = "Help" }
171};
172
173int initFont(font_t *font, image_t *image);
174void colorFont(font_t *font, uint32_t color);
175void makeRoundedCorners(pixmap_t *p);
176
177static int infoMenuSelection = 0;
178static int infoMenuItemsCount = sizeof(infoMenuItems)/sizeof(infoMenuItems[0]);
179
180static bool infoMenuNativeBoot = false;
181
182// here we store the used screen resolution
183static unsigned long screen_params[4] = {DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 32, 0};
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
206// generated manualy, 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
943//prompt[0] = '\0';
944//prompt_pos=0;
945
946
947if(gui.bootprompt.draw == true )
948{
949gui.bootprompt.draw = false;
950gui.redraw = true;
951// this causes extra frames to be drawn
952//updateVRAM();
953}
954
955return;
956}
957
958void updateGraphicBootPrompt(int key)
959{
960fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);
961
962makeRoundedCorners( gui.bootprompt.pixmap);
963
964position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );
965
966// print the boot prompt text
967drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);
968
969// get the position of the end of the boot prompt text to display user input
970position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );
971
972// calculate the position of the cursor
973intoffset = ( strlen(gBootArgs) - ( ( gui.bootprompt.width / font_console.chars[0]->width ) - strlen(prompt_text) - 2 ) );
974
975if ( offset < 0)
976offset = 0;
977
978drawStr( gBootArgs, &font_console, gui.bootprompt.pixmap, p_prompt);
979
980gui.menu.draw = false;
981gui.bootprompt.draw = true;
982gui.redraw = true;
983
984updateVRAM();
985
986return;
987}
988
989inline
990void vramwrite (void *data, int width, int height)
991{
992if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)
993memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
994else
995{
996uint32_t r, g, b;
997int i, j;
998for (i = 0; i < VIDEO (height); i++)
999for (j = 0; j < VIDEO (width); j++)
1000{
1001b = ((uint8_t *) data)[4*i*width + 4*j];
1002g = ((uint8_t *) data)[4*i*width + 4*j + 1];
1003r = ((uint8_t *) data)[4*i*width + 4*j + 2];
1004switch (VIDEO (depth))
1005{
1006case 32:
1007*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1008break;
1009case 24:
1010*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)
1011| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1012break;
1013case 16:
1014// Somehow 16-bit is always 15-bits really
1015//*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);
1016//break;
1017case 15:
1018*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);
1019break;
1020}
1021}
1022}
1023}
1024
1025void updateVRAM()
1026{
1027if (gui.redraw)
1028{
1029if (gui.devicelist.draw)
1030blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
1031
1032if (gui.bootprompt.draw)
1033blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
1034
1035if (gui.menu.draw)
1036blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
1037
1038if (gui.infobox.draw)
1039blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
1040}
1041
1042vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
1043
1044if (gui.redraw)
1045{
1046memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
1047gui.redraw = false;
1048}
1049}
1050
1051struct putc_info //Azi: same as below
1052{
1053 char * str;
1054 char * last_str;
1055};
1056
1057static int
1058sputc(int c, struct putc_info * pi) //Azi: exists on console.c & printf.c
1059{
1060 if (pi->last_str)
1061 if (pi->str == pi->last_str) {
1062 *(pi->str) = '\0';
1063 return 0;
1064 }
1065 *(pi->str)++ = c;
1066 return c;
1067}
1068
1069int gprintf( window_t * window, const char * fmt, ...)
1070{
1071char *formattedtext;
1072
1073va_list ap;
1074
1075struct putc_info pi;
1076
1077if ((formattedtext = malloc(1024)) != NULL) {
1078// format the text
1079va_start(ap, fmt);
1080pi.str = formattedtext;
1081pi.last_str = 0;
1082prf(fmt, ap, sputc, &pi);
1083*pi.str = '\0';
1084va_end(ap);
1085
1086position_torigin, cursor, bounds;
1087
1088int i;
1089int character;
1090
1091origin.x = MAX( window->cursor.x, window->hborder );
1092origin.y = MAX( window->cursor.y, window->vborder );
1093
1094bounds.x = ( window->width - window->hborder );
1095bounds.y = ( window->height - window->vborder );
1096
1097cursor = origin;
1098
1099font_t *font = &font_console;
1100
1101for( i=0; i< strlen(formattedtext); i++ )
1102{
1103character = formattedtext[i];
1104
1105character -= 32;
1106
1107// newline ?
1108if( formattedtext[i] == '\n' )
1109{
1110cursor.x = window->hborder;
1111cursor.y += font->height;
1112
1113if ( cursor.y > bounds.y )
1114cursor.y = origin.y;
1115
1116continue;
1117}
1118
1119// tab ?
1120if( formattedtext[i] == '\t' )
1121cursor.x += ( font->chars[0]->width * 5 );
1122
1123// draw the character
1124if( font->chars[character])
1125blend(font->chars[character], window->pixmap, cursor);
1126
1127cursor.x += font->chars[character]->width;
1128
1129// check x pos and do newline
1130if ( cursor.x > bounds.x )
1131{
1132cursor.x = origin.x;
1133cursor.y += font->height;
1134}
1135
1136// check y pos and reset to origin.y
1137if ( cursor.y > bounds.y )
1138cursor.y = origin.y;
1139}
1140
1141// update cursor postition
1142window->cursor = cursor;
1143
1144free(formattedtext);
1145
1146return 0;
1147
1148}
1149return 1;
1150}
1151
1152int dprintf( window_t * window, const char * fmt, ...)
1153{
1154char *formattedtext;
1155
1156va_list ap;
1157
1158//window = &gui.debug;
1159
1160struct putc_info pi;
1161
1162if ((formattedtext = malloc(1024)) != NULL) {
1163// format the text
1164va_start(ap, fmt);
1165pi.str = formattedtext;
1166pi.last_str = 0;
1167prf(fmt, ap, sputc, &pi);
1168*pi.str = '\0';
1169va_end(ap);
1170
1171position_torigin, cursor, bounds;
1172
1173int i;
1174int character;
1175
1176origin.x = MAX( gui.debug.cursor.x, window->hborder );
1177origin.y = MAX( gui.debug.cursor.y, window->vborder );
1178
1179bounds.x = ( window->width - window->hborder );
1180bounds.y = ( window->height - window->vborder );
1181
1182cursor = origin;
1183
1184font_t *font = &font_console;
1185
1186for( i=0; i< strlen(formattedtext); i++ )
1187{
1188character = formattedtext[i];
1189
1190character -= 32;
1191
1192// newline ?
1193if( formattedtext[i] == '\n' )
1194{
1195cursor.x = window->hborder;
1196cursor.y += font->height;
1197
1198if ( cursor.y > bounds.y )
1199cursor.y = origin.y;
1200
1201continue;
1202}
1203
1204// tab ?
1205if( formattedtext[i] == '\t' )
1206cursor.x += ( font->chars[0]->width * 5 );
1207
1208// draw the character
1209if( font->chars[character])
1210blend(font->chars[character], gui.backbuffer, cursor);
1211
1212cursor.x += font->chars[character]->width;
1213
1214// check x pos and do newline
1215if ( cursor.x > bounds.x )
1216{
1217cursor.x = origin.x;
1218cursor.y += font->height;
1219}
1220
1221// check y pos and reset to origin.y
1222if ( cursor.y > bounds.y )
1223cursor.y = origin.y;
1224}
1225
1226// update cursor postition
1227gui.debug.cursor = cursor;
1228
1229free(formattedtext);
1230
1231return 0;
1232
1233}
1234return 1;
1235}
1236
1237int vprf(const char * fmt, va_list ap)
1238{
1239int i;
1240int character;
1241
1242char *formattedtext;
1243window_t *window = &gui.screen;
1244struct putc_info pi;
1245
1246position_torigin, cursor, bounds;
1247font_t *font = &font_console;
1248
1249if ((formattedtext = malloc(1024)) != NULL) {
1250// format the text
1251pi.str = formattedtext;
1252pi.last_str = 0;
1253prf(fmt, ap, sputc, &pi);
1254*pi.str = '\0';
1255
1256origin.x = MAX( window->cursor.x, window->hborder );
1257origin.y = MAX( window->cursor.y, window->vborder );
1258bounds.x = ( window->width - ( window->hborder * 2 ) );
1259bounds.y = ( window->height - ( window->vborder * 2 ) );
1260cursor = origin;
1261
1262for( i=0; i< strlen(formattedtext); i++ )
1263{
1264character = formattedtext[i];
1265character -= 32;
1266
1267// newline ?
1268if( formattedtext[i] == '\n' )
1269{
1270cursor.x = window->hborder;
1271cursor.y += font->height;
1272if ( cursor.y > bounds.y )
1273{
1274gui.redraw = true;
1275updateVRAM();
1276cursor.y = window->vborder;
1277}
1278window->cursor.y = cursor.y;
1279continue;
1280}
1281
1282// tab ?
1283if( formattedtext[i] == '\t' )
1284{
1285cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
1286continue;
1287}
1288cursor.x += font->chars[character]->width;
1289
1290// check x pos and do newline
1291if ( cursor.x > bounds.x )
1292{
1293cursor.x = origin.x;
1294cursor.y += font->height;
1295}
1296
1297// check y pos and reset to origin.y
1298if ( cursor.y > ( bounds.y + font->chars[0]->height) )
1299{
1300gui.redraw = true;
1301updateVRAM();
1302cursor.y = window->vborder;
1303}
1304// draw the character
1305if( font->chars[character])
1306blend(font->chars[character], gui.backbuffer, cursor);
1307}
1308// save cursor postition
1309window->cursor.x = cursor.x;
1310updateVRAM();
1311free(formattedtext);
1312return 0;
1313}
1314return 1;
1315}
1316
1317void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)
1318{
1319int i=0;
1320int y=0; // we need this to support multilines '\n'
1321int x=0;
1322
1323for(i=0;i<strlen(ch);i++)
1324{
1325int cha=(int)ch[i];
1326
1327cha-=32;
1328
1329// newline ?
1330if( ch[i] == '\n' )
1331{
1332x = 0;
1333y += font->height;
1334continue;
1335}
1336
1337// tab ?
1338if( ch[i] == '\t' )
1339x+=(font->chars[0]->width*5);
1340
1341if(font->chars[cha])
1342blend(font->chars[cha], blendInto, pos(p.x+x, p.y+y));
1343
1344x += font->chars[cha]->width;
1345}
1346}
1347
1348void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)
1349{
1350int i = 0;
1351int width = 0;
1352
1353// calculate the width in pixels
1354for(i=0;i<strlen(text);i++)
1355width += font->chars[text[i]-32]->width;
1356
1357p.x = ( p.x - ( width / 2 ) );
1358p.y = ( p.y - ( font->height / 2 ) );
1359
1360if ( p.x == -6 )
1361{
1362p.x = 0;
1363}
1364
1365for(i=0;i<strlen(text);i++)
1366{
1367int cha=(int)text[i];
1368
1369cha-=32;
1370
1371if(font->chars[cha])
1372{
1373blend(font->chars[cha], blendInto, p);
1374p.x += font->chars[cha]->width;
1375}
1376}
1377
1378}
1379
1380int initFont(font_t *font, image_t *data)
1381{
1382unsigned int x = 0, y = 0, x2 = 0, x3 = 0;
1383
1384int start = 0, end = 0, count = 0, space = 0;
1385
1386bool monospaced = false;
1387
1388font->height = data->image->height;
1389
1390for( x = 0; x < data->image->width; x++)
1391{
1392start = end;
1393
1394// if the pixel is red we've reached the end of the char
1395if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
1396{
1397end = x + 1;
1398
1399if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
1400{
1401font->chars[count]->width = ( end - start) - 1;
1402font->chars[count]->height = font->height;
1403
1404if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
1405{
1406space += ( font->chars[count]->width * data->image->height * 4 );
1407// we skip the first line because there are just the red pixels for the char width
1408for( y = 1; y< (font->height); y++)
1409{
1410for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
1411{
1412pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
1413}
1414}
1415
1416// check if font is monospaced
1417if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
1418monospaced = true;
1419
1420font->width = font->chars[count]->width;
1421
1422count++;
1423}
1424}
1425}
1426}
1427
1428if(monospaced)
1429font->width = 0;
1430
1431return 0;
1432}
1433
1434void colorFont(font_t *font, uint32_t color)
1435{
1436if( !color )
1437return;
1438
1439int x, y, width, height;
1440int count = 0;
1441pixel_t *buff;
1442
1443while( font->chars[count++] )
1444{
1445width = font->chars[count-1]->width;
1446height = font->chars[count-1]->height;
1447for( y = 0; y < height; y++ )
1448{
1449for( x = 0; x < width; x++ )
1450{
1451buff = &(pixel( font->chars[count-1], x, y ));
1452if( buff->ch.a )
1453{
1454buff->ch.r = (color & 0xFFFF0000) >> 16;
1455buff->ch.g = (color & 0xFF00FF00) >> 8;
1456buff->ch.b = (color & 0xFF0000FF);
1457}
1458}
1459}
1460}
1461}
1462
1463void makeRoundedCorners(pixmap_t *p)
1464{
1465int x,y;
1466int width=p->width-1;
1467int height=p->height-1;
1468
1469// 10px rounded corner alpha values
1470uint8_t roundedCorner[10][10] =
1471{
1472{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},
1473{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},
1474{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1475{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1476{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1477{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1478{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1479{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1480{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1481{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
1482};
1483
1484uint8_t alpha=0;
1485
1486for( y=0; y<10; y++)
1487{
1488for( x=0; x<10; x++)
1489{
1490// skip if the pixel should be visible
1491if(roundedCorner[y][x] != 0xFF)
1492{
1493alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
1494// Upper left corner
1495pixel(p, x, y).ch.a = alpha;
1496
1497// upper right corner
1498pixel(p, width-x,y).ch.a = alpha;
1499
1500// lower left corner
1501pixel(p, x, height-y).ch.a = alpha;
1502
1503// lower right corner
1504pixel(p, width-x, height-y).ch.a = alpha;
1505}
1506}
1507}
1508}
1509
1510void showInfoBox(char *title, char *text)
1511{
1512int i, key, lines, visiblelines;
1513
1514int currentline=0;
1515int cnt=0;
1516int offset=0;
1517
1518if( !title || !text )
1519return;
1520
1521position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );
1522
1523// calculate number of lines in the title
1524for ( i = 0, lines = 1; i<strlen(title); i++ )
1525if( title[i] == '\n')
1526lines++;
1527
1528// y position of text is lines in title * height of font
1529position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));
1530
1531// calculate number of lines in the text
1532for ( i=0, lines = 1; i<strlen(text); i++ )
1533if( text[i] == '\n')
1534lines++;
1535
1536// if text ends with \n strip off
1537if( text[i] == '\n' || text[i] == '\0')
1538lines--;
1539
1540visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
1541
1542// lets display the text and allow scroll thru using up down / arrows
1543while(1)
1544{
1545// move to current line in text
1546for( offset = 0, i = 0; offset < strlen(text); offset++ )
1547{
1548if( currentline == i)
1549break;
1550if( text[offset] =='\n')
1551i++;
1552}
1553
1554// find last visible line in text and place \0
1555for( i = offset, cnt = 0; i < strlen(text); i++)
1556{
1557if(text[i]=='\n')
1558cnt++;
1559if ( cnt == visiblelines )
1560{
1561text[i]='\0';
1562break;
1563}
1564}
1565
1566fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);
1567
1568makeRoundedCorners( gui.infobox.pixmap);
1569
1570// print the title if present
1571if( title )
1572drawStr(title, &font_console, gui.infobox.pixmap, pos_title);
1573
1574// print the text
1575drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);
1576
1577// restore \n in text
1578if ( cnt == visiblelines )
1579text[i] = '\n';
1580
1581position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
1582
1583// draw prev indicator
1584if(offset)
1585{
1586blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
1587}
1588
1589// draw next indicator
1590if( lines > ( currentline + visiblelines ) )
1591{
1592pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
1593blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
1594}
1595
1596gui.bootprompt.draw = false;
1597gui.infobox.draw = true;
1598gui.redraw = true;
1599
1600updateVRAM();
1601
1602key = getchar();
1603
1604if( key == kUpArrowkey )
1605if( currentline > 0 )
1606currentline--;
1607
1608if( key == kDownArrowkey )
1609if( lines > ( currentline + visiblelines ) )
1610currentline++;
1611
1612if( key == kEscapeKey || key == 'q' || key == 'Q')
1613{
1614gui.infobox.draw = false;
1615gui.redraw = true;
1616updateVRAM();
1617break;
1618}
1619}
1620}
1621
1622void animateProgressBar()
1623{
1624int y;
1625
1626if( time18() > lasttime)
1627{
1628lasttime = time18();
1629
1630pixmap_t *buffBar = images[iProgressBar].image;
1631
1632uint32_t buff = buffBar->pixels[0].value;
1633
1634memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );
1635
1636for( y = buffBar->height - 1; y > 0; y--)
1637pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);
1638
1639pixel(buffBar, buffBar->width-1, 0).value = buff;
1640}
1641}
1642
1643void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)
1644{
1645if(progress>100)
1646return;
1647
1648p.x = ( p.x - ( width / 2 ) );
1649
1650int todraw = (width * progress) / 100;
1651
1652pixmap_t *buff = images[iProgressBar].image;
1653pixmap_t *buffBG = images[iProgressBarBackground].image;
1654if(!buff || !buffBG)
1655return;
1656
1657pixmap_t progressbar;
1658progressbar.pixels=malloc(width * 4 * buff->height);
1659if(!progressbar.pixels)
1660return;
1661
1662progressbar.width = width;
1663progressbar.height = buff->height;
1664
1665int x=0,x2=0,y=0;
1666
1667for(y=0; y<buff->height; y++)
1668{
1669for(x=0; x<todraw; x++, x2++)
1670{
1671if(x2 == (buff->width-1)) x2=0;
1672pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;
1673}
1674x2=0;
1675}
1676
1677for(y=0; y<buff->height; y++)
1678{
1679for(x=todraw, x2 = 0; x < width - 1; x++, x2++)
1680{
1681if(x2 == (buffBG->width -2 )) x2 = 0;
1682pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;
1683}
1684if(progress < 100)
1685pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1686if(progress == 0)
1687pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1688x2=0;
1689}
1690
1691blend(&progressbar, blendInto, p);
1692animateProgressBar();
1693free(progressbar.pixels);
1694}
1695
1696void drawInfoMenuItems()
1697{
1698int i,n;
1699
1700position_t position;
1701
1702pixmap_t *selection = images[iMenuSelection].image;
1703
1704pixmap_t *pbuff;
1705
1706fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);
1707
1708makeRoundedCorners(gui.menu.pixmap);
1709
1710uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;
1711
1712position = pos(0,0);
1713
1714for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)
1715{
1716if (i == infoMenuSelection)
1717blend(selection, gui.menu.pixmap, position);
1718
1719pbuff = images[n].image;
1720if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)
1721blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
1722pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1723else
1724blend( pbuff, gui.menu.pixmap,
1725pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1726
1727drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap,
1728pos(position.x + (pbuff->width + gui.menu.hborder),
1729position.y + ((selection->height - font_console.height) / 2)));
1730position.y += images[iMenuSelection].image->height;
1731
1732}
1733
1734gui.redraw = true;
1735}
1736
1737int drawInfoMenu()
1738{
1739drawInfoMenuItems();
1740
1741gui.menu.draw = true;
1742
1743updateVRAM();
1744
1745return 1;
1746}
1747
1748int updateInfoMenu(int key)
1749{
1750switch (key)
1751{
1752
1753case kUpArrowkey:// up arrow
1754if (infoMenuSelection > 0)
1755{
1756if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)
1757infoMenuSelection -= 4;
1758
1759else
1760infoMenuSelection--;
1761drawInfoMenuItems();
1762updateVRAM();
1763
1764} else {
1765
1766gui.menu.draw = false;
1767gui.redraw = true;
1768
1769updateVRAM();
1770
1771return CLOSE_INFO_MENU;
1772}
1773break;
1774
1775case kDownArrowkey:// down arrow
1776if (infoMenuSelection < infoMenuItemsCount - 1)
1777{
1778if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
1779infoMenuSelection += 4;
1780else
1781infoMenuSelection++;
1782drawInfoMenuItems();
1783updateVRAM();
1784}
1785break;
1786
1787case kReturnKey:
1788key = 0;
1789if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )
1790showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
1791
1792else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )
1793showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
1794
1795else if( infoMenuSelection == MENU_SHOW_HELP )
1796showHelp();
1797
1798else
1799{
1800int buff = infoMenuSelection;
1801infoMenuSelection = 0;
1802return buff;
1803}
1804break;
1805}
1806return DO_NOT_BOOT;
1807}
1808
1809uint16_t bootImageWidth = 0;
1810uint16_t bootImageHeight = 0;
1811uint8_t *bootImageData = NULL;
1812static bool usePngImage = true;
1813
1814//==========================================================================
1815// loadBootGraphics
1816static void loadBootGraphics(void)
1817{
1818if (bootImageData != NULL) {
1819return;
1820}
1821
1822char dirspec[256];
1823
1824if ((strlen(theme_name) + 24) > sizeof(dirspec)) {
1825usePngImage = false;
1826return;
1827}
1828sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);
1829if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {
1830#ifdef CONFIG_EMBED_THEME
1831 if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
1832#endif
1833usePngImage = false;
1834}
1835}
1836
1837//==========================================================================
1838// drawBootGraphics
1839void drawBootGraphics(void)
1840{
1841int pos;
1842int length;
1843const char *dummyVal;
1844int oldScreenWidth, oldScreenHeight;
1845bool legacy_logo;
1846uint16_t x, y;
1847
1848if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->bootConfig) && legacy_logo) {
1849usePngImage = false;
1850} else if (bootImageData == NULL) {
1851loadBootGraphics();
1852}
1853
1854// parse screen size parameters
1855if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0) {
1856screen_params[0] = pos;
1857} else {
1858screen_params[0] = DEFAULT_SCREEN_WIDTH;
1859}
1860if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0) {
1861screen_params[1] = pos;
1862} else {
1863screen_params[1] = DEFAULT_SCREEN_HEIGHT;
1864}
1865
1866 // Save current screen resolution.
1867oldScreenWidth = gui.screen.width;
1868oldScreenHeight = gui.screen.height;
1869
1870gui.screen.width = screen_params[0];
1871gui.screen.height = screen_params[1];
1872
1873// find best matching vesa mode for our requested width & height
1874getGraphicModeParams(screen_params);
1875
1876 // Set graphics mode if the booter was in text mode or the screen resolution has changed.
1877if (bootArgs->Video.v_display == VGA_TEXT_MODE
1878|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )
1879{
1880setVideoMode(GRAPHICS_MODE, 0);
1881}
1882
1883if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) {
1884drawCheckerBoard();
1885} else {
1886// Fill the background to 75% grey (same as BootX).
1887drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
1888}
1889if ((bootImageData) && (usePngImage)) {
1890x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
1891y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
1892
1893// Draw the image in the center of the display.
1894blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
1895} else {
1896uint8_t *appleBootPict;
1897bootImageData = NULL;
1898bootImageWidth = kAppleBootWidth;
1899bootImageHeight = kAppleBootHeight;
1900
1901// Prepare the data for the default Apple boot image.
1902appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
1903if (appleBootPict) {
1904convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
1905if (bootImageData) {
1906x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
1907y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
1908drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
1909free(bootImageData);
1910}
1911free(appleBootPict);
1912}
1913}
1914}
1915

Archive Download this file

Revision: 310