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