Chameleon

Chameleon Svn Source Tree

Root/branches/prasys/i386/boot2/gui.c

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

Archive Download this file

Revision: 33