aboutsummaryrefslogtreecommitdiff
path: root/src/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer')
-rw-r--r--src/renderer/mod.rs29
-rw-r--r--src/renderer/rects.rs (renamed from src/renderer/lines.rs)30
2 files changed, 32 insertions, 27 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index e96d35a5..9a33410f 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -29,12 +29,12 @@ use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher};
use crate::gl::types::*;
use crate::gl;
use crate::index::{Column, Line, RangeInclusive};
-use crate::Rgb;
+use crate::term::color::Rgb;
use crate::config::{self, Config, Delta};
use crate::term::{self, cell, RenderableCell};
-use crate::renderer::lines::Lines;
+use crate::renderer::rects::{Rect, Rects};
-pub mod lines;
+pub mod rects;
// Shader paths for live reload
static TEXT_SHADER_F_PATH: &'static str = concat!(env!("CARGO_MANIFEST_DIR"), "/res/text.f.glsl");
@@ -668,7 +668,7 @@ impl QuadRenderer {
config: &Config,
props: &term::SizeInfo,
visual_bell_intensity: f64,
- cell_line_rects: Lines,
+ cell_line_rects: Rects,
) {
// Swap to rectangle rendering program
unsafe {
@@ -866,20 +866,6 @@ impl QuadRenderer {
}
}
-#[derive(Debug, Copy, Clone)]
-pub struct Rect<T> {
- x: T,
- y: T,
- width: T,
- height: T,
-}
-
-impl<T> Rect<T> {
- pub fn new(x: T, y: T, width: T, height: T) -> Self {
- Rect { x, y, width, height }
- }
-}
-
impl<'a> RenderApi<'a> {
pub fn clear(&self, color: Rgb) {
let alpha = self.config.background_opacity().get();
@@ -941,8 +927,9 @@ impl<'a> RenderApi<'a> {
string: &str,
line: Line,
glyph_cache: &mut GlyphCache,
- color: Rgb
+ color: Option<Rgb>
) {
+ let bg_alpha = color.map(|_| 1.0).unwrap_or(0.0);
let col = Column(0);
let cells = string
@@ -956,10 +943,10 @@ impl<'a> RenderApi<'a> {
chars[0] = c;
chars
},
- bg: color,
+ bg: color.unwrap_or(Rgb { r: 0, g: 0, b: 0}),
fg: Rgb { r: 0, g: 0, b: 0 },
flags: cell::Flags::empty(),
- bg_alpha: 1.0,
+ bg_alpha,
})
.collect::<Vec<_>>();
diff --git a/src/renderer/lines.rs b/src/renderer/rects.rs
index 3c250caf..e066c365 100644
--- a/src/renderer/lines.rs
+++ b/src/renderer/rects.rs
@@ -13,14 +13,27 @@
// limitations under the License.
use std::collections::HashMap;
-use crate::renderer::Rect;
use crate::term::cell::Flags;
use crate::term::{RenderableCell, SizeInfo};
-use crate::Rgb;
+use crate::term::color::Rgb;
use font::Metrics;
-/// Lines for underline and strikeout.
-pub struct Lines<'a> {
+#[derive(Debug, Copy, Clone)]
+pub struct Rect<T> {
+ pub x: T,
+ pub y: T,
+ pub width: T,
+ pub height: T,
+}
+
+impl<T> Rect<T> {
+ pub fn new(x: T, y: T, width: T, height: T) -> Self {
+ Rect { x, y, width, height }
+ }
+}
+
+/// Rects for underline, strikeout and more.
+pub struct Rects<'a> {
inner: Vec<(Rect<f32>, Rgb)>,
last_starts: HashMap<Flags, Option<RenderableCell>>,
last_cell: Option<RenderableCell>,
@@ -28,7 +41,7 @@ pub struct Lines<'a> {
size: &'a SizeInfo,
}
-impl<'a> Lines<'a> {
+impl<'a> Rects<'a> {
pub fn new(metrics: &'a Metrics, size: &'a SizeInfo) -> Self {
let mut last_starts = HashMap::new();
last_starts.insert(Flags::UNDERLINE, None);
@@ -43,7 +56,7 @@ impl<'a> Lines<'a> {
}
}
- /// Convert the stored lines to rectangles for the renderer.
+ /// Convert the stored rects to rectangles for the renderer.
pub fn rects(mut self) -> Vec<(Rect<f32>, Rgb)> {
// If there's still a line pending, draw it until the last cell
for (flag, start_cell) in self.last_starts.iter_mut() {
@@ -107,6 +120,11 @@ impl<'a> Lines<'a> {
self.last_cell = Some(*cell);
}
+
+ // Add a rectangle
+ pub fn push(&mut self, rect: Rect<f32>, color: Rgb) {
+ self.inner.push((rect, color));
+ }
}
/// Create a rectangle that starts on the left of `start` and ends on the right