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