Root/
Source at commit 355 created 13 years 11 months ago. By meklort, Fixed the rebase + bind code, now works properly. Removed a few ugly hacks. KernelPatcher now loads properly (no more reboots). | |
---|---|
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 | ␉/*␊ |
582 | ␉// parse display size parameters␊ |
583 | ␉if (getIntForKey("screen_width", &val, &bootInfo->themeConfig)) {␊ |
584 | ␉␉screen_params[0] = val;␊ |
585 | ␉}␊ |
586 | ␉if (getIntForKey("screen_height", &val, &bootInfo->themeConfig)) {␊ |
587 | ␉␉screen_params[1] = val;␊ |
588 | ␉}␊ |
589 | ␉screen_params[2] = 32;␊ |
590 | ␉*/␊ |
591 | ␉getResolution(&screen_params[0], &screen_params[1], &screen_params[2]);␊ |
592 | ␊ |
593 | ␉␊ |
594 | ␉// Initalizing GUI strucutre.␊ |
595 | ␉bzero(&gui, sizeof(gui_t));␊ |
596 | ␉␊ |
597 | ␉// find best matching vesa mode for our requested width & height␊ |
598 | ␉getGraphicModeParams(screen_params);␊ |
599 | ␊ |
600 | ␉// set our screen structure with the mode width & height␊ |
601 | ␉gui.screen.width = screen_params[0];␉␊ |
602 | ␉gui.screen.height = screen_params[1];␊ |
603 | ␊ |
604 | ␉// load graphics otherwise fail and return␊ |
605 | ␉if (loadGraphics() == 0) {␊ |
606 | ␉␉loadThemeValues(&bootInfo->themeConfig, true);␊ |
607 | ␉␉colorFont(&font_small, gui.screen.font_small_color);␊ |
608 | ␉␉colorFont(&font_console, gui.screen.font_console_color);␊ |
609 | ␊ |
610 | ␉␉// create the screen & window buffers␊ |
611 | ␉␉if (createBackBuffer(&gui.screen) == 0) {␊ |
612 | ␉␉␉if (createWindowBuffer(&gui.screen) == 0) {␊ |
613 | ␉␉␉␉if (createWindowBuffer(&gui.devicelist) == 0) {␊ |
614 | ␉␉␉␉␉if (createWindowBuffer(&gui.bootprompt) == 0) {␊ |
615 | ␉␉␉␉␉␉if (createWindowBuffer(&gui.infobox) == 0) {␊ |
616 | ␉␉␉␉␉␉␉if (createWindowBuffer(&gui.menu) == 0) {␉␉␉␉␉␉␉␊ |
617 | ␉␉␉␉␉␉␉␉drawBackground();␊ |
618 | ␉␉␉␉␉␉␉␉// lets copy the screen into the back buffer␊ |
619 | ␉␉␉␉␉␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
620 | ␉␉␉␉␉␉␉␉setVideoMode( GRAPHICS_MODE, 0 );␊ |
621 | ␉␉␉␉␉␉␉␉gui.initialised = true;␊ |
622 | ␉␉␉␉␉␉␉␉return 0;␊ |
623 | ␉␉␉␉␉␉␉}␊ |
624 | ␉␉␉␉␉␉}␊ |
625 | ␉␉␉␉␉}␊ |
626 | ␉␉␉␉}␊ |
627 | ␉␉␉}␊ |
628 | ␉␉}␊ |
629 | ␉}␊ |
630 | ␉return 1;␊ |
631 | }␊ |
632 | ␊ |
633 | void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p)␊ |
634 | {␊ |
635 | ␉int devicetype;␊ |
636 | ␉␊ |
637 | ␉if( diskIsCDROM(device) )␊ |
638 | ␉␉devicetype = iDeviceCDROM;␉␉␉␉// Use CDROM icon␊ |
639 | ␉else␊ |
640 | ␉{␉␊ |
641 | ␉␉switch (device->part_type)␊ |
642 | ␉␉{␊ |
643 | ␉␉␉case kPartitionTypeHFS:␊ |
644 | ␊ |
645 | ␉␉␉␉// TODO: add apple raid icon choices␊ |
646 | ␉␉␉␉␊ |
647 | ␉␉␉␉devicetype = iDeviceHFS;␉␉// Use HFS icon␊ |
648 | ␉␉␉␉break;␊ |
649 | ␉␉␉␉␊ |
650 | ␉␉␉case kPartitionTypeHPFS:␊ |
651 | ␉␉␉␉devicetype = iDeviceNTFS;␉␉// Use HPFS / NTFS icon␊ |
652 | ␉␉␉␉break;␊ |
653 | ␉␉␉␉␊ |
654 | ␉␉␉case kPartitionTypeFAT16:␊ |
655 | ␉␉␉␉devicetype = iDeviceFAT16;␉␉// Use FAT16 icon␊ |
656 | ␉␉␉␉break;␊ |
657 | ␉␉␉␉␊ |
658 | ␉␉␉case kPartitionTypeFAT32:␊ |
659 | ␉␉␉␉devicetype = iDeviceFAT32;␉␉// Use FAT32 icon␊ |
660 | ␉␉␉␉break;␊ |
661 | ␉␉␉␉␊ |
662 | ␉␉␉case kPartitionTypeEXT3:␊ |
663 | ␉␉␉␉devicetype = iDeviceEXT3;␉␉// Use EXT2/3 icon␊ |
664 | ␉␉␉␉break;␊ |
665 | ␉␉␉␉␊ |
666 | ␉␉␉default:␊ |
667 | ␉␉␉␉devicetype = iDeviceGeneric;␉// Use Generic icon␊ |
668 | ␉␉␉␉break;␊ |
669 | ␉␉}␊ |
670 | ␉}␊ |
671 | ␉␊ |
672 | ␉// draw icon␊ |
673 | ␉blend( images[devicetype].image, buffer, centeredAt( images[devicetype].image, p ));␊ |
674 | ␉␊ |
675 | ␉p.y += (images[iSelection].image->height / 2) + font_console.chars[0]->height;␊ |
676 | ␉␊ |
677 | ␉// draw volume label ␊ |
678 | ␉drawStrCenteredAt( device->label, &font_small, buffer, p);␉␊ |
679 | ␊ |
680 | }␊ |
681 | ␊ |
682 | void drawDeviceList (int start, int end, int selection)␊ |
683 | {␊ |
684 | ␉int i;␊ |
685 | ␉position_t p, p_prev, p_next;␊ |
686 | ␊ |
687 | ␉//uint8_t␉maxDevices = MIN( gui.maxdevices, menucount );␊ |
688 | ␉␉␊ |
689 | ␉fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);␊ |
690 | ␊ |
691 | ␉makeRoundedCorners( gui.devicelist.pixmap);␊ |
692 | ␊ |
693 | ␉switch (gui.layout)␊ |
694 | ␉{␊ |
695 | ␊ |
696 | ␉␉case VerticalLayout:␊ |
697 | ␉␉␉p.x = (gui.devicelist.width /2);␊ |
698 | ␉␉␉p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );␊ |
699 | ␊ |
700 | ␉␉␉// place scroll indicators at top & bottom edges␊ |
701 | ␉␉␉p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );␊ |
702 | ␉␉␉p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );␊ |
703 | ␉␉␉␊ |
704 | ␉␉␉break;␊ |
705 | ␉␉␉␊ |
706 | ␉␉default:␉// use Horizontal layout as the default␊ |
707 | ␊ |
708 | ␉␉case HorizontalLayout:␊ |
709 | ␉␉␉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;␊ |
710 | ␉␉␉p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );␊ |
711 | ␊ |
712 | ␉␉␉// place scroll indicators at left & right edges␊ |
713 | ␉␉␉p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );␊ |
714 | ␉␉␉p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );␊ |
715 | ␉␉␉␊ |
716 | ␉␉␉break;␊ |
717 | ␉␉␉␊ |
718 | ␉}␊ |
719 | ␉␊ |
720 | ␉// draw visible device icons␊ |
721 | ␉for ( i=0; i < gui.maxdevices; i++ )␊ |
722 | ␉{␊ |
723 | ␉␉BVRef param = menuItems[start+i].param;␊ |
724 | ␊ |
725 | ␉␉if((start+i) == selection)␊ |
726 | ␉␉{␊ |
727 | ␉␉␉ if(param->flags & kBVFlagNativeBoot)␊ |
728 | ␉␉␉␉infoMenuNativeBoot = true;␊ |
729 | ␉␉␉ else␊ |
730 | ␉␉␉ {␊ |
731 | ␉␉␉␉infoMenuNativeBoot = false;␊ |
732 | ␉␉␉␉if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)␊ |
733 | ␉␉␉␉infoMenuSelection = 0;␊ |
734 | ␉␉␉ }␊ |
735 | ␉␉␉ ␊ |
736 | ␉␉␉if(gui.menu.draw)␊ |
737 | ␉␉␉␉drawInfoMenuItems();␊ |
738 | ␉␉␉ ␊ |
739 | ␉␉␉blend( images[iSelection].image, gui.devicelist.pixmap, centeredAt( images[iSelection].image, p ) );␊ |
740 | ␉␉␉␊ |
741 | #if DEBUG␊ |
742 | ␉␉␉gui.debug.cursor = pos( 10, 100);␊ |
743 | ␉␉␉dprintf( &gui.screen, "label %s\n", param->label );␊ |
744 | ␉␉␉dprintf( &gui.screen, "biosdev 0x%x\n", param->biosdev );␊ |
745 | dprintf(&gui.screen, "width %d\n", gui.screen.width);␊ |
746 | dprintf(&gui.screen, "height %d\n", gui.screen.height);␊ |
747 | ␉␉␉dprintf( &gui.screen, "type 0x%x\n", param->type );␊ |
748 | ␉␉␉dprintf( &gui.screen, "flags 0x%x\n", param->flags );␊ |
749 | ␉␉␉dprintf( &gui.screen, "part_no %d\n", param->part_no );␊ |
750 | ␉␉␉dprintf( &gui.screen, "part_boff 0x%x\n", param->part_boff );␊ |
751 | ␉␉␉dprintf( &gui.screen, "part_type 0x%x\n", param->part_type );␊ |
752 | ␉␉␉dprintf( &gui.screen, "bps 0x%x\n", param->bps );␊ |
753 | ␉␉␉dprintf( &gui.screen, "name %s\n", param->name );␊ |
754 | ␉␉␉dprintf( &gui.screen, "type_name %s\n", param->type_name );␊ |
755 | ␉␉␉dprintf( &gui.screen, "modtime %d\n", param->modTime );␊ |
756 | #endif␊ |
757 | ␉␉}␊ |
758 | ␉␉␊ |
759 | ␉␉drawDeviceIcon( param, gui.devicelist.pixmap, p );␊ |
760 | ␉␉␊ |
761 | ␉␉if (gui.layout == HorizontalLayout)␊ |
762 | ␉␉{␊ |
763 | ␉␉␉p.x += images[iSelection].image->width + gui.devicelist.iconspacing; ␊ |
764 | ␉␉}␊ |
765 | ␉␉if (gui.layout == VerticalLayout)␊ |
766 | ␉␉{␊ |
767 | ␉␉␉p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing ); ␊ |
768 | ␉␉}␊ |
769 | ␉}␊ |
770 | ␊ |
771 | ␉// draw prev indicator␊ |
772 | ␉if(start)␊ |
773 | ␉␉blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );␊ |
774 | ␊ |
775 | ␉// draw next indicator␊ |
776 | ␉if( end < gDeviceCount - 1 )␊ |
777 | ␉␉blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );␊ |
778 | ␊ |
779 | ␉gui.redraw = true;␊ |
780 | ␉␊ |
781 | ␉updateVRAM();␊ |
782 | ␉␊ |
783 | }␊ |
784 | ␊ |
785 | void clearGraphicBootPrompt()␊ |
786 | {␊ |
787 | ␉// clear text buffer␊ |
788 | ␉prompt[0] = '\0';␊ |
789 | ␉prompt_pos=0;␊ |
790 | ␊ |
791 | ␉␊ |
792 | ␉if(␉gui.bootprompt.draw == true )␊ |
793 | ␉{␊ |
794 | ␉␉gui.bootprompt.draw = false;␊ |
795 | ␉␉gui.redraw = true;␊ |
796 | ␉␉// this causes extra frames to be drawn␊ |
797 | ␉␉//updateVRAM();␊ |
798 | ␉}␊ |
799 | ␊ |
800 | ␉return;␊ |
801 | }␊ |
802 | ␊ |
803 | void updateGraphicBootPrompt(int key)␊ |
804 | {␊ |
805 | ␉if ( key == kBackspaceKey )␊ |
806 | ␉␉prompt[--prompt_pos] = '\0';␊ |
807 | ␉else ␊ |
808 | ␉{␊ |
809 | ␉␉prompt[prompt_pos] = key;␊ |
810 | ␉␉prompt_pos++;␊ |
811 | ␉␉prompt[prompt_pos] = '\0';␊ |
812 | ␉}␊ |
813 | ␊ |
814 | ␉fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);␊ |
815 | ␊ |
816 | ␉makeRoundedCorners( gui.bootprompt.pixmap);␊ |
817 | ␊ |
818 | ␉position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );␊ |
819 | ␊ |
820 | ␉// print the boot prompt text␊ |
821 | ␉drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);␊ |
822 | ␉␊ |
823 | ␉// get the position of the end of the boot prompt text to display user input␊ |
824 | ␉position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );␊ |
825 | ␊ |
826 | ␉// calculate the position of the cursor␊ |
827 | ␉int␉offset = ( prompt_pos - ( ( gui.bootprompt.width / font_console.chars[0]->width ) - strlen(prompt_text) - 2 ) );␉␊ |
828 | ␊ |
829 | ␉if ( offset < 0)␊ |
830 | ␉␉offset = 0;␊ |
831 | ␉␊ |
832 | ␉drawStr( prompt+offset, &font_console, gui.bootprompt.pixmap, p_prompt);␊ |
833 | ␊ |
834 | ␉gui.menu.draw = false;␊ |
835 | ␉gui.bootprompt.draw = true;␊ |
836 | ␉gui.redraw = true;␊ |
837 | ␉␊ |
838 | ␉updateVRAM();␊ |
839 | ␉␊ |
840 | ␉return;␊ |
841 | }␊ |
842 | ␊ |
843 | inline␊ |
844 | void vramwrite (void *data, int width, int height)␊ |
845 | {␊ |
846 | ␉if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)␊ |
847 | ␉␉memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));␊ |
848 | ␉else␊ |
849 | ␉{␊ |
850 | ␉␉uint32_t r, g, b;␊ |
851 | ␉␉int i, j;␊ |
852 | ␉␉for (i = 0; i < VIDEO (height); i++)␊ |
853 | ␉␉␉for (j = 0; j < VIDEO (width); j++)␊ |
854 | ␉␉␉{␊ |
855 | ␉␉␉␉b = ((uint8_t *) data)[4*i*width + 4*j];␊ |
856 | ␉␉␉␉g = ((uint8_t *) data)[4*i*width + 4*j + 1];␊ |
857 | ␉␉␉␉r = ((uint8_t *) data)[4*i*width + 4*j + 2];␊ |
858 | ␉␉␉␉switch (VIDEO (depth))␊ |
859 | ␉␉␉␉{␊ |
860 | ␉␉␉␉␉case 32:␊ |
861 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
862 | ␉␉␉␉␉␉break;␊ |
863 | ␉␉␉␉␉case 24:␊ |
864 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)␊ |
865 | ␉␉␉␉␉␉| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
866 | ␉␉␉␉␉␉break;␊ |
867 | ␉␉␉␉␉case 16:␊ |
868 | ␉␉␉␉␉␉// Somehow 16-bit is always 15-bits really␊ |
869 | ␉␉␉␉␉␉//␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);␊ |
870 | ␉␉␉␉␉␉//␉␉␉␉␉␉break;␉␉␉␉␉␉␉␊ |
871 | ␉␉␉␉␉case 15:␊ |
872 | ␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);␊ |
873 | ␉␉␉␉␉␉break;␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
874 | ␉␉␉␉}␊ |
875 | ␉␉␉}␊ |
876 | ␉}␊ |
877 | }␊ |
878 | ␊ |
879 | void updateVRAM()␊ |
880 | {␊ |
881 | ␉if (gui.redraw)␊ |
882 | ␉{␊ |
883 | ␉␉if (gui.devicelist.draw)␊ |
884 | ␉␉␉blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );␊ |
885 | ␊ |
886 | ␉␉if (gui.bootprompt.draw)␊ |
887 | ␉␉␉blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );␊ |
888 | ␉␉␉␉␊ |
889 | ␉␉if (gui.menu.draw)␊ |
890 | ␉␉␉blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );␊ |
891 | ␉␉␊ |
892 | ␉␉if (gui.infobox.draw)␊ |
893 | ␉␉␉blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );␊ |
894 | ␉}␊ |
895 | ␉␊ |
896 | ␉vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );␊ |
897 | ␊ |
898 | ␉if (gui.redraw)␊ |
899 | ␉{␊ |
900 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
901 | ␉␉gui.redraw = false;␊ |
902 | ␉}␊ |
903 | }␊ |
904 | ␊ |
905 | struct putc_info {␊ |
906 | char * str;␊ |
907 | char * last_str;␊ |
908 | };␊ |
909 | ␊ |
910 | static void␊ |
911 | sputc(int c, struct putc_info * pi)␊ |
912 | {␊ |
913 | if (pi->last_str)␊ |
914 | if (pi->str == pi->last_str) {␊ |
915 | *(pi->str) = '\0';␊ |
916 | return;␊ |
917 | }␊ |
918 | *(pi->str)++ = c;␊ |
919 | }␊ |
920 | ␊ |
921 | int gprintf( window_t * window, const char * fmt, ...)␊ |
922 | {␊ |
923 | ␉char *formattedtext;␊ |
924 | ␊ |
925 | ␉va_list ap;␊ |
926 | ␉␊ |
927 | ␉struct putc_info pi;␊ |
928 | ␊ |
929 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
930 | ␉␉// format the text␊ |
931 | ␉␉va_start(ap, fmt);␊ |
932 | ␉␉pi.str = formattedtext;␊ |
933 | ␉␉pi.last_str = 0;␊ |
934 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
935 | ␉␉*pi.str = '\0';␊ |
936 | ␉␉va_end(ap);␊ |
937 | ␉␉␊ |
938 | ␉␉position_t␉origin, cursor, bounds;␊ |
939 | ␊ |
940 | ␉␉int i;␊ |
941 | ␉␉int character;␊ |
942 | ␊ |
943 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
944 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
945 | ␉␉␊ |
946 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
947 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
948 | ␉␉␊ |
949 | ␉␉cursor = origin;␊ |
950 | ␉␉␉␊ |
951 | ␉␉font_t *font = &font_console;␊ |
952 | ␉␉␉␊ |
953 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
954 | ␉␉{␊ |
955 | ␉␉␉character = formattedtext[i];␊ |
956 | ␉␉␉␊ |
957 | ␉␉␉character -= 32;␊ |
958 | ␉␉␉␉␊ |
959 | ␉␉␉// newline ?␊ |
960 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
961 | ␉␉␉{␊ |
962 | ␉␉␉␉cursor.x = window->hborder;␊ |
963 | ␉␉␉␉cursor.y += font->height;␊ |
964 | ␊ |
965 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
966 | ␉␉␉␉␉cursor.y = origin.y;␊ |
967 | ␊ |
968 | ␉␉␉␉continue;␊ |
969 | ␉␉␉}␊ |
970 | ␉␉␉␉␊ |
971 | ␉␉␉// tab ?␊ |
972 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
973 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
974 | ␉␉␉␊ |
975 | ␉␉␉// draw the character␊ |
976 | ␉␉␉if( font->chars[character])␊ |
977 | ␉␉␉␉blend(font->chars[character], window->pixmap, cursor);␊ |
978 | ␊ |
979 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
980 | ␊ |
981 | ␉␉␉// check x pos and do newline␊ |
982 | ␉␉␉if ( cursor.x > bounds.x )␊ |
983 | ␉␉␉{␊ |
984 | ␉␉␉␉cursor.x = origin.x;␊ |
985 | ␉␉␉␉cursor.y += font->height;␊ |
986 | ␉␉␉}␊ |
987 | ␉␉␉␊ |
988 | ␉␉␉// check y pos and reset to origin.y␊ |
989 | ␉␉␉if ( cursor.y > bounds.y )␊ |
990 | ␉␉␉␉cursor.y = origin.y;␊ |
991 | ␉␉}␊ |
992 | ␊ |
993 | ␉␉// update cursor postition␊ |
994 | ␉␉window->cursor = cursor;␊ |
995 | ␉␉␊ |
996 | ␉␉free(formattedtext);␊ |
997 | ␉␉␊ |
998 | ␉␉return 0;␊ |
999 | ␊ |
1000 | ␉}␊ |
1001 | ␉return 1;␊ |
1002 | }␊ |
1003 | ␊ |
1004 | int dprintf( window_t * window, const char * fmt, ...)␊ |
1005 | {␊ |
1006 | ␉char *formattedtext;␊ |
1007 | ␉␊ |
1008 | ␉va_list ap;␊ |
1009 | ␉␊ |
1010 | ␉//window = &gui.debug;␊ |
1011 | ␉␊ |
1012 | ␉struct putc_info pi;␊ |
1013 | ␉␊ |
1014 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1015 | ␉␉// format the text␊ |
1016 | ␉␉va_start(ap, fmt);␊ |
1017 | ␉␉pi.str = formattedtext;␊ |
1018 | ␉␉pi.last_str = 0;␊ |
1019 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1020 | ␉␉*pi.str = '\0';␊ |
1021 | ␉␉va_end(ap);␊ |
1022 | ␉␉␊ |
1023 | ␉␉position_t␉origin, cursor, bounds;␊ |
1024 | ␉␉␊ |
1025 | ␉␉int i;␊ |
1026 | ␉␉int character;␊ |
1027 | ␉␉␊ |
1028 | ␉␉origin.x = MAX( gui.debug.cursor.x, window->hborder );␊ |
1029 | ␉␉origin.y = MAX( gui.debug.cursor.y, window->vborder );␊ |
1030 | ␉␉␊ |
1031 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1032 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1033 | ␉␉␊ |
1034 | ␉␉cursor = origin;␊ |
1035 | ␉␉␊ |
1036 | ␉␉font_t *font = &font_console;␊ |
1037 | ␉␉␊ |
1038 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1039 | ␉␉{␊ |
1040 | ␉␉␉character = formattedtext[i];␊ |
1041 | ␉␉␉␊ |
1042 | ␉␉␉character -= 32;␊ |
1043 | ␉␉␉␊ |
1044 | ␉␉␉// newline ?␊ |
1045 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1046 | ␉␉␉{␊ |
1047 | ␉␉␉␉cursor.x = window->hborder;␊ |
1048 | ␉␉␉␉cursor.y += font->height;␊ |
1049 | ␉␉␉␉␊ |
1050 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1051 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1052 | ␉␉␉␉␊ |
1053 | ␉␉␉␉continue;␊ |
1054 | ␉␉␉}␊ |
1055 | ␉␉␉␊ |
1056 | ␉␉␉// tab ?␊ |
1057 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1058 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1059 | ␉␉␉␊ |
1060 | ␉␉␉// draw the character␊ |
1061 | ␉␉␉if( font->chars[character])␊ |
1062 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1063 | ␊ |
1064 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1065 | ␉␉␉␊ |
1066 | ␉␉␉// check x pos and do newline␊ |
1067 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1068 | ␉␉␉{␊ |
1069 | ␉␉␉␉cursor.x = origin.x;␊ |
1070 | ␉␉␉␉cursor.y += font->height;␊ |
1071 | ␉␉␉}␊ |
1072 | ␉␉␉␊ |
1073 | ␉␉␉// check y pos and reset to origin.y␊ |
1074 | ␉␉␉if ( cursor.y > bounds.y )␊ |
1075 | ␉␉␉␉cursor.y = origin.y;␊ |
1076 | ␉␉}␊ |
1077 | ␉␉␊ |
1078 | ␉␉// update cursor postition␊ |
1079 | ␉␉gui.debug.cursor = cursor;␊ |
1080 | ␉␉␊ |
1081 | ␉␉free(formattedtext);␊ |
1082 | ␉␉␊ |
1083 | ␉␉return 0;␊ |
1084 | ␉␉␊ |
1085 | ␉}␊ |
1086 | ␉return 1;␊ |
1087 | }␊ |
1088 | ␊ |
1089 | int vprf(const char * fmt, va_list ap)␊ |
1090 | {␊ |
1091 | ␉int i;␊ |
1092 | ␉int character;␊ |
1093 | ␊ |
1094 | ␉char *formattedtext;␊ |
1095 | ␉window_t *window = &gui.screen;␊ |
1096 | ␉struct putc_info pi;␊ |
1097 | ␉␊ |
1098 | ␉position_t␉origin, cursor, bounds;␊ |
1099 | ␉font_t *font = &font_console;␊ |
1100 | ␉␊ |
1101 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1102 | ␉␉// format the text␊ |
1103 | ␉␉pi.str = formattedtext;␊ |
1104 | ␉␉pi.last_str = 0;␊ |
1105 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1106 | ␉␉*pi.str = '\0';␊ |
1107 | ␉␉␊ |
1108 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1109 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1110 | ␉␉bounds.x = ( window->width - ( window->hborder * 2 ) );␊ |
1111 | ␉␉bounds.y = ( window->height - ( window->vborder * 2 ) );␊ |
1112 | ␉␉cursor = origin;␊ |
1113 | ␉␉␉␊ |
1114 | ␉␉for( i=0; i< strlen(formattedtext); i++ )␊ |
1115 | ␉␉{␊ |
1116 | ␉␉␉character = formattedtext[i];␊ |
1117 | ␉␉␉character -= 32;␊ |
1118 | ␉␉␉␊ |
1119 | ␉␉␉// newline ?␊ |
1120 | ␉␉␉if( formattedtext[i] == '\n' )␊ |
1121 | ␉␉␉{␊ |
1122 | ␉␉␉␉cursor.x = window->hborder;␊ |
1123 | ␉␉␉␉cursor.y += font->height;␊ |
1124 | ␉␉␉␉if ( cursor.y > bounds.y )␊ |
1125 | ␉␉␉␉{␊ |
1126 | ␉␉␉␉␉gui.redraw = true;␊ |
1127 | ␉␉␉␉␉updateVRAM();␊ |
1128 | ␉␉␉␉␉cursor.y = window->vborder;␊ |
1129 | ␉␉␉␉}␊ |
1130 | ␉␉␉␉window->cursor.y = cursor.y;␊ |
1131 | ␉␉␉␉continue;␊ |
1132 | ␉␉␉}␊ |
1133 | ␊ |
1134 | ␉␉␉// tab ?␊ |
1135 | ␉␉␉if( formattedtext[i] == '\t' )␊ |
1136 | ␉␉␉{␊ |
1137 | ␉␉␉␉cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );␊ |
1138 | ␉␉␉␉continue;␊ |
1139 | ␉␉␉}␊ |
1140 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1141 | ␉␉␉␊ |
1142 | ␉␉␉// check x pos and do newline␊ |
1143 | ␉␉␉if ( cursor.x > bounds.x )␊ |
1144 | ␉␉␉{␊ |
1145 | ␉␉␉␉cursor.x = origin.x;␊ |
1146 | ␉␉␉␉cursor.y += font->height;␊ |
1147 | ␉␉␉}␊ |
1148 | ␉␉␉␉␊ |
1149 | ␉␉␉// check y pos and reset to origin.y␊ |
1150 | ␉␉␉if ( cursor.y > ( bounds.y + font->chars[0]->height) )␊ |
1151 | ␉␉␉{␊ |
1152 | ␉␉␉␉gui.redraw = true;␊ |
1153 | ␉␉␉␉updateVRAM();␊ |
1154 | ␉␉␉␉cursor.y = window->vborder;␊ |
1155 | ␉␉␉}␊ |
1156 | ␉␉␉// draw the character␊ |
1157 | ␉␉␉if( font->chars[character])␊ |
1158 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1159 | ␉␉}␊ |
1160 | ␉␉// save cursor postition␊ |
1161 | ␉␉window->cursor.x = cursor.x;␊ |
1162 | ␉␉updateVRAM();␊ |
1163 | ␉␉free(formattedtext);␊ |
1164 | ␉␉return 0;␊ |
1165 | ␉}␊ |
1166 | ␉return 1;␊ |
1167 | }␊ |
1168 | ␊ |
1169 | void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1170 | {␊ |
1171 | ␉int i=0;␊ |
1172 | ␉int y=0; // we need this to support multilines '\n'␊ |
1173 | ␉int x=0;␊ |
1174 | ␉␊ |
1175 | ␉for(i=0;i<strlen(ch);i++)␊ |
1176 | ␉{␊ |
1177 | ␉␉int cha=(int)ch[i];␊ |
1178 | ␉␉␊ |
1179 | ␉␉cha-=32;␊ |
1180 | ␉␉␊ |
1181 | ␉␉// newline ?␊ |
1182 | ␉␉if( ch[i] == '\n' )␊ |
1183 | ␉␉{␊ |
1184 | ␉␉␉x = 0;␊ |
1185 | ␉␉␉y += font->height;␊ |
1186 | ␉␉␉continue;␊ |
1187 | ␉␉}␊ |
1188 | ␉␉␊ |
1189 | ␉␉// tab ?␊ |
1190 | ␉␉if( ch[i] == '\t' )␊ |
1191 | ␉␉␉x+=(font->chars[0]->width*5);␊ |
1192 | ␉␉␊ |
1193 | ␉␉if(font->chars[cha])␊ |
1194 | ␉␉␉blend(font->chars[cha], blendInto, pos(p.x+x, p.y+y));␊ |
1195 | ␉␉␊ |
1196 | ␉␉x += font->chars[cha]->width;␊ |
1197 | ␉}␊ |
1198 | }␊ |
1199 | ␊ |
1200 | void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1201 | {␊ |
1202 | ␉int i = 0;␊ |
1203 | ␉int width = 0;␊ |
1204 | ␊ |
1205 | ␉// calculate the width in pixels␊ |
1206 | ␉for(i=0;i<strlen(text);i++)␊ |
1207 | ␉␉width += font->chars[text[i]-32]->width;␊ |
1208 | ␊ |
1209 | ␉p.x = ( p.x - ( width / 2 ) );␊ |
1210 | ␉p.y = ( p.y - ( font->height / 2 ) ); ␊ |
1211 | ␉␊ |
1212 | ␉if ( p.x == -6 )␊ |
1213 | ␉{␊ |
1214 | ␉␉p.x = 0;␊ |
1215 | ␉}␊ |
1216 | ␉␊ |
1217 | ␉for(i=0;i<strlen(text);i++)␊ |
1218 | ␉{␊ |
1219 | ␉␉int cha=(int)text[i];␊ |
1220 | ␉␉␊ |
1221 | ␉␉cha-=32;␊ |
1222 | ␊ |
1223 | ␉␉if(font->chars[cha])␊ |
1224 | ␉␉{␊ |
1225 | ␉␉␉blend(font->chars[cha], blendInto, p);␊ |
1226 | ␉␉␉p.x += font->chars[cha]->width;␊ |
1227 | ␉␉}␊ |
1228 | ␉}␊ |
1229 | ␉␊ |
1230 | }␊ |
1231 | ␊ |
1232 | int initFont(font_t *font, image_t *data)␊ |
1233 | {␊ |
1234 | ␉unsigned int x = 0, y = 0, x2 = 0, x3 = 0;␊ |
1235 | ␉␊ |
1236 | ␉int start = 0, end = 0, count = 0, space = 0;␊ |
1237 | ␉␊ |
1238 | ␉bool monospaced = false;␊ |
1239 | ␉␊ |
1240 | ␉font->height = data->image->height;␉␊ |
1241 | ␊ |
1242 | ␉for( x = 0; x < data->image->width; x++)␊ |
1243 | ␉{␊ |
1244 | ␉␉start = end;␊ |
1245 | ␉␉␉␉␊ |
1246 | ␉␉// if the pixel is red we've reached the end of the char␊ |
1247 | ␉␉if( pixel( data->image, x, 0 ).value == 0xFFFF0000)␊ |
1248 | ␉␉{␊ |
1249 | ␉␉␉end = x + 1;␊ |
1250 | ␊ |
1251 | ␉␉␉if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )␊ |
1252 | ␉␉␉{␊ |
1253 | ␉␉␉␉font->chars[count]->width = ( end - start) - 1;␊ |
1254 | ␉␉␉␉font->chars[count]->height = font->height;␊ |
1255 | ␉␉␉␊ |
1256 | ␉␉␉␉if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )␊ |
1257 | ␉␉␉␉{␊ |
1258 | ␉␉␉␉␉space += ( font->chars[count]->width * data->image->height * 4 );␊ |
1259 | ␉␉␉␉␉// we skip the first line because there are just the red pixels for the char width␊ |
1260 | ␉␉␉␉␉for( y = 1; y< (font->height); y++)␊ |
1261 | ␉␉␉␉␉{␊ |
1262 | ␉␉␉␉␉␉for( x2 = start, x3 = 0; x2 < end; x2++, x3++)␊ |
1263 | ␉␉␉␉␉␉{␊ |
1264 | ␉␉␉␉␉␉␉pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );␊ |
1265 | ␉␉␉␉␉␉}␉␊ |
1266 | ␉␉␉␉␉}␊ |
1267 | ␉␉␉␉␉␊ |
1268 | ␉␉␉␉␉// check if font is monospaced␊ |
1269 | ␉␉␉␉␉if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )␊ |
1270 | ␉␉␉␉␉␉monospaced = true;␊ |
1271 | ␉␉␉␉␉␉␊ |
1272 | ␉␉␉␉␉font->width = font->chars[count]->width;␊ |
1273 | ␉␉␉␉␉␊ |
1274 | ␉␉␉␉␉count++;␊ |
1275 | ␉␉␉␉}␊ |
1276 | ␉␉␉}␊ |
1277 | ␉␉}␊ |
1278 | ␉}␊ |
1279 | ␊ |
1280 | ␉if(monospaced)␊ |
1281 | ␉␉font->width = 0;␊ |
1282 | ␊ |
1283 | ␉return 0;␊ |
1284 | }␊ |
1285 | ␊ |
1286 | void colorFont(font_t *font, uint32_t color)␊ |
1287 | {␊ |
1288 | ␉if( !color )␊ |
1289 | ␉␉return;␊ |
1290 | ␉␊ |
1291 | ␉int x, y, width, height;␊ |
1292 | ␉int count = 0;␊ |
1293 | ␉pixel_t *buff;␊ |
1294 | ␉␊ |
1295 | ␉while( font->chars[count++] )␊ |
1296 | ␉{␊ |
1297 | ␉␉width = font->chars[count-1]->width;␊ |
1298 | ␉␉height = font->chars[count-1]->height;␊ |
1299 | ␉␉for( y = 0; y < height; y++ )␊ |
1300 | ␉␉{␊ |
1301 | ␉␉␉for( x = 0; x < width; x++ )␊ |
1302 | ␉␉␉{␊ |
1303 | ␉␉␉␉buff = &(pixel( font->chars[count-1], x, y ));␊ |
1304 | ␉␉␉␉if( buff->ch.a )␊ |
1305 | ␉␉␉␉{␊ |
1306 | ␉␉␉␉␉buff->ch.r = (color & 0xFFFF0000) >> 16;␊ |
1307 | ␉␉␉␉␉buff->ch.g = (color & 0xFF00FF00) >> 8;␊ |
1308 | ␉␉␉␉␉buff->ch.b = (color & 0xFF0000FF);␊ |
1309 | ␉␉␉␉}␊ |
1310 | ␉␉␉}␊ |
1311 | ␉␉}␊ |
1312 | ␉}␊ |
1313 | }␊ |
1314 | ␊ |
1315 | void makeRoundedCorners(pixmap_t *p)␊ |
1316 | {␊ |
1317 | ␉int x,y;␊ |
1318 | ␉int width=p->width-1;␊ |
1319 | ␉int height=p->height-1;␊ |
1320 | ␉␊ |
1321 | ␉// 10px rounded corner alpha values␊ |
1322 | ␉uint8_t roundedCorner[10][10] =␊ |
1323 | ␉{␊ |
1324 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},␊ |
1325 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1326 | ␉␉{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1327 | ␉␉{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1328 | ␉␉{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1329 | ␉␉{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1330 | ␉␉{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1331 | ␉␉{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1332 | ␉␉{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1333 | ␉␉{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}␊ |
1334 | ␉};␊ |
1335 | ␉␊ |
1336 | ␉uint8_t alpha=0;␊ |
1337 | ␉␊ |
1338 | ␉for( y=0; y<10; y++)␊ |
1339 | ␉{␊ |
1340 | ␉␉for( x=0; x<10; x++)␊ |
1341 | ␉␉{␊ |
1342 | ␉␉␉// skip if the pixel should be visible␊ |
1343 | ␉␉␉if(roundedCorner[y][x] != 0xFF) ␊ |
1344 | ␉␉␉{ ␊ |
1345 | ␉␉␉␉alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );␊ |
1346 | ␉␉␉␉// Upper left corner␊ |
1347 | ␉␉␉␉pixel(p, x, y).ch.a = alpha;␊ |
1348 | ␊ |
1349 | ␉␉␉␉// upper right corner␊ |
1350 | ␉␉␉␉pixel(p, width-x,y).ch.a = alpha;␊ |
1351 | ␊ |
1352 | ␉␉␉␉// lower left corner␊ |
1353 | ␉␉␉␉pixel(p, x, height-y).ch.a = alpha;␊ |
1354 | ␊ |
1355 | ␉␉␉␉// lower right corner␊ |
1356 | ␉␉␉␉pixel(p, width-x, height-y).ch.a = alpha;␊ |
1357 | ␉␉␉}␊ |
1358 | ␉␉}␊ |
1359 | ␉}␊ |
1360 | }␊ |
1361 | ␊ |
1362 | void showInfoBox(char *title, char *text)␊ |
1363 | {␊ |
1364 | ␉int i, key, lines, visiblelines;␊ |
1365 | ␊ |
1366 | ␉int currentline=0;␊ |
1367 | ␉int cnt=0;␊ |
1368 | ␉int offset=0;␊ |
1369 | ␉␊ |
1370 | ␉if( !title || !text )␊ |
1371 | ␉␉return;␊ |
1372 | ␉␊ |
1373 | ␉position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );␊ |
1374 | ␊ |
1375 | ␉// calculate number of lines in the title␊ |
1376 | ␉for ( i = 0, lines = 1; i<strlen(title); i++ )␊ |
1377 | ␉␉if( title[i] == '\n')␊ |
1378 | ␉␉␉lines++;␊ |
1379 | ␉␊ |
1380 | ␉// y position of text is lines in title * height of font␊ |
1381 | ␉position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));␊ |
1382 | ␉␊ |
1383 | ␉// calculate number of lines in the text␊ |
1384 | ␉for ( i=0, lines = 1; i<strlen(text); i++ )␊ |
1385 | ␉␉if( text[i] == '\n')␊ |
1386 | ␉␉␉lines++;␊ |
1387 | ␉␊ |
1388 | ␉// if text ends with \n strip off␊ |
1389 | ␉if( text[i] == '\n' || text[i] == '\0')␊ |
1390 | ␉␉lines--;␊ |
1391 | ␉␊ |
1392 | ␉visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;␊ |
1393 | ␉␊ |
1394 | ␉// lets display the text and allow scroll thru using up down / arrows␊ |
1395 | ␉while(1)␊ |
1396 | ␉{␊ |
1397 | ␉␉// move to current line in text␊ |
1398 | ␉␉for( offset = 0, i = 0; offset < strlen(text); offset++ )␊ |
1399 | ␉␉{␊ |
1400 | ␉␉␉if( currentline == i)␊ |
1401 | ␉␉␉␉break;␊ |
1402 | ␉␉␉if( text[offset] =='\n')␊ |
1403 | ␉␉␉␉i++;␊ |
1404 | ␉␉}␊ |
1405 | ␊ |
1406 | ␉␉// find last visible line in text and place \0␊ |
1407 | ␉␉for( i = offset, cnt = 0; i < strlen(text); i++)␊ |
1408 | ␉␉{␊ |
1409 | ␉␉␉if(text[i]=='\n')␊ |
1410 | ␉␉␉␉cnt++;␊ |
1411 | ␉␉␉if ( cnt == visiblelines )␊ |
1412 | ␉␉␉{␊ |
1413 | ␉␉␉␉text[i]='\0';␊ |
1414 | ␉␉␉␉break;␊ |
1415 | ␉␉␉}␊ |
1416 | ␉␉}␊ |
1417 | ␉␉␉␉␊ |
1418 | ␉␉fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);␊ |
1419 | ␊ |
1420 | ␉␉makeRoundedCorners( gui.infobox.pixmap);␊ |
1421 | ␉␉␉␊ |
1422 | ␉␉// print the title if present␊ |
1423 | ␉␉if( title )␊ |
1424 | ␉␉␉drawStr(title, &font_console, gui.infobox.pixmap, pos_title);␊ |
1425 | ␊ |
1426 | ␉␉// print the text␊ |
1427 | ␉␉drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);␊ |
1428 | ␊ |
1429 | ␉␉// restore \n in text␊ |
1430 | ␉␉if ( cnt == visiblelines )␊ |
1431 | ␉␉␉text[i] = '\n';␊ |
1432 | ␉␉␊ |
1433 | ␉␉position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );␊ |
1434 | ␉␉␊ |
1435 | ␉␉// draw prev indicator␊ |
1436 | ␉␉if(offset)␊ |
1437 | ␉␉{␊ |
1438 | ␉␉␉blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));␊ |
1439 | ␉␉}␊ |
1440 | ␉␉␊ |
1441 | ␉␉// draw next indicator␊ |
1442 | ␉␉if( lines > ( currentline + visiblelines ) )␊ |
1443 | ␉␉{␊ |
1444 | ␉␉␉pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );␊ |
1445 | ␉␉␉blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );␊ |
1446 | ␉␉}␊ |
1447 | ␊ |
1448 | ␉␉gui.bootprompt.draw = false;␊ |
1449 | ␉␉gui.infobox.draw = true;␊ |
1450 | ␉␉gui.redraw = true;␊ |
1451 | ␉␉␊ |
1452 | ␉␉updateVRAM();␊ |
1453 | ␉␉␊ |
1454 | ␉␉key = getc();␊ |
1455 | ␉␉␉␊ |
1456 | ␉␉if( key == kUpArrowkey )␊ |
1457 | ␉␉␉if( currentline > 0 )␊ |
1458 | ␉␉␉␉currentline--;␊ |
1459 | ␊ |
1460 | ␉␉if( key == kDownArrowkey )␊ |
1461 | ␉␉␉if( lines > ( currentline + visiblelines ) )␊ |
1462 | ␉␉␉␉currentline++;␊ |
1463 | ␊ |
1464 | ␉␉if( key == kEscapeKey || key == 'q' || key == 'Q')␊ |
1465 | ␉␉{␊ |
1466 | ␉␉␉gui.infobox.draw = false;␊ |
1467 | ␉␉␉gui.redraw = true;␊ |
1468 | ␉␉␉updateVRAM();␊ |
1469 | ␉␉␉break;␊ |
1470 | ␉␉}␊ |
1471 | ␉}␊ |
1472 | }␊ |
1473 | ␊ |
1474 | void animateProgressBar()␊ |
1475 | {␊ |
1476 | ␉int y;␊ |
1477 | ␉␊ |
1478 | ␉if( time18() > lasttime)␊ |
1479 | ␉{␊ |
1480 | ␉␉lasttime = time18();␊ |
1481 | ␊ |
1482 | ␉␉pixmap_t *buffBar = images[iProgressBar].image;␊ |
1483 | ␊ |
1484 | ␉␉uint32_t buff = buffBar->pixels[0].value;␊ |
1485 | ␉␊ |
1486 | ␉␉memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );␊ |
1487 | ␊ |
1488 | ␉␉for( y = buffBar->height - 1; y > 0; y--)␊ |
1489 | ␉␉␉pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);␊ |
1490 | ␊ |
1491 | ␉␉pixel(buffBar, buffBar->width-1, 0).value = buff;␊ |
1492 | ␉}␊ |
1493 | }␊ |
1494 | ␊ |
1495 | void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)␊ |
1496 | {␊ |
1497 | ␉if(progress>100)␊ |
1498 | ␉␉return;␊ |
1499 | ␉␊ |
1500 | ␉p.x = ( p.x - ( width / 2 ) );␊ |
1501 | ␊ |
1502 | ␉int todraw = (width * progress) / 100;␊ |
1503 | ␊ |
1504 | ␉pixmap_t *buff = images[iProgressBar].image;␊ |
1505 | ␉pixmap_t *buffBG = images[iProgressBarBackground].image;␊ |
1506 | ␉if(!buff || !buffBG)␊ |
1507 | ␉␉return;␊ |
1508 | ␉␊ |
1509 | ␉pixmap_t progressbar;␊ |
1510 | ␉progressbar.pixels=malloc(width * 4 * buff->height);␊ |
1511 | ␉if(!progressbar.pixels)␊ |
1512 | ␉␉return; ␊ |
1513 | ␉␊ |
1514 | ␉progressbar.width = width;␊ |
1515 | ␉progressbar.height = buff->height;␊ |
1516 | ␊ |
1517 | ␉int x=0,x2=0,y=0;␊ |
1518 | ␉␊ |
1519 | ␉for(y=0; y<buff->height; y++)␊ |
1520 | ␉{␊ |
1521 | ␉␉for(x=0; x<todraw; x++, x2++)␊ |
1522 | ␉␉{␊ |
1523 | ␉␉␉if(x2 == (buff->width-1)) x2=0;␊ |
1524 | ␉␉␉pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;␊ |
1525 | ␉␉}␊ |
1526 | ␉␉x2=0;␊ |
1527 | ␉}␊ |
1528 | ␊ |
1529 | ␉for(y=0; y<buff->height; y++)␊ |
1530 | ␉{␊ |
1531 | ␉␉for(x=todraw, x2 = 0; x < width - 1; x++, x2++)␊ |
1532 | ␉␉{␊ |
1533 | ␉␉␉if(x2 == (buffBG->width -2 )) x2 = 0;␊ |
1534 | ␉␉␉␉pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;␊ |
1535 | ␉␉}␊ |
1536 | ␉␉if(progress < 100)␊ |
1537 | ␉␉␉pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
1538 | ␉␉if(progress == 0)␊ |
1539 | ␉␉␉pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
1540 | ␉␉x2=0;␊ |
1541 | ␉}␊ |
1542 | ␉ ␊ |
1543 | ␉blend(&progressbar, blendInto, p);␊ |
1544 | ␉animateProgressBar();␊ |
1545 | ␉free(progressbar.pixels);␊ |
1546 | }␊ |
1547 | ␊ |
1548 | void drawInfoMenuItems()␊ |
1549 | {␊ |
1550 | ␉int i,n;␊ |
1551 | ␉␊ |
1552 | ␉position_t position;␊ |
1553 | ␉␊ |
1554 | ␉pixmap_t *selection = images[iMenuSelection].image;␊ |
1555 | ␉␊ |
1556 | ␉pixmap_t *pbuff;␊ |
1557 | ␊ |
1558 | ␉fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);␊ |
1559 | ␊ |
1560 | ␉makeRoundedCorners(gui.menu.pixmap);␊ |
1561 | ␉␊ |
1562 | ␉uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;␊ |
1563 | ␊ |
1564 | ␉position = pos(0,0);␊ |
1565 | ␉␊ |
1566 | ␉for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)␊ |
1567 | ␉{␊ |
1568 | ␉␉if (i == infoMenuSelection)␊ |
1569 | ␉␉␉blend(selection, gui.menu.pixmap, position);␊ |
1570 | ␊ |
1571 | ␉␉pbuff = images[n].image;␊ |
1572 | ␉␉if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)␊ |
1573 | ␉␉␉blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap, ␊ |
1574 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
1575 | ␉␉else␊ |
1576 | ␉␉␉blend( pbuff, gui.menu.pixmap, ␊ |
1577 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
1578 | ␊ |
1579 | ␉␉drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap, ␊ |
1580 | ␉␉␉pos(position.x + (pbuff->width + gui.menu.hborder), ␊ |
1581 | ␉␉␉␉position.y + ((selection->height - font_console.height) / 2)));␊ |
1582 | ␉␉position.y += images[iMenuSelection].image->height;␊ |
1583 | ␉␊ |
1584 | ␉}␊ |
1585 | ␉␊ |
1586 | ␉gui.redraw = true;␊ |
1587 | }␊ |
1588 | ␊ |
1589 | int drawInfoMenu()␊ |
1590 | {␊ |
1591 | ␉drawInfoMenuItems();␊ |
1592 | ␊ |
1593 | ␉gui.menu.draw = true;␊ |
1594 | ␊ |
1595 | ␉updateVRAM();␊ |
1596 | ␉␊ |
1597 | ␉return 1;␊ |
1598 | }␊ |
1599 | ␊ |
1600 | int updateInfoMenu(int key)␊ |
1601 | {␊ |
1602 | ␉switch (key)␊ |
1603 | ␉{␊ |
1604 | ␊ |
1605 | ␉␉case kUpArrowkey:␉// up arrow␊ |
1606 | ␉␉␉␉if (infoMenuSelection > 0)␊ |
1607 | ␉␉␉␉{␊ |
1608 | ␉␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)␊ |
1609 | ␉␉␉␉␉␉infoMenuSelection -= 4;␊ |
1610 | ␉␉␉␉␉␊ |
1611 | ␉␉␉␉␉else␊ |
1612 | ␉␉␉␉␉␉infoMenuSelection--;␊ |
1613 | ␉␉␉␉␉␉drawInfoMenuItems();␊ |
1614 | ␉␉␉␉␉␉updateVRAM();␊ |
1615 | ␉␉␉␉␉␊ |
1616 | ␉␉␉␉} else {␊ |
1617 | ␉␉␉␉␉␊ |
1618 | ␉␉␉␉␉gui.menu.draw = false;␊ |
1619 | ␉␉␉␉␉gui.redraw = true;␊ |
1620 | ␊ |
1621 | ␉␉␉␉␉updateVRAM();␊ |
1622 | ␉␉␉␉␉␊ |
1623 | ␉␉␉␉␉return CLOSE_INFO_MENU;␊ |
1624 | ␉␉␉␉}␊ |
1625 | ␉␉␉␉break;␊ |
1626 | ␊ |
1627 | ␉␉case kDownArrowkey:␉// down arrow␊ |
1628 | ␉␉␉␉if (infoMenuSelection < infoMenuItemsCount - 1)␊ |
1629 | ␉␉␉␉{␊ |
1630 | ␉␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)␊ |
1631 | ␉␉␉␉␉␉infoMenuSelection += 4;␊ |
1632 | ␉␉␉␉␉else␊ |
1633 | ␉␉␉␉␉␉infoMenuSelection++;␊ |
1634 | ␉␉␉␉␉drawInfoMenuItems();␊ |
1635 | ␉␉␉␉␉updateVRAM();␊ |
1636 | ␉␉␉␉}␊ |
1637 | ␉␉␉␉break;␊ |
1638 | ␊ |
1639 | ␉␉case kReturnKey:␊ |
1640 | ␉␉␉␉key = 0;␊ |
1641 | ␉␉␉␉if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )␊ |
1642 | ␉␉␉␉␉showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());␊ |
1643 | ␊ |
1644 | ␉␉␉␉else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )␊ |
1645 | ␉␉␉␉␉showInfoBox( getVBEInfoString(), getVBEModeInfoString() );␊ |
1646 | ␉␉␉␊ |
1647 | ␉␉␉␉else if( infoMenuSelection == MENU_SHOW_HELP )␊ |
1648 | ␉␉␉␉␉showHelp();␊ |
1649 | ␉␉␉␉␉␊ |
1650 | ␉␉␉␉else␊ |
1651 | ␉␉␉␉{␊ |
1652 | ␉␉␉␉␉int buff = infoMenuSelection;␊ |
1653 | ␉␉␉␉␉infoMenuSelection = 0;␊ |
1654 | ␉␉␉␉␉return buff;␊ |
1655 | ␉␉␉␉}␊ |
1656 | ␉␉␉␉break;␊ |
1657 | ␉␉}␊ |
1658 | ␉return DO_NOT_BOOT;␊ |
1659 | }␊ |
1660 | ␊ |
1661 | uint16_t bootImageWidth = 0; ␊ |
1662 | uint16_t bootImageHeight = 0; ␊ |
1663 | uint8_t *bootImageData = NULL; ␊ |
1664 | static bool usePngImage = true;␊ |
1665 | ␊ |
1666 | //==========================================================================␊ |
1667 | // loadBootGraphics␊ |
1668 | static void loadBootGraphics(void)␊ |
1669 | {␊ |
1670 | ␉if (bootImageData != NULL) {␊ |
1671 | ␉␉return;␊ |
1672 | ␉}␊ |
1673 | ␊ |
1674 | ␉char dirspec[256];␊ |
1675 | ␊ |
1676 | ␉if ((strlen(theme_name) + 24) > sizeof(dirspec)) {␊ |
1677 | ␉␉usePngImage = false; ␊ |
1678 | ␉␉return;␊ |
1679 | ␉}␊ |
1680 | ␉sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);␊ |
1681 | ␉if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {␊ |
1682 | #ifdef EMBED_THEME␊ |
1683 | ␉if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)␊ |
1684 | #endif␊ |
1685 | ␉␉usePngImage = false; ␊ |
1686 | ␉}␊ |
1687 | }␊ |
1688 | ␊ |
1689 | //==========================================================================␊ |
1690 | // drawBootGraphics␊ |
1691 | void drawBootGraphics(void)␊ |
1692 | {␊ |
1693 | ␉//int pos;␊ |
1694 | ␉int length;␊ |
1695 | ␉const char *dummyVal;␊ |
1696 | ␉bool legacy_logo;␊ |
1697 | ␉uint16_t x, y; ␊ |
1698 | ␉␊ |
1699 | ␉if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->bootConfig) && legacy_logo) {␊ |
1700 | ␉␉usePngImage = false; ␊ |
1701 | ␉} else if (bootImageData == NULL) {␊ |
1702 | ␉␉loadBootGraphics();␊ |
1703 | ␉}␊ |
1704 | ␊ |
1705 | ␉/*␊ |
1706 | ␉// parse screen size parameters␊ |
1707 | ␉if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig)) {␊ |
1708 | ␉␉screen_params[0] = pos;␊ |
1709 | ␉} else {␊ |
1710 | ␉␉screen_params[0] = DEFAULT_SCREEN_WIDTH;␊ |
1711 | ␉}␊ |
1712 | ␉if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig)) {␊ |
1713 | ␉␉screen_params[1] = pos;␊ |
1714 | ␉} else {␊ |
1715 | ␉␉screen_params[1] = DEFAULT_SCREEN_HEIGHT;␊ |
1716 | ␉}␊ |
1717 | ␉screen_params[2] = 32;␊ |
1718 | ␉*/␊ |
1719 | ␉␊ |
1720 | ␉getResolution(&screen_params[0], &screen_params[1], &screen_params[2]);␊ |
1721 | ␊ |
1722 | ␊ |
1723 | ␉gui.screen.width = screen_params[0];␊ |
1724 | ␉gui.screen.height = screen_params[1];␊ |
1725 | ␊ |
1726 | ␉// find best matching vesa mode for our requested width & height␊ |
1727 | ␉getGraphicModeParams(screen_params);␊ |
1728 | ␊ |
1729 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
1730 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
1731 | ␉}␊ |
1732 | ␉␊ |
1733 | ␉if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) {␊ |
1734 | ␉␉drawCheckerBoard();␊ |
1735 | ␉} else {␊ |
1736 | ␉␉// Fill the background to 75% grey (same as BootX). ␊ |
1737 | ␉␉drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01); ␊ |
1738 | ␉}␊ |
1739 | ␉if ((bootImageData) && (usePngImage)) { ␊ |
1740 | ␉␉x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2; ␊ |
1741 | ␉␉y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2; ␊ |
1742 | ␊ |
1743 | ␉␉// Draw the image in the center of the display. ␊ |
1744 | ␉␉blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData); ␊ |
1745 | ␉} else { ␊ |
1746 | ␉␉uint8_t *appleBootPict; ␊ |
1747 | ␉␉bootImageData = NULL; ␊ |
1748 | ␉␉bootImageWidth = kAppleBootWidth; ␊ |
1749 | ␉␉bootImageHeight = kAppleBootHeight; ␊ |
1750 | ␊ |
1751 | ␉␉// Prepare the data for the default Apple boot image. ␊ |
1752 | ␉␉appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight); ␊ |
1753 | ␉␉if (appleBootPict) { ␊ |
1754 | ␉␉␉convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData); ␊ |
1755 | ␉␉␉if (bootImageData) {␉␊ |
1756 | ␉␉␉␉x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2; ␊ |
1757 | ␉␉␉␉y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2; ␊ |
1758 | ␉␉␉␉drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);␊ |
1759 | ␉␉␉␉free(bootImageData);␊ |
1760 | ␉␉␉}␊ |
1761 | ␉␉␉free(appleBootPict); ␊ |
1762 | ␉␉} ␊ |
1763 | ␉} ␊ |
1764 | }␊ |
1765 |