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