From 92bc1725f1733547eb0ae25b740425f03f358c2a Mon Sep 17 00:00:00 2001 From: Natasha England-Elbro <46329225+0x00002a@users.noreply.github.com> Date: Fri, 4 Feb 2022 20:14:45 +0000 Subject: [PATCH] feat: add support for blend=100 (#1195) * feat: add support for blend=100 * feat: add support for blend between 0 and 100 for cursor * fix: cursor not updating on window switch * fix: crash on set cursor group * chore: formatting * chore: curr -> current --- src/editor/cursor.rs | 8 ++++++++ src/editor/mod.rs | 14 +++++++++++++- src/renderer/cursor_renderer/mod.rs | 7 ++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/editor/cursor.rs b/src/editor/cursor.rs index 475e5e0..781caa1 100644 --- a/src/editor/cursor.rs +++ b/src/editor/cursor.rs @@ -80,6 +80,14 @@ impl Cursor { .unwrap_or_else(|| default_colors.foreground.unwrap()) } + pub fn alpha(&self) -> u8 { + return self + .style + .as_ref() + .map(|s| (255 as f32 * ((100 - s.blend) as f32 / (100.0 as f32))) as u8) + .unwrap_or(255); + } + pub fn change_mode(&mut self, cursor_mode: &CursorMode, styles: &HashMap>) { let CursorMode { shape, diff --git a/src/editor/mod.rs b/src/editor/mod.rs index 8a265a6..65fab92 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -60,6 +60,7 @@ pub struct Editor { pub defined_styles: HashMap>, pub mode_list: Vec, pub draw_command_batcher: Arc, + pub current_mode_index: Option, } impl Editor { @@ -70,6 +71,7 @@ impl Editor { defined_styles: HashMap::new(), mode_list: Vec::new(), draw_command_batcher: Arc::new(DrawCommandBatcher::new()), + current_mode_index: None, } } @@ -79,11 +81,21 @@ impl Editor { RedrawEvent::SetTitle { title } => { EVENT_AGGREGATOR.send(WindowCommand::TitleChanged(title)); } - RedrawEvent::ModeInfoSet { cursor_modes } => self.mode_list = cursor_modes, + RedrawEvent::ModeInfoSet { cursor_modes } => { + self.mode_list = cursor_modes; + if let Some(current_mode_i) = self.current_mode_index.clone() { + if let Some(current_mode) = self.mode_list.get(current_mode_i as usize) { + self.cursor.change_mode(current_mode, &self.defined_styles) + } + } + } RedrawEvent::OptionSet { gui_option } => self.set_option(gui_option), RedrawEvent::ModeChange { mode, mode_index } => { if let Some(cursor_mode) = self.mode_list.get(mode_index as usize) { self.cursor.change_mode(cursor_mode, &self.defined_styles); + self.current_mode_index = Some(mode_index) + } else { + self.current_mode_index = None } self.draw_command_batcher .queue(DrawCommand::ModeChanged(mode)) diff --git a/src/renderer/cursor_renderer/mod.rs b/src/renderer/cursor_renderer/mod.rs index c4730ce..826d2ec 100644 --- a/src/renderer/cursor_renderer/mod.rs +++ b/src/renderer/cursor_renderer/mod.rs @@ -340,7 +340,6 @@ impl CursorRenderer { } else { self.previous_editor_mode = current_mode.clone(); } - if !(self.cursor.enabled && render) { return; } @@ -348,7 +347,8 @@ impl CursorRenderer { let background_color = self .cursor .background(&grid_renderer.default_style.colors) - .to_color(); + .to_color() + .with_a(self.cursor.alpha()); paint.set_color(background_color); // The cursor is made up of four points, so I create a path with each of the four @@ -367,7 +367,8 @@ impl CursorRenderer { let foreground_color = self .cursor .foreground(&grid_renderer.default_style.colors) - .to_color(); + .to_color() + .with_a(self.cursor.alpha()); paint.set_color(foreground_color); canvas.save();