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