Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
much more stable zoom interpolation
Brendan Allan0a187c07946a
diff --git a/Cargo.lock b/Cargo.lockindex 6b3834d0d..d0bc30774 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -496,6 +496,12 @@ version = "0.22.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"+[[package]]+name = "bezier_easing"+version = "0.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0fa4734ba28c4eb6dcd44213f969e007bd2a17f966151656d1c7676f8526bedd"+[[package]]name = "bindgen"version = "0.56.0"@@ -882,6 +888,7 @@ name = "cap-rendering"version = "0.1.0"dependencies = ["anyhow",+ "bezier_easing","bytemuck","cap-flags","cap-project",diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsxindex 2c8347d96..4cecad665 100644--- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx+++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx@@ -24,7 +24,11 @@ import {Toggle,Slider,} from "./ui";-import { DEFAULT_GRADIENT_FROM, DEFAULT_GRADIENT_TO } from "./projectConfig";+import {+ DEFAULT_GRADIENT_FROM,+ DEFAULT_GRADIENT_TO,+ DEFAULT_PROJECT_CONFIG,+} from "./projectConfig";const BACKGROUND_SOURCES = {wallpaper: "Wallpaper",@@ -450,10 +454,10 @@ export function ConfigSidebar() {<Fieldname="Size"icon={<IconCapEnlarge />}- value={`${project.camera.size ?? 30}%`}+ value={`${project.camera.size}%`}><Slider- value={[project.camera.size ?? 30]}+ value={[project.camera.size]}onChange={(v) => setProject("camera", "size", v[0])}minValue={20}maxValue={80}@@ -464,10 +468,16 @@ export function ConfigSidebar() {<Fieldname="Size During Zoom"icon={<IconCapEnlarge />}- value={`${project.camera.zoom_size ?? 20}%`}+ value={`${+ project.camera.zoom_size ??+ DEFAULT_PROJECT_CONFIG.camera.zoom_size+ }%`}><Slider- value={[project.camera.zoom_size ?? 20]}+ value={[+ project.camera.zoom_size ??+ DEFAULT_PROJECT_CONFIG.camera.zoom_size,+ ]}onChange={(v) => setProject("camera", "zoom_size", v[0])}minValue={10}maxValue={60}@@ -477,7 +487,10 @@ export function ConfigSidebar() {)}<Field name="Rounded Corners" icon={<IconCapCorners />}><Slider- value={[project.camera.rounding ?? 100.0]}+ value={[+ project.camera.rounding ??+ DEFAULT_PROJECT_CONFIG.camera.rounding,+ ]}onChange={(v) => setProject("camera", "rounding", v[0])}minValue={0}maxValue={100}@@ -721,37 +734,42 @@ export function ConfigSidebar() {<div class="w-full h-52 bg-gray-100 rounded-xl p-1"><divclass="w-full h-full bg-blue-400 rounded-lg relative"- onMouseMove={(e) => {- if (e.buttons === 1) {- const bounds =- e.currentTarget.getBoundingClientRect();+ onMouseDown={(downEvent) => {+ const bounds =+ downEvent.currentTarget.getBoundingClientRect();- setProject(- "timeline",- "zoomSegments",- value().selection.index,- "mode",- "manual",- {- x: Math.max(- Math.min(- (e.clientX - bounds.left) /- bounds.width,- 1- ),- 0- ),- y: Math.max(- Math.min(- (e.clientY - bounds.top) /- bounds.height,- 1- ),- 0- ),- }- );- }+ createRoot((dispose) => {+ createEventListenerMap(window, {+ mouseup: () => dispose(),+ mousemove: (moveEvent) => {+ setProject(+ "timeline",+ "zoomSegments",+ value().selection.index,+ "mode",+ "manual",+ {+ x: Math.max(+ Math.min(+ (moveEvent.clientX - bounds.left) /+ bounds.width,+ 1+ ),+ 0+ ),+ y: Math.max(+ Math.min(+ (moveEvent.clientY - bounds.top) /+ bounds.height,+ 1+ ),+ 0+ ),+ }+ );+ },+ });+ });}}><divdiff --git a/apps/desktop/src/routes/editor/Header.tsx b/apps/desktop/src/routes/editor/Header.tsxindex 8c5c116cf..2742f59b0 100644--- a/apps/desktop/src/routes/editor/Header.tsx+++ b/apps/desktop/src/routes/editor/Header.tsx@@ -234,6 +234,7 @@ import { Channel } from "@tauri-apps/api/core";import { save } from "@tauri-apps/plugin-dialog";import { DEFAULT_PROJECT_CONFIG } from "./projectConfig";import { createMutation } from "@tanstack/solid-query";+import { getRequestEvent } from "solid-js/web";function ExportButton() {const { videoId, project, prettyName } = useEditorContext();@@ -410,6 +411,8 @@ function ShareButton() {}};+ getRequestEvent()?.nativeEvent;+await commands.exportVideo(videoId,projectConfig,diff --git a/apps/desktop/src/routes/editor/projectConfig.ts b/apps/desktop/src/routes/editor/projectConfig.tsindex ca7465355..34a9ac8d2 100644--- a/apps/desktop/src/routes/editor/projectConfig.ts+++ b/apps/desktop/src/routes/editor/projectConfig.ts@@ -5,7 +5,7 @@ export type RGBColor = [number, number, number];export const DEFAULT_GRADIENT_FROM = [71, 133, 255] satisfies RGBColor;export const DEFAULT_GRADIENT_TO = [255, 71, 102] satisfies RGBColor;-export const DEFAULT_PROJECT_CONFIG: ProjectConfiguration = {+export const DEFAULT_PROJECT_CONFIG = {aspectRatio: null,background: {source: {@@ -26,18 +26,18 @@ export const DEFAULT_PROJECT_CONFIG: ProjectConfiguration = {rounding: 100,shadow: 50,size: 30,- zoom_size: 20,+ zoom_size: 60,},audio: { mute: false, improve: false },- cursor: {- hideWhenIdle: false,- size: 0,+ cursor: {+ hideWhenIdle: false,+ size: 0,type: "pointer",- animationStyle: "regular" as const+ animationStyle: "regular" as const,},hotkeys: { show: false },motionBlur: 0.2,-};+} satisfies ProjectConfiguration;export const ASPECT_RATIOS = {wide: { name: "Wide", ratio: [16, 9] },diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.tsindex f4a7722b4..a8b14ca3f 100644--- a/apps/desktop/src/utils/tauri.ts+++ b/apps/desktop/src/utils/tauri.ts@@ -237,7 +237,7 @@ export type CursorConfiguration = { hideWhenIdle: boolean; size: number; type: Cexport type CursorType = "pointer" | "circle"export type Display = { path: string }export type EditorStateChanged = { playhead_position: number }-export type Flags = { recordMouse: boolean; split: boolean; pauseResume: boolean; zoom: boolean; customS3: boolean }+export type Flags = { recordMouse: boolean; split: boolean; pauseResume: boolean; zoom: boolean }export type GeneralSettingsStore = { uploadIndividualFiles?: boolean; openEditorAfterRecording?: boolean; hideDockIcon?: boolean; autoCreateShareableLink?: boolean; enableNotifications?: boolean; disableAutoOpenLinks?: boolean; hasCompletedStartup?: boolean; theme?: AppTheme }export type Hotkey = { code: string; meta: boolean; ctrl: boolean; alt: boolean; shift: boolean }export type HotkeyAction = "startRecording" | "stopRecording" | "restartRecording" | "takeScreenshot"diff --git a/crates/flags/src/lib.rs b/crates/flags/src/lib.rsindex be57136c1..1d3980908 100644--- a/crates/flags/src/lib.rs+++ b/crates/flags/src/lib.rs@@ -5,13 +5,11 @@ pub struct Flags {pub split: bool,pub pause_resume: bool,pub zoom: bool,- pub custom_s3: bool,}pub const FLAGS: Flags = Flags {record_mouse: false, // cfg!(debug_assertions),split: false, // cfg!(debug_assertions),- pause_resume: cfg!(debug_assertions),- zoom: false, // cfg!(debug_assertions),- custom_s3: true,+ pause_resume: false, // cfg!(debug_assertions),+ zoom: cfg!(debug_assertions),};diff --git a/crates/rendering/Cargo.toml b/crates/rendering/Cargo.tomlindex 5cf21305c..81f67f86f 100644--- a/crates/rendering/Cargo.toml+++ b/crates/rendering/Cargo.toml@@ -19,6 +19,7 @@ ffmpeg.workspace = trueffmpeg-sys-next.workspace = truefutures = "0.3.30"thiserror.workspace = true+bezier_easing = "0.1.1"[target.'cfg(unix)'.dependencies]nix = { version = "0.29.0", features = ["fs"] }diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rsindex a4f8bbf2e..146dd7836 100644--- a/crates/rendering/src/lib.rs+++ b/crates/rendering/src/lib.rs@@ -718,7 +718,7 @@ pub enum ZoomPosition {#[derive(Debug, PartialEq)]pub struct ZoomKeyframes(Vec<ZoomKeyframe>);-pub const ZOOM_DURATION: f64 = 0.8;+pub const ZOOM_DURATION: f64 = 0.6;#[cfg(test)]mod test {@@ -976,6 +976,7 @@ mod test {ZoomKeyframe {time: 2.5 + ZOOM_DURATION,scale: 1.0,+ has_segment: false,..base}])@@ -1181,26 +1182,23 @@ impl ZoomKeyframes {let keyframe_length = next.time - prev.time;let delta_time = time - prev.time;- let t = do_easing(delta_time / keyframe_length);-- let position = match (&prev.position, &next.position) {- (ZoomPosition::Manual { x: x1, y: y1 }, ZoomPosition::Manual { x: x2, y: y2 }) => {- ZoomPosition::Manual {- x: x1 + (x2 - x1) * t as f32,- y: y1 + (y2 - y1) * t as f32,- }- }- _ => ZoomPosition::Manual { x: 0.0, y: 0.0 },+ let ease = if next.scale >= prev.scale {+ bezier_easing::bezier_easing(0.1, 0.0, 0.3, 1.0).unwrap()+ } else {+ bezier_easing::bezier_easing(0.5, 0.0, 0.5, 1.0).unwrap()};+ let time_t = delta_time / keyframe_length;+let keyframe_diff = next.scale - prev.scale;- let amount = prev.scale + (keyframe_diff) * t;+ let amount = prev.scale + (keyframe_diff) * time_t;- InterpolatedZoom {- amount: prev.scale + (next.scale - prev.scale) * t,- position,- t: do_easing(if prev.scale > 1.0 && next.scale > 1.0 {+ let time_t = ease(time_t as f32) as f64;++ // the process we use to get to this is way too convoluted lol+ let t = ease(+ (if prev.scale > 1.0 && next.scale > 1.0 {if !next.has_segment {(amount - 1.0) / (prev.scale - 1.0)} else if !prev.has_segment {@@ -1214,44 +1212,31 @@ impl ZoomKeyframes {(amount - 1.0) / (prev.scale - 1.0)} else {0.0- }),+ }) as f32,+ ) as f64;++ let position = match (&prev.position, &next.position) {+ (ZoomPosition::Manual { x: x1, y: y1 }, ZoomPosition::Manual { x: x2, y: y2 }) => {+ ZoomPosition::Manual {+ x: x1 + (x2 - x1) * time_t as f32,+ y: y1 + (y2 - y1) * time_t as f32,+ }+ }+ _ => ZoomPosition::Manual { x: 0.0, y: 0.0 },+ };++ InterpolatedZoom {+ amount: if next.scale > prev.scale {+ prev.scale + (next.scale - prev.scale) * t+ } else {+ prev.scale + (next.scale - prev.scale) * (1.0 - t)+ },+ position,+ t,}}}-// fn do_easing(t: f64) -> f64 {-// if t < 0.5 {-// 4.0 * t * t * t-// } else {-// 1.0 - f64::powf(-2.0 * t + 2.0, 3.0) / 2.0-// }-// }--// fn do_easing(t: f64) -> f64 {-// if t < 0.5 {-// 2.0 * t * t-// } else {-// -1.0 + (4.0 - 2.0 * t) * t-// }-// }--// fn do_easing(t: f64) -> f64 {-// 0.5 * (1.0 - f64::cos(f64::consts::PI * t))-// }--// fn do_easing(t: f64) -> f64 {-// let t = t - 1.0;-// t * t * t + 1.0-// }--// fn do_easing(t: f64) -> f64 {-// f64::sin((t * f64::consts::PI) / 2.0)-// }--fn do_easing(t: f64) -> f64 {- 1.0 - (1.0 - t) * (1.0 - t)-}-#[derive(Clone)]pub struct RenderedFrame {pub data: Vec<u8>,diff --git a/crates/rendering/src/zoom.rs b/crates/rendering/src/zoom.rsnew file mode 100644index 000000000..e69de29bb