mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 06:38:03 +08:00
New node: Pointer Position (#3535)
* New node: Pointer Position * Fix test
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use core_types::{Ctx, ExtractAnimationTime, ExtractRealTime};
|
||||
use core_types::{Ctx, ExtractAnimationTime, ExtractPointer, ExtractRealTime};
|
||||
use glam::DVec2;
|
||||
|
||||
const DAY: f64 = 1000. * 3600. * 24.;
|
||||
|
||||
@@ -47,6 +48,12 @@ fn animation_time(ctx: impl Ctx + ExtractAnimationTime) -> f64 {
|
||||
ctx.try_animation_time().unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Produces the current position of the user's pointer within the document canvas.
|
||||
#[node_macro::node(category("Animation"))]
|
||||
fn pointer_position(ctx: impl Ctx + ExtractPointer) -> DVec2 {
|
||||
ctx.try_pointer().unwrap_or_default()
|
||||
}
|
||||
|
||||
// TODO: These nodes require more sophisticated algorithms for giving the correct result
|
||||
// #[node_macro::node(category("Animation"))]
|
||||
// fn month(ctx: impl Ctx + ExtractRealTime) -> f64 {
|
||||
|
||||
@@ -113,6 +113,7 @@ async fn create_context<'a: 'n>(
|
||||
.with_footprint(footprint)
|
||||
.with_real_time(render_config.time.time)
|
||||
.with_animation_time(render_config.time.animation_time.as_secs_f64())
|
||||
.with_pointer(render_config.pointer)
|
||||
.with_vararg(Box::new(render_params))
|
||||
.into_context();
|
||||
|
||||
|
||||
@@ -471,12 +471,41 @@ fn ceiling<T: num_traits::float::Float>(
|
||||
value.ceil()
|
||||
}
|
||||
|
||||
trait AbsoluteValue {
|
||||
fn abs(self) -> Self;
|
||||
}
|
||||
impl AbsoluteValue for DVec2 {
|
||||
fn abs(self) -> Self {
|
||||
DVec2::new(self.x.abs(), self.y.abs())
|
||||
}
|
||||
}
|
||||
impl AbsoluteValue for f32 {
|
||||
fn abs(self) -> Self {
|
||||
self.abs()
|
||||
}
|
||||
}
|
||||
impl AbsoluteValue for f64 {
|
||||
fn abs(self) -> Self {
|
||||
self.abs()
|
||||
}
|
||||
}
|
||||
impl AbsoluteValue for i32 {
|
||||
fn abs(self) -> Self {
|
||||
self.abs()
|
||||
}
|
||||
}
|
||||
impl AbsoluteValue for i64 {
|
||||
fn abs(self) -> Self {
|
||||
self.abs()
|
||||
}
|
||||
}
|
||||
|
||||
/// The absolute value function (`abs`) removes the negative sign from an input value, if present.
|
||||
#[node_macro::node(category("Math: Numeric"))]
|
||||
fn absolute_value<T: num_traits::sign::Signed>(
|
||||
fn absolute_value<T: AbsoluteValue>(
|
||||
_: impl Ctx,
|
||||
/// The number to be made positive.
|
||||
#[implementations(f64, f32, i32, i64)]
|
||||
#[implementations(f64, f32, i32, i64, DVec2)]
|
||||
value: T,
|
||||
) -> T {
|
||||
value.abs()
|
||||
|
||||
Reference in New Issue
Block a user