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