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