From 82645fe6a10be1a40b8a2a7591b2941c14f299c0 Mon Sep 17 00:00:00 2001 From: yunusey Date: Mon, 6 Jan 2025 14:08:20 -0500 Subject: [PATCH] Add anchor options --- src/config/Config.zig | 12 ++++++++++++ src/renderer/shaders/bgimage.v.glsl | 30 ++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index e6dca80054..761790f2c2 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -466,6 +466,14 @@ foreground: Color = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF }, /// * `tiled` - Image is repeated horizontally and vertically to fill the window. /// * `centered` - Image is centered in the window and displayed 1-to-1 pixel /// scale, preserving both the aspect ratio and the image size. +/// * `upper-left` - Image is anchored to the upper left corner of the window, +/// preserving the aspect ratio. +/// * `upper-right` - Image is anchored to the upper right corner of the window, +/// preserving the aspect ratio. +/// * `lower-left` - Image is anchored to the lower left corner of the window, +/// preserving the aspect ratio. +/// * `lower-right` - Image is anchored to the lower right corner of the window, +/// preserving the aspect ratio. /// @"background-image-mode": BackgroundImageMode = .zoomed, @@ -5917,6 +5925,10 @@ pub const BackgroundImageMode = enum(u8) { stretched = 1, tiled = 2, centered = 3, + upper_left = 4, + upper_right = 5, + lower_left = 6, + lower_right = 7, }; /// See freetype-load-flag diff --git a/src/renderer/shaders/bgimage.v.glsl b/src/renderer/shaders/bgimage.v.glsl index 1d0b5fe760..0834b7c297 100644 --- a/src/renderer/shaders/bgimage.v.glsl +++ b/src/renderer/shaders/bgimage.v.glsl @@ -7,6 +7,10 @@ const uint MODE_ZOOMED = 0u; const uint MODE_STRETCHED = 1u; const uint MODE_TILED = 2u; const uint MODE_CENTERED = 3u; +const uint MODE_UPPER_LEFT = 4u; +const uint MODE_UPPER_RIGHT = 5u; +const uint MODE_LOWER_LEFT = 6u; +const uint MODE_LOWER_RIGHT = 7u; layout (location = 0) in vec2 terminal_size; layout (location = 1) in uint mode; @@ -43,6 +47,10 @@ void main() { } break; case MODE_CENTERED: + case MODE_UPPER_LEFT: + case MODE_UPPER_RIGHT: + case MODE_LOWER_LEFT: + case MODE_LOWER_RIGHT: // If centered, the final scale of the image should match the actual // size of the image and should be centered scale.x = image_size.x / terminal_size.x; @@ -55,7 +63,27 @@ void main() { } vec2 final_image_size = terminal_size * position * scale; - vec2 offset = (terminal_size * (1.0 - scale)) / 2.0; + vec2 offset = vec2(0.0, 0.0); + switch (mode) { + case MODE_ZOOMED: + case MODE_STRETCHED: + case MODE_TILED: + case MODE_CENTERED: + offset = (terminal_size * (1.0 - scale)) / 2.0; + break; + case MODE_UPPER_LEFT: + offset = vec2(0.0, 0.0); + break; + case MODE_UPPER_RIGHT: + offset = vec2(terminal_size.x - image_size.x, 0.0); + break; + case MODE_LOWER_LEFT: + offset = vec2(0.0, terminal_size.y - image_size.y); + break; + case MODE_LOWER_RIGHT: + offset = vec2(terminal_size.x - image_size.x, terminal_size.y - image_size.y); + break; + } gl_Position = projection * vec4(final_image_size.xy + offset, 0.0, 1.0); tex_coord = position; if (mode == MODE_TILED) {