Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2391