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