mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Add anchor options
This commit is contained in:
@ -475,6 +475,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,
|
||||
|
||||
@ -6325,6 +6333,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
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user