mirror of
https://github.com/limine-bootloader/limine
synced 2024-11-23 09:02:11 +03:00
image: Add support for centering images
This commit is contained in:
parent
bf9962e86f
commit
91f0600e6b
@ -51,7 +51,7 @@ Some keys take *URIs* as values; these are described in the next section.
|
||||
*Globally assignable* keys are:
|
||||
* `TIMEOUT` - Specifies the timeout in seconds before the first *entry* is automatically booted. If set to `no`, disable automatic boot. If set to `0`, boots default entry instantly (see `DEFAULT_ENTRY` key).
|
||||
* `DEFAULT_ENTRY` - 1-based entry index of the entry which will be automatically selected at startup. If unspecified, it is `1`.
|
||||
* `GRAPHICS` - If set to `yes`, do use graphical VESA framebuffer for the boot menu, else use text mode. Ignored with Limine UEFI.
|
||||
* `GRAPHICS` - If set to `yes`, use a graphical framebuffer for the boot menu, else use text mode. Ignored with Limine UEFI, forced to `yes`.
|
||||
* `MENU_RESOLUTION` - Specify screen resolution to be used by the Limine menu in the form `<width>x<height>`. This will *only* affect the menu, not any booted OS. If not specified, Limine will pick a resolution automatically. If the resolution is not available, Limine will pick another one automatically. Ignored if `GRAPHICS` is not `yes`.
|
||||
* `MENU_BRANDING` - A string that will be displayed on top of the Limine menu.
|
||||
* `MENU_FONT` - URI path to a font file to be used instead of the default one for the menu. The font file must be a code page 437 character set comprised of 256 consecutive 8x16 glyphs bitmaps (4096 byte font file). Each glyph's bitmap must be expressed left to right (1 byte per row), and top to bottom (16 bytes per whole glyph).
|
||||
@ -60,6 +60,9 @@ Some keys take *URIs* as values; these are described in the next section.
|
||||
* `THEME_MARGIN` - Set the amount of margin around the terminal. Ignored if `GRAPHICS` is not `yes`.
|
||||
* `THEME_MARGIN_GRADIENT` - Set the thickness in pixel for the gradient around the terminal. Ignored if `GRAPHICS` is not `yes`.
|
||||
* `BACKGROUND_PATH` - URI where to find the background .BMP file. Ignored if `GRAPHICS` is not `yes`.
|
||||
* `BACKGROUND_STYLE` - The style which will be used to display the background image. Either `tiled` or `centered`. Default is `tiled`.
|
||||
* `BACKDROP_COLOUR` - When the background style is `centered`, this specifies the colour of the backdrop for parts of the screen not covered by the background image, in RRGGBB format.
|
||||
* `BACKDROP_COLOR` - Alias of `BACKDROP_COLOUR`.
|
||||
|
||||
*Locally assignable (non protocol specific)* keys are:
|
||||
* `PROTOCOL` - The boot protocol that will be used to boot the kernel. Valid protocols are: `linux`, `stivale`, `stivale2`, `chainload`.
|
||||
|
@ -38,8 +38,20 @@ static uint32_t get_pixel(struct image *this, int x, int y) {
|
||||
struct bmp_local *local = this->local;
|
||||
struct bmp_header *header = &local->header;
|
||||
|
||||
x %= header->bi_width;
|
||||
y %= header->bi_height;
|
||||
switch (this->type) {
|
||||
case IMAGE_TILED: {
|
||||
x %= header->bi_width;
|
||||
y %= header->bi_height;
|
||||
break;
|
||||
}
|
||||
case IMAGE_CENTERED: {
|
||||
x -= this->x_displacement;
|
||||
y -= this->y_displacement;
|
||||
if (x < 0 || y < 0 || x >= this->x_size || y >= this->y_size)
|
||||
return this->back_colour;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
size_t pixel_offset = local->pitch * (header->bi_height - y - 1) + x * (header->bi_bpp / 8);
|
||||
|
||||
|
@ -5,11 +5,21 @@
|
||||
#include <mm/pmm.h>
|
||||
#include <lib/bmp.h>
|
||||
|
||||
void image_make_centered(struct image *image, int frame_x_size, int frame_y_size, uint32_t back_colour) {
|
||||
image->type = IMAGE_CENTERED;
|
||||
|
||||
image->x_displacement = frame_x_size / 2 - image->x_size / 2;
|
||||
image->y_displacement = frame_y_size / 2 - image->y_size / 2;
|
||||
image->back_colour = back_colour;
|
||||
}
|
||||
|
||||
int open_image(struct image *image, struct file_handle *file) {
|
||||
image->file = file;
|
||||
|
||||
if (!bmp_open_image(image, file))
|
||||
return 0;
|
||||
|
||||
image->type = IMAGE_TILED;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -8,10 +8,20 @@ struct image {
|
||||
struct file_handle *file;
|
||||
int x_size;
|
||||
int y_size;
|
||||
int type;
|
||||
int x_displacement;
|
||||
int y_displacement;
|
||||
uint32_t back_colour;
|
||||
uint32_t (*get_pixel)(struct image *this, int x, int y);
|
||||
void *local;
|
||||
};
|
||||
|
||||
enum {
|
||||
IMAGE_TILED,
|
||||
IMAGE_CENTERED
|
||||
};
|
||||
|
||||
void image_make_centered(struct image *image, int frame_x_size, int frame_y_size, uint32_t back_colour);
|
||||
int open_image(struct image *image, struct file_handle *file);
|
||||
|
||||
#endif
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <lib/libc.h>
|
||||
#include <lib/config.h>
|
||||
#include <lib/term.h>
|
||||
#include <lib/gterm.h>
|
||||
#include <lib/readline.h>
|
||||
#include <lib/uri.h>
|
||||
#include <mm/pmm.h>
|
||||
@ -431,6 +432,21 @@ char *menu(char **cmdline) {
|
||||
bg = NULL;
|
||||
|
||||
nobg:
|
||||
term_vbe(colourscheme, margin, margin_gradient, NULL);
|
||||
|
||||
if (bg != NULL) {
|
||||
char *background_layout = config_get_value(NULL, 0, "BACKGROUND_STYLE");
|
||||
if (background_layout != NULL && strcmp(background_layout, "centered") == 0) {
|
||||
char *background_colour = config_get_value(NULL, 0, "BACKDROP_COLOUR");
|
||||
if (background_colour == NULL)
|
||||
background_colour = config_get_value(NULL, 0, "BACKDROP_COLOR");
|
||||
if (background_colour == NULL)
|
||||
background_colour = "0";
|
||||
uint32_t bg_col = strtoui(background_colour, NULL, 16);
|
||||
image_make_centered(bg, fbinfo.framebuffer_width, fbinfo.framebuffer_height, bg_col);
|
||||
}
|
||||
}
|
||||
|
||||
term_vbe(colourscheme, margin, margin_gradient, bg);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,8 @@ THEME_COLOURS=000000;aa0000;00aaff;aa5500;0000aa;aa00aa;9076de;aaaaaa;60000000;a
|
||||
THEME_MARGIN=64
|
||||
|
||||
BACKGROUND_PATH=boot:///boot/bg.bmp
|
||||
BACKGROUND_STYLE=centered
|
||||
BACKDROP_COLOUR=008080
|
||||
|
||||
:Stivale2 Test
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user