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