MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ wire_canvas_drag()

MAYAFLUX_API void MayaFlux::Portal::Forma::Geometry::wire_canvas_drag ( Context &  ctx,
uint32_t  id,
const std::shared_ptr< MappedState< std::vector< float > > > &  state,
Kinesis::AABB2D  bounds 
)

Wire drag interaction for a drawable canvas element.

Registers a left-button drag callback on ctx that maps NDC cursor position to a sample index and amplitude, writes into state, and increments the version. Linear interpolation fills the range between the previously touched index and the current one, preventing sparse samples under fast drag.

Parameters
ctxContext owning the element.
idElement id from the Mapped.
stateMappedState<vector<float>> to write into.
boundsCanvas NDC bounds — must match those passed to drawable_canvas().

Definition at line 445 of file FormFactory.cpp.

450{
451 struct DragState {
452 std::optional<size_t> prev_index;
453 };
454 auto ds = std::make_shared<DragState>();
455
456 ctx.on_drag(id, IO::MouseButtons::Left,
457 [state, bounds, ds](uint32_t, glm::vec2 ndc) {
458 auto& v = state->value;
459 if (v.empty())
460 return;
461
462 const float t = (ndc.x - bounds.min.x) / bounds.width();
463 const float a = (ndc.y - bounds.min.y) / bounds.height();
464
465 Kinesis::stroke_samples(v, ds->prev_index, t, a);
466 ++state->version;
467 });
468
469 ctx.on_release(id, IO::MouseButtons::Left, [ds](uint32_t, glm::vec2) {
470 ds->prev_index = std::nullopt;
471 });
472}
size_t a
void on_release(uint32_t id, IO::MouseButtons btn, PressFn fn)
Called when a mouse button is released over an element.
Definition Context.cpp:43
void on_drag(uint32_t id, IO::MouseButtons btn, MoveFn fn)
Called on each mouse-move event while btn is held, tracking the element where the drag began even whe...
Definition Context.cpp:53
float height() const noexcept
Definition Bounds.hpp:80
float width() const noexcept
Definition Bounds.hpp:79

References a, MayaFlux::Kinesis::AABB2D::height(), MayaFlux::IO::Left, MayaFlux::Kinesis::AABB2D::min, MayaFlux::Portal::Forma::Context::on_drag(), MayaFlux::Portal::Forma::Context::on_release(), MayaFlux::Kinesis::stroke_samples(), and MayaFlux::Kinesis::AABB2D::width().

Referenced by paint_over().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: