You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Add gesture to ViewPanner and simplify a bit its API
This commit is contained in:
@@ -1380,34 +1380,15 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
|
||||
accept_event();
|
||||
}
|
||||
}
|
||||
|
||||
Ref<InputEventMagnifyGesture> magnify_gesture = p_ev;
|
||||
if (magnify_gesture.is_valid()) {
|
||||
set_zoom_custom(zoom * magnify_gesture->get_factor(), magnify_gesture->get_position());
|
||||
}
|
||||
|
||||
Ref<InputEventPanGesture> pan_gesture = p_ev;
|
||||
if (pan_gesture.is_valid()) {
|
||||
h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * pan_gesture->get_delta().x / 8);
|
||||
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphEdit::_scroll_callback(Vector2 p_scroll_vec, bool p_alt) {
|
||||
if (p_scroll_vec.x != 0) {
|
||||
h_scroll->set_value(h_scroll->get_value() + (h_scroll->get_page() * Math::abs(p_scroll_vec.x) / 8) * SIGN(p_scroll_vec.x));
|
||||
} else {
|
||||
v_scroll->set_value(v_scroll->get_value() + (v_scroll->get_page() * Math::abs(p_scroll_vec.y) / 8) * SIGN(p_scroll_vec.y));
|
||||
}
|
||||
}
|
||||
|
||||
void GraphEdit::_pan_callback(Vector2 p_scroll_vec) {
|
||||
void GraphEdit::_pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event) {
|
||||
h_scroll->set_value(h_scroll->get_value() - p_scroll_vec.x);
|
||||
v_scroll->set_value(v_scroll->get_value() - p_scroll_vec.y);
|
||||
}
|
||||
|
||||
void GraphEdit::_zoom_callback(Vector2 p_scroll_vec, Vector2 p_origin, bool p_alt) {
|
||||
set_zoom_custom(p_scroll_vec.y < 0 ? zoom * zoom_step : zoom / zoom_step, p_origin);
|
||||
void GraphEdit::_zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event) {
|
||||
set_zoom_custom(zoom * p_zoom_factor, p_origin);
|
||||
}
|
||||
|
||||
void GraphEdit::set_connection_activity(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port, float p_activity) {
|
||||
@@ -1502,6 +1483,7 @@ void GraphEdit::set_zoom_step(float p_zoom_step) {
|
||||
}
|
||||
|
||||
zoom_step = p_zoom_step;
|
||||
panner->set_scroll_zoom_factor(zoom_step);
|
||||
}
|
||||
|
||||
float GraphEdit::get_zoom_step() const {
|
||||
@@ -2421,7 +2403,7 @@ GraphEdit::GraphEdit() {
|
||||
zoom_max = (1 * Math::pow(zoom_step, 4));
|
||||
|
||||
panner.instantiate();
|
||||
panner->set_callbacks(callable_mp(this, &GraphEdit::_scroll_callback), callable_mp(this, &GraphEdit::_pan_callback), callable_mp(this, &GraphEdit::_zoom_callback));
|
||||
panner->set_callbacks(callable_mp(this, &GraphEdit::_pan_callback), callable_mp(this, &GraphEdit::_zoom_callback));
|
||||
|
||||
top_layer = memnew(GraphEditFilter(this));
|
||||
add_child(top_layer, false, INTERNAL_MODE_BACK);
|
||||
|
||||
Reference in New Issue
Block a user