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