Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / term / gfxterm_background.c
blob8da71a8c8b94ef552bc3cea2e0614d6f1981713b
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2006,2007,2008,2009,2013 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #include <grub/term.h>
20 #include <grub/types.h>
21 #include <grub/dl.h>
22 #include <grub/misc.h>
23 #include <grub/font.h>
24 #include <grub/mm.h>
25 #include <grub/env.h>
26 #include <grub/video.h>
27 #include <grub/gfxterm.h>
28 #include <grub/bitmap.h>
29 #include <grub/command.h>
30 #include <grub/extcmd.h>
31 #include <grub/bitmap_scale.h>
32 #include <grub/i18n.h>
33 #include <grub/color.h>
35 GRUB_MOD_LICENSE ("GPLv3+");
37 /* Option array indices. */
38 enum
40 BACKGROUND_CMD_ARGINDEX_MODE = 0
43 static const struct grub_arg_option background_image_cmd_options[] =
45 {"mode", 'm', 0, N_("Background image mode."),
46 /* TRANSLATORS: This refers to background image mode (stretched or
47 in left-top corner). Note that GRUB will accept only original
48 keywords stretch and normal, not the translated ones.
49 So please put both in translation
50 e.g. stretch(=%STRETCH%)|normal(=%NORMAL%).
51 The percents mark the translated version. Since many people
52 may not know the word stretch or normal I recommend
53 putting the translation either here or in "Background image mode."
54 string. */
55 N_("stretch|normal"),
56 ARG_TYPE_STRING},
57 {0, 0, 0, 0, 0, 0}
60 static grub_err_t
61 grub_gfxterm_background_image_cmd (grub_extcmd_context_t ctxt,
62 int argc, char **args)
64 struct grub_arg_list *state = ctxt->state;
66 /* Check that we have video adapter active. */
67 if (grub_video_get_info(NULL) != GRUB_ERR_NONE)
68 return grub_errno;
70 /* Destroy existing background bitmap if loaded. */
71 if (grub_gfxterm_background.bitmap)
73 grub_video_bitmap_destroy (grub_gfxterm_background.bitmap);
74 grub_gfxterm_background.bitmap = 0;
75 grub_gfxterm_background.blend_text_bg = 0;
77 /* Mark whole screen as dirty. */
78 grub_gfxterm_schedule_repaint ();
81 /* If filename was provided, try to load that. */
82 if (argc >= 1)
84 /* Try to load new one. */
85 grub_video_bitmap_load (&grub_gfxterm_background.bitmap, args[0]);
86 if (grub_errno != GRUB_ERR_NONE)
87 return grub_errno;
89 /* Determine if the bitmap should be scaled to fit the screen. */
90 if (!state[BACKGROUND_CMD_ARGINDEX_MODE].set
91 || grub_strcmp (state[BACKGROUND_CMD_ARGINDEX_MODE].arg,
92 "stretch") == 0)
94 unsigned int width, height;
95 grub_gfxterm_get_dimensions (&width, &height);
96 if (width
97 != grub_video_bitmap_get_width (grub_gfxterm_background.bitmap)
98 || height
99 != grub_video_bitmap_get_height (grub_gfxterm_background.bitmap))
101 struct grub_video_bitmap *scaled_bitmap;
102 grub_video_bitmap_create_scaled (&scaled_bitmap,
103 width,
104 height,
105 grub_gfxterm_background.bitmap,
106 GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST);
107 if (grub_errno == GRUB_ERR_NONE)
109 /* Replace the original bitmap with the scaled one. */
110 grub_video_bitmap_destroy (grub_gfxterm_background.bitmap);
111 grub_gfxterm_background.bitmap = scaled_bitmap;
116 /* If bitmap was loaded correctly, display it. */
117 if (grub_gfxterm_background.bitmap)
119 grub_gfxterm_background.blend_text_bg = 1;
121 /* Mark whole screen as dirty. */
122 grub_gfxterm_schedule_repaint ();
126 /* All was ok. */
127 grub_errno = GRUB_ERR_NONE;
128 return grub_errno;
131 static grub_err_t
132 grub_gfxterm_background_color_cmd (grub_command_t cmd __attribute__ ((unused)),
133 int argc, char **args)
135 if (argc != 1)
136 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
138 /* Check that we have video adapter active. */
139 if (grub_video_get_info (NULL) != GRUB_ERR_NONE)
140 return grub_errno;
142 if (grub_video_parse_color (args[0],
143 &grub_gfxterm_background.default_bg_color)
144 != GRUB_ERR_NONE)
145 return grub_errno;
147 /* Destroy existing background bitmap if loaded. */
148 if (grub_gfxterm_background.bitmap)
150 grub_video_bitmap_destroy (grub_gfxterm_background.bitmap);
151 grub_gfxterm_background.bitmap = 0;
153 /* Mark whole screen as dirty. */
154 grub_gfxterm_schedule_repaint ();
157 /* Set the background and border colors. The background color needs to be
158 compatible with the text layer. */
159 grub_gfxterm_video_update_color ();
160 grub_gfxterm_background.blend_text_bg = 1;
162 /* Mark whole screen as dirty. */
163 grub_gfxterm_schedule_repaint ();
165 return GRUB_ERR_NONE;
168 static grub_extcmd_t background_image_cmd_handle;
169 static grub_command_t background_color_cmd_handle;
171 GRUB_MOD_INIT(gfxterm_background)
173 background_image_cmd_handle =
174 grub_register_extcmd ("background_image",
175 grub_gfxterm_background_image_cmd, 0,
176 N_("[-m (stretch|normal)] FILE"),
177 N_("Load background image for active terminal."),
178 background_image_cmd_options);
179 background_color_cmd_handle =
180 grub_register_command ("background_color",
181 grub_gfxterm_background_color_cmd,
182 N_("COLOR"),
183 N_("Set background color for active terminal."));
186 GRUB_MOD_FINI(gfxterm_background)
188 grub_unregister_command (background_color_cmd_handle);
189 grub_unregister_extcmd (background_image_cmd_handle);