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