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