From 72eef89b259082da2e1748643f3f8856f4715d34 Mon Sep 17 00:00:00 2001 From: yunusey Date: Sat, 24 May 2025 00:05:49 -0400 Subject: [PATCH] Rename background image modes aligned with the CSS standards --- src/config/Config.zig | 30 ++++++------- .../opengl/BackgroundImageProgram.zig | 2 +- src/renderer/shaders/bgimage.v.glsl | 42 +++++++++---------- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index 6e4ad2f4f..810818a33 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -469,23 +469,23 @@ foreground: Color = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF }, /// /// Valid values are: /// -/// * `zoomed` - Image is scaled to fit the window, preserving aspect ratio. -/// * `stretched` - Image is stretched to fill the window, not preserving aspect ratio. -/// * `cropped` - Image is centered in the window, preserving the aspect ratio +/// * `contain` - Image is scaled to fit the window, preserving aspect ratio. +/// * `fill` - Image is stretched to fill the window, not preserving aspect ratio. +/// * `cover` - Image is centered in the window, preserving the aspect ratio /// but cropping the image to fill the window, as needed. /// * `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, +/// * `top-left` - Image is anchored to the top left corner of the window, /// preserving the aspect ratio. -/// * `upper-right` - Image is anchored to the upper right corner of the window, +/// * `top-right` - Image is anchored to the top right corner of the window, /// preserving the aspect ratio. -/// * `lower-left` - Image is anchored to the lower left corner of the window, +/// * `bottom-left` - Image is anchored to the bottom left corner of the window, /// preserving the aspect ratio. -/// * `lower-right` - Image is anchored to the lower right corner of the window, +/// * `bottom-right` - Image is anchored to the bottom right corner of the window, /// preserving the aspect ratio. /// -@"background-image-mode": BackgroundImageMode = .zoomed, +@"background-image-mode": BackgroundImageMode = .contain, /// The foreground and background color for selection. If this is not set, then /// the selection color is just the inverted window background and foreground @@ -6330,15 +6330,15 @@ pub const AlphaBlending = enum { /// in sync with the values in the vertex shader used to render the /// background image (`bgimage`). pub const BackgroundImageMode = enum(u8) { - zoomed = 0, - stretched = 1, - cropped = 2, + contain = 0, + fill = 1, + cover = 2, tiled = 3, centered = 4, - upper_left = 5, - upper_right = 6, - lower_left = 7, - lower_right = 8, + @"top-left" = 5, + @"top-right" = 6, + @"bottom-left" = 7, + @"bottom-right" = 8, }; /// See freetype-load-flag diff --git a/src/renderer/opengl/BackgroundImageProgram.zig b/src/renderer/opengl/BackgroundImageProgram.zig index d73c2b98e..575df649d 100644 --- a/src/renderer/opengl/BackgroundImageProgram.zig +++ b/src/renderer/opengl/BackgroundImageProgram.zig @@ -11,7 +11,7 @@ pub const Input = extern struct { terminal_height: u32 = 0, /// uint mode - mode: configpkg.BackgroundImageMode = .zoomed, + mode: configpkg.BackgroundImageMode = .contain, }; program: gl.Program, diff --git a/src/renderer/shaders/bgimage.v.glsl b/src/renderer/shaders/bgimage.v.glsl index f83096ecd..f816807b4 100644 --- a/src/renderer/shaders/bgimage.v.glsl +++ b/src/renderer/shaders/bgimage.v.glsl @@ -3,15 +3,15 @@ // These are the possible modes that "mode" can be set to. // // NOTE: this must be kept in sync with the BackgroundImageMode -const uint MODE_ZOOMED = 0u; -const uint MODE_STRETCHED = 1u; -const uint MODE_CROPPED = 2u; +const uint MODE_CONTAIN = 0u; +const uint MODE_FILL = 1u; +const uint MODE_COVER = 2u; const uint MODE_TILED = 3u; const uint MODE_CENTERED = 4u; -const uint MODE_UPPER_LEFT = 5u; -const uint MODE_UPPER_RIGHT = 6u; -const uint MODE_LOWER_LEFT = 7u; -const uint MODE_LOWER_RIGHT = 8u; +const uint MODE_TOP_LEFT = 5u; +const uint MODE_TOP_RIGHT = 6u; +const uint MODE_BOTTOM_LEFT = 7u; +const uint MODE_BOTTOM_RIGHT = 8u; layout (location = 0) in vec2 terminal_size; layout (location = 1) in uint mode; @@ -40,7 +40,7 @@ void main() { ); switch (mode) { - case MODE_ZOOMED: + case MODE_CONTAIN: // If zoomed, we want to scale the image to fit the terminal if (aspect_ratio.x > aspect_ratio.y) { scale.x = aspect_ratio.y / aspect_ratio.x; @@ -49,7 +49,7 @@ void main() { scale.y = aspect_ratio.x / aspect_ratio.y; } break; - case MODE_CROPPED: + case MODE_COVER: // If cropped, we want to scale the image to fit the terminal if (aspect_ratio.x < aspect_ratio.y) { scale.x = aspect_ratio.y / aspect_ratio.x; @@ -59,16 +59,16 @@ void main() { } break; case MODE_CENTERED: - case MODE_UPPER_LEFT: - case MODE_UPPER_RIGHT: - case MODE_LOWER_LEFT: - case MODE_LOWER_RIGHT: + case MODE_TOP_LEFT: + case MODE_TOP_RIGHT: + case MODE_BOTTOM_LEFT: + case MODE_BOTTOM_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; scale.y = image_size.y / terminal_size.y; break; - case MODE_STRETCHED: + case MODE_FILL: case MODE_TILED: // We don't need to do anything for stretched or tiled break; @@ -77,23 +77,23 @@ void main() { vec2 final_image_size = terminal_size * position * scale; vec2 offset = vec2(0.0, 0.0); switch (mode) { - case MODE_ZOOMED: - case MODE_STRETCHED: - case MODE_CROPPED: + case MODE_CONTAIN: + case MODE_FILL: + case MODE_COVER: case MODE_TILED: case MODE_CENTERED: offset = (terminal_size * (1.0 - scale)) / 2.0; break; - case MODE_UPPER_LEFT: + case MODE_TOP_LEFT: offset = vec2(0.0, 0.0); break; - case MODE_UPPER_RIGHT: + case MODE_TOP_RIGHT: offset = vec2(terminal_size.x - image_size.x, 0.0); break; - case MODE_LOWER_LEFT: + case MODE_BOTTOM_LEFT: offset = vec2(0.0, terminal_size.y - image_size.y); break; - case MODE_LOWER_RIGHT: + case MODE_BOTTOM_RIGHT: offset = vec2(terminal_size.x - image_size.x, terminal_size.y - image_size.y); break; }