Renamed CursorVFX to PointHighlight. Implemented Ripple and Wireframe modes

macos-click-through
Jon Valdés 5 years ago
parent 7c3585e9a6
commit 028c36d32a

@ -1,19 +1,37 @@
use skulpin::skia_safe::{BlendMode, Canvas, Color, Paint, Point, Rect}; use skulpin::skia_safe::{BlendMode, Canvas, Color, Paint, Point, Rect, paint::Style};
use crate::editor::{Colors, Cursor}; use crate::editor::{Colors, Cursor};
pub trait CursorVFX { pub trait CursorVFX {
fn update(&mut self, current_cursor_destination: Point, dt: f32) -> bool; fn update(&mut self, current_cursor_destination: Point, dt: f32) -> bool;
fn restart(&mut self, position: Point); fn restart(&mut self, position: Point);
fn render(&self, _paint: &mut Paint, canvas: &mut Canvas, cursor: &Cursor, colors: &Colors); fn render(&self, canvas: &mut Canvas, cursor: &Cursor, colors: &Colors, font_size: (f32, f32));
} }
pub struct SonicBoom { #[allow(dead_code)]
pub t: f32, pub enum HighlightMode {
pub center_position: Point, SonicBoom,
Ripple,
Wireframe,
} }
impl CursorVFX for SonicBoom { pub struct PointHighlight {
t: f32,
center_position: Point,
mode: HighlightMode,
}
impl PointHighlight {
pub fn new(center: Point, mode: HighlightMode) -> PointHighlight {
PointHighlight {
t: 0.0,
center_position: center,
mode,
}
}
}
impl CursorVFX for PointHighlight {
fn update(&mut self, _current_cursor_destination: Point, dt: f32) -> bool { fn update(&mut self, _current_cursor_destination: Point, dt: f32) -> bool {
self.t = (self.t + dt * 5.0).min(1.0); // TODO - speed config self.t = (self.t + dt * 5.0).min(1.0); // TODO - speed config
return self.t < 1.0; return self.t < 1.0;
@ -24,7 +42,7 @@ impl CursorVFX for SonicBoom {
self.center_position = position; self.center_position = position;
} }
fn render(&self, _paint: &mut Paint, canvas: &mut Canvas, cursor: &Cursor, colors: &Colors) { fn render(&self, canvas: &mut Canvas, cursor: &Cursor, colors: &Colors, font_size: (f32, f32)) {
if self.t == 1.0 { if self.t == 1.0 {
return; return;
} }
@ -36,7 +54,8 @@ impl CursorVFX for SonicBoom {
let color = Color::from_argb(alpha, base_color.r(), base_color.g(), base_color.b()); let color = Color::from_argb(alpha, base_color.r(), base_color.g(), base_color.b());
paint.set_color(color); paint.set_color(color);
let size = 40.0; // TODO -- Compute from font size
let size = 3.0 * font_size.1;
let radius = self.t * size; let radius = self.t * size;
let hr = radius * 0.5; let hr = radius * 0.5;
let rect = Rect::from_xywh( let rect = Rect::from_xywh(
@ -46,6 +65,22 @@ impl CursorVFX for SonicBoom {
radius, radius,
); );
canvas.draw_oval(&rect, &paint); match self.mode {
HighlightMode::SonicBoom => {
canvas.draw_oval(&rect, &paint);
},
HighlightMode::Ripple => {
paint.set_style(Style::Stroke);
paint.set_stroke_width(font_size.1 * 0.2);
canvas.draw_oval(&rect, &paint);
},
HighlightMode::Wireframe => {
paint.set_style(Style::Stroke);
paint.set_stroke_width(font_size.1 * 0.2);
canvas.draw_rect(&rect, &paint);
},
}
} }
} }

@ -11,6 +11,7 @@ mod animation_utils;
use animation_utils::*; use animation_utils::*;
mod cursor_vfx; mod cursor_vfx;
use cursor_vfx::*;
const BASE_ANIMATION_LENGTH_SECONDS: f32 = 0.06; const BASE_ANIMATION_LENGTH_SECONDS: f32 = 0.06;
const CURSOR_TRAIL_SIZE: f32 = 0.7; const CURSOR_TRAIL_SIZE: f32 = 0.7;
@ -182,7 +183,7 @@ pub struct CursorRenderer {
pub command_line_delay: u64, pub command_line_delay: u64,
blink_status: BlinkStatus, blink_status: BlinkStatus,
previous_cursor_shape: Option<CursorShape>, previous_cursor_shape: Option<CursorShape>,
cursor_vfx: Box<dyn cursor_vfx::CursorVFX>, cursor_vfx: Box<dyn CursorVFX>,
} }
impl CursorRenderer { impl CursorRenderer {
@ -193,7 +194,7 @@ impl CursorRenderer {
command_line_delay: 0, command_line_delay: 0,
blink_status: BlinkStatus::new(), blink_status: BlinkStatus::new(),
previous_cursor_shape: None, previous_cursor_shape: None,
cursor_vfx: Box::new(cursor_vfx::SonicBoom{t: 0.0, center_position: Point{x:0.0, y:0.0}}), cursor_vfx: Box::new(PointHighlight::new(Point{x:0.0, y:0.0}, HighlightMode::Ripple)),
}; };
renderer.set_cursor_shape(&CursorShape::Block, DEFAULT_CELL_PERCENTAGE); renderer.set_cursor_shape(&CursorShape::Block, DEFAULT_CELL_PERCENTAGE);
renderer renderer
@ -325,7 +326,7 @@ impl CursorRenderer {
canvas.draw_text_blob(&blob, destination, &paint); canvas.draw_text_blob(&blob, destination, &paint);
} }
canvas.restore(); canvas.restore();
self.cursor_vfx.render(paint, canvas, &cursor, &default_colors); self.cursor_vfx.render(canvas, &cursor, &default_colors, (font_width, font_height));
} }
} }
} }

Loading…
Cancel
Save