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