/* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2006,2007,2008,2009,2013 Free Software Foundation, Inc. * * VAS_EBOOT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VAS_EBOOT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAS_EBOOT. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include VAS_EBOOT_MOD_LICENSE ("GPLv3+"); /* Option array indices. */ enum { BACKGROUND_CMD_ARGINDEX_MODE = 0 }; static const struct VasEBoot_arg_option background_image_cmd_options[] = { {"mode", 'm', 0, N_("Background image mode."), /* TRANSLATORS: This refers to background image mode (stretched or in left-top corner). Note that VAS_EBOOT will accept only original keywords stretch and normal, not the translated ones. So please put both in translation e.g. stretch(=%STRETCH%)|normal(=%NORMAL%). The percents mark the translated version. Since many people may not know the word stretch or normal I recommend putting the translation either here or in "Background image mode." string. */ N_("stretch|normal"), ARG_TYPE_STRING}, {0, 0, 0, 0, 0, 0} }; static VasEBoot_err_t VasEBoot_gfxterm_background_image_cmd (VasEBoot_extcmd_context_t ctxt, int argc, char **args) { struct VasEBoot_arg_list *state = ctxt->state; /* Check that we have video adapter active. */ if (VasEBoot_video_get_info(NULL) != VAS_EBOOT_ERR_NONE) return VasEBoot_errno; /* Destroy existing background bitmap if loaded. */ if (VasEBoot_gfxterm_background.bitmap) { VasEBoot_video_bitmap_destroy (VasEBoot_gfxterm_background.bitmap); VasEBoot_gfxterm_background.bitmap = 0; VasEBoot_gfxterm_background.blend_text_bg = 0; /* Mark whole screen as dirty. */ VasEBoot_gfxterm_schedule_repaint (); } /* If filename was provided, try to load that. */ if (argc >= 1) { /* Try to load new one. */ VasEBoot_video_bitmap_load (&VasEBoot_gfxterm_background.bitmap, args[0]); if (VasEBoot_errno != VAS_EBOOT_ERR_NONE) return VasEBoot_errno; /* Determine if the bitmap should be scaled to fit the screen. */ if (!state[BACKGROUND_CMD_ARGINDEX_MODE].set || VasEBoot_strcmp (state[BACKGROUND_CMD_ARGINDEX_MODE].arg, "stretch") == 0) { unsigned int width, height; VasEBoot_gfxterm_get_dimensions (&width, &height); if (width != VasEBoot_video_bitmap_get_width (VasEBoot_gfxterm_background.bitmap) || height != VasEBoot_video_bitmap_get_height (VasEBoot_gfxterm_background.bitmap)) { struct VasEBoot_video_bitmap *scaled_bitmap; VasEBoot_video_bitmap_create_scaled (&scaled_bitmap, width, height, VasEBoot_gfxterm_background.bitmap, VAS_EBOOT_VIDEO_BITMAP_SCALE_METHOD_BEST); if (VasEBoot_errno == VAS_EBOOT_ERR_NONE) { /* Replace the original bitmap with the scaled one. */ VasEBoot_video_bitmap_destroy (VasEBoot_gfxterm_background.bitmap); VasEBoot_gfxterm_background.bitmap = scaled_bitmap; } } } /* If bitmap was loaded correctly, display it. */ if (VasEBoot_gfxterm_background.bitmap) { VasEBoot_gfxterm_background.blend_text_bg = 1; /* Mark whole screen as dirty. */ VasEBoot_gfxterm_schedule_repaint (); } } /* All was ok. */ VasEBoot_errno = VAS_EBOOT_ERR_NONE; return VasEBoot_errno; } static VasEBoot_err_t VasEBoot_gfxterm_background_color_cmd (VasEBoot_command_t cmd __attribute__ ((unused)), int argc, char **args) { if (argc != 1) return VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, N_("one argument expected")); /* Check that we have video adapter active. */ if (VasEBoot_video_get_info (NULL) != VAS_EBOOT_ERR_NONE) return VasEBoot_errno; if (VasEBoot_video_parse_color (args[0], &VasEBoot_gfxterm_background.default_bg_color) != VAS_EBOOT_ERR_NONE) return VasEBoot_errno; /* Destroy existing background bitmap if loaded. */ if (VasEBoot_gfxterm_background.bitmap) { VasEBoot_video_bitmap_destroy (VasEBoot_gfxterm_background.bitmap); VasEBoot_gfxterm_background.bitmap = 0; /* Mark whole screen as dirty. */ VasEBoot_gfxterm_schedule_repaint (); } /* Set the background and border colors. The background color needs to be compatible with the text layer. */ VasEBoot_gfxterm_video_update_color (); VasEBoot_gfxterm_background.blend_text_bg = 1; /* Mark whole screen as dirty. */ VasEBoot_gfxterm_schedule_repaint (); return VAS_EBOOT_ERR_NONE; } static VasEBoot_extcmd_t background_image_cmd_handle; static VasEBoot_command_t background_color_cmd_handle; VAS_EBOOT_MOD_INIT(gfxterm_background) { background_image_cmd_handle = VasEBoot_register_extcmd ("background_image", VasEBoot_gfxterm_background_image_cmd, 0, N_("[-m (stretch|normal)] FILE"), N_("Load background image for active terminal."), background_image_cmd_options); background_color_cmd_handle = VasEBoot_register_command ("background_color", VasEBoot_gfxterm_background_color_cmd, N_("COLOR"), N_("Set background color for active terminal.")); } VAS_EBOOT_MOD_FINI(gfxterm_background) { VasEBoot_unregister_command (background_color_cmd_handle); VasEBoot_unregister_extcmd (background_image_cmd_handle); }