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