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 | #include "autoresolution.h" //Azi:autoresolution␊ |
15 | ␊ |
16 | #define IMG_REQUIRED -1␊ |
17 | #define THEME_NAME_DEFAULT␉"Default"␊ |
18 | static const char *theme_name = THEME_NAME_DEFAULT;␉␊ |
19 | ␊ |
20 | #ifdef CONFIG_EMBED_THEME␊ |
21 | #include "art.h"␊ |
22 | #endif␊ |
23 | ␊ |
24 | #define LOADPNG(img, alt_img) if (loadThemeImage(#img, alt_img) != 0) { return 1; }␊ |
25 | ␊ |
26 | #define MIN(x, y) ((x) < (y) ? (x) : (y))␊ |
27 | #define MAX(x, y) ((x) > (y) ? (x) : (y))␊ |
28 | ␊ |
29 | #define VIDEO(x) (bootArgs->Video.v_ ## x)␊ |
30 | ␊ |
31 | #define vram VIDEO(baseAddr)␊ |
32 | ␊ |
33 | int lasttime = 0; // we need this for animating maybe␊ |
34 | ␊ |
35 | extern int gDeviceCount;␊ |
36 | ␊ |
37 | ␊ |
38 | /*␊ |
39 | * ATTENTION: the enum and the following array images[] MUST match !!!␊ |
40 | */␊ |
41 | enum {␊ |
42 | iBackground = 0,␊ |
43 | iLogo,␊ |
44 | ␊ |
45 | iDeviceGeneric,␊ |
46 | iDeviceGeneric_o,␊ |
47 | iDeviceHFS,␊ |
48 | iDeviceHFS_o,␊ |
49 | iDeviceHFSRAID,␊ |
50 | iDeviceHFSRAID_o,␊ |
51 | iDeviceEXT3,␊ |
52 | iDeviceEXT3_o,␊ |
53 | iDeviceFAT,␊ |
54 | iDeviceFAT_o,␊ |
55 | iDeviceFAT16,␊ |
56 | iDeviceFAT16_o,␊ |
57 | iDeviceFAT32,␊ |
58 | iDeviceFAT32_o,␊ |
59 | iDeviceNTFS,␊ |
60 | iDeviceNTFS_o,␊ |
61 | iDeviceCDROM,␊ |
62 | iDeviceCDROM_o,␊ |
63 | ␊ |
64 | iSelection,␊ |
65 | iDeviceScrollPrev,␊ |
66 | iDeviceScrollNext,␊ |
67 | ␊ |
68 | iMenuBoot,␊ |
69 | iMenuVerbose,␊ |
70 | iMenuIgnoreCaches,␊ |
71 | iMenuSingleUser,␊ |
72 | iMenuMemoryInfo,␊ |
73 | iMenuVideoInfo,␊ |
74 | iMenuHelp,␊ |
75 | iMenuVerboseDisabled,␊ |
76 | iMenuIgnoreCachesDisabled,␊ |
77 | iMenuSingleUserDisabled,␊ |
78 | iMenuSelection,␊ |
79 | ␊ |
80 | iProgressBar,␊ |
81 | iProgressBarBackground,␊ |
82 | ␊ |
83 | iTextScrollPrev,␊ |
84 | iTextScrollNext,␊ |
85 | ␊ |
86 | iFontConsole,␊ |
87 | iFontSmall,␊ |
88 | };␊ |
89 | ␊ |
90 | image_t images[] = {␊ |
91 | {.name = "background", .image = NULL},␊ |
92 | {.name = "logo", .image = NULL},␊ |
93 | ␊ |
94 | {.name = "device_generic", .image = NULL},␊ |
95 | {.name = "device_generic_o", .image = NULL},␊ |
96 | {.name = "device_hfsplus", .image = NULL},␊ |
97 | {.name = "device_hfsplus_o", .image = NULL},␊ |
98 | {.name = "device_hfsraid", .image = NULL},␊ |
99 | {.name = "device_hfsraid_o", .image = NULL},␊ |
100 | {.name = "device_ext3", .image = NULL},␊ |
101 | {.name = "device_ext3_o", .image = NULL},␊ |
102 | {.name = "device_fat", .image = NULL},␊ |
103 | {.name = "device_fat_o", .image = NULL},␊ |
104 | {.name = "device_fat16", .image = NULL},␊ |
105 | {.name = "device_fat16_o", .image = NULL},␊ |
106 | {.name = "device_fat32", .image = NULL},␊ |
107 | {.name = "device_fat32_o", .image = NULL},␊ |
108 | {.name = "device_ntfs", .image = NULL},␊ |
109 | {.name = "device_ntfs_o", .image = NULL},␊ |
110 | {.name = "device_cdrom", .image = NULL},␊ |
111 | {.name = "device_cdrom_o", .image = NULL},␊ |
112 | ␊ |
113 | {.name = "device_selection", .image = NULL},␊ |
114 | {.name = "device_scroll_prev", .image = NULL},␊ |
115 | {.name = "device_scroll_next", .image = NULL},␊ |
116 | ␊ |
117 | {.name = "menu_boot", .image = NULL},␊ |
118 | {.name = "menu_verbose", .image = NULL},␊ |
119 | {.name = "menu_ignore_caches", .image = NULL},␊ |
120 | {.name = "menu_single_user", .image = NULL},␊ |
121 | {.name = "menu_memory_info", .image = NULL},␊ |
122 | {.name = "menu_video_info", .image = NULL},␊ |
123 | {.name = "menu_help", .image = NULL},␊ |
124 | {.name = "menu_verbose_disabled", .image = NULL},␊ |
125 | {.name = "menu_ignore_caches_disabled", .image = NULL},␊ |
126 | {.name = "menu_single_user_disabled", .image = NULL},␊ |
127 | {.name = "menu_selection", .image = NULL},␊ |
128 | ␊ |
129 | {.name = "progress_bar", .image = NULL},␊ |
130 | {.name = "progress_bar_background", .image = NULL},␊ |
131 | ␊ |
132 | {.name = "text_scroll_prev", .image = NULL},␊ |
133 | {.name = "text_scroll_next", .image = NULL},␊ |
134 | ␊ |
135 | {.name = "font_console", .image = NULL},␊ |
136 | {.name = "font_small", .image = NULL},␊ |
137 | };␊ |
138 | ␊ |
139 | int imageCnt = 0;␊ |
140 | ␊ |
141 | extern int␉gDeviceCount;␊ |
142 | extern int␉selectIndex;␊ |
143 | ␊ |
144 | extern MenuItem *menuItems;␊ |
145 | ␊ |
146 | //char prompt[BOOT_STRING_LEN];␊ |
147 | extern char gBootArgs[BOOT_STRING_LEN];␊ |
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 CONFIG_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␊ |
195 | ␉// generated manualy, 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 CONFIG_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 CONFIG_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 CONFIG_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;␊ |
684 | ␉int␉len;␊ |
685 | ␉char␉dirspec[256];␊ |
686 | ␊ |
687 | ␉getValueForKey( "Theme", &theme_name, &len, &bootInfo->bootConfig );␊ |
688 | ␉if ((strlen(theme_name) + 27) > sizeof(dirspec)) {␊ |
689 | ␉␉return 1;␊ |
690 | ␉}␊ |
691 | ␉sprintf(dirspec, "/Extra/Themes/%s/theme.plist", theme_name);␊ |
692 | ␉if (loadConfigFile(dirspec, &bootInfo->themeConfig) != 0) {␊ |
693 | #ifdef CONFIG_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 | ␉//Azi:autoresolution␊ |
706 | ␉if (gAutoResolution == true)␊ |
707 | ␉{␊ |
708 | ␉␉screen_params[0] = paramsAR[0];␊ |
709 | ␉␉screen_params[1] = paramsAR[1];␊ |
710 | ␉}␊ |
711 | ␉else␊ |
712 | ␉{␊ |
713 | ␉␉// parse screen size parameters␊ |
714 | ␉␉if (getIntForKey("screen_width", &val, &bootInfo->themeConfig) && val > 0)␊ |
715 | ␉␉{␊ |
716 | ␉␉␉screen_params[0] = val;␊ |
717 | ␉␉}␊ |
718 | ␊ |
719 | ␉␉if (getIntForKey("screen_height", &val, &bootInfo->themeConfig) && val > 0)␊ |
720 | ␉␉{␊ |
721 | ␉␉␉screen_params[1] = val;␊ |
722 | ␉␉}␊ |
723 | ␉}␊ |
724 | ␊ |
725 | ␉// Initalizing GUI strucutre.␊ |
726 | ␉bzero(&gui, sizeof(gui_t));␊ |
727 | ␉␊ |
728 | ␉// find best matching vesa mode for our requested width & height␊ |
729 | ␉getGraphicModeParams(screen_params);␊ |
730 | ␊ |
731 | ␉// set our screen structure with the mode width & height␊ |
732 | ␉gui.screen.width = screen_params[0];␉␊ |
733 | ␉gui.screen.height = screen_params[1];␊ |
734 | ␉␊ |
735 | ␉PRINT("Found mode %dx%d in VESA Table\n", gui.screen.width, gui.screen.height); //Azi:autoresolution␊ |
736 | ␉␊ |
737 | ␉// load graphics otherwise fail and return␊ |
738 | ␉if (loadGraphics() == 0) {␊ |
739 | ␉␉loadThemeValues(&bootInfo->themeConfig);␊ |
740 | ␉␉colorFont(&font_small, gui.screen.font_small_color);␊ |
741 | ␉␉colorFont(&font_console, gui.screen.font_console_color);␊ |
742 | ␊ |
743 | ␉␉// create the screen & window buffers␊ |
744 | ␉␉if (createBackBuffer(&gui.screen) == 0) {␊ |
745 | ␉␉␉if (createWindowBuffer(&gui.screen) == 0) {␊ |
746 | ␉␉␉␉if (createWindowBuffer(&gui.devicelist) == 0) {␊ |
747 | ␉␉␉␉␉if (createWindowBuffer(&gui.bootprompt) == 0) {␊ |
748 | ␉␉␉␉␉␉if (createWindowBuffer(&gui.infobox) == 0) {␊ |
749 | ␉␉␉␉␉␉␉if (createWindowBuffer(&gui.menu) == 0) {␊ |
750 | #ifdef AUTORES_DEBUG␊ |
751 | ␉␉␉␉␉␉␉␉pause();␊ |
752 | #endif␊ |
753 | ␉␉␉␉␉␉␉ gui.logo.draw = true;␊ |
754 | ␉␉␉␉␉␉␉␉drawBackground();␊ |
755 | ␉␉␉␉␉␉␉␉// lets copy the screen into the back buffer␊ |
756 | ␉␉␉␉␉␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
757 | ␉␉␉␉␉␉␉␉setVideoMode( GRAPHICS_MODE, 0 );␊ |
758 | ␉␉␉␉␉␉␉␉gui.initialised = true;␊ |
759 | ␉␉␉␉␉␉␉␉return 0;␊ |
760 | ␉␉␉␉␉␉␉} else printf("createWindowBuffer(&gui.menu) Failed\n");␊ |
761 | ␉␉␉␉␉␉} else printf("createWindowBuffer(&gui.infobox) Failed\n");␊ |
762 | ␉␉␉␉␉} else printf("createWindowBuffer(&gui.bootprompt) Failed\n");␊ |
763 | ␉␉␉␉} else printf("createWindowBuffer(&gui.devicelist) Failed\n");␊ |
764 | ␉␉␉} else printf("createWindowBuffer(&gui.screen) Failed\n");␊ |
765 | ␉␉} else printf("createBackBuffer(&gui.screen) Failed\n");␊ |
766 | ␉} else printf("loadGraphics() Failed\n");␊ |
767 | //Azi: removed a #ifdef AUTORES_DEBUG from here, long time ago; was just a pause()␊ |
768 | // and if i'm not mistaken caused some problem ?!␊ |
769 | ␉return 1;␊ |
770 | }␊ |
771 | ␊ |
772 | void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected)␊ |
773 | {␊ |
774 | ␉int devicetype;␊ |
775 | ␊ |
776 | ␉if( diskIsCDROM(device) )␊ |
777 | ␉␉devicetype = iDeviceCDROM;␉␉␉␉// Use CDROM icon␊ |
778 | ␉else␊ |
779 | ␉{␉␊ |
780 | ␉␉switch (device->part_type)␊ |
781 | ␉␉{␊ |
782 | ␉␉␉case kPartitionTypeHFS:␊ |
783 | ␊ |
784 | ␉␉␉␉// Use HFS or HFSRAID icon depending on bvr flags.␊ |
785 | ␉␉␉␉devicetype = (device->flags & kBVFlagBooter) ? iDeviceHFSRAID : iDeviceHFS;␊ |
786 | ␉␉␉␉break;␊ |
787 | ␊ |
788 | ␉␉␉case kPartitionTypeHPFS:␊ |
789 | ␉␉␉␉devicetype = iDeviceNTFS;␉␉// Use HPFS / NTFS icon␊ |
790 | ␉␉␉␉break;␊ |
791 | ␊ |
792 | ␉␉␉case kPartitionTypeFAT16:␊ |
793 | ␉␉␉␉devicetype = iDeviceFAT16;␉␉// Use FAT16 icon␊ |
794 | ␉␉␉␉break;␊ |
795 | ␊ |
796 | ␉␉␉case kPartitionTypeFAT32:␊ |
797 | ␉␉␉␉devicetype = iDeviceFAT32;␉␉// Use FAT32 icon␊ |
798 | ␉␉␉␉break;␊ |
799 | ␊ |
800 | ␉␉␉case kPartitionTypeEXT3:␊ |
801 | ␉␉␉␉devicetype = iDeviceEXT3;␉␉// Use EXT2/3 icon␊ |
802 | ␉␉␉␉break;␊ |
803 | ␊ |
804 | ␉␉␉default:␊ |
805 | ␉␉␉␉devicetype = iDeviceGeneric;␉// Use Generic icon␊ |
806 | ␉␉␉␉break;␊ |
807 | ␉␉}␊ |
808 | ␉}␊ |
809 | ␉␊ |
810 | ␉// Draw the selection image and use the next (device_*_o) image for the selected item.␊ |
811 | if (isSelected)␊ |
812 | ␉{␊ |
813 | ␉␉blend(images[iSelection].image, buffer, centeredAt(images[iSelection].image, p));␊ |
814 | ␉␉devicetype++;␊ |
815 | ␉}␊ |
816 | ␊ |
817 | ␉// draw icon␊ |
818 | ␉blend( images[devicetype].image, buffer, centeredAt( images[devicetype].image, p ));␊ |
819 | ␉␊ |
820 | ␉p.y += (images[iSelection].image->height / 2) + font_console.chars[0]->height;␊ |
821 | ␉␊ |
822 | ␉// draw volume label ␊ |
823 | ␉drawStrCenteredAt( device->label, &font_small, buffer, p);␉␊ |
824 | ␊ |
825 | }␊ |
826 | ␊ |
827 | void drawDeviceList (int start, int end, int selection)␊ |
828 | {␊ |
829 | ␉int i;␊ |
830 | ␉position_t p, p_prev, p_next;␊ |
831 | ␊ |
832 | ␉//uint8_t␉maxDevices = MIN( gui.maxdevices, menucount );␊ |
833 | ␉␉␊ |
834 | ␉fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);␊ |
835 | ␊ |
836 | ␉makeRoundedCorners( gui.devicelist.pixmap);␊ |
837 | ␊ |
838 | ␉switch (gui.layout)␊ |
839 | ␉{␊ |
840 | ␊ |
841 | ␉␉case VerticalLayout:␊ |
842 | ␉␉␉p.x = (gui.devicelist.width /2);␊ |
843 | ␉␉␉p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );␊ |
844 | ␊ |
845 | ␉␉␉// place scroll indicators at top & bottom edges␊ |
846 | ␉␉␉p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );␊ |
847 | ␉␉␉p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );␊ |
848 | ␉␉␉␊ |
849 | ␉␉␉break;␊ |
850 | ␉␉␉␊ |
851 | ␉␉default:␉// use Horizontal layout as the default␊ |
852 | ␊ |
853 | ␉␉case HorizontalLayout:␊ |
854 | ␉␉␉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;␊ |
855 | ␉␉␉p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );␊ |
856 | ␊ |
857 | ␉␉␉// place scroll indicators at left & right edges␊ |
858 | ␉␉␉p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );␊ |
859 | ␉␉␉p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );␊ |
860 | ␉␉␉␊ |
861 | ␉␉␉break;␊ |
862 | ␉␉␉␊ |
863 | ␉}␊ |
864 | ␉␊ |
865 | ␉// draw visible device icons␊ |
866 | ␉for (i = 0; i < gui.maxdevices; i++)␊ |
867 | ␉{␊ |
868 | ␉␉BVRef param = menuItems[start + i].param;␊ |
869 | ␊ |
870 | bool isSelected = ((start + i) == selection) ? true : false;␊ |
871 | ␉␉if (isSelected)␊ |
872 | ␉␉{␊ |
873 | if (param->flags & kBVFlagNativeBoot)␊ |
874 | {␊ |
875 | infoMenuNativeBoot = true;␊ |
876 | }␊ |
877 | else␊ |
878 | {␊ |
879 | infoMenuNativeBoot = false;␊ |
880 | if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)␊ |
881 | infoMenuSelection = 0;␊ |
882 | }␊ |
883 | ␉␉␉ ␊ |
884 | ␉␉␉if (gui.menu.draw)␊ |
885 | ␉␉␉␉drawInfoMenuItems();␊ |
886 | #ifdef AUTORES_DEBUG //Azi: update diff␊ |
887 | #define DEBUG␊ |
888 | #endif␊ |
889 | ␉␉␉ ␊ |
890 | #ifdef DEBUG //Azi: changed from if to ifdef␊ |
891 | gui.debug.cursor = pos( 10, 100);␊ |
892 | ␉␉␉dprintf( &gui.screen, "label: %s\n", param->label );␊ |
893 | ␉␉␉dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev );␊ |
894 | ␉␉␉dprintf( &gui.screen, "type: 0x%x\n", param->type );␊ |
895 | ␉␉␉dprintf( &gui.screen, "flags: 0x%x\n", param->flags );␊ |
896 | ␉␉␉dprintf( &gui.screen, "part_no: %d\n", param->part_no );␊ |
897 | ␉␉␉dprintf( &gui.screen, "part_boff: 0x%x\n", param->part_boff );␊ |
898 | ␉␉␉dprintf( &gui.screen, "part_type: 0x%x\n", param->part_type );␊ |
899 | ␉␉␉dprintf( &gui.screen, "bps: 0x%x\n", param->bps );␊ |
900 | ␉␉␉dprintf( &gui.screen, "name: %s\n", param->name );␊ |
901 | ␉␉␉dprintf( &gui.screen, "type_name: %s\n", param->type_name );␊ |
902 | ␉␉␉dprintf( &gui.screen, "modtime: %d\n", param->modTime );␊ |
903 | ␉␉␉dprintf( &gui.screen, "width: %d\n", gui.screen.width );␊ |
904 | ␉␉␉dprintf( &gui.screen, "height: %d\n", gui.screen.height );␊ |
905 | ␉␉␉dprintf( &gui.screen, "attr: 0x%x\n", gui.screen.attr );␊ |
906 | ␉␉␉dprintf( &gui.screen, "mm: %d\n", gui.screen.mm );␊ |
907 | #endif␊ |
908 | ␊ |
909 | #ifdef AUTORES_DEBUG␊ |
910 | #undef DEBUG␊ |
911 | #endif␊ |
912 | ␉␉}␊ |
913 | ␉␉␊ |
914 | ␉␉drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);␊ |
915 | ␉␉␊ |
916 | ␉␉if (gui.layout == HorizontalLayout)␊ |
917 | ␉␉{␊ |
918 | ␉␉␉p.x += images[iSelection].image->width + gui.devicelist.iconspacing; ␊ |
919 | ␉␉}␊ |
920 | ␉␉if (gui.layout == VerticalLayout)␊ |
921 | ␉␉{␊ |
922 | ␉␉␉p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing ); ␊ |
923 | ␉␉}␊ |
924 | ␉}␊ |
925 | ␊ |
926 | ␉// draw prev indicator␊ |
927 | ␉if(start)␊ |
928 | ␉␉blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );␊ |
929 | ␊ |
930 | ␉// draw next indicator␊ |
931 | ␉if( end < gDeviceCount - 1 )␊ |
932 | ␉␉blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );␊ |
933 | ␊ |
934 | ␉gui.redraw = true;␊ |
935 | ␉␊ |
936 | ␉updateVRAM();␊ |
937 | ␉␊ |
938 | }␊ |
939 | ␊ |
940 | void clearGraphicBootPrompt()␊ |
941 | {␊ |
942 | ␉// clear text buffer␊ |
943 | ␉//prompt[0] = '\0';␊ |
944 | ␉//prompt_pos=0;␊ |
945 | ␊ |
946 | ␉␊ |
947 | ␉if(␉gui.bootprompt.draw == true )␊ |
948 | ␉{␊ |
949 | ␉␉gui.bootprompt.draw = false;␊ |
950 | ␉␉gui.redraw = true;␊ |
951 | ␉␉// this causes extra frames to be drawn␊ |
952 | ␉␉//updateVRAM();␊ |
953 | ␉}␊ |
954 | ␊ |
955 | ␉return;␊ |
956 | }␊ |
957 | ␊ |
958 | void updateGraphicBootPrompt(int key)␊ |
959 | {␊ |
960 | ␉fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);␊ |
961 | ␊ |
962 | ␉makeRoundedCorners( gui.bootprompt.pixmap);␊ |
963 | ␊ |
964 | ␉position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );␊ |
965 | ␊ |
966 | ␉// print the boot prompt text␊ |
967 | ␉drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);␊ |
968 | ␉␊ |
969 | ␉// get the position of the end of the boot prompt text to display user input␊ |
970 | ␉position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );␊ |
971 | ␊ |
972 | ␉// calculate the position of the cursor␊ |
973 | ␉int␉offset = ( strlen(gBootArgs) - ( ( gui.bootprompt.width / font_console.chars[0]->width ) - strlen(prompt_text) - 2 ) );␉␊ |
974 | ␊ |
975 | ␉if ( offset < 0)␊ |
976 | ␉␉offset = 0;␊ |
977 | ␉␊ |
978 | ␉drawStr( gBootArgs, &font_console, gui.bootprompt.pixmap, p_prompt);␊ |
979 | ␊ |
980 | ␉gui.menu.draw = false;␊ |
981 | ␉gui.bootprompt.draw = true;␊ |
982 | ␉gui.redraw = true;␊ |
983 | ␉␊ |
984 | ␉updateVRAM();␊ |
985 | ␉␊ |
986 | ␉return;␊ |
987 | }␊ |
988 | ␊ |
989 | inline␊ |
990 | void vramwrite (void *data, int width, int height)␊ |
991 | {␊ |
992 | ␉if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)␊ |
993 | ␉␉memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));␊ |
994 | ␉else␊ |
995 | ␉{␊ |
996 | ␉␉uint32_t r, g, b;␊ |
997 | ␉␉int i, j;␊ |
998 | ␉␉for (i = 0; i < VIDEO (height); i++)␊ |
999 | ␉␉␉for (j = 0; j < VIDEO (width); j++)␊ |
1000 | ␉␉␉{␊ |
1001 | ␉␉␉␉b = ((uint8_t *) data)[4*i*width + 4*j];␊ |
1002 | ␉␉␉␉g = ((uint8_t *) data)[4*i*width + 4*j + 1];␊ |
1003 | ␉␉␉␉r = ((uint8_t *) data)[4*i*width + 4*j + 2];␊ |
1004 | ␉␉␉␉switch (VIDEO (depth))␊ |
1005 | ␉␉␉␉{␊ |
1006 | ␉␉␉␉␉case 32:␊ |
1007 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
1008 | ␉␉␉␉␉␉break;␊ |
1009 | ␉␉␉␉␉case 24:␊ |
1010 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)␊ |
1011 | ␉␉␉␉␉␉| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
1012 | ␉␉␉␉␉␉break;␊ |
1013 | ␉␉␉␉␉case 16:␊ |
1014 | ␉␉␉␉␉␉// Somehow 16-bit is always 15-bits really␊ |
1015 | ␉␉␉␉␉␉//␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);␊ |
1016 | ␉␉␉␉␉␉//␉␉␉␉␉␉break;␉␉␉␉␉␉␉␊ |
1017 | ␉␉␉␉␉case 15:␊ |
1018 | ␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);␊ |
1019 | ␉␉␉␉␉␉break;␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
1020 | ␉␉␉␉}␊ |
1021 | ␉␉␉}␊ |
1022 | ␉}␊ |
1023 | }␊ |
1024 | ␊ |
1025 | void updateVRAM()␊ |
1026 | {␊ |
1027 | ␉if (gui.redraw)␊ |
1028 | ␉{␊ |
1029 | ␉␉if (gui.devicelist.draw)␊ |
1030 | ␉␉␉blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );␊ |
1031 | ␊ |
1032 | ␉␉if (gui.bootprompt.draw)␊ |
1033 | ␉␉␉blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );␊ |
1034 | ␉␉␉␉␊ |
1035 | ␉␉if (gui.menu.draw)␊ |
1036 | ␉␉␉blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );␊ |
1037 | ␉␉␊ |
1038 | ␉␉if (gui.infobox.draw)␊ |
1039 | ␉␉␉blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );␊ |
1040 | ␉}␊ |
1041 | ␉␊ |
1042 | ␉vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );␊ |
1043 | ␊ |
1044 | ␉if (gui.redraw)␊ |
1045 | ␉{␊ |
1046 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
1047 | ␉␉gui.redraw = false;␊ |
1048 | ␉}␊ |
1049 | }␊ |
1050 | ␊ |
1051 | struct putc_info //Azi: same as below␊ |
1052 | {␊ |
1053 | char * str;␊ |
1054 | char * last_str;␊ |
1055 | };␊ |
1056 | ␊ |
1057 | static int␊ |
1058 | sputc(int c, struct putc_info * pi) //Azi: exists on console.c & printf.c␊ |
1059 | {␊ |
1060 | if (pi->last_str)␊ |
1061 | if (pi->str == pi->last_str) {␊ |
1062 | *(pi->str) = '\0';␊ |
1063 | return 0;␊ |
1064 | }␊ |
1065 | *(pi->str)++ = c;␊ |
1066 | return c;␊ |
1067 | }␊ |
1068 | ␊ |
1069 | int gprintf( window_t * window, const char * fmt, ...)␊ |
1070 | {␊ |
1071 | ␉char *formattedtext;␊ |
1072 | ␊ |
1073 | ␉va_list ap;␊ |
1074 | ␉␊ |
1075 | ␉struct putc_info pi;␊ |
1076 | ␊ |
1077 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1078 | ␉␉// format the text␊ |
1079 | ␉␉va_start(ap, fmt);␊ |
1080 | ␉␉pi.str = formattedtext;␊ |
1081 | ␉␉pi.last_str = 0;␊ |
1082 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1083 | ␉␉*pi.str = '\0';␊ |
1084 | ␉␉va_end(ap);␊ |
1085 | ␉␉␊ |
1086 | ␉␉position_t␉origin, cursor, bounds;␊ |
1087 | ␊ |
1088 | ␉␉int i;␊ |
1089 | ␉␉int character;␊ |
1090 | ␊ |
1091 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1092 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1093 | ␉␉␊ |
1094 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1095 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1096 | ␉␉␊ |
1097 | ␉␉cursor = origin;␊ |
1098 | ␉␉␉␊ |
1099 | ␉␉font_t *font = &font_console;␊ |
1100 | ␉␉␉␊ |
1101 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1102 | ␉␉{␊ |
1103 | ␉␉␉character = formattedtext[i];␊ |
1104 | ␉␉␉␊ |
1105 | ␉␉␉character -= 32;␊ |
1106 | ␉␉␉␉␊ |
1107 | ␉␉␉// newline ?␊ |
1108 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1109 | ␉␉␉{␊ |
1110 | ␉␉␉␉cursor.x = window->hborder;␊ |
1111 | ␉␉␉␉cursor.y += font->height;␊ |
1112 | ␊ |
1113 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1114 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1115 | ␊ |
1116 | ␉␉␉␉continue;␊ |
1117 | ␉␉␉}␊ |
1118 | ␉␉␉␉␊ |
1119 | ␉␉␉// tab ?␊ |
1120 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1121 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1122 | ␉␉␉␊ |
1123 | ␉␉␉// draw the character␊ |
1124 | ␉␉␉if( font->chars[character])␊ |
1125 | ␉␉␉␉blend(font->chars[character], window->pixmap, cursor);␊ |
1126 | ␊ |
1127 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1128 | ␊ |
1129 | ␉␉␉// check x pos and do newline␊ |
1130 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1131 | ␉␉␉{␊ |
1132 | ␉␉␉␉cursor.x = origin.x;␊ |
1133 | ␉␉␉␉cursor.y += font->height;␊ |
1134 | ␉␉␉}␊ |
1135 | ␉␉␉␊ |
1136 | ␉␉␉// check y pos and reset to origin.y␊ |
1137 | ␉␉␉if ( cursor.y > bounds.y )␊ |
1138 | ␉␉␉␉cursor.y = origin.y;␊ |
1139 | ␉␉}␊ |
1140 | ␊ |
1141 | ␉␉// update cursor postition␊ |
1142 | ␉␉window->cursor = cursor;␊ |
1143 | ␉␉␊ |
1144 | ␉␉free(formattedtext);␊ |
1145 | ␉␉␊ |
1146 | ␉␉return 0;␊ |
1147 | ␊ |
1148 | ␉}␊ |
1149 | ␉return 1;␊ |
1150 | }␊ |
1151 | ␊ |
1152 | int dprintf( window_t * window, const char * fmt, ...)␊ |
1153 | {␊ |
1154 | ␉char *formattedtext;␊ |
1155 | ␉␊ |
1156 | ␉va_list ap;␊ |
1157 | ␉␊ |
1158 | ␉//window = &gui.debug;␊ |
1159 | ␉␊ |
1160 | ␉struct putc_info pi;␊ |
1161 | ␉␊ |
1162 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1163 | ␉␉// format the text␊ |
1164 | ␉␉va_start(ap, fmt);␊ |
1165 | ␉␉pi.str = formattedtext;␊ |
1166 | ␉␉pi.last_str = 0;␊ |
1167 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1168 | ␉␉*pi.str = '\0';␊ |
1169 | ␉␉va_end(ap);␊ |
1170 | ␉␉␊ |
1171 | ␉␉position_t␉origin, cursor, bounds;␊ |
1172 | ␉␉␊ |
1173 | ␉␉int i;␊ |
1174 | ␉␉int character;␊ |
1175 | ␉␉␊ |
1176 | ␉␉origin.x = MAX( gui.debug.cursor.x, window->hborder );␊ |
1177 | ␉␉origin.y = MAX( gui.debug.cursor.y, window->vborder );␊ |
1178 | ␉␉␊ |
1179 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1180 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1181 | ␉␉␊ |
1182 | ␉␉cursor = origin;␊ |
1183 | ␉␉␊ |
1184 | ␉␉font_t *font = &font_console;␊ |
1185 | ␉␉␊ |
1186 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1187 | ␉␉{␊ |
1188 | ␉␉␉character = formattedtext[i];␊ |
1189 | ␉␉␉␊ |
1190 | ␉␉␉character -= 32;␊ |
1191 | ␉␉␉␊ |
1192 | ␉␉␉// newline ?␊ |
1193 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1194 | ␉␉␉{␊ |
1195 | ␉␉␉␉cursor.x = window->hborder;␊ |
1196 | ␉␉␉␉cursor.y += font->height;␊ |
1197 | ␉␉␉␉␊ |
1198 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1199 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1200 | ␉␉␉␉␊ |
1201 | ␉␉␉␉continue;␊ |
1202 | ␉␉␉}␊ |
1203 | ␉␉␉␊ |
1204 | ␉␉␉// tab ?␊ |
1205 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1206 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1207 | ␉␉␉␊ |
1208 | ␉␉␉// draw the character␊ |
1209 | ␉␉␉if( font->chars[character])␊ |
1210 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1211 | ␊ |
1212 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1213 | ␉␉␉␊ |
1214 | ␉␉␉// check x pos and do newline␊ |
1215 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1216 | ␉␉␉{␊ |
1217 | ␉␉␉␉cursor.x = origin.x;␊ |
1218 | ␉␉␉␉cursor.y += font->height;␊ |
1219 | ␉␉␉}␊ |
1220 | ␉␉␉␊ |
1221 | ␉␉␉// check y pos and reset to origin.y␊ |
1222 | ␉␉␉if ( cursor.y > bounds.y )␊ |
1223 | ␉␉␉␉cursor.y = origin.y;␊ |
1224 | ␉␉}␊ |
1225 | ␉␉␊ |
1226 | ␉␉// update cursor postition␊ |
1227 | ␉␉gui.debug.cursor = cursor;␊ |
1228 | ␉␉␊ |
1229 | ␉␉free(formattedtext);␊ |
1230 | ␉␉␊ |
1231 | ␉␉return 0;␊ |
1232 | ␉␉␊ |
1233 | ␉}␊ |
1234 | ␉return 1;␊ |
1235 | }␊ |
1236 | ␊ |
1237 | int vprf(const char * fmt, va_list ap)␊ |
1238 | {␊ |
1239 | ␉int i;␊ |
1240 | ␉int character;␊ |
1241 | ␊ |
1242 | ␉char *formattedtext;␊ |
1243 | ␉window_t *window = &gui.screen;␊ |
1244 | ␉struct putc_info pi;␊ |
1245 | ␉␊ |
1246 | ␉position_t␉origin, cursor, bounds;␊ |
1247 | ␉font_t *font = &font_console;␊ |
1248 | ␉␊ |
1249 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1250 | ␉␉// format the text␊ |
1251 | ␉␉pi.str = formattedtext;␊ |
1252 | ␉␉pi.last_str = 0;␊ |
1253 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1254 | ␉␉*pi.str = '\0';␊ |
1255 | ␉␉␊ |
1256 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1257 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1258 | ␉␉bounds.x = ( window->width - ( window->hborder * 2 ) );␊ |
1259 | ␉␉bounds.y = ( window->height - ( window->vborder * 2 ) );␊ |
1260 | ␉␉cursor = origin;␊ |
1261 | ␉␉␉␊ |
1262 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1263 | ␉␉{␊ |
1264 | ␉␉␉character = formattedtext[i];␊ |
1265 | ␉␉␉character -= 32;␊ |
1266 | ␉␉␉␊ |
1267 | ␉␉␉// newline ?␊ |
1268 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1269 | ␉␉␉{␊ |
1270 | ␉␉␉␉cursor.x = window->hborder;␊ |
1271 | ␉␉␉␉cursor.y += font->height;␊ |
1272 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1273 | ␉␉␉␉{␊ |
1274 | ␉␉␉␉␉gui.redraw = true;␊ |
1275 | ␉␉␉␉␉updateVRAM();␊ |
1276 | ␉␉␉␉␉cursor.y = window->vborder;␊ |
1277 | ␉␉␉␉}␊ |
1278 | ␉␉␉␉window->cursor.y = cursor.y;␊ |
1279 | ␉␉␉␉continue;␊ |
1280 | ␉␉␉}␊ |
1281 | ␊ |
1282 | ␉␉␉// tab ?␊ |
1283 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1284 | ␉␉␉{␊ |
1285 | ␉␉␉␉cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );␊ |
1286 | ␉␉␉␉continue;␊ |
1287 | ␉␉␉}␊ |
1288 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1289 | ␉␉␉␊ |
1290 | ␉␉␉// check x pos and do newline␊ |
1291 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1292 | ␉␉␉{␊ |
1293 | ␉␉␉␉cursor.x = origin.x;␊ |
1294 | ␉␉␉␉cursor.y += font->height;␊ |
1295 | ␉␉␉}␊ |
1296 | ␉␉␉␉␊ |
1297 | ␉␉␉// check y pos and reset to origin.y␊ |
1298 | ␉␉␉if ( cursor.y > ( bounds.y + font->chars[0]->height) )␊ |
1299 | ␉␉␉{␊ |
1300 | ␉␉␉␉gui.redraw = true;␊ |
1301 | ␉␉␉␉updateVRAM();␊ |
1302 | ␉␉␉␉cursor.y = window->vborder;␊ |
1303 | ␉␉␉}␊ |
1304 | ␉␉␉// draw the character␊ |
1305 | ␉␉␉if( font->chars[character])␊ |
1306 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1307 | ␉␉}␊ |
1308 | ␉␉// save cursor postition␊ |
1309 | ␉␉window->cursor.x = cursor.x;␊ |
1310 | ␉␉updateVRAM();␊ |
1311 | ␉␉free(formattedtext);␊ |
1312 | ␉␉return 0;␊ |
1313 | ␉}␊ |
1314 | ␉return 1;␊ |
1315 | }␊ |
1316 | ␊ |
1317 | void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1318 | {␊ |
1319 | ␉int i=0;␊ |
1320 | ␉int y=0; // we need this to support multilines '\n'␊ |
1321 | ␉int x=0;␊ |
1322 | ␉␊ |
1323 | ␉for(i=0;i<strlen(ch);i++)␊ |
1324 | ␉{␊ |
1325 | ␉␉int cha=(int)ch[i];␊ |
1326 | ␉␉␊ |
1327 | ␉␉cha-=32;␊ |
1328 | ␉␉␊ |
1329 | ␉␉// newline ?␊ |
1330 | ␉␉if( ch[i] == '\n' )␊ |
1331 | ␉␉{␊ |
1332 | ␉␉␉x = 0;␊ |
1333 | ␉␉␉y += font->height;␊ |
1334 | ␉␉␉continue;␊ |
1335 | ␉␉}␊ |
1336 | ␉␉␊ |
1337 | ␉␉// tab ?␊ |
1338 | ␉␉if( ch[i] == '\t' )␊ |
1339 | ␉␉␉x+=(font->chars[0]->width*5);␊ |
1340 | ␉␉␊ |
1341 | ␉␉if(font->chars[cha])␊ |
1342 | ␉␉␉blend(font->chars[cha], blendInto, pos(p.x+x, p.y+y));␊ |
1343 | ␉␉␊ |
1344 | ␉␉x += font->chars[cha]->width;␊ |
1345 | ␉}␊ |
1346 | }␊ |
1347 | ␊ |
1348 | void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1349 | {␊ |
1350 | ␉int i = 0;␊ |
1351 | ␉int width = 0;␊ |
1352 | ␊ |
1353 | ␉// calculate the width in pixels␊ |
1354 | ␉for(i=0;i<strlen(text);i++)␊ |
1355 | ␉␉width += font->chars[text[i]-32]->width;␊ |
1356 | ␊ |
1357 | ␉p.x = ( p.x - ( width / 2 ) );␊ |
1358 | ␉p.y = ( p.y - ( font->height / 2 ) ); ␊ |
1359 | ␉␊ |
1360 | ␉if ( p.x == -6 )␊ |
1361 | ␉{␊ |
1362 | ␉␉p.x = 0;␊ |
1363 | ␉}␊ |
1364 | ␉␊ |
1365 | ␉for(i=0;i<strlen(text);i++)␊ |
1366 | ␉{␊ |
1367 | ␉␉int cha=(int)text[i];␊ |
1368 | ␉␉␊ |
1369 | ␉␉cha-=32;␊ |
1370 | ␊ |
1371 | ␉␉if(font->chars[cha])␊ |
1372 | ␉␉{␊ |
1373 | ␉␉␉blend(font->chars[cha], blendInto, p);␊ |
1374 | ␉␉␉p.x += font->chars[cha]->width;␊ |
1375 | ␉␉}␊ |
1376 | ␉}␊ |
1377 | ␉␊ |
1378 | }␊ |
1379 | ␊ |
1380 | int initFont(font_t *font, image_t *data)␊ |
1381 | {␊ |
1382 | ␉unsigned int x = 0, y = 0, x2 = 0, x3 = 0;␊ |
1383 | ␉␊ |
1384 | ␉int start = 0, end = 0, count = 0, space = 0;␊ |
1385 | ␉␊ |
1386 | ␉bool monospaced = false;␊ |
1387 | ␉␊ |
1388 | ␉font->height = data->image->height;␉␊ |
1389 | ␊ |
1390 | ␉for( x = 0; x < data->image->width; x++)␊ |
1391 | ␉{␊ |
1392 | ␉␉start = end;␊ |
1393 | ␉␉␉␉␊ |
1394 | ␉␉// if the pixel is red we've reached the end of the char␊ |
1395 | ␉␉if( pixel( data->image, x, 0 ).value == 0xFFFF0000)␊ |
1396 | ␉␉{␊ |
1397 | ␉␉␉end = x + 1;␊ |
1398 | ␊ |
1399 | ␉␉␉if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )␊ |
1400 | ␉␉␉{␊ |
1401 | ␉␉␉␉font->chars[count]->width = ( end - start) - 1;␊ |
1402 | ␉␉␉␉font->chars[count]->height = font->height;␊ |
1403 | ␉␉␉␊ |
1404 | ␉␉␉␉if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )␊ |
1405 | ␉␉␉␉{␊ |
1406 | ␉␉␉␉␉space += ( font->chars[count]->width * data->image->height * 4 );␊ |
1407 | ␉␉␉␉␉// we skip the first line because there are just the red pixels for the char width␊ |
1408 | ␉␉␉␉␉for( y = 1; y< (font->height); y++)␊ |
1409 | ␉␉␉␉␉{␊ |
1410 | ␉␉␉␉␉␉for( x2 = start, x3 = 0; x2 < end; x2++, x3++)␊ |
1411 | ␉␉␉␉␉␉{␊ |
1412 | ␉␉␉␉␉␉␉pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );␊ |
1413 | ␉␉␉␉␉␉}␉␊ |
1414 | ␉␉␉␉␉}␊ |
1415 | ␉␉␉␉␉␊ |
1416 | ␉␉␉␉␉// check if font is monospaced␊ |
1417 | ␉␉␉␉␉if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )␊ |
1418 | ␉␉␉␉␉␉monospaced = true;␊ |
1419 | ␉␉␉␉␉␉␊ |
1420 | ␉␉␉␉␉font->width = font->chars[count]->width;␊ |
1421 | ␉␉␉␉␉␊ |
1422 | ␉␉␉␉␉count++;␊ |
1423 | ␉␉␉␉}␊ |
1424 | ␉␉␉}␊ |
1425 | ␉␉}␊ |
1426 | ␉}␊ |
1427 | ␊ |
1428 | ␉if(monospaced)␊ |
1429 | ␉␉font->width = 0;␊ |
1430 | ␊ |
1431 | ␉return 0;␊ |
1432 | }␊ |
1433 | ␊ |
1434 | void colorFont(font_t *font, uint32_t color)␊ |
1435 | {␊ |
1436 | ␉if( !color )␊ |
1437 | ␉␉return;␊ |
1438 | ␉␊ |
1439 | ␉int x, y, width, height;␊ |
1440 | ␉int count = 0;␊ |
1441 | ␉pixel_t *buff;␊ |
1442 | ␉␊ |
1443 | ␉while( font->chars[count++] )␊ |
1444 | ␉{␊ |
1445 | ␉␉width = font->chars[count-1]->width;␊ |
1446 | ␉␉height = font->chars[count-1]->height;␊ |
1447 | ␉␉for( y = 0; y < height; y++ )␊ |
1448 | ␉␉{␊ |
1449 | ␉␉␉for( x = 0; x < width; x++ )␊ |
1450 | ␉␉␉{␊ |
1451 | ␉␉␉␉buff = &(pixel( font->chars[count-1], x, y ));␊ |
1452 | ␉␉␉␉if( buff->ch.a )␊ |
1453 | ␉␉␉␉{␊ |
1454 | ␉␉␉␉␉buff->ch.r = (color & 0xFFFF0000) >> 16;␊ |
1455 | ␉␉␉␉␉buff->ch.g = (color & 0xFF00FF00) >> 8;␊ |
1456 | ␉␉␉␉␉buff->ch.b = (color & 0xFF0000FF);␊ |
1457 | ␉␉␉␉}␊ |
1458 | ␉␉␉}␊ |
1459 | ␉␉}␊ |
1460 | ␉}␊ |
1461 | }␊ |
1462 | ␊ |
1463 | void makeRoundedCorners(pixmap_t *p)␊ |
1464 | {␊ |
1465 | ␉int x,y;␊ |
1466 | ␉int width=p->width-1;␊ |
1467 | ␉int height=p->height-1;␊ |
1468 | ␉␊ |
1469 | ␉// 10px rounded corner alpha values␊ |
1470 | ␉uint8_t roundedCorner[10][10] =␊ |
1471 | ␉{␊ |
1472 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},␊ |
1473 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1474 | ␉␉{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1475 | ␉␉{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1476 | ␉␉{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1477 | ␉␉{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1478 | ␉␉{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1479 | ␉␉{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1480 | ␉␉{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1481 | ␉␉{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}␊ |
1482 | ␉};␊ |
1483 | ␉␊ |
1484 | ␉uint8_t alpha=0;␊ |
1485 | ␉␊ |
1486 | ␉for( y=0; y<10; y++)␊ |
1487 | ␉{␊ |
1488 | ␉␉for( x=0; x<10; x++)␊ |
1489 | ␉␉{␊ |
1490 | ␉␉␉// skip if the pixel should be visible␊ |
1491 | ␉␉␉if(roundedCorner[y][x] != 0xFF) ␊ |
1492 | ␉␉␉{ ␊ |
1493 | ␉␉␉␉alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );␊ |
1494 | ␉␉␉␉// Upper left corner␊ |
1495 | ␉␉␉␉pixel(p, x, y).ch.a = alpha;␊ |
1496 | ␊ |
1497 | ␉␉␉␉// upper right corner␊ |
1498 | ␉␉␉␉pixel(p, width-x,y).ch.a = alpha;␊ |
1499 | ␊ |
1500 | ␉␉␉␉// lower left corner␊ |
1501 | ␉␉␉␉pixel(p, x, height-y).ch.a = alpha;␊ |
1502 | ␊ |
1503 | ␉␉␉␉// lower right corner␊ |
1504 | ␉␉␉␉pixel(p, width-x, height-y).ch.a = alpha;␊ |
1505 | ␉␉␉}␊ |
1506 | ␉␉}␊ |
1507 | ␉}␊ |
1508 | }␊ |
1509 | ␊ |
1510 | void showInfoBox(char *title, char *text)␊ |
1511 | {␊ |
1512 | ␉int i, key, lines, visiblelines;␊ |
1513 | ␊ |
1514 | ␉int currentline=0;␊ |
1515 | ␉int cnt=0;␊ |
1516 | ␉int offset=0;␊ |
1517 | ␉␊ |
1518 | ␉if( !title || !text )␊ |
1519 | ␉␉return;␊ |
1520 | ␉␊ |
1521 | ␉position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );␊ |
1522 | ␊ |
1523 | ␉// calculate number of lines in the title␊ |
1524 | ␉for ( i = 0, lines = 1; i<strlen(title); i++ )␊ |
1525 | ␉␉if( title[i] == '\n')␊ |
1526 | ␉␉␉lines++;␊ |
1527 | ␉␊ |
1528 | ␉// y position of text is lines in title * height of font␊ |
1529 | ␉position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));␊ |
1530 | ␉␊ |
1531 | ␉// calculate number of lines in the text␊ |
1532 | ␉for ( i=0, lines = 1; i<strlen(text); i++ )␊ |
1533 | ␉␉if( text[i] == '\n')␊ |
1534 | ␉␉␉lines++;␊ |
1535 | ␉␊ |
1536 | ␉// if text ends with \n strip off␊ |
1537 | ␉if( text[i] == '\n' || text[i] == '\0')␊ |
1538 | ␉␉lines--;␊ |
1539 | ␉␊ |
1540 | ␉visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;␊ |
1541 | ␉␊ |
1542 | ␉// lets display the text and allow scroll thru using up down / arrows␊ |
1543 | ␉while(1)␊ |
1544 | ␉{␊ |
1545 | ␉␉// move to current line in text␊ |
1546 | ␉␉for( offset = 0, i = 0; offset < strlen(text); offset++ )␊ |
1547 | ␉␉{␊ |
1548 | ␉␉␉if( currentline == i)␊ |
1549 | ␉␉␉␉break;␊ |
1550 | ␉␉␉if( text[offset] =='\n')␊ |
1551 | ␉␉␉␉i++;␊ |
1552 | ␉␉}␊ |
1553 | ␊ |
1554 | ␉␉// find last visible line in text and place \0␊ |
1555 | ␉␉for( i = offset, cnt = 0; i < strlen(text); i++)␊ |
1556 | ␉␉{␊ |
1557 | ␉␉␉if(text[i]=='\n')␊ |
1558 | ␉␉␉␉cnt++;␊ |
1559 | ␉␉␉if ( cnt == visiblelines )␊ |
1560 | ␉␉␉{␊ |
1561 | ␉␉␉␉text[i]='\0';␊ |
1562 | ␉␉␉␉break;␊ |
1563 | ␉␉␉}␊ |
1564 | ␉␉}␊ |
1565 | ␉␉␉␉␊ |
1566 | ␉␉fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);␊ |
1567 | ␊ |
1568 | ␉␉makeRoundedCorners( gui.infobox.pixmap);␊ |
1569 | ␉␉␉␊ |
1570 | ␉␉// print the title if present␊ |
1571 | ␉␉if( title )␊ |
1572 | ␉␉␉drawStr(title, &font_console, gui.infobox.pixmap, pos_title);␊ |
1573 | ␊ |
1574 | ␉␉// print the text␊ |
1575 | ␉␉drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);␊ |
1576 | ␊ |
1577 | ␉␉// restore \n in text␊ |
1578 | ␉␉if ( cnt == visiblelines )␊ |
1579 | ␉␉␉text[i] = '\n';␊ |
1580 | ␉␉␊ |
1581 | ␉␉position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );␊ |
1582 | ␉␉␊ |
1583 | ␉␉// draw prev indicator␊ |
1584 | ␉␉if(offset)␊ |
1585 | ␉␉{␊ |
1586 | ␉␉␉blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));␊ |
1587 | ␉␉}␊ |
1588 | ␉␉␊ |
1589 | ␉␉// draw next indicator␊ |
1590 | ␉␉if( lines > ( currentline + visiblelines ) )␊ |
1591 | ␉␉{␊ |
1592 | ␉␉␉pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );␊ |
1593 | ␉␉␉blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );␊ |
1594 | ␉␉}␊ |
1595 | ␊ |
1596 | ␉␉gui.bootprompt.draw = false;␊ |
1597 | ␉␉gui.infobox.draw = true;␊ |
1598 | ␉␉gui.redraw = true;␊ |
1599 | ␉␉␊ |
1600 | ␉␉updateVRAM();␊ |
1601 | ␉␉␊ |
1602 | ␉␉key = getchar();␊ |
1603 | ␉␉␉␊ |
1604 | ␉␉if( key == kUpArrowkey )␊ |
1605 | ␉␉␉if( currentline > 0 )␊ |
1606 | ␉␉␉␉currentline--;␊ |
1607 | ␊ |
1608 | ␉␉if( key == kDownArrowkey )␊ |
1609 | ␉␉␉if( lines > ( currentline + visiblelines ) )␊ |
1610 | ␉␉␉␉currentline++;␊ |
1611 | ␊ |
1612 | ␉␉if( key == kEscapeKey || key == 'q' || key == 'Q')␊ |
1613 | ␉␉{␊ |
1614 | ␉␉␉gui.infobox.draw = false;␊ |
1615 | ␉␉␉gui.redraw = true;␊ |
1616 | ␉␉␉updateVRAM();␊ |
1617 | ␉␉␉break;␊ |
1618 | ␉␉}␊ |
1619 | ␉}␊ |
1620 | }␊ |
1621 | ␊ |
1622 | void animateProgressBar()␊ |
1623 | {␊ |
1624 | ␉int y;␊ |
1625 | ␉␊ |
1626 | ␉if( time18() > lasttime)␊ |
1627 | ␉{␊ |
1628 | ␉␉lasttime = time18();␊ |
1629 | ␊ |
1630 | ␉␉pixmap_t *buffBar = images[iProgressBar].image;␊ |
1631 | ␊ |
1632 | ␉␉uint32_t buff = buffBar->pixels[0].value;␊ |
1633 | ␉␊ |
1634 | ␉␉memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );␊ |
1635 | ␊ |
1636 | ␉␉for( y = buffBar->height - 1; y > 0; y--)␊ |
1637 | ␉␉␉pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);␊ |
1638 | ␊ |
1639 | ␉␉pixel(buffBar, buffBar->width-1, 0).value = buff;␊ |
1640 | ␉}␊ |
1641 | }␊ |
1642 | ␊ |
1643 | void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)␊ |
1644 | {␊ |
1645 | ␉if(progress>100)␊ |
1646 | ␉␉return;␊ |
1647 | ␉␊ |
1648 | ␉p.x = ( p.x - ( width / 2 ) );␊ |
1649 | ␊ |
1650 | ␉int todraw = (width * progress) / 100;␊ |
1651 | ␊ |
1652 | ␉pixmap_t *buff = images[iProgressBar].image;␊ |
1653 | ␉pixmap_t *buffBG = images[iProgressBarBackground].image;␊ |
1654 | ␉if(!buff || !buffBG)␊ |
1655 | ␉␉return;␊ |
1656 | ␉␊ |
1657 | ␉pixmap_t progressbar;␊ |
1658 | ␉progressbar.pixels=malloc(width * 4 * buff->height);␊ |
1659 | ␉if(!progressbar.pixels)␊ |
1660 | ␉␉return; ␊ |
1661 | ␉␊ |
1662 | ␉progressbar.width = width;␊ |
1663 | ␉progressbar.height = buff->height;␊ |
1664 | ␊ |
1665 | ␉int x=0,x2=0,y=0;␊ |
1666 | ␉␊ |
1667 | ␉for(y=0; y<buff->height; y++)␊ |
1668 | ␉{␊ |
1669 | ␉␉for(x=0; x<todraw; x++, x2++)␊ |
1670 | ␉␉{␊ |
1671 | ␉␉␉if(x2 == (buff->width-1)) x2=0;␊ |
1672 | ␉␉␉pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;␊ |
1673 | ␉␉}␊ |
1674 | ␉␉x2=0;␊ |
1675 | ␉}␊ |
1676 | ␊ |
1677 | ␉for(y=0; y<buff->height; y++)␊ |
1678 | ␉{␊ |
1679 | ␉␉for(x=todraw, x2 = 0; x < width - 1; x++, x2++)␊ |
1680 | ␉␉{␊ |
1681 | ␉␉␉if(x2 == (buffBG->width -2 )) x2 = 0;␊ |
1682 | ␉␉␉␉pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;␊ |
1683 | ␉␉}␊ |
1684 | ␉␉if(progress < 100)␊ |
1685 | ␉␉␉pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
1686 | ␉␉if(progress == 0)␊ |
1687 | ␉␉␉pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
1688 | ␉␉x2=0;␊ |
1689 | ␉}␊ |
1690 | ␉ ␊ |
1691 | ␉blend(&progressbar, blendInto, p);␊ |
1692 | ␉animateProgressBar();␊ |
1693 | ␉free(progressbar.pixels);␊ |
1694 | }␊ |
1695 | ␊ |
1696 | void drawInfoMenuItems()␊ |
1697 | {␊ |
1698 | ␉int i,n;␊ |
1699 | ␉␊ |
1700 | ␉position_t position;␊ |
1701 | ␉␊ |
1702 | ␉pixmap_t *selection = images[iMenuSelection].image;␊ |
1703 | ␉␊ |
1704 | ␉pixmap_t *pbuff;␊ |
1705 | ␊ |
1706 | ␉fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);␊ |
1707 | ␊ |
1708 | ␉makeRoundedCorners(gui.menu.pixmap);␊ |
1709 | ␉␊ |
1710 | ␉uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;␊ |
1711 | ␊ |
1712 | ␉position = pos(0,0);␊ |
1713 | ␉␊ |
1714 | ␉for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)␊ |
1715 | ␉{␊ |
1716 | ␉␉if (i == infoMenuSelection)␊ |
1717 | ␉␉␉blend(selection, gui.menu.pixmap, position);␊ |
1718 | ␊ |
1719 | ␉␉pbuff = images[n].image;␊ |
1720 | ␉␉if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)␊ |
1721 | ␉␉␉blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap, ␊ |
1722 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
1723 | ␉␉else␊ |
1724 | ␉␉␉blend( pbuff, gui.menu.pixmap, ␊ |
1725 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
1726 | ␊ |
1727 | ␉␉drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap, ␊ |
1728 | ␉␉␉pos(position.x + (pbuff->width + gui.menu.hborder), ␊ |
1729 | ␉␉␉␉position.y + ((selection->height - font_console.height) / 2)));␊ |
1730 | ␉␉position.y += images[iMenuSelection].image->height;␊ |
1731 | ␉␊ |
1732 | ␉}␊ |
1733 | ␉␊ |
1734 | ␉gui.redraw = true;␊ |
1735 | }␊ |
1736 | ␊ |
1737 | int drawInfoMenu()␊ |
1738 | {␊ |
1739 | ␉drawInfoMenuItems();␊ |
1740 | ␊ |
1741 | ␉gui.menu.draw = true;␊ |
1742 | ␊ |
1743 | ␉updateVRAM();␊ |
1744 | ␉␊ |
1745 | ␉return 1;␊ |
1746 | }␊ |
1747 | ␊ |
1748 | int updateInfoMenu(int key)␊ |
1749 | {␊ |
1750 | ␉switch (key)␊ |
1751 | ␉{␊ |
1752 | ␊ |
1753 | ␉␉case kUpArrowkey:␉// up arrow␊ |
1754 | ␉␉␉␉if (infoMenuSelection > 0)␊ |
1755 | ␉␉␉␉{␊ |
1756 | ␉␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)␊ |
1757 | ␉␉␉␉␉␉infoMenuSelection -= 4;␊ |
1758 | ␉␉␉␉␉␊ |
1759 | ␉␉␉␉␉else␊ |
1760 | ␉␉␉␉␉␉infoMenuSelection--;␊ |
1761 | ␉␉␉␉␉␉drawInfoMenuItems();␊ |
1762 | ␉␉␉␉␉␉updateVRAM();␊ |
1763 | ␉␉␉␉␉␊ |
1764 | ␉␉␉␉} else {␊ |
1765 | ␉␉␉␉␉␊ |
1766 | ␉␉␉␉␉gui.menu.draw = false;␊ |
1767 | ␉␉␉␉␉gui.redraw = true;␊ |
1768 | ␊ |
1769 | ␉␉␉␉␉updateVRAM();␊ |
1770 | ␉␉␉␉␉␊ |
1771 | ␉␉␉␉␉return CLOSE_INFO_MENU;␊ |
1772 | ␉␉␉␉}␊ |
1773 | ␉␉␉␉break;␊ |
1774 | ␊ |
1775 | ␉␉case kDownArrowkey:␉// down arrow␊ |
1776 | ␉␉␉␉if (infoMenuSelection < infoMenuItemsCount - 1)␊ |
1777 | ␉␉␉␉{␊ |
1778 | ␉␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)␊ |
1779 | ␉␉␉␉␉␉infoMenuSelection += 4;␊ |
1780 | ␉␉␉␉␉else␊ |
1781 | ␉␉␉␉␉␉infoMenuSelection++;␊ |
1782 | ␉␉␉␉␉drawInfoMenuItems();␊ |
1783 | ␉␉␉␉␉updateVRAM();␊ |
1784 | ␉␉␉␉}␊ |
1785 | ␉␉␉␉break;␊ |
1786 | ␊ |
1787 | ␉␉case kReturnKey:␊ |
1788 | ␉␉␉␉key = 0;␊ |
1789 | ␉␉␉␉if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )␊ |
1790 | ␉␉␉␉␉showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());␊ |
1791 | ␊ |
1792 | ␉␉␉␉else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )␊ |
1793 | ␉␉␉␉␉showInfoBox( getVBEInfoString(), getVBEModeInfoString() );␊ |
1794 | ␉␉␉␊ |
1795 | ␉␉␉␉else if( infoMenuSelection == MENU_SHOW_HELP )␊ |
1796 | ␉␉␉␉␉showHelp();␊ |
1797 | ␉␉␉␉␉␊ |
1798 | ␉␉␉␉else␊ |
1799 | ␉␉␉␉{␊ |
1800 | ␉␉␉␉␉int buff = infoMenuSelection;␊ |
1801 | ␉␉␉␉␉infoMenuSelection = 0;␊ |
1802 | ␉␉␉␉␉return buff;␊ |
1803 | ␉␉␉␉}␊ |
1804 | ␉␉␉␉break;␊ |
1805 | ␉␉}␊ |
1806 | ␉return DO_NOT_BOOT;␊ |
1807 | }␊ |
1808 | ␊ |
1809 | uint16_t bootImageWidth = 0; ␊ |
1810 | uint16_t bootImageHeight = 0; ␊ |
1811 | uint8_t *bootImageData = NULL; ␊ |
1812 | static bool usePngImage = true;␊ |
1813 | ␊ |
1814 | //==========================================================================␊ |
1815 | // loadBootGraphics␊ |
1816 | static void loadBootGraphics(void)␊ |
1817 | {␊ |
1818 | ␉if (bootImageData != NULL) {␊ |
1819 | ␉␉return;␊ |
1820 | ␉}␊ |
1821 | ␊ |
1822 | ␉char dirspec[256];␊ |
1823 | ␊ |
1824 | ␉if ((strlen(theme_name) + 24) > sizeof(dirspec)) {␊ |
1825 | ␉␉usePngImage = false; ␊ |
1826 | ␉␉return;␊ |
1827 | ␉}␊ |
1828 | ␉sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);␊ |
1829 | ␉if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {␊ |
1830 | #ifdef CONFIG_EMBED_THEME␊ |
1831 | ␉if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)␊ |
1832 | #endif␊ |
1833 | ␉␉usePngImage = false; ␊ |
1834 | ␉}␊ |
1835 | }␊ |
1836 | ␊ |
1837 | //==========================================================================␊ |
1838 | // drawBootGraphics␊ |
1839 | void drawBootGraphics(void)␊ |
1840 | {␊ |
1841 | ␉int pos;␊ |
1842 | ␉int length;␊ |
1843 | ␉const char *dummyVal;␊ |
1844 | ␉int oldScreenWidth, oldScreenHeight;␊ |
1845 | ␉bool legacy_logo;␊ |
1846 | ␉uint16_t x, y; ␊ |
1847 | ␉␊ |
1848 | ␉if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->bootConfig) && legacy_logo) {␊ |
1849 | ␉␉usePngImage = false; ␊ |
1850 | ␉} else if (bootImageData == NULL) {␊ |
1851 | ␉␉loadBootGraphics();␊ |
1852 | ␉}␊ |
1853 | ␊ |
1854 | ␉// Save current screen resolution.␊ |
1855 | ␉oldScreenWidth = gui.screen.width;␊ |
1856 | ␉oldScreenHeight = gui.screen.height;␊ |
1857 | //␉printf("Res: %dx%d (drawbg: current/old)\n", oldScreenWidth, oldScreenHeight);␊ |
1858 | ␊ |
1859 | ␉//Azi:autoresolution␊ |
1860 | ␉if (gAutoResolution == true)␊ |
1861 | ␉{␊ |
1862 | ␉␉screen_params[0] = paramsAR[0];␊ |
1863 | ␉␉screen_params[1] = paramsAR[1];␊ |
1864 | //␉␉printf("Res: %dx%d (drawbg: AR)\n", screen_params[0], screen_params[1]);␊ |
1865 | ␉}␊ |
1866 | ␉else␊ |
1867 | ␉{␊ |
1868 | ␉␉// parse boot screen size parameters␊ |
1869 | ␉␉if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0)␊ |
1870 | ␉␉{␊ |
1871 | ␉␉␉screen_params[0] = pos;␊ |
1872 | ␉␉}␊ |
1873 | ␉␉else␊ |
1874 | ␉␉{␊ |
1875 | ␉␉␉screen_params[0] = DEFAULT_SCREEN_WIDTH;␊ |
1876 | ␉␉}␊ |
1877 | ␊ |
1878 | ␉␉if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0)␊ |
1879 | ␉␉{␊ |
1880 | ␉␉␉screen_params[1] = pos;␊ |
1881 | ␉␉}␊ |
1882 | ␉␉else␊ |
1883 | ␉␉{␊ |
1884 | ␉␉␉screen_params[1] = DEFAULT_SCREEN_HEIGHT;␊ |
1885 | ␉␉}␊ |
1886 | ␉}␊ |
1887 | ␊ |
1888 | ␉gui.screen.width = screen_params[0];␊ |
1889 | ␉gui.screen.height = screen_params[1];␊ |
1890 | //␉printf("Res: %dx%d (drawbg: gsw/h new)\n", gui.screen.width, gui.screen.height);␊ |
1891 | ␊ |
1892 | ␉// find best matching vesa mode for our requested width & height␊ |
1893 | ␉getGraphicModeParams(screen_params);␊ |
1894 | ␊ |
1895 | // Set graphics mode if the booter was in text mode or the screen resolution has changed.␊ |
1896 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE␊ |
1897 | ␉␉|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )␊ |
1898 | ␉{␊ |
1899 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
1900 | ␉}␊ |
1901 | ␊ |
1902 | ␉if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) {␊ |
1903 | ␉␉drawCheckerBoard();␊ |
1904 | ␉} else {␊ |
1905 | ␉␉// Fill the background to 75% grey (same as BootX). ␊ |
1906 | ␉␉drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01); ␊ |
1907 | ␉}␊ |
1908 | ␉if ((bootImageData) && (usePngImage)) { ␊ |
1909 | ␉␉x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2; ␊ |
1910 | ␉␉y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2; ␊ |
1911 | ␊ |
1912 | ␉␉// Draw the image in the center of the display. ␊ |
1913 | ␉␉blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData); ␊ |
1914 | ␉} else { ␊ |
1915 | ␉␉uint8_t *appleBootPict; ␊ |
1916 | ␉␉bootImageData = NULL; ␊ |
1917 | ␉␉bootImageWidth = kAppleBootWidth; ␊ |
1918 | ␉␉bootImageHeight = kAppleBootHeight; ␊ |
1919 | ␊ |
1920 | ␉␉// Prepare the data for the default Apple boot image. ␊ |
1921 | ␉␉appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight); ␊ |
1922 | ␉␉if (appleBootPict) { ␊ |
1923 | ␉␉␉convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData); ␊ |
1924 | ␉␉␉if (bootImageData) {␉␊ |
1925 | ␉␉␉␉x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2; ␊ |
1926 | ␉␉␉␉y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2; ␊ |
1927 | ␉␉␉␉drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);␊ |
1928 | ␉␉␉␉free(bootImageData);␊ |
1929 | ␉␉␉}␊ |
1930 | ␉␉␉free(appleBootPict); ␊ |
1931 | ␉␉} ␊ |
1932 | ␉} ␊ |
1933 | }␊ |
1934 | |