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