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