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