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