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