From 75c3dc438623d17ee89b31647efbc0e545d36371 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 20 May 2022 13:17:31 -0700 Subject: [PATCH] render: bar cursor style --- shaders/cell.f.glsl | 7 ++++++- shaders/cell.v.glsl | 12 ++++++++++++ src/Grid.zig | 3 +++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/shaders/cell.f.glsl b/shaders/cell.f.glsl index 3126ff433..d665b29d6 100644 --- a/shaders/cell.f.glsl +++ b/shaders/cell.f.glsl @@ -22,11 +22,12 @@ uniform sampler2D text; // Dimensions of the cell uniform vec2 cell_size; -// See fragment shader +// See vertex shader const uint MODE_BG = 1u; const uint MODE_FG = 2u; const uint MODE_CURSOR_RECT = 3u; const uint MODE_CURSOR_RECT_HOLLOW = 4u; +const uint MODE_CURSOR_BAR = 5u; void main() { switch (mode) { @@ -78,5 +79,9 @@ void main() { } break; + + case MODE_CURSOR_BAR: + out_FragColor = color; + break; } } diff --git a/shaders/cell.v.glsl b/shaders/cell.v.glsl index 6363b5689..1cdd9e22b 100644 --- a/shaders/cell.v.glsl +++ b/shaders/cell.v.glsl @@ -8,6 +8,7 @@ const uint MODE_BG = 1u; const uint MODE_FG = 2u; const uint MODE_CURSOR_RECT = 3u; const uint MODE_CURSOR_RECT_HOLLOW = 4u; +const uint MODE_CURSOR_BAR = 5u; // The grid coordinates (x, y) where x < columns and y < rows layout (location = 0) in vec2 grid_coord; @@ -143,6 +144,17 @@ void main() { // Same as background since we're taking up the whole cell. cell_pos = cell_pos + cell_size * position; + gl_Position = projection * vec4(cell_pos, 0.0, 1.0); + color = bg_color_in / 255.0; + break; + + case MODE_CURSOR_BAR: + // Make the bar a smaller version of our cell + vec2 bar_size = vec2(cell_size.x * 0.2, cell_size.y); + + // Same as background since we're taking up the whole cell. + cell_pos = cell_pos + bar_size * position; + gl_Position = projection * vec4(cell_pos, 0.0, 1.0); color = bg_color_in / 255.0; break; diff --git a/src/Grid.zig b/src/Grid.zig index 7130358f3..06d3ecfc7 100644 --- a/src/Grid.zig +++ b/src/Grid.zig @@ -45,9 +45,12 @@ cursor_style: CursorStyle, /// Default foreground color foreground: terminal.color.RGB, +/// Available cursor styles for drawing. The values represents the mode value +/// in the shader. const CursorStyle = enum(u8) { box = 3, box_hollow = 4, + bar = 5, }; /// The raw structure that maps directly to the buffer sent to the vertex shader.