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