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