render: bar cursor style

This commit is contained in:
Mitchell Hashimoto
2022-05-20 13:17:31 -07:00
parent 37f621bc19
commit 75c3dc4386
3 changed files with 21 additions and 1 deletions

View File

@ -22,11 +22,12 @@ uniform sampler2D text;
// Dimensions of the cell // Dimensions of the cell
uniform vec2 cell_size; uniform vec2 cell_size;
// See fragment shader // See vertex shader
const uint MODE_BG = 1u; const uint MODE_BG = 1u;
const uint MODE_FG = 2u; const uint MODE_FG = 2u;
const uint MODE_CURSOR_RECT = 3u; const uint MODE_CURSOR_RECT = 3u;
const uint MODE_CURSOR_RECT_HOLLOW = 4u; const uint MODE_CURSOR_RECT_HOLLOW = 4u;
const uint MODE_CURSOR_BAR = 5u;
void main() { void main() {
switch (mode) { switch (mode) {
@ -78,5 +79,9 @@ void main() {
} }
break; break;
case MODE_CURSOR_BAR:
out_FragColor = color;
break;
} }
} }

View File

@ -8,6 +8,7 @@ const uint MODE_BG = 1u;
const uint MODE_FG = 2u; const uint MODE_FG = 2u;
const uint MODE_CURSOR_RECT = 3u; const uint MODE_CURSOR_RECT = 3u;
const uint MODE_CURSOR_RECT_HOLLOW = 4u; const uint MODE_CURSOR_RECT_HOLLOW = 4u;
const uint MODE_CURSOR_BAR = 5u;
// The grid coordinates (x, y) where x < columns and y < rows // The grid coordinates (x, y) where x < columns and y < rows
layout (location = 0) in vec2 grid_coord; layout (location = 0) in vec2 grid_coord;
@ -143,6 +144,17 @@ void main() {
// Same as background since we're taking up the whole cell. // Same as background since we're taking up the whole cell.
cell_pos = cell_pos + cell_size * position; 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); gl_Position = projection * vec4(cell_pos, 0.0, 1.0);
color = bg_color_in / 255.0; color = bg_color_in / 255.0;
break; break;

View File

@ -45,9 +45,12 @@ cursor_style: CursorStyle,
/// Default foreground color /// Default foreground color
foreground: terminal.color.RGB, foreground: terminal.color.RGB,
/// Available cursor styles for drawing. The values represents the mode value
/// in the shader.
const CursorStyle = enum(u8) { const CursorStyle = enum(u8) {
box = 3, box = 3,
box_hollow = 4, box_hollow = 4,
bar = 5,
}; };
/// The raw structure that maps directly to the buffer sent to the vertex shader. /// The raw structure that maps directly to the buffer sent to the vertex shader.