Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2406