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