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