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 | ␉extern void* memcpy_interruptible(void*, const void*, size_t);␊ |
1312 | ␉if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)␊ |
1313 | ␉{␊ |
1314 | ␉␉memcpy_interruptible((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));␊ |
1315 | ␉}␊ |
1316 | ␉else␊ |
1317 | ␉{␊ |
1318 | ␉␉uint32_t r;␊ |
1319 | ␉␉uint32_t g;␊ |
1320 | ␉␉uint32_t b;␊ |
1321 | ␉␉int i, j;␊ |
1322 | ␉␉for (i = 0; i < VIDEO (height); i++)␊ |
1323 | ␉␉{␊ |
1324 | ␉␉␉for (j = 0; j < VIDEO (width); j++)␊ |
1325 | ␉␉␉{␊ |
1326 | ␉␉␉␉b = ((uint8_t *) data)[4*i*width + 4*j];␊ |
1327 | ␉␉␉␉g = ((uint8_t *) data)[4*i*width + 4*j + 1];␊ |
1328 | ␉␉␉␉r = ((uint8_t *) data)[4*i*width + 4*j + 2];␊ |
1329 | ␉␉␉␉switch (VIDEO (depth))␊ |
1330 | ␉␉␉␉{␊ |
1331 | ␉␉␉␉␉case 32:␊ |
1332 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
1333 | ␉␉␉␉␉␉break;␊ |
1334 | ␉␉␉␉␉case 24:␊ |
1335 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)␊ |
1336 | ␉␉␉␉␉␉| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
1337 | ␉␉␉␉␉␉break;␊ |
1338 | ␉␉␉␉␉case 16:␊ |
1339 | ␉␉␉␉␉␉// Somehow 16-bit is always 15-bits really␊ |
1340 | ␉␉␉␉␉␉//␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);␊ |
1341 | ␉␉␉␉␉␉//␉␉␉␉␉␉break;␉␉␉␉␉␉␉␊ |
1342 | ␉␉␉␉␉case 15:␊ |
1343 | ␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);␊ |
1344 | ␉␉␉␉␉␉break;␉␊ |
1345 | ␉␉␉␉␉default:␊ |
1346 | ␉␉␉␉␉␉break;␊ |
1347 | ␉␉␉␉}␊ |
1348 | ␉␉␉}␊ |
1349 | ␉␉}␊ |
1350 | ␉}␊ |
1351 | }␊ |
1352 | ␊ |
1353 | // ====================================================================␊ |
1354 | ␊ |
1355 | void updateVRAM()␊ |
1356 | {␊ |
1357 | ␉if (gui.redraw)␊ |
1358 | ␉{␊ |
1359 | ␉␉if (gui.devicelist.draw)␊ |
1360 | ␉␉{␊ |
1361 | ␉␉␉blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );␊ |
1362 | ␉␉}␊ |
1363 | ␉␉if (gui.bootprompt.draw)␊ |
1364 | ␉␉{␊ |
1365 | ␉␉␉blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );␊ |
1366 | ␉␉}␊ |
1367 | ␉␉if (gui.menu.draw)␊ |
1368 | ␉␉{␊ |
1369 | ␉␉blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );␊ |
1370 | ␉␉}␊ |
1371 | ␉␉if (gui.infobox.draw)␊ |
1372 | ␉␉{␊ |
1373 | ␉␉␉blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );␊ |
1374 | ␉␉}␊ |
1375 | ␉}␊ |
1376 | ␊ |
1377 | ␉vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );␊ |
1378 | ␊ |
1379 | ␉if (gui.redraw)␊ |
1380 | ␉{␊ |
1381 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
1382 | ␉␉gui.redraw = false;␊ |
1383 | ␉}␊ |
1384 | }␊ |
1385 | ␊ |
1386 | // ====================================================================␊ |
1387 | ␊ |
1388 | struct putc_info //Azi: exists on console.c & printf.c␊ |
1389 | {␊ |
1390 | ␉char *str;␊ |
1391 | ␉char *last_str;␊ |
1392 | };␊ |
1393 | ␊ |
1394 | // ====================================================================␊ |
1395 | ␊ |
1396 | static int sputc(int c, struct putc_info * pi) //Azi: same as above␊ |
1397 | {␊ |
1398 | ␉if (pi->last_str)␊ |
1399 | ␉{␊ |
1400 | ␉␉if (pi->str == pi->last_str)␊ |
1401 | ␉␉{␊ |
1402 | ␉␉␉*(pi->str) = '\0';␊ |
1403 | ␉␉␉return 0;␊ |
1404 | ␉␉}␊ |
1405 | ␉}␊ |
1406 | ␉*(pi->str)++ = c;␊ |
1407 | ␉return c;␊ |
1408 | }␊ |
1409 | ␊ |
1410 | // ====================================================================␊ |
1411 | ␊ |
1412 | int gprintf( window_t * window, const char * fmt, ...)␊ |
1413 | {␊ |
1414 | ␉char *formattedtext;␊ |
1415 | ␊ |
1416 | ␉va_list ap;␊ |
1417 | ␊ |
1418 | ␉struct putc_info pi;␊ |
1419 | ␊ |
1420 | ␉if ((formattedtext = malloc(1024)) != NULL)␊ |
1421 | ␉{␊ |
1422 | ␉␉// format the text␊ |
1423 | ␉␉va_start(ap, fmt);␊ |
1424 | ␉␉pi.str = formattedtext;␊ |
1425 | ␉␉pi.last_str = 0;␊ |
1426 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1427 | ␉␉*pi.str = '\0';␊ |
1428 | ␉␉va_end(ap);␊ |
1429 | ␉␉␊ |
1430 | ␉␉position_t␉origin, cursor, bounds;␊ |
1431 | ␊ |
1432 | ␉␉int i;␊ |
1433 | ␉␉int character;␊ |
1434 | ␊ |
1435 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1436 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1437 | ␉␉␊ |
1438 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1439 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1440 | ␉␉␊ |
1441 | ␉␉cursor = origin;␊ |
1442 | ␊ |
1443 | ␉␉font_t *font = &font_console;␊ |
1444 | ␊ |
1445 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1446 | ␉␉{␊ |
1447 | ␉␉␉character = formattedtext[i];␊ |
1448 | ␉␉␉␊ |
1449 | ␉␉␉character -= 32;␊ |
1450 | ␊ |
1451 | ␉␉␉// newline ?␊ |
1452 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1453 | ␉␉␉{␊ |
1454 | ␉␉␉␉cursor.x = window->hborder;␊ |
1455 | ␉␉␉␉cursor.y += font->height;␊ |
1456 | ␊ |
1457 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1458 | ␉␉␉␉{␊ |
1459 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1460 | ␉␉␉␉}␊ |
1461 | ␉␉␉␉continue;␊ |
1462 | ␉␉␉}␊ |
1463 | ␊ |
1464 | ␉␉␉// tab ?␊ |
1465 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1466 | ␉␉␉{␊ |
1467 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1468 | ␉␉␉}␊ |
1469 | ␊ |
1470 | ␉␉␉// draw the character␊ |
1471 | ␉␉␉if( font->chars[character])␊ |
1472 | ␉␉␉{␊ |
1473 | ␉␉␉␉blend(font->chars[character], window->pixmap, cursor);␊ |
1474 | ␉␉␉}␊ |
1475 | ␊ |
1476 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1477 | ␊ |
1478 | ␉␉␉// check x pos and do newline␊ |
1479 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1480 | ␉␉␉{␊ |
1481 | ␉␉␉␉cursor.x = origin.x;␊ |
1482 | ␉␉␉␉cursor.y += font->height;␊ |
1483 | ␉␉␉}␊ |
1484 | ␉␉␉␊ |
1485 | ␉␉␉// check y pos and reset to origin.y␊ |
1486 | ␉␉␉if ( cursor.y > bounds.y )␊ |
1487 | ␉␉␉{␊ |
1488 | ␉␉␉␉cursor.y = origin.y;␊ |
1489 | ␉␉␉}␊ |
1490 | ␉␉}␊ |
1491 | ␊ |
1492 | ␉␉// update cursor postition␊ |
1493 | ␉␉window->cursor = cursor;␊ |
1494 | ␉␉␊ |
1495 | ␉␉free(formattedtext);␊ |
1496 | ␉␉␊ |
1497 | ␉␉return 0;␊ |
1498 | ␉}␊ |
1499 | ␉return 1;␊ |
1500 | }␊ |
1501 | ␊ |
1502 | // ====================================================================␊ |
1503 | ␊ |
1504 | int dprintf( window_t * window, const char * fmt, ...)␊ |
1505 | {␊ |
1506 | ␉char *formattedtext;␊ |
1507 | ␉␊ |
1508 | ␉va_list ap;␊ |
1509 | ␊ |
1510 | ␉//window = &gui.debug;␊ |
1511 | ␉␊ |
1512 | ␉struct putc_info pi;␊ |
1513 | ␊ |
1514 | ␉if ((formattedtext = malloc(1024)) != NULL)␊ |
1515 | ␉{␊ |
1516 | ␉␉// format the text␊ |
1517 | ␉␉va_start(ap, fmt);␊ |
1518 | ␉␉pi.str = formattedtext;␊ |
1519 | ␉␉pi.last_str = 0;␊ |
1520 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1521 | ␉␉*pi.str = '\0';␊ |
1522 | ␉␉va_end(ap);␊ |
1523 | ␉␉␊ |
1524 | ␉␉position_t␉origin, cursor, bounds;␊ |
1525 | ␊ |
1526 | ␉␉int i;␊ |
1527 | ␉␉int character;␊ |
1528 | ␊ |
1529 | ␉␉origin.x = MAX( gui.debug.cursor.x, window->hborder );␊ |
1530 | ␉␉origin.y = MAX( gui.debug.cursor.y, window->vborder );␊ |
1531 | ␉␉␊ |
1532 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1533 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1534 | ␉␉␊ |
1535 | ␉␉cursor = origin;␊ |
1536 | ␉␉␊ |
1537 | ␉␉font_t *font = &font_console;␊ |
1538 | ␉␉␊ |
1539 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1540 | ␉␉{␊ |
1541 | ␉␉␉character = formattedtext[i];␊ |
1542 | ␉␉␉␊ |
1543 | ␉␉␉character -= 32;␊ |
1544 | ␉␉␉␊ |
1545 | ␉␉␉// newline ?␊ |
1546 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1547 | ␉␉␉{␊ |
1548 | ␉␉␉␉cursor.x = window->hborder;␊ |
1549 | ␉␉␉␉cursor.y += font->height;␊ |
1550 | ␉␉␉␉␊ |
1551 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1552 | ␉␉␉␉{␊ |
1553 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1554 | ␉␉␉␉}␊ |
1555 | ␉␉␉␉continue;␊ |
1556 | ␉␉␉}␊ |
1557 | ␉␉␉␊ |
1558 | ␉␉␉// tab ?␊ |
1559 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1560 | ␉␉␉{␊ |
1561 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1562 | ␉␉␉}␊ |
1563 | ␉␉␉// draw the character␊ |
1564 | ␉␉␉if( font->chars[character])␊ |
1565 | ␉␉␉{␊ |
1566 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1567 | ␉␉␉}␊ |
1568 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1569 | ␉␉␉␊ |
1570 | ␉␉␉// check x pos and do newline␊ |
1571 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1572 | ␉␉␉{␊ |
1573 | ␉␉␉␉cursor.x = origin.x;␊ |
1574 | ␉␉␉␉cursor.y += font->height;␊ |
1575 | ␉␉␉}␊ |
1576 | ␉␉␉␊ |
1577 | ␉␉␉// check y pos and reset to origin.y␊ |
1578 | ␉␉␉if ( cursor.y > bounds.y )␊ |
1579 | ␉␉␉{␊ |
1580 | ␉␉␉␉cursor.y = origin.y;␊ |
1581 | ␉␉␉}␊ |
1582 | ␉␉}␊ |
1583 | ␉␉␊ |
1584 | ␉␉// update cursor postition␊ |
1585 | ␉␉gui.debug.cursor = cursor;␊ |
1586 | ␉␉␊ |
1587 | ␉␉free(formattedtext);␊ |
1588 | ␉␉␊ |
1589 | ␉␉return 0;␊ |
1590 | ␉␉␊ |
1591 | ␉}␊ |
1592 | ␉return 1;␊ |
1593 | }␊ |
1594 | ␊ |
1595 | // ====================================================================␊ |
1596 | ␊ |
1597 | int vprf(const char * fmt, va_list ap)␊ |
1598 | {␊ |
1599 | ␉int i;␊ |
1600 | ␉int character;␊ |
1601 | ␊ |
1602 | ␉char *formattedtext;␊ |
1603 | ␉window_t *window = &gui.screen;␊ |
1604 | ␉struct putc_info pi;␊ |
1605 | ␉␊ |
1606 | ␉position_t␉origin, cursor, bounds;␊ |
1607 | ␉font_t *font = &font_console;␊ |
1608 | ␉␊ |
1609 | ␉if ((formattedtext = malloc(1024)) != NULL)␊ |
1610 | ␉{␊ |
1611 | ␉␉// format the text␊ |
1612 | ␉␉pi.str = formattedtext;␊ |
1613 | ␉␉pi.last_str = 0;␊ |
1614 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1615 | ␉␉*pi.str = '\0';␊ |
1616 | ␉␉␊ |
1617 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1618 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1619 | ␉␉bounds.x = ( window->width - ( window->hborder * 2 ) );␊ |
1620 | ␉␉bounds.y = ( window->height - ( window->vborder * 2 ) );␊ |
1621 | ␉␉cursor = origin;␊ |
1622 | ␊ |
1623 | ␉␉for( i=0; i< strlen(formattedtext) ; i++ )␊ |
1624 | ␉␉{␊ |
1625 | ␉␉␉character = formattedtext[i];␊ |
1626 | ␉␉␉character -= 32;␊ |
1627 | ␉␉␉␊ |
1628 | ␉␉␉// newline ?␊ |
1629 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1630 | ␉␉␉{␊ |
1631 | ␉␉␉␉cursor.x = window->hborder;␊ |
1632 | ␉␉␉␉cursor.y += font->height;␊ |
1633 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1634 | ␉␉␉␉{␊ |
1635 | ␉␉␉␉␉gui.redraw = true;␊ |
1636 | ␉␉␉␉␉updateVRAM();␊ |
1637 | ␉␉␉␉␉cursor.y = window->vborder;␊ |
1638 | ␉␉␉␉}␊ |
1639 | ␉␉␉␉window->cursor.y = cursor.y;␊ |
1640 | ␉␉␉␉continue;␊ |
1641 | ␉␉␉}␊ |
1642 | ␊ |
1643 | ␉␉␉// tab ?␊ |
1644 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1645 | ␉␉␉{␊ |
1646 | ␉␉␉␉cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );␊ |
1647 | ␉␉␉␉continue;␊ |
1648 | ␉␉␉}␊ |
1649 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1650 | ␉␉␉␊ |
1651 | ␉␉␉// check x pos and do newline␊ |
1652 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1653 | ␉␉␉{␊ |
1654 | ␉␉␉␉cursor.x = origin.x;␊ |
1655 | ␉␉␉␉cursor.y += font->height;␊ |
1656 | ␉␉␉}␊ |
1657 | ␊ |
1658 | ␉␉␉// check y pos and reset to origin.y␊ |
1659 | ␉␉␉if ( cursor.y > ( bounds.y + font->chars[0]->height) )␊ |
1660 | ␉␉␉{␊ |
1661 | ␉␉␉␉gui.redraw = true;␊ |
1662 | ␉␉␉␉updateVRAM();␊ |
1663 | ␉␉␉␉cursor.y = window->vborder;␊ |
1664 | ␉␉␉}␊ |
1665 | ␉␉␉// draw the character␊ |
1666 | ␉␉␉if( font->chars[character])␊ |
1667 | ␉␉␉{␊ |
1668 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1669 | ␉␉␉}␊ |
1670 | ␉␉}␊ |
1671 | ␉␉// save cursor postition␊ |
1672 | ␉␉window->cursor.x = cursor.x;␊ |
1673 | ␉␉updateVRAM();␊ |
1674 | ␉␉free(formattedtext);␊ |
1675 | ␉␉return 0;␊ |
1676 | ␉}␊ |
1677 | ␉return 1;␊ |
1678 | }␊ |
1679 | ␊ |
1680 | // ====================================================================␊ |
1681 | ␊ |
1682 | pixmap_t *charToPixmap(unsigned char ch, font_t *font)␊ |
1683 | {␊ |
1684 | ␉unsigned int cha = (unsigned int)ch - 32;␊ |
1685 | ␉if (cha >= font->count)␊ |
1686 | ␉{␊ |
1687 | ␉␉// return ? if the font for the char doesn't exists␊ |
1688 | ␉␉cha = '?' - 32;␊ |
1689 | ␉}␊ |
1690 | ␉return font->chars[cha] ? font->chars[cha] : NULL;␊ |
1691 | }␊ |
1692 | ␊ |
1693 | // ====================================================================␊ |
1694 | ␊ |
1695 | position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1696 | {␊ |
1697 | ␉pixmap_t* pm = charToPixmap(ch, font);␊ |
1698 | ␉if (pm && ((p.x + pm->width) < blendInto->width))␊ |
1699 | ␉{␊ |
1700 | ␉␉blend(pm, blendInto, p);␊ |
1701 | ␉␉return pos(p.x + pm->width, p.y);␊ |
1702 | ␉}␊ |
1703 | ␉else␊ |
1704 | ␉{␊ |
1705 | ␉␉return p;␊ |
1706 | ␉}␊ |
1707 | }␊ |
1708 | ␊ |
1709 | // ====================================================================␊ |
1710 | ␊ |
1711 | void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1712 | {␊ |
1713 | ␉int i=0;␊ |
1714 | ␉position_t current_pos = pos(p.x, p.y);␊ |
1715 | ␉␊ |
1716 | ␉for (i=0; i < strlen(ch); i++)␊ |
1717 | ␉{␊ |
1718 | ␉␉// newline ?␊ |
1719 | ␉␉if ( ch[i] == '\n' )␊ |
1720 | ␉␉{␊ |
1721 | ␉␉␉current_pos.x = p.x;␊ |
1722 | ␉␉␉current_pos.y += font->height;␊ |
1723 | ␉␉␉continue;␊ |
1724 | ␉␉}␊ |
1725 | ␉␉␊ |
1726 | ␉␉// tab ?␊ |
1727 | ␉␉if ( ch[i] == '\t' )␊ |
1728 | ␉␉{␊ |
1729 | ␉␉␉current_pos.x += TAB_PIXELS_WIDTH;␊ |
1730 | ␉␉␉continue;␊ |
1731 | ␉␉}␊ |
1732 | ␉␉␊ |
1733 | ␉␉current_pos = drawChar(ch[i], font, blendInto, current_pos);␊ |
1734 | ␉}␊ |
1735 | }␊ |
1736 | ␊ |
1737 | // ====================================================================␊ |
1738 | ␊ |
1739 | void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1740 | {␊ |
1741 | ␉int i = 0;␊ |
1742 | ␉int width = 0;␊ |
1743 | ␉int max_width = 0;␊ |
1744 | ␉int height = font->height;␊ |
1745 | ␊ |
1746 | ␉// calculate the width in pixels␊ |
1747 | ␉for (i=0; i < strlen(text); i++)␊ |
1748 | ␉{␊ |
1749 | ␉␉if (text[i] == '\n')␊ |
1750 | ␉␉{␊ |
1751 | ␉␉␉width = 0;␊ |
1752 | ␉␉␉height += font->height;␊ |
1753 | ␉␉}␊ |
1754 | ␉␉else if (text[i] == '\t')␊ |
1755 | ␉␉{␊ |
1756 | ␉␉␉width += TAB_PIXELS_WIDTH;␊ |
1757 | ␉␉}␊ |
1758 | ␉␉else␊ |
1759 | ␉␉{␊ |
1760 | ␉␉␉pixmap_t* pm = charToPixmap(text[i], font);␊ |
1761 | ␉␉␉if (pm)␊ |
1762 | ␉␉␉{␊ |
1763 | ␉␉␉␉width += pm->width;␊ |
1764 | ␉␉␉}␊ |
1765 | ␉␉}␊ |
1766 | ␉␉if (width > max_width)␊ |
1767 | ␉␉{␊ |
1768 | ␉␉␉max_width = width;␊ |
1769 | ␉␉}␊ |
1770 | ␉}␊ |
1771 | ␊ |
1772 | ␉p.x = ( p.x - ( max_width / 2 ) );␊ |
1773 | ␉p.y = ( p.y - ( height / 2 ) );␊ |
1774 | ␉␊ |
1775 | ␉drawStr(text, font, blendInto, p);␊ |
1776 | }␊ |
1777 | ␊ |
1778 | // ====================================================================␊ |
1779 | ␊ |
1780 | int destroyFont(font_t *font)␊ |
1781 | {␊ |
1782 | ␉int i;␊ |
1783 | ␉for (i = 0; i < CHARACTERS_COUNT; i++)␊ |
1784 | ␉{␊ |
1785 | ␉␉if (font->chars[i])␊ |
1786 | ␉␉{␊ |
1787 | ␉␉␉if (font->chars[i]->pixels)␊ |
1788 | ␉␉␉{␊ |
1789 | ␉␉␉␉free (font->chars[i]->pixels);␊ |
1790 | ␉␉␉}␊ |
1791 | ␉␉␉free (font->chars[i]);␊ |
1792 | ␉␉␉font->chars[i] = 0;␊ |
1793 | ␉␉}␊ |
1794 | ␉}␊ |
1795 | ␉return 0;␊ |
1796 | }␊ |
1797 | ␊ |
1798 | // ====================================================================␊ |
1799 | ␊ |
1800 | int initFont(font_t *font, image_t *data)␊ |
1801 | {␊ |
1802 | ␉unsigned int x = 0, y = 0, x2 = 0, x3 = 0;␊ |
1803 | ␉␊ |
1804 | ␉int start = 0, end = 0, count = 0, space = 0;␊ |
1805 | ␉␊ |
1806 | ␉bool monospaced = false;␊ |
1807 | ␉␊ |
1808 | ␉font->height = data->image->height;␊ |
1809 | ␊ |
1810 | ␉for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++)␊ |
1811 | ␉{␊ |
1812 | ␉␉start = end;␊ |
1813 | ␊ |
1814 | ␉␉// if the pixel is red we've reached the end of the char␊ |
1815 | ␉␉if( pixel( data->image, x, 0 ).value == 0xFFFF0000)␊ |
1816 | ␉␉{␊ |
1817 | ␉␉␉end = x + 1;␊ |
1818 | ␊ |
1819 | ␉␉␉if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )␊ |
1820 | ␉␉␉{␊ |
1821 | ␉␉␉␉font->chars[count]->width = ( end - start) - 1;␊ |
1822 | ␉␉␉␉font->chars[count]->height = font->height;␊ |
1823 | ␊ |
1824 | ␉␉␉␉if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )␊ |
1825 | ␉␉␉␉{␊ |
1826 | ␉␉␉␉␉space += ( font->chars[count]->width * data->image->height * 4 );␊ |
1827 | ␉␉␉␉␉// we skip the first line because there are just the red pixels for the char width␊ |
1828 | ␉␉␉␉␉for( y = 1; y< (font->height); y++)␊ |
1829 | ␉␉␉␉␉{␊ |
1830 | ␉␉␉␉␉␉for( x2 = start, x3 = 0; x2 < end; x2++, x3++)␊ |
1831 | ␉␉␉␉␉␉{␊ |
1832 | ␉␉␉␉␉␉␉pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );␊ |
1833 | ␉␉␉␉␉␉}␉␊ |
1834 | ␉␉␉␉␉}␊ |
1835 | ␊ |
1836 | ␉␉␉␉␉// check if font is monospaced␊ |
1837 | ␉␉␉␉␉if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )␊ |
1838 | ␉␉␉␉␉{␊ |
1839 | ␉␉␉␉␉␉monospaced = true;␊ |
1840 | ␉␉␉␉␉}␊ |
1841 | ␊ |
1842 | ␉␉␉␉␉font->width = font->chars[count]->width;␊ |
1843 | ␊ |
1844 | ␉␉␉␉␉count++;␊ |
1845 | ␉␉␉␉}␊ |
1846 | ␉␉␉}␊ |
1847 | ␉␉}␊ |
1848 | ␉}␊ |
1849 | ␊ |
1850 | ␉for (x = count; x < CHARACTERS_COUNT; x++)␊ |
1851 | ␉{␊ |
1852 | ␉␉font->chars[x] = NULL;␊ |
1853 | ␉}␊ |
1854 | ␊ |
1855 | ␉if(monospaced)␊ |
1856 | ␉{␊ |
1857 | ␉␉font->width = 0;␊ |
1858 | ␉}␊ |
1859 | ␊ |
1860 | ␉font->count = count;␊ |
1861 | ␊ |
1862 | ␉return 0;␊ |
1863 | }␊ |
1864 | ␊ |
1865 | // ====================================================================␊ |
1866 | ␊ |
1867 | void colorFont(font_t *font, uint32_t color)␊ |
1868 | {␊ |
1869 | ␉if( !color )␊ |
1870 | ␉{␊ |
1871 | ␉␉return;␊ |
1872 | ␉}␊ |
1873 | ␊ |
1874 | ␉int x, y, width, height;␊ |
1875 | ␉int count = 0;␊ |
1876 | ␉pixel_t *buff;␊ |
1877 | ␉␊ |
1878 | ␉while( font->chars[count++] )␊ |
1879 | ␉{␊ |
1880 | ␉␉width = font->chars[count-1]->width;␊ |
1881 | ␉␉height = font->chars[count-1]->height;␊ |
1882 | ␉␉for( y = 0; y < height; y++ )␊ |
1883 | ␉␉{␊ |
1884 | ␉␉␉for( x = 0; x < width; x++ )␊ |
1885 | ␉␉␉{␊ |
1886 | ␉␉␉␉buff = &(pixel( font->chars[count-1], x, y ));␊ |
1887 | ␉␉␉␉if( buff->ch.a )␊ |
1888 | ␉␉␉␉{␊ |
1889 | ␉␉␉␉␉buff->ch.r = (color & 0xFFFF0000) >> 16;␊ |
1890 | ␉␉␉␉␉buff->ch.g = (color & 0xFF00FF00) >> 8;␊ |
1891 | ␉␉␉␉␉buff->ch.b = (color & 0xFF0000FF);␊ |
1892 | ␉␉␉␉}␊ |
1893 | ␉␉␉}␊ |
1894 | ␉␉}␊ |
1895 | ␉}␊ |
1896 | }␊ |
1897 | ␊ |
1898 | // ====================================================================␊ |
1899 | ␊ |
1900 | void makeRoundedCorners(pixmap_t *p)␊ |
1901 | {␊ |
1902 | ␉int x,y;␊ |
1903 | ␉int width=p->width-1;␊ |
1904 | ␉int height=p->height-1;␊ |
1905 | ␉␊ |
1906 | ␉// 10px rounded corner alpha values␊ |
1907 | ␉uint8_t roundedCorner[10][10] =␊ |
1908 | ␉{␊ |
1909 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},␊ |
1910 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1911 | ␉␉{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1912 | ␉␉{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1913 | ␉␉{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1914 | ␉␉{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1915 | ␉␉{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1916 | ␉␉{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1917 | ␉␉{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1918 | ␉␉{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}␊ |
1919 | ␉};␊ |
1920 | ␉␊ |
1921 | ␉uint8_t alpha=0;␊ |
1922 | ␉␊ |
1923 | ␉for( y=0; y<10; y++)␊ |
1924 | ␉{␊ |
1925 | ␉␉for( x=0; x<10; x++)␊ |
1926 | ␉␉{␊ |
1927 | ␉␉␉// skip if the pixel should be visible␊ |
1928 | ␉␉␉if(roundedCorner[y][x] != 0xFF)␊ |
1929 | ␉␉␉{ ␊ |
1930 | ␉␉␉␉alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );␊ |
1931 | ␉␉␉␉// Upper left corner␊ |
1932 | ␉␉␉␉pixel(p, x, y).ch.a = alpha;␊ |
1933 | ␊ |
1934 | ␉␉␉␉// upper right corner␊ |
1935 | ␉␉␉␉pixel(p, width-x,y).ch.a = alpha;␊ |
1936 | ␊ |
1937 | ␉␉␉␉// lower left corner␊ |
1938 | ␉␉␉␉pixel(p, x, height-y).ch.a = alpha;␊ |
1939 | ␊ |
1940 | ␉␉␉␉// lower right corner␊ |
1941 | ␉␉␉␉pixel(p, width-x, height-y).ch.a = alpha;␊ |
1942 | ␉␉␉}␊ |
1943 | ␉␉}␊ |
1944 | ␉}␊ |
1945 | }␊ |
1946 | ␊ |
1947 | // ====================================================================␊ |
1948 | ␊ |
1949 | void showInfoBox(char *title, char *text_orig)␊ |
1950 | {␊ |
1951 | ␉char* text;␊ |
1952 | ␉int i, key, lines, visiblelines;␊ |
1953 | ␊ |
1954 | ␉int currentline=0;␊ |
1955 | ␉int cnt=0;␊ |
1956 | ␉int offset=0;␊ |
1957 | ␉␊ |
1958 | ␉if( !title || !text_orig ) {␊ |
1959 | ␉␉return;␊ |
1960 | ␉}␊ |
1961 | ␊ |
1962 | ␉// Create a copy so that we don't mangle the original␊ |
1963 | ␉text = malloc(strlen(text_orig) + 1);␊ |
1964 | ␉strcpy(text, text_orig);␊ |
1965 | ␊ |
1966 | ␉position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );␊ |
1967 | ␊ |
1968 | ␉// calculate number of lines in the title␊ |
1969 | ␉for ( i = 0, lines = 1; i<strlen(title); i++ ) {␊ |
1970 | ␉␉if( title[i] == '\n') {␊ |
1971 | ␉␉␉lines++;␊ |
1972 | ␉␉}␊ |
1973 | ␉}␊ |
1974 | ␉// y position of text is lines in title * height of font␊ |
1975 | ␉position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));␊ |
1976 | ␉␊ |
1977 | ␉// calculate number of lines in the text␊ |
1978 | ␉for ( i=0, lines = 1; i<strlen(text); i++ ) {␊ |
1979 | ␉␉if( text[i] == '\n') {␊ |
1980 | ␉␉␉lines++;␊ |
1981 | ␉␉}␊ |
1982 | ␉}␊ |
1983 | ␉// if text ends with \n strip off␊ |
1984 | ␉if( text[i] == '\n' || text[i] == '\0') {␊ |
1985 | ␉␉lines--;␊ |
1986 | ␉}␊ |
1987 | ␉visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;␊ |
1988 | ␉␊ |
1989 | ␉// lets display the text and allow scroll thru using up down / arrows␊ |
1990 | ␉while(1)␊ |
1991 | ␉{␊ |
1992 | ␉␉// move to current line in text␊ |
1993 | ␉␉for( offset = 0, i = 0; offset < strlen(text); offset++ )␊ |
1994 | ␉␉{␊ |
1995 | ␉␉␉if( currentline == i)␊ |
1996 | ␉␉␉{␊ |
1997 | ␉␉␉␉break;␊ |
1998 | ␉␉␉}␊ |
1999 | ␊ |
2000 | ␉␉␉if( text[offset] =='\n')␊ |
2001 | ␉␉␉{␊ |
2002 | ␉␉␉␉i++;␊ |
2003 | ␉␉␉}␊ |
2004 | ␉␉}␊ |
2005 | ␊ |
2006 | ␉␉// find last visible line in text and place \0␊ |
2007 | ␉␉for( i = offset, cnt = 0; i < strlen(text); i++)␊ |
2008 | ␉␉{␊ |
2009 | ␉␉␉if(text[i]=='\n')␊ |
2010 | ␉␉␉{␊ |
2011 | ␉␉␉␉cnt++;␊ |
2012 | ␉␉␉}␊ |
2013 | ␊ |
2014 | ␉␉␉if ( cnt == visiblelines )␊ |
2015 | ␉␉␉{␊ |
2016 | ␉␉␉␉text[i]='\0';␊ |
2017 | ␉␉␉␉break;␊ |
2018 | ␉␉␉}␊ |
2019 | ␉␉}␊ |
2020 | ␊ |
2021 | ␉␉fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);␊ |
2022 | ␊ |
2023 | ␉␉makeRoundedCorners( gui.infobox.pixmap);␊ |
2024 | ␊ |
2025 | ␉␉// print the title if present␊ |
2026 | ␉␉if( title ) {␊ |
2027 | ␉␉␉drawStr(title, &font_console, gui.infobox.pixmap, pos_title);␊ |
2028 | ␉␉}␊ |
2029 | ␉␉// print the text␊ |
2030 | ␉␉drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);␊ |
2031 | ␊ |
2032 | ␉␉// restore \n in text␊ |
2033 | ␉␉if ( cnt == visiblelines ) {␊ |
2034 | ␉␉␉text[i] = '\n';␊ |
2035 | ␉␉}␊ |
2036 | ␉␉position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );␊ |
2037 | ␉␉␊ |
2038 | ␉␉// draw prev indicator␊ |
2039 | ␉␉if(offset)␊ |
2040 | ␉␉{␊ |
2041 | ␉␉␉blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));␊ |
2042 | ␉␉}␊ |
2043 | ␉␉␊ |
2044 | ␉␉// draw next indicator␊ |
2045 | ␉␉if( lines > ( currentline + visiblelines ) )␊ |
2046 | ␉␉{␊ |
2047 | ␉␉␉pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );␊ |
2048 | ␉␉␉blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );␊ |
2049 | ␉␉}␊ |
2050 | ␊ |
2051 | ␉␉gui.bootprompt.draw = false;␊ |
2052 | ␉␉gui.infobox.draw = true;␊ |
2053 | ␉␉gui.redraw = true;␊ |
2054 | ␉␉␊ |
2055 | ␉␉updateVRAM();␊ |
2056 | ␉␉␊ |
2057 | ␉␉key = getchar();␊ |
2058 | ␊ |
2059 | ␉␉if( key == KEY_UP ) {␊ |
2060 | ␉␉␉if( currentline > 0 ) {␊ |
2061 | ␉␉␉␉currentline--;␊ |
2062 | ␉␉␉}␊ |
2063 | ␉␉}␊ |
2064 | ␊ |
2065 | ␉␉if( key == KEY_DOWN ) {␊ |
2066 | ␉␉␉if( lines > ( currentline + visiblelines ) ) {␊ |
2067 | ␉␉␉␉currentline++;␊ |
2068 | ␉␉␉}␊ |
2069 | ␉␉}␊ |
2070 | ␊ |
2071 | ␉␉if( key == KEY_ESC || key == 'q' || key == 'Q') {␊ |
2072 | ␉␉␉gui.infobox.draw = false;␊ |
2073 | ␉␉␉gui.redraw = true;␊ |
2074 | ␉␉␉updateVRAM();␊ |
2075 | ␉␉␉break;␊ |
2076 | ␉␉}␊ |
2077 | ␊ |
2078 | ␉␉if(key == ' ') { // spacebar = next page␊ |
2079 | ␉␉␉if( lines > ( currentline + visiblelines ) ) {␊ |
2080 | ␉␉␉␉currentline += visiblelines;␊ |
2081 | ␉␉␉}␊ |
2082 | ␉␉␉if(lines < (currentline + visiblelines)) {␊ |
2083 | ␉␉␉␉currentline = lines - visiblelines;␊ |
2084 | ␉␉␉}␊ |
2085 | ␉␉}␊ |
2086 | ␉}␊ |
2087 | ␉free(text);␊ |
2088 | }␊ |
2089 | ␊ |
2090 | // ====================================================================␊ |
2091 | ␊ |
2092 | #if UNUSED␊ |
2093 | void animateProgressBar()␊ |
2094 | {␊ |
2095 | ␉int y;␊ |
2096 | ␉␊ |
2097 | ␉if( time18() > lasttime)␊ |
2098 | ␉{␊ |
2099 | ␉␉lasttime = time18();␊ |
2100 | ␊ |
2101 | ␉␉pixmap_t *buffBar = images[iProgressBar].image;␊ |
2102 | ␊ |
2103 | ␉␉uint32_t buff = buffBar->pixels[0].value;␊ |
2104 | ␉␊ |
2105 | ␉␉memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );␊ |
2106 | ␊ |
2107 | ␉␉for( y = buffBar->height - 1; y > 0; y--) {␊ |
2108 | ␉␉␉pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);␊ |
2109 | ␉␉}␊ |
2110 | ␉␉pixel(buffBar, buffBar->width-1, 0).value = buff;␊ |
2111 | ␉}␊ |
2112 | }␊ |
2113 | #endif␊ |
2114 | ␊ |
2115 | // ====================================================================␊ |
2116 | ␊ |
2117 | void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)␊ |
2118 | {␊ |
2119 | ␉if(progress>100) {␊ |
2120 | ␉␉return;␊ |
2121 | ␉}␊ |
2122 | ␊ |
2123 | ␉p.x = ( p.x - ( width / 2 ) );␊ |
2124 | ␊ |
2125 | ␉int todraw = (width * progress) / 100;␊ |
2126 | ␊ |
2127 | ␉pixmap_t *buff = images[iProgressBar].image;␊ |
2128 | ␉pixmap_t *buffBG = images[iProgressBarBackground].image;␊ |
2129 | ␉if(!buff || !buffBG) {␊ |
2130 | ␉␉return;␊ |
2131 | ␉}␊ |
2132 | ␊ |
2133 | ␉pixmap_t progressbar;␊ |
2134 | ␉progressbar.pixels=malloc(width * 4 * buff->height);␊ |
2135 | ␉if(!progressbar.pixels) {␊ |
2136 | ␉␉return; ␊ |
2137 | ␉}␊ |
2138 | ␊ |
2139 | ␉progressbar.width = width;␊ |
2140 | ␉progressbar.height = buff->height;␊ |
2141 | ␊ |
2142 | ␉int x=0,x2=0,y=0;␊ |
2143 | ␉␊ |
2144 | ␉for(y=0; y<buff->height; y++) {␊ |
2145 | ␉␉for(x=0; x<todraw; x++, x2++) {␊ |
2146 | ␉␉␉if(x2 == (buff->width-1)) {␊ |
2147 | ␉␉␉␉x2=0;␊ |
2148 | ␉␉␉}␊ |
2149 | ␉␉␉pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;␊ |
2150 | ␉␉}␊ |
2151 | ␉␉x2=0;␊ |
2152 | ␉}␊ |
2153 | ␊ |
2154 | ␉for(y=0; y<buff->height; y++) {␊ |
2155 | ␉␉for(x=todraw, x2 = 0; x < width - 1; x++, x2++) {␊ |
2156 | ␉␉␉if(x2 == (buffBG->width -2 )) {␊ |
2157 | ␉␉␉␉x2 = 0;␊ |
2158 | ␉␉␉}␊ |
2159 | ␉␉␉pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;␊ |
2160 | ␉␉}␊ |
2161 | ␉␉if(progress < 100) {␊ |
2162 | ␉␉␉pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
2163 | ␉␉}␊ |
2164 | ␊ |
2165 | ␉␉if(progress == 0) {␊ |
2166 | ␉␉␉pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
2167 | ␉␉}␊ |
2168 | ␊ |
2169 | ␉␉x2=0;␊ |
2170 | ␉}␊ |
2171 | ␊ |
2172 | ␉blend(&progressbar, blendInto, p);␊ |
2173 | #if 0␊ |
2174 | ␉animateProgressBar();␊ |
2175 | #endif␊ |
2176 | ␉free(progressbar.pixels);␊ |
2177 | }␊ |
2178 | ␊ |
2179 | // ====================================================================␊ |
2180 | ␊ |
2181 | void drawInfoMenuItems()␊ |
2182 | {␊ |
2183 | ␉int i,n;␊ |
2184 | ␉␊ |
2185 | ␉position_t position;␊ |
2186 | ␉␊ |
2187 | ␉pixmap_t *selection = images[iMenuSelection].image;␊ |
2188 | ␉␊ |
2189 | ␉pixmap_t *pbuff;␊ |
2190 | ␊ |
2191 | ␉fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);␊ |
2192 | ␊ |
2193 | ␉makeRoundedCorners(gui.menu.pixmap);␊ |
2194 | ␉␊ |
2195 | ␉uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;␊ |
2196 | ␊ |
2197 | ␉position = pos(0,0);␊ |
2198 | ␉␊ |
2199 | ␉for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++) {␊ |
2200 | ␉␉if (i == infoMenuSelection) {␊ |
2201 | ␉␉␉blend(selection, gui.menu.pixmap, position);␊ |
2202 | ␉␉}␊ |
2203 | ␊ |
2204 | ␉␉pbuff = images[n].image;␊ |
2205 | ␉␉if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END) {␊ |
2206 | ␉␉␉blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap, ␊ |
2207 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
2208 | ␉␉} else {␊ |
2209 | ␉␉␉blend( pbuff, gui.menu.pixmap, ␊ |
2210 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
2211 | ␉␉}␊ |
2212 | ␊ |
2213 | ␉␉drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap, ␊ |
2214 | ␉␉␉pos(position.x + (pbuff->width + gui.menu.hborder), ␊ |
2215 | ␉␉␉␉position.y + ((selection->height - font_console.height) / 2)));␊ |
2216 | ␉␉position.y += images[iMenuSelection].image->height;␊ |
2217 | ␉␊ |
2218 | ␉}␊ |
2219 | ␉␊ |
2220 | ␉gui.redraw = true;␊ |
2221 | }␊ |
2222 | ␊ |
2223 | // ====================================================================␊ |
2224 | ␊ |
2225 | int drawInfoMenu()␊ |
2226 | {␊ |
2227 | ␉drawInfoMenuItems();␊ |
2228 | ␊ |
2229 | ␉gui.menu.draw = true;␊ |
2230 | ␊ |
2231 | ␉updateVRAM();␊ |
2232 | ␉␊ |
2233 | ␉return 1;␊ |
2234 | }␊ |
2235 | ␊ |
2236 | // ====================================================================␊ |
2237 | ␊ |
2238 | int updateInfoMenu(int key)␊ |
2239 | {␊ |
2240 | ␉switch (key)␊ |
2241 | ␉{␊ |
2242 | ␊ |
2243 | ␉␉case KEY_UP:␉// up arrow␊ |
2244 | ␉␉␉if (infoMenuSelection > 0) {␊ |
2245 | ␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1) {␊ |
2246 | ␉␉␉␉␉infoMenuSelection -= 4;␊ |
2247 | ␉␉␉␉} else {␊ |
2248 | ␉␉␉␉␉infoMenuSelection--;␊ |
2249 | ␉␉␉␉}␊ |
2250 | ␉␉␉␉drawInfoMenuItems();␊ |
2251 | ␉␉␉␉updateVRAM();␊ |
2252 | ␊ |
2253 | ␉␉␉} else {␊ |
2254 | ␊ |
2255 | ␉␉␉␉gui.menu.draw = false;␊ |
2256 | ␉␉␉␉gui.redraw = true;␊ |
2257 | ␊ |
2258 | ␉␉␉␉updateVRAM();␊ |
2259 | ␉␉␉␉␊ |
2260 | ␉␉␉␉return CLOSE_INFO_MENU;␊ |
2261 | ␉␉␉}␊ |
2262 | ␉␉␉break;␊ |
2263 | ␊ |
2264 | ␉␉case KEY_DOWN:␉// down arrow␊ |
2265 | ␉␉␉if (infoMenuSelection < infoMenuItemsCount - 1) {␊ |
2266 | ␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)␊ |
2267 | ␉␉␉␉{␊ |
2268 | ␉␉␉␉␉infoMenuSelection += 4;␊ |
2269 | ␉␉␉␉} else {␊ |
2270 | ␉␉␉␉␉infoMenuSelection++;␊ |
2271 | ␉␉␉␉}␊ |
2272 | ␉␉␉␉drawInfoMenuItems();␊ |
2273 | ␉␉␉␉updateVRAM();␊ |
2274 | ␉␉␉}␊ |
2275 | ␉␉␉break;␊ |
2276 | ␊ |
2277 | ␉␉case KEY_ENTER:␊ |
2278 | ␉␉␉key = 0;␊ |
2279 | ␉␉␉if( infoMenuSelection == MENU_SHOW_MEMORY_INFO ) {␊ |
2280 | ␉␉␉␉showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());␊ |
2281 | ␉␉␉} else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO ) {␊ |
2282 | ␉␉␉␉showInfoBox( getVBEInfoString(), getVBEModeInfoString() );␊ |
2283 | ␉␉␉} else if( infoMenuSelection == MENU_SHOW_HELP ) {␊ |
2284 | ␉␉␉␉showHelp();␊ |
2285 | ␉␉␉} else {␊ |
2286 | ␉␉␉␉int buff = infoMenuSelection;␊ |
2287 | ␉␉␉␉infoMenuSelection = 0;␊ |
2288 | ␉␉␉␉return buff;␊ |
2289 | ␉␉␉}␊ |
2290 | ␉␉␉break;␊ |
2291 | ␉␉default:␊ |
2292 | ␉␉␉break;␊ |
2293 | ␉}␊ |
2294 | ␉return DO_NOT_BOOT;␊ |
2295 | }␊ |
2296 | ␊ |
2297 | // ====================================================================␊ |
2298 | ␊ |
2299 | uint16_t bootImageWidth = 0;␊ |
2300 | uint16_t bootImageHeight = 0;␊ |
2301 | uint8_t *bootImageData = NULL;␊ |
2302 | static bool usePngImage = true;␊ |
2303 | ␊ |
2304 | //==========================================================================␊ |
2305 | // loadBootGraphics␊ |
2306 | static void loadBootGraphics(void)␊ |
2307 | {␊ |
2308 | ␉if (bootImageData != NULL) {␊ |
2309 | ␉␉return;␊ |
2310 | ␉}␊ |
2311 | ␊ |
2312 | ␉char dirspec[256];␊ |
2313 | ␊ |
2314 | ␉if ((strlen(theme_name) + 24) > sizeof(dirspec))␊ |
2315 | ␉{␊ |
2316 | ␉␉usePngImage = false; ␊ |
2317 | ␉␉return;␊ |
2318 | ␉}␊ |
2319 | ␉sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);␊ |
2320 | ␉if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {␊ |
2321 | #ifdef CONFIG_EMBED_THEME␊ |
2322 | ␉␉if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)␊ |
2323 | #endif␊ |
2324 | ␉␉usePngImage = false; ␊ |
2325 | ␉}␊ |
2326 | }␊ |
2327 | ␊ |
2328 | //==========================================================================␊ |
2329 | // drawBootGraphics␊ |
2330 | void drawBootGraphics(void)␊ |
2331 | {␊ |
2332 | ␉int pos;␊ |
2333 | ␉int length;␊ |
2334 | ␉const char *dummyVal;␊ |
2335 | ␉int oldScreenWidth, oldScreenHeight;␊ |
2336 | ␉bool legacy_logo = true; // ErmaC: Legacy Logo is enabled by default␊ |
2337 | ␊ |
2338 | ␉uint16_t x, y;␊ |
2339 | ␊ |
2340 | ␉getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->chameleonConfig);␊ |
2341 | ␊ |
2342 | ␉if ( legacy_logo )␊ |
2343 | ␉{␊ |
2344 | ␉␉usePngImage = false; ␊ |
2345 | ␉}␊ |
2346 | ␉else if (bootImageData == NULL)␊ |
2347 | ␉{␊ |
2348 | ␉␉loadBootGraphics();␊ |
2349 | ␉}␊ |
2350 | ␊ |
2351 | ␉// parse screen size parameters␊ |
2352 | ␉if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0)␊ |
2353 | ␉{␊ |
2354 | ␉␉screen_params[0] = pos;␊ |
2355 | ␉}␊ |
2356 | ␉else␊ |
2357 | ␉{␊ |
2358 | ␉␉screen_params[0] = DEFAULT_SCREEN_WIDTH;␊ |
2359 | ␉}␊ |
2360 | ␊ |
2361 | ␉if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0)␊ |
2362 | ␉{␊ |
2363 | ␉␉screen_params[1] = pos;␊ |
2364 | ␉}␊ |
2365 | ␉else␊ |
2366 | ␉{␊ |
2367 | ␉␉screen_params[1] = DEFAULT_SCREEN_HEIGHT;␊ |
2368 | ␉}␊ |
2369 | ␊ |
2370 | ␉// Save current screen resolution.␊ |
2371 | ␉oldScreenWidth = gui.screen.width;␊ |
2372 | ␉oldScreenHeight = gui.screen.height;␊ |
2373 | ␊ |
2374 | ␉gui.screen.width = screen_params[0];␊ |
2375 | ␉gui.screen.height = screen_params[1];␊ |
2376 | ␊ |
2377 | ␉// find best matching vesa mode for our requested width & height␊ |
2378 | ␉getGraphicModeParams(screen_params);␊ |
2379 | ␊ |
2380 | ␉// Set graphics mode if the booter was in text mode or the screen resolution has changed.␊ |
2381 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )␊ |
2382 | ␉{␊ |
2383 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
2384 | ␉}␊ |
2385 | ␊ |
2386 | ␉if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->chameleonConfig))␊ |
2387 | ␉{␊ |
2388 | ␉␉drawCheckerBoard();␊ |
2389 | ␉}␊ |
2390 | ␉else␊ |
2391 | ␉{␊ |
2392 | ␉␉// Fill the background to 75% grey (same as BootX).␊ |
2393 | ␉␉drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);␊ |
2394 | ␉}␊ |
2395 | ␊ |
2396 | ␉if ((bootImageData) && (usePngImage))␊ |
2397 | ␉{␊ |
2398 | ␉␉x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2; ␊ |
2399 | ␉␉y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2; ␊ |
2400 | ␊ |
2401 | ␉␉// Draw the image in the center of the display. ␊ |
2402 | ␉␉blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData); ␊ |
2403 | ␉}␊ |
2404 | ␉else␊ |
2405 | ␉{␊ |
2406 | ␉␉uint8_t *appleBootPict;␊ |
2407 | ␉␉bootImageData = NULL;␊ |
2408 | ␉␉bootImageWidth = kAppleBootWidth;␊ |
2409 | ␉␉bootImageHeight = kAppleBootHeight;␊ |
2410 | ␊ |
2411 | ␉␉// Prepare the data for the default Apple boot image.␊ |
2412 | ␉␉appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);␊ |
2413 | ␉␉if (appleBootPict)␊ |
2414 | ␉␉{␊ |
2415 | ␉␉␉convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);␊ |
2416 | ␉␉␉if (bootImageData)␊ |
2417 | ␉␉␉{␊ |
2418 | ␉␉␉␉x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;␊ |
2419 | ␉␉␉␉y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;␊ |
2420 | ␉␉␉␉drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);␊ |
2421 | ␉␉␉␉free(bootImageData);␊ |
2422 | ␉␉␉}␊ |
2423 | ␉␉␉free(appleBootPict);␊ |
2424 | ␉␉}␊ |
2425 | ␉}␊ |
2426 | }␊ |
2427 | // ====================================================================␊ |
2428 | |