MayaFlux 1.0.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 245 of file ViewportPreset.cpp.

251{
252 auto& record = s_registry[make_key(window, name)];
253 record.saved_config = window->get_input_config();
254 record.registered_events.clear();
255
256 auto st = std::make_shared<Kinesis::PanZoom2DState>(Kinesis::make_pan_zoom_state(config));
257
258 on_mouse_pressed(window, key_map.drag_button, [st](double /*x*/, double /*y*/) {
259 st->drag_held = true;
260 st->first_mouse = true; }, event_name(name, "drag_dn"));
261
262 on_mouse_released(window, key_map.drag_button, [st](double /*x*/, double /*y*/) { st->drag_held = false; }, event_name(name, "drag_up"));
263
264 on_mouse_move(window, [st, window_weak = std::weak_ptr<Core::Window>(window)](double x, double y) {
265 if (!st->drag_held) {
266 st->first_mouse = true;
267 return;
268 }
269 if (st->first_mouse) {
270 st->last_x = x;
271 st->last_y = y;
272 st->first_mouse = false;
273 return;
274 }
275 const auto dx = static_cast<float>(x - st->last_x);
276 const auto dy = static_cast<float>(y - st->last_y);
277 st->last_x = x;
278 st->last_y = y;
279
280 auto win = window_weak.lock();
281 if (!win)
282 return;
283 const auto& ws = win->get_state();
284 if (ws.current_width > 0 && ws.current_height > 0) {
285 Kinesis::apply_pan_zoom_pan(*st, dx, dy,
286 static_cast<float>(ws.current_width),
287 static_cast<float>(ws.current_height));
288 } }, event_name(name, "mouse"));
289
290 on_scroll(window, [st](double /*dx*/, double dy) { Kinesis::apply_pan_zoom_scroll(*st, static_cast<float>(dy)); }, event_name(name, "scroll"));
291
292 processor->set_view_transform_source(
293 [st, window_weak = std::weak_ptr<Core::Window>(window)]() -> Kinesis::ViewTransform {
294 auto win = window_weak.lock();
295 if (!win)
296 return {};
297 const auto& ws = win->get_state();
298 const float aspect = (ws.current_height > 0)
299 ? static_cast<float>(ws.current_width) / static_cast<float>(ws.current_height)
300 : 1.0F;
301 return Kinesis::compute_pan_zoom_view_transform(*st, aspect);
302 });
303}
std::weak_ptr< Core::Window > window
Definition Picker.cpp:23
std::string name
Definition VKDevice.cpp:123
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:231
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:264
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:197
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:214
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(), name, on_mouse_move(), on_mouse_pressed(), on_mouse_released(), on_scroll(), and window.

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: