MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ScrollState.cpp
Go to the documentation of this file.
1#include "ScrollState.hpp"
2
3namespace MayaFlux::Kinesis {
4
6 glm::vec2 pixel_delta,
7 glm::vec2 visible_extent,
8 glm::vec2 viewport_size_pixels) noexcept
9{
10 return (pixel_delta / viewport_size_pixels) * visible_extent;
11}
12
14 glm::vec2 offset,
15 glm::vec2 viewport_extent,
16 AABB2D content_bounds) noexcept
17{
18 const float max_x = std::max(0.F, content_bounds.width() - viewport_extent.x);
19 const float max_y = std::max(0.F, content_bounds.height() - viewport_extent.y);
20
21 return { std::clamp(offset.x, 0.F, max_x), std::clamp(offset.y, 0.F, max_y) };
22}
23
24void apply_scroll(ScrollState& state, glm::vec2 delta) noexcept
25{
26 state.offset = clamp_offset_to_content(
27 state.offset + delta,
28 glm::vec2(state.viewport_bounds.width(), state.viewport_bounds.height()),
29 state.content_bounds);
30}
31
32void apply_wheel_scroll(ScrollState& state, double dx, double dy, float speed) noexcept
33{
34 apply_scroll(state, glm::vec2(static_cast<float>(dx), static_cast<float>(dy)) * speed);
35}
36
38{
39 return {
40 .view = glm::translate(glm::mat4(1.0F), glm::vec3(state.offset, 0.F)),
41 .projection = glm::mat4(1.0F),
42 };
43}
44
45} // namespace MayaFlux::Kinesis
uint64_t offset
Definition Composite.cpp:10
ViewTransform scroll_view_transform(const ScrollState &state) noexcept
Build an orthographic ViewTransform that translates by +offset.
void apply_wheel_scroll(ScrollState &state, double dx, double dy, float speed) noexcept
Apply a wheel-tick delta, scaled by speed, and clamp.
void apply_scroll(NavigationState &st, float ticks)
Dolly eye along the current forward vector.
double speed(const Memory::HistoryBuffer< double > &history, double dt) noexcept
Absolute value of a scalar first difference.
glm::vec2 drag_to_offset_delta(glm::vec2 pixel_delta, glm::vec2 visible_extent, glm::vec2 viewport_size_pixels) noexcept
Convert a pixel-space drag delta into a content-space delta.
glm::vec2 clamp_offset_to_content(glm::vec2 offset, glm::vec2 viewport_extent, AABB2D content_bounds) noexcept
Clamp a content-space offset so a viewport of the given extent never scrolls past the edges of a cont...
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:63
CPU-side scroll offset for a bounded content region.
View and projection matrices as a named push constant slot.