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