Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/trunkAutoResolution/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 "appleboot.h"
13#include "vers.h"
14#include "autoresolution.h" //Azi:autoresolution
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
718//Azi:autoresolution
719if (gAutoResolution == true)
720{
721screen_params[0] = paramsAR[0];
722screen_params[1] = paramsAR[1];
723 }
724else
725{
726// parse screen size parameters
727 if (getIntForKey("screen_width", &val, &bootInfo->themeConfig) && val > 0)
728{
729screen_params[0] = val;
730}
731
732 if (getIntForKey("screen_height", &val, &bootInfo->themeConfig) && val > 0)
733{
734screen_params[1] = val;
735}
736}
737
738// Initalizing GUI strucutre.
739bzero(&gui, sizeof(gui_t));
740
741// find best matching vesa mode for our requested width & height
742getGraphicModeParams(screen_params);
743
744// set our screen structure with the mode width & height
745gui.screen.width = screen_params[0];
746gui.screen.height = screen_params[1];
747
748PRINT("Found mode %dx%d in VESA Table\n", gui.screen.width, gui.screen.height); //Azi:autoresolution
749
750// load graphics otherwise fail and return
751if (loadGraphics() == 0) {
752loadThemeValues(&bootInfo->themeConfig);
753colorFont(&font_small, gui.screen.font_small_color);
754colorFont(&font_console, gui.screen.font_console_color);
755
756// create the screen & window buffers
757if (createBackBuffer(&gui.screen) == 0) {
758if (createWindowBuffer(&gui.screen) == 0) {
759if (createWindowBuffer(&gui.devicelist) == 0) {
760if (createWindowBuffer(&gui.bootprompt) == 0) {
761if (createWindowBuffer(&gui.infobox) == 0) {
762if (createWindowBuffer(&gui.menu) == 0) {
763#ifdef AUTORES_DEBUG
764pause();
765#endif
766 gui.logo.draw = true;
767drawBackground();
768// lets copy the screen into the back buffer
769memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
770setVideoMode( GRAPHICS_MODE, 0 );
771gui.initialised = true;
772return 0;
773} else printf("createWindowBuffer(&gui.menu) Failed\n");
774} else printf("createWindowBuffer(&gui.infobox) Failed\n");
775} else printf("createWindowBuffer(&gui.bootprompt) Failed\n");
776} else printf("createWindowBuffer(&gui.devicelist) Failed\n");
777} else printf("createWindowBuffer(&gui.screen) Failed\n");
778} else printf("createBackBuffer(&gui.screen) Failed\n");
779} else printf("loadGraphics() Failed\n");
780//Azi: removed a #ifdef AUTORES_DEBUG from here, long time ago; was just a pause()
781// and if i'm not mistaken caused some problem ?!
782return 1;
783}
784
785void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected)
786{
787int devicetype;
788
789if( diskIsCDROM(device) )
790devicetype = iDeviceCDROM;// Use CDROM icon
791else
792{
793switch (device->part_type)
794{
795case kPartitionTypeHFS:
796
797// Use HFS or HFSRAID icon depending on bvr flags.
798devicetype = (device->flags & kBVFlagBooter) ? iDeviceHFSRAID : iDeviceHFS;
799break;
800
801case kPartitionTypeHPFS:
802devicetype = iDeviceNTFS;// Use HPFS / NTFS icon
803break;
804
805case kPartitionTypeBEFS: /* Haiku detection and Icon credits to scorpius */
806devicetype = iDeviceBEFS;// Use BEFS / Haiku icon
807break;
808
809case kPartitionTypeFreeBSD: /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */
810devicetype = iDeviceFreeBSD; // Use FreeBSD icon
811break;
812
813case kPartitionTypeOpenBSD: /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */
814devicetype = iDeviceOpenBSD; // Use OpenBSD icon
815break;
816
817case kPartitionTypeFAT16:
818devicetype = iDeviceFAT16;// Use FAT16 icon
819break;
820
821case kPartitionTypeFAT32:
822devicetype = iDeviceFAT32;// Use FAT32 icon
823break;
824
825case kPartitionTypeEXT3:
826devicetype = iDeviceEXT3;// Use EXT2/3 icon
827break;
828
829default:
830devicetype = iDeviceGeneric;// Use Generic icon
831break;
832}
833}
834
835// Draw the selection image and use the next (device_*_o) image for the selected item.
836 if (isSelected)
837{
838blend(images[iSelection].image, buffer, centeredAt(images[iSelection].image, p));
839devicetype++;
840}
841
842// draw icon
843blend( images[devicetype].image, buffer, centeredAt( images[devicetype].image, p ));
844
845p.y += (images[iSelection].image->height / 2) + font_console.chars[0]->height;
846
847// draw volume label
848drawStrCenteredAt( device->label, &font_small, buffer, p);
849
850}
851
852void drawDeviceList (int start, int end, int selection)
853{
854inti;
855boolshoWinfo = true; //Azi:showinfo
856extern bool showBootBanner; //
857position_tp, p_prev, p_next;
858
859//uint8_tmaxDevices = MIN( gui.maxdevices, menucount );
860
861fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);
862
863makeRoundedCorners( gui.devicelist.pixmap);
864
865switch (gui.layout)
866{
867
868case VerticalLayout:
869p.x = (gui.devicelist.width /2);
870p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );
871
872// place scroll indicators at top & bottom edges
873p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );
874p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );
875
876break;
877
878default:// use Horizontal layout as the default
879
880case HorizontalLayout:
881p.x = (gui.devicelist.width - ( gui.devicelist.width / gui.maxdevices ) * gui.maxdevices ) / 2 + ( images[iSelection].image->width / 2) + images[iDeviceScrollPrev].image->width + gui.devicelist.iconspacing;
882p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );
883
884// place scroll indicators at left & right edges
885p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );
886p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );
887
888break;
889
890}
891
892// draw visible device icons
893for (i = 0; i < gui.maxdevices; i++)
894{
895BVRef param = menuItems[start + i].param;
896
897 bool isSelected = ((start + i) == selection) ? true : false;
898if (isSelected)
899{
900 if (param->flags & kBVFlagNativeBoot)
901 {
902 infoMenuNativeBoot = true;
903 }
904 else
905 {
906 infoMenuNativeBoot = false;
907 if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)
908 infoMenuSelection = 0;
909 }
910
911if (gui.menu.draw)
912drawInfoMenuItems();
913
914getBoolForKey(kShowInfoKey, &shoWinfo, &bootInfo->chameleonConfig);
915
916if (shoWinfo && showBootBanner) // no boot banner, no showinfo.
917{
918// keep formatted with spaces instead of tabs
919gui.debug.cursor = pos( 10, 100);
920dprintf( &gui.screen, "label: %s\n", param->label );
921dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev );
922dprintf( &gui.screen, "type: 0x%x\n", param->type );
923dprintf( &gui.screen, "flags: 0x%x\n", param->flags );
924dprintf( &gui.screen, "part_no: %d\n", param->part_no );
925dprintf( &gui.screen, "part_boff: 0x%x\n", param->part_boff );
926dprintf( &gui.screen, "part_type: 0x%x\n", param->part_type );
927dprintf( &gui.screen, "bps: 0x%x\n", param->bps );
928dprintf( &gui.screen, "name: %s\n", param->name );
929dprintf( &gui.screen, "type_name: %s\n", param->type_name );
930dprintf( &gui.screen, "modtime: %d\n", param->modTime );
931dprintf( &gui.screen, "width: %d\n", gui.screen.width );
932dprintf( &gui.screen, "height: %d\n", gui.screen.height );
933dprintf( &gui.screen, "attr: 0x%x\n", gui.screen.attr ); //Azi: reminder
934dprintf( &gui.screen, "mm: %d\n", gui.screen.mm );
935}
936}
937
938drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);
939
940if (gui.layout == HorizontalLayout)
941{
942p.x += images[iSelection].image->width + gui.devicelist.iconspacing;
943}
944if (gui.layout == VerticalLayout)
945{
946p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing );
947}
948}
949
950// draw prev indicator
951if (start)
952blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );
953
954// draw next indicator
955if ( end < gDeviceCount - 1 )
956blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );
957
958gui.redraw = true;
959
960updateVRAM();
961
962}
963
964void clearGraphicBootPrompt()
965{
966// clear text buffer
967//prompt[0] = '\0';
968//prompt_pos=0;
969
970
971if(gui.bootprompt.draw == true )
972{
973gui.bootprompt.draw = false;
974gui.redraw = true;
975// this causes extra frames to be drawn
976//updateVRAM();
977}
978
979return;
980}
981
982void updateGraphicBootPrompt()
983{
984fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);
985
986makeRoundedCorners( gui.bootprompt.pixmap);
987
988position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );
989
990// print the boot prompt text
991drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);
992
993// get the position of the end of the boot prompt text to display user input
994position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );
995
996drawStr( gBootArgs, &font_console, gui.bootprompt.pixmap, p_prompt);
997
998gui.menu.draw = false;
999gui.bootprompt.draw = true;
1000gui.redraw = true;
1001
1002updateVRAM();
1003
1004return;
1005}
1006
1007inline
1008void vramwrite (void *data, int width, int height)
1009{
1010if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)
1011memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
1012else
1013{
1014uint32_t r, g, b;
1015int i, j;
1016for (i = 0; i < VIDEO (height); i++)
1017for (j = 0; j < VIDEO (width); j++)
1018{
1019b = ((uint8_t *) data)[4*i*width + 4*j];
1020g = ((uint8_t *) data)[4*i*width + 4*j + 1];
1021r = ((uint8_t *) data)[4*i*width + 4*j + 2];
1022switch (VIDEO (depth))
1023{
1024case 32:
1025*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1026break;
1027case 24:
1028*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)
1029| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1030break;
1031case 16:
1032// Somehow 16-bit is always 15-bits really
1033//*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);
1034//break;
1035case 15:
1036*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);
1037break;
1038}
1039}
1040}
1041}
1042
1043void updateVRAM()
1044{
1045if (gui.redraw)
1046{
1047if (gui.devicelist.draw)
1048blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
1049
1050if (gui.bootprompt.draw)
1051blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
1052
1053if (gui.menu.draw)
1054blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
1055
1056if (gui.infobox.draw)
1057blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
1058}
1059
1060vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
1061
1062if (gui.redraw)
1063{
1064memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
1065gui.redraw = false;
1066}
1067}
1068
1069struct putc_info //Azi: exists on console.c & printf.c
1070{
1071 char * str;
1072 char * last_str;
1073};
1074
1075static int
1076sputc(int c, struct putc_info * pi) //Azi: same as above
1077{
1078 if (pi->last_str)
1079 if (pi->str == pi->last_str) {
1080 *(pi->str) = '\0';
1081 return 0;
1082 }
1083 *(pi->str)++ = c;
1084 return c;
1085}
1086
1087int gprintf( window_t * window, const char * fmt, ...)
1088{
1089char *formattedtext;
1090
1091va_list ap;
1092
1093struct putc_info pi;
1094
1095if ((formattedtext = malloc(1024)) != NULL) {
1096// format the text
1097va_start(ap, fmt);
1098pi.str = formattedtext;
1099pi.last_str = 0;
1100prf(fmt, ap, sputc, &pi);
1101*pi.str = '\0';
1102va_end(ap);
1103
1104position_torigin, cursor, bounds;
1105
1106int i;
1107int character;
1108
1109origin.x = MAX( window->cursor.x, window->hborder );
1110origin.y = MAX( window->cursor.y, window->vborder );
1111
1112bounds.x = ( window->width - window->hborder );
1113bounds.y = ( window->height - window->vborder );
1114
1115cursor = origin;
1116
1117font_t *font = &font_console;
1118
1119for( i=0; i< strlen(formattedtext); i++ )
1120{
1121character = formattedtext[i];
1122
1123character -= 32;
1124
1125// newline ?
1126if( formattedtext[i] == '\n' )
1127{
1128cursor.x = window->hborder;
1129cursor.y += font->height;
1130
1131if ( cursor.y > bounds.y )
1132cursor.y = origin.y;
1133
1134continue;
1135}
1136
1137// tab ?
1138if( formattedtext[i] == '\t' )
1139cursor.x += ( font->chars[0]->width * 5 );
1140
1141// draw the character
1142if( font->chars[character])
1143blend(font->chars[character], window->pixmap, cursor);
1144
1145cursor.x += font->chars[character]->width;
1146
1147// check x pos and do newline
1148if ( cursor.x > bounds.x )
1149{
1150cursor.x = origin.x;
1151cursor.y += font->height;
1152}
1153
1154// check y pos and reset to origin.y
1155if ( cursor.y > bounds.y )
1156cursor.y = origin.y;
1157}
1158
1159// update cursor postition
1160window->cursor = cursor;
1161
1162free(formattedtext);
1163
1164return 0;
1165
1166}
1167return 1;
1168}
1169
1170int dprintf( window_t * window, const char * fmt, ...)
1171{
1172char *formattedtext;
1173
1174va_list ap;
1175
1176//window = &gui.debug;
1177
1178struct putc_info pi;
1179
1180if ((formattedtext = malloc(1024)) != NULL) {
1181// format the text
1182va_start(ap, fmt);
1183pi.str = formattedtext;
1184pi.last_str = 0;
1185prf(fmt, ap, sputc, &pi);
1186*pi.str = '\0';
1187va_end(ap);
1188
1189position_torigin, cursor, bounds;
1190
1191int i;
1192int character;
1193
1194origin.x = MAX( gui.debug.cursor.x, window->hborder );
1195origin.y = MAX( gui.debug.cursor.y, window->vborder );
1196
1197bounds.x = ( window->width - window->hborder );
1198bounds.y = ( window->height - window->vborder );
1199
1200cursor = origin;
1201
1202font_t *font = &font_console;
1203
1204for( i=0; i< strlen(formattedtext); i++ )
1205{
1206character = formattedtext[i];
1207
1208character -= 32;
1209
1210// newline ?
1211if( formattedtext[i] == '\n' )
1212{
1213cursor.x = window->hborder;
1214cursor.y += font->height;
1215
1216if ( cursor.y > bounds.y )
1217cursor.y = origin.y;
1218
1219continue;
1220}
1221
1222// tab ?
1223if( formattedtext[i] == '\t' )
1224cursor.x += ( font->chars[0]->width * 5 );
1225
1226// draw the character
1227if( font->chars[character])
1228blend(font->chars[character], gui.backbuffer, cursor);
1229
1230cursor.x += font->chars[character]->width;
1231
1232// check x pos and do newline
1233if ( cursor.x > bounds.x )
1234{
1235cursor.x = origin.x;
1236cursor.y += font->height;
1237}
1238
1239// check y pos and reset to origin.y
1240if ( cursor.y > bounds.y )
1241cursor.y = origin.y;
1242}
1243
1244// update cursor postition
1245gui.debug.cursor = cursor;
1246
1247free(formattedtext);
1248
1249return 0;
1250
1251}
1252return 1;
1253}
1254
1255int vprf(const char * fmt, va_list ap)
1256{
1257int i;
1258int character;
1259
1260char *formattedtext;
1261window_t *window = &gui.screen;
1262struct putc_info pi;
1263
1264position_torigin, cursor, bounds;
1265font_t *font = &font_console;
1266
1267if ((formattedtext = malloc(1024)) != NULL) {
1268// format the text
1269pi.str = formattedtext;
1270pi.last_str = 0;
1271prf(fmt, ap, sputc, &pi);
1272*pi.str = '\0';
1273
1274origin.x = MAX( window->cursor.x, window->hborder );
1275origin.y = MAX( window->cursor.y, window->vborder );
1276bounds.x = ( window->width - ( window->hborder * 2 ) );
1277bounds.y = ( window->height - ( window->vborder * 2 ) );
1278cursor = origin;
1279
1280for( i=0; i< strlen(formattedtext); i++ )
1281{
1282character = formattedtext[i];
1283character -= 32;
1284
1285// newline ?
1286if( formattedtext[i] == '\n' )
1287{
1288cursor.x = window->hborder;
1289cursor.y += font->height;
1290if ( cursor.y > bounds.y )
1291{
1292gui.redraw = true;
1293updateVRAM();
1294cursor.y = window->vborder;
1295}
1296window->cursor.y = cursor.y;
1297continue;
1298}
1299
1300// tab ?
1301if( formattedtext[i] == '\t' )
1302{
1303cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
1304continue;
1305}
1306cursor.x += font->chars[character]->width;
1307
1308// check x pos and do newline
1309if ( cursor.x > bounds.x )
1310{
1311cursor.x = origin.x;
1312cursor.y += font->height;
1313}
1314
1315// check y pos and reset to origin.y
1316if ( cursor.y > ( bounds.y + font->chars[0]->height) )
1317{
1318gui.redraw = true;
1319updateVRAM();
1320cursor.y = window->vborder;
1321}
1322// draw the character
1323if( font->chars[character])
1324blend(font->chars[character], gui.backbuffer, cursor);
1325}
1326// save cursor postition
1327window->cursor.x = cursor.x;
1328updateVRAM();
1329free(formattedtext);
1330return 0;
1331}
1332return 1;
1333}
1334
1335void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)
1336{
1337int i=0;
1338int y=0; // we need this to support multilines '\n'
1339int x=0;
1340
1341for(i=0;i<strlen(ch);i++)
1342{
1343int cha=(int)ch[i];
1344
1345cha-=32;
1346
1347// newline ?
1348if( ch[i] == '\n' )
1349{
1350x = 0;
1351y += font->height;
1352continue;
1353}
1354
1355// tab ?
1356if( ch[i] == '\t' )
1357x+=(font->chars[0]->width*5);
1358
1359if(font->chars[cha] && ((x + font->chars[cha]->width) < blendInto->width))
1360blend(font->chars[cha], blendInto, pos(p.x+x, p.y+y));
1361
1362x += font->chars[cha]->width;
1363}
1364}
1365
1366void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)
1367{
1368int i = 0;
1369int width = 0;
1370
1371// calculate the width in pixels
1372for(i=0;i<strlen(text);i++)
1373width += font->chars[text[i]-32]->width;
1374
1375p.x = ( p.x - ( width / 2 ) );
1376p.y = ( p.y - ( font->height / 2 ) );
1377
1378if ( p.x == -6 )
1379{
1380p.x = 0;
1381}
1382
1383for(i=0;i<strlen(text);i++)
1384{
1385int cha=(int)text[i];
1386
1387cha-=32;
1388
1389if(font->chars[cha])
1390{
1391blend(font->chars[cha], blendInto, p);
1392p.x += font->chars[cha]->width;
1393}
1394}
1395
1396}
1397
1398int initFont(font_t *font, image_t *data)
1399{
1400unsigned int x = 0, y = 0, x2 = 0, x3 = 0;
1401
1402int start = 0, end = 0, count = 0, space = 0;
1403
1404bool monospaced = false;
1405
1406font->height = data->image->height;
1407
1408for( x = 0; x < data->image->width; x++)
1409{
1410start = end;
1411
1412// if the pixel is red we've reached the end of the char
1413if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
1414{
1415end = x + 1;
1416
1417if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
1418{
1419font->chars[count]->width = ( end - start) - 1;
1420font->chars[count]->height = font->height;
1421
1422if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
1423{
1424space += ( font->chars[count]->width * data->image->height * 4 );
1425// we skip the first line because there are just the red pixels for the char width
1426for( y = 1; y< (font->height); y++)
1427{
1428for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
1429{
1430pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
1431}
1432}
1433
1434// check if font is monospaced
1435if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
1436monospaced = true;
1437
1438font->width = font->chars[count]->width;
1439
1440count++;
1441}
1442}
1443}
1444}
1445
1446if(monospaced)
1447font->width = 0;
1448
1449return 0;
1450}
1451
1452void colorFont(font_t *font, uint32_t color)
1453{
1454if( !color )
1455return;
1456
1457int x, y, width, height;
1458int count = 0;
1459pixel_t *buff;
1460
1461while( font->chars[count++] )
1462{
1463width = font->chars[count-1]->width;
1464height = font->chars[count-1]->height;
1465for( y = 0; y < height; y++ )
1466{
1467for( x = 0; x < width; x++ )
1468{
1469buff = &(pixel( font->chars[count-1], x, y ));
1470if( buff->ch.a )
1471{
1472buff->ch.r = (color & 0xFFFF0000) >> 16;
1473buff->ch.g = (color & 0xFF00FF00) >> 8;
1474buff->ch.b = (color & 0xFF0000FF);
1475}
1476}
1477}
1478}
1479}
1480
1481void makeRoundedCorners(pixmap_t *p)
1482{
1483int x,y;
1484int width=p->width-1;
1485int height=p->height-1;
1486
1487// 10px rounded corner alpha values
1488uint8_t roundedCorner[10][10] =
1489{
1490{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},
1491{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},
1492{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1493{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1494{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1495{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1496{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1497{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1498{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1499{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
1500};
1501
1502uint8_t alpha=0;
1503
1504for( y=0; y<10; y++)
1505{
1506for( x=0; x<10; x++)
1507{
1508// skip if the pixel should be visible
1509if(roundedCorner[y][x] != 0xFF)
1510{
1511alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
1512// Upper left corner
1513pixel(p, x, y).ch.a = alpha;
1514
1515// upper right corner
1516pixel(p, width-x,y).ch.a = alpha;
1517
1518// lower left corner
1519pixel(p, x, height-y).ch.a = alpha;
1520
1521// lower right corner
1522pixel(p, width-x, height-y).ch.a = alpha;
1523}
1524}
1525}
1526}
1527
1528void showInfoBox(char *title, char *text_orig)
1529{
1530char* text;
1531int i, key, lines, visiblelines;
1532
1533int currentline=0;
1534int cnt=0;
1535int offset=0;
1536
1537if( !title || !text_orig )
1538return;
1539
1540// Create a copy so that we don't mangle the original
1541text = malloc(strlen(text_orig) + 1);
1542strcpy(text, text_orig);
1543
1544
1545position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );
1546
1547// calculate number of lines in the title
1548for ( i = 0, lines = 1; i<strlen(title); i++ )
1549if( title[i] == '\n')
1550lines++;
1551
1552// y position of text is lines in title * height of font
1553position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));
1554
1555// calculate number of lines in the text
1556for ( i=0, lines = 1; i<strlen(text); i++ )
1557if( text[i] == '\n')
1558lines++;
1559
1560// if text ends with \n strip off
1561if( text[i] == '\n' || text[i] == '\0')
1562lines--;
1563
1564visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
1565
1566// lets display the text and allow scroll thru using up down / arrows
1567while(1)
1568{
1569// move to current line in text
1570for( offset = 0, i = 0; offset < strlen(text); offset++ )
1571{
1572if( currentline == i)
1573break;
1574if( text[offset] =='\n')
1575i++;
1576}
1577
1578// find last visible line in text and place \0
1579for( i = offset, cnt = 0; i < strlen(text); i++)
1580{
1581if(text[i]=='\n')
1582cnt++;
1583if ( cnt == visiblelines )
1584{
1585text[i]='\0';
1586break;
1587}
1588}
1589
1590fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);
1591
1592makeRoundedCorners( gui.infobox.pixmap);
1593
1594// print the title if present
1595if( title )
1596drawStr(title, &font_console, gui.infobox.pixmap, pos_title);
1597
1598// print the text
1599drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);
1600
1601// restore \n in text
1602if ( cnt == visiblelines )
1603text[i] = '\n';
1604
1605position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
1606
1607// draw prev indicator
1608if(offset)
1609{
1610blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
1611}
1612
1613// draw next indicator
1614if( lines > ( currentline + visiblelines ) )
1615{
1616pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
1617blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
1618}
1619
1620gui.bootprompt.draw = false;
1621gui.infobox.draw = true;
1622gui.redraw = true;
1623
1624updateVRAM();
1625
1626key = getchar();
1627
1628if( key == kUpArrowkey )
1629if( currentline > 0 )
1630currentline--;
1631
1632if( key == kDownArrowkey )
1633if( lines > ( currentline + visiblelines ) )
1634currentline++;
1635
1636if( key == kEscapeKey || key == 'q' || key == 'Q')
1637{
1638gui.infobox.draw = false;
1639gui.redraw = true;
1640updateVRAM();
1641break;
1642}
1643
1644if(key == ' ') // spacebar = next page
1645{
1646if( lines > ( currentline + visiblelines ) )
1647currentline += visiblelines;
1648
1649if(lines < (currentline + visiblelines))
1650currentline = lines - visiblelines;
1651}
1652}
1653}
1654
1655void animateProgressBar()
1656{
1657int y;
1658
1659if( time18() > lasttime)
1660{
1661lasttime = time18();
1662
1663pixmap_t *buffBar = images[iProgressBar].image;
1664
1665uint32_t buff = buffBar->pixels[0].value;
1666
1667memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );
1668
1669for( y = buffBar->height - 1; y > 0; y--)
1670pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);
1671
1672pixel(buffBar, buffBar->width-1, 0).value = buff;
1673}
1674}
1675
1676void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)
1677{
1678if(progress>100)
1679return;
1680
1681p.x = ( p.x - ( width / 2 ) );
1682
1683int todraw = (width * progress) / 100;
1684
1685pixmap_t *buff = images[iProgressBar].image;
1686pixmap_t *buffBG = images[iProgressBarBackground].image;
1687if(!buff || !buffBG)
1688return;
1689
1690pixmap_t progressbar;
1691progressbar.pixels=malloc(width * 4 * buff->height);
1692if(!progressbar.pixels)
1693return;
1694
1695progressbar.width = width;
1696progressbar.height = buff->height;
1697
1698int x=0,x2=0,y=0;
1699
1700for(y=0; y<buff->height; y++)
1701{
1702for(x=0; x<todraw; x++, x2++)
1703{
1704if(x2 == (buff->width-1)) x2=0;
1705pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;
1706}
1707x2=0;
1708}
1709
1710for(y=0; y<buff->height; y++)
1711{
1712for(x=todraw, x2 = 0; x < width - 1; x++, x2++)
1713{
1714if(x2 == (buffBG->width -2 )) x2 = 0;
1715pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;
1716}
1717if(progress < 100)
1718pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1719if(progress == 0)
1720pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1721x2=0;
1722}
1723
1724blend(&progressbar, blendInto, p);
1725animateProgressBar();
1726free(progressbar.pixels);
1727}
1728
1729void drawInfoMenuItems()
1730{
1731int i,n;
1732
1733position_t position;
1734
1735pixmap_t *selection = images[iMenuSelection].image;
1736
1737pixmap_t *pbuff;
1738
1739fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);
1740
1741makeRoundedCorners(gui.menu.pixmap);
1742
1743uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;
1744
1745position = pos(0,0);
1746
1747for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)
1748{
1749if (i == infoMenuSelection)
1750blend(selection, gui.menu.pixmap, position);
1751
1752pbuff = images[n].image;
1753if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)
1754blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
1755pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1756else
1757blend( pbuff, gui.menu.pixmap,
1758pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1759
1760drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap,
1761pos(position.x + (pbuff->width + gui.menu.hborder),
1762position.y + ((selection->height - font_console.height) / 2)));
1763position.y += images[iMenuSelection].image->height;
1764
1765}
1766
1767gui.redraw = true;
1768}
1769
1770int drawInfoMenu()
1771{
1772drawInfoMenuItems();
1773
1774gui.menu.draw = true;
1775
1776updateVRAM();
1777
1778return 1;
1779}
1780
1781int updateInfoMenu(int key)
1782{
1783switch (key)
1784{
1785
1786case kUpArrowkey:// up arrow
1787if (infoMenuSelection > 0)
1788{
1789if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)
1790infoMenuSelection -= 4;
1791
1792else
1793infoMenuSelection--;
1794drawInfoMenuItems();
1795updateVRAM();
1796
1797} else {
1798
1799gui.menu.draw = false;
1800gui.redraw = true;
1801
1802updateVRAM();
1803
1804return CLOSE_INFO_MENU;
1805}
1806break;
1807
1808case kDownArrowkey:// down arrow
1809if (infoMenuSelection < infoMenuItemsCount - 1)
1810{
1811if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
1812infoMenuSelection += 4;
1813else
1814infoMenuSelection++;
1815drawInfoMenuItems();
1816updateVRAM();
1817}
1818break;
1819
1820case kReturnKey:
1821key = 0;
1822if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )
1823showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
1824
1825else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )
1826showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
1827
1828else if( infoMenuSelection == MENU_SHOW_HELP )
1829showHelp();
1830
1831else
1832{
1833int buff = infoMenuSelection;
1834infoMenuSelection = 0;
1835return buff;
1836}
1837break;
1838}
1839return DO_NOT_BOOT;
1840}
1841
1842uint16_t bootImageWidth = 0;
1843uint16_t bootImageHeight = 0;
1844uint8_t *bootImageData = NULL;
1845static bool usePngImage = true;
1846
1847//==========================================================================
1848// loadBootGraphics
1849static void loadBootGraphics(void)
1850{
1851if (bootImageData != NULL) {
1852return;
1853}
1854
1855char dirspec[256];
1856
1857if ((strlen(theme_name) + 24) > sizeof(dirspec)) {
1858usePngImage = false;
1859return;
1860}
1861sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);
1862if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {
1863#ifdef CONFIG_EMBED_THEME
1864 if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
1865#endif
1866usePngImage = false;
1867}
1868}
1869
1870//==========================================================================
1871// drawBootGraphics
1872void drawBootGraphics(void)
1873{
1874int pos;
1875int length;
1876const char *dummyVal;
1877int oldScreenWidth, oldScreenHeight;
1878bool legacy_logo;
1879uint16_t x, y;
1880
1881if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->chameleonConfig) && legacy_logo) {
1882usePngImage = false;
1883} else if (bootImageData == NULL) {
1884loadBootGraphics();
1885}
1886
1887// Save current screen resolution.
1888oldScreenWidth = gui.screen.width;
1889oldScreenHeight = gui.screen.height;
1890//printf("Res: %dx%d (drawbg: current/old)\n", oldScreenWidth, oldScreenHeight);
1891
1892//Azi:autoresolution
1893if (gAutoResolution == true)
1894{
1895screen_params[0] = paramsAR[0];
1896screen_params[1] = paramsAR[1];
1897//printf("Res: %dx%d (drawbg: AR)\n", screen_params[0], screen_params[1]);
1898}
1899else
1900{
1901// parse boot screen size parameters
1902if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0)
1903{
1904screen_params[0] = pos;
1905}
1906else
1907{
1908screen_params[0] = DEFAULT_SCREEN_WIDTH;
1909}
1910
1911if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0)
1912{
1913screen_params[1] = pos;
1914}
1915else
1916{
1917screen_params[1] = DEFAULT_SCREEN_HEIGHT;
1918}
1919}
1920
1921gui.screen.width = screen_params[0];
1922gui.screen.height = screen_params[1];
1923//printf("Res: %dx%d (drawbg: gsw/h new)\n", gui.screen.width, gui.screen.height);
1924
1925// find best matching vesa mode for our requested width & height
1926getGraphicModeParams(screen_params);
1927
1928 // Set graphics mode if the booter was in text mode or the screen resolution has changed.
1929if (bootArgs->Video.v_display == VGA_TEXT_MODE
1930|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )
1931{
1932setVideoMode(GRAPHICS_MODE, 0);
1933}
1934
1935if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->chameleonConfig)) {
1936drawCheckerBoard();
1937} else {
1938// Fill the background to 75% grey (same as BootX).
1939drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
1940}
1941if ((bootImageData) && (usePngImage)) {
1942x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
1943y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
1944
1945// Draw the image in the center of the display.
1946blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
1947} else {
1948uint8_t *appleBootPict;
1949bootImageData = NULL;
1950bootImageWidth = kAppleBootWidth;
1951bootImageHeight = kAppleBootHeight;
1952
1953// Prepare the data for the default Apple boot image.
1954appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
1955if (appleBootPict) {
1956convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
1957if (bootImageData) {
1958x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
1959y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
1960drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
1961free(bootImageData);
1962}
1963free(appleBootPict);
1964}
1965}
1966}
1967

Archive Download this file

Revision: 1441