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