Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/trunkGraphicsEnablerModules/i386/boot2/gui.c

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

Archive Download this file

Revision: 1540