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