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