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