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