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