Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 296