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