Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat: Add cursor movement style presets and motion blur
Richie McIlroyd0795aa3b645
diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsxindex 3cacb36c2..578155807 100644--- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx+++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx@@ -45,6 +45,7 @@ import {type BackgroundSource,type CameraShape,type ClipOffsets,+ type CursorAnimationStyle,commands,type SceneSegment,type StereoMode,@@ -54,6 +55,8 @@ import {import IconLucideMonitor from "~icons/lucide/monitor";import IconLucideSparkles from "~icons/lucide/sparkles";import IconLucideTimer from "~icons/lucide/timer";+import IconLucideRabbit from "~icons/lucide/rabbit";+import IconLucideWind from "~icons/lucide/wind";import { CaptionsTab } from "./CaptionsTab";import { useEditorContext } from "./context";import {@@ -215,6 +218,59 @@ const BACKGROUND_THEMES = {orange: "Orange",};+type CursorPresetValues = {+ tension: number;+ mass: number;+ friction: number;+};++const CURSOR_ANIMATION_STYLE_OPTIONS = [+ {+ value: "slow",+ label: "Slow",+ description: "Relaxed easing with a gentle follow and higher inertia.",+ preset: { tension: 65, mass: 1.8, friction: 16 },+ },+ {+ value: "mellow",+ label: "Mellow",+ description: "Balanced smoothing for everyday tutorials and walkthroughs.",+ preset: { tension: 120, mass: 1.1, friction: 18 },+ },+ {+ value: "custom",+ label: "Custom",+ description: "Tune tension, friction, and mass manually for full control.",+ },+] satisfies Array<{+ value: CursorAnimationStyle;+ label: string;+ description: string;+ preset?: CursorPresetValues;+}>;++const CURSOR_PRESET_TOLERANCE = {+ tension: 1,+ mass: 0.05,+ friction: 0.2,+} as const;++const findCursorPreset = (+ values: CursorPresetValues,+): CursorAnimationStyle | null => {+ const preset = CURSOR_ANIMATION_STYLE_OPTIONS.find(+ (option) =>+ option.preset &&+ Math.abs(option.preset.tension - values.tension) <=+ CURSOR_PRESET_TOLERANCE.tension &&+ Math.abs(option.preset.mass - values.mass) <= CURSOR_PRESET_TOLERANCE.mass &&+ Math.abs(option.preset.friction - values.friction) <=+ CURSOR_PRESET_TOLERANCE.friction,+ );++ return preset?.value ?? null;+};+const TAB_IDS = {background: "background",camera: "camera",@@ -242,6 +298,40 @@ export function ConfigSidebar() {const clampIdleDelay = (value: number) =>Math.round(Math.min(5, Math.max(0.5, value)) * 10) / 10;+ type CursorPhysicsKey = "tension" | "mass" | "friction";++ const setCursorPhysics = (key: CursorPhysicsKey, value: number) => {+ const nextValues: CursorPresetValues = {+ tension: key === "tension" ? value : project.cursor.tension,+ mass: key === "mass" ? value : project.cursor.mass,+ friction: key === "friction" ? value : project.cursor.friction,+ };+ const matched = findCursorPreset(nextValues);+ const nextStyle = (matched ?? "custom") as CursorAnimationStyle;++ batch(() => {+ setProject("cursor", key, value);+ if (project.cursor.animationStyle !== nextStyle) {+ setProject("cursor", "animationStyle", nextStyle);+ }+ });+ };++ const applyCursorStylePreset = (style: CursorAnimationStyle) => {+ const option = CURSOR_ANIMATION_STYLE_OPTIONS.find(+ (item) => item.value === style,+ );++ batch(() => {+ setProject("cursor", "animationStyle", style);+ if (option?.preset) {+ setProject("cursor", "tension", option.preset.tension);+ setProject("cursor", "mass", option.preset.mass);+ setProject("cursor", "friction", option.preset.friction);+ }+ });+ };+const [state, setState] = createStore({selectedTab: "background" as| "background"@@ -517,6 +607,38 @@ export function ConfigSidebar() {</div></Subfield></Show>+ <Field+ name="Cursor Movement Style"+ icon={<IconLucideRabbit class="size-4" />}+ >+ <RadioGroup+ class="flex flex-col gap-2"+ value={project.cursor.animationStyle}+ onChange={(value) =>+ applyCursorStylePreset(value as CursorAnimationStyle)+ }+ >+ {CURSOR_ANIMATION_STYLE_OPTIONS.map((option) => (+ <RadioGroup.Item+ value={option.value}+ class="rounded-lg border border-gray-3 transition-colors ui-checked:border-blue-8 ui-checked:bg-blue-3/40"+ >+ <RadioGroup.ItemInput class="sr-only" />+ <RadioGroup.ItemLabel class="flex cursor-pointer items-start gap-3 p-3">+ <RadioGroup.ItemControl class="mt-1 size-4 rounded-full border border-gray-7 ui-checked:border-blue-9 ui-checked:bg-blue-9" />+ <div class="flex flex-col text-left">+ <span class="text-sm font-medium text-gray-12">+ {option.label}+ </span>+ <span class="text-xs text-gray-11">+ {option.description}+ </span>+ </div>+ </RadioGroup.ItemLabel>+ </RadioGroup.Item>+ ))}+ </RadioGroup>+ </Field><KCollapsible open={!project.cursor.raw}><Fieldname="Smooth Movement"@@ -536,7 +658,7 @@ export function ConfigSidebar() {<Field name="Tension"><Slidervalue={[project.cursor.tension]}- onChange={(v) => setProject("cursor", "tension", v[0])}+ onChange={(v) => setCursorPhysics("tension", v[0])}minValue={1}maxValue={500}step={1}@@ -545,7 +667,7 @@ export function ConfigSidebar() {<Field name="Friction"><Slidervalue={[project.cursor.friction]}- onChange={(v) => setProject("cursor", "friction", v[0])}+ onChange={(v) => setCursorPhysics("friction", v[0])}minValue={0}maxValue={50}step={0.1}@@ -554,7 +676,7 @@ export function ConfigSidebar() {<Field name="Mass"><Slidervalue={[project.cursor.mass]}- onChange={(v) => setProject("cursor", "mass", v[0])}+ onChange={(v) => setCursorPhysics("mass", v[0])}minValue={0.1}maxValue={10}step={0.01}@@ -575,6 +697,18 @@ export function ConfigSidebar() {/>}/>+ <Field name="Motion Blur" icon={<IconLucideWind class="size-4" />}>+ <Slider+ value={[project.cursor.motionBlur ?? 0]}+ onChange={(v) =>+ setProject("cursor", "motionBlur" as any, v[0])+ }+ minValue={0}+ maxValue={1}+ step={0.01}+ formatTooltip={(value) => `${Math.round(value * 100)}%`}+ />+ </Field></Show>{/* <Field name="Motion Blur">diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.tsindex 0a0199912..af8507f86 100644--- a/apps/desktop/src/utils/tauri.ts+++ b/apps/desktop/src/utils/tauri.ts@@ -385,7 +385,7 @@ export type Crop = { position: XY<number>; size: XY<number> }export type CurrentRecording = { target: CurrentRecordingTarget; mode: RecordingMode }export type CurrentRecordingChanged = nullexport type CurrentRecordingTarget = { window: { id: WindowId; bounds: LogicalBounds } } | { screen: { id: DisplayId } } | { area: { screen: DisplayId; bounds: LogicalBounds } }-export type CursorAnimationStyle = "regular" | "slow" | "fast"+export type CursorAnimationStyle = "slow" | "mellow" | "custom"export type CursorConfiguration = { hide?: boolean; hideWhenIdle?: boolean; hideWhenIdleDelay?: number; size: number; type: CursorType; animationStyle: CursorAnimationStyle; tension: number; mass: number; friction: number; raw?: boolean; motionBlur?: number; useSvg?: boolean }export type CursorMeta = { imagePath: string; hotspot: XY<number>; shape?: string | null }export type CursorType = "pointer" | "circle"diff --git a/crates/project/src/configuration.rs b/crates/project/src/configuration.rsindex e787e1b5a..16646bbce 100644--- a/crates/project/src/configuration.rs+++ b/crates/project/src/configuration.rs@@ -384,13 +384,39 @@ pub enum CursorType {Circle,}-#[derive(Type, Serialize, Deserialize, Clone, Debug, Default)]+#[derive(Type, Serialize, Deserialize, Clone, Copy, Debug, Default, PartialEq, Eq)]#[serde(rename_all = "camelCase")]pub enum CursorAnimationStyle {#[default]- Regular,Slow,- Fast,+ #[serde(alias = "regular", alias = "quick", alias = "rapid", alias = "fast")]+ Mellow,+ Custom,+}++#[derive(Clone, Copy, Debug)]+pub struct CursorSmoothingPreset {+ pub tension: f32,+ pub mass: f32,+ pub friction: f32,+}++impl CursorAnimationStyle {+ pub fn preset(self) -> Option<CursorSmoothingPreset> {+ match self {+ Self::Slow => Some(CursorSmoothingPreset {+ tension: 65.0,+ mass: 1.8,+ friction: 16.0,+ }),+ Self::Mellow => Some(CursorSmoothingPreset {+ tension: 120.0,+ mass: 1.1,+ friction: 18.0,+ }),+ Self::Custom => None,+ }+ }}#[derive(Type, Serialize, Deserialize, Clone, Debug)]@@ -422,20 +448,29 @@ fn yes() -> bool {impl Default for CursorConfiguration {fn default() -> Self {- Self {+ let animation_style = CursorAnimationStyle::default();+ let mut config = Self {hide: false,hide_when_idle: false,hide_when_idle_delay: Self::default_hide_when_idle_delay(),size: 100,r#type: CursorType::default(),- animation_style: CursorAnimationStyle::Regular,- tension: 100.0,- mass: 1.0,- friction: 20.0,+ animation_style,+ tension: 65.0,+ mass: 1.8,+ friction: 16.0,raw: false,motion_blur: 0.5,use_svg: true,+ };++ if let Some(preset) = animation_style.preset() {+ config.tension = preset.tension;+ config.mass = preset.mass;+ config.friction = preset.friction;}++ config}}impl CursorConfiguration {diff --git a/crates/rendering/src/cursor_interpolation.rs b/crates/rendering/src/cursor_interpolation.rsindex fff16b9f8..05dd03296 100644--- a/crates/rendering/src/cursor_interpolation.rs+++ b/crates/rendering/src/cursor_interpolation.rs@@ -38,7 +38,7 @@ pub fn interpolate_cursor(}if let Some(event) = cursor.moves.last()- && event.time_ms < time_ms+ && event.time_ms <= time_ms{return Some(InterpolatedCursorPosition {position: Coord::new(XY {@@ -54,10 +54,18 @@ pub fn interpolate_cursor(let events = get_smoothed_cursor_events(&cursor.moves, smoothing_config);interpolate_smoothed_position(&events, time_secs as f64, smoothing_config)} else {- let (pos, cursor_id) = cursor.moves.windows(2).find_map(|chunk| {+ let (pos, cursor_id, velocity) = cursor.moves.windows(2).find_map(|chunk| {if time_ms >= chunk[0].time_ms && time_ms < chunk[1].time_ms {let c = &chunk[0];- Some((XY::new(c.x as f32, c.y as f32), c.cursor_id.clone()))+ let next = &chunk[1];+ let delta_ms = (next.time_ms - c.time_ms) as f32;+ let dt = (delta_ms / 1000.0).max(0.000_1);+ let velocity = XY::new(((next.x - c.x) as f32) / dt, ((next.y - c.y) as f32) / dt);+ Some((+ XY::new(c.x as f32, c.y as f32),+ c.cursor_id.clone(),+ velocity,+ ))} else {None}@@ -68,7 +76,7 @@ pub fn interpolate_cursor(x: pos.x as f64,y: pos.y as f64,}),- velocity: XY::new(0.0, 0.0),+ velocity,cursor_id,})}diff --git a/crates/rendering/src/layers/cursor.rs b/crates/rendering/src/layers/cursor.rsindex a5a493581..fd4636848 100644--- a/crates/rendering/src/layers/cursor.rs+++ b/crates/rendering/src/layers/cursor.rs@@ -16,6 +16,8 @@ const CURSOR_CLICK_DURATION_MS: f64 = CURSOR_CLICK_DURATION * 1000.0;const CLICK_SHRINK_SIZE: f32 = 0.7;const CURSOR_IDLE_MIN_DELAY_MS: f64 = 500.0;const CURSOR_IDLE_FADE_OUT_MS: f64 = 400.0;+const MAX_CURSOR_VELOCITY_PX_PER_FRAME: f32 = 220.0;+const MOTION_BLUR_SPEED_BASE: f32 = 22.0;/// The size to render the svg to.static SVG_CURSOR_RASTERIZED_HEIGHT: u32 = 200;@@ -205,14 +207,30 @@ impl CursorLayer {return;};- let velocity: [f32; 2] = [0.0, 0.0];- // let velocity: [f32; 2] = [- // interpolated_cursor.velocity.x * 75.0,- // interpolated_cursor.velocity.y * 75.0,- // ];+ let fps = uniforms.frame_rate.max(1) as f32;+ let screen_size = constants.options.screen_size;+ let mut velocity = [+ (interpolated_cursor.velocity.x * screen_size.x as f32) / fps,+ (interpolated_cursor.velocity.y * screen_size.y as f32) / fps,+ ];+ velocity[0] = velocity[0].clamp(+ -MAX_CURSOR_VELOCITY_PX_PER_FRAME,+ MAX_CURSOR_VELOCITY_PX_PER_FRAME,+ );+ velocity[1] = velocity[1].clamp(+ -MAX_CURSOR_VELOCITY_PX_PER_FRAME,+ MAX_CURSOR_VELOCITY_PX_PER_FRAME,+ );let speed = (velocity[0] * velocity[0] + velocity[1] * velocity[1]).sqrt();- let motion_blur_amount = (speed * 0.3).min(1.0) * 0.0; // uniforms.project.cursor.motion_blur;+ let user_motion_blur = uniforms.project.cursor.motion_blur.clamp(0.0, 1.0);+ let intensity_multiplier = (user_motion_blur / 0.35).max(0.0);+ let motion_blur_amount = if user_motion_blur <= f32::EPSILON {+ 0.0+ } else {+ let dynamic = (speed / MOTION_BLUR_SPEED_BASE).clamp(0.0, 1.0);+ (dynamic.powf(0.75) * intensity_multiplier).min(2.5)+ };let mut cursor_opacity = 1.0f32;if uniforms.project.cursor.hide_when_idle && !cursor.moves.is_empty() {diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rsindex 99cfe29fc..0650853a0 100644--- a/crates/rendering/src/lib.rs+++ b/crates/rendering/src/lib.rs@@ -363,6 +363,7 @@ impl RenderVideoConstants {pub struct ProjectUniforms {pub output_size: (u32, u32),pub cursor_size: f32,+ pub frame_rate: u32,display: CompositeVideoFrameUniforms,camera: Option<CompositeVideoFrameUniforms>,camera_only: Option<CompositeVideoFrameUniforms>,@@ -979,6 +980,7 @@ impl ProjectUniforms {zoom,scene,interpolated_cursor,+ frame_rate: fps,}}}diff --git a/crates/rendering/src/shaders/cursor.wgsl b/crates/rendering/src/shaders/cursor.wgslindex 4c3e3e2e0..63213bff7 100644--- a/crates/rendering/src/shaders/cursor.wgsl+++ b/crates/rendering/src/shaders/cursor.wgsl@@ -102,7 +102,7 @@ fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {);}- final_color *= vec4<f32>(1.0, 1.0, 1.0, 1.0 - motion_blur_amount * 0.2);+ // Preserve opacity regardless of blur intensity so the cursor stays fully visible.final_color *= opacity;return final_color;diff --git a/crates/rendering/src/spring_mass_damper.rs b/crates/rendering/src/spring_mass_damper.rsindex a5be0567a..91e175f07 100644--- a/crates/rendering/src/spring_mass_damper.rs+++ b/crates/rendering/src/spring_mass_damper.rs@@ -16,7 +16,7 @@ pub struct SpringMassDamperSimulation {pub target_position: XY<f32>,}-const SIMULATION_TICK: f32 = 1000.0 / 60.0;+const SIMULATION_TICK_MS: f32 = 1000.0 / 60.0;impl SpringMassDamperSimulation {pub fn new(config: SpringMassDamperSimulationConfig) -> Self {@@ -40,14 +40,16 @@ impl SpringMassDamperSimulation {self.target_position = target_position;}- pub fn run(&mut self, dt: f32) -> XY<f32> {- if dt == 0.0 {+ pub fn run(&mut self, dt_ms: f32) -> XY<f32> {+ if dt_ms <= 0.0 {return self.position;}- let mut t = 0.0;+ let mut remaining = dt_ms;- loop {+ while remaining > 0.0 {+ let step_ms = remaining.min(SIMULATION_TICK_MS);+ let tick = step_ms / 1000.0;let d = self.target_position - self.position;let spring_force = d * self.tension;@@ -57,16 +59,10 @@ impl SpringMassDamperSimulation {let accel = total_force / self.mass.max(0.001);- let tick = (SIMULATION_TICK / 1000.0).min(dt - t);-self.velocity = self.velocity + accel * tick;self.position = self.position + self.velocity * tick;- if t >= dt {- break;- }-- t = (t + SIMULATION_TICK).min(dt);+ remaining -= step_ms;}self.position