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