Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/boot2/gui.c

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

Archive Download this file

Revision: 2245