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