Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat: Cursor zoom animation on click
Richie McIlroy0fdceec74c4d
diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rsindex a3acd73b5..5811e0740 100644--- a/crates/rendering/src/lib.rs+++ b/crates/rendering/src/lib.rs@@ -16,18 +16,14 @@ use cap_project::{CursorData, CursorMoveEvent, ProjectConfiguration, XY,};-use std::time::Instant;--// Add this import at the top with the other imports-use std::path::PathBuf;--// Add this import at the topuse image::GenericImageView;+use std::path::PathBuf;+use std::time::Instant;pub mod decoder;pub use decoder::DecodedFrame;-const STANDARD_CURSOR_HEIGHT: f32 = 50.0; // Standard height for all cursors+const STANDARD_CURSOR_HEIGHT: f32 = 75.0;#[derive(Debug, Clone, Type)]pub struct RenderOptions {@@ -1023,13 +1019,17 @@ fn draw_cursor(return;};- // println!(- // "Raw cursor position: ({}, {})",- // cursor_position.0, cursor_position.1- // );-let cursor_event = find_cursor_event(&constants.cursor, time);+ let last_click_time = constants+ .cursor+ .clicks+ .iter()+ .filter(|click| click.down && click.process_time_ms <= (time as f64) * 1000.0)+ .max_by_key(|click| click.process_time_ms as i64)+ .map(|click| ((time as f64) * 1000.0 - click.process_time_ms) as f32 / 1000.0)+ .unwrap_or(1.0);+let Some(cursor_texture) = constants.cursor_textures.get(&cursor_event.cursor_id) else {return;};@@ -1040,21 +1040,20 @@ fn draw_cursor(let cursor_size_percentage = if uniforms.cursor_size <= 0.0 {100.0} else {- uniforms.cursor_size / 100.0 // Convert percentage to scale factor+ uniforms.cursor_size / 100.0};- // Calculate normalized size maintaining aspect ratiolet normalized_size = [STANDARD_CURSOR_HEIGHT * aspect_ratio * cursor_size_percentage,STANDARD_CURSOR_HEIGHT * cursor_size_percentage,];- let position = uniforms- .zoom- .apply_scale(cursor_position.to_frame_space(&constants.options, &uniforms.project));+ let frame_position = cursor_position.to_frame_space(&constants.options, &uniforms.project);+ let position = uniforms.zoom.apply_scale(frame_position);+ let relative_position = [position.x as f32, position.y as f32];let cursor_uniforms = CursorUniforms {- position: [position.x as f32, position.y as f32, 0.0, 0.0],+ position: [relative_position[0], relative_position[1], 0.0, 0.0],size: [normalized_size[0], normalized_size[1], 0.0, 0.0],output_size: [uniforms.output_size.0 as f32,@@ -1064,7 +1063,8 @@ fn draw_cursor(],screen_bounds: uniforms.display.target_bounds,cursor_size: cursor_size_percentage,- padding: [0.0; 3],+ last_click_time: last_click_time.min(0.5),+ padding: [0.0; 2],_alignment: [0.0; 8],};@@ -1357,7 +1357,6 @@ impl GradientOrColorPipeline {}}-// Update the do_render_pass function to accept a LoadOp parameterfn do_render_pass(encoder: &mut wgpu::CommandEncoder,output_view: &wgpu::TextureView,@@ -1469,8 +1468,6 @@ fn get_either<T>((a, b): (T, T), left: bool) -> T {}}-// Add this to the AsyncVideoDecoderHandle struct or impl block-impl AsyncVideoDecoderHandle {// ... (existing methods)@@ -1535,7 +1532,8 @@ struct CursorUniforms {output_size: [f32; 4],screen_bounds: [f32; 4],cursor_size: f32,- padding: [f32; 3],+ last_click_time: f32,+ padding: [f32; 2],_alignment: [f32; 8],}diff --git a/crates/rendering/src/shaders/cursor.wgsl b/crates/rendering/src/shaders/cursor.wgslindex 5ecdd42c0..54bd56f11 100644--- a/crates/rendering/src/shaders/cursor.wgsl+++ b/crates/rendering/src/shaders/cursor.wgsl@@ -9,7 +9,8 @@ struct Uniforms {output_size: vec4<f32>,screen_bounds: vec4<f32>,cursor_size: f32,- padding: vec3<f32>,+ last_click_time: f32,+ padding: vec2<f32>,_alignment: vec4<f32>,};@@ -25,10 +26,10 @@ var s_cursor: sampler;@vertexfn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {var positions = array<vec2<f32>, 4>(- vec2<f32>(-1.0, 1.0),- vec2<f32>(-1.0, -1.0),- vec2<f32>(1.0, 1.0),- vec2<f32>(1.0, -1.0)+ vec2<f32>(-0.5, 0.5),+ vec2<f32>(-0.5, -0.5),+ vec2<f32>(0.5, 0.5),+ vec2<f32>(0.5, -0.5));var uvs = array<vec2<f32>, 4>(@@ -42,11 +43,19 @@ fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {let size = uniforms.size.xy;let screen_pos = uniforms.position.xy;- // Apply cursor size scaling- let scaled_size = size * uniforms.cursor_size;+ // Calculate click animation scale factor+ let time_since_click = uniforms.last_click_time;+ let click_scale = 1.0 - (0.2 * smoothstep(0.0, 0.25, time_since_click) * (1.0 - smoothstep(0.25, 0.5, time_since_click)));- // Calculate final position- let final_pos = (pos * scaled_size + screen_pos) / uniforms.output_size.xy * 2.0 - 1.0;+ // Apply cursor size scaling with click animation+ let scaled_size = size * uniforms.cursor_size * click_scale;++ // Calculate final position - centered around cursor position+ // Flip the Y coordinate by subtracting from output height+ var adjusted_pos = screen_pos;+ adjusted_pos.y = uniforms.output_size.y - adjusted_pos.y; // Flip Y coordinate++ let final_pos = ((pos * scaled_size) + adjusted_pos) / uniforms.output_size.xy * 2.0 - 1.0;var output: VertexOutput;output.position = vec4<f32>(final_pos, 0.0, 1.0);