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