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 | // 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 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 ever␊ |
195 | ␉// manualy generated, 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 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 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 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 | void fillPixmapWithColor(pixmap_t *pm, uint32_t color)␊ |
422 | {␊ |
423 | ␉int x,y;␊ |
424 | ␉␊ |
425 | ␉// fill with given color AARRGGBB␊ |
426 | ␉for( x=0; x < pm->width; x++ )␊ |
427 | ␉␉for( y=0; y< pm->height; y++)␊ |
428 | ␉␉␉pixel(pm,x,y).value = color;␊ |
429 | }␊ |
430 | ␊ |
431 | void drawBackground()␊ |
432 | {␊ |
433 | ␉// reset text cursor␊ |
434 | ␉gui.screen.cursor.x = gui.screen.hborder;␊ |
435 | ␉gui.screen.cursor.y = gui.screen.vborder;␊ |
436 | ␉␊ |
437 | ␉fillPixmapWithColor( gui.screen.pixmap, gui.screen.bgcolor);␊ |
438 | ␉␊ |
439 | ␉// draw background.png into background buffer␊ |
440 | ␉blend( images[iBackground].image, gui.screen.pixmap, gui.background.pos );␊ |
441 | ␉␊ |
442 | ␉// draw logo.png into background buffer␊ |
443 | ␉blend( images[iLogo].image, gui.screen.pixmap, gui.logo.pos);␊ |
444 | ␉␊ |
445 | ␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
446 | }␊ |
447 | ␊ |
448 | void loadThemeValues(config_file_t *theme, bool overide)␊ |
449 | {␊ |
450 | ␉unsigned int screen_width = gui.screen.width;␊ |
451 | ␉unsigned int screen_height = gui.screen.height;␊ |
452 | ␉unsigned int pixel;␊ |
453 | ␉int␉alpha;␉␉␉␉// transparency level 0 (obligue) - 255 (transparent)␊ |
454 | ␉uint32_t color;␉␉␉// color value formatted RRGGBB␊ |
455 | ␉int val, len;␊ |
456 | ␉const char *string;␉␊ |
457 | ␊ |
458 | ␉/*␊ |
459 | ␉ * Parse screen parameters␊ |
460 | ␉ */␊ |
461 | ␉if(getColorForKey("screen_bgcolor", &color, theme ))␊ |
462 | ␉␉gui.screen.bgcolor = (color & 0x00FFFFFF);␊ |
463 | ␊ |
464 | ␉if(getIntForKey("screen_textmargin_h", &val, theme))␊ |
465 | ␉␉gui.screen.hborder = MIN( gui.screen.width , val );␊ |
466 | ␊ |
467 | ␉if(getIntForKey("screen_textmargin_v", &val, theme))␊ |
468 | ␉␉gui.screen.vborder = MIN( gui.screen.height , val );␊ |
469 | ␊ |
470 | ␉/*␊ |
471 | ␉ * Parse background parameters␊ |
472 | ␉ */␊ |
473 | ␉if(getDimensionForKey("background_pos_x", &pixel, theme, screen_width , images[iBackground].image->width ) )␊ |
474 | ␉␉gui.background.pos.x = pixel;␊ |
475 | ␊ |
476 | ␉if(getDimensionForKey("background_pos_y", &pixel, theme, screen_height , images[iBackground].image->height ) )␊ |
477 | ␉␉gui.background.pos.y = pixel;␊ |
478 | ␊ |
479 | ␉/*␊ |
480 | ␉ * Parse logo parameters␊ |
481 | ␉ */␊ |
482 | ␉if(getDimensionForKey("logo_pos_x", &pixel, theme, screen_width , images[iLogo].image->width ) )␊ |
483 | ␉␉gui.logo.pos.x = pixel;␊ |
484 | ␊ |
485 | ␉if(getDimensionForKey("logo_pos_y", &pixel, theme, screen_height , images[iLogo].image->height ) )␊ |
486 | ␉␉gui.logo.pos.y = pixel;␊ |
487 | ␊ |
488 | ␉/*␊ |
489 | ␉ * Parse progress bar parameters␊ |
490 | ␉ */␊ |
491 | ␉if(getDimensionForKey("progressbar_pos_x", &pixel, theme, screen_width , 0 ) )␊ |
492 | ␉␉gui.progressbar.pos.x = pixel;␊ |
493 | ␊ |
494 | ␉if(getDimensionForKey("progressbar_pos_y", &pixel, theme, screen_height , 0 ) )␊ |
495 | ␉␉gui.progressbar.pos.y = pixel;␊ |
496 | ␊ |
497 | ␉/*␊ |
498 | ␉ * Parse countdown text parameters␊ |
499 | ␉ */␊ |
500 | ␉if(getDimensionForKey("countdown_pos_x", &pixel, theme, screen_width , 0 ) )␊ |
501 | ␉␉gui.countdown.pos.x = pixel;␊ |
502 | ␊ |
503 | ␉if(getDimensionForKey("countdown_pos_y", &pixel, theme, screen_height , 0 ) )␊ |
504 | ␉␉gui.countdown.pos.y = pixel;␊ |
505 | ␊ |
506 | ␉/*␊ |
507 | ␉ * Parse devicelist parameters␊ |
508 | ␉ */␊ |
509 | ␉if(getIntForKey("devices_max_visible", &val, theme ))␊ |
510 | ␉␉gui.maxdevices = MIN( val, gDeviceCount );␊ |
511 | ␊ |
512 | ␉if(getIntForKey("devices_iconspacing", &val, theme ))␊ |
513 | ␉␉gui.devicelist.iconspacing = val;␊ |
514 | ␊ |
515 | ␉// check layout for horizontal or vertical␊ |
516 | ␉gui.layout = HorizontalLayout;␊ |
517 | ␉if(getValueForKey( "devices_layout", &string, &len, theme)) {␊ |
518 | ␉␉if (!strcmp (string, "vertical")) {␊ |
519 | ␉␉␉gui.layout = VerticalLayout;␊ |
520 | ␉␉}␊ |
521 | ␉}␊ |
522 | ␊ |
523 | ␉switch (gui.layout) {␊ |
524 | ␉case VerticalLayout:␊ |
525 | ␉␉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);␊ |
526 | ␉␉gui.devicelist.width = (images[iSelection].image->width + gui.devicelist.iconspacing);␊ |
527 | ␊ |
528 | ␉␉if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , images[iSelection].image->width ) )␊ |
529 | ␉␉␉gui.devicelist.pos.x = pixel;␊ |
530 | ␊ |
531 | ␉␉if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , gui.devicelist.height ) )␊ |
532 | ␉␉␉gui.devicelist.pos.y = pixel;␊ |
533 | ␉␉break;␊ |
534 | ␉␉␊ |
535 | ␉case HorizontalLayout:␊ |
536 | ␉default:␊ |
537 | ␉␉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);␊ |
538 | ␉␉gui.devicelist.height = (images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing);␊ |
539 | ␊ |
540 | ␉␉if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , gui.devicelist.width ) )␊ |
541 | ␉␉␉gui.devicelist.pos.x = pixel;␊ |
542 | ␉␉else␊ |
543 | ␉␉␉gui.devicelist.pos.x = ( gui.screen.width - gui.devicelist.width ) / 2;␊ |
544 | ␉␉␊ |
545 | ␉␉if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , images[iSelection].image->height ) )␊ |
546 | ␉␉␉gui.devicelist.pos.y = pixel;␊ |
547 | ␉␉else␊ |
548 | ␉␉␉gui.devicelist.pos.y = ( gui.screen.height - gui.devicelist.height ) / 2;␊ |
549 | ␉␉break;␊ |
550 | ␉}␊ |
551 | ␊ |
552 | ␉if(getColorForKey("devices_bgcolor", &color, theme))␊ |
553 | ␉␉gui.devicelist.bgcolor = (color & 0x00FFFFFF);␊ |
554 | ␊ |
555 | ␉if(getIntForKey("devices_transparency", &alpha, theme))␊ |
556 | ␉␉gui.devicelist.bgcolor = gui.devicelist.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␊ |
557 | ␊ |
558 | ␉/*␊ |
559 | ␉ * Parse infobox parameters␊ |
560 | ␉ */␊ |
561 | ␉if(getIntForKey("infobox_width", &val, theme))␊ |
562 | ␉␉gui.infobox.width = MIN( screen_width , val );␊ |
563 | ␊ |
564 | ␉if(getIntForKey("infobox_height", &val, theme))␊ |
565 | ␉␉gui.infobox.height = MIN( screen_height , val );␊ |
566 | ␊ |
567 | ␉if(getDimensionForKey("infobox_pos_x", &pixel, theme, screen_width , gui.infobox.width ) )␊ |
568 | ␉␉gui.infobox.pos.x = pixel;␊ |
569 | ␊ |
570 | ␉if(getDimensionForKey("infobox_pos_y", &pixel, theme, screen_height , gui.infobox.height ) )␊ |
571 | ␉␉gui.infobox.pos.y = pixel;␊ |
572 | ␊ |
573 | ␉if(getIntForKey("infobox_textmargin_h", &val, theme))␊ |
574 | ␉␉gui.infobox.hborder = MIN( gui.infobox.width , val );␊ |
575 | ␊ |
576 | ␉if(getIntForKey("infobox_textmargin_v", &val, theme))␊ |
577 | ␉␉gui.infobox.vborder = MIN( gui.infobox.height , val );␊ |
578 | ␊ |
579 | ␉if(getColorForKey("infobox_bgcolor", &color, theme))␊ |
580 | ␉␉gui.infobox.bgcolor = (color & 0x00FFFFFF);␊ |
581 | ␊ |
582 | ␉if(getIntForKey("infobox_transparency", &alpha, theme))␊ |
583 | ␉␉gui.infobox.bgcolor = gui.infobox.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␊ |
584 | ␊ |
585 | ␉/*␊ |
586 | ␉ * Parse menu parameters␊ |
587 | ␉ */␊ |
588 | ␉if(getDimensionForKey("menu_width", &pixel, theme, gui.screen.width , 0 ) )␊ |
589 | ␉␉gui.menu.width = pixel;␊ |
590 | ␉else␊ |
591 | ␉␉gui.menu.width = images[iMenuSelection].image->width;␊ |
592 | ␊ |
593 | ␉if(getDimensionForKey("menu_height", &pixel, theme, gui.screen.height , 0 ) )␊ |
594 | ␉␉gui.menu.height = pixel;␊ |
595 | ␉else␊ |
596 | ␉␉gui.menu.height = (infoMenuItemsCount) * images[iMenuSelection].image->height;␊ |
597 | ␊ |
598 | ␉if(getDimensionForKey("menu_pos_x", &pixel, theme, screen_width , gui.menu.width ) )␊ |
599 | ␉␉gui.menu.pos.x = pixel;␊ |
600 | ␊ |
601 | ␉if(getDimensionForKey("menu_pos_y", &pixel, theme, screen_height , gui.menu.height ) )␊ |
602 | ␉␉gui.menu.pos.y = pixel;␊ |
603 | ␊ |
604 | ␉if(getIntForKey("menu_textmargin_h", &val, theme))␊ |
605 | ␉␉gui.menu.hborder = MIN( gui.menu.width , val );␊ |
606 | ␊ |
607 | ␉if(getIntForKey("menu_textmargin_v", &val, theme))␊ |
608 | ␉␉gui.menu.vborder = MIN( gui.menu.height , val );␊ |
609 | ␊ |
610 | ␉if(getColorForKey("menu_bgcolor", &color, theme))␊ |
611 | ␉␉gui.menu.bgcolor = (color & 0x00FFFFFF);␊ |
612 | ␊ |
613 | ␉if(getIntForKey("menu_transparency", &alpha, theme))␊ |
614 | ␉␉gui.menu.bgcolor = gui.menu.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␉␉␊ |
615 | ␊ |
616 | ␉/*␊ |
617 | ␉ * Parse bootprompt parameters␊ |
618 | ␉ */␊ |
619 | ␉if(getDimensionForKey("bootprompt_width", &pixel, theme, screen_width , 0 ) )␊ |
620 | ␉␉gui.bootprompt.width = pixel;␊ |
621 | ␊ |
622 | ␉if(getIntForKey("bootprompt_height", &val, theme))␊ |
623 | ␉␉gui.bootprompt.height = MIN( screen_height , val );␊ |
624 | ␊ |
625 | ␉if(getDimensionForKey("bootprompt_pos_x", &pixel, theme, screen_width , gui.bootprompt.width ) )␊ |
626 | ␉␉gui.bootprompt.pos.x = pixel;␊ |
627 | ␊ |
628 | ␉if(getDimensionForKey("bootprompt_pos_y", &pixel, theme, screen_height , gui.bootprompt.height ) )␊ |
629 | ␉␉gui.bootprompt.pos.y = pixel;␊ |
630 | ␊ |
631 | ␉if(getIntForKey("bootprompt_textmargin_h", &val, theme))␊ |
632 | ␉␉gui.bootprompt.hborder = MIN( gui.bootprompt.width , val );␊ |
633 | ␊ |
634 | ␉if(getIntForKey("bootprompt_textmargin_v", &val, theme))␊ |
635 | ␉␉gui.bootprompt.vborder = MIN( gui.bootprompt.height , val );␊ |
636 | ␊ |
637 | ␉if(getColorForKey("bootprompt_bgcolor", &color, theme))␊ |
638 | ␉␉gui.bootprompt.bgcolor = (color & 0x00FFFFFF);␊ |
639 | ␊ |
640 | ␉if(getIntForKey("bootprompt_transparency", &alpha, theme))␊ |
641 | ␉␉gui.bootprompt.bgcolor = gui.bootprompt.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␊ |
642 | ␊ |
643 | ␉if(getColorForKey("font_small_color", &color, theme))␊ |
644 | ␉␉gui.screen.font_small_color = (color & 0x00FFFFFF);␊ |
645 | ␊ |
646 | ␉if(getColorForKey("font_console_color", &color, theme))␊ |
647 | ␉␉gui.screen.font_console_color = (color & 0x00FFFFFF);␊ |
648 | }␊ |
649 | ␊ |
650 | int initGUI(void)␊ |
651 | {␊ |
652 | ␉int␉␉val;␊ |
653 | ␉int␉len;␊ |
654 | ␉char␉dirspec[256];␊ |
655 | ␊ |
656 | ␉getValueForKey( "Theme", &theme_name, &len, &bootInfo->bootConfig );␊ |
657 | ␉if ((strlen(theme_name) + 27) > sizeof(dirspec)) {␊ |
658 | ␉␉return 1;␊ |
659 | ␉}␊ |
660 | ␉sprintf(dirspec, "/Extra/Themes/%s/theme.plist", theme_name);␊ |
661 | ␉if (loadConfigFile(dirspec, &bootInfo->themeConfig) != 0) {␊ |
662 | #ifdef EMBED_THEME␊ |
663 | config_file_t␉*config;␊ |
664 | ␊ |
665 | config = &bootInfo->themeConfig;␊ |
666 | if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) {␊ |
667 | return 1;␊ |
668 | }␊ |
669 | #else␊ |
670 | ␉␉return 1;␊ |
671 | #endif␊ |
672 | ␉}␊ |
673 | ␉// parse display size parameters␊ |
674 | ␉if (getIntForKey("screen_width", &val, &bootInfo->themeConfig) && val > 0) {␊ |
675 | ␉␉screen_params[0] = val;␊ |
676 | ␉}␊ |
677 | ␉if (getIntForKey("screen_height", &val, &bootInfo->themeConfig) && val > 0) {␊ |
678 | ␉␉screen_params[1] = val;␊ |
679 | ␉}␊ |
680 | ␊ |
681 | ␉// Initalizing GUI strucutre.␊ |
682 | ␉bzero(&gui, sizeof(gui_t));␊ |
683 | ␉␊ |
684 | ␉// find best matching vesa mode for our requested width & height␊ |
685 | ␉getGraphicModeParams(screen_params);␊ |
686 | ␊ |
687 | ␉// set our screen structure with the mode width & height␊ |
688 | ␉gui.screen.width = screen_params[0];␉␊ |
689 | ␉gui.screen.height = screen_params[1];␊ |
690 | ␊ |
691 | ␉// load graphics otherwise fail and return␊ |
692 | ␉if (loadGraphics() == 0) {␊ |
693 | ␉␉loadThemeValues(&bootInfo->themeConfig, true);␊ |
694 | ␉␉colorFont(&font_small, gui.screen.font_small_color);␊ |
695 | ␉␉colorFont(&font_console, gui.screen.font_console_color);␊ |
696 | ␊ |
697 | ␉␉// create the screen & window buffers␊ |
698 | ␉␉if (createBackBuffer(&gui.screen) == 0) {␊ |
699 | ␉␉␉if (createWindowBuffer(&gui.screen) == 0) {␊ |
700 | ␉␉␉␉if (createWindowBuffer(&gui.devicelist) == 0) {␊ |
701 | ␉␉␉␉␉if (createWindowBuffer(&gui.bootprompt) == 0) {␊ |
702 | ␉␉␉␉␉␉if (createWindowBuffer(&gui.infobox) == 0) {␊ |
703 | ␉␉␉␉␉␉␉if (createWindowBuffer(&gui.menu) == 0) {␉␉␉␉␉␉␉␊ |
704 | ␉␉␉␉␉␉␉␉drawBackground();␊ |
705 | ␉␉␉␉␉␉␉␉// lets copy the screen into the back buffer␊ |
706 | ␉␉␉␉␉␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
707 | ␉␉␉␉␉␉␉␉setVideoMode( GRAPHICS_MODE, 0 );␊ |
708 | ␉␉␉␉␉␉␉␉gui.initialised = true;␊ |
709 | ␉␉␉␉␉␉␉␉return 0;␊ |
710 | ␉␉␉␉␉␉␉}␊ |
711 | ␉␉␉␉␉␉}␊ |
712 | ␉␉␉␉␉}␊ |
713 | ␉␉␉␉}␊ |
714 | ␉␉␉}␊ |
715 | ␉␉}␊ |
716 | ␉}␊ |
717 | ␉return 1;␊ |
718 | }␊ |
719 | ␊ |
720 | void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected)␊ |
721 | {␊ |
722 | ␉int devicetype;␊ |
723 | ␊ |
724 | ␉if( diskIsCDROM(device) )␊ |
725 | ␉␉devicetype = iDeviceCDROM;␉␉␉␉// Use CDROM icon␊ |
726 | ␉else␊ |
727 | ␉{␉␊ |
728 | ␉␉switch (device->part_type)␊ |
729 | ␉␉{␊ |
730 | ␉␉␉case kPartitionTypeHFS:␊ |
731 | ␊ |
732 | ␉␉␉␉// Use HFS or HFSRAID icon depending on bvr flags.␊ |
733 | ␉␉␉␉devicetype = (device->flags & kBVFlagBooter) ? iDeviceHFSRAID : iDeviceHFS;␊ |
734 | ␉␉␉␉break;␊ |
735 | ␊ |
736 | ␉␉␉case kPartitionTypeHPFS:␊ |
737 | ␉␉␉␉devicetype = iDeviceNTFS;␉␉// Use HPFS / NTFS icon␊ |
738 | ␉␉␉␉break;␊ |
739 | ␊ |
740 | ␉␉␉case kPartitionTypeFAT16:␊ |
741 | ␉␉␉␉devicetype = iDeviceFAT16;␉␉// Use FAT16 icon␊ |
742 | ␉␉␉␉break;␊ |
743 | ␊ |
744 | ␉␉␉case kPartitionTypeFAT32:␊ |
745 | ␉␉␉␉devicetype = iDeviceFAT32;␉␉// Use FAT32 icon␊ |
746 | ␉␉␉␉break;␊ |
747 | ␊ |
748 | ␉␉␉case kPartitionTypeEXT3:␊ |
749 | ␉␉␉␉devicetype = iDeviceEXT3;␉␉// Use EXT2/3 icon␊ |
750 | ␉␉␉␉break;␊ |
751 | ␊ |
752 | ␉␉␉default:␊ |
753 | ␉␉␉␉devicetype = iDeviceGeneric;␉// Use Generic icon␊ |
754 | ␉␉␉␉break;␊ |
755 | ␉␉}␊ |
756 | ␉}␊ |
757 | ␉␊ |
758 | ␉// Draw the selection image and use the next (device_*_o) image for the selected item.␊ |
759 | if (isSelected)␊ |
760 | ␉{␊ |
761 | ␉␉blend(images[iSelection].image, buffer, centeredAt(images[iSelection].image, p));␊ |
762 | ␉␉devicetype++;␊ |
763 | ␉}␊ |
764 | ␊ |
765 | ␉// draw icon␊ |
766 | ␉blend( images[devicetype].image, buffer, centeredAt( images[devicetype].image, p ));␊ |
767 | ␉␊ |
768 | ␉p.y += (images[iSelection].image->height / 2) + font_console.chars[0]->height;␊ |
769 | ␉␊ |
770 | ␉// draw volume label ␊ |
771 | ␉drawStrCenteredAt( device->label, &font_small, buffer, p);␉␊ |
772 | ␊ |
773 | }␊ |
774 | ␊ |
775 | void drawDeviceList (int start, int end, int selection)␊ |
776 | {␊ |
777 | ␉int i;␊ |
778 | ␉position_t p, p_prev, p_next;␊ |
779 | ␊ |
780 | ␉//uint8_t␉maxDevices = MIN( gui.maxdevices, menucount );␊ |
781 | ␉␉␊ |
782 | ␉fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);␊ |
783 | ␊ |
784 | ␉makeRoundedCorners( gui.devicelist.pixmap);␊ |
785 | ␊ |
786 | ␉switch (gui.layout)␊ |
787 | ␉{␊ |
788 | ␊ |
789 | ␉␉case VerticalLayout:␊ |
790 | ␉␉␉p.x = (gui.devicelist.width /2);␊ |
791 | ␉␉␉p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );␊ |
792 | ␊ |
793 | ␉␉␉// place scroll indicators at top & bottom edges␊ |
794 | ␉␉␉p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );␊ |
795 | ␉␉␉p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );␊ |
796 | ␉␉␉␊ |
797 | ␉␉␉break;␊ |
798 | ␉␉␉␊ |
799 | ␉␉default:␉// use Horizontal layout as the default␊ |
800 | ␊ |
801 | ␉␉case HorizontalLayout:␊ |
802 | ␉␉␉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;␊ |
803 | ␉␉␉p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );␊ |
804 | ␊ |
805 | ␉␉␉// place scroll indicators at left & right edges␊ |
806 | ␉␉␉p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );␊ |
807 | ␉␉␉p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );␊ |
808 | ␉␉␉␊ |
809 | ␉␉␉break;␊ |
810 | ␉␉␉␊ |
811 | ␉}␊ |
812 | ␉␊ |
813 | ␉// draw visible device icons␊ |
814 | ␉for (i = 0; i < gui.maxdevices; i++)␊ |
815 | ␉{␊ |
816 | ␉␉BVRef param = menuItems[start + i].param;␊ |
817 | ␊ |
818 | bool isSelected = ((start + i) == selection) ? true : false;␊ |
819 | ␉␉if (isSelected)␊ |
820 | ␉␉{␊ |
821 | if (param->flags & kBVFlagNativeBoot)␊ |
822 | {␊ |
823 | infoMenuNativeBoot = true;␊ |
824 | }␊ |
825 | else␊ |
826 | {␊ |
827 | infoMenuNativeBoot = false;␊ |
828 | if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)␊ |
829 | infoMenuSelection = 0;␊ |
830 | }␊ |
831 | ␉␉␉ ␊ |
832 | ␉␉␉if(gui.menu.draw)␊ |
833 | ␉␉␉␉drawInfoMenuItems();␊ |
834 | ␉␉␉ ␊ |
835 | #if DEBUG␊ |
836 | gui.debug.cursor = pos( 10, 100);␊ |
837 | dprintf( &gui.screen, "label %s\n", param->label );␊ |
838 | dprintf( &gui.screen, "biosdev 0x%x\n", param->biosdev );␊ |
839 | dprintf(&gui.screen, "width %d\n", gui.screen.width);␊ |
840 | dprintf(&gui.screen, "height %d\n", gui.screen.height);␊ |
841 | dprintf( &gui.screen, "type 0x%x\n", param->type );␊ |
842 | dprintf( &gui.screen, "flags 0x%x\n", param->flags );␊ |
843 | dprintf( &gui.screen, "part_no %d\n", param->part_no );␊ |
844 | dprintf( &gui.screen, "part_boff 0x%x\n", param->part_boff );␊ |
845 | dprintf( &gui.screen, "part_type 0x%x\n", param->part_type );␊ |
846 | dprintf( &gui.screen, "bps 0x%x\n", param->bps );␊ |
847 | dprintf( &gui.screen, "name %s\n", param->name );␊ |
848 | dprintf( &gui.screen, "type_name %s\n", param->type_name );␊ |
849 | dprintf( &gui.screen, "modtime %d\n", param->modTime );␊ |
850 | #endif␊ |
851 | ␉␉}␊ |
852 | ␉␉␊ |
853 | ␉␉drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);␊ |
854 | ␉␉␊ |
855 | ␉␉if (gui.layout == HorizontalLayout)␊ |
856 | ␉␉{␊ |
857 | ␉␉␉p.x += images[iSelection].image->width + gui.devicelist.iconspacing; ␊ |
858 | ␉␉}␊ |
859 | ␉␉if (gui.layout == VerticalLayout)␊ |
860 | ␉␉{␊ |
861 | ␉␉␉p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing ); ␊ |
862 | ␉␉}␊ |
863 | ␉}␊ |
864 | ␊ |
865 | ␉// draw prev indicator␊ |
866 | ␉if(start)␊ |
867 | ␉␉blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );␊ |
868 | ␊ |
869 | ␉// draw next indicator␊ |
870 | ␉if( end < gDeviceCount - 1 )␊ |
871 | ␉␉blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );␊ |
872 | ␊ |
873 | ␉gui.redraw = true;␊ |
874 | ␉␊ |
875 | ␉updateVRAM();␊ |
876 | ␉␊ |
877 | }␊ |
878 | ␊ |
879 | void clearGraphicBootPrompt()␊ |
880 | {␊ |
881 | ␉// clear text buffer␊ |
882 | ␉prompt[0] = '\0';␊ |
883 | ␉prompt_pos=0;␊ |
884 | ␊ |
885 | ␉␊ |
886 | ␉if(␉gui.bootprompt.draw == true )␊ |
887 | ␉{␊ |
888 | ␉␉gui.bootprompt.draw = false;␊ |
889 | ␉␉gui.redraw = true;␊ |
890 | ␉␉// this causes extra frames to be drawn␊ |
891 | ␉␉//updateVRAM();␊ |
892 | ␉}␊ |
893 | ␊ |
894 | ␉return;␊ |
895 | }␊ |
896 | ␊ |
897 | void updateGraphicBootPrompt(int key)␊ |
898 | {␊ |
899 | ␉if ( key == kBackspaceKey )␊ |
900 | ␉␉prompt[--prompt_pos] = '\0';␊ |
901 | ␉else ␊ |
902 | ␉{␊ |
903 | ␉␉prompt[prompt_pos] = key;␊ |
904 | ␉␉prompt_pos++;␊ |
905 | ␉␉prompt[prompt_pos] = '\0';␊ |
906 | ␉}␊ |
907 | ␊ |
908 | ␉fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);␊ |
909 | ␊ |
910 | ␉makeRoundedCorners( gui.bootprompt.pixmap);␊ |
911 | ␊ |
912 | ␉position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );␊ |
913 | ␊ |
914 | ␉// print the boot prompt text␊ |
915 | ␉drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);␊ |
916 | ␉␊ |
917 | ␉// get the position of the end of the boot prompt text to display user input␊ |
918 | ␉position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );␊ |
919 | ␊ |
920 | ␉// calculate the position of the cursor␊ |
921 | ␉int␉offset = ( prompt_pos - ( ( gui.bootprompt.width / font_console.chars[0]->width ) - strlen(prompt_text) - 2 ) );␉␊ |
922 | ␊ |
923 | ␉if ( offset < 0)␊ |
924 | ␉␉offset = 0;␊ |
925 | ␉␊ |
926 | ␉drawStr( prompt+offset, &font_console, gui.bootprompt.pixmap, p_prompt);␊ |
927 | ␊ |
928 | ␉gui.menu.draw = false;␊ |
929 | ␉gui.bootprompt.draw = true;␊ |
930 | ␉gui.redraw = true;␊ |
931 | ␉␊ |
932 | ␉updateVRAM();␊ |
933 | ␉␊ |
934 | ␉return;␊ |
935 | }␊ |
936 | ␊ |
937 | inline␊ |
938 | void vramwrite (void *data, int width, int height)␊ |
939 | {␊ |
940 | ␉if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)␊ |
941 | ␉␉memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));␊ |
942 | ␉else␊ |
943 | ␉{␊ |
944 | ␉␉uint32_t r, g, b;␊ |
945 | ␉␉int i, j;␊ |
946 | ␉␉for (i = 0; i < VIDEO (height); i++)␊ |
947 | ␉␉␉for (j = 0; j < VIDEO (width); j++)␊ |
948 | ␉␉␉{␊ |
949 | ␉␉␉␉b = ((uint8_t *) data)[4*i*width + 4*j];␊ |
950 | ␉␉␉␉g = ((uint8_t *) data)[4*i*width + 4*j + 1];␊ |
951 | ␉␉␉␉r = ((uint8_t *) data)[4*i*width + 4*j + 2];␊ |
952 | ␉␉␉␉switch (VIDEO (depth))␊ |
953 | ␉␉␉␉{␊ |
954 | ␉␉␉␉␉case 32:␊ |
955 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
956 | ␉␉␉␉␉␉break;␊ |
957 | ␉␉␉␉␉case 24:␊ |
958 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)␊ |
959 | ␉␉␉␉␉␉| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
960 | ␉␉␉␉␉␉break;␊ |
961 | ␉␉␉␉␉case 16:␊ |
962 | ␉␉␉␉␉␉// Somehow 16-bit is always 15-bits really␊ |
963 | ␉␉␉␉␉␉//␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);␊ |
964 | ␉␉␉␉␉␉//␉␉␉␉␉␉break;␉␉␉␉␉␉␉␊ |
965 | ␉␉␉␉␉case 15:␊ |
966 | ␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);␊ |
967 | ␉␉␉␉␉␉break;␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
968 | ␉␉␉␉}␊ |
969 | ␉␉␉}␊ |
970 | ␉}␊ |
971 | }␊ |
972 | ␊ |
973 | void updateVRAM()␊ |
974 | {␊ |
975 | ␉if (gui.redraw)␊ |
976 | ␉{␊ |
977 | ␉␉if (gui.devicelist.draw)␊ |
978 | ␉␉␉blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );␊ |
979 | ␊ |
980 | ␉␉if (gui.bootprompt.draw)␊ |
981 | ␉␉␉blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );␊ |
982 | ␉␉␉␉␊ |
983 | ␉␉if (gui.menu.draw)␊ |
984 | ␉␉␉blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );␊ |
985 | ␉␉␊ |
986 | ␉␉if (gui.infobox.draw)␊ |
987 | ␉␉␉blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );␊ |
988 | ␉}␊ |
989 | ␉␊ |
990 | ␉vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );␊ |
991 | ␊ |
992 | ␉if (gui.redraw)␊ |
993 | ␉{␊ |
994 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
995 | ␉␉gui.redraw = false;␊ |
996 | ␉}␊ |
997 | }␊ |
998 | ␊ |
999 | struct putc_info {␊ |
1000 | char * str;␊ |
1001 | char * last_str;␊ |
1002 | };␊ |
1003 | ␊ |
1004 | static void␊ |
1005 | sputc(int c, struct putc_info * pi)␊ |
1006 | {␊ |
1007 | if (pi->last_str)␊ |
1008 | if (pi->str == pi->last_str) {␊ |
1009 | *(pi->str) = '\0';␊ |
1010 | return;␊ |
1011 | }␊ |
1012 | *(pi->str)++ = c;␊ |
1013 | }␊ |
1014 | ␊ |
1015 | int gprintf( window_t * window, const char * fmt, ...)␊ |
1016 | {␊ |
1017 | ␉char *formattedtext;␊ |
1018 | ␊ |
1019 | ␉va_list ap;␊ |
1020 | ␉␊ |
1021 | ␉struct putc_info pi;␊ |
1022 | ␊ |
1023 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1024 | ␉␉// format the text␊ |
1025 | ␉␉va_start(ap, fmt);␊ |
1026 | ␉␉pi.str = formattedtext;␊ |
1027 | ␉␉pi.last_str = 0;␊ |
1028 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1029 | ␉␉*pi.str = '\0';␊ |
1030 | ␉␉va_end(ap);␊ |
1031 | ␉␉␊ |
1032 | ␉␉position_t␉origin, cursor, bounds;␊ |
1033 | ␊ |
1034 | ␉␉int i;␊ |
1035 | ␉␉int character;␊ |
1036 | ␊ |
1037 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1038 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1039 | ␉␉␊ |
1040 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1041 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1042 | ␉␉␊ |
1043 | ␉␉cursor = origin;␊ |
1044 | ␉␉␉␊ |
1045 | ␉␉font_t *font = &font_console;␊ |
1046 | ␉␉␉␊ |
1047 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1048 | ␉␉{␊ |
1049 | ␉␉␉character = formattedtext[i];␊ |
1050 | ␉␉␉␊ |
1051 | ␉␉␉character -= 32;␊ |
1052 | ␉␉␉␉␊ |
1053 | ␉␉␉// newline ?␊ |
1054 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1055 | ␉␉␉{␊ |
1056 | ␉␉␉␉cursor.x = window->hborder;␊ |
1057 | ␉␉␉␉cursor.y += font->height;␊ |
1058 | ␊ |
1059 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1060 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1061 | ␊ |
1062 | ␉␉␉␉continue;␊ |
1063 | ␉␉␉}␊ |
1064 | ␉␉␉␉␊ |
1065 | ␉␉␉// tab ?␊ |
1066 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1067 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1068 | ␉␉␉␊ |
1069 | ␉␉␉// draw the character␊ |
1070 | ␉␉␉if( font->chars[character])␊ |
1071 | ␉␉␉␉blend(font->chars[character], window->pixmap, cursor);␊ |
1072 | ␊ |
1073 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1074 | ␊ |
1075 | ␉␉␉// check x pos and do newline␊ |
1076 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1077 | ␉␉␉{␊ |
1078 | ␉␉␉␉cursor.x = origin.x;␊ |
1079 | ␉␉␉␉cursor.y += font->height;␊ |
1080 | ␉␉␉}␊ |
1081 | ␉␉␉␊ |
1082 | ␉␉␉// check y pos and reset to origin.y␊ |
1083 | ␉␉␉if ( cursor.y > bounds.y )␊ |
1084 | ␉␉␉␉cursor.y = origin.y;␊ |
1085 | ␉␉}␊ |
1086 | ␊ |
1087 | ␉␉// update cursor postition␊ |
1088 | ␉␉window->cursor = cursor;␊ |
1089 | ␉␉␊ |
1090 | ␉␉free(formattedtext);␊ |
1091 | ␉␉␊ |
1092 | ␉␉return 0;␊ |
1093 | ␊ |
1094 | ␉}␊ |
1095 | ␉return 1;␊ |
1096 | }␊ |
1097 | ␊ |
1098 | int dprintf( window_t * window, const char * fmt, ...)␊ |
1099 | {␊ |
1100 | ␉char *formattedtext;␊ |
1101 | ␉␊ |
1102 | ␉va_list ap;␊ |
1103 | ␉␊ |
1104 | ␉//window = &gui.debug;␊ |
1105 | ␉␊ |
1106 | ␉struct putc_info pi;␊ |
1107 | ␉␊ |
1108 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1109 | ␉␉// format the text␊ |
1110 | ␉␉va_start(ap, fmt);␊ |
1111 | ␉␉pi.str = formattedtext;␊ |
1112 | ␉␉pi.last_str = 0;␊ |
1113 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1114 | ␉␉*pi.str = '\0';␊ |
1115 | ␉␉va_end(ap);␊ |
1116 | ␉␉␊ |
1117 | ␉␉position_t␉origin, cursor, bounds;␊ |
1118 | ␉␉␊ |
1119 | ␉␉int i;␊ |
1120 | ␉␉int character;␊ |
1121 | ␉␉␊ |
1122 | ␉␉origin.x = MAX( gui.debug.cursor.x, window->hborder );␊ |
1123 | ␉␉origin.y = MAX( gui.debug.cursor.y, window->vborder );␊ |
1124 | ␉␉␊ |
1125 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1126 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1127 | ␉␉␊ |
1128 | ␉␉cursor = origin;␊ |
1129 | ␉␉␊ |
1130 | ␉␉font_t *font = &font_console;␊ |
1131 | ␉␉␊ |
1132 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1133 | ␉␉{␊ |
1134 | ␉␉␉character = formattedtext[i];␊ |
1135 | ␉␉␉␊ |
1136 | ␉␉␉character -= 32;␊ |
1137 | ␉␉␉␊ |
1138 | ␉␉␉// newline ?␊ |
1139 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1140 | ␉␉␉{␊ |
1141 | ␉␉␉␉cursor.x = window->hborder;␊ |
1142 | ␉␉␉␉cursor.y += font->height;␊ |
1143 | ␉␉␉␉␊ |
1144 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1145 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1146 | ␉␉␉␉␊ |
1147 | ␉␉␉␉continue;␊ |
1148 | ␉␉␉}␊ |
1149 | ␉␉␉␊ |
1150 | ␉␉␉// tab ?␊ |
1151 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1152 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1153 | ␉␉␉␊ |
1154 | ␉␉␉// draw the character␊ |
1155 | ␉␉␉if( font->chars[character])␊ |
1156 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1157 | ␊ |
1158 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1159 | ␉␉␉␊ |
1160 | ␉␉␉// check x pos and do newline␊ |
1161 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1162 | ␉␉␉{␊ |
1163 | ␉␉␉␉cursor.x = origin.x;␊ |
1164 | ␉␉␉␉cursor.y += font->height;␊ |
1165 | ␉␉␉}␊ |
1166 | ␉␉␉␊ |
1167 | ␉␉␉// check y pos and reset to origin.y␊ |
1168 | ␉␉␉if ( cursor.y > bounds.y )␊ |
1169 | ␉␉␉␉cursor.y = origin.y;␊ |
1170 | ␉␉}␊ |
1171 | ␉␉␊ |
1172 | ␉␉// update cursor postition␊ |
1173 | ␉␉gui.debug.cursor = cursor;␊ |
1174 | ␉␉␊ |
1175 | ␉␉free(formattedtext);␊ |
1176 | ␉␉␊ |
1177 | ␉␉return 0;␊ |
1178 | ␉␉␊ |
1179 | ␉}␊ |
1180 | ␉return 1;␊ |
1181 | }␊ |
1182 | ␊ |
1183 | int vprf(const char * fmt, va_list ap)␊ |
1184 | {␊ |
1185 | ␉int i;␊ |
1186 | ␉int character;␊ |
1187 | ␊ |
1188 | ␉char *formattedtext;␊ |
1189 | ␉window_t *window = &gui.screen;␊ |
1190 | ␉struct putc_info pi;␊ |
1191 | ␉␊ |
1192 | ␉position_t␉origin, cursor, bounds;␊ |
1193 | ␉font_t *font = &font_console;␊ |
1194 | ␉␊ |
1195 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1196 | ␉␉// format the text␊ |
1197 | ␉␉pi.str = formattedtext;␊ |
1198 | ␉␉pi.last_str = 0;␊ |
1199 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1200 | ␉␉*pi.str = '\0';␊ |
1201 | ␉␉␊ |
1202 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1203 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1204 | ␉␉bounds.x = ( window->width - ( window->hborder * 2 ) );␊ |
1205 | ␉␉bounds.y = ( window->height - ( window->vborder * 2 ) );␊ |
1206 | ␉␉cursor = origin;␊ |
1207 | ␉␉␉␊ |
1208 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1209 | ␉␉{␊ |
1210 | ␉␉␉character = formattedtext[i];␊ |
1211 | ␉␉␉character -= 32;␊ |
1212 | ␉␉␉␊ |
1213 | ␉␉␉// newline ?␊ |
1214 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1215 | ␉␉␉{␊ |
1216 | ␉␉␉␉cursor.x = window->hborder;␊ |
1217 | ␉␉␉␉cursor.y += font->height;␊ |
1218 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1219 | ␉␉␉␉{␊ |
1220 | ␉␉␉␉␉gui.redraw = true;␊ |
1221 | ␉␉␉␉␉updateVRAM();␊ |
1222 | ␉␉␉␉␉cursor.y = window->vborder;␊ |
1223 | ␉␉␉␉}␊ |
1224 | ␉␉␉␉window->cursor.y = cursor.y;␊ |
1225 | ␉␉␉␉continue;␊ |
1226 | ␉␉␉}␊ |
1227 | ␊ |
1228 | ␉␉␉// tab ?␊ |
1229 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1230 | ␉␉␉{␊ |
1231 | ␉␉␉␉cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );␊ |
1232 | ␉␉␉␉continue;␊ |
1233 | ␉␉␉}␊ |
1234 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1235 | ␉␉␉␊ |
1236 | ␉␉␉// check x pos and do newline␊ |
1237 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1238 | ␉␉␉{␊ |
1239 | ␉␉␉␉cursor.x = origin.x;␊ |
1240 | ␉␉␉␉cursor.y += font->height;␊ |
1241 | ␉␉␉}␊ |
1242 | ␉␉␉␉␊ |
1243 | ␉␉␉// check y pos and reset to origin.y␊ |
1244 | ␉␉␉if ( cursor.y > ( bounds.y + font->chars[0]->height) )␊ |
1245 | ␉␉␉{␊ |
1246 | ␉␉␉␉gui.redraw = true;␊ |
1247 | ␉␉␉␉updateVRAM();␊ |
1248 | ␉␉␉␉cursor.y = window->vborder;␊ |
1249 | ␉␉␉}␊ |
1250 | ␉␉␉// draw the character␊ |
1251 | ␉␉␉if( font->chars[character])␊ |
1252 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1253 | ␉␉}␊ |
1254 | ␉␉// save cursor postition␊ |
1255 | ␉␉window->cursor.x = cursor.x;␊ |
1256 | ␉␉updateVRAM();␊ |
1257 | ␉␉free(formattedtext);␊ |
1258 | ␉␉return 0;␊ |
1259 | ␉}␊ |
1260 | ␉return 1;␊ |
1261 | }␊ |
1262 | ␊ |
1263 | void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1264 | {␊ |
1265 | ␉int i=0;␊ |
1266 | ␉int y=0; // we need this to support multilines '\n'␊ |
1267 | ␉int x=0;␊ |
1268 | ␉␊ |
1269 | ␉for(i=0;i<strlen(ch);i++)␊ |
1270 | ␉{␊ |
1271 | ␉␉int cha=(int)ch[i];␊ |
1272 | ␉␉␊ |
1273 | ␉␉cha-=32;␊ |
1274 | ␉␉␊ |
1275 | ␉␉// newline ?␊ |
1276 | ␉␉if( ch[i] == '\n' )␊ |
1277 | ␉␉{␊ |
1278 | ␉␉␉x = 0;␊ |
1279 | ␉␉␉y += font->height;␊ |
1280 | ␉␉␉continue;␊ |
1281 | ␉␉}␊ |
1282 | ␉␉␊ |
1283 | ␉␉// tab ?␊ |
1284 | ␉␉if( ch[i] == '\t' )␊ |
1285 | ␉␉␉x+=(font->chars[0]->width*5);␊ |
1286 | ␉␉␊ |
1287 | ␉␉if(font->chars[cha])␊ |
1288 | ␉␉␉blend(font->chars[cha], blendInto, pos(p.x+x, p.y+y));␊ |
1289 | ␉␉␊ |
1290 | ␉␉x += font->chars[cha]->width;␊ |
1291 | ␉}␊ |
1292 | }␊ |
1293 | ␊ |
1294 | void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1295 | {␊ |
1296 | ␉int i = 0;␊ |
1297 | ␉int width = 0;␊ |
1298 | ␊ |
1299 | ␉// calculate the width in pixels␊ |
1300 | ␉for(i=0;i<strlen(text);i++)␊ |
1301 | ␉␉width += font->chars[text[i]-32]->width;␊ |
1302 | ␊ |
1303 | ␉p.x = ( p.x - ( width / 2 ) );␊ |
1304 | ␉p.y = ( p.y - ( font->height / 2 ) ); ␊ |
1305 | ␉␊ |
1306 | ␉if ( p.x == -6 )␊ |
1307 | ␉{␊ |
1308 | ␉␉p.x = 0;␊ |
1309 | ␉}␊ |
1310 | ␉␊ |
1311 | ␉for(i=0;i<strlen(text);i++)␊ |
1312 | ␉{␊ |
1313 | ␉␉int cha=(int)text[i];␊ |
1314 | ␉␉␊ |
1315 | ␉␉cha-=32;␊ |
1316 | ␊ |
1317 | ␉␉if(font->chars[cha])␊ |
1318 | ␉␉{␊ |
1319 | ␉␉␉blend(font->chars[cha], blendInto, p);␊ |
1320 | ␉␉␉p.x += font->chars[cha]->width;␊ |
1321 | ␉␉}␊ |
1322 | ␉}␊ |
1323 | ␉␊ |
1324 | }␊ |
1325 | ␊ |
1326 | int initFont(font_t *font, image_t *data)␊ |
1327 | {␊ |
1328 | ␉unsigned int x = 0, y = 0, x2 = 0, x3 = 0;␊ |
1329 | ␉␊ |
1330 | ␉int start = 0, end = 0, count = 0, space = 0;␊ |
1331 | ␉␊ |
1332 | ␉bool monospaced = false;␊ |
1333 | ␉␊ |
1334 | ␉font->height = data->image->height;␉␊ |
1335 | ␊ |
1336 | ␉for( x = 0; x < data->image->width; x++)␊ |
1337 | ␉{␊ |
1338 | ␉␉start = end;␊ |
1339 | ␉␉␉␉␊ |
1340 | ␉␉// if the pixel is red we've reached the end of the char␊ |
1341 | ␉␉if( pixel( data->image, x, 0 ).value == 0xFFFF0000)␊ |
1342 | ␉␉{␊ |
1343 | ␉␉␉end = x + 1;␊ |
1344 | ␊ |
1345 | ␉␉␉if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )␊ |
1346 | ␉␉␉{␊ |
1347 | ␉␉␉␉font->chars[count]->width = ( end - start) - 1;␊ |
1348 | ␉␉␉␉font->chars[count]->height = font->height;␊ |
1349 | ␉␉␉␊ |
1350 | ␉␉␉␉if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )␊ |
1351 | ␉␉␉␉{␊ |
1352 | ␉␉␉␉␉space += ( font->chars[count]->width * data->image->height * 4 );␊ |
1353 | ␉␉␉␉␉// we skip the first line because there are just the red pixels for the char width␊ |
1354 | ␉␉␉␉␉for( y = 1; y< (font->height); y++)␊ |
1355 | ␉␉␉␉␉{␊ |
1356 | ␉␉␉␉␉␉for( x2 = start, x3 = 0; x2 < end; x2++, x3++)␊ |
1357 | ␉␉␉␉␉␉{␊ |
1358 | ␉␉␉␉␉␉␉pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );␊ |
1359 | ␉␉␉␉␉␉}␉␊ |
1360 | ␉␉␉␉␉}␊ |
1361 | ␉␉␉␉␉␊ |
1362 | ␉␉␉␉␉// check if font is monospaced␊ |
1363 | ␉␉␉␉␉if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )␊ |
1364 | ␉␉␉␉␉␉monospaced = true;␊ |
1365 | ␉␉␉␉␉␉␊ |
1366 | ␉␉␉␉␉font->width = font->chars[count]->width;␊ |
1367 | ␉␉␉␉␉␊ |
1368 | ␉␉␉␉␉count++;␊ |
1369 | ␉␉␉␉}␊ |
1370 | ␉␉␉}␊ |
1371 | ␉␉}␊ |
1372 | ␉}␊ |
1373 | ␊ |
1374 | ␉if(monospaced)␊ |
1375 | ␉␉font->width = 0;␊ |
1376 | ␊ |
1377 | ␉return 0;␊ |
1378 | }␊ |
1379 | ␊ |
1380 | void colorFont(font_t *font, uint32_t color)␊ |
1381 | {␊ |
1382 | ␉if( !color )␊ |
1383 | ␉␉return;␊ |
1384 | ␉␊ |
1385 | ␉int x, y, width, height;␊ |
1386 | ␉int count = 0;␊ |
1387 | ␉pixel_t *buff;␊ |
1388 | ␉␊ |
1389 | ␉while( font->chars[count++] )␊ |
1390 | ␉{␊ |
1391 | ␉␉width = font->chars[count-1]->width;␊ |
1392 | ␉␉height = font->chars[count-1]->height;␊ |
1393 | ␉␉for( y = 0; y < height; y++ )␊ |
1394 | ␉␉{␊ |
1395 | ␉␉␉for( x = 0; x < width; x++ )␊ |
1396 | ␉␉␉{␊ |
1397 | ␉␉␉␉buff = &(pixel( font->chars[count-1], x, y ));␊ |
1398 | ␉␉␉␉if( buff->ch.a )␊ |
1399 | ␉␉␉␉{␊ |
1400 | ␉␉␉␉␉buff->ch.r = (color & 0xFFFF0000) >> 16;␊ |
1401 | ␉␉␉␉␉buff->ch.g = (color & 0xFF00FF00) >> 8;␊ |
1402 | ␉␉␉␉␉buff->ch.b = (color & 0xFF0000FF);␊ |
1403 | ␉␉␉␉}␊ |
1404 | ␉␉␉}␊ |
1405 | ␉␉}␊ |
1406 | ␉}␊ |
1407 | }␊ |
1408 | ␊ |
1409 | void makeRoundedCorners(pixmap_t *p)␊ |
1410 | {␊ |
1411 | ␉int x,y;␊ |
1412 | ␉int width=p->width-1;␊ |
1413 | ␉int height=p->height-1;␊ |
1414 | ␉␊ |
1415 | ␉// 10px rounded corner alpha values␊ |
1416 | ␉uint8_t roundedCorner[10][10] =␊ |
1417 | ␉{␊ |
1418 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},␊ |
1419 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1420 | ␉␉{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1421 | ␉␉{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1422 | ␉␉{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1423 | ␉␉{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1424 | ␉␉{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1425 | ␉␉{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1426 | ␉␉{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1427 | ␉␉{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}␊ |
1428 | ␉};␊ |
1429 | ␉␊ |
1430 | ␉uint8_t alpha=0;␊ |
1431 | ␉␊ |
1432 | ␉for( y=0; y<10; y++)␊ |
1433 | ␉{␊ |
1434 | ␉␉for( x=0; x<10; x++)␊ |
1435 | ␉␉{␊ |
1436 | ␉␉␉// skip if the pixel should be visible␊ |
1437 | ␉␉␉if(roundedCorner[y][x] != 0xFF) ␊ |
1438 | ␉␉␉{ ␊ |
1439 | ␉␉␉␉alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );␊ |
1440 | ␉␉␉␉// Upper left corner␊ |
1441 | ␉␉␉␉pixel(p, x, y).ch.a = alpha;␊ |
1442 | ␊ |
1443 | ␉␉␉␉// upper right corner␊ |
1444 | ␉␉␉␉pixel(p, width-x,y).ch.a = alpha;␊ |
1445 | ␊ |
1446 | ␉␉␉␉// lower left corner␊ |
1447 | ␉␉␉␉pixel(p, x, height-y).ch.a = alpha;␊ |
1448 | ␊ |
1449 | ␉␉␉␉// lower right corner␊ |
1450 | ␉␉␉␉pixel(p, width-x, height-y).ch.a = alpha;␊ |
1451 | ␉␉␉}␊ |
1452 | ␉␉}␊ |
1453 | ␉}␊ |
1454 | }␊ |
1455 | ␊ |
1456 | void showInfoBox(char *title, char *text)␊ |
1457 | {␊ |
1458 | ␉int i, key, lines, visiblelines;␊ |
1459 | ␊ |
1460 | ␉int currentline=0;␊ |
1461 | ␉int cnt=0;␊ |
1462 | ␉int offset=0;␊ |
1463 | ␉␊ |
1464 | ␉if( !title || !text )␊ |
1465 | ␉␉return;␊ |
1466 | ␉␊ |
1467 | ␉position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );␊ |
1468 | ␊ |
1469 | ␉// calculate number of lines in the title␊ |
1470 | ␉for ( i = 0, lines = 1; i<strlen(title); i++ )␊ |
1471 | ␉␉if( title[i] == '\n')␊ |
1472 | ␉␉␉lines++;␊ |
1473 | ␉␊ |
1474 | ␉// y position of text is lines in title * height of font␊ |
1475 | ␉position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));␊ |
1476 | ␉␊ |
1477 | ␉// calculate number of lines in the text␊ |
1478 | ␉for ( i=0, lines = 1; i<strlen(text); i++ )␊ |
1479 | ␉␉if( text[i] == '\n')␊ |
1480 | ␉␉␉lines++;␊ |
1481 | ␉␊ |
1482 | ␉// if text ends with \n strip off␊ |
1483 | ␉if( text[i] == '\n' || text[i] == '\0')␊ |
1484 | ␉␉lines--;␊ |
1485 | ␉␊ |
1486 | ␉visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;␊ |
1487 | ␉␊ |
1488 | ␉// lets display the text and allow scroll thru using up down / arrows␊ |
1489 | ␉while(1)␊ |
1490 | ␉{␊ |
1491 | ␉␉// move to current line in text␊ |
1492 | ␉␉for( offset = 0, i = 0; offset < strlen(text); offset++ )␊ |
1493 | ␉␉{␊ |
1494 | ␉␉␉if( currentline == i)␊ |
1495 | ␉␉␉␉break;␊ |
1496 | ␉␉␉if( text[offset] =='\n')␊ |
1497 | ␉␉␉␉i++;␊ |
1498 | ␉␉}␊ |
1499 | ␊ |
1500 | ␉␉// find last visible line in text and place \0␊ |
1501 | ␉␉for( i = offset, cnt = 0; i < strlen(text); i++)␊ |
1502 | ␉␉{␊ |
1503 | ␉␉␉if(text[i]=='\n')␊ |
1504 | ␉␉␉␉cnt++;␊ |
1505 | ␉␉␉if ( cnt == visiblelines )␊ |
1506 | ␉␉␉{␊ |
1507 | ␉␉␉␉text[i]='\0';␊ |
1508 | ␉␉␉␉break;␊ |
1509 | ␉␉␉}␊ |
1510 | ␉␉}␊ |
1511 | ␉␉␉␉␊ |
1512 | ␉␉fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);␊ |
1513 | ␊ |
1514 | ␉␉makeRoundedCorners( gui.infobox.pixmap);␊ |
1515 | ␉␉␉␊ |
1516 | ␉␉// print the title if present␊ |
1517 | ␉␉if( title )␊ |
1518 | ␉␉␉drawStr(title, &font_console, gui.infobox.pixmap, pos_title);␊ |
1519 | ␊ |
1520 | ␉␉// print the text␊ |
1521 | ␉␉drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);␊ |
1522 | ␊ |
1523 | ␉␉// restore \n in text␊ |
1524 | ␉␉if ( cnt == visiblelines )␊ |
1525 | ␉␉␉text[i] = '\n';␊ |
1526 | ␉␉␊ |
1527 | ␉␉position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );␊ |
1528 | ␉␉␊ |
1529 | ␉␉// draw prev indicator␊ |
1530 | ␉␉if(offset)␊ |
1531 | ␉␉{␊ |
1532 | ␉␉␉blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));␊ |
1533 | ␉␉}␊ |
1534 | ␉␉␊ |
1535 | ␉␉// draw next indicator␊ |
1536 | ␉␉if( lines > ( currentline + visiblelines ) )␊ |
1537 | ␉␉{␊ |
1538 | ␉␉␉pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );␊ |
1539 | ␉␉␉blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );␊ |
1540 | ␉␉}␊ |
1541 | ␊ |
1542 | ␉␉gui.bootprompt.draw = false;␊ |
1543 | ␉␉gui.infobox.draw = true;␊ |
1544 | ␉␉gui.redraw = true;␊ |
1545 | ␉␉␊ |
1546 | ␉␉updateVRAM();␊ |
1547 | ␉␉␊ |
1548 | ␉␉key = getc();␊ |
1549 | ␉␉␉␊ |
1550 | ␉␉if( key == kUpArrowkey )␊ |
1551 | ␉␉␉if( currentline > 0 )␊ |
1552 | ␉␉␉␉currentline--;␊ |
1553 | ␊ |
1554 | ␉␉if( key == kDownArrowkey )␊ |
1555 | ␉␉␉if( lines > ( currentline + visiblelines ) )␊ |
1556 | ␉␉␉␉currentline++;␊ |
1557 | ␊ |
1558 | ␉␉if( key == kEscapeKey || key == 'q' || key == 'Q')␊ |
1559 | ␉␉{␊ |
1560 | ␉␉␉gui.infobox.draw = false;␊ |
1561 | ␉␉␉gui.redraw = true;␊ |
1562 | ␉␉␉updateVRAM();␊ |
1563 | ␉␉␉break;␊ |
1564 | ␉␉}␊ |
1565 | ␉}␊ |
1566 | }␊ |
1567 | ␊ |
1568 | void animateProgressBar()␊ |
1569 | {␊ |
1570 | ␉int y;␊ |
1571 | ␉␊ |
1572 | ␉if( time18() > lasttime)␊ |
1573 | ␉{␊ |
1574 | ␉␉lasttime = time18();␊ |
1575 | ␊ |
1576 | ␉␉pixmap_t *buffBar = images[iProgressBar].image;␊ |
1577 | ␊ |
1578 | ␉␉uint32_t buff = buffBar->pixels[0].value;␊ |
1579 | ␉␊ |
1580 | ␉␉memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );␊ |
1581 | ␊ |
1582 | ␉␉for( y = buffBar->height - 1; y > 0; y--)␊ |
1583 | ␉␉␉pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);␊ |
1584 | ␊ |
1585 | ␉␉pixel(buffBar, buffBar->width-1, 0).value = buff;␊ |
1586 | ␉}␊ |
1587 | }␊ |
1588 | ␊ |
1589 | void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)␊ |
1590 | {␊ |
1591 | ␉if(progress>100)␊ |
1592 | ␉␉return;␊ |
1593 | ␉␊ |
1594 | ␉p.x = ( p.x - ( width / 2 ) );␊ |
1595 | ␊ |
1596 | ␉int todraw = (width * progress) / 100;␊ |
1597 | ␊ |
1598 | ␉pixmap_t *buff = images[iProgressBar].image;␊ |
1599 | ␉pixmap_t *buffBG = images[iProgressBarBackground].image;␊ |
1600 | ␉if(!buff || !buffBG)␊ |
1601 | ␉␉return;␊ |
1602 | ␉␊ |
1603 | ␉pixmap_t progressbar;␊ |
1604 | ␉progressbar.pixels=malloc(width * 4 * buff->height);␊ |
1605 | ␉if(!progressbar.pixels)␊ |
1606 | ␉␉return; ␊ |
1607 | ␉␊ |
1608 | ␉progressbar.width = width;␊ |
1609 | ␉progressbar.height = buff->height;␊ |
1610 | ␊ |
1611 | ␉int x=0,x2=0,y=0;␊ |
1612 | ␉␊ |
1613 | ␉for(y=0; y<buff->height; y++)␊ |
1614 | ␉{␊ |
1615 | ␉␉for(x=0; x<todraw; x++, x2++)␊ |
1616 | ␉␉{␊ |
1617 | ␉␉␉if(x2 == (buff->width-1)) x2=0;␊ |
1618 | ␉␉␉pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;␊ |
1619 | ␉␉}␊ |
1620 | ␉␉x2=0;␊ |
1621 | ␉}␊ |
1622 | ␊ |
1623 | ␉for(y=0; y<buff->height; y++)␊ |
1624 | ␉{␊ |
1625 | ␉␉for(x=todraw, x2 = 0; x < width - 1; x++, x2++)␊ |
1626 | ␉␉{␊ |
1627 | ␉␉␉if(x2 == (buffBG->width -2 )) x2 = 0;␊ |
1628 | ␉␉␉␉pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;␊ |
1629 | ␉␉}␊ |
1630 | ␉␉if(progress < 100)␊ |
1631 | ␉␉␉pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
1632 | ␉␉if(progress == 0)␊ |
1633 | ␉␉␉pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
1634 | ␉␉x2=0;␊ |
1635 | ␉}␊ |
1636 | ␉ ␊ |
1637 | ␉blend(&progressbar, blendInto, p);␊ |
1638 | ␉animateProgressBar();␊ |
1639 | ␉free(progressbar.pixels);␊ |
1640 | }␊ |
1641 | ␊ |
1642 | void drawInfoMenuItems()␊ |
1643 | {␊ |
1644 | ␉int i,n;␊ |
1645 | ␉␊ |
1646 | ␉position_t position;␊ |
1647 | ␉␊ |
1648 | ␉pixmap_t *selection = images[iMenuSelection].image;␊ |
1649 | ␉␊ |
1650 | ␉pixmap_t *pbuff;␊ |
1651 | ␊ |
1652 | ␉fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);␊ |
1653 | ␊ |
1654 | ␉makeRoundedCorners(gui.menu.pixmap);␊ |
1655 | ␉␊ |
1656 | ␉uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;␊ |
1657 | ␊ |
1658 | ␉position = pos(0,0);␊ |
1659 | ␉␊ |
1660 | ␉for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)␊ |
1661 | ␉{␊ |
1662 | ␉␉if (i == infoMenuSelection)␊ |
1663 | ␉␉␉blend(selection, gui.menu.pixmap, position);␊ |
1664 | ␊ |
1665 | ␉␉pbuff = images[n].image;␊ |
1666 | ␉␉if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)␊ |
1667 | ␉␉␉blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap, ␊ |
1668 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
1669 | ␉␉else␊ |
1670 | ␉␉␉blend( pbuff, gui.menu.pixmap, ␊ |
1671 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
1672 | ␊ |
1673 | ␉␉drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap, ␊ |
1674 | ␉␉␉pos(position.x + (pbuff->width + gui.menu.hborder), ␊ |
1675 | ␉␉␉␉position.y + ((selection->height - font_console.height) / 2)));␊ |
1676 | ␉␉position.y += images[iMenuSelection].image->height;␊ |
1677 | ␉␊ |
1678 | ␉}␊ |
1679 | ␉␊ |
1680 | ␉gui.redraw = true;␊ |
1681 | }␊ |
1682 | ␊ |
1683 | int drawInfoMenu()␊ |
1684 | {␊ |
1685 | ␉drawInfoMenuItems();␊ |
1686 | ␊ |
1687 | ␉gui.menu.draw = true;␊ |
1688 | ␊ |
1689 | ␉updateVRAM();␊ |
1690 | ␉␊ |
1691 | ␉return 1;␊ |
1692 | }␊ |
1693 | ␊ |
1694 | int updateInfoMenu(int key)␊ |
1695 | {␊ |
1696 | ␉switch (key)␊ |
1697 | ␉{␊ |
1698 | ␊ |
1699 | ␉␉case kUpArrowkey:␉// up arrow␊ |
1700 | ␉␉␉␉if (infoMenuSelection > 0)␊ |
1701 | ␉␉␉␉{␊ |
1702 | ␉␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)␊ |
1703 | ␉␉␉␉␉␉infoMenuSelection -= 4;␊ |
1704 | ␉␉␉␉␉␊ |
1705 | ␉␉␉␉␉else␊ |
1706 | ␉␉␉␉␉␉infoMenuSelection--;␊ |
1707 | ␉␉␉␉␉␉drawInfoMenuItems();␊ |
1708 | ␉␉␉␉␉␉updateVRAM();␊ |
1709 | ␉␉␉␉␉␊ |
1710 | ␉␉␉␉} else {␊ |
1711 | ␉␉␉␉␉␊ |
1712 | ␉␉␉␉␉gui.menu.draw = false;␊ |
1713 | ␉␉␉␉␉gui.redraw = true;␊ |
1714 | ␊ |
1715 | ␉␉␉␉␉updateVRAM();␊ |
1716 | ␉␉␉␉␉␊ |
1717 | ␉␉␉␉␉return CLOSE_INFO_MENU;␊ |
1718 | ␉␉␉␉}␊ |
1719 | ␉␉␉␉break;␊ |
1720 | ␊ |
1721 | ␉␉case kDownArrowkey:␉// down arrow␊ |
1722 | ␉␉␉␉if (infoMenuSelection < infoMenuItemsCount - 1)␊ |
1723 | ␉␉␉␉{␊ |
1724 | ␉␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)␊ |
1725 | ␉␉␉␉␉␉infoMenuSelection += 4;␊ |
1726 | ␉␉␉␉␉else␊ |
1727 | ␉␉␉␉␉␉infoMenuSelection++;␊ |
1728 | ␉␉␉␉␉drawInfoMenuItems();␊ |
1729 | ␉␉␉␉␉updateVRAM();␊ |
1730 | ␉␉␉␉}␊ |
1731 | ␉␉␉␉break;␊ |
1732 | ␊ |
1733 | ␉␉case kReturnKey:␊ |
1734 | ␉␉␉␉key = 0;␊ |
1735 | ␉␉␉␉if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )␊ |
1736 | ␉␉␉␉␉showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());␊ |
1737 | ␊ |
1738 | ␉␉␉␉else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )␊ |
1739 | ␉␉␉␉␉showInfoBox( getVBEInfoString(), getVBEModeInfoString() );␊ |
1740 | ␉␉␉␊ |
1741 | ␉␉␉␉else if( infoMenuSelection == MENU_SHOW_HELP )␊ |
1742 | ␉␉␉␉␉showHelp();␊ |
1743 | ␉␉␉␉␉␊ |
1744 | ␉␉␉␉else␊ |
1745 | ␉␉␉␉{␊ |
1746 | ␉␉␉␉␉int buff = infoMenuSelection;␊ |
1747 | ␉␉␉␉␉infoMenuSelection = 0;␊ |
1748 | ␉␉␉␉␉return buff;␊ |
1749 | ␉␉␉␉}␊ |
1750 | ␉␉␉␉break;␊ |
1751 | ␉␉}␊ |
1752 | ␉return DO_NOT_BOOT;␊ |
1753 | }␊ |
1754 | ␊ |
1755 | uint16_t bootImageWidth = 0; ␊ |
1756 | uint16_t bootImageHeight = 0; ␊ |
1757 | uint8_t *bootImageData = NULL; ␊ |
1758 | static bool usePngImage = true;␊ |
1759 | ␊ |
1760 | //==========================================================================␊ |
1761 | // loadBootGraphics␊ |
1762 | static void loadBootGraphics(void)␊ |
1763 | {␊ |
1764 | ␉if (bootImageData != NULL) {␊ |
1765 | ␉␉return;␊ |
1766 | ␉}␊ |
1767 | ␊ |
1768 | ␉char dirspec[256];␊ |
1769 | ␊ |
1770 | ␉if ((strlen(theme_name) + 24) > sizeof(dirspec)) {␊ |
1771 | ␉␉usePngImage = false; ␊ |
1772 | ␉␉return;␊ |
1773 | ␉}␊ |
1774 | ␉sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);␊ |
1775 | ␉if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {␊ |
1776 | #ifdef EMBED_THEME␊ |
1777 | ␉if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)␊ |
1778 | #endif␊ |
1779 | ␉␉usePngImage = false; ␊ |
1780 | ␉}␊ |
1781 | }␊ |
1782 | ␊ |
1783 | //==========================================================================␊ |
1784 | // drawBootGraphics␊ |
1785 | void drawBootGraphics(void)␊ |
1786 | {␊ |
1787 | ␉int pos;␊ |
1788 | ␉int length;␊ |
1789 | ␉const char *dummyVal;␊ |
1790 | ␉int oldScreenWidth, oldScreenHeight;␊ |
1791 | ␉bool legacy_logo;␊ |
1792 | ␉uint16_t x, y; ␊ |
1793 | ␉␊ |
1794 | ␉if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->bootConfig) && legacy_logo) {␊ |
1795 | ␉␉usePngImage = false; ␊ |
1796 | ␉} else if (bootImageData == NULL) {␊ |
1797 | ␉␉loadBootGraphics();␊ |
1798 | ␉}␊ |
1799 | ␊ |
1800 | ␉// parse display size parameters - Azi: shouldn't this stuff be like the one on initGUI? no "else"␊ |
1801 | ␉if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0) {␊ |
1802 | ␉␉screen_params[0] = pos;␊ |
1803 | ␉} else {␊ |
1804 | ␉␉screen_params[0] = DEFAULT_SCREEN_WIDTH;␊ |
1805 | ␉}␊ |
1806 | ␉if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0) {␊ |
1807 | ␉␉screen_params[1] = pos;␊ |
1808 | ␉} else {␊ |
1809 | ␉␉screen_params[1] = DEFAULT_SCREEN_HEIGHT;␊ |
1810 | ␉}␊ |
1811 | ␊ |
1812 | // Save current screen resolution.␊ |
1813 | ␉oldScreenWidth = gui.screen.width;␊ |
1814 | ␉oldScreenHeight = gui.screen.height;␊ |
1815 | ␊ |
1816 | ␉gui.screen.width = screen_params[0];␊ |
1817 | ␉gui.screen.height = screen_params[1];␊ |
1818 | ␊ |
1819 | ␉// find best matching vesa mode for our requested width & height␊ |
1820 | ␉getGraphicModeParams(screen_params);␊ |
1821 | ␊ |
1822 | // Set graphics mode if the booter was in text mode or the screen resolution has changed.␊ |
1823 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE␊ |
1824 | ␉␉|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )␊ |
1825 | ␉{␊ |
1826 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
1827 | ␉}␊ |
1828 | ␊ |
1829 | ␉if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) {␊ |
1830 | ␉␉drawCheckerBoard();␊ |
1831 | ␉} else {␊ |
1832 | ␉␉// Fill the background to 75% grey (same as BootX). ␊ |
1833 | ␉␉drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01); ␊ |
1834 | ␉}␊ |
1835 | ␉if ((bootImageData) && (usePngImage)) { ␊ |
1836 | ␉␉x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2; ␊ |
1837 | ␉␉y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2; ␊ |
1838 | ␊ |
1839 | ␉␉// Draw the image in the center of the display. ␊ |
1840 | ␉␉blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData); ␊ |
1841 | ␉} else { ␊ |
1842 | ␉␉uint8_t *appleBootPict; ␊ |
1843 | ␉␉bootImageData = NULL; ␊ |
1844 | ␉␉bootImageWidth = kAppleBootWidth; ␊ |
1845 | ␉␉bootImageHeight = kAppleBootHeight; ␊ |
1846 | ␊ |
1847 | ␉␉// Prepare the data for the default Apple boot image. ␊ |
1848 | ␉␉appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight); ␊ |
1849 | ␉␉if (appleBootPict) { ␊ |
1850 | ␉␉␉convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData); ␊ |
1851 | ␉␉␉if (bootImageData) {␉␊ |
1852 | ␉␉␉␉x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2; ␊ |
1853 | ␉␉␉␉y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2; ␊ |
1854 | ␉␉␉␉drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);␊ |
1855 | ␉␉␉␉free(bootImageData);␊ |
1856 | ␉␉␉}␊ |
1857 | ␉␉␉free(appleBootPict); ␊ |
1858 | ␉␉} ␊ |
1859 | ␉} ␊ |
1860 | }␊ |
1861 | |