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