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