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