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