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