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