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