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