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