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