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