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