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