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