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 | ␉␉screen_params[0] = val;␊ |
916 | ␉}␊ |
917 | ␉if (getIntForKey("screen_height", &val, &bootInfo->themeConfig) && (val > 0)) {␊ |
918 | ␉␉screen_params[1] = val;␊ |
919 | ␉}␊ |
920 | verbose("\ninitGUI: theme res.=%dx%d.\n", screen_params[0], screen_params[1]);␊ |
921 | verbose("initGUI: gui res.=%dx%d.\n", gui.screen.width, gui.screen.height);␊ |
922 | ␊ |
923 | ␉// Initalizing GUI strucutre.␊ |
924 | ␉bzero(&gui, sizeof(gui_t));␊ |
925 | ␉␊ |
926 | ␉// find best matching vesa mode for our requested width & height␊ |
927 | ␉getGraphicModeParams(screen_params);␊ |
928 | ␊ |
929 | ␉// set our screen structure with the mode width & height␊ |
930 | ␉gui.screen.width = screen_params[0];␉␊ |
931 | ␉gui.screen.height = screen_params[1];␊ |
932 | verbose("\ninitGUI: gui res.=%dx%d.\n", gui.screen.width, gui.screen.height);␊ |
933 | ␊ |
934 | ␉// load graphics otherwise fail and return␊ |
935 | ␉if (loadGraphics() == 0) {␊ |
936 | ␉␉loadThemeValues(&bootInfo->themeConfig);␊ |
937 | ␉␉colorFont(&font_small, gui.screen.font_small_color);␊ |
938 | ␉␉colorFont(&font_console, gui.screen.font_console_color);␊ |
939 | ␊ |
940 | ␉␉// create the screen & window buffers␊ |
941 | ␉␉if (createBackBuffer(&gui.screen) == 0) {␊ |
942 | ␉␉␉if (createWindowBuffer(&gui.screen) == 0) {␊ |
943 | ␉␉␉␉if (createWindowBuffer(&gui.devicelist) == 0) {␊ |
944 | ␉␉␉␉␉if (createWindowBuffer(&gui.bootprompt) == 0) {␊ |
945 | ␉␉␉␉␉␉if (createWindowBuffer(&gui.infobox) == 0) {␊ |
946 | ␉␉␉␉␉␉␉if (createWindowBuffer(&gui.menu) == 0) {␊ |
947 | ␉␉␉␉␉␉␉␉gui.logo.draw = true;␊ |
948 | ␉␉␉␉␉␉␉␉drawBackground();␊ |
949 | ␉␉␉␉␉␉␉␉// lets copy the screen into the back buffer␊ |
950 | ␉␉␉␉␉␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
951 | ␉␉␉␉␉␉␉␉setVideoMode( GRAPHICS_MODE, 0 );␊ |
952 | ␉␉␉␉␉␉␉␉gui.initialised = true;␊ |
953 | ␉␉␉␉␉␉␉␉return 0;␊ |
954 | ␉␉␉␉␉␉␉}␊ |
955 | ␉␉␉␉␉␉}␊ |
956 | ␉␉␉␉␉}␊ |
957 | ␉␉␉␉}␊ |
958 | ␉␉␉}␊ |
959 | ␉␉}␊ |
960 | ␉}␊ |
961 | ␊ |
962 | // not available memory, freeing resources␊ |
963 | freeWindowBuffer(&gui.menu);␊ |
964 | freeWindowBuffer(&gui.infobox);␊ |
965 | freeWindowBuffer(&gui.bootprompt);␊ |
966 | freeWindowBuffer(&gui.devicelist);␊ |
967 | freeWindowBuffer(&gui.screen);␊ |
968 | freeBackBuffer(&gui.screen);␊ |
969 | unloadGraphics();␊ |
970 | ␊ |
971 | ␉return 1;␊ |
972 | }␊ |
973 | ␊ |
974 | // ====================================================================␊ |
975 | ␊ |
976 | bool is_image_loaded(int i)␊ |
977 | {␉␊ |
978 | ␉return (images[i].image != NULL) ? true : false;␊ |
979 | }␊ |
980 | ␊ |
981 | // ====================================================================␊ |
982 | ␊ |
983 | void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected)␊ |
984 | {␊ |
985 | ␉int devicetype;␊ |
986 | ␊ |
987 | ␉if( diskIsCDROM(device) ) {␊ |
988 | ␉␉devicetype = iDeviceCDROM;␉␉␉␉// Use CDROM icon␊ |
989 | ␉} else {␊ |
990 | ␉␉switch (device->part_type)␊ |
991 | ␉␉{␊ |
992 | ␉␉␉case kPartitionTypeHFS:␊ |
993 | ␉␉␉{␊ |
994 | ␉␉␉␉// ErmaC : TODO test needed for recovery icon␊ |
995 | ␉␉␉␉// Use HFSRECOVERY icon.␊ |
996 | ␉␉␉␉if (device->flags & kBVFlagBooter)␊ |
997 | ␉␉␉␉{␊ |
998 | ␉␉␉␉␉devicetype = iDeviceHFSRECOVERY;␊ |
999 | ␉␉␉␉}␊ |
1000 | ␉␉␉␉else␊ |
1001 | ␉␉␉␉{␊ |
1002 | ␊ |
1003 | ␉␉␉␉␉// Use HFS or HFSRAID icon depending on bvr flags. Fallbacks are handled by alt_image above.␊ |
1004 | ␉␉␉␉␉switch (device->OSVersion[3]) {␊ |
1005 | ␉␉␉␉␉␉case '9':␊ |
1006 | ␉␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_mav : iDeviceHFS_mav);␊ |
1007 | ␉␉␉␉␉␉␉break;␊ |
1008 | ␉␉␉␉␉␉case '8':␊ |
1009 | ␉␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_ML : iDeviceHFS_ML);␊ |
1010 | ␉␉␉␉␉␉␉break;␊ |
1011 | ␉␉␉␉␉␉case '7':␊ |
1012 | ␉␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_Lion : iDeviceHFS_Lion);␊ |
1013 | ␉␉␉␉␉␉␉break;␊ |
1014 | ␉␉␉␉␉␉case '6':␊ |
1015 | ␉␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_SL : iDeviceHFS_SL);␊ |
1016 | ␉␉␉␉␉␉␉break;␊ |
1017 | ␉␉␉␉␉␉case '5':␊ |
1018 | ␉␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_Leo : iDeviceHFS_Leo);␊ |
1019 | ␉␉␉␉␉␉␉break;␊ |
1020 | ␉␉␉␉␉␉case '4':␊ |
1021 | ␉␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_Tiger : iDeviceHFS_Tiger);␊ |
1022 | ␉␉␉␉␉␉␉break;␊ |
1023 | ␉␉␉␉␉␉case '1':␊ |
1024 | ␉␉␉␉␉␉␉if (device->OSVersion[4] == '0') { // 10.10␊ |
1025 | ␉␉␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_yos : iDeviceHFS_yos);␊ |
1026 | ␉␉␉␉␉␉␉␉break;␊ |
1027 | ␉␉␉␉␉␉␉}␊ |
1028 | ␉␉␉␉␉␉␉//if (device->OSVersion[4] == '1') { // 10.11␊ |
1029 | ␉␉␉␉␉␉␉//␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_??? : iDeviceHFS_???);␊ |
1030 | ␉␉␉␉␉␉␉//␉break;␊ |
1031 | ␉␉␉␉␉␉␉//}␊ |
1032 | ␉␉␉␉␉␉default:␊ |
1033 | ␉␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID : iDeviceHFS);␊ |
1034 | ␉␉␉␉␉␉␉break;␊ |
1035 | ␉␉␉␉␉}␊ |
1036 | ␉␉␉␉}␊ |
1037 | ␊ |
1038 | ␉␉␉␉break;␊ |
1039 | ␊ |
1040 | ␉␉␉}␊ |
1041 | ␉␉␉case kPartitionTypeHPFS:␊ |
1042 | ␉␉␉␉devicetype = iDeviceNTFS;␉␉// Use HPFS / NTFS icon␊ |
1043 | ␉␉␉␉break;␊ |
1044 | ␊ |
1045 | ␉␉␉case kPartitionTypeFAT16:␊ |
1046 | ␉␉␉␉devicetype = iDeviceFAT16;␉␉// Use FAT16 icon␊ |
1047 | ␉␉␉␉break;␊ |
1048 | ␊ |
1049 | ␉␉␉case kPartitionTypeFAT32:␊ |
1050 | ␉␉␉␉devicetype = iDeviceFAT32;␉␉// Use FAT32 icon␊ |
1051 | ␉␉␉␉break;␊ |
1052 | ␊ |
1053 | ␉␉␉case kPartitionTypeEXT3:␊ |
1054 | ␉␉␉␉devicetype = iDeviceEXT3;␉␉// Use EXT2/3 icon␊ |
1055 | ␉␉␉␉break;␊ |
1056 | ␊ |
1057 | ␉␉␉case kPartitionTypeFreeBSD: /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
1058 | ␉␉␉␉devicetype = iDeviceFreeBSD;␉␉// Use FreeBSD icon␊ |
1059 | ␉␉␉␉break;␊ |
1060 | ␊ |
1061 | ␉␉␉case kPartitionTypeOpenBSD: /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
1062 | ␉␉␉␉devicetype = iDeviceOpenBSD;␉␉// Use OpenBSD icon␊ |
1063 | ␉␉␉␉break;␊ |
1064 | ␊ |
1065 | ␉␉␉case kPartitionTypeBEFS: /* Haiku detection and Icon credits to scorpius */␊ |
1066 | ␉␉␉␉devicetype = iDeviceBEFS;␉␉// Use BEFS / Haiku icon␊ |
1067 | ␉␉␉␉break;␊ |
1068 | ␊ |
1069 | ␉␉␉default:␊ |
1070 | ␉␉␉␉devicetype = iDeviceGeneric;␉␉// Use Generic icon␊ |
1071 | ␉␉␉␉break;␊ |
1072 | ␉␉}␊ |
1073 | ␉}␊ |
1074 | ␉␊ |
1075 | ␉// Draw the selection image and use the next (device_*_o) image for the selected item.␊ |
1076 | ␉if (isSelected)␊ |
1077 | ␉{␊ |
1078 | ␉␉blend(images[iSelection].image, buffer, centeredAt(images[iSelection].image, p));␊ |
1079 | ␉␉devicetype++; // select override image ␊ |
1080 | ␉}␊ |
1081 | ␊ |
1082 | ␉// draw icon␊ |
1083 | ␉blend(images[devicetype].image, buffer, centeredAt(images[devicetype].image, p));␊ |
1084 | ␉␊ |
1085 | ␉p.y += (images[iSelection].image->height / 2) + font_console.chars[0]->height;␊ |
1086 | ␉␊ |
1087 | ␉// draw volume label ␊ |
1088 | ␉drawStrCenteredAt( device->label, &font_small, buffer, p);␉␊ |
1089 | ␊ |
1090 | }␊ |
1091 | ␊ |
1092 | // ====================================================================␊ |
1093 | ␊ |
1094 | void drawDeviceList (int start, int end, int selection)␊ |
1095 | {␊ |
1096 | ␉int␉␉␉i;␊ |
1097 | ␉bool␉␉shoWinfo = false;␊ |
1098 | ␉extern bool showBootBanner;␊ |
1099 | ␉position_t␉p, p_prev, p_next;␊ |
1100 | ␊ |
1101 | ␉//uint8_t␉maxDevices = MIN( gui.maxdevices, menucount );␊ |
1102 | ␊ |
1103 | ␉fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);␊ |
1104 | ␊ |
1105 | ␉makeRoundedCorners( gui.devicelist.pixmap);␊ |
1106 | ␊ |
1107 | ␉switch (gui.layout) {␊ |
1108 | ␊ |
1109 | ␉␉case VerticalLayout:␊ |
1110 | ␉␉␉p.x = (gui.devicelist.width /2);␊ |
1111 | ␉␉␉p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );␊ |
1112 | ␊ |
1113 | ␉␉␉// place scroll indicators at top & bottom edges␊ |
1114 | ␉␉␉p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );␊ |
1115 | ␉␉␉p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );␊ |
1116 | ␉␉␉␊ |
1117 | ␉␉␉break;␊ |
1118 | ␉␉␉␊ |
1119 | ␉␉default:␉// use Horizontal layout as the default␊ |
1120 | ␊ |
1121 | ␉␉case HorizontalLayout:␊ |
1122 | ␉␉␉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;␊ |
1123 | ␉␉␉p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );␊ |
1124 | ␊ |
1125 | ␉␉␉// place scroll indicators at left & right edges␊ |
1126 | ␉␉␉p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );␊ |
1127 | ␉␉␉p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );␊ |
1128 | ␉␉␉␊ |
1129 | ␉␉␉break;␊ |
1130 | ␉␉␉␊ |
1131 | ␉}␊ |
1132 | ␉␊ |
1133 | ␉// draw visible device icons␊ |
1134 | ␉for (i = 0; i < gui.maxdevices; i++) {␊ |
1135 | ␉␉BVRef param = menuItems[start + i].param;␊ |
1136 | ␊ |
1137 | ␉␉bool isSelected = ((start + i) == selection) ? true : false;␊ |
1138 | ␉␉if (isSelected) {␊ |
1139 | ␉␉␉if (param->flags & kBVFlagNativeBoot) {␊ |
1140 | ␉␉␉␉infoMenuNativeBoot = true;␊ |
1141 | ␉␉␉} else {␊ |
1142 | ␉␉␉␉infoMenuNativeBoot = false;␊ |
1143 | ␉␉␉␉if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END) {␊ |
1144 | ␉␉␉␉␉infoMenuSelection = 0;␊ |
1145 | ␉␉␉␉}␊ |
1146 | ␉␉␉}␊ |
1147 | ␊ |
1148 | ␉␉␉if (gui.menu.draw) {␊ |
1149 | ␉␉␉␉drawInfoMenuItems();␊ |
1150 | ␉␉␉}␊ |
1151 | ␉␉␉getBoolForKey(kShowInfoKey, &shoWinfo, &bootInfo->chameleonConfig);␊ |
1152 | ␉␉␉␊ |
1153 | ␉␉␉if (shoWinfo && showBootBanner) {␊ |
1154 | ␉␉␉␉gui.debug.cursor = pos( 10, 100);␊ |
1155 | ␉␉␉␉dprintf( &gui.screen, "label: %s\n", param->label );␊ |
1156 | ␉␉␉␉dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev );␊ |
1157 | ␉␉␉␉dprintf( &gui.screen, "type: 0x%x\n", param->type );␊ |
1158 | ␉␉␉␉dprintf( &gui.screen, "flags: 0x%x\n", param->flags );␊ |
1159 | ␉␉␉␉dprintf( &gui.screen, "part_no: %d\n", param->part_no );␊ |
1160 | ␉␉␉␉dprintf( &gui.screen, "part_boff: 0x%x\n", param->part_boff );␊ |
1161 | ␉␉␉␉dprintf( &gui.screen, "part_type: 0x%x\n", param->part_type );␊ |
1162 | ␉␉␉␉dprintf( &gui.screen, "bps: 0x%x\n", param->bps );␊ |
1163 | ␉␉␉␉dprintf( &gui.screen, "name: %s\n", param->name );␊ |
1164 | ␉␉␉␉dprintf( &gui.screen, "type_name: %s\n", param->type_name );␊ |
1165 | ␉␉␉␉dprintf( &gui.screen, "modtime: %d\n", param->modTime );␊ |
1166 | //␉␉␉␉// res␊ |
1167 | ␉␉␉␉dprintf( &gui.screen, "width: %d\n", gui.screen.width );␊ |
1168 | ␉␉␉␉dprintf( &gui.screen, "height: %d\n", gui.screen.height );␊ |
1169 | //␉␉␉␉dprintf( &gui.screen, "attr: 0x%x\n", gui.screen.attr ); //Azi: reminder␊ |
1170 | //␉␉␉␉dprintf( &gui.screen, "mm: %d\n", gui.screen.mm );␊ |
1171 | ␉␉␉}␊ |
1172 | ␉␉}␊ |
1173 | ␉␉␊ |
1174 | ␉␉drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);␊ |
1175 | ␉␉␊ |
1176 | ␉␉if (gui.layout == HorizontalLayout) {␊ |
1177 | ␉␉␉p.x += images[iSelection].image->width + gui.devicelist.iconspacing; ␊ |
1178 | ␉␉}␊ |
1179 | ␉␉if (gui.layout == VerticalLayout) {␊ |
1180 | ␉␉␉p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing ); ␊ |
1181 | ␉␉}␊ |
1182 | ␉}␊ |
1183 | ␊ |
1184 | ␉// draw prev indicator␊ |
1185 | ␉if (start) {␊ |
1186 | ␉␉blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );␊ |
1187 | ␉}␊ |
1188 | ␉// draw next indicator␊ |
1189 | ␉if ( end < gDeviceCount - 1 ) {␊ |
1190 | ␉␉blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );␊ |
1191 | ␉}␊ |
1192 | ␉gui.redraw = true;␊ |
1193 | ␉␊ |
1194 | ␉updateVRAM();␊ |
1195 | ␉␊ |
1196 | }␊ |
1197 | ␊ |
1198 | // ====================================================================␊ |
1199 | ␊ |
1200 | void clearGraphicBootPrompt()␊ |
1201 | {␊ |
1202 | ␉// clear text buffer␊ |
1203 | ␉//prompt[0] = '\0';␊ |
1204 | ␉//prompt_pos=0;␊ |
1205 | ␊ |
1206 | ␉␊ |
1207 | ␉if( gui.bootprompt.draw == true ) {␊ |
1208 | ␉␉gui.bootprompt.draw = false;␊ |
1209 | ␉␉gui.redraw = true;␊ |
1210 | ␉␉// this causes extra frames to be drawn␊ |
1211 | ␉␉//updateVRAM();␊ |
1212 | ␉}␊ |
1213 | ␊ |
1214 | ␉return;␊ |
1215 | }␊ |
1216 | ␊ |
1217 | // ====================================================================␊ |
1218 | ␊ |
1219 | void updateGraphicBootPrompt()␊ |
1220 | {␊ |
1221 | ␉fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);␊ |
1222 | ␊ |
1223 | ␉makeRoundedCorners( gui.bootprompt.pixmap);␊ |
1224 | ␊ |
1225 | ␉position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );␊ |
1226 | ␊ |
1227 | ␉// print the boot prompt text␊ |
1228 | ␉drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);␊ |
1229 | ␉␊ |
1230 | ␉// get the position of the end of the boot prompt text to display user input␊ |
1231 | ␉position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );␊ |
1232 | ␉␊ |
1233 | ␉drawStr( gBootArgs, &font_console, gui.bootprompt.pixmap, p_prompt);␊ |
1234 | ␊ |
1235 | ␉gui.menu.draw = false;␊ |
1236 | ␉gui.bootprompt.draw = true;␊ |
1237 | ␉gui.redraw = true;␊ |
1238 | ␉␊ |
1239 | ␉updateVRAM();␊ |
1240 | ␉␊ |
1241 | ␉return;␊ |
1242 | }␊ |
1243 | ␊ |
1244 | // ====================================================================␊ |
1245 | ␊ |
1246 | static inline␊ |
1247 | void vramwrite (void *data, int width, int height)␊ |
1248 | {␊ |
1249 | ␉if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4) {␊ |
1250 | ␉␉memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));␊ |
1251 | ␉} else {␊ |
1252 | ␉␉uint32_t r, g, b;␊ |
1253 | ␉␉int i, j;␊ |
1254 | ␉␉for (i = 0; i < VIDEO (height); i++) {␊ |
1255 | ␉␉␉for (j = 0; j < VIDEO (width); j++) {␊ |
1256 | ␉␉␉␉b = ((uint8_t *) data)[4*i*width + 4*j];␊ |
1257 | ␉␉␉␉g = ((uint8_t *) data)[4*i*width + 4*j + 1];␊ |
1258 | ␉␉␉␉r = ((uint8_t *) data)[4*i*width + 4*j + 2];␊ |
1259 | ␉␉␉␉switch (VIDEO (depth)) {␊ |
1260 | ␉␉␉␉␉case 32:␊ |
1261 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
1262 | ␉␉␉␉␉␉break;␊ |
1263 | ␉␉␉␉␉case 24:␊ |
1264 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)␊ |
1265 | ␉␉␉␉␉␉| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
1266 | ␉␉␉␉␉␉break;␊ |
1267 | ␉␉␉␉␉case 16:␊ |
1268 | ␉␉␉␉␉␉// Somehow 16-bit is always 15-bits really␊ |
1269 | ␉␉␉␉␉␉//␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);␊ |
1270 | ␉␉␉␉␉␉//␉␉␉␉␉␉break;␉␉␉␉␉␉␉␊ |
1271 | ␉␉␉␉␉case 15:␊ |
1272 | ␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);␊ |
1273 | ␉␉␉␉␉␉break;␉␊ |
1274 | ␉␉␉␉}␊ |
1275 | ␉␉␉}␊ |
1276 | ␉␉}␊ |
1277 | ␉}␊ |
1278 | }␊ |
1279 | ␊ |
1280 | // ====================================================================␊ |
1281 | ␊ |
1282 | void updateVRAM()␊ |
1283 | {␊ |
1284 | ␉if (gui.redraw) {␊ |
1285 | ␉␉if (gui.devicelist.draw) {␊ |
1286 | ␉␉␉blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );␊ |
1287 | ␉␉}␊ |
1288 | ␉␉if (gui.bootprompt.draw) {␊ |
1289 | ␉␉␉blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );␊ |
1290 | ␉␉}␊ |
1291 | ␉␉if (gui.menu.draw) {␊ |
1292 | ␉␉␉blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );␊ |
1293 | ␉␉}␊ |
1294 | ␉␉if (gui.infobox.draw) {␊ |
1295 | ␉␉␉blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );␊ |
1296 | ␉␉}␊ |
1297 | ␉}␊ |
1298 | ␊ |
1299 | ␉vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );␊ |
1300 | ␊ |
1301 | ␉if (gui.redraw) {␊ |
1302 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
1303 | ␉␉gui.redraw = false;␊ |
1304 | ␉}␊ |
1305 | }␊ |
1306 | ␊ |
1307 | // ====================================================================␊ |
1308 | ␊ |
1309 | struct putc_info //Azi: exists on console.c & printf.c␊ |
1310 | {␊ |
1311 | ␉char * str;␊ |
1312 | ␉char * last_str;␊ |
1313 | };␊ |
1314 | ␊ |
1315 | // ====================================================================␊ |
1316 | ␊ |
1317 | static int␊ |
1318 | sputc(int c, struct putc_info * pi) //Azi: same as above␊ |
1319 | {␊ |
1320 | ␉if (pi->last_str) {␊ |
1321 | ␉␉if (pi->str == pi->last_str) {␊ |
1322 | ␉␉␉*(pi->str) = '\0';␊ |
1323 | ␉␉␉return 0;␊ |
1324 | ␉␉}␊ |
1325 | ␉}␊ |
1326 | ␉*(pi->str)++ = c;␊ |
1327 | ␉return c;␊ |
1328 | }␊ |
1329 | ␊ |
1330 | // ====================================================================␊ |
1331 | ␊ |
1332 | int gprintf( window_t * window, const char * fmt, ...)␊ |
1333 | {␊ |
1334 | ␉char *formattedtext;␊ |
1335 | ␊ |
1336 | ␉va_list ap;␊ |
1337 | ␉␊ |
1338 | ␉struct putc_info pi;␊ |
1339 | ␊ |
1340 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1341 | ␉␉// format the text␊ |
1342 | ␉␉va_start(ap, fmt);␊ |
1343 | ␉␉pi.str = formattedtext;␊ |
1344 | ␉␉pi.last_str = 0;␊ |
1345 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1346 | ␉␉*pi.str = '\0';␊ |
1347 | ␉␉va_end(ap);␊ |
1348 | ␉␉␊ |
1349 | ␉␉position_t␉origin, cursor, bounds;␊ |
1350 | ␊ |
1351 | ␉␉int i;␊ |
1352 | ␉␉int character;␊ |
1353 | ␊ |
1354 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1355 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1356 | ␉␉␊ |
1357 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1358 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1359 | ␉␉␊ |
1360 | ␉␉cursor = origin;␊ |
1361 | ␊ |
1362 | ␉␉font_t *font = &font_console;␊ |
1363 | ␊ |
1364 | ␉␉for( i=0; i< strlen(formattedtext); i++ ) {␊ |
1365 | ␉␉␉character = formattedtext[i];␊ |
1366 | ␉␉␉␊ |
1367 | ␉␉␉character -= 32;␊ |
1368 | ␊ |
1369 | ␉␉␉// newline ?␊ |
1370 | ␉␉␉if( formattedtext[i] == '\n' ) {␊ |
1371 | ␉␉␉␉cursor.x = window->hborder;␊ |
1372 | ␉␉␉␉cursor.y += font->height;␊ |
1373 | ␊ |
1374 | ␉␉␉␉if ( cursor.y > bounds.y ) {␊ |
1375 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1376 | ␉␉␉␉}␊ |
1377 | ␉␉␉␉continue;␊ |
1378 | ␉␉␉}␊ |
1379 | ␊ |
1380 | ␉␉␉// tab ?␊ |
1381 | ␉␉␉if( formattedtext[i] == '\t' ) {␊ |
1382 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1383 | ␉␉␉}␊ |
1384 | ␊ |
1385 | ␉␉␉// draw the character␊ |
1386 | ␉␉␉if( font->chars[character]) {␊ |
1387 | ␉␉␉␉blend(font->chars[character], window->pixmap, cursor);␊ |
1388 | ␉␉␉}␊ |
1389 | ␊ |
1390 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1391 | ␊ |
1392 | ␉␉␉// check x pos and do newline␊ |
1393 | ␉␉␉if ( cursor.x > bounds.x ) {␊ |
1394 | ␉␉␉␉cursor.x = origin.x;␊ |
1395 | ␉␉␉␉cursor.y += font->height;␊ |
1396 | ␉␉␉}␊ |
1397 | ␉␉␉␊ |
1398 | ␉␉␉// check y pos and reset to origin.y␊ |
1399 | ␉␉␉if ( cursor.y > bounds.y ) {␊ |
1400 | ␉␉␉␉cursor.y = origin.y;␊ |
1401 | ␉␉␉}␊ |
1402 | ␉␉}␊ |
1403 | ␊ |
1404 | ␉␉// update cursor postition␊ |
1405 | ␉␉window->cursor = cursor;␊ |
1406 | ␉␉␊ |
1407 | ␉␉free(formattedtext);␊ |
1408 | ␉␉␊ |
1409 | ␉␉return 0;␊ |
1410 | ␉}␊ |
1411 | ␉return 1;␊ |
1412 | }␊ |
1413 | ␊ |
1414 | // ====================================================================␊ |
1415 | ␊ |
1416 | int dprintf( window_t * window, const char * fmt, ...)␊ |
1417 | {␊ |
1418 | ␉char *formattedtext;␊ |
1419 | ␉␊ |
1420 | ␉va_list ap;␊ |
1421 | ␉␊ |
1422 | ␉//window = &gui.debug;␊ |
1423 | ␉␊ |
1424 | ␉struct putc_info pi;␊ |
1425 | ␉␊ |
1426 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1427 | ␉␉// format the text␊ |
1428 | ␉␉va_start(ap, fmt);␊ |
1429 | ␉␉pi.str = formattedtext;␊ |
1430 | ␉␉pi.last_str = 0;␊ |
1431 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1432 | ␉␉*pi.str = '\0';␊ |
1433 | ␉␉va_end(ap);␊ |
1434 | ␉␉␊ |
1435 | ␉␉position_t␉origin, cursor, bounds;␊ |
1436 | ␉␉␊ |
1437 | ␉␉int i;␊ |
1438 | ␉␉int character;␊ |
1439 | ␉␉␊ |
1440 | ␉␉origin.x = MAX( gui.debug.cursor.x, window->hborder );␊ |
1441 | ␉␉origin.y = MAX( gui.debug.cursor.y, window->vborder );␊ |
1442 | ␉␉␊ |
1443 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1444 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1445 | ␉␉␊ |
1446 | ␉␉cursor = origin;␊ |
1447 | ␉␉␊ |
1448 | ␉␉font_t *font = &font_console;␊ |
1449 | ␉␉␊ |
1450 | ␉␉for( i=0; i< strlen(formattedtext); i++ ) {␊ |
1451 | ␉␉␉character = formattedtext[i];␊ |
1452 | ␉␉␉␊ |
1453 | ␉␉␉character -= 32;␊ |
1454 | ␉␉␉␊ |
1455 | ␉␉␉// newline ?␊ |
1456 | ␉␉␉if( formattedtext[i] == '\n' ) {␊ |
1457 | ␉␉␉␉cursor.x = window->hborder;␊ |
1458 | ␉␉␉␉cursor.y += font->height;␊ |
1459 | ␉␉␉␉␊ |
1460 | ␉␉␉␉if ( cursor.y > bounds.y ) {␊ |
1461 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1462 | ␉␉␉␉}␊ |
1463 | ␉␉␉␉continue;␊ |
1464 | ␉␉␉}␊ |
1465 | ␉␉␉␊ |
1466 | ␉␉␉// tab ?␊ |
1467 | ␉␉␉if( formattedtext[i] == '\t' ) {␊ |
1468 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1469 | ␉␉␉}␊ |
1470 | ␉␉␉// draw the character␊ |
1471 | ␉␉␉if( font->chars[character]) {␊ |
1472 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1473 | ␉␉␉}␊ |
1474 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1475 | ␉␉␉␊ |
1476 | ␉␉␉// check x pos and do newline␊ |
1477 | ␉␉␉if ( cursor.x > bounds.x ) {␊ |
1478 | ␉␉␉␉cursor.x = origin.x;␊ |
1479 | ␉␉␉␉cursor.y += font->height;␊ |
1480 | ␉␉␉}␊ |
1481 | ␉␉␉␊ |
1482 | ␉␉␉// check y pos and reset to origin.y␊ |
1483 | ␉␉␉if ( cursor.y > bounds.y ) {␊ |
1484 | ␉␉␉␉cursor.y = origin.y;␊ |
1485 | ␉␉␉}␊ |
1486 | ␉␉}␊ |
1487 | ␉␉␊ |
1488 | ␉␉// update cursor postition␊ |
1489 | ␉␉gui.debug.cursor = cursor;␊ |
1490 | ␉␉␊ |
1491 | ␉␉free(formattedtext);␊ |
1492 | ␉␉␊ |
1493 | ␉␉return 0;␊ |
1494 | ␉␉␊ |
1495 | ␉}␊ |
1496 | ␉return 1;␊ |
1497 | }␊ |
1498 | ␊ |
1499 | // ====================================================================␊ |
1500 | ␊ |
1501 | int vprf(const char * fmt, va_list ap)␊ |
1502 | {␊ |
1503 | ␉int i;␊ |
1504 | ␉int character;␊ |
1505 | ␊ |
1506 | ␉char *formattedtext;␊ |
1507 | ␉window_t *window = &gui.screen;␊ |
1508 | ␉struct putc_info pi;␊ |
1509 | ␉␊ |
1510 | ␉position_t␉origin, cursor, bounds;␊ |
1511 | ␉font_t *font = &font_console;␊ |
1512 | ␉␊ |
1513 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1514 | ␉␉// format the text␊ |
1515 | ␉␉pi.str = formattedtext;␊ |
1516 | ␉␉pi.last_str = 0;␊ |
1517 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1518 | ␉␉*pi.str = '\0';␊ |
1519 | ␉␉␊ |
1520 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1521 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1522 | ␉␉bounds.x = ( window->width - ( window->hborder * 2 ) );␊ |
1523 | ␉␉bounds.y = ( window->height - ( window->vborder * 2 ) );␊ |
1524 | ␉␉cursor = origin;␊ |
1525 | ␊ |
1526 | ␉␉for( i=0; i< strlen(formattedtext); i++ ) {␊ |
1527 | ␉␉␉character = formattedtext[i];␊ |
1528 | ␉␉␉character -= 32;␊ |
1529 | ␉␉␉␊ |
1530 | ␉␉␉// newline ?␊ |
1531 | ␉␉␉if( formattedtext[i] == '\n' ) {␊ |
1532 | ␉␉␉␉cursor.x = window->hborder;␊ |
1533 | ␉␉␉␉cursor.y += font->height;␊ |
1534 | ␉␉␉␉if ( cursor.y > bounds.y ) {␊ |
1535 | ␉␉␉␉␉gui.redraw = true;␊ |
1536 | ␉␉␉␉␉updateVRAM();␊ |
1537 | ␉␉␉␉␉cursor.y = window->vborder;␊ |
1538 | ␉␉␉␉}␊ |
1539 | ␉␉␉␉window->cursor.y = cursor.y;␊ |
1540 | ␉␉␉␉continue;␊ |
1541 | ␉␉␉}␊ |
1542 | ␊ |
1543 | ␉␉␉// tab ?␊ |
1544 | ␉␉␉if( formattedtext[i] == '\t' ) {␊ |
1545 | ␉␉␉␉cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );␊ |
1546 | ␉␉␉␉continue;␊ |
1547 | ␉␉␉}␊ |
1548 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1549 | ␉␉␉␊ |
1550 | ␉␉␉// check x pos and do newline␊ |
1551 | ␉␉␉if ( cursor.x > bounds.x ) {␊ |
1552 | ␉␉␉␉cursor.x = origin.x;␊ |
1553 | ␉␉␉␉cursor.y += font->height;␊ |
1554 | ␉␉␉}␊ |
1555 | ␊ |
1556 | ␉␉␉// check y pos and reset to origin.y␊ |
1557 | ␉␉␉if ( cursor.y > ( bounds.y + font->chars[0]->height) ) {␊ |
1558 | ␉␉␉␉gui.redraw = true;␊ |
1559 | ␉␉␉␉updateVRAM();␊ |
1560 | ␉␉␉␉cursor.y = window->vborder;␊ |
1561 | ␉␉␉}␊ |
1562 | ␉␉␉// draw the character␊ |
1563 | ␉␉␉if( font->chars[character]) {␊ |
1564 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1565 | ␉␉␉}␊ |
1566 | ␉␉}␊ |
1567 | ␉␉// save cursor postition␊ |
1568 | ␉␉window->cursor.x = cursor.x;␊ |
1569 | ␉␉updateVRAM();␊ |
1570 | ␉␉free(formattedtext);␊ |
1571 | ␉␉return 0;␊ |
1572 | ␉}␊ |
1573 | ␉return 1;␊ |
1574 | }␊ |
1575 | ␊ |
1576 | // ====================================================================␊ |
1577 | ␊ |
1578 | pixmap_t* charToPixmap(unsigned char ch, font_t *font) {␊ |
1579 | ␉unsigned int cha = (unsigned int)ch - 32;␊ |
1580 | ␉if (cha >= font->count) {␊ |
1581 | ␉␉// return ? if the font for the char doesn't exists␊ |
1582 | ␉␉cha = '?' - 32;␊ |
1583 | ␉}␊ |
1584 | ␉return font->chars[cha] ? font->chars[cha] : NULL;␊ |
1585 | }␊ |
1586 | ␊ |
1587 | // ====================================================================␊ |
1588 | ␊ |
1589 | position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) {␊ |
1590 | ␉pixmap_t* pm = charToPixmap(ch, font);␊ |
1591 | ␉if (pm && ((p.x + pm->width) < blendInto->width)) {␊ |
1592 | ␉␉blend(pm, blendInto, p);␊ |
1593 | ␉␉return pos(p.x + pm->width, p.y);␊ |
1594 | ␉} else {␊ |
1595 | ␉␉return p;␊ |
1596 | ␉}␊ |
1597 | }␊ |
1598 | ␊ |
1599 | // ====================================================================␊ |
1600 | ␊ |
1601 | void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1602 | {␊ |
1603 | ␉int i=0;␊ |
1604 | ␉position_t current_pos = pos(p.x, p.y);␊ |
1605 | ␉␊ |
1606 | ␉for (i=0; i < strlen(ch); i++) {␊ |
1607 | ␉␉// newline ?␊ |
1608 | ␉␉if ( ch[i] == '\n' ) {␊ |
1609 | ␉␉␉current_pos.x = p.x;␊ |
1610 | ␉␉␉current_pos.y += font->height;␊ |
1611 | ␉␉␉continue;␊ |
1612 | ␉␉}␊ |
1613 | ␉␉␊ |
1614 | ␉␉// tab ?␊ |
1615 | ␉␉if ( ch[i] == '\t' ) {␊ |
1616 | ␉␉␉current_pos.x += TAB_PIXELS_WIDTH;␊ |
1617 | ␉␉␉continue;␊ |
1618 | ␉␉}␊ |
1619 | ␉␉␊ |
1620 | ␉␉current_pos = drawChar(ch[i], font, blendInto, current_pos);␊ |
1621 | ␉}␊ |
1622 | }␊ |
1623 | ␊ |
1624 | // ====================================================================␊ |
1625 | ␊ |
1626 | void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1627 | {␊ |
1628 | ␉int i = 0;␊ |
1629 | ␉int width = 0;␊ |
1630 | ␉int max_width = 0;␊ |
1631 | ␉int height = font->height;␊ |
1632 | ␊ |
1633 | ␉// calculate the width in pixels␊ |
1634 | ␉for (i=0; i < strlen(text); i++) {␊ |
1635 | ␉␉if (text[i] == '\n') {␊ |
1636 | ␉␉␉width = 0;␊ |
1637 | ␉␉␉height += font->height;␊ |
1638 | ␉␉} else if (text[i] == '\t') {␊ |
1639 | ␉␉␉width += TAB_PIXELS_WIDTH;␊ |
1640 | ␉␉} else {␊ |
1641 | ␉␉␉pixmap_t* pm = charToPixmap(text[i], font);␊ |
1642 | ␉␉␉if (pm)␉{␊ |
1643 | ␉␉␉␉width += pm->width;␊ |
1644 | ␉␉␉}␊ |
1645 | ␉␉}␊ |
1646 | ␉␉if (width > max_width) {␊ |
1647 | ␉␉␉max_width = width;␊ |
1648 | ␉␉}␊ |
1649 | ␉}␊ |
1650 | ␊ |
1651 | ␉p.x = ( p.x - ( max_width / 2 ) );␊ |
1652 | ␉p.y = ( p.y - ( height / 2 ) );␊ |
1653 | ␉␊ |
1654 | ␉drawStr(text, font, blendInto, p);␊ |
1655 | }␊ |
1656 | ␊ |
1657 | // ====================================================================␊ |
1658 | ␊ |
1659 | int destroyFont(font_t *font)␊ |
1660 | {␊ |
1661 | ␉int i;␊ |
1662 | ␉for (i = 0; i < CHARACTERS_COUNT; i++) {␊ |
1663 | ␉␉if (font->chars[i]) {␊ |
1664 | ␉␉␉if (font->chars[i]->pixels) {␊ |
1665 | ␉␉␉␉free (font->chars[i]->pixels);␊ |
1666 | ␉␉␉}␊ |
1667 | ␉␉␉free (font->chars[i]);␊ |
1668 | ␉␉␉font->chars[i] = 0;␊ |
1669 | ␉␉}␊ |
1670 | ␉}␊ |
1671 | ␉return 0;␊ |
1672 | }␊ |
1673 | ␊ |
1674 | // ====================================================================␊ |
1675 | ␊ |
1676 | int initFont(font_t *font, image_t *data)␊ |
1677 | {␊ |
1678 | ␉unsigned int x = 0, y = 0, x2 = 0, x3 = 0;␊ |
1679 | ␉␊ |
1680 | ␉int start = 0, end = 0, count = 0, space = 0;␊ |
1681 | ␉␊ |
1682 | ␉bool monospaced = false;␊ |
1683 | ␉␊ |
1684 | ␉font->height = data->image->height;␊ |
1685 | ␊ |
1686 | ␉for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++) {␊ |
1687 | ␉␉start = end;␊ |
1688 | ␊ |
1689 | ␉␉// if the pixel is red we've reached the end of the char␊ |
1690 | ␉␉if( pixel( data->image, x, 0 ).value == 0xFFFF0000) {␊ |
1691 | ␉␉␉end = x + 1;␊ |
1692 | ␊ |
1693 | ␉␉␉if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) ) {␊ |
1694 | ␉␉␉␉font->chars[count]->width = ( end - start) - 1;␊ |
1695 | ␉␉␉␉font->chars[count]->height = font->height;␊ |
1696 | ␉␉␉␊ |
1697 | ␉␉␉␉if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) ) {␊ |
1698 | ␉␉␉␉␉space += ( font->chars[count]->width * data->image->height * 4 );␊ |
1699 | ␉␉␉␉␉// we skip the first line because there are just the red pixels for the char width␊ |
1700 | ␉␉␉␉␉for( y = 1; y< (font->height); y++) {␊ |
1701 | ␉␉␉␉␉␉for( x2 = start, x3 = 0; x2 < end; x2++, x3++) {␊ |
1702 | ␉␉␉␉␉␉␉pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );␊ |
1703 | ␉␉␉␉␉␉}␉␊ |
1704 | ␉␉␉␉␉}␊ |
1705 | ␉␉␉␉␉␊ |
1706 | ␉␉␉␉␉// check if font is monospaced␊ |
1707 | ␉␉␉␉␉if( ( count > 0 ) && ( font->width != font->chars[count]->width ) ) {␊ |
1708 | ␉␉␉␉␉␉monospaced = true;␊ |
1709 | ␉␉␉␉␉}␊ |
1710 | ␊ |
1711 | ␉␉␉␉␉font->width = font->chars[count]->width;␊ |
1712 | ␉␉␉␉␉␊ |
1713 | ␉␉␉␉␉count++;␊ |
1714 | ␉␉␉␉}␊ |
1715 | ␉␉␉}␊ |
1716 | ␉␉}␊ |
1717 | ␉}␊ |
1718 | ␊ |
1719 | ␉for (x = count; x < CHARACTERS_COUNT; x++) {␊ |
1720 | ␉␉font->chars[x] = NULL;␊ |
1721 | ␉}␊ |
1722 | ␊ |
1723 | ␉if(monospaced) {␊ |
1724 | ␉␉font->width = 0;␊ |
1725 | ␉}␊ |
1726 | ␊ |
1727 | ␉font->count = count;␊ |
1728 | ␊ |
1729 | ␉return 0;␊ |
1730 | }␊ |
1731 | ␊ |
1732 | // ====================================================================␊ |
1733 | ␊ |
1734 | void colorFont(font_t *font, uint32_t color)␊ |
1735 | {␊ |
1736 | ␉if( !color ) {␊ |
1737 | ␉␉return;␊ |
1738 | ␉}␊ |
1739 | ␊ |
1740 | ␉int x, y, width, height;␊ |
1741 | ␉int count = 0;␊ |
1742 | ␉pixel_t *buff;␊ |
1743 | ␉␊ |
1744 | ␉while( font->chars[count++] ) {␊ |
1745 | ␉␉width = font->chars[count-1]->width;␊ |
1746 | ␉␉height = font->chars[count-1]->height;␊ |
1747 | ␉␉for( y = 0; y < height; y++ ) {␊ |
1748 | ␉␉␉for( x = 0; x < width; x++ ) {␊ |
1749 | ␉␉␉␉buff = &(pixel( font->chars[count-1], x, y ));␊ |
1750 | ␉␉␉␉if( buff->ch.a ) {␊ |
1751 | ␉␉␉␉␉buff->ch.r = (color & 0xFFFF0000) >> 16;␊ |
1752 | ␉␉␉␉␉buff->ch.g = (color & 0xFF00FF00) >> 8;␊ |
1753 | ␉␉␉␉␉buff->ch.b = (color & 0xFF0000FF);␊ |
1754 | ␉␉␉␉}␊ |
1755 | ␉␉␉}␊ |
1756 | ␉␉}␊ |
1757 | ␉}␊ |
1758 | }␊ |
1759 | ␊ |
1760 | // ====================================================================␊ |
1761 | ␊ |
1762 | void makeRoundedCorners(pixmap_t *p)␊ |
1763 | {␊ |
1764 | ␉int x,y;␊ |
1765 | ␉int width=p->width-1;␊ |
1766 | ␉int height=p->height-1;␊ |
1767 | ␉␊ |
1768 | ␉// 10px rounded corner alpha values␊ |
1769 | ␉uint8_t roundedCorner[10][10] =␊ |
1770 | ␉{␊ |
1771 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},␊ |
1772 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1773 | ␉␉{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1774 | ␉␉{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1775 | ␉␉{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1776 | ␉␉{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1777 | ␉␉{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1778 | ␉␉{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1779 | ␉␉{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1780 | ␉␉{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}␊ |
1781 | ␉};␊ |
1782 | ␉␊ |
1783 | ␉uint8_t alpha=0;␊ |
1784 | ␉␊ |
1785 | ␉for( y=0; y<10; y++) {␊ |
1786 | ␉␉for( x=0; x<10; x++) {␊ |
1787 | ␉␉␉// skip if the pixel should be visible␊ |
1788 | ␉␉␉if(roundedCorner[y][x] != 0xFF)␉{ ␊ |
1789 | ␉␉␉␉alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );␊ |
1790 | ␉␉␉␉// Upper left corner␊ |
1791 | ␉␉␉␉pixel(p, x, y).ch.a = alpha;␊ |
1792 | ␊ |
1793 | ␉␉␉␉// upper right corner␊ |
1794 | ␉␉␉␉pixel(p, width-x,y).ch.a = alpha;␊ |
1795 | ␊ |
1796 | ␉␉␉␉// lower left corner␊ |
1797 | ␉␉␉␉pixel(p, x, height-y).ch.a = alpha;␊ |
1798 | ␊ |
1799 | ␉␉␉␉// lower right corner␊ |
1800 | ␉␉␉␉pixel(p, width-x, height-y).ch.a = alpha;␊ |
1801 | ␉␉␉}␊ |
1802 | ␉␉}␊ |
1803 | ␉}␊ |
1804 | }␊ |
1805 | ␊ |
1806 | // ====================================================================␊ |
1807 | ␊ |
1808 | void showInfoBox(char *title, char *text_orig)␊ |
1809 | {␊ |
1810 | ␉char* text;␊ |
1811 | ␉int i, key, lines, visiblelines;␊ |
1812 | ␊ |
1813 | ␉int currentline=0;␊ |
1814 | ␉int cnt=0;␊ |
1815 | ␉int offset=0;␊ |
1816 | ␉␊ |
1817 | ␉if( !title || !text_orig ) {␊ |
1818 | ␉␉return;␊ |
1819 | ␉}␊ |
1820 | ␊ |
1821 | ␉// Create a copy so that we don't mangle the original␊ |
1822 | ␉text = malloc(strlen(text_orig) + 1);␊ |
1823 | ␉strcpy(text, text_orig);␊ |
1824 | ␊ |
1825 | ␉position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );␊ |
1826 | ␊ |
1827 | ␉// calculate number of lines in the title␊ |
1828 | ␉for ( i = 0, lines = 1; i<strlen(title); i++ ) {␊ |
1829 | ␉␉if( title[i] == '\n') {␊ |
1830 | ␉␉␉lines++;␊ |
1831 | ␉␉}␊ |
1832 | ␉}␊ |
1833 | ␉// y position of text is lines in title * height of font␊ |
1834 | ␉position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));␊ |
1835 | ␉␊ |
1836 | ␉// calculate number of lines in the text␊ |
1837 | ␉for ( i=0, lines = 1; i<strlen(text); i++ ) {␊ |
1838 | ␉␉if( text[i] == '\n') {␊ |
1839 | ␉␉␉lines++;␊ |
1840 | ␉␉}␊ |
1841 | ␉}␊ |
1842 | ␉// if text ends with \n strip off␊ |
1843 | ␉if( text[i] == '\n' || text[i] == '\0') {␊ |
1844 | ␉␉lines--;␊ |
1845 | ␉}␊ |
1846 | ␉visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;␊ |
1847 | ␉␊ |
1848 | ␉// lets display the text and allow scroll thru using up down / arrows␊ |
1849 | ␉while(1) {␊ |
1850 | ␉␉// move to current line in text␊ |
1851 | ␉␉for( offset = 0, i = 0; offset < strlen(text); offset++ ) {␊ |
1852 | ␉␉␉if( currentline == i) {␊ |
1853 | ␉␉␉␉break;␊ |
1854 | ␉␉␉}␊ |
1855 | ␉␉␉if( text[offset] =='\n') {␊ |
1856 | ␉␉␉␉i++;␊ |
1857 | ␉␉␉}␊ |
1858 | ␉␉}␊ |
1859 | ␊ |
1860 | ␉␉// find last visible line in text and place \0␊ |
1861 | ␉␉for( i = offset, cnt = 0; i < strlen(text); i++) {␊ |
1862 | ␉␉␉if(text[i]=='\n') {␊ |
1863 | ␉␉␉␉cnt++;␊ |
1864 | ␉␉␉}␊ |
1865 | ␉␉␉if ( cnt == visiblelines ) {␊ |
1866 | ␉␉␉␉text[i]='\0';␊ |
1867 | ␉␉␉␉break;␊ |
1868 | ␉␉␉}␊ |
1869 | ␉␉}␊ |
1870 | ␊ |
1871 | ␉␉fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);␊ |
1872 | ␊ |
1873 | ␉␉makeRoundedCorners( gui.infobox.pixmap);␊ |
1874 | ␊ |
1875 | ␉␉// print the title if present␊ |
1876 | ␉␉if( title ) {␊ |
1877 | ␉␉␉drawStr(title, &font_console, gui.infobox.pixmap, pos_title);␊ |
1878 | ␉␉}␊ |
1879 | ␉␉// print the text␊ |
1880 | ␉␉drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);␊ |
1881 | ␊ |
1882 | ␉␉// restore \n in text␊ |
1883 | ␉␉if ( cnt == visiblelines ) {␊ |
1884 | ␉␉␉text[i] = '\n';␊ |
1885 | ␉␉}␊ |
1886 | ␉␉position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );␊ |
1887 | ␉␉␊ |
1888 | ␉␉// draw prev indicator␊ |
1889 | ␉␉if(offset) {␊ |
1890 | ␉␉␉blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));␊ |
1891 | ␉␉}␊ |
1892 | ␉␉␊ |
1893 | ␉␉// draw next indicator␊ |
1894 | ␉␉if( lines > ( currentline + visiblelines ) ) {␊ |
1895 | ␉␉␉pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );␊ |
1896 | ␉␉␉blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );␊ |
1897 | ␉␉}␊ |
1898 | ␊ |
1899 | ␉␉gui.bootprompt.draw = false;␊ |
1900 | ␉␉gui.infobox.draw = true;␊ |
1901 | ␉␉gui.redraw = true;␊ |
1902 | ␉␉␊ |
1903 | ␉␉updateVRAM();␊ |
1904 | ␉␉␊ |
1905 | ␉␉key = getchar();␊ |
1906 | ␉␉␉␊ |
1907 | ␉␉if( key == KEY_UP ) {␊ |
1908 | ␉␉␉if( currentline > 0 ) {␊ |
1909 | ␉␉␉␉currentline--;␊ |
1910 | ␉␉␉}␊ |
1911 | ␉␉}␊ |
1912 | ␊ |
1913 | ␉␉if( key == KEY_DOWN ) {␊ |
1914 | ␉␉␉if( lines > ( currentline + visiblelines ) ) {␊ |
1915 | ␉␉␉␉currentline++;␊ |
1916 | ␉␉␉}␊ |
1917 | ␉␉}␊ |
1918 | ␊ |
1919 | ␉␉if( key == KEY_ESC || key == 'q' || key == 'Q') {␊ |
1920 | ␉␉␉gui.infobox.draw = false;␊ |
1921 | ␉␉␉gui.redraw = true;␊ |
1922 | ␉␉␉updateVRAM();␊ |
1923 | ␉␉␉break;␊ |
1924 | ␉␉}␊ |
1925 | ␊ |
1926 | ␉␉if(key == ' ') { // spacebar = next page␊ |
1927 | ␉␉␉if( lines > ( currentline + visiblelines ) ) {␊ |
1928 | ␉␉␉␉currentline += visiblelines;␊ |
1929 | ␉␉␉}␊ |
1930 | ␉␉␉if(lines < (currentline + visiblelines)) {␊ |
1931 | ␉␉␉␉currentline = lines - visiblelines;␊ |
1932 | ␉␉␉}␊ |
1933 | ␉␉}␊ |
1934 | ␉}␊ |
1935 | ␉free(text);␊ |
1936 | }␊ |
1937 | ␊ |
1938 | // ====================================================================␊ |
1939 | ␊ |
1940 | void animateProgressBar()␊ |
1941 | {␊ |
1942 | ␉int y;␊ |
1943 | ␉␊ |
1944 | ␉if( time18() > lasttime) {␊ |
1945 | ␉␉lasttime = time18();␊ |
1946 | ␊ |
1947 | ␉␉pixmap_t *buffBar = images[iProgressBar].image;␊ |
1948 | ␊ |
1949 | ␉␉uint32_t buff = buffBar->pixels[0].value;␊ |
1950 | ␉␊ |
1951 | ␉␉memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );␊ |
1952 | ␊ |
1953 | ␉␉for( y = buffBar->height - 1; y > 0; y--) {␊ |
1954 | ␉␉␉pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);␊ |
1955 | ␉␉}␊ |
1956 | ␉␉pixel(buffBar, buffBar->width-1, 0).value = buff;␊ |
1957 | ␉}␊ |
1958 | }␊ |
1959 | ␊ |
1960 | // ====================================================================␊ |
1961 | ␊ |
1962 | void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)␊ |
1963 | {␊ |
1964 | ␉if(progress>100) {␊ |
1965 | ␉␉return;␊ |
1966 | ␉}␊ |
1967 | ␊ |
1968 | ␉p.x = ( p.x - ( width / 2 ) );␊ |
1969 | ␊ |
1970 | ␉int todraw = (width * progress) / 100;␊ |
1971 | ␊ |
1972 | ␉pixmap_t *buff = images[iProgressBar].image;␊ |
1973 | ␉pixmap_t *buffBG = images[iProgressBarBackground].image;␊ |
1974 | ␉if(!buff || !buffBG) {␊ |
1975 | ␉␉return;␊ |
1976 | ␉}␊ |
1977 | ␊ |
1978 | ␉pixmap_t progressbar;␊ |
1979 | ␉progressbar.pixels=malloc(width * 4 * buff->height);␊ |
1980 | ␉if(!progressbar.pixels) {␊ |
1981 | ␉␉return; ␊ |
1982 | ␉}␊ |
1983 | ␊ |
1984 | ␉progressbar.width = width;␊ |
1985 | ␉progressbar.height = buff->height;␊ |
1986 | ␊ |
1987 | ␉int x=0,x2=0,y=0;␊ |
1988 | ␉␊ |
1989 | ␉for(y=0; y<buff->height; y++) {␊ |
1990 | ␉␉for(x=0; x<todraw; x++, x2++) {␊ |
1991 | ␉␉␉if(x2 == (buff->width-1)) {␊ |
1992 | ␉␉␉␉x2=0;␊ |
1993 | ␉␉␉}␊ |
1994 | ␉␉␉pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;␊ |
1995 | ␉␉}␊ |
1996 | ␉␉x2=0;␊ |
1997 | ␉}␊ |
1998 | ␊ |
1999 | ␉for(y=0; y<buff->height; y++) {␊ |
2000 | ␉␉for(x=todraw, x2 = 0; x < width - 1; x++, x2++) {␊ |
2001 | ␉␉␉if(x2 == (buffBG->width -2 )) {␊ |
2002 | ␉␉␉␉x2 = 0;␊ |
2003 | ␉␉␉}␊ |
2004 | ␉␉␉pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;␊ |
2005 | ␉␉}␊ |
2006 | ␉␉if(progress < 100) {␊ |
2007 | ␉␉␉pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
2008 | ␉␉}␊ |
2009 | ␊ |
2010 | ␉␉if(progress == 0) {␊ |
2011 | ␉␉␉pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
2012 | ␉␉}␊ |
2013 | ␊ |
2014 | ␉␉x2=0;␊ |
2015 | ␉}␊ |
2016 | ␊ |
2017 | ␉blend(&progressbar, blendInto, p);␊ |
2018 | ␉animateProgressBar();␊ |
2019 | ␉free(progressbar.pixels);␊ |
2020 | }␊ |
2021 | ␊ |
2022 | // ====================================================================␊ |
2023 | ␊ |
2024 | void drawInfoMenuItems()␊ |
2025 | {␊ |
2026 | ␉int i,n;␊ |
2027 | ␉␊ |
2028 | ␉position_t position;␊ |
2029 | ␉␊ |
2030 | ␉pixmap_t *selection = images[iMenuSelection].image;␊ |
2031 | ␉␊ |
2032 | ␉pixmap_t *pbuff;␊ |
2033 | ␊ |
2034 | ␉fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);␊ |
2035 | ␊ |
2036 | ␉makeRoundedCorners(gui.menu.pixmap);␊ |
2037 | ␉␊ |
2038 | ␉uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;␊ |
2039 | ␊ |
2040 | ␉position = pos(0,0);␊ |
2041 | ␉␊ |
2042 | ␉for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++) {␊ |
2043 | ␉␉if (i == infoMenuSelection) {␊ |
2044 | ␉␉␉blend(selection, gui.menu.pixmap, position);␊ |
2045 | ␉␉}␊ |
2046 | ␊ |
2047 | ␉␉pbuff = images[n].image;␊ |
2048 | ␉␉if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END) {␊ |
2049 | ␉␉␉blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap, ␊ |
2050 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
2051 | ␉␉} else {␊ |
2052 | ␉␉␉blend( pbuff, gui.menu.pixmap, ␊ |
2053 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
2054 | ␉␉}␊ |
2055 | ␊ |
2056 | ␉␉drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap, ␊ |
2057 | ␉␉␉pos(position.x + (pbuff->width + gui.menu.hborder), ␊ |
2058 | ␉␉␉␉position.y + ((selection->height - font_console.height) / 2)));␊ |
2059 | ␉␉position.y += images[iMenuSelection].image->height;␊ |
2060 | ␉␊ |
2061 | ␉}␊ |
2062 | ␉␊ |
2063 | ␉gui.redraw = true;␊ |
2064 | }␊ |
2065 | ␊ |
2066 | // ====================================================================␊ |
2067 | ␊ |
2068 | int drawInfoMenu()␊ |
2069 | {␊ |
2070 | ␉drawInfoMenuItems();␊ |
2071 | ␊ |
2072 | ␉gui.menu.draw = true;␊ |
2073 | ␊ |
2074 | ␉updateVRAM();␊ |
2075 | ␉␊ |
2076 | ␉return 1;␊ |
2077 | }␊ |
2078 | ␊ |
2079 | // ====================================================================␊ |
2080 | ␊ |
2081 | int updateInfoMenu(int key)␊ |
2082 | {␊ |
2083 | ␉switch (key)␊ |
2084 | ␉{␊ |
2085 | ␊ |
2086 | ␉␉case KEY_UP:␉// up arrow␊ |
2087 | ␉␉␉if (infoMenuSelection > 0) {␊ |
2088 | ␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1) {␊ |
2089 | ␉␉␉␉␉infoMenuSelection -= 4;␊ |
2090 | ␉␉␉␉} else {␊ |
2091 | ␉␉␉␉␉infoMenuSelection--;␊ |
2092 | ␉␉␉␉}␊ |
2093 | ␉␉␉␉drawInfoMenuItems();␊ |
2094 | ␉␉␉␉updateVRAM();␊ |
2095 | ␊ |
2096 | ␉␉␉} else {␊ |
2097 | ␊ |
2098 | ␉␉␉␉gui.menu.draw = false;␊ |
2099 | ␉␉␉␉gui.redraw = true;␊ |
2100 | ␊ |
2101 | ␉␉␉␉updateVRAM();␊ |
2102 | ␉␉␉␉␊ |
2103 | ␉␉␉␉return CLOSE_INFO_MENU;␊ |
2104 | ␉␉␉}␊ |
2105 | ␉␉␉break;␊ |
2106 | ␊ |
2107 | ␉␉case KEY_DOWN:␉// down arrow␊ |
2108 | ␉␉␉if (infoMenuSelection < infoMenuItemsCount - 1) {␊ |
2109 | ␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)␊ |
2110 | ␉␉␉␉{␊ |
2111 | ␉␉␉␉␉infoMenuSelection += 4;␊ |
2112 | ␉␉␉␉} else {␊ |
2113 | ␉␉␉␉␉infoMenuSelection++;␊ |
2114 | ␉␉␉␉}␊ |
2115 | ␉␉␉␉drawInfoMenuItems();␊ |
2116 | ␉␉␉␉updateVRAM();␊ |
2117 | ␉␉␉}␊ |
2118 | ␉␉␉break;␊ |
2119 | ␊ |
2120 | ␉␉case KEY_ENTER:␊ |
2121 | ␉␉␉key = 0;␊ |
2122 | ␉␉␉if( infoMenuSelection == MENU_SHOW_MEMORY_INFO ) {␊ |
2123 | ␉␉␉␉showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());␊ |
2124 | ␉␉␉} else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO ) {␊ |
2125 | ␉␉␉␉showInfoBox( getVBEInfoString(), getVBEModeInfoString() );␊ |
2126 | ␉␉␉} else if( infoMenuSelection == MENU_SHOW_HELP ) {␊ |
2127 | ␉␉␉␉showHelp();␊ |
2128 | ␉␉␉} else {␊ |
2129 | ␉␉␉␉int buff = infoMenuSelection;␊ |
2130 | ␉␉␉␉infoMenuSelection = 0;␊ |
2131 | ␉␉␉␉return buff;␊ |
2132 | ␉␉␉}␊ |
2133 | ␉␉␉break;␊ |
2134 | ␉}␊ |
2135 | ␉return DO_NOT_BOOT;␊ |
2136 | }␊ |
2137 | ␊ |
2138 | // ====================================================================␊ |
2139 | ␊ |
2140 | uint16_t bootImageWidth = 0; ␊ |
2141 | uint16_t bootImageHeight = 0; ␊ |
2142 | uint8_t *bootImageData = NULL; ␊ |
2143 | static bool usePngImage = true;␊ |
2144 | ␊ |
2145 | //==========================================================================␊ |
2146 | // loadBootGraphics␊ |
2147 | static void loadBootGraphics(void)␊ |
2148 | {␊ |
2149 | ␉if (bootImageData != NULL) {␊ |
2150 | ␉␉return;␊ |
2151 | ␉}␊ |
2152 | ␊ |
2153 | ␉char dirspec[256];␊ |
2154 | ␊ |
2155 | ␉if ((strlen(theme_name) + 24) > sizeof(dirspec)) {␊ |
2156 | ␉␉usePngImage = false; ␊ |
2157 | ␉␉return;␊ |
2158 | ␉}␊ |
2159 | ␉sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);␊ |
2160 | ␉if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {␊ |
2161 | #ifdef CONFIG_EMBED_THEME␊ |
2162 | ␉␉if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)␊ |
2163 | #endif␊ |
2164 | ␉␉usePngImage = false; ␊ |
2165 | ␉}␊ |
2166 | }␊ |
2167 | ␊ |
2168 | //==========================================================================␊ |
2169 | // drawBootGraphics␊ |
2170 | void drawBootGraphics(void)␊ |
2171 | {␊ |
2172 | ␉int pos;␊ |
2173 | ␉int length;␊ |
2174 | ␉const char *dummyVal;␊ |
2175 | ␉int oldScreenWidth, oldScreenHeight;␊ |
2176 | ␉bool legacy_logo;␊ |
2177 | ␉uint16_t x, y; ␊ |
2178 | ␉␊ |
2179 | ␉if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->chameleonConfig) && legacy_logo) {␊ |
2180 | ␉␉usePngImage = false; ␊ |
2181 | ␉} else if (bootImageData == NULL) {␊ |
2182 | ␉␉loadBootGraphics();␊ |
2183 | ␉}␊ |
2184 | ␊ |
2185 | ␉// parse screen size parameters␊ |
2186 | ␉if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0) {␊ |
2187 | ␉␉screen_params[0] = pos;␊ |
2188 | ␉} else {␊ |
2189 | ␉␉screen_params[0] = DEFAULT_SCREEN_WIDTH;␊ |
2190 | ␉}␊ |
2191 | ␉if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0) {␊ |
2192 | ␉␉screen_params[1] = pos;␊ |
2193 | ␉} else {␊ |
2194 | ␉␉screen_params[1] = DEFAULT_SCREEN_HEIGHT;␊ |
2195 | ␉}␊ |
2196 | verbose("\ndrawBootGraphics: gui res.=%dx%d.\n", gui.screen.width, gui.screen.height);␊ |
2197 | verbose("drawBootGraphics: boot res.=%dx%d.\n", screen_params[0], screen_params[1]);␊ |
2198 | ␊ |
2199 | ␉// Save current screen resolution.␊ |
2200 | ␉oldScreenWidth = gui.screen.width;␊ |
2201 | ␉oldScreenHeight = gui.screen.height;␊ |
2202 | ␊ |
2203 | ␉gui.screen.width = screen_params[0];␊ |
2204 | ␉gui.screen.height = screen_params[1];␊ |
2205 | ␊ |
2206 | ␉// find best matching vesa mode for our requested width & height␊ |
2207 | ␉getGraphicModeParams(screen_params);␊ |
2208 | verbose("\ndrawBootGraphics: gui res.=%dx%d.\n", gui.screen.width, gui.screen.height);␊ |
2209 | verbose("drawBootGraphics: boot res.=%dx%d.\n", screen_params[0], screen_params[1]);␊ |
2210 | ␊ |
2211 | ␉// Set graphics mode if the booter was in text mode or the screen resolution has changed.␊ |
2212 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) ) {␊ |
2213 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
2214 | ␉}␊ |
2215 | ␊ |
2216 | ␉if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->chameleonConfig)) {␊ |
2217 | ␉␉drawCheckerBoard();␊ |
2218 | ␉} else {␊ |
2219 | ␉␉// Fill the background to 75% grey (same as BootX). ␊ |
2220 | ␉␉drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01); ␊ |
2221 | ␉}␊ |
2222 | ␉if ((bootImageData) && (usePngImage)) { ␊ |
2223 | ␉␉x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2; ␊ |
2224 | ␉␉y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2; ␊ |
2225 | ␊ |
2226 | ␉␉// Draw the image in the center of the display. ␊ |
2227 | ␉␉blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData); ␊ |
2228 | ␉} else { ␊ |
2229 | ␉␉uint8_t *appleBootPict; ␊ |
2230 | ␉␉bootImageData = NULL; ␊ |
2231 | ␉␉bootImageWidth = kAppleBootWidth; ␊ |
2232 | ␉␉bootImageHeight = kAppleBootHeight; ␊ |
2233 | ␊ |
2234 | ␉␉// Prepare the data for the default Apple boot image. ␊ |
2235 | ␉␉appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight); ␊ |
2236 | ␉␉if (appleBootPict) { ␊ |
2237 | ␉␉␉convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData); ␊ |
2238 | ␉␉␉if (bootImageData) {␉␊ |
2239 | ␉␉␉␉x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2; ␊ |
2240 | ␉␉␉␉y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2; ␊ |
2241 | ␉␉␉␉drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);␊ |
2242 | ␉␉␉␉free(bootImageData);␊ |
2243 | ␉␉␉}␊ |
2244 | ␉␉␉free(appleBootPict); ␊ |
2245 | ␉␉} ␊ |
2246 | ␉}␊ |
2247 | }␊ |
2248 | // ====================================================================␊ |
2249 | |