aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAyose <ayosec@gmail.com>2022-07-12 22:39:50 +0100
committerAyose <ayosec@gmail.com>2022-07-12 22:39:50 +0100
commitf796ba2afa445254da02157765344164d04f7dad (patch)
treea288459671e37e838b692ccf7c4e27d9b98c0e10
parentb73717649bbc61cc9a3f62b530d724cf9731dc10 (diff)
downloadr-alacritty-f796ba2afa445254da02157765344164d04f7dad.tar.gz
r-alacritty-f796ba2afa445254da02157765344164d04f7dad.tar.bz2
r-alacritty-f796ba2afa445254da02157765344164d04f7dad.zip
Highlight graphics to show hints.
Similar to the underline line rendered when the cursor is over an hyperlink, for graphics we now render a border around the graphic.
-rw-r--r--alacritty/src/display/mod.rs9
-rw-r--r--alacritty/src/renderer/graphics/draw.rs60
-rw-r--r--alacritty/src/renderer/graphics/mod.rs12
-rw-r--r--alacritty/src/renderer/mod.rs10
4 files changed, 80 insertions, 11 deletions
diff --git a/alacritty/src/display/mod.rs b/alacritty/src/display/mod.rs
index c87cc124..195164bf 100644
--- a/alacritty/src/display/mod.rs
+++ b/alacritty/src/display/mod.rs
@@ -819,6 +819,8 @@ impl Display {
// Underline hints hovered by mouse or vi mode cursor.
let point = term::viewport_to_point(display_offset, cell.point);
+ let mut show_hint = false;
+
if has_highlighted_hint {
let hyperlink =
cell.extra.as_ref().and_then(|extra| extra.hyperlink.as_ref());
@@ -829,6 +831,7 @@ impl Display {
.as_ref()
.map_or(false, |hint| hint.should_highlight(point, hyperlink))
{
+ show_hint = true;
cell.flags.insert(Flags::UNDERLINE);
}
}
@@ -837,17 +840,17 @@ impl Display {
lines.update(&cell);
// Track any graphic present in the cell.
- graphics_list.update(&cell);
+ graphics_list.update(&cell, show_hint);
cell
}),
);
}
- self.renderer.graphics_draw(graphics_list, &size_info);
-
let mut rects = lines.rects(&metrics, &size_info);
+ self.renderer.graphics_draw(graphics_list, &size_info, &mut rects, &metrics);
+
if let Some(vi_cursor_point) = vi_cursor_point {
// Indicate vi mode by showing the cursor's position in the top right corner.
let line = (-vi_cursor_point.line.0 + size_info.bottommost_line().0) as usize;
diff --git a/alacritty/src/renderer/graphics/draw.rs b/alacritty/src/renderer/graphics/draw.rs
index 3d0a87e1..f9207823 100644
--- a/alacritty/src/renderer/graphics/draw.rs
+++ b/alacritty/src/renderer/graphics/draw.rs
@@ -13,10 +13,13 @@ use crate::display::SizeInfo;
use crate::gl::types::*;
use crate::gl::{self};
use crate::renderer::graphics::{shader, GraphicsRenderer};
+use crate::renderer::{RenderRect, Rgb};
use alacritty_terminal::graphics::GraphicId;
use alacritty_terminal::index::Column;
+use crossfont::Metrics;
+
use log::trace;
/// Position to render each texture in the grid.
@@ -25,6 +28,8 @@ struct RenderPosition {
line: usize,
offset_x: u16,
offset_y: u16,
+ cell_color: Rgb,
+ show_hint: bool,
}
/// Track textures to be rendered in the display.
@@ -38,7 +43,7 @@ impl RenderList {
///
/// The graphic is added only the first time it is found in a cell.
#[inline]
- pub fn update(&mut self, cell: &RenderableCell) {
+ pub fn update(&mut self, cell: &RenderableCell, show_hint: bool) {
let graphic = match cell.extra.as_ref().and_then(|cell| cell.graphic.as_ref()) {
Some(graphic) => graphic,
_ => return,
@@ -53,6 +58,8 @@ impl RenderList {
line: cell.point.line,
offset_x: graphic.offset_x,
offset_y: graphic.offset_y,
+ cell_color: cell.fg,
+ show_hint,
};
self.items.insert(graphic.id, render_item);
@@ -65,7 +72,13 @@ impl RenderList {
}
/// Builds a list of vertex for the shader program.
- pub fn build_vertices(self, renderer: &GraphicsRenderer) -> Vec<shader::Vertex> {
+ fn build_vertices(
+ self,
+ renderer: &GraphicsRenderer,
+ size_info: &SizeInfo,
+ rects: &mut Vec<RenderRect>,
+ line_thickness: f32,
+ ) -> Vec<shader::Vertex> {
use shader::VertexSide::{BottomLeft, BottomRight, TopLeft, TopRight};
let mut vertices = Vec::new();
@@ -95,6 +108,38 @@ impl RenderList {
for &sides in &[TopRight, BottomLeft, TopRight, BottomRight, BottomLeft] {
vertices.push(shader::Vertex { sides, ..vertex });
}
+
+ if render_item.show_hint {
+ let scale = size_info.cell_height() / graphic_texture.cell_height;
+
+ let x = render_item.column.0 as f32 * size_info.cell_width()
+ - render_item.offset_x as f32 * scale;
+ let y = render_item.line as f32 * size_info.cell_height()
+ - render_item.offset_y as f32 * scale;
+
+ let tex_width = graphic_texture.width as f32 * scale;
+ let tex_height = graphic_texture.height as f32 * scale;
+
+ let right = x + tex_width - line_thickness;
+ let bottom = y + tex_height - line_thickness;
+
+ let template = RenderRect {
+ x,
+ y,
+ width: tex_width,
+ height: line_thickness,
+ color: render_item.cell_color,
+ alpha: 1.,
+ kind: crate::renderer::rects::RectKind::Normal,
+ };
+
+ rects.push(template);
+ rects.push(RenderRect { y: bottom, ..template });
+
+ let template = RenderRect { width: line_thickness, height: tex_height, ..template };
+ rects.push(template);
+ rects.push(RenderRect { x: right, ..template });
+ }
}
vertices
@@ -102,8 +147,15 @@ impl RenderList {
/// Draw graphics in the display, using the graphics rendering shader
/// program.
- pub fn draw(self, renderer: &GraphicsRenderer, size_info: &SizeInfo) {
- let vertices = self.build_vertices(renderer);
+ pub fn draw(
+ self,
+ renderer: &GraphicsRenderer,
+ size_info: &SizeInfo,
+ rects: &mut Vec<RenderRect>,
+ metrics: &Metrics,
+ ) {
+ let vertices =
+ self.build_vertices(renderer, size_info, rects, metrics.underline_thickness.max(3.0));
// Initialize the rendering program.
unsafe {
diff --git a/alacritty/src/renderer/graphics/mod.rs b/alacritty/src/renderer/graphics/mod.rs
index 797a3711..cb6a1c9e 100644
--- a/alacritty/src/renderer/graphics/mod.rs
+++ b/alacritty/src/renderer/graphics/mod.rs
@@ -3,10 +3,12 @@
use std::mem;
use crate::display::SizeInfo;
+use crate::renderer::RenderRect;
use alacritty_terminal::graphics::{
ClearSubregion, ColorType, GraphicData, GraphicId, UpdateQueues,
};
+use crossfont::Metrics;
use log::trace;
use serde::{Deserialize, Serialize};
@@ -248,9 +250,15 @@ impl GraphicsRenderer {
/// Draw graphics in the display.
#[inline]
- pub fn draw(&mut self, render_list: RenderList, size_info: &SizeInfo) {
+ pub fn draw(
+ &mut self,
+ render_list: RenderList,
+ size_info: &SizeInfo,
+ rects: &mut Vec<RenderRect>,
+ metrics: &Metrics,
+ ) {
if !render_list.is_empty() {
- render_list.draw(self, size_info);
+ render_list.draw(self, size_info, rects, metrics);
}
}
}
diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs
index 8d1058ff..898df15d 100644
--- a/alacritty/src/renderer/mod.rs
+++ b/alacritty/src/renderer/mod.rs
@@ -239,9 +239,15 @@ impl Renderer {
/// Draw graphics visible in the display.
#[inline]
- pub fn graphics_draw(&mut self, render_list: graphics::RenderList, size_info: &SizeInfo) {
+ pub fn graphics_draw(
+ &mut self,
+ render_list: graphics::RenderList,
+ size_info: &SizeInfo,
+ rects: &mut Vec<RenderRect>,
+ metrics: &Metrics,
+ ) {
if let Some(graphics_renderer) = self.graphics_renderer.as_mut() {
- graphics_renderer.draw(render_list, size_info);
+ graphics_renderer.draw(render_list, size_info, rects, metrics);
}
self.reset_active_tex();