Skip to content

Commit 8da8c9d

Browse files
committed
Update cursor type and improve circle cursor rendering
1 parent adf0428 commit 8da8c9d

3 files changed

Lines changed: 33 additions & 27 deletions

File tree

apps/desktop/src/utils/tauri.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ export type CurrentRecordingTarget = { window: { id: WindowId; bounds: LogicalBo
388388
export type CursorAnimationStyle = "slow" | "mellow" | "custom"
389389
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 }
390390
export type CursorMeta = { imagePath: string; hotspot: XY<number>; shape?: string | null }
391-
export type CursorType = "pointer" | "circle"
391+
export type CursorType = "auto" | "pointer" | "circle"
392392
export type Cursors = { [key in string]: string } | { [key in string]: CursorMeta }
393393
export type DeviceOrModelID = { DeviceID: string } | { ModelID: ModelIDType }
394394
export type DisplayId = string

crates/project/src/configuration.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,10 @@ impl CursorConfiguration {
500500
fn default_hide_when_idle_delay() -> f32 {
501501
2.0
502502
}
503+
504+
pub fn cursor_type(&self) -> &CursorType {
505+
&self.r#type
506+
}
503507
}
504508

505509
#[derive(Type, Serialize, Deserialize, Clone, Debug, Default)]

crates/rendering/src/layers/cursor.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const CURSOR_MAX_STRENGTH: f32 = 5.0;
2626
/// The size to render the svg to.
2727
static SVG_CURSOR_RASTERIZED_HEIGHT: u32 = 200;
2828

29-
const CIRCLE_CURSOR_SIZE: u32 = 64;
29+
const CIRCLE_CURSOR_SIZE: u32 = 256;
3030

3131
pub struct CursorLayer {
3232
statics: Statics,
@@ -201,36 +201,38 @@ impl CursorLayer {
201201
let size = CIRCLE_CURSOR_SIZE;
202202
let mut rgba = vec![0u8; (size * size * 4) as usize];
203203
let center = size as f32 / 2.0;
204-
let outer_radius = center - 2.0;
205-
let inner_radius = outer_radius - 4.0;
204+
let outer_radius = center - size as f32 * 0.08;
205+
let border_width = size as f32 * 0.025;
206+
let edge_softness = size as f32 * 0.015;
207+
208+
let fill_alpha = 0.2_f32;
209+
let border_alpha = 0.55_f32;
206210

207211
for y in 0..size {
208212
for x in 0..size {
209-
let dx = x as f32 - center;
210-
let dy = y as f32 - center;
213+
let dx = x as f32 - center + 0.5;
214+
let dy = y as f32 - center + 0.5;
211215
let dist = (dx * dx + dy * dy).sqrt();
212216
let idx = ((y * size + x) * 4) as usize;
213217

214-
if dist <= outer_radius && dist >= inner_radius {
215-
let edge_softness = 1.5;
216-
let outer_alpha = 1.0
217-
- ((dist - outer_radius + edge_softness) / edge_softness).clamp(0.0, 1.0);
218-
let inner_alpha = ((dist - inner_radius) / edge_softness).clamp(0.0, 1.0);
219-
let alpha = (outer_alpha * inner_alpha * 255.0) as u8;
220-
221-
rgba[idx] = 80;
222-
rgba[idx + 1] = 80;
223-
rgba[idx + 2] = 80;
224-
rgba[idx + 3] = alpha;
225-
} else if dist < inner_radius {
226-
let fill_alpha = 0.15;
227-
let edge_alpha = ((inner_radius - dist) / 2.0).clamp(0.0, 1.0);
228-
let alpha = (fill_alpha * edge_alpha * 255.0) as u8;
229-
230-
rgba[idx] = 128;
231-
rgba[idx + 1] = 128;
232-
rgba[idx + 2] = 128;
233-
rgba[idx + 3] = alpha;
218+
if dist <= outer_radius + edge_softness {
219+
let outer_fade = 1.0 - ((dist - outer_radius) / edge_softness).clamp(0.0, 1.0);
220+
221+
let border_start = outer_radius - border_width;
222+
let border_factor = if dist >= border_start {
223+
((dist - border_start) / border_width).clamp(0.0, 1.0)
224+
} else {
225+
0.0
226+
};
227+
228+
let base_alpha = fill_alpha + border_factor * (border_alpha - fill_alpha);
229+
let alpha = base_alpha * outer_fade;
230+
231+
let premul = (255.0 * alpha) as u8;
232+
rgba[idx] = premul;
233+
rgba[idx + 1] = premul;
234+
rgba[idx + 2] = premul;
235+
rgba[idx + 3] = premul;
234236
}
235237
}
236238
}
@@ -317,7 +319,7 @@ impl CursorLayer {
317319
}
318320
}
319321

320-
let cursor_type = uniforms.project.cursor.r#type.clone();
322+
let cursor_type = uniforms.project.cursor.cursor_type().clone();
321323

322324
if self.prev_cursor_type.as_ref() != Some(&cursor_type) {
323325
self.prev_cursor_type = Some(cursor_type.clone());

0 commit comments

Comments
 (0)