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

◆ bind_pan_zoom_preset() [2/2]

MAYAFLUX_API void MayaFlux::bind_pan_zoom_preset ( const std::shared_ptr< Core::Window > &  window,
const std::shared_ptr< Buffers::RenderProcessor > &  processor,
const Kinesis::PanZoom2DConfig config = {},
const Kinesis::PanZoom2DKeyMap key_map = {},
const std::string &  name = "default" 
)

Bind the 2D pan/zoom controller to a window and render processor.

Drag pans the view; scroll zooms by scaling the orthographic half-height. View matrix is always identity; only the orthographic projection changes.

Parameters
windowWindow supplying input events
processorRenderProcessor that receives the ViewTransform source
configPan/zoom tuning parameters
key_mapInput assignments; defaults to MMB drag
nameUnique prefix for registered events; must be unique per window

Definition at line 244 of file ViewportPreset.cpp.

250{
251 auto& record = s_registry[make_key(window, name)];
252 record.saved_config = window->get_input_config();
253 record.registered_events.clear();
254
255 auto st = std::make_shared<Kinesis::PanZoom2DState>(Kinesis::make_pan_zoom_state(config));
256
257 on_mouse_pressed(window, key_map.drag_button, [st](double /*x*/, double /*y*/) {
258 st->drag_held = true;
259 st->first_mouse = true; }, event_name(name, "drag_dn"));
260
261 on_mouse_released(window, key_map.drag_button, [st](double /*x*/, double /*y*/) { st->drag_held = false; }, event_name(name, "drag_up"));
262
263 on_mouse_move(window, [st, window_weak = std::weak_ptr<Core::Window>(window)](double x, double y) {
264 if (!st->drag_held) {
265 st->first_mouse = true;
266 return;
267 }
268 if (st->first_mouse) {
269 st->last_x = x;
270 st->last_y = y;
271 st->first_mouse = false;
272 return;
273 }
274 const auto dx = static_cast<float>(x - st->last_x);
275 const auto dy = static_cast<float>(y - st->last_y);
276 st->last_x = x;
277 st->last_y = y;
278
279 auto win = window_weak.lock();
280 if (!win)
281 return;
282 const auto& ws = win->get_state();
283 if (ws.current_width > 0 && ws.current_height > 0) {
284 Kinesis::apply_pan_zoom_pan(*st, dx, dy,
285 static_cast<float>(ws.current_width),
286 static_cast<float>(ws.current_height));
287 } }, event_name(name, "mouse"));
288
289 on_scroll(window, [st](double /*dx*/, double dy) { Kinesis::apply_pan_zoom_scroll(*st, static_cast<float>(dy)); }, event_name(name, "scroll"));
290
291 processor->set_view_transform_source(
292 [st, window_weak = std::weak_ptr<Core::Window>(window)]() -> Kinesis::ViewTransform {
293 auto win = window_weak.lock();
294 if (!win)
295 return {};
296 const auto& ws = win->get_state();
297 const float aspect = (ws.current_height > 0)
298 ? static_cast<float>(ws.current_width) / static_cast<float>(ws.current_height)
299 : 1.0F;
300 return Kinesis::compute_pan_zoom_view_transform(*st, aspect);
301 });
302}
void on_mouse_move(const std::shared_ptr< Core::Window > &window, std::function< void(double, double)> callback, std::string name)
Schedule a mouse movement handler.
Definition Chronie.cpp:217
void on_scroll(const std::shared_ptr< Core::Window > &window, std::function< void(double, double)> callback, std::string name)
Schedule a mouse scroll handler.
Definition Chronie.cpp:250
void on_mouse_pressed(const std::shared_ptr< Core::Window > &window, IO::MouseButtons button, std::function< void(double, double)> callback, std::string name)
Schedule a mouse button press handler.
Definition Chronie.cpp:183
void on_mouse_released(const std::shared_ptr< Core::Window > &window, IO::MouseButtons button, std::function< void(double, double)> callback, std::string name)
Schedule a mouse button release handler.
Definition Chronie.cpp:200
IO::MouseButtons drag_button
Button held to pan.

References MayaFlux::Kinesis::apply_pan_zoom_pan(), MayaFlux::Kinesis::apply_pan_zoom_scroll(), MayaFlux::Kinesis::compute_pan_zoom_view_transform(), MayaFlux::Kinesis::PanZoom2DKeyMap::drag_button, MayaFlux::Kinesis::make_pan_zoom_state(), on_mouse_move(), on_mouse_pressed(), on_mouse_released(), and on_scroll().

Referenced by bind_pan_zoom_preset(), and bind_viewport_preset().

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