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 | ␉for (i = 0; i < sizeof(images) / sizeof(images[0]); i++)␊ |
443 | ␉{␊ |
444 | ␉ if (images[i].image)␊ |
445 | ␉ {␊ |
446 | ␉ ␉if (images[i].image->pixels) free(images[i].image->pixels);␊ |
447 | ␉ ␉free (images[i].image);␊ |
448 | ␉ ␉images[i].image = 0;␊ |
449 | ␉ }␊ |
450 | ␉}␊ |
451 | ␉return 0;␊ |
452 | }␊ |
453 | ␊ |
454 | pixmap_t *getCroppedPixmapAtPosition( pixmap_t *from, position_t pos, uint16_t width, uint16_t height )␊ |
455 | {␊ |
456 | ␉␊ |
457 | ␉pixmap_t *cropped = malloc( sizeof( pixmap_t ) );␊ |
458 | ␉if( !cropped )␊ |
459 | ␉␉return 0;␊ |
460 | ␉cropped->pixels = malloc( width * height * 4 );␊ |
461 | ␉if ( !cropped->pixels )␊ |
462 | ␉␉return 0;␊ |
463 | ␉␊ |
464 | ␉cropped->width = width;␊ |
465 | ␉cropped->height = height;␊ |
466 | ␉␊ |
467 | ␉int destx = 0, desty = 0;␊ |
468 | ␉int srcx = pos.x, srcy = pos.y;␊ |
469 | ␉␊ |
470 | ␉for( ; desty < height; desty++, srcy++)␊ |
471 | ␉{␊ |
472 | ␉␉for( destx = 0, srcx = pos.x; destx < width; destx++, srcx++ )␊ |
473 | ␉␉{␊ |
474 | ␉␉␉pixel( cropped, destx, desty ).value = pixel( from, srcx, srcy ).value;␊ |
475 | ␉␉}␊ |
476 | ␉}␊ |
477 | ␉return cropped;␊ |
478 | }␊ |
479 | ␊ |
480 | int createBackBuffer( window_t *window )␊ |
481 | {␊ |
482 | ␉gui.backbuffer = malloc(sizeof(pixmap_t));␊ |
483 | ␉if(!gui.backbuffer)␊ |
484 | ␉␉return 1;␊ |
485 | ␉␊ |
486 | ␉gui.backbuffer->pixels = malloc( window->width * window->height * 4 );␊ |
487 | ␉if(!gui.backbuffer->pixels)␊ |
488 | ␉{␊ |
489 | ␉␉free(gui.backbuffer);␊ |
490 | ␉␉gui.backbuffer = 0;␊ |
491 | ␉␉return 1;␊ |
492 | ␉}␊ |
493 | ␉␊ |
494 | ␉gui.backbuffer->width = gui.screen.width;␊ |
495 | ␉gui.backbuffer->height = gui.screen.height;␊ |
496 | ␊ |
497 | ␉return 0;␊ |
498 | }␊ |
499 | ␊ |
500 | int freeBackBuffer( window_t *window )␊ |
501 | {␊ |
502 | if (gui.backbuffer && gui.backbuffer->pixels)␊ |
503 | {␊ |
504 | free(gui.backbuffer->pixels);␊ |
505 | free(gui.backbuffer);␊ |
506 | gui.backbuffer = 0;␊ |
507 | return 0;␊ |
508 | }␊ |
509 | ␊ |
510 | return 1;␊ |
511 | }␊ |
512 | ␊ |
513 | int createWindowBuffer( window_t *window )␊ |
514 | {␊ |
515 | ␉window->pixmap = malloc(sizeof(pixmap_t));␊ |
516 | ␉if(!window->pixmap)␊ |
517 | ␉␉return 1;␊ |
518 | ␊ |
519 | ␉window->pixmap->pixels = malloc( window->width * window->height * 4 );␊ |
520 | ␉if(!window->pixmap->pixels)␊ |
521 | ␉{␊ |
522 | ␉␉free(window->pixmap);␊ |
523 | ␉␉window->pixmap = 0;␊ |
524 | ␉␉return 1;␊ |
525 | ␉}␊ |
526 | ␉␊ |
527 | ␉window->pixmap->width = window->width;␊ |
528 | ␉window->pixmap->height = window->height;␊ |
529 | ␊ |
530 | ␉return 0;␊ |
531 | }␊ |
532 | ␊ |
533 | int freeWindowBuffer( window_t *window )␊ |
534 | {␊ |
535 | ␉if (window->pixmap && window->pixmap->pixels)␊ |
536 | {␊ |
537 | ␉␉free(window->pixmap->pixels);␊ |
538 | ␉␉free(window->pixmap);␊ |
539 | ␉␉return 0;␊ |
540 | ␉}␊ |
541 | ␊ |
542 | ␉return 1;␊ |
543 | }␊ |
544 | ␊ |
545 | void fillPixmapWithColor(pixmap_t *pm, uint32_t color)␊ |
546 | {␊ |
547 | ␉int x,y;␊ |
548 | ␉␊ |
549 | ␉// fill with given color AARRGGBB␊ |
550 | ␉for( x=0; x < pm->width; x++ )␊ |
551 | ␉␉for( y=0; y< pm->height; y++)␊ |
552 | ␉␉␉pixel(pm,x,y).value = color;␊ |
553 | }␊ |
554 | ␊ |
555 | void drawBackground()␊ |
556 | {␊ |
557 | ␉// reset text cursor␊ |
558 | ␉gui.screen.cursor.x = gui.screen.hborder;␊ |
559 | ␉gui.screen.cursor.y = gui.screen.vborder;␊ |
560 | ␉␊ |
561 | ␉fillPixmapWithColor( gui.screen.pixmap, gui.screen.bgcolor);␊ |
562 | ␉␊ |
563 | ␉// draw background.png into background buffer␊ |
564 | ␉blend( images[iBackground].image, gui.screen.pixmap, gui.background.pos );␊ |
565 | ␉␊ |
566 | ␉// draw logo.png into background buffer␊ |
567 | ␉if (gui.logo.draw)␊ |
568 | ␉{␊ |
569 | ␉blend( images[iLogo].image, gui.screen.pixmap, gui.logo.pos);␊ |
570 | ␉}␊ |
571 | ␉␊ |
572 | ␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
573 | }␊ |
574 | ␊ |
575 | void setupDeviceList(config_file_t *theme)␊ |
576 | {␊ |
577 | ␉unsigned int pixel;␊ |
578 | ␉int␉alpha;␉␉␉␉// transparency level 0 (obligue) - 255 (transparent)␊ |
579 | ␉uint32_t color;␉␉␉// color value formatted RRGGBB␊ |
580 | ␉int val, len;␊ |
581 | ␉const char *string;␉␊ |
582 | ␊ |
583 | ␉if(getIntForKey("devices_max_visible", &val, theme ))␊ |
584 | ␉␉gui.maxdevices = MIN( val, gDeviceCount );␊ |
585 | ␊ |
586 | ␉if(getIntForKey("devices_iconspacing", &val, theme ))␊ |
587 | ␉␉gui.devicelist.iconspacing = val;␊ |
588 | ␊ |
589 | ␉// check layout for horizontal or vertical␊ |
590 | ␉gui.layout = HorizontalLayout;␊ |
591 | ␉if(getValueForKey( "devices_layout", &string, &len, theme)) {␊ |
592 | ␉␉if (!strcmp (string, "vertical")) {␊ |
593 | ␉␉␉gui.layout = VerticalLayout;␊ |
594 | ␉␉}␊ |
595 | ␉}␊ |
596 | ␊ |
597 | ␉switch (gui.layout) {␊ |
598 | ␉case VerticalLayout:␊ |
599 | ␉␉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);␊ |
600 | ␉␉gui.devicelist.width = (images[iSelection].image->width + gui.devicelist.iconspacing);␊ |
601 | ␊ |
602 | ␉␉if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , images[iSelection].image->width ) )␊ |
603 | ␉␉␉gui.devicelist.pos.x = pixel;␊ |
604 | ␊ |
605 | ␉␉if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , gui.devicelist.height ) )␊ |
606 | ␉␉␉gui.devicelist.pos.y = pixel;␊ |
607 | ␉␉break;␊ |
608 | ␊ |
609 | ␉case HorizontalLayout:␊ |
610 | ␉default:␊ |
611 | ␉␉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);␊ |
612 | ␉␉gui.devicelist.height = (images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing);␊ |
613 | ␊ |
614 | ␉␉if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , gui.devicelist.width ) )␊ |
615 | ␉␉␉gui.devicelist.pos.x = pixel;␊ |
616 | ␉␉else␊ |
617 | ␉␉␉gui.devicelist.pos.x = ( gui.screen.width - gui.devicelist.width ) / 2;␊ |
618 | ␉␉␊ |
619 | ␉␉if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , images[iSelection].image->height ) )␊ |
620 | ␉␉␉gui.devicelist.pos.y = pixel;␊ |
621 | ␉␉else␊ |
622 | ␉␉␉gui.devicelist.pos.y = ( gui.screen.height - gui.devicelist.height ) / 2;␊ |
623 | ␉␉break;␊ |
624 | ␉}␊ |
625 | ␊ |
626 | ␉if(getColorForKey("devices_bgcolor", &color, theme))␊ |
627 | ␉␉gui.devicelist.bgcolor = (color & 0x00FFFFFF);␊ |
628 | ␊ |
629 | ␉if(getIntForKey("devices_transparency", &alpha, theme))␊ |
630 | ␉␉gui.devicelist.bgcolor = gui.devicelist.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␊ |
631 | ␊ |
632 | ␉if (gui.devicelist.pixmap)␊ |
633 | ␉{␊ |
634 | ␉ freeWindowBuffer(&gui.devicelist);␊ |
635 | createWindowBuffer(&gui.devicelist);␊ |
636 | }␊ |
637 | }␊ |
638 | ␊ |
639 | void loadThemeValues(config_file_t *theme)␊ |
640 | {␊ |
641 | ␉unsigned int screen_width = gui.screen.width;␊ |
642 | ␉unsigned int screen_height = gui.screen.height;␊ |
643 | ␉unsigned int pixel;␊ |
644 | ␉int␉alpha;␉␉␉␉// transparency level 0 (obligue) - 255 (transparent)␊ |
645 | ␉uint32_t color;␉␉␉// color value formatted RRGGBB␊ |
646 | ␉int val;␊ |
647 | ␊ |
648 | ␉/*␊ |
649 | ␉ * Parse screen parameters␊ |
650 | ␉ */␊ |
651 | ␉if(getColorForKey("screen_bgcolor", &color, theme ))␊ |
652 | ␉␉gui.screen.bgcolor = (color & 0x00FFFFFF);␊ |
653 | ␊ |
654 | ␉if(getIntForKey("screen_textmargin_h", &val, theme))␊ |
655 | ␉␉gui.screen.hborder = MIN( gui.screen.width , val );␊ |
656 | ␊ |
657 | ␉if(getIntForKey("screen_textmargin_v", &val, theme))␊ |
658 | ␉␉gui.screen.vborder = MIN( gui.screen.height , val );␊ |
659 | ␊ |
660 | ␉/*␊ |
661 | ␉ * Parse background parameters␊ |
662 | ␉ */␊ |
663 | ␉if(getDimensionForKey("background_pos_x", &pixel, theme, screen_width , images[iBackground].image->width ) )␊ |
664 | ␉␉gui.background.pos.x = pixel;␊ |
665 | ␊ |
666 | ␉if(getDimensionForKey("background_pos_y", &pixel, theme, screen_height , images[iBackground].image->height ) )␊ |
667 | ␉␉gui.background.pos.y = pixel;␊ |
668 | ␊ |
669 | ␉/*␊ |
670 | ␉ * Parse logo parameters␊ |
671 | ␉ */␊ |
672 | ␉if(getDimensionForKey("logo_pos_x", &pixel, theme, screen_width , images[iLogo].image->width ) )␊ |
673 | ␉␉gui.logo.pos.x = pixel;␊ |
674 | ␊ |
675 | ␉if(getDimensionForKey("logo_pos_y", &pixel, theme, screen_height , images[iLogo].image->height ) )␊ |
676 | ␉␉gui.logo.pos.y = pixel;␊ |
677 | ␊ |
678 | ␉/*␊ |
679 | ␉ * Parse progress bar parameters␊ |
680 | ␉ */␊ |
681 | ␉if(getDimensionForKey("progressbar_pos_x", &pixel, theme, screen_width , 0 ) )␊ |
682 | ␉␉gui.progressbar.pos.x = pixel;␊ |
683 | ␊ |
684 | ␉if(getDimensionForKey("progressbar_pos_y", &pixel, theme, screen_height , 0 ) )␊ |
685 | ␉␉gui.progressbar.pos.y = pixel;␊ |
686 | ␊ |
687 | ␉/*␊ |
688 | ␉ * Parse countdown text parameters␊ |
689 | ␉ */␊ |
690 | ␉if(getDimensionForKey("countdown_pos_x", &pixel, theme, screen_width , 0 ) )␊ |
691 | ␉␉gui.countdown.pos.x = pixel;␊ |
692 | ␊ |
693 | ␉if(getDimensionForKey("countdown_pos_y", &pixel, theme, screen_height , 0 ) )␊ |
694 | ␉␉gui.countdown.pos.y = pixel;␊ |
695 | ␊ |
696 | /*␊ |
697 | ␉ * Parse devicelist parameters␊ |
698 | ␉ */␊ |
699 | ␉setupDeviceList(theme);␊ |
700 | ␊ |
701 | ␉/*␊ |
702 | ␉ * Parse infobox parameters␊ |
703 | ␉ */␊ |
704 | ␉if(getIntForKey("infobox_width", &val, theme))␊ |
705 | ␉␉gui.infobox.width = MIN( screen_width , val );␊ |
706 | ␊ |
707 | ␉if(getIntForKey("infobox_height", &val, theme))␊ |
708 | ␉␉gui.infobox.height = MIN( screen_height , val );␊ |
709 | ␊ |
710 | ␉if(getDimensionForKey("infobox_pos_x", &pixel, theme, screen_width , gui.infobox.width ) )␊ |
711 | ␉␉gui.infobox.pos.x = pixel;␊ |
712 | ␊ |
713 | ␉if(getDimensionForKey("infobox_pos_y", &pixel, theme, screen_height , gui.infobox.height ) )␊ |
714 | ␉␉gui.infobox.pos.y = pixel;␊ |
715 | ␊ |
716 | ␉if(getIntForKey("infobox_textmargin_h", &val, theme))␊ |
717 | ␉␉gui.infobox.hborder = MIN( gui.infobox.width , val );␊ |
718 | ␊ |
719 | ␉if(getIntForKey("infobox_textmargin_v", &val, theme))␊ |
720 | ␉␉gui.infobox.vborder = MIN( gui.infobox.height , val );␊ |
721 | ␊ |
722 | ␉if(getColorForKey("infobox_bgcolor", &color, theme))␊ |
723 | ␉␉gui.infobox.bgcolor = (color & 0x00FFFFFF);␊ |
724 | ␊ |
725 | ␉if(getIntForKey("infobox_transparency", &alpha, theme))␊ |
726 | ␉␉gui.infobox.bgcolor = gui.infobox.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␊ |
727 | ␊ |
728 | ␉/*␊ |
729 | ␉ * Parse menu parameters␊ |
730 | ␉ */␊ |
731 | ␉if(getDimensionForKey("menu_width", &pixel, theme, gui.screen.width , 0 ) )␊ |
732 | ␉␉gui.menu.width = pixel;␊ |
733 | ␉else␊ |
734 | ␉␉gui.menu.width = images[iMenuSelection].image->width;␊ |
735 | ␊ |
736 | ␉if(getDimensionForKey("menu_height", &pixel, theme, gui.screen.height , 0 ) )␊ |
737 | ␉␉gui.menu.height = pixel;␊ |
738 | ␉else␊ |
739 | ␉␉gui.menu.height = (infoMenuItemsCount) * images[iMenuSelection].image->height;␊ |
740 | ␊ |
741 | ␉if(getDimensionForKey("menu_pos_x", &pixel, theme, screen_width , gui.menu.width ) )␊ |
742 | ␉␉gui.menu.pos.x = pixel;␊ |
743 | ␊ |
744 | ␉if(getDimensionForKey("menu_pos_y", &pixel, theme, screen_height , gui.menu.height ) )␊ |
745 | ␉␉gui.menu.pos.y = pixel;␊ |
746 | ␊ |
747 | ␉if(getIntForKey("menu_textmargin_h", &val, theme))␊ |
748 | ␉␉gui.menu.hborder = MIN( gui.menu.width , val );␊ |
749 | ␊ |
750 | ␉if(getIntForKey("menu_textmargin_v", &val, theme))␊ |
751 | ␉␉gui.menu.vborder = MIN( gui.menu.height , val );␊ |
752 | ␊ |
753 | ␉if(getColorForKey("menu_bgcolor", &color, theme))␊ |
754 | ␉␉gui.menu.bgcolor = (color & 0x00FFFFFF);␊ |
755 | ␊ |
756 | ␉if(getIntForKey("menu_transparency", &alpha, theme))␊ |
757 | ␉␉gui.menu.bgcolor = gui.menu.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␉␉␊ |
758 | ␊ |
759 | ␉/*␊ |
760 | ␉ * Parse bootprompt parameters␊ |
761 | ␉ */␊ |
762 | ␉if(getDimensionForKey("bootprompt_width", &pixel, theme, screen_width , 0 ) )␊ |
763 | ␉␉gui.bootprompt.width = pixel;␊ |
764 | ␊ |
765 | ␉if(getIntForKey("bootprompt_height", &val, theme))␊ |
766 | ␉␉gui.bootprompt.height = MIN( screen_height , val );␊ |
767 | ␊ |
768 | ␉if(getDimensionForKey("bootprompt_pos_x", &pixel, theme, screen_width , gui.bootprompt.width ) )␊ |
769 | ␉␉gui.bootprompt.pos.x = pixel;␊ |
770 | ␊ |
771 | ␉if(getDimensionForKey("bootprompt_pos_y", &pixel, theme, screen_height , gui.bootprompt.height ) )␊ |
772 | ␉␉gui.bootprompt.pos.y = pixel;␊ |
773 | ␊ |
774 | ␉if(getIntForKey("bootprompt_textmargin_h", &val, theme))␊ |
775 | ␉␉gui.bootprompt.hborder = MIN( gui.bootprompt.width , val );␊ |
776 | ␊ |
777 | ␉if(getIntForKey("bootprompt_textmargin_v", &val, theme))␊ |
778 | ␉␉gui.bootprompt.vborder = MIN( gui.bootprompt.height , val );␊ |
779 | ␊ |
780 | ␉if(getColorForKey("bootprompt_bgcolor", &color, theme))␊ |
781 | ␉␉gui.bootprompt.bgcolor = (color & 0x00FFFFFF);␊ |
782 | ␊ |
783 | ␉if(getIntForKey("bootprompt_transparency", &alpha, theme))␊ |
784 | ␉␉gui.bootprompt.bgcolor = gui.bootprompt.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␊ |
785 | ␊ |
786 | ␉if(getColorForKey("font_small_color", &color, theme))␊ |
787 | ␉␉gui.screen.font_small_color = (color & 0x00FFFFFF);␊ |
788 | ␊ |
789 | ␉if(getColorForKey("font_console_color", &color, theme))␊ |
790 | ␉␉gui.screen.font_console_color = (color & 0x00FFFFFF);␊ |
791 | }␊ |
792 | ␊ |
793 | int initGUI(void)␊ |
794 | {␊ |
795 | ␉int␉␉val;␊ |
796 | ␉int␉len;␊ |
797 | ␉char␉dirspec[256];␊ |
798 | ␊ |
799 | ␉getValueForKey( "Theme", &theme_name, &len, &bootInfo->chameleonConfig );␊ |
800 | ␉if ((strlen(theme_name) + 27) > sizeof(dirspec)) {␊ |
801 | ␉␉return 1;␊ |
802 | ␉}␊ |
803 | ␉sprintf(dirspec, "/Extra/Themes/%s/theme.plist", theme_name);␊ |
804 | ␉if (loadConfigFile(dirspec, &bootInfo->themeConfig) != 0) {␊ |
805 | #ifdef CONFIG_EMBED_THEME␊ |
806 | config_file_t␉*config;␊ |
807 | ␊ |
808 | config = &bootInfo->themeConfig;␊ |
809 | if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) {␊ |
810 | return 1;␊ |
811 | }␊ |
812 | #else␊ |
813 | ␉␉return 1;␊ |
814 | #endif␊ |
815 | ␉}␊ |
816 | ␉// parse display size parameters␊ |
817 | ␉if (getIntForKey("screen_width", &val, &bootInfo->themeConfig) && val > 0) {␊ |
818 | ␉␉screen_params[0] = val;␊ |
819 | ␉}␊ |
820 | ␉if (getIntForKey("screen_height", &val, &bootInfo->themeConfig) && val > 0) {␊ |
821 | ␉␉screen_params[1] = val;␊ |
822 | ␉}␊ |
823 | ␊ |
824 | ␉// Initalizing GUI strucutre.␊ |
825 | ␉bzero(&gui, sizeof(gui_t));␊ |
826 | ␉␊ |
827 | ␉// find best matching vesa mode for our requested width & height␊ |
828 | ␉getGraphicModeParams(screen_params);␊ |
829 | ␊ |
830 | ␉// set our screen structure with the mode width & height␊ |
831 | ␉gui.screen.width = screen_params[0];␉␊ |
832 | ␉gui.screen.height = screen_params[1];␊ |
833 | ␊ |
834 | ␉// load graphics otherwise fail and return␊ |
835 | ␉if (loadGraphics() == 0) {␊ |
836 | ␉␉loadThemeValues(&bootInfo->themeConfig);␊ |
837 | ␉␉colorFont(&font_small, gui.screen.font_small_color);␊ |
838 | ␉␉colorFont(&font_console, gui.screen.font_console_color);␊ |
839 | ␊ |
840 | ␉␉// create the screen & window buffers␊ |
841 | ␉␉if (createBackBuffer(&gui.screen) == 0) {␊ |
842 | ␉␉␉if (createWindowBuffer(&gui.screen) == 0) {␊ |
843 | ␉␉␉␉if (createWindowBuffer(&gui.devicelist) == 0) {␊ |
844 | ␉␉␉␉␉if (createWindowBuffer(&gui.bootprompt) == 0) {␊ |
845 | ␉␉␉␉␉␉if (createWindowBuffer(&gui.infobox) == 0) {␊ |
846 | ␉␉␉␉␉␉␉if (createWindowBuffer(&gui.menu) == 0) {␊ |
847 | ␉␉␉␉␉␉␉ gui.logo.draw = true;␊ |
848 | ␉␉␉␉␉␉␉␉drawBackground();␊ |
849 | ␉␉␉␉␉␉␉␉// lets copy the screen into the back buffer␊ |
850 | ␉␉␉␉␉␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
851 | ␉␉␉␉␉␉␉␉setVideoMode( GRAPHICS_MODE, 0 );␊ |
852 | ␉␉␉␉␉␉␉␉gui.initialised = true;␊ |
853 | ␉␉␉␉␉␉␉␉return 0;␊ |
854 | ␉␉␉␉␉␉␉}␊ |
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 | ␊ |
871 | ␉return 1;␊ |
872 | }␊ |
873 | ␊ |
874 | bool is_image_loaded(int i)␊ |
875 | {␉␊ |
876 | ␉return (images[i].image != NULL) ? true : false;␊ |
877 | }␊ |
878 | ␊ |
879 | void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected)␊ |
880 | {␊ |
881 | ␉int devicetype;␊ |
882 | ␊ |
883 | ␉if( diskIsCDROM(device) )␊ |
884 | ␉␉devicetype = iDeviceCDROM;␉␉␉␉// Use CDROM icon␊ |
885 | ␉else␊ |
886 | ␉{␉␊ |
887 | ␉␉switch (device->part_type)␊ |
888 | ␉␉{␊ |
889 | ␉␉␉case kPartitionTypeHFS:␊ |
890 | ␉␉␉{␉␉␉␉␊ |
891 | ␊ |
892 | ␉␉␉␉// Use HFS or HFSRAID icon depending on bvr flags.␊ |
893 | ␉␉␉␉if (device->flags & kBVFlagBooter) {␊ |
894 | ␊ |
895 | ␉␉␉␉␉switch (device->OSVersion[3]) {␊ |
896 | ␉␉␉␉␉␉case '7':␊ |
897 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFSRAID_Lion) ? iDeviceHFSRAID_Lion : is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;␊ |
898 | ␉␉␉␉␉␉␉break;␊ |
899 | ␉␉␉␉␉␉case '6':␊ |
900 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFSRAID_SL) ? iDeviceHFSRAID_SL : is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;␊ |
901 | ␉␉␉␉␉␉␉break;␊ |
902 | ␉␉␉␉␉␉case '5':␊ |
903 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFSRAID_Leo) ? iDeviceHFSRAID_Leo : is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;␊ |
904 | ␉␉␉␉␉␉␉break;␊ |
905 | ␉␉␉␉␉␉case '4':␊ |
906 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFSRAID_Tiger) ? iDeviceHFSRAID_Tiger : is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;␊ |
907 | ␉␉␉␉␉␉␉break;␊ |
908 | ␉␉␉␉␉␉default:␊ |
909 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFSRAID) ? iDeviceHFSRAID : iDeviceGeneric;␊ |
910 | ␉␉␉␉␉␉␉break;␊ |
911 | ␉␉␉␉␉}␊ |
912 | ␉␉␉␉␉␊ |
913 | ␉␉␉␉} ␊ |
914 | else␊ |
915 | ␉␉␉␉{␉␉␉␉␉␊ |
916 | ␉␉␉␉␉␊ |
917 | ␉␉␉␉␉switch (device->OSVersion[3]) {␊ |
918 | ␉␉␉␉␉␉case '7':␊ |
919 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFS_Lion) ? iDeviceHFS_Lion : is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;␊ |
920 | ␉␉␉␉␉␉␉break;␊ |
921 | ␉␉␉␉␉␉case '6':␊ |
922 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFS_SL) ? iDeviceHFS_SL : is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;␊ |
923 | ␉␉␉␉␉␉␉break;␊ |
924 | ␉␉␉␉␉␉case '5':␊ |
925 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFS_Leo) ? iDeviceHFS_Leo : is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;␊ |
926 | ␉␉␉␉␉␉␉break;␊ |
927 | ␉␉␉␉␉␉case '4':␊ |
928 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFS_Tiger) ? iDeviceHFS_Tiger : is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;␊ |
929 | ␉␉␉␉␉␉␉break;␊ |
930 | ␉␉␉␉␉␉default:␊ |
931 | ␉␉␉␉␉␉␉devicetype = is_image_loaded(iDeviceHFS) ? iDeviceHFS : iDeviceGeneric;␊ |
932 | ␉␉␉␉␉␉␉break;␊ |
933 | ␉␉␉␉␉}␉␉␉␉␉␉␊ |
934 | ␉␉␉␉␉␊ |
935 | ␉␉␉␉}␊ |
936 | ␉␉␉␉␊ |
937 | ␉␉␉␉break;␊ |
938 | ␉␉␉␉␊ |
939 | ␉␉␉}␉␉␉␉␊ |
940 | ␉␉␉case kPartitionTypeHPFS:␊ |
941 | ␉␉␉␉devicetype = is_image_loaded(iDeviceNTFS) ? iDeviceNTFS : iDeviceGeneric;␉␉// Use HPFS / NTFS icon␊ |
942 | ␉␉␉␉break;␊ |
943 | ␊ |
944 | ␉␉␉case kPartitionTypeFAT16:␊ |
945 | ␉␉␉␉devicetype = is_image_loaded(iDeviceFAT16) ? iDeviceFAT16 : iDeviceGeneric;␉␉// Use FAT16 icon␊ |
946 | ␉␉␉␉break;␊ |
947 | ␊ |
948 | ␉␉␉case kPartitionTypeFAT32:␊ |
949 | ␉␉␉␉devicetype = is_image_loaded(iDeviceFAT32) ? iDeviceFAT32 : iDeviceGeneric;␉␉// Use FAT32 icon␊ |
950 | ␉␉␉␉break;␊ |
951 | ␊ |
952 | ␉␉␉case kPartitionTypeEXT3:␊ |
953 | ␉␉␉␉devicetype = is_image_loaded(iDeviceEXT3) ? iDeviceEXT3 : iDeviceGeneric;␉␉// Use EXT2/3 icon␊ |
954 | ␉␉␉␉break;␊ |
955 | ␊ |
956 | ␉␉␉case kPartitionTypeFreeBSD: /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
957 | ␉␉␉␉devicetype = is_image_loaded(iDeviceFreeBSD) ? iDeviceFreeBSD : iDeviceGeneric;␉␉// Use FreeBSD icon␊ |
958 | ␉␉␉␉break;␊ |
959 | ␊ |
960 | ␉␉␉case kPartitionTypeOpenBSD: /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
961 | ␉␉␉␉devicetype = is_image_loaded(iDeviceOpenBSD) ? iDeviceOpenBSD : iDeviceGeneric;␉␉// Use OpenBSD icon␊ |
962 | ␉␉␉␉break;␊ |
963 | ␊ |
964 | ␉␉␉case kPartitionTypeBEFS: /* Haiku detection and Icon credits to scorpius */␊ |
965 | ␉␉␉␉devicetype = is_image_loaded(iDeviceBEFS) ? iDeviceBEFS : iDeviceGeneric;// Use BEFS / Haiku icon␊ |
966 | ␉␉␉␉break;␊ |
967 | ␊ |
968 | ␉␉␉default:␊ |
969 | ␉␉␉␉devicetype = iDeviceGeneric;␉// Use Generic icon␊ |
970 | ␉␉␉␉break;␊ |
971 | ␉␉}␊ |
972 | ␉}␊ |
973 | ␉␊ |
974 | ␉// Draw the selection image and use the next (device_*_o) image for the selected item.␊ |
975 | if (isSelected)␊ |
976 | ␉{␊ |
977 | ␉␉blend(images[iSelection].image, buffer, centeredAt(images[iSelection].image, p));␊ |
978 | ␉␉devicetype++; // selec override image ␊ |
979 | ␉}␊ |
980 | ␊ |
981 | ␉// draw icon␊ |
982 | ␉blend( images[devicetype].image, buffer, centeredAt( images[devicetype].image, p ));␊ |
983 | ␉␊ |
984 | ␉p.y += (images[iSelection].image->height / 2) + font_console.chars[0]->height;␊ |
985 | ␉␊ |
986 | ␉// draw volume label ␊ |
987 | ␉drawStrCenteredAt( device->label, &font_small, buffer, p);␉␊ |
988 | ␊ |
989 | }␊ |
990 | ␊ |
991 | void drawDeviceList (int start, int end, int selection)␊ |
992 | {␊ |
993 | ␉int␉␉␉i;␊ |
994 | ␉bool␉␉shoWinfo = false;␊ |
995 | ␉extern bool showBootBanner;␊ |
996 | ␉position_t␉p, p_prev, p_next;␊ |
997 | ␊ |
998 | ␉//uint8_t␉maxDevices = MIN( gui.maxdevices, menucount );␊ |
999 | ␊ |
1000 | ␉fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);␊ |
1001 | ␊ |
1002 | ␉makeRoundedCorners( gui.devicelist.pixmap);␊ |
1003 | ␊ |
1004 | ␉switch (gui.layout)␊ |
1005 | ␉{␊ |
1006 | ␊ |
1007 | ␉␉case VerticalLayout:␊ |
1008 | ␉␉␉p.x = (gui.devicelist.width /2);␊ |
1009 | ␉␉␉p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );␊ |
1010 | ␊ |
1011 | ␉␉␉// place scroll indicators at top & bottom edges␊ |
1012 | ␉␉␉p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );␊ |
1013 | ␉␉␉p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );␊ |
1014 | ␉␉␉␊ |
1015 | ␉␉␉break;␊ |
1016 | ␉␉␉␊ |
1017 | ␉␉default:␉// use Horizontal layout as the default␊ |
1018 | ␊ |
1019 | ␉␉case HorizontalLayout:␊ |
1020 | ␉␉␉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;␊ |
1021 | ␉␉␉p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );␊ |
1022 | ␊ |
1023 | ␉␉␉// place scroll indicators at left & right edges␊ |
1024 | ␉␉␉p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );␊ |
1025 | ␉␉␉p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );␊ |
1026 | ␉␉␉␊ |
1027 | ␉␉␉break;␊ |
1028 | ␉␉␉␊ |
1029 | ␉}␊ |
1030 | ␉␊ |
1031 | ␉// draw visible device icons␊ |
1032 | ␉for (i = 0; i < gui.maxdevices; i++)␊ |
1033 | ␉{␊ |
1034 | ␉␉BVRef param = menuItems[start + i].param;␊ |
1035 | ␊ |
1036 | bool isSelected = ((start + i) == selection) ? true : false;␊ |
1037 | ␉␉if (isSelected)␊ |
1038 | ␉␉{␊ |
1039 | if (param->flags & kBVFlagNativeBoot)␊ |
1040 | {␊ |
1041 | infoMenuNativeBoot = true;␊ |
1042 | }␊ |
1043 | else␊ |
1044 | {␊ |
1045 | infoMenuNativeBoot = false;␊ |
1046 | if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)␊ |
1047 | infoMenuSelection = 0;␊ |
1048 | }␊ |
1049 | ␊ |
1050 | ␉␉␉if (gui.menu.draw)␊ |
1051 | ␉␉␉␉drawInfoMenuItems();␊ |
1052 | ␉␉␉␊ |
1053 | ␉␉␉getBoolForKey(kShowInfoKey, &shoWinfo, &bootInfo->chameleonConfig);␊ |
1054 | ␉␉␉␊ |
1055 | ␉␉␉if (shoWinfo && showBootBanner)␊ |
1056 | ␉␉␉{␊ |
1057 | ␉␉␉␉gui.debug.cursor = pos( 10, 100);␊ |
1058 | ␉␉␉␉dprintf( &gui.screen, "label: %s\n", param->label );␊ |
1059 | ␉␉␉␉dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev );␊ |
1060 | ␉␉␉␉dprintf( &gui.screen, "type: 0x%x\n", param->type );␊ |
1061 | ␉␉␉␉dprintf( &gui.screen, "flags: 0x%x\n", param->flags );␊ |
1062 | ␉␉␉␉dprintf( &gui.screen, "part_no: %d\n", param->part_no );␊ |
1063 | ␉␉␉␉dprintf( &gui.screen, "part_boff: 0x%x\n", param->part_boff );␊ |
1064 | ␉␉␉␉dprintf( &gui.screen, "part_type: 0x%x\n", param->part_type );␊ |
1065 | ␉␉␉␉dprintf( &gui.screen, "bps: 0x%x\n", param->bps );␊ |
1066 | ␉␉␉␉dprintf( &gui.screen, "name: %s\n", param->name );␊ |
1067 | ␉␉␉␉dprintf( &gui.screen, "type_name: %s\n", param->type_name );␊ |
1068 | ␉␉␉␉dprintf( &gui.screen, "modtime: %d\n", param->modTime );␊ |
1069 | //␉␉␉␉// res␊ |
1070 | ␉␉␉␉dprintf( &gui.screen, "width: %d\n", gui.screen.width );␊ |
1071 | ␉␉␉␉dprintf( &gui.screen, "height: %d\n", gui.screen.height );␊ |
1072 | //␉␉␉␉dprintf( &gui.screen, "attr: 0x%x\n", gui.screen.attr ); //Azi: reminder␊ |
1073 | //␉␉␉␉dprintf( &gui.screen, "mm: %d\n", gui.screen.mm );␊ |
1074 | ␉␉␉}␊ |
1075 | ␉␉}␊ |
1076 | ␉␉␊ |
1077 | ␉␉drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);␊ |
1078 | ␉␉␊ |
1079 | ␉␉if (gui.layout == HorizontalLayout)␊ |
1080 | ␉␉{␊ |
1081 | ␉␉␉p.x += images[iSelection].image->width + gui.devicelist.iconspacing; ␊ |
1082 | ␉␉}␊ |
1083 | ␉␉if (gui.layout == VerticalLayout)␊ |
1084 | ␉␉{␊ |
1085 | ␉␉␉p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing ); ␊ |
1086 | ␉␉}␊ |
1087 | ␉}␊ |
1088 | ␊ |
1089 | ␉// draw prev indicator␊ |
1090 | ␉if (start)␊ |
1091 | ␉␉blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );␊ |
1092 | ␊ |
1093 | ␉// draw next indicator␊ |
1094 | ␉if ( end < gDeviceCount - 1 )␊ |
1095 | ␉␉blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );␊ |
1096 | ␊ |
1097 | ␉gui.redraw = true;␊ |
1098 | ␉␊ |
1099 | ␉updateVRAM();␊ |
1100 | ␉␊ |
1101 | }␊ |
1102 | ␊ |
1103 | void clearGraphicBootPrompt()␊ |
1104 | {␊ |
1105 | ␉// clear text buffer␊ |
1106 | ␉//prompt[0] = '\0';␊ |
1107 | ␉//prompt_pos=0;␊ |
1108 | ␊ |
1109 | ␉␊ |
1110 | ␉if(␉gui.bootprompt.draw == true )␊ |
1111 | ␉{␊ |
1112 | ␉␉gui.bootprompt.draw = false;␊ |
1113 | ␉␉gui.redraw = true;␊ |
1114 | ␉␉// this causes extra frames to be drawn␊ |
1115 | ␉␉//updateVRAM();␊ |
1116 | ␉}␊ |
1117 | ␊ |
1118 | ␉return;␊ |
1119 | }␊ |
1120 | ␊ |
1121 | void updateGraphicBootPrompt()␊ |
1122 | {␊ |
1123 | ␉fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);␊ |
1124 | ␊ |
1125 | ␉makeRoundedCorners( gui.bootprompt.pixmap);␊ |
1126 | ␊ |
1127 | ␉position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );␊ |
1128 | ␊ |
1129 | ␉// print the boot prompt text␊ |
1130 | ␉drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);␊ |
1131 | ␉␊ |
1132 | ␉// get the position of the end of the boot prompt text to display user input␊ |
1133 | ␉position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );␊ |
1134 | ␉␊ |
1135 | ␉drawStr( gBootArgs, &font_console, gui.bootprompt.pixmap, p_prompt);␊ |
1136 | ␊ |
1137 | ␉gui.menu.draw = false;␊ |
1138 | ␉gui.bootprompt.draw = true;␊ |
1139 | ␉gui.redraw = true;␊ |
1140 | ␉␊ |
1141 | ␉updateVRAM();␊ |
1142 | ␉␊ |
1143 | ␉return;␊ |
1144 | }␊ |
1145 | ␊ |
1146 | inline␊ |
1147 | void vramwrite (void *data, int width, int height)␊ |
1148 | {␊ |
1149 | ␉if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)␊ |
1150 | ␉␉memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));␊ |
1151 | ␉else␊ |
1152 | ␉{␊ |
1153 | ␉␉uint32_t r, g, b;␊ |
1154 | ␉␉int i, j;␊ |
1155 | ␉␉for (i = 0; i < VIDEO (height); i++)␊ |
1156 | ␉␉␉for (j = 0; j < VIDEO (width); j++)␊ |
1157 | ␉␉␉{␊ |
1158 | ␉␉␉␉b = ((uint8_t *) data)[4*i*width + 4*j];␊ |
1159 | ␉␉␉␉g = ((uint8_t *) data)[4*i*width + 4*j + 1];␊ |
1160 | ␉␉␉␉r = ((uint8_t *) data)[4*i*width + 4*j + 2];␊ |
1161 | ␉␉␉␉switch (VIDEO (depth))␊ |
1162 | ␉␉␉␉{␊ |
1163 | ␉␉␉␉␉case 32:␊ |
1164 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
1165 | ␉␉␉␉␉␉break;␊ |
1166 | ␉␉␉␉␉case 24:␊ |
1167 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)␊ |
1168 | ␉␉␉␉␉␉| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
1169 | ␉␉␉␉␉␉break;␊ |
1170 | ␉␉␉␉␉case 16:␊ |
1171 | ␉␉␉␉␉␉// Somehow 16-bit is always 15-bits really␊ |
1172 | ␉␉␉␉␉␉//␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);␊ |
1173 | ␉␉␉␉␉␉//␉␉␉␉␉␉break;␉␉␉␉␉␉␉␊ |
1174 | ␉␉␉␉␉case 15:␊ |
1175 | ␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);␊ |
1176 | ␉␉␉␉␉␉break;␉␊ |
1177 | ␉␉␉␉}␊ |
1178 | ␉␉␉}␊ |
1179 | ␉}␊ |
1180 | }␊ |
1181 | ␊ |
1182 | void updateVRAM()␊ |
1183 | {␊ |
1184 | ␉if (gui.redraw)␊ |
1185 | ␉{␊ |
1186 | ␉␉if (gui.devicelist.draw)␊ |
1187 | ␉␉␉blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );␊ |
1188 | ␊ |
1189 | ␉␉if (gui.bootprompt.draw)␊ |
1190 | ␉␉␉blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );␊ |
1191 | ␊ |
1192 | ␉␉if (gui.menu.draw)␊ |
1193 | ␉␉␉blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );␊ |
1194 | ␉␉␊ |
1195 | ␉␉if (gui.infobox.draw)␊ |
1196 | ␉␉␉blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );␊ |
1197 | ␉}␊ |
1198 | ␊ |
1199 | ␉vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );␊ |
1200 | ␊ |
1201 | ␉if (gui.redraw)␊ |
1202 | ␉{␊ |
1203 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
1204 | ␉␉gui.redraw = false;␊ |
1205 | ␉}␊ |
1206 | }␊ |
1207 | ␊ |
1208 | struct putc_info //Azi: exists on console.c & printf.c␊ |
1209 | {␊ |
1210 | char * str;␊ |
1211 | char * last_str;␊ |
1212 | };␊ |
1213 | ␊ |
1214 | static int␊ |
1215 | sputc(int c, struct putc_info * pi) //Azi: same as above␊ |
1216 | {␊ |
1217 | if (pi->last_str)␊ |
1218 | if (pi->str == pi->last_str) {␊ |
1219 | *(pi->str) = '\0';␊ |
1220 | return 0;␊ |
1221 | }␊ |
1222 | *(pi->str)++ = c;␊ |
1223 | return c;␊ |
1224 | }␊ |
1225 | ␊ |
1226 | int gprintf( window_t * window, const char * fmt, ...)␊ |
1227 | {␊ |
1228 | ␉char *formattedtext;␊ |
1229 | ␊ |
1230 | ␉va_list ap;␊ |
1231 | ␉␊ |
1232 | ␉struct putc_info pi;␊ |
1233 | ␊ |
1234 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1235 | ␉␉// format the text␊ |
1236 | ␉␉va_start(ap, fmt);␊ |
1237 | ␉␉pi.str = formattedtext;␊ |
1238 | ␉␉pi.last_str = 0;␊ |
1239 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1240 | ␉␉*pi.str = '\0';␊ |
1241 | ␉␉va_end(ap);␊ |
1242 | ␉␉␊ |
1243 | ␉␉position_t␉origin, cursor, bounds;␊ |
1244 | ␊ |
1245 | ␉␉int i;␊ |
1246 | ␉␉int character;␊ |
1247 | ␊ |
1248 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1249 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1250 | ␉␉␊ |
1251 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1252 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1253 | ␉␉␊ |
1254 | ␉␉cursor = origin;␊ |
1255 | ␊ |
1256 | ␉␉font_t *font = &font_console;␊ |
1257 | ␊ |
1258 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1259 | ␉␉{␊ |
1260 | ␉␉␉character = formattedtext[i];␊ |
1261 | ␉␉␉␊ |
1262 | ␉␉␉character -= 32;␊ |
1263 | ␊ |
1264 | ␉␉␉// newline ?␊ |
1265 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1266 | ␉␉␉{␊ |
1267 | ␉␉␉␉cursor.x = window->hborder;␊ |
1268 | ␉␉␉␉cursor.y += font->height;␊ |
1269 | ␊ |
1270 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1271 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1272 | ␊ |
1273 | ␉␉␉␉continue;␊ |
1274 | ␉␉␉}␊ |
1275 | ␊ |
1276 | ␉␉␉// tab ?␊ |
1277 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1278 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1279 | ␉␉␉␊ |
1280 | ␉␉␉// draw the character␊ |
1281 | ␉␉␉if( font->chars[character])␊ |
1282 | ␉␉␉␉blend(font->chars[character], window->pixmap, cursor);␊ |
1283 | ␊ |
1284 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1285 | ␊ |
1286 | ␉␉␉// check x pos and do newline␊ |
1287 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1288 | ␉␉␉{␊ |
1289 | ␉␉␉␉cursor.x = origin.x;␊ |
1290 | ␉␉␉␉cursor.y += font->height;␊ |
1291 | ␉␉␉}␊ |
1292 | ␉␉␉␊ |
1293 | ␉␉␉// check y pos and reset to origin.y␊ |
1294 | ␉␉␉if ( cursor.y > bounds.y )␊ |
1295 | ␉␉␉␉cursor.y = origin.y;␊ |
1296 | ␉␉}␊ |
1297 | ␊ |
1298 | ␉␉// update cursor postition␊ |
1299 | ␉␉window->cursor = cursor;␊ |
1300 | ␉␉␊ |
1301 | ␉␉free(formattedtext);␊ |
1302 | ␉␉␊ |
1303 | ␉␉return 0;␊ |
1304 | ␊ |
1305 | ␉}␊ |
1306 | ␉return 1;␊ |
1307 | }␊ |
1308 | ␊ |
1309 | int dprintf( window_t * window, const char * fmt, ...)␊ |
1310 | {␊ |
1311 | ␉char *formattedtext;␊ |
1312 | ␉␊ |
1313 | ␉va_list ap;␊ |
1314 | ␉␊ |
1315 | ␉//window = &gui.debug;␊ |
1316 | ␉␊ |
1317 | ␉struct putc_info pi;␊ |
1318 | ␉␊ |
1319 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1320 | ␉␉// format the text␊ |
1321 | ␉␉va_start(ap, fmt);␊ |
1322 | ␉␉pi.str = formattedtext;␊ |
1323 | ␉␉pi.last_str = 0;␊ |
1324 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1325 | ␉␉*pi.str = '\0';␊ |
1326 | ␉␉va_end(ap);␊ |
1327 | ␉␉␊ |
1328 | ␉␉position_t␉origin, cursor, bounds;␊ |
1329 | ␉␉␊ |
1330 | ␉␉int i;␊ |
1331 | ␉␉int character;␊ |
1332 | ␉␉␊ |
1333 | ␉␉origin.x = MAX( gui.debug.cursor.x, window->hborder );␊ |
1334 | ␉␉origin.y = MAX( gui.debug.cursor.y, window->vborder );␊ |
1335 | ␉␉␊ |
1336 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1337 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1338 | ␉␉␊ |
1339 | ␉␉cursor = origin;␊ |
1340 | ␉␉␊ |
1341 | ␉␉font_t *font = &font_console;␊ |
1342 | ␉␉␊ |
1343 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1344 | ␉␉{␊ |
1345 | ␉␉␉character = formattedtext[i];␊ |
1346 | ␉␉␉␊ |
1347 | ␉␉␉character -= 32;␊ |
1348 | ␉␉␉␊ |
1349 | ␉␉␉// newline ?␊ |
1350 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1351 | ␉␉␉{␊ |
1352 | ␉␉␉␉cursor.x = window->hborder;␊ |
1353 | ␉␉␉␉cursor.y += font->height;␊ |
1354 | ␉␉␉␉␊ |
1355 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1356 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1357 | ␉␉␉␉␊ |
1358 | ␉␉␉␉continue;␊ |
1359 | ␉␉␉}␊ |
1360 | ␉␉␉␊ |
1361 | ␉␉␉// tab ?␊ |
1362 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1363 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1364 | ␉␉␉␊ |
1365 | ␉␉␉// draw the character␊ |
1366 | ␉␉␉if( font->chars[character])␊ |
1367 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1368 | ␊ |
1369 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1370 | ␉␉␉␊ |
1371 | ␉␉␉// check x pos and do newline␊ |
1372 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1373 | ␉␉␉{␊ |
1374 | ␉␉␉␉cursor.x = origin.x;␊ |
1375 | ␉␉␉␉cursor.y += font->height;␊ |
1376 | ␉␉␉}␊ |
1377 | ␉␉␉␊ |
1378 | ␉␉␉// check y pos and reset to origin.y␊ |
1379 | ␉␉␉if ( cursor.y > bounds.y )␊ |
1380 | ␉␉␉␉cursor.y = origin.y;␊ |
1381 | ␉␉}␊ |
1382 | ␉␉␊ |
1383 | ␉␉// update cursor postition␊ |
1384 | ␉␉gui.debug.cursor = cursor;␊ |
1385 | ␉␉␊ |
1386 | ␉␉free(formattedtext);␊ |
1387 | ␉␉␊ |
1388 | ␉␉return 0;␊ |
1389 | ␉␉␊ |
1390 | ␉}␊ |
1391 | ␉return 1;␊ |
1392 | }␊ |
1393 | ␊ |
1394 | int vprf(const char * fmt, va_list ap)␊ |
1395 | {␊ |
1396 | ␉int i;␊ |
1397 | ␉int character;␊ |
1398 | ␊ |
1399 | ␉char *formattedtext;␊ |
1400 | ␉window_t *window = &gui.screen;␊ |
1401 | ␉struct putc_info pi;␊ |
1402 | ␉␊ |
1403 | ␉position_t␉origin, cursor, bounds;␊ |
1404 | ␉font_t *font = &font_console;␊ |
1405 | ␉␊ |
1406 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1407 | ␉␉// format the text␊ |
1408 | ␉␉pi.str = formattedtext;␊ |
1409 | ␉␉pi.last_str = 0;␊ |
1410 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1411 | ␉␉*pi.str = '\0';␊ |
1412 | ␉␉␊ |
1413 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1414 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1415 | ␉␉bounds.x = ( window->width - ( window->hborder * 2 ) );␊ |
1416 | ␉␉bounds.y = ( window->height - ( window->vborder * 2 ) );␊ |
1417 | ␉␉cursor = origin;␊ |
1418 | ␊ |
1419 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1420 | ␉␉{␊ |
1421 | ␉␉␉character = formattedtext[i];␊ |
1422 | ␉␉␉character -= 32;␊ |
1423 | ␉␉␉␊ |
1424 | ␉␉␉// newline ?␊ |
1425 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1426 | ␉␉␉{␊ |
1427 | ␉␉␉␉cursor.x = window->hborder;␊ |
1428 | ␉␉␉␉cursor.y += font->height;␊ |
1429 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1430 | ␉␉␉␉{␊ |
1431 | ␉␉␉␉␉gui.redraw = true;␊ |
1432 | ␉␉␉␉␉updateVRAM();␊ |
1433 | ␉␉␉␉␉cursor.y = window->vborder;␊ |
1434 | ␉␉␉␉}␊ |
1435 | ␉␉␉␉window->cursor.y = cursor.y;␊ |
1436 | ␉␉␉␉continue;␊ |
1437 | ␉␉␉}␊ |
1438 | ␊ |
1439 | ␉␉␉// tab ?␊ |
1440 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1441 | ␉␉␉{␊ |
1442 | ␉␉␉␉cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );␊ |
1443 | ␉␉␉␉continue;␊ |
1444 | ␉␉␉}␊ |
1445 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1446 | ␉␉␉␊ |
1447 | ␉␉␉// check x pos and do newline␊ |
1448 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1449 | ␉␉␉{␊ |
1450 | ␉␉␉␉cursor.x = origin.x;␊ |
1451 | ␉␉␉␉cursor.y += font->height;␊ |
1452 | ␉␉␉}␊ |
1453 | ␊ |
1454 | ␉␉␉// check y pos and reset to origin.y␊ |
1455 | ␉␉␉if ( cursor.y > ( bounds.y + font->chars[0]->height) )␊ |
1456 | ␉␉␉{␊ |
1457 | ␉␉␉␉gui.redraw = true;␊ |
1458 | ␉␉␉␉updateVRAM();␊ |
1459 | ␉␉␉␉cursor.y = window->vborder;␊ |
1460 | ␉␉␉}␊ |
1461 | ␉␉␉// draw the character␊ |
1462 | ␉␉␉if( font->chars[character])␊ |
1463 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1464 | ␉␉}␊ |
1465 | ␉␉// save cursor postition␊ |
1466 | ␉␉window->cursor.x = cursor.x;␊ |
1467 | ␉␉updateVRAM();␊ |
1468 | ␉␉free(formattedtext);␊ |
1469 | ␉␉return 0;␊ |
1470 | ␉}␊ |
1471 | ␉return 1;␊ |
1472 | }␊ |
1473 | ␊ |
1474 | pixmap_t* charToPixmap(unsigned char ch, font_t *font) {␊ |
1475 | ␉unsigned int cha = (unsigned int)ch - 32;␊ |
1476 | ␉if (cha >= font->count)␊ |
1477 | ␉␉// return ? if the font for the char doesn't exists␊ |
1478 | ␉␉cha = '?' - 32;␊ |
1479 | ␊ |
1480 | ␉return font->chars[cha] ? font->chars[cha] : NULL;␊ |
1481 | }␊ |
1482 | ␊ |
1483 | position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) {␊ |
1484 | ␉pixmap_t* pm = charToPixmap(ch, font);␊ |
1485 | ␉if (pm && ((p.x + pm->width) < blendInto->width))␊ |
1486 | ␉{␊ |
1487 | ␉␉blend(pm, blendInto, p);␊ |
1488 | ␉␉return pos(p.x + pm->width, p.y);␊ |
1489 | ␉}␊ |
1490 | ␉else␊ |
1491 | ␉␉return p;␊ |
1492 | }␊ |
1493 | ␊ |
1494 | void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1495 | {␊ |
1496 | ␉int i=0;␊ |
1497 | ␉position_t current_pos = pos(p.x, p.y);␊ |
1498 | ␉␊ |
1499 | ␉for (i=0; i < strlen(ch); i++)␊ |
1500 | ␉{␊ |
1501 | ␉␉// newline ?␊ |
1502 | ␉␉if ( ch[i] == '\n' )␊ |
1503 | ␉␉{␊ |
1504 | ␉␉␉current_pos.x = p.x;␊ |
1505 | ␉␉␉current_pos.y += font->height;␊ |
1506 | ␉␉␉continue;␊ |
1507 | ␉␉}␊ |
1508 | ␉␉␊ |
1509 | ␉␉// tab ?␊ |
1510 | ␉␉if ( ch[i] == '\t' )␊ |
1511 | ␉␉{␊ |
1512 | ␉␉␉current_pos.x += TAB_PIXELS_WIDTH;␊ |
1513 | ␉␉␉continue;␊ |
1514 | ␉␉}␊ |
1515 | ␉␉␊ |
1516 | ␉␉current_pos = drawChar(ch[i], font, blendInto, current_pos);␊ |
1517 | ␉}␊ |
1518 | }␊ |
1519 | ␊ |
1520 | void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1521 | {␊ |
1522 | ␉int i = 0;␊ |
1523 | ␉int width = 0;␊ |
1524 | ␉int max_width = 0;␊ |
1525 | ␉int height = font->height;␊ |
1526 | ␊ |
1527 | ␉// calculate the width in pixels␊ |
1528 | ␉for (i=0; i < strlen(text); i++) {␊ |
1529 | ␉␉if (text[i] == '\n')␊ |
1530 | ␉␉{␊ |
1531 | ␉␉␉width = 0;␊ |
1532 | ␉␉␉height += font->height;␊ |
1533 | ␉␉}␊ |
1534 | ␉␉else if (text[i] == '\t')␊ |
1535 | ␉␉␉width += TAB_PIXELS_WIDTH;␊ |
1536 | ␉␉else␊ |
1537 | ␉␉{␊ |
1538 | ␉␉␉pixmap_t* pm = charToPixmap(text[i], font);␊ |
1539 | ␉␉␉if (pm)␊ |
1540 | ␉␉␉␉width += pm->width;␊ |
1541 | ␉␉}␊ |
1542 | ␉␉if (width > max_width)␊ |
1543 | ␉␉␉max_width = width;␊ |
1544 | ␉}␊ |
1545 | ␊ |
1546 | ␉p.x = ( p.x - ( max_width / 2 ) );␊ |
1547 | ␉p.y = ( p.y - ( height / 2 ) );␊ |
1548 | ␉␊ |
1549 | ␉drawStr(text, font, blendInto, p);␊ |
1550 | }␊ |
1551 | ␊ |
1552 | int initFont(font_t *font, image_t *data)␊ |
1553 | {␊ |
1554 | ␉unsigned int x = 0, y = 0, x2 = 0, x3 = 0;␊ |
1555 | ␉␊ |
1556 | ␉int start = 0, end = 0, count = 0, space = 0;␊ |
1557 | ␉␊ |
1558 | ␉bool monospaced = false;␊ |
1559 | ␉␊ |
1560 | ␉font->height = data->image->height;␊ |
1561 | ␊ |
1562 | ␉for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++)␊ |
1563 | ␉{␊ |
1564 | ␉␉start = end;␊ |
1565 | ␊ |
1566 | ␉␉// if the pixel is red we've reached the end of the char␊ |
1567 | ␉␉if( pixel( data->image, x, 0 ).value == 0xFFFF0000)␊ |
1568 | ␉␉{␊ |
1569 | ␉␉␉end = x + 1;␊ |
1570 | ␊ |
1571 | ␉␉␉if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )␊ |
1572 | ␉␉␉{␊ |
1573 | ␉␉␉␉font->chars[count]->width = ( end - start) - 1;␊ |
1574 | ␉␉␉␉font->chars[count]->height = font->height;␊ |
1575 | ␉␉␉␊ |
1576 | ␉␉␉␉if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )␊ |
1577 | ␉␉␉␉{␊ |
1578 | ␉␉␉␉␉space += ( font->chars[count]->width * data->image->height * 4 );␊ |
1579 | ␉␉␉␉␉// we skip the first line because there are just the red pixels for the char width␊ |
1580 | ␉␉␉␉␉for( y = 1; y< (font->height); y++)␊ |
1581 | ␉␉␉␉␉{␊ |
1582 | ␉␉␉␉␉␉for( x2 = start, x3 = 0; x2 < end; x2++, x3++)␊ |
1583 | ␉␉␉␉␉␉{␊ |
1584 | ␉␉␉␉␉␉␉pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );␊ |
1585 | ␉␉␉␉␉␉}␉␊ |
1586 | ␉␉␉␉␉}␊ |
1587 | ␉␉␉␉␉␊ |
1588 | ␉␉␉␉␉// check if font is monospaced␊ |
1589 | ␉␉␉␉␉if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )␊ |
1590 | ␉␉␉␉␉␉monospaced = true;␊ |
1591 | ␊ |
1592 | ␉␉␉␉␉font->width = font->chars[count]->width;␊ |
1593 | ␉␉␉␉␉␊ |
1594 | ␉␉␉␉␉count++;␊ |
1595 | ␉␉␉␉}␊ |
1596 | ␉␉␉}␊ |
1597 | ␉␉}␊ |
1598 | ␉}␊ |
1599 | ␊ |
1600 | ␉for (x = count; x < CHARACTERS_COUNT; x++)␊ |
1601 | ␉␉font->chars[x] = NULL;␊ |
1602 | ␊ |
1603 | ␉if(monospaced)␊ |
1604 | ␉␉font->width = 0;␊ |
1605 | ␊ |
1606 | ␉font->count = count;␊ |
1607 | ␊ |
1608 | ␉return 0;␊ |
1609 | }␊ |
1610 | ␊ |
1611 | int destroyFont(font_t *font)␊ |
1612 | {␊ |
1613 | int i;␊ |
1614 | for (i = 0; i < CHARACTERS_COUNT; i++)␊ |
1615 | {␊ |
1616 | if (font->chars[i])␊ |
1617 | {␊ |
1618 | if (font->chars[i]->pixels) free (font->chars[i]->pixels);␊ |
1619 | free (font->chars[i]);␊ |
1620 | font->chars[i] = 0;␊ |
1621 | }␊ |
1622 | }␊ |
1623 | return 0;␊ |
1624 | }␊ |
1625 | ␊ |
1626 | void colorFont(font_t *font, uint32_t color)␊ |
1627 | {␊ |
1628 | ␉if( !color )␊ |
1629 | ␉␉return;␊ |
1630 | ␉␊ |
1631 | ␉int x, y, width, height;␊ |
1632 | ␉int count = 0;␊ |
1633 | ␉pixel_t *buff;␊ |
1634 | ␉␊ |
1635 | ␉while( font->chars[count++] )␊ |
1636 | ␉{␊ |
1637 | ␉␉width = font->chars[count-1]->width;␊ |
1638 | ␉␉height = font->chars[count-1]->height;␊ |
1639 | ␉␉for( y = 0; y < height; y++ )␊ |
1640 | ␉␉{␊ |
1641 | ␉␉␉for( x = 0; x < width; x++ )␊ |
1642 | ␉␉␉{␊ |
1643 | ␉␉␉␉buff = &(pixel( font->chars[count-1], x, y ));␊ |
1644 | ␉␉␉␉if( buff->ch.a )␊ |
1645 | ␉␉␉␉{␊ |
1646 | ␉␉␉␉␉buff->ch.r = (color & 0xFFFF0000) >> 16;␊ |
1647 | ␉␉␉␉␉buff->ch.g = (color & 0xFF00FF00) >> 8;␊ |
1648 | ␉␉␉␉␉buff->ch.b = (color & 0xFF0000FF);␊ |
1649 | ␉␉␉␉}␊ |
1650 | ␉␉␉}␊ |
1651 | ␉␉}␊ |
1652 | ␉}␊ |
1653 | }␊ |
1654 | ␊ |
1655 | void makeRoundedCorners(pixmap_t *p)␊ |
1656 | {␊ |
1657 | ␉int x,y;␊ |
1658 | ␉int width=p->width-1;␊ |
1659 | ␉int height=p->height-1;␊ |
1660 | ␉␊ |
1661 | ␉// 10px rounded corner alpha values␊ |
1662 | ␉uint8_t roundedCorner[10][10] =␊ |
1663 | ␉{␊ |
1664 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},␊ |
1665 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1666 | ␉␉{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1667 | ␉␉{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1668 | ␉␉{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1669 | ␉␉{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1670 | ␉␉{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1671 | ␉␉{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1672 | ␉␉{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1673 | ␉␉{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}␊ |
1674 | ␉};␊ |
1675 | ␉␊ |
1676 | ␉uint8_t alpha=0;␊ |
1677 | ␉␊ |
1678 | ␉for( y=0; y<10; y++)␊ |
1679 | ␉{␊ |
1680 | ␉␉for( x=0; x<10; x++)␊ |
1681 | ␉␉{␊ |
1682 | ␉␉␉// skip if the pixel should be visible␊ |
1683 | ␉␉␉if(roundedCorner[y][x] != 0xFF) ␊ |
1684 | ␉␉␉{ ␊ |
1685 | ␉␉␉␉alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );␊ |
1686 | ␉␉␉␉// Upper left corner␊ |
1687 | ␉␉␉␉pixel(p, x, y).ch.a = alpha;␊ |
1688 | ␊ |
1689 | ␉␉␉␉// upper right corner␊ |
1690 | ␉␉␉␉pixel(p, width-x,y).ch.a = alpha;␊ |
1691 | ␊ |
1692 | ␉␉␉␉// lower left corner␊ |
1693 | ␉␉␉␉pixel(p, x, height-y).ch.a = alpha;␊ |
1694 | ␊ |
1695 | ␉␉␉␉// lower right corner␊ |
1696 | ␉␉␉␉pixel(p, width-x, height-y).ch.a = alpha;␊ |
1697 | ␉␉␉}␊ |
1698 | ␉␉}␊ |
1699 | ␉}␊ |
1700 | }␊ |
1701 | ␊ |
1702 | void showInfoBox(char *title, char *text_orig)␊ |
1703 | {␊ |
1704 | ␉char* text;␊ |
1705 | ␉int i, key, lines, visiblelines;␊ |
1706 | ␊ |
1707 | ␉int currentline=0;␊ |
1708 | ␉int cnt=0;␊ |
1709 | ␉int offset=0;␊ |
1710 | ␉␊ |
1711 | ␉if( !title || !text_orig )␊ |
1712 | ␉␉return;␊ |
1713 | ␉␊ |
1714 | ␉// Create a copy so that we don't mangle the original␊ |
1715 | ␉text = malloc(strlen(text_orig) + 1);␊ |
1716 | ␉strcpy(text, text_orig);␊ |
1717 | ␉␊ |
1718 | ␉␊ |
1719 | ␉position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );␊ |
1720 | ␊ |
1721 | ␉// calculate number of lines in the title␊ |
1722 | ␉for ( i = 0, lines = 1; i<strlen(title); i++ )␊ |
1723 | ␉␉if( title[i] == '\n')␊ |
1724 | ␉␉␉lines++;␊ |
1725 | ␉␊ |
1726 | ␉// y position of text is lines in title * height of font␊ |
1727 | ␉position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));␊ |
1728 | ␉␊ |
1729 | ␉// calculate number of lines in the text␊ |
1730 | ␉for ( i=0, lines = 1; i<strlen(text); i++ )␊ |
1731 | ␉␉if( text[i] == '\n')␊ |
1732 | ␉␉␉lines++;␊ |
1733 | ␉␊ |
1734 | ␉// if text ends with \n strip off␊ |
1735 | ␉if( text[i] == '\n' || text[i] == '\0')␊ |
1736 | ␉␉lines--;␊ |
1737 | ␉␊ |
1738 | ␉visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;␊ |
1739 | ␉␊ |
1740 | ␉// lets display the text and allow scroll thru using up down / arrows␊ |
1741 | ␉while(1)␊ |
1742 | ␉{␊ |
1743 | ␉␉// move to current line in text␊ |
1744 | ␉␉for( offset = 0, i = 0; offset < strlen(text); offset++ )␊ |
1745 | ␉␉{␊ |
1746 | ␉␉␉if( currentline == i)␊ |
1747 | ␉␉␉␉break;␊ |
1748 | ␉␉␉if( text[offset] =='\n')␊ |
1749 | ␉␉␉␉i++;␊ |
1750 | ␉␉}␊ |
1751 | ␊ |
1752 | ␉␉// find last visible line in text and place \0␊ |
1753 | ␉␉for( i = offset, cnt = 0; i < strlen(text); i++)␊ |
1754 | ␉␉{␊ |
1755 | ␉␉␉if(text[i]=='\n')␊ |
1756 | ␉␉␉␉cnt++;␊ |
1757 | ␉␉␉if ( cnt == visiblelines )␊ |
1758 | ␉␉␉{␊ |
1759 | ␉␉␉␉text[i]='\0';␊ |
1760 | ␉␉␉␉break;␊ |
1761 | ␉␉␉}␊ |
1762 | ␉␉}␊ |
1763 | ␊ |
1764 | ␉␉fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);␊ |
1765 | ␊ |
1766 | ␉␉makeRoundedCorners( gui.infobox.pixmap);␊ |
1767 | ␊ |
1768 | ␉␉// print the title if present␊ |
1769 | ␉␉if( title )␊ |
1770 | ␉␉␉drawStr(title, &font_console, gui.infobox.pixmap, pos_title);␊ |
1771 | ␊ |
1772 | ␉␉// print the text␊ |
1773 | ␉␉drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);␊ |
1774 | ␊ |
1775 | ␉␉// restore \n in text␊ |
1776 | ␉␉if ( cnt == visiblelines )␊ |
1777 | ␉␉␉text[i] = '\n';␊ |
1778 | ␉␉␊ |
1779 | ␉␉position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );␊ |
1780 | ␉␉␊ |
1781 | ␉␉// draw prev indicator␊ |
1782 | ␉␉if(offset)␊ |
1783 | ␉␉{␊ |
1784 | ␉␉␉blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));␊ |
1785 | ␉␉}␊ |
1786 | ␉␉␊ |
1787 | ␉␉// draw next indicator␊ |
1788 | ␉␉if( lines > ( currentline + visiblelines ) )␊ |
1789 | ␉␉{␊ |
1790 | ␉␉␉pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );␊ |
1791 | ␉␉␉blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );␊ |
1792 | ␉␉}␊ |
1793 | ␊ |
1794 | ␉␉gui.bootprompt.draw = false;␊ |
1795 | ␉␉gui.infobox.draw = true;␊ |
1796 | ␉␉gui.redraw = true;␊ |
1797 | ␉␉␊ |
1798 | ␉␉updateVRAM();␊ |
1799 | ␉␉␊ |
1800 | ␉␉key = getchar();␊ |
1801 | ␉␉␉␊ |
1802 | ␉␉if( key == KEY_UP )␊ |
1803 | ␉␉␉if( currentline > 0 )␊ |
1804 | ␉␉␉␉currentline--;␊ |
1805 | ␊ |
1806 | ␉␉if( key == KEY_DOWN )␊ |
1807 | ␉␉␉if( lines > ( currentline + visiblelines ) )␊ |
1808 | ␉␉␉␉currentline++;␊ |
1809 | ␊ |
1810 | ␉␉if( key == KEY_ESC || key == 'q' || key == 'Q')␊ |
1811 | ␉␉{␊ |
1812 | ␉␉␉gui.infobox.draw = false;␊ |
1813 | ␉␉␉gui.redraw = true;␊ |
1814 | ␉␉␉updateVRAM();␊ |
1815 | ␉␉␉break;␊ |
1816 | ␉␉}␊ |
1817 | ␊ |
1818 | ␉␉if(key == ' ') // spacebar = next page␊ |
1819 | ␉␉{␊ |
1820 | ␉␉␉if( lines > ( currentline + visiblelines ) ) ␊ |
1821 | ␉␉␉␉currentline += visiblelines;␊ |
1822 | ␉␉␉␊ |
1823 | ␉␉␉if(lines < (currentline + visiblelines))␊ |
1824 | ␉␉␉␉currentline = lines - visiblelines;␊ |
1825 | ␉␉}␊ |
1826 | ␉}␊ |
1827 | }␊ |
1828 | ␊ |
1829 | void animateProgressBar()␊ |
1830 | {␊ |
1831 | ␉int y;␊ |
1832 | ␉␊ |
1833 | ␉if( time18() > lasttime)␊ |
1834 | ␉{␊ |
1835 | ␉␉lasttime = time18();␊ |
1836 | ␊ |
1837 | ␉␉pixmap_t *buffBar = images[iProgressBar].image;␊ |
1838 | ␊ |
1839 | ␉␉uint32_t buff = buffBar->pixels[0].value;␊ |
1840 | ␉␊ |
1841 | ␉␉memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );␊ |
1842 | ␊ |
1843 | ␉␉for( y = buffBar->height - 1; y > 0; y--)␊ |
1844 | ␉␉␉pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);␊ |
1845 | ␊ |
1846 | ␉␉pixel(buffBar, buffBar->width-1, 0).value = buff;␊ |
1847 | ␉}␊ |
1848 | }␊ |
1849 | ␊ |
1850 | void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)␊ |
1851 | {␊ |
1852 | ␉if(progress>100)␊ |
1853 | ␉␉return;␊ |
1854 | ␉␊ |
1855 | ␉p.x = ( p.x - ( width / 2 ) );␊ |
1856 | ␊ |
1857 | ␉int todraw = (width * progress) / 100;␊ |
1858 | ␊ |
1859 | ␉pixmap_t *buff = images[iProgressBar].image;␊ |
1860 | ␉pixmap_t *buffBG = images[iProgressBarBackground].image;␊ |
1861 | ␉if(!buff || !buffBG)␊ |
1862 | ␉␉return;␊ |
1863 | ␉␊ |
1864 | ␉pixmap_t progressbar;␊ |
1865 | ␉progressbar.pixels=malloc(width * 4 * buff->height);␊ |
1866 | ␉if(!progressbar.pixels)␊ |
1867 | ␉␉return; ␊ |
1868 | ␉␊ |
1869 | ␉progressbar.width = width;␊ |
1870 | ␉progressbar.height = buff->height;␊ |
1871 | ␊ |
1872 | ␉int x=0,x2=0,y=0;␊ |
1873 | ␉␊ |
1874 | ␉for(y=0; y<buff->height; y++)␊ |
1875 | ␉{␊ |
1876 | ␉␉for(x=0; x<todraw; x++, x2++)␊ |
1877 | ␉␉{␊ |
1878 | ␉␉␉if(x2 == (buff->width-1)) x2=0;␊ |
1879 | ␉␉␉pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;␊ |
1880 | ␉␉}␊ |
1881 | ␉␉x2=0;␊ |
1882 | ␉}␊ |
1883 | ␊ |
1884 | ␉for(y=0; y<buff->height; y++)␊ |
1885 | ␉{␊ |
1886 | ␉␉for(x=todraw, x2 = 0; x < width - 1; x++, x2++)␊ |
1887 | ␉␉{␊ |
1888 | ␉␉␉if(x2 == (buffBG->width -2 )) x2 = 0;␊ |
1889 | ␉␉␉pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;␊ |
1890 | ␉␉}␊ |
1891 | ␉␉if(progress < 100)␊ |
1892 | ␉␉␉pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
1893 | ␉␉if(progress == 0)␊ |
1894 | ␉␉␉pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
1895 | ␉␉x2=0;␊ |
1896 | ␉}␊ |
1897 | ␊ |
1898 | ␉blend(&progressbar, blendInto, p);␊ |
1899 | ␉animateProgressBar();␊ |
1900 | ␉free(progressbar.pixels);␊ |
1901 | }␊ |
1902 | ␊ |
1903 | void drawInfoMenuItems()␊ |
1904 | {␊ |
1905 | ␉int i,n;␊ |
1906 | ␉␊ |
1907 | ␉position_t position;␊ |
1908 | ␉␊ |
1909 | ␉pixmap_t *selection = images[iMenuSelection].image;␊ |
1910 | ␉␊ |
1911 | ␉pixmap_t *pbuff;␊ |
1912 | ␊ |
1913 | ␉fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);␊ |
1914 | ␊ |
1915 | ␉makeRoundedCorners(gui.menu.pixmap);␊ |
1916 | ␉␊ |
1917 | ␉uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;␊ |
1918 | ␊ |
1919 | ␉position = pos(0,0);␊ |
1920 | ␉␊ |
1921 | ␉for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)␊ |
1922 | ␉{␊ |
1923 | ␉␉if (i == infoMenuSelection)␊ |
1924 | ␉␉␉blend(selection, gui.menu.pixmap, position);␊ |
1925 | ␊ |
1926 | ␉␉pbuff = images[n].image;␊ |
1927 | ␉␉if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)␊ |
1928 | ␉␉␉blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap, ␊ |
1929 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
1930 | ␉␉else␊ |
1931 | ␉␉␉blend( pbuff, gui.menu.pixmap, ␊ |
1932 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
1933 | ␊ |
1934 | ␉␉drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap, ␊ |
1935 | ␉␉␉pos(position.x + (pbuff->width + gui.menu.hborder), ␊ |
1936 | ␉␉␉␉position.y + ((selection->height - font_console.height) / 2)));␊ |
1937 | ␉␉position.y += images[iMenuSelection].image->height;␊ |
1938 | ␉␊ |
1939 | ␉}␊ |
1940 | ␉␊ |
1941 | ␉gui.redraw = true;␊ |
1942 | }␊ |
1943 | ␊ |
1944 | int drawInfoMenu()␊ |
1945 | {␊ |
1946 | ␉drawInfoMenuItems();␊ |
1947 | ␊ |
1948 | ␉gui.menu.draw = true;␊ |
1949 | ␊ |
1950 | ␉updateVRAM();␊ |
1951 | ␉␊ |
1952 | ␉return 1;␊ |
1953 | }␊ |
1954 | ␊ |
1955 | int updateInfoMenu(int key)␊ |
1956 | {␊ |
1957 | ␉switch (key)␊ |
1958 | ␉{␊ |
1959 | ␊ |
1960 | ␉␉case KEY_UP:␉// up arrow␊ |
1961 | ␉␉␉␉if (infoMenuSelection > 0)␊ |
1962 | ␉␉␉␉{␊ |
1963 | ␉␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)␊ |
1964 | ␉␉␉␉␉␉infoMenuSelection -= 4;␊ |
1965 | ␉␉␉␉␉␊ |
1966 | ␉␉␉␉␉else␊ |
1967 | ␉␉␉␉␉␉infoMenuSelection--;␊ |
1968 | ␉␉␉␉␉␉drawInfoMenuItems();␊ |
1969 | ␉␉␉␉␉␉updateVRAM();␊ |
1970 | ␉␉␉␉␉␊ |
1971 | ␉␉␉␉} else {␊ |
1972 | ␉␉␉␉␉␊ |
1973 | ␉␉␉␉␉gui.menu.draw = false;␊ |
1974 | ␉␉␉␉␉gui.redraw = true;␊ |
1975 | ␊ |
1976 | ␉␉␉␉␉updateVRAM();␊ |
1977 | ␉␉␉␉␉␊ |
1978 | ␉␉␉␉␉return CLOSE_INFO_MENU;␊ |
1979 | ␉␉␉␉}␊ |
1980 | ␉␉␉␉break;␊ |
1981 | ␊ |
1982 | ␉␉case KEY_DOWN:␉// down arrow␊ |
1983 | ␉␉␉␉if (infoMenuSelection < infoMenuItemsCount - 1)␊ |
1984 | ␉␉␉␉{␊ |
1985 | ␉␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)␊ |
1986 | ␉␉␉␉␉␉infoMenuSelection += 4;␊ |
1987 | ␉␉␉␉␉else␊ |
1988 | ␉␉␉␉␉␉infoMenuSelection++;␊ |
1989 | ␉␉␉␉␉drawInfoMenuItems();␊ |
1990 | ␉␉␉␉␉updateVRAM();␊ |
1991 | ␉␉␉␉}␊ |
1992 | ␉␉␉␉break;␊ |
1993 | ␊ |
1994 | ␉␉case KEY_ENTER:␊ |
1995 | ␉␉␉␉key = 0;␊ |
1996 | ␉␉␉␉if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )␊ |
1997 | ␉␉␉␉␉showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());␊ |
1998 | ␊ |
1999 | ␉␉␉␉else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )␊ |
2000 | ␉␉␉␉␉showInfoBox( getVBEInfoString(), getVBEModeInfoString() );␊ |
2001 | ␉␉␉␊ |
2002 | ␉␉␉␉else if( infoMenuSelection == MENU_SHOW_HELP )␊ |
2003 | ␉␉␉␉␉showHelp();␊ |
2004 | ␊ |
2005 | ␉␉␉␉else␊ |
2006 | ␉␉␉␉{␊ |
2007 | ␉␉␉␉␉int buff = infoMenuSelection;␊ |
2008 | ␉␉␉␉␉infoMenuSelection = 0;␊ |
2009 | ␉␉␉␉␉return buff;␊ |
2010 | ␉␉␉␉}␊ |
2011 | ␉␉␉␉break;␊ |
2012 | ␉␉}␊ |
2013 | ␉return DO_NOT_BOOT;␊ |
2014 | }␊ |
2015 | ␊ |
2016 | uint16_t bootImageWidth = 0; ␊ |
2017 | uint16_t bootImageHeight = 0; ␊ |
2018 | uint8_t *bootImageData = NULL; ␊ |
2019 | static bool usePngImage = true;␊ |
2020 | ␊ |
2021 | //==========================================================================␊ |
2022 | // loadBootGraphics␊ |
2023 | static void loadBootGraphics(void)␊ |
2024 | {␊ |
2025 | ␉if (bootImageData != NULL) {␊ |
2026 | ␉␉return;␊ |
2027 | ␉}␊ |
2028 | ␊ |
2029 | ␉char dirspec[256];␊ |
2030 | ␊ |
2031 | ␉if ((strlen(theme_name) + 24) > sizeof(dirspec)) {␊ |
2032 | ␉␉usePngImage = false; ␊ |
2033 | ␉␉return;␊ |
2034 | ␉}␊ |
2035 | ␉sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);␊ |
2036 | ␉if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {␊ |
2037 | #ifdef CONFIG_EMBED_THEME␊ |
2038 | ␉if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)␊ |
2039 | #endif␊ |
2040 | ␉␉usePngImage = false; ␊ |
2041 | ␉}␊ |
2042 | }␊ |
2043 | ␊ |
2044 | //==========================================================================␊ |
2045 | // drawBootGraphics␊ |
2046 | void drawBootGraphics(void)␊ |
2047 | {␊ |
2048 | ␉int pos;␊ |
2049 | ␉int length;␊ |
2050 | ␉const char *dummyVal;␊ |
2051 | ␉int oldScreenWidth, oldScreenHeight;␊ |
2052 | ␉bool legacy_logo;␊ |
2053 | ␉uint16_t x, y; ␊ |
2054 | ␉␊ |
2055 | ␉if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->chameleonConfig) && legacy_logo) {␊ |
2056 | ␉␉usePngImage = false; ␊ |
2057 | ␉} else if (bootImageData == NULL) {␊ |
2058 | ␉␉loadBootGraphics();␊ |
2059 | ␉}␊ |
2060 | ␊ |
2061 | ␉// parse screen size parameters␊ |
2062 | ␉if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0) {␊ |
2063 | ␉␉screen_params[0] = pos;␊ |
2064 | ␉} else {␊ |
2065 | ␉␉screen_params[0] = DEFAULT_SCREEN_WIDTH;␊ |
2066 | ␉}␊ |
2067 | ␉if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0) {␊ |
2068 | ␉␉screen_params[1] = pos;␊ |
2069 | ␉} else {␊ |
2070 | ␉␉screen_params[1] = DEFAULT_SCREEN_HEIGHT;␊ |
2071 | ␉}␊ |
2072 | ␊ |
2073 | // Save current screen resolution.␊ |
2074 | ␉oldScreenWidth = gui.screen.width;␊ |
2075 | ␉oldScreenHeight = gui.screen.height;␊ |
2076 | ␊ |
2077 | ␉gui.screen.width = screen_params[0];␊ |
2078 | ␉gui.screen.height = screen_params[1];␊ |
2079 | ␊ |
2080 | ␉// find best matching vesa mode for our requested width & height␊ |
2081 | ␉getGraphicModeParams(screen_params);␊ |
2082 | ␊ |
2083 | // Set graphics mode if the booter was in text mode or the screen resolution has changed.␊ |
2084 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE␊ |
2085 | ␉␉|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )␊ |
2086 | ␉{␊ |
2087 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
2088 | ␉}␊ |
2089 | ␊ |
2090 | ␉if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->chameleonConfig)) {␊ |
2091 | ␉␉drawCheckerBoard();␊ |
2092 | ␉} else {␊ |
2093 | ␉␉// Fill the background to 75% grey (same as BootX). ␊ |
2094 | ␉␉drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01); ␊ |
2095 | ␉}␊ |
2096 | ␉if ((bootImageData) && (usePngImage)) { ␊ |
2097 | ␉␉x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2; ␊ |
2098 | ␉␉y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2; ␊ |
2099 | ␊ |
2100 | ␉␉// Draw the image in the center of the display. ␊ |
2101 | ␉␉blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData); ␊ |
2102 | ␉} else { ␊ |
2103 | ␉␉uint8_t *appleBootPict; ␊ |
2104 | ␉␉bootImageData = NULL; ␊ |
2105 | ␉␉bootImageWidth = kAppleBootWidth; ␊ |
2106 | ␉␉bootImageHeight = kAppleBootHeight; ␊ |
2107 | ␊ |
2108 | ␉␉// Prepare the data for the default Apple boot image. ␊ |
2109 | ␉␉appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight); ␊ |
2110 | ␉␉if (appleBootPict) { ␊ |
2111 | ␉␉␉convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData); ␊ |
2112 | ␉␉␉if (bootImageData) {␉␊ |
2113 | ␉␉␉␉x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2; ␊ |
2114 | ␉␉␉␉y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2; ␊ |
2115 | ␉␉␉␉drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);␊ |
2116 | ␉␉␉␉free(bootImageData);␊ |
2117 | ␉␉␉}␊ |
2118 | ␉␉␉free(appleBootPict); ␊ |
2119 | ␉␉} ␊ |
2120 | ␉} ␊ |
2121 | }␊ |
2122 | |