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