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