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