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