Make particle effects based on font size. Spawn particles at text baseline

macos-click-through
Jon Valdés 5 years ago
parent b11642c6b0
commit 1b2a2552c3

@ -11,6 +11,7 @@ pub trait CursorVfx {
&mut self,
settings: &CursorSettings,
current_cursor_destination: Point,
font_size: (f32, f32),
dt: f32,
) -> bool;
fn restart(&mut self, position: Point);
@ -110,6 +111,7 @@ impl CursorVfx for PointHighlight {
&mut self,
_settings: &CursorSettings,
_current_cursor_destination: Point,
_font_size: (f32, f32),
dt: f32,
) -> bool {
self.t = (self.t + dt * 5.0).min(1.0); // TODO - speed config
@ -208,7 +210,12 @@ impl ParticleTrail {
}
impl CursorVfx for ParticleTrail {
fn update(&mut self, settings: &CursorSettings, current_cursor_dest: Point, dt: f32) -> bool {
fn update(
&mut self,
settings: &CursorSettings,
current_cursor_dest: Point,
font_size: (f32, f32),
dt: f32) -> bool {
// Update lifetimes and remove dead particles
let mut i = 0;
while i < self.particles.len() {
@ -232,9 +239,8 @@ impl CursorVfx for ParticleTrail {
let travel = current_cursor_dest - self.previous_cursor_dest;
let travel_distance = travel.length();
// Increase amount of particles when cursor travels further
// TODO -- particle count should not depend on font size
let particle_count =
(travel_distance.powf(1.5) * settings.vfx_particle_density * 0.01) as usize;
((travel_distance / font_size.0).powf(1.5) * settings.vfx_particle_density * 0.01) as usize;
let prev_p = self.previous_cursor_dest;
@ -246,7 +252,9 @@ impl CursorVfx for ParticleTrail {
let phase = t * 60.0; // TODO -- Hardcoded spiral curl
Point::new(phase.sin(), phase.cos()) * 20.0 // TODO -- Hardcoded spiral outward speed
}
TrailMode::Torpedo => self.rng.rand_dir_normalized() * 10.0, // TODO -- Hardcoded particle speed
TrailMode::Torpedo => {
self.rng.rand_dir_normalized() * 10.0 // TODO -- Hardcoded particle speed
}
TrailMode::PixieDust => {
let base_dir = self.rng.rand_dir_normalized();
let dir = Point::new(base_dir.x * 0.5, 0.4 + base_dir.y.abs());
@ -254,16 +262,13 @@ impl CursorVfx for ParticleTrail {
}
};
// TODO -- Spawn position should be at the base of the cursor, not the
// middle
// Distribute particles along the travel distance, with a random offset to make it
// look random
let pos = match self.trail_mode {
TrailMode::Railgun => prev_p + travel * t,
TrailMode::PixieDust | TrailMode::Torpedo => {
prev_p + travel * self.rng.next_f32()
prev_p + travel * self.rng.next_f32() + Point::new(0.0, font_size.1 * 0.5)
}
};

@ -37,7 +37,7 @@ pub fn initialize_settings() {
vfx_mode: cursor_vfx::VfxMode::Disabled,
vfx_opacity: 200.0,
vfx_particle_lifetime: 1.2,
vfx_particle_density: 0.8,
vfx_particle_density: 7.0,
});
register_nvim_setting!("cursor_animation_length", CursorSettings::animation_length);
@ -338,7 +338,7 @@ impl CursorRenderer {
}
let vfx_animating = if let Some(vfx) = self.cursor_vfx.as_mut() {
vfx.update(&settings, center_destination, dt)
vfx.update(&settings, center_destination, (font_width, font_height), dt)
}else{
false
};

Loading…
Cancel
Save