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