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