diff --git a/src/main.rs b/src/main.rs index 7eb62aa..04c18f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,6 +52,7 @@ fn main() { window::initialize_settings(); redraw_scheduler::initialize_settings(); + renderer::initialize_settings(); renderer::cursor_renderer::initialize_settings(); bridge::layouts::initialize_settings(); diff --git a/src/renderer/cursor_renderer/animation_utils.rs b/src/renderer/animation_utils.rs similarity index 100% rename from src/renderer/cursor_renderer/animation_utils.rs rename to src/renderer/animation_utils.rs diff --git a/src/renderer/cursor_renderer/cursor_vfx.rs b/src/renderer/cursor_renderer/cursor_vfx.rs index 9ab603e..31ab2bc 100644 --- a/src/renderer/cursor_renderer/cursor_vfx.rs +++ b/src/renderer/cursor_renderer/cursor_vfx.rs @@ -1,8 +1,8 @@ use log::error; use skulpin::skia_safe::{paint::Style, BlendMode, Canvas, Color, Paint, Point, Rect}; -use super::animation_utils::*; use super::CursorSettings; +use crate::renderer::animation_utils::*; use crate::editor::{Colors, Cursor}; use crate::settings::*; diff --git a/src/renderer/cursor_renderer/mod.rs b/src/renderer/cursor_renderer/mod.rs index 415ea5c..a66026e 100644 --- a/src/renderer/cursor_renderer/mod.rs +++ b/src/renderer/cursor_renderer/mod.rs @@ -1,4 +1,3 @@ -mod animation_utils; mod blink; mod cursor_vfx; @@ -7,10 +6,10 @@ use skulpin::skia_safe::{Canvas, Paint, Path, Point}; use crate::editor::{Colors, Cursor, CursorShape, EDITOR}; use crate::redraw_scheduler::REDRAW_SCHEDULER; use crate::renderer::CachingShaper; +use crate::renderer::animation_utils::*; use crate::settings::*; - use crate::bridge::EditorMode; -use animation_utils::*; + use blink::*; const DEFAULT_CELL_PERCENTAGE: f32 = 1.0 / 8.0; diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 4c10bf5..990489a 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -4,24 +4,93 @@ use std::sync::Arc; use log::trace; use skulpin::skia_safe::gpu::SurfaceOrigin; use skulpin::skia_safe::{ - colors, dash_path_effect, Budgeted, Canvas, ImageInfo, Paint, Rect, Surface + colors, dash_path_effect, Budgeted, Canvas, ImageInfo, Paint, Rect, Surface, Point, Color, image_filters::* }; use skulpin::CoordinateSystemHelper; mod caching_shaper; pub mod cursor_renderer; pub mod font_options; +pub mod animation_utils; pub use caching_shaper::CachingShaper; pub use font_options::*; +use animation_utils::*; use crate::editor::{Style, WindowRenderInfo, EDITOR}; use crate::redraw_scheduler::REDRAW_SCHEDULER; +use crate::settings::*; use cursor_renderer::CursorRenderer; + +// ---------------------------------------------------------------------------- + +#[derive(Clone)] +pub struct RendererSettings { + animation_length: f32, +} + +pub fn initialize_settings() { + SETTINGS.set(&RendererSettings { + animation_length: 0.15, + }); + + register_nvim_setting!("window_animation_length", RendererSettings::animation_length); +} + +// ---------------------------------------------------------------------------- + pub struct RenderedWindow { surface: Surface, - current_position: (f32, f32) + start_position: Point, + current_position: Point, + previous_destination: Point, + t: f32 +} + +impl RenderedWindow { + pub fn new(surface: Surface, position: Point) -> RenderedWindow { + RenderedWindow { + surface, + start_position: position.clone(), + current_position: position.clone(), + previous_destination: position.clone(), + t: 2.0 // 2.0 is out of the 0.0 to 1.0 range and stops animation + } + } + + pub fn update( + &mut self, + settings: &RendererSettings, + destination: Point, + dt: f32 + ) -> bool { + if destination != self.previous_destination { + self.t = 0.0; + self.start_position = self.current_position; + self.previous_destination = destination; + } + + if (self.t - 1.0).abs() < std::f32::EPSILON { + return false; + } + + if (self.t - 1.0).abs() < std::f32::EPSILON { + // We are at destination, move t out of 0-1 range to stop the animation + self.t = 2.0; + } else { + self.t = (self.t + dt / settings.animation_length).min(1.0); + } + + self.current_position = ease_point( + ease_out_expo, + self.start_position, + destination, + self.t, + ); + + true + } } pub struct Renderer { @@ -195,13 +264,14 @@ impl Renderer { pub fn draw_window( &mut self, + settings: &RendererSettings, root_canvas: &mut Canvas, window_render_info: &WindowRenderInfo, default_style: &Arc