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