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