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