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