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