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