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␉␉debugInfo = false; //Azi:displayinfo␊ |
818 | ␉extern bool␉showBootBanner;␊ |
819 | ␉position_t␉p, p_prev, p_next;␊ |
820 | ␊ |
821 | ␉//uint8_t␉maxDevices = MIN( gui.maxdevices, menucount );␊ |
822 | ␉␉␊ |
823 | ␉fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);␊ |
824 | ␊ |
825 | ␉makeRoundedCorners( gui.devicelist.pixmap);␊ |
826 | ␊ |
827 | ␉switch (gui.layout)␊ |
828 | ␉{␊ |
829 | ␊ |
830 | ␉␉case VerticalLayout:␊ |
831 | ␉␉␉p.x = (gui.devicelist.width /2);␊ |
832 | ␉␉␉p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );␊ |
833 | ␊ |
834 | ␉␉␉// place scroll indicators at top & bottom edges␊ |
835 | ␉␉␉p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );␊ |
836 | ␉␉␉p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );␊ |
837 | ␉␉␉␊ |
838 | ␉␉␉break;␊ |
839 | ␉␉␉␊ |
840 | ␉␉default:␉// use Horizontal layout as the default␊ |
841 | ␊ |
842 | ␉␉case HorizontalLayout:␊ |
843 | ␉␉␉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;␊ |
844 | ␉␉␉p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );␊ |
845 | ␊ |
846 | ␉␉␉// place scroll indicators at left & right edges␊ |
847 | ␉␉␉p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );␊ |
848 | ␉␉␉p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );␊ |
849 | ␉␉␉␊ |
850 | ␉␉␉break;␊ |
851 | ␉␉␉␊ |
852 | ␉}␊ |
853 | ␉␊ |
854 | ␉// draw visible device icons␊ |
855 | ␉for (i = 0; i < gui.maxdevices; i++)␊ |
856 | ␉{␊ |
857 | ␉␉BVRef param = menuItems[start + i].param;␊ |
858 | ␊ |
859 | bool isSelected = ((start + i) == selection) ? true : false;␊ |
860 | ␉␉if (isSelected)␊ |
861 | ␉␉{␊ |
862 | if (param->flags & kBVFlagNativeBoot)␊ |
863 | {␊ |
864 | infoMenuNativeBoot = true;␊ |
865 | }␊ |
866 | else␊ |
867 | {␊ |
868 | infoMenuNativeBoot = false;␊ |
869 | if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)␊ |
870 | infoMenuSelection = 0;␊ |
871 | }␊ |
872 | ␊ |
873 | ␉␉␉if (gui.menu.draw)␊ |
874 | ␉␉␉␉drawInfoMenuItems();␊ |
875 | ␉␉␊ |
876 | ␉␉␉//Azi: making this info more accessible. TODO: remove the stuff on graphics.c!␊ |
877 | ␉␉␉getBoolForKey(kDebugInfoKey, &debugInfo, &bootInfo->bootConfig);␊ |
878 | ␉␉␉␊ |
879 | #ifdef AUTORES_DEBUG //Azi:autoresolution␊ |
880 | ␉␉␉debugInfo = true;␊ |
881 | #endif␊ |
882 | ␊ |
883 | ␉␉␉if (debugInfo && showBootBanner)␊ |
884 | ␉␉␉{␊ |
885 | ␉␉␉␉gui.debug.cursor = pos( 10, 100);␊ |
886 | ␉␉␉␉dprintf( &gui.screen, "label: %s\n", param->label );␊ |
887 | ␉␉␉␉dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev );␊ |
888 | ␉␉␉␉dprintf( &gui.screen, "type: 0x%x\n", param->type );␊ |
889 | ␉␉␉␉dprintf( &gui.screen, "flags: 0x%x\n", param->flags );␊ |
890 | ␉␉␉␉dprintf( &gui.screen, "part_no: %d\n", param->part_no );␊ |
891 | ␉␉␉␉dprintf( &gui.screen, "part_boff: 0x%x\n", param->part_boff );␊ |
892 | ␉␉␉␉dprintf( &gui.screen, "part_type: 0x%x\n", param->part_type );␊ |
893 | ␉␉␉␉dprintf( &gui.screen, "bps: 0x%x\n", param->bps );␊ |
894 | ␉␉␉␉dprintf( &gui.screen, "name: %s\n", param->name );␊ |
895 | ␉␉␉␉dprintf( &gui.screen, "type_name: %s\n", param->type_name );␊ |
896 | ␉␉␉␉dprintf( &gui.screen, "modtime: %d\n", param->modTime );␊ |
897 | ␉␉␉␉dprintf( &gui.screen, "width: %d\n", gui.screen.width );␊ |
898 | ␉␉␉␉dprintf( &gui.screen, "height: %d\n", gui.screen.height );␊ |
899 | ␉␉␉␉dprintf( &gui.screen, "attr: 0x%x\n", gui.screen.attr );␊ |
900 | ␉␉␉␉dprintf( &gui.screen, "mm: %d\n", gui.screen.mm );␊ |
901 | ␉␉␉}␊ |
902 | ␉␉}␊ |
903 | ␉␉␊ |
904 | ␉␉drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);␊ |
905 | ␉␉␊ |
906 | ␉␉if (gui.layout == HorizontalLayout)␊ |
907 | ␉␉{␊ |
908 | ␉␉␉p.x += images[iSelection].image->width + gui.devicelist.iconspacing; ␊ |
909 | ␉␉}␊ |
910 | ␉␉if (gui.layout == VerticalLayout)␊ |
911 | ␉␉{␊ |
912 | ␉␉␉p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing ); ␊ |
913 | ␉␉}␊ |
914 | ␉}␊ |
915 | ␊ |
916 | ␉// draw prev indicator␊ |
917 | ␉if(start)␊ |
918 | ␉␉blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );␊ |
919 | ␊ |
920 | ␉// draw next indicator␊ |
921 | ␉if( end < gDeviceCount - 1 )␊ |
922 | ␉␉blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );␊ |
923 | ␊ |
924 | ␉gui.redraw = true;␊ |
925 | ␉␊ |
926 | ␉updateVRAM();␊ |
927 | ␉␊ |
928 | }␊ |
929 | ␊ |
930 | void clearGraphicBootPrompt()␊ |
931 | {␊ |
932 | ␉// clear text buffer␊ |
933 | ␉prompt[0] = '\0';␊ |
934 | ␉prompt_pos=0;␊ |
935 | ␊ |
936 | ␉␊ |
937 | ␉if(␉gui.bootprompt.draw == true )␊ |
938 | ␉{␊ |
939 | ␉␉gui.bootprompt.draw = false;␊ |
940 | ␉␉gui.redraw = true;␊ |
941 | ␉␉// this causes extra frames to be drawn␊ |
942 | ␉␉//updateVRAM();␊ |
943 | ␉}␊ |
944 | ␊ |
945 | ␉return;␊ |
946 | }␊ |
947 | ␊ |
948 | void updateGraphicBootPrompt(int key)␊ |
949 | {␊ |
950 | ␉if ( key == kBackspaceKey )␊ |
951 | ␉␉prompt[--prompt_pos] = '\0';␊ |
952 | ␉else ␊ |
953 | ␉{␊ |
954 | ␉␉prompt[prompt_pos] = key;␊ |
955 | ␉␉prompt_pos++;␊ |
956 | ␉␉prompt[prompt_pos] = '\0';␊ |
957 | ␉}␊ |
958 | ␊ |
959 | ␉fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);␊ |
960 | ␊ |
961 | ␉makeRoundedCorners( gui.bootprompt.pixmap);␊ |
962 | ␊ |
963 | ␉position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );␊ |
964 | ␊ |
965 | ␉// print the boot prompt text␊ |
966 | ␉drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);␊ |
967 | ␉␊ |
968 | ␉// get the position of the end of the boot prompt text to display user input␊ |
969 | ␉position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );␊ |
970 | ␊ |
971 | ␉// calculate the position of the cursor␊ |
972 | ␉int␉offset = ( prompt_pos - ( ( gui.bootprompt.width / font_console.chars[0]->width ) - strlen(prompt_text) - 2 ) );␉␊ |
973 | ␊ |
974 | ␉if ( offset < 0)␊ |
975 | ␉␉offset = 0;␊ |
976 | ␉␊ |
977 | ␉drawStr( prompt+offset, &font_console, gui.bootprompt.pixmap, p_prompt);␊ |
978 | ␊ |
979 | ␉gui.menu.draw = false;␊ |
980 | ␉gui.bootprompt.draw = true;␊ |
981 | ␉gui.redraw = true;␊ |
982 | ␉␊ |
983 | ␉updateVRAM();␊ |
984 | ␉␊ |
985 | ␉return;␊ |
986 | }␊ |
987 | ␊ |
988 | inline␊ |
989 | void vramwrite (void *data, int width, int height)␊ |
990 | {␊ |
991 | ␉if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)␊ |
992 | ␉␉memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));␊ |
993 | ␉else␊ |
994 | ␉{␊ |
995 | ␉␉uint32_t r, g, b;␊ |
996 | ␉␉int i, j;␊ |
997 | ␉␉for (i = 0; i < VIDEO (height); i++)␊ |
998 | ␉␉␉for (j = 0; j < VIDEO (width); j++)␊ |
999 | ␉␉␉{␊ |
1000 | ␉␉␉␉b = ((uint8_t *) data)[4*i*width + 4*j];␊ |
1001 | ␉␉␉␉g = ((uint8_t *) data)[4*i*width + 4*j + 1];␊ |
1002 | ␉␉␉␉r = ((uint8_t *) data)[4*i*width + 4*j + 2];␊ |
1003 | ␉␉␉␉switch (VIDEO (depth))␊ |
1004 | ␉␉␉␉{␊ |
1005 | ␉␉␉␉␉case 32:␊ |
1006 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
1007 | ␉␉␉␉␉␉break;␊ |
1008 | ␉␉␉␉␉case 24:␊ |
1009 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)␊ |
1010 | ␉␉␉␉␉␉| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
1011 | ␉␉␉␉␉␉break;␊ |
1012 | ␉␉␉␉␉case 16:␊ |
1013 | ␉␉␉␉␉␉// Somehow 16-bit is always 15-bits really␊ |
1014 | ␉␉␉␉␉␉//␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);␊ |
1015 | ␉␉␉␉␉␉//␉␉␉␉␉␉break;␉␉␉␉␉␉␉␊ |
1016 | ␉␉␉␉␉case 15:␊ |
1017 | ␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);␊ |
1018 | ␉␉␉␉␉␉break;␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
1019 | ␉␉␉␉}␊ |
1020 | ␉␉␉}␊ |
1021 | ␉}␊ |
1022 | }␊ |
1023 | ␊ |
1024 | void updateVRAM()␊ |
1025 | {␊ |
1026 | ␉if (gui.redraw)␊ |
1027 | ␉{␊ |
1028 | ␉␉if (gui.devicelist.draw)␊ |
1029 | ␉␉␉blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );␊ |
1030 | ␊ |
1031 | ␉␉if (gui.bootprompt.draw)␊ |
1032 | ␉␉␉blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );␊ |
1033 | ␉␉␉␉␊ |
1034 | ␉␉if (gui.menu.draw)␊ |
1035 | ␉␉␉blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );␊ |
1036 | ␉␉␊ |
1037 | ␉␉if (gui.infobox.draw)␊ |
1038 | ␉␉␉blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );␊ |
1039 | ␉}␊ |
1040 | ␉␊ |
1041 | ␉vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );␊ |
1042 | ␊ |
1043 | ␉if (gui.redraw)␊ |
1044 | ␉{␊ |
1045 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
1046 | ␉␉gui.redraw = false;␊ |
1047 | ␉}␊ |
1048 | }␊ |
1049 | ␊ |
1050 | struct putc_info {␊ |
1051 | char * str;␊ |
1052 | char * last_str;␊ |
1053 | };␊ |
1054 | ␊ |
1055 | static void␊ |
1056 | sputc(int c, struct putc_info * pi)␊ |
1057 | {␊ |
1058 | if (pi->last_str)␊ |
1059 | if (pi->str == pi->last_str) {␊ |
1060 | *(pi->str) = '\0';␊ |
1061 | return;␊ |
1062 | }␊ |
1063 | *(pi->str)++ = c;␊ |
1064 | }␊ |
1065 | ␊ |
1066 | int gprintf( window_t * window, const char * fmt, ...)␊ |
1067 | {␊ |
1068 | ␉char *formattedtext;␊ |
1069 | ␊ |
1070 | ␉va_list ap;␊ |
1071 | ␉␊ |
1072 | ␉struct putc_info pi;␊ |
1073 | ␊ |
1074 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1075 | ␉␉// format the text␊ |
1076 | ␉␉va_start(ap, fmt);␊ |
1077 | ␉␉pi.str = formattedtext;␊ |
1078 | ␉␉pi.last_str = 0;␊ |
1079 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1080 | ␉␉*pi.str = '\0';␊ |
1081 | ␉␉va_end(ap);␊ |
1082 | ␉␉␊ |
1083 | ␉␉position_t␉origin, cursor, bounds;␊ |
1084 | ␊ |
1085 | ␉␉int i;␊ |
1086 | ␉␉int character;␊ |
1087 | ␊ |
1088 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1089 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1090 | ␉␉␊ |
1091 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1092 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1093 | ␉␉␊ |
1094 | ␉␉cursor = origin;␊ |
1095 | ␉␉␉␊ |
1096 | ␉␉font_t *font = &font_console;␊ |
1097 | ␉␉␉␊ |
1098 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1099 | ␉␉{␊ |
1100 | ␉␉␉character = formattedtext[i];␊ |
1101 | ␉␉␉␊ |
1102 | ␉␉␉character -= 32;␊ |
1103 | ␉␉␉␉␊ |
1104 | ␉␉␉// newline ?␊ |
1105 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1106 | ␉␉␉{␊ |
1107 | ␉␉␉␉cursor.x = window->hborder;␊ |
1108 | ␉␉␉␉cursor.y += font->height;␊ |
1109 | ␊ |
1110 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1111 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1112 | ␊ |
1113 | ␉␉␉␉continue;␊ |
1114 | ␉␉␉}␊ |
1115 | ␉␉␉␉␊ |
1116 | ␉␉␉// tab ?␊ |
1117 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1118 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1119 | ␉␉␉␊ |
1120 | ␉␉␉// draw the character␊ |
1121 | ␉␉␉if( font->chars[character])␊ |
1122 | ␉␉␉␉blend(font->chars[character], window->pixmap, cursor);␊ |
1123 | ␊ |
1124 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1125 | ␊ |
1126 | ␉␉␉// check x pos and do newline␊ |
1127 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1128 | ␉␉␉{␊ |
1129 | ␉␉␉␉cursor.x = origin.x;␊ |
1130 | ␉␉␉␉cursor.y += font->height;␊ |
1131 | ␉␉␉}␊ |
1132 | ␉␉␉␊ |
1133 | ␉␉␉// check y pos and reset to origin.y␊ |
1134 | ␉␉␉if ( cursor.y > bounds.y )␊ |
1135 | ␉␉␉␉cursor.y = origin.y;␊ |
1136 | ␉␉}␊ |
1137 | ␊ |
1138 | ␉␉// update cursor postition␊ |
1139 | ␉␉window->cursor = cursor;␊ |
1140 | ␉␉␊ |
1141 | ␉␉free(formattedtext);␊ |
1142 | ␉␉␊ |
1143 | ␉␉return 0;␊ |
1144 | ␊ |
1145 | ␉}␊ |
1146 | ␉return 1;␊ |
1147 | }␊ |
1148 | ␊ |
1149 | int dprintf( window_t * window, const char * fmt, ...)␊ |
1150 | {␊ |
1151 | ␉char *formattedtext;␊ |
1152 | ␉␊ |
1153 | ␉va_list ap;␊ |
1154 | ␉␊ |
1155 | ␉//window = &gui.debug;␊ |
1156 | ␉␊ |
1157 | ␉struct putc_info pi;␊ |
1158 | ␉␊ |
1159 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1160 | ␉␉// format the text␊ |
1161 | ␉␉va_start(ap, fmt);␊ |
1162 | ␉␉pi.str = formattedtext;␊ |
1163 | ␉␉pi.last_str = 0;␊ |
1164 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1165 | ␉␉*pi.str = '\0';␊ |
1166 | ␉␉va_end(ap);␊ |
1167 | ␉␉␊ |
1168 | ␉␉position_t␉origin, cursor, bounds;␊ |
1169 | ␉␉␊ |
1170 | ␉␉int i;␊ |
1171 | ␉␉int character;␊ |
1172 | ␉␉␊ |
1173 | ␉␉origin.x = MAX( gui.debug.cursor.x, window->hborder );␊ |
1174 | ␉␉origin.y = MAX( gui.debug.cursor.y, window->vborder );␊ |
1175 | ␉␉␊ |
1176 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1177 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1178 | ␉␉␊ |
1179 | ␉␉cursor = origin;␊ |
1180 | ␉␉␊ |
1181 | ␉␉font_t *font = &font_console;␊ |
1182 | ␉␉␊ |
1183 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1184 | ␉␉{␊ |
1185 | ␉␉␉character = formattedtext[i];␊ |
1186 | ␉␉␉␊ |
1187 | ␉␉␉character -= 32;␊ |
1188 | ␉␉␉␊ |
1189 | ␉␉␉// newline ?␊ |
1190 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1191 | ␉␉␉{␊ |
1192 | ␉␉␉␉cursor.x = window->hborder;␊ |
1193 | ␉␉␉␉cursor.y += font->height;␊ |
1194 | ␉␉␉␉␊ |
1195 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1196 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1197 | ␉␉␉␉␊ |
1198 | ␉␉␉␉continue;␊ |
1199 | ␉␉␉}␊ |
1200 | ␉␉␉␊ |
1201 | ␉␉␉// tab ?␊ |
1202 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1203 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1204 | ␉␉␉␊ |
1205 | ␉␉␉// draw the character␊ |
1206 | ␉␉␉if( font->chars[character])␊ |
1207 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1208 | ␊ |
1209 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1210 | ␉␉␉␊ |
1211 | ␉␉␉// check x pos and do newline␊ |
1212 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1213 | ␉␉␉{␊ |
1214 | ␉␉␉␉cursor.x = origin.x;␊ |
1215 | ␉␉␉␉cursor.y += font->height;␊ |
1216 | ␉␉␉}␊ |
1217 | ␉␉␉␊ |
1218 | ␉␉␉// check y pos and reset to origin.y␊ |
1219 | ␉␉␉if ( cursor.y > bounds.y )␊ |
1220 | ␉␉␉␉cursor.y = origin.y;␊ |
1221 | ␉␉}␊ |
1222 | ␉␉␊ |
1223 | ␉␉// update cursor postition␊ |
1224 | ␉␉gui.debug.cursor = cursor;␊ |
1225 | ␉␉␊ |
1226 | ␉␉free(formattedtext);␊ |
1227 | ␉␉␊ |
1228 | ␉␉return 0;␊ |
1229 | ␉␉␊ |
1230 | ␉}␊ |
1231 | ␉return 1;␊ |
1232 | }␊ |
1233 | ␊ |
1234 | int vprf(const char * fmt, va_list ap)␊ |
1235 | {␊ |
1236 | ␉int i;␊ |
1237 | ␉int character;␊ |
1238 | ␊ |
1239 | ␉char *formattedtext;␊ |
1240 | ␉window_t *window = &gui.screen;␊ |
1241 | ␉struct putc_info pi;␊ |
1242 | ␉␊ |
1243 | ␉position_t␉origin, cursor, bounds;␊ |
1244 | ␉font_t *font = &font_console;␊ |
1245 | ␉␊ |
1246 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1247 | ␉␉// format the text␊ |
1248 | ␉␉pi.str = formattedtext;␊ |
1249 | ␉␉pi.last_str = 0;␊ |
1250 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1251 | ␉␉*pi.str = '\0';␊ |
1252 | ␉␉␊ |
1253 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1254 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1255 | ␉␉bounds.x = ( window->width - ( window->hborder * 2 ) );␊ |
1256 | ␉␉bounds.y = ( window->height - ( window->vborder * 2 ) );␊ |
1257 | ␉␉cursor = origin;␊ |
1258 | ␉␉␉␊ |
1259 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1260 | ␉␉{␊ |
1261 | ␉␉␉character = formattedtext[i];␊ |
1262 | ␉␉␉character -= 32;␊ |
1263 | ␉␉␉␊ |
1264 | ␉␉␉// newline ?␊ |
1265 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1266 | ␉␉␉{␊ |
1267 | ␉␉␉␉cursor.x = window->hborder;␊ |
1268 | ␉␉␉␉cursor.y += font->height;␊ |
1269 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1270 | ␉␉␉␉{␊ |
1271 | ␉␉␉␉␉gui.redraw = true;␊ |
1272 | ␉␉␉␉␉updateVRAM();␊ |
1273 | ␉␉␉␉␉cursor.y = window->vborder;␊ |
1274 | ␉␉␉␉}␊ |
1275 | ␉␉␉␉window->cursor.y = cursor.y;␊ |
1276 | ␉␉␉␉continue;␊ |
1277 | ␉␉␉}␊ |
1278 | ␊ |
1279 | ␉␉␉// tab ?␊ |
1280 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1281 | ␉␉␉{␊ |
1282 | ␉␉␉␉cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );␊ |
1283 | ␉␉␉␉continue;␊ |
1284 | ␉␉␉}␊ |
1285 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1286 | ␉␉␉␊ |
1287 | ␉␉␉// check x pos and do newline␊ |
1288 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1289 | ␉␉␉{␊ |
1290 | ␉␉␉␉cursor.x = origin.x;␊ |
1291 | ␉␉␉␉cursor.y += font->height;␊ |
1292 | ␉␉␉}␊ |
1293 | ␉␉␉␉␊ |
1294 | ␉␉␉// check y pos and reset to origin.y␊ |
1295 | ␉␉␉if ( cursor.y > ( bounds.y + font->chars[0]->height) )␊ |
1296 | ␉␉␉{␊ |
1297 | ␉␉␉␉gui.redraw = true;␊ |
1298 | ␉␉␉␉updateVRAM();␊ |
1299 | ␉␉␉␉cursor.y = window->vborder;␊ |
1300 | ␉␉␉}␊ |
1301 | ␉␉␉// draw the character␊ |
1302 | ␉␉␉if( font->chars[character])␊ |
1303 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1304 | ␉␉}␊ |
1305 | ␉␉// save cursor postition␊ |
1306 | ␉␉window->cursor.x = cursor.x;␊ |
1307 | ␉␉updateVRAM();␊ |
1308 | ␉␉free(formattedtext);␊ |
1309 | ␉␉return 0;␊ |
1310 | ␉}␊ |
1311 | ␉return 1;␊ |
1312 | }␊ |
1313 | ␊ |
1314 | void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1315 | {␊ |
1316 | ␉int i=0;␊ |
1317 | ␉int y=0; // we need this to support multilines '\n'␊ |
1318 | ␉int x=0;␊ |
1319 | ␉␊ |
1320 | ␉for(i=0;i<strlen(ch);i++)␊ |
1321 | ␉{␊ |
1322 | ␉␉int cha=(int)ch[i];␊ |
1323 | ␉␉␊ |
1324 | ␉␉cha-=32;␊ |
1325 | ␉␉␊ |
1326 | ␉␉// newline ?␊ |
1327 | ␉␉if( ch[i] == '\n' )␊ |
1328 | ␉␉{␊ |
1329 | ␉␉␉x = 0;␊ |
1330 | ␉␉␉y += font->height;␊ |
1331 | ␉␉␉continue;␊ |
1332 | ␉␉}␊ |
1333 | ␉␉␊ |
1334 | ␉␉// tab ?␊ |
1335 | ␉␉if( ch[i] == '\t' )␊ |
1336 | ␉␉␉x+=(font->chars[0]->width*5);␊ |
1337 | ␉␉␊ |
1338 | ␉␉if(font->chars[cha])␊ |
1339 | ␉␉␉blend(font->chars[cha], blendInto, pos(p.x+x, p.y+y));␊ |
1340 | ␉␉␊ |
1341 | ␉␉x += font->chars[cha]->width;␊ |
1342 | ␉}␊ |
1343 | }␊ |
1344 | ␊ |
1345 | void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1346 | {␊ |
1347 | ␉int i = 0;␊ |
1348 | ␉int width = 0;␊ |
1349 | ␊ |
1350 | ␉// calculate the width in pixels␊ |
1351 | ␉for(i=0;i<strlen(text);i++)␊ |
1352 | ␉␉width += font->chars[text[i]-32]->width;␊ |
1353 | ␊ |
1354 | ␉p.x = ( p.x - ( width / 2 ) );␊ |
1355 | ␉p.y = ( p.y - ( font->height / 2 ) ); ␊ |
1356 | ␉␊ |
1357 | ␉if ( p.x == -6 )␊ |
1358 | ␉{␊ |
1359 | ␉␉p.x = 0;␊ |
1360 | ␉}␊ |
1361 | ␉␊ |
1362 | ␉for(i=0;i<strlen(text);i++)␊ |
1363 | ␉{␊ |
1364 | ␉␉int cha=(int)text[i];␊ |
1365 | ␉␉␊ |
1366 | ␉␉cha-=32;␊ |
1367 | ␊ |
1368 | ␉␉if(font->chars[cha])␊ |
1369 | ␉␉{␊ |
1370 | ␉␉␉blend(font->chars[cha], blendInto, p);␊ |
1371 | ␉␉␉p.x += font->chars[cha]->width;␊ |
1372 | ␉␉}␊ |
1373 | ␉}␊ |
1374 | ␉␊ |
1375 | }␊ |
1376 | ␊ |
1377 | int initFont(font_t *font, image_t *data)␊ |
1378 | {␊ |
1379 | ␉unsigned int x = 0, y = 0, x2 = 0, x3 = 0;␊ |
1380 | ␉␊ |
1381 | ␉int start = 0, end = 0, count = 0, space = 0;␊ |
1382 | ␉␊ |
1383 | ␉bool monospaced = false;␊ |
1384 | ␉␊ |
1385 | ␉font->height = data->image->height;␉␊ |
1386 | ␊ |
1387 | ␉for( x = 0; x < data->image->width; x++)␊ |
1388 | ␉{␊ |
1389 | ␉␉start = end;␊ |
1390 | ␉␉␉␉␊ |
1391 | ␉␉// if the pixel is red we've reached the end of the char␊ |
1392 | ␉␉if( pixel( data->image, x, 0 ).value == 0xFFFF0000)␊ |
1393 | ␉␉{␊ |
1394 | ␉␉␉end = x + 1;␊ |
1395 | ␊ |
1396 | ␉␉␉if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )␊ |
1397 | ␉␉␉{␊ |
1398 | ␉␉␉␉font->chars[count]->width = ( end - start) - 1;␊ |
1399 | ␉␉␉␉font->chars[count]->height = font->height;␊ |
1400 | ␉␉␉␊ |
1401 | ␉␉␉␉if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )␊ |
1402 | ␉␉␉␉{␊ |
1403 | ␉␉␉␉␉space += ( font->chars[count]->width * data->image->height * 4 );␊ |
1404 | ␉␉␉␉␉// we skip the first line because there are just the red pixels for the char width␊ |
1405 | ␉␉␉␉␉for( y = 1; y< (font->height); y++)␊ |
1406 | ␉␉␉␉␉{␊ |
1407 | ␉␉␉␉␉␉for( x2 = start, x3 = 0; x2 < end; x2++, x3++)␊ |
1408 | ␉␉␉␉␉␉{␊ |
1409 | ␉␉␉␉␉␉␉pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );␊ |
1410 | ␉␉␉␉␉␉}␉␊ |
1411 | ␉␉␉␉␉}␊ |
1412 | ␉␉␉␉␉␊ |
1413 | ␉␉␉␉␉// check if font is monospaced␊ |
1414 | ␉␉␉␉␉if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )␊ |
1415 | ␉␉␉␉␉␉monospaced = true;␊ |
1416 | ␉␉␉␉␉␉␊ |
1417 | ␉␉␉␉␉font->width = font->chars[count]->width;␊ |
1418 | ␉␉␉␉␉␊ |
1419 | ␉␉␉␉␉count++;␊ |
1420 | ␉␉␉␉}␊ |
1421 | ␉␉␉}␊ |
1422 | ␉␉}␊ |
1423 | ␉}␊ |
1424 | ␊ |
1425 | ␉if(monospaced)␊ |
1426 | ␉␉font->width = 0;␊ |
1427 | ␊ |
1428 | ␉return 0;␊ |
1429 | }␊ |
1430 | ␊ |
1431 | void colorFont(font_t *font, uint32_t color)␊ |
1432 | {␊ |
1433 | ␉if( !color )␊ |
1434 | ␉␉return;␊ |
1435 | ␉␊ |
1436 | ␉int x, y, width, height;␊ |
1437 | ␉int count = 0;␊ |
1438 | ␉pixel_t *buff;␊ |
1439 | ␉␊ |
1440 | ␉while( font->chars[count++] )␊ |
1441 | ␉{␊ |
1442 | ␉␉width = font->chars[count-1]->width;␊ |
1443 | ␉␉height = font->chars[count-1]->height;␊ |
1444 | ␉␉for( y = 0; y < height; y++ )␊ |
1445 | ␉␉{␊ |
1446 | ␉␉␉for( x = 0; x < width; x++ )␊ |
1447 | ␉␉␉{␊ |
1448 | ␉␉␉␉buff = &(pixel( font->chars[count-1], x, y ));␊ |
1449 | ␉␉␉␉if( buff->ch.a )␊ |
1450 | ␉␉␉␉{␊ |
1451 | ␉␉␉␉␉buff->ch.r = (color & 0xFFFF0000) >> 16;␊ |
1452 | ␉␉␉␉␉buff->ch.g = (color & 0xFF00FF00) >> 8;␊ |
1453 | ␉␉␉␉␉buff->ch.b = (color & 0xFF0000FF);␊ |
1454 | ␉␉␉␉}␊ |
1455 | ␉␉␉}␊ |
1456 | ␉␉}␊ |
1457 | ␉}␊ |
1458 | }␊ |
1459 | ␊ |
1460 | void makeRoundedCorners(pixmap_t *p)␊ |
1461 | {␊ |
1462 | ␉int x,y;␊ |
1463 | ␉int width=p->width-1;␊ |
1464 | ␉int height=p->height-1;␊ |
1465 | ␉␊ |
1466 | ␉// 10px rounded corner alpha values␊ |
1467 | ␉uint8_t roundedCorner[10][10] =␊ |
1468 | ␉{␊ |
1469 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},␊ |
1470 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1471 | ␉␉{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1472 | ␉␉{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1473 | ␉␉{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1474 | ␉␉{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1475 | ␉␉{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1476 | ␉␉{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1477 | ␉␉{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1478 | ␉␉{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}␊ |
1479 | ␉};␊ |
1480 | ␉␊ |
1481 | ␉uint8_t alpha=0;␊ |
1482 | ␉␊ |
1483 | ␉for( y=0; y<10; y++)␊ |
1484 | ␉{␊ |
1485 | ␉␉for( x=0; x<10; x++)␊ |
1486 | ␉␉{␊ |
1487 | ␉␉␉// skip if the pixel should be visible␊ |
1488 | ␉␉␉if(roundedCorner[y][x] != 0xFF) ␊ |
1489 | ␉␉␉{ ␊ |
1490 | ␉␉␉␉alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );␊ |
1491 | ␉␉␉␉// Upper left corner␊ |
1492 | ␉␉␉␉pixel(p, x, y).ch.a = alpha;␊ |
1493 | ␊ |
1494 | ␉␉␉␉// upper right corner␊ |
1495 | ␉␉␉␉pixel(p, width-x,y).ch.a = alpha;␊ |
1496 | ␊ |
1497 | ␉␉␉␉// lower left corner␊ |
1498 | ␉␉␉␉pixel(p, x, height-y).ch.a = alpha;␊ |
1499 | ␊ |
1500 | ␉␉␉␉// lower right corner␊ |
1501 | ␉␉␉␉pixel(p, width-x, height-y).ch.a = alpha;␊ |
1502 | ␉␉␉}␊ |
1503 | ␉␉}␊ |
1504 | ␉}␊ |
1505 | }␊ |
1506 | ␊ |
1507 | void showInfoBox(char *title, char *text)␊ |
1508 | {␊ |
1509 | ␉int i, key, lines, visiblelines;␊ |
1510 | ␊ |
1511 | ␉int currentline=0;␊ |
1512 | ␉int cnt=0;␊ |
1513 | ␉int offset=0;␊ |
1514 | ␉␊ |
1515 | ␉if( !title || !text )␊ |
1516 | ␉␉return;␊ |
1517 | ␉␊ |
1518 | ␉position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );␊ |
1519 | ␊ |
1520 | ␉// calculate number of lines in the title␊ |
1521 | ␉for ( i = 0, lines = 1; i<strlen(title); i++ )␊ |
1522 | ␉␉if( title[i] == '\n')␊ |
1523 | ␉␉␉lines++;␊ |
1524 | ␉␊ |
1525 | ␉// y position of text is lines in title * height of font␊ |
1526 | ␉position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));␊ |
1527 | ␉␊ |
1528 | ␉// calculate number of lines in the text␊ |
1529 | ␉for ( i=0, lines = 1; i<strlen(text); i++ )␊ |
1530 | ␉␉if( text[i] == '\n')␊ |
1531 | ␉␉␉lines++;␊ |
1532 | ␉␊ |
1533 | ␉// if text ends with \n strip off␊ |
1534 | ␉if( text[i] == '\n' || text[i] == '\0')␊ |
1535 | ␉␉lines--;␊ |
1536 | ␉␊ |
1537 | ␉visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;␊ |
1538 | ␉␊ |
1539 | ␉// lets display the text and allow scroll thru using up down / arrows␊ |
1540 | ␉while(1)␊ |
1541 | ␉{␊ |
1542 | ␉␉// move to current line in text␊ |
1543 | ␉␉for( offset = 0, i = 0; offset < strlen(text); offset++ )␊ |
1544 | ␉␉{␊ |
1545 | ␉␉␉if( currentline == i)␊ |
1546 | ␉␉␉␉break;␊ |
1547 | ␉␉␉if( text[offset] =='\n')␊ |
1548 | ␉␉␉␉i++;␊ |
1549 | ␉␉}␊ |
1550 | ␊ |
1551 | ␉␉// find last visible line in text and place \0␊ |
1552 | ␉␉for( i = offset, cnt = 0; i < strlen(text); i++)␊ |
1553 | ␉␉{␊ |
1554 | ␉␉␉if(text[i]=='\n')␊ |
1555 | ␉␉␉␉cnt++;␊ |
1556 | ␉␉␉if ( cnt == visiblelines )␊ |
1557 | ␉␉␉{␊ |
1558 | ␉␉␉␉text[i]='\0';␊ |
1559 | ␉␉␉␉break;␊ |
1560 | ␉␉␉}␊ |
1561 | ␉␉}␊ |
1562 | ␉␉␉␉␊ |
1563 | ␉␉fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);␊ |
1564 | ␊ |
1565 | ␉␉makeRoundedCorners( gui.infobox.pixmap);␊ |
1566 | ␉␉␉␊ |
1567 | ␉␉// print the title if present␊ |
1568 | ␉␉if( title )␊ |
1569 | ␉␉␉drawStr(title, &font_console, gui.infobox.pixmap, pos_title);␊ |
1570 | ␊ |
1571 | ␉␉// print the text␊ |
1572 | ␉␉drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);␊ |
1573 | ␊ |
1574 | ␉␉// restore \n in text␊ |
1575 | ␉␉if ( cnt == visiblelines )␊ |
1576 | ␉␉␉text[i] = '\n';␊ |
1577 | ␉␉␊ |
1578 | ␉␉position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );␊ |
1579 | ␉␉␊ |
1580 | ␉␉// draw prev indicator␊ |
1581 | ␉␉if(offset)␊ |
1582 | ␉␉{␊ |
1583 | ␉␉␉blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));␊ |
1584 | ␉␉}␊ |
1585 | ␉␉␊ |
1586 | ␉␉// draw next indicator␊ |
1587 | ␉␉if( lines > ( currentline + visiblelines ) )␊ |
1588 | ␉␉{␊ |
1589 | ␉␉␉pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );␊ |
1590 | ␉␉␉blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );␊ |
1591 | ␉␉}␊ |
1592 | ␊ |
1593 | ␉␉gui.bootprompt.draw = false;␊ |
1594 | ␉␉gui.infobox.draw = true;␊ |
1595 | ␉␉gui.redraw = true;␊ |
1596 | ␉␉␊ |
1597 | ␉␉updateVRAM();␊ |
1598 | ␉␉␊ |
1599 | ␉␉key = getc();␊ |
1600 | ␉␉␉␊ |
1601 | ␉␉if( key == kUpArrowkey )␊ |
1602 | ␉␉␉if( currentline > 0 )␊ |
1603 | ␉␉␉␉currentline--;␊ |
1604 | ␊ |
1605 | ␉␉if( key == kDownArrowkey )␊ |
1606 | ␉␉␉if( lines > ( currentline + visiblelines ) )␊ |
1607 | ␉␉␉␉currentline++;␊ |
1608 | ␊ |
1609 | ␉␉if( key == kEscapeKey || key == 'q' || key == 'Q')␊ |
1610 | ␉␉{␊ |
1611 | ␉␉␉gui.infobox.draw = false;␊ |
1612 | ␉␉␉gui.redraw = true;␊ |
1613 | ␉␉␉updateVRAM();␊ |
1614 | ␉␉␉break;␊ |
1615 | ␉␉}␊ |
1616 | ␉}␊ |
1617 | }␊ |
1618 | ␊ |
1619 | void animateProgressBar()␊ |
1620 | {␊ |
1621 | ␉int y;␊ |
1622 | ␉␊ |
1623 | ␉if( time18() > lasttime)␊ |
1624 | ␉{␊ |
1625 | ␉␉lasttime = time18();␊ |
1626 | ␊ |
1627 | ␉␉pixmap_t *buffBar = images[iProgressBar].image;␊ |
1628 | ␊ |
1629 | ␉␉uint32_t buff = buffBar->pixels[0].value;␊ |
1630 | ␉␊ |
1631 | ␉␉memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );␊ |
1632 | ␊ |
1633 | ␉␉for( y = buffBar->height - 1; y > 0; y--)␊ |
1634 | ␉␉␉pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);␊ |
1635 | ␊ |
1636 | ␉␉pixel(buffBar, buffBar->width-1, 0).value = buff;␊ |
1637 | ␉}␊ |
1638 | }␊ |
1639 | ␊ |
1640 | void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)␊ |
1641 | {␊ |
1642 | ␉if(progress>100)␊ |
1643 | ␉␉return;␊ |
1644 | ␉␊ |
1645 | ␉p.x = ( p.x - ( width / 2 ) );␊ |
1646 | ␊ |
1647 | ␉int todraw = (width * progress) / 100;␊ |
1648 | ␊ |
1649 | ␉pixmap_t *buff = images[iProgressBar].image;␊ |
1650 | ␉pixmap_t *buffBG = images[iProgressBarBackground].image;␊ |
1651 | ␉if(!buff || !buffBG)␊ |
1652 | ␉␉return;␊ |
1653 | ␉␊ |
1654 | ␉pixmap_t progressbar;␊ |
1655 | ␉progressbar.pixels=malloc(width * 4 * buff->height);␊ |
1656 | ␉if(!progressbar.pixels)␊ |
1657 | ␉␉return; ␊ |
1658 | ␉␊ |
1659 | ␉progressbar.width = width;␊ |
1660 | ␉progressbar.height = buff->height;␊ |
1661 | ␊ |
1662 | ␉int x=0,x2=0,y=0;␊ |
1663 | ␉␊ |
1664 | ␉for(y=0; y<buff->height; y++)␊ |
1665 | ␉{␊ |
1666 | ␉␉for(x=0; x<todraw; x++, x2++)␊ |
1667 | ␉␉{␊ |
1668 | ␉␉␉if(x2 == (buff->width-1)) x2=0;␊ |
1669 | ␉␉␉pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;␊ |
1670 | ␉␉}␊ |
1671 | ␉␉x2=0;␊ |
1672 | ␉}␊ |
1673 | ␊ |
1674 | ␉for(y=0; y<buff->height; y++)␊ |
1675 | ␉{␊ |
1676 | ␉␉for(x=todraw, x2 = 0; x < width - 1; x++, x2++)␊ |
1677 | ␉␉{␊ |
1678 | ␉␉␉if(x2 == (buffBG->width -2 )) x2 = 0;␊ |
1679 | ␉␉␉␉pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;␊ |
1680 | ␉␉}␊ |
1681 | ␉␉if(progress < 100)␊ |
1682 | ␉␉␉pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
1683 | ␉␉if(progress == 0)␊ |
1684 | ␉␉␉pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
1685 | ␉␉x2=0;␊ |
1686 | ␉}␊ |
1687 | ␉ ␊ |
1688 | ␉blend(&progressbar, blendInto, p);␊ |
1689 | ␉animateProgressBar();␊ |
1690 | ␉free(progressbar.pixels);␊ |
1691 | }␊ |
1692 | ␊ |
1693 | void drawInfoMenuItems()␊ |
1694 | {␊ |
1695 | ␉int i,n;␊ |
1696 | ␉␊ |
1697 | ␉position_t position;␊ |
1698 | ␉␊ |
1699 | ␉pixmap_t *selection = images[iMenuSelection].image;␊ |
1700 | ␉␊ |
1701 | ␉pixmap_t *pbuff;␊ |
1702 | ␊ |
1703 | ␉fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);␊ |
1704 | ␊ |
1705 | ␉makeRoundedCorners(gui.menu.pixmap);␊ |
1706 | ␉␊ |
1707 | ␉uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;␊ |
1708 | ␊ |
1709 | ␉position = pos(0,0);␊ |
1710 | ␉␊ |
1711 | ␉for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)␊ |
1712 | ␉{␊ |
1713 | ␉␉if (i == infoMenuSelection)␊ |
1714 | ␉␉␉blend(selection, gui.menu.pixmap, position);␊ |
1715 | ␊ |
1716 | ␉␉pbuff = images[n].image;␊ |
1717 | ␉␉if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)␊ |
1718 | ␉␉␉blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap, ␊ |
1719 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
1720 | ␉␉else␊ |
1721 | ␉␉␉blend( pbuff, gui.menu.pixmap, ␊ |
1722 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
1723 | ␊ |
1724 | ␉␉drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap, ␊ |
1725 | ␉␉␉pos(position.x + (pbuff->width + gui.menu.hborder), ␊ |
1726 | ␉␉␉␉position.y + ((selection->height - font_console.height) / 2)));␊ |
1727 | ␉␉position.y += images[iMenuSelection].image->height;␊ |
1728 | ␉␊ |
1729 | ␉}␊ |
1730 | ␉␊ |
1731 | ␉gui.redraw = true;␊ |
1732 | }␊ |
1733 | ␊ |
1734 | int drawInfoMenu()␊ |
1735 | {␊ |
1736 | ␉drawInfoMenuItems();␊ |
1737 | ␊ |
1738 | ␉gui.menu.draw = true;␊ |
1739 | ␊ |
1740 | ␉updateVRAM();␊ |
1741 | ␉␊ |
1742 | ␉return 1;␊ |
1743 | }␊ |
1744 | ␊ |
1745 | int updateInfoMenu(int key)␊ |
1746 | {␊ |
1747 | ␉switch (key)␊ |
1748 | ␉{␊ |
1749 | ␊ |
1750 | ␉␉case kUpArrowkey:␉// up arrow␊ |
1751 | ␉␉␉␉if (infoMenuSelection > 0)␊ |
1752 | ␉␉␉␉{␊ |
1753 | ␉␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)␊ |
1754 | ␉␉␉␉␉␉infoMenuSelection -= 4;␊ |
1755 | ␉␉␉␉␉␊ |
1756 | ␉␉␉␉␉else␊ |
1757 | ␉␉␉␉␉␉infoMenuSelection--;␊ |
1758 | ␉␉␉␉␉␉drawInfoMenuItems();␊ |
1759 | ␉␉␉␉␉␉updateVRAM();␊ |
1760 | ␉␉␉␉␉␊ |
1761 | ␉␉␉␉} else {␊ |
1762 | ␉␉␉␉␉␊ |
1763 | ␉␉␉␉␉gui.menu.draw = false;␊ |
1764 | ␉␉␉␉␉gui.redraw = true;␊ |
1765 | ␊ |
1766 | ␉␉␉␉␉updateVRAM();␊ |
1767 | ␉␉␉␉␉␊ |
1768 | ␉␉␉␉␉return CLOSE_INFO_MENU;␊ |
1769 | ␉␉␉␉}␊ |
1770 | ␉␉␉␉break;␊ |
1771 | ␊ |
1772 | ␉␉case kDownArrowkey:␉// down arrow␊ |
1773 | ␉␉␉␉if (infoMenuSelection < infoMenuItemsCount - 1)␊ |
1774 | ␉␉␉␉{␊ |
1775 | ␉␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)␊ |
1776 | ␉␉␉␉␉␉infoMenuSelection += 4;␊ |
1777 | ␉␉␉␉␉else␊ |
1778 | ␉␉␉␉␉␉infoMenuSelection++;␊ |
1779 | ␉␉␉␉␉drawInfoMenuItems();␊ |
1780 | ␉␉␉␉␉updateVRAM();␊ |
1781 | ␉␉␉␉}␊ |
1782 | ␉␉␉␉break;␊ |
1783 | ␊ |
1784 | ␉␉case kReturnKey:␊ |
1785 | ␉␉␉␉key = 0;␊ |
1786 | ␉␉␉␉if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )␊ |
1787 | ␉␉␉␉␉showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());␊ |
1788 | ␊ |
1789 | ␉␉␉␉else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )␊ |
1790 | ␉␉␉␉␉showInfoBox( getVBEInfoString(), getVBEModeInfoString() );␊ |
1791 | ␉␉␉␊ |
1792 | ␉␉␉␉else if( infoMenuSelection == MENU_SHOW_HELP )␊ |
1793 | ␉␉␉␉␉showHelp();␊ |
1794 | ␉␉␉␉␉␊ |
1795 | ␉␉␉␉else␊ |
1796 | ␉␉␉␉{␊ |
1797 | ␉␉␉␉␉int buff = infoMenuSelection;␊ |
1798 | ␉␉␉␉␉infoMenuSelection = 0;␊ |
1799 | ␉␉␉␉␉return buff;␊ |
1800 | ␉␉␉␉}␊ |
1801 | ␉␉␉␉break;␊ |
1802 | ␉␉}␊ |
1803 | ␉return DO_NOT_BOOT;␊ |
1804 | }␊ |
1805 | ␊ |
1806 | uint16_t bootImageWidth = 0; ␊ |
1807 | uint16_t bootImageHeight = 0; ␊ |
1808 | uint8_t *bootImageData = NULL; ␊ |
1809 | static bool usePngImage = true;␊ |
1810 | ␊ |
1811 | //==========================================================================␊ |
1812 | // loadBootGraphics Azi: loading "boot logo"␊ |
1813 | static void loadBootGraphics(void)␊ |
1814 | {␊ |
1815 | ␉if (bootImageData != NULL) {␊ |
1816 | ␉␉return;␊ |
1817 | ␉}␊ |
1818 | ␊ |
1819 | ␉char dirspec[256];␊ |
1820 | ␊ |
1821 | ␉if ((strlen(theme_name) + 24) > sizeof(dirspec)) {␊ |
1822 | ␉␉usePngImage = false; ␊ |
1823 | ␉␉return;␊ |
1824 | ␉}␊ |
1825 | ␉//Azi: Should this be bt(0,0)!?␊ |
1826 | ␉sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);␊ |
1827 | ␉if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {␊ |
1828 | #ifdef EMBED_THEME␊ |
1829 | ␉if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)␊ |
1830 | #endif␊ |
1831 | ␉␉usePngImage = false; ␊ |
1832 | ␉}␊ |
1833 | }␊ |
1834 | ␊ |
1835 | //==========================================================================␊ |
1836 | // drawBootGraphics Azi: drawing graphics for the boot process (after pressing Enter to boot)␊ |
1837 | void drawBootGraphics(void)␊ |
1838 | {␊ |
1839 | ␉int pos;␊ |
1840 | ␉int length, count;␊ |
1841 | ␉const char *dummyVal;␊ |
1842 | ␉int oldScreenWidth, oldScreenHeight;␊ |
1843 | ␉bool legacy_logo;␊ |
1844 | ␉uint16_t x, y; ␊ |
1845 | ␉␊ |
1846 | ␉if (getBoolForKey(kLegacyLogoKey, &legacy_logo, &bootInfo->bootConfig) && legacy_logo) {␊ |
1847 | ␉␉usePngImage = false; ␊ |
1848 | ␉} else if (bootImageData == NULL) {␊ |
1849 | ␉␉loadBootGraphics();␊ |
1850 | ␉}␊ |
1851 | ␊ |
1852 | ␉/*␊ |
1853 | ␉ * AutoResolution␊ |
1854 | ␉ */␊ |
1855 | ␉if (gAutoResolution == true)␊ |
1856 | ␉{␊ |
1857 | ␉␉// Get Resolution from Graphics Mode key␊ |
1858 | ␉␉count = getNumberArrayFromProperty(kGraphicsModeKey, screen_params, 4);␊ |
1859 | ␉␉␊ |
1860 | ␉␉// If no Graphics Mode key, get it from EDID␊ |
1861 | ␉␉if ( count < 3 )␊ |
1862 | ␉␉{␊ |
1863 | ␉␉␉getResolution(screen_params);␊ |
1864 | ␉␉}␊ |
1865 | ␉}␊ |
1866 | ␉else␊ |
1867 | ␉{␊ |
1868 | ␉␉// parse display size parameters //Azi: check this stuff!!!...␊ |
1869 | ␉␉if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0)␊ |
1870 | ␉␉{␊ |
1871 | ␉␉␉screen_params[0] = pos;␊ |
1872 | ␉␉}␊ |
1873 | ␉␉␊ |
1874 | ␉␉if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0)␊ |
1875 | ␉␉{␊ |
1876 | ␉␉␉screen_params[1] = pos;␊ |
1877 | ␉␉}␊ |
1878 | ␉}␊ |
1879 | ␊ |
1880 | ␉// Save current screen resolution.␊ |
1881 | ␉oldScreenWidth = gui.screen.width; //Azi: ... and this stuff too!!!␊ |
1882 | ␉oldScreenHeight = gui.screen.height;␊ |
1883 | ␊ |
1884 | ␉gui.screen.width = screen_params[0];␊ |
1885 | ␉gui.screen.height = screen_params[1];␊ |
1886 | ␊ |
1887 | ␉// find best matching vesa mode for our requested width & height␊ |
1888 | ␉getGraphicModeParams(screen_params);␊ |
1889 | ␉␊ |
1890 | // Set graphics mode if the booter was in text mode or the screen resolution has changed.␊ |
1891 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE␊ |
1892 | ␉␉|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )␊ |
1893 | ␉{␊ |
1894 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
1895 | ␉}␊ |
1896 | ␉␊ |
1897 | ␉if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) {␊ |
1898 | ␉␉drawCheckerBoard();␊ |
1899 | ␉} else {␊ |
1900 | ␉␉// Fill the background to 75% grey (same as BootX). ␊ |
1901 | ␉␉drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01); ␊ |
1902 | ␉}␊ |
1903 | ␉if ((bootImageData) && (usePngImage)) { ␊ |
1904 | ␉␉x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2; ␊ |
1905 | ␉␉y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2; ␊ |
1906 | ␊ |
1907 | ␉␉// Draw the image in the center of the display. ␊ |
1908 | ␉␉blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData); ␊ |
1909 | ␉} else { ␊ |
1910 | ␉␉uint8_t *appleBootPict; ␊ |
1911 | ␉␉bootImageData = NULL; ␊ |
1912 | ␉␉bootImageWidth = kAppleBootWidth; ␊ |
1913 | ␉␉bootImageHeight = kAppleBootHeight; ␊ |
1914 | ␊ |
1915 | ␉␉// Prepare the data for the default Apple boot image. ␊ |
1916 | ␉␉appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight); ␊ |
1917 | ␉␉if (appleBootPict) { ␊ |
1918 | ␉␉␉convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData); ␊ |
1919 | ␉␉␉if (bootImageData) {␉␊ |
1920 | ␉␉␉␉x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2; ␊ |
1921 | ␉␉␉␉y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2; ␊ |
1922 | ␉␉␉␉drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);␊ |
1923 | ␉␉␉␉free(bootImageData);␊ |
1924 | ␉␉␉}␊ |
1925 | ␉␉␉free(appleBootPict); ␊ |
1926 | ␉␉} ␊ |
1927 | ␉} ␊ |
1928 | }␊ |
1929 | |