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