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