Chameleon Applications

Chameleon Applications Svn Source Tree

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

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

Archive Download this file

Revision: 298