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