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