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