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