summaryrefslogtreecommitdiff
path: root/scene/gui/scroll_bar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/scroll_bar.cpp')
-rw-r--r--scene/gui/scroll_bar.cpp152
1 files changed, 67 insertions, 85 deletions
diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp
index df27fb0e6b..07380f45cc 100644
--- a/scene/gui/scroll_bar.cpp
+++ b/scene/gui/scroll_bar.cpp
@@ -300,24 +300,24 @@ void ScrollBar::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
- if (has_node(drag_slave_path)) {
- Node *n = get_node(drag_slave_path);
- drag_slave = Object::cast_to<Control>(n);
+ if (has_node(drag_node_path)) {
+ Node *n = get_node(drag_node_path);
+ drag_node = Object::cast_to<Control>(n);
}
- if (drag_slave) {
- drag_slave->connect("gui_input", this, "_drag_slave_input");
- drag_slave->connect("tree_exiting", this, "_drag_slave_exit", varray(), CONNECT_ONESHOT);
+ if (drag_node) {
+ drag_node->connect("gui_input", this, "_drag_node_input");
+ drag_node->connect("tree_exiting", this, "_drag_node_exit", varray(), CONNECT_ONESHOT);
}
}
if (p_what == NOTIFICATION_EXIT_TREE) {
- if (drag_slave) {
- drag_slave->disconnect("gui_input", this, "_drag_slave_input");
- drag_slave->disconnect("tree_exiting", this, "_drag_slave_exit");
+ if (drag_node) {
+ drag_node->disconnect("gui_input", this, "_drag_node_input");
+ drag_node->disconnect("tree_exiting", this, "_drag_node_exit");
}
- drag_slave = NULL;
+ drag_node = NULL;
}
if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
@@ -337,12 +337,13 @@ void ScrollBar::_notification(int p_what) {
scrolling = false;
set_physics_process_internal(false);
}
- } else if (drag_slave_touching) {
- if (drag_slave_touching_deaccel) {
+ } else if (drag_node_touching) {
+
+ if (drag_node_touching_deaccel) {
Vector2 pos = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0);
- pos += drag_slave_speed * get_physics_process_delta_time();
+ pos += drag_node_speed * get_physics_process_delta_time();
bool turnoff = false;
@@ -360,15 +361,15 @@ void ScrollBar::_notification(int p_what) {
set_value(pos.x);
- float sgn_x = drag_slave_speed.x < 0 ? -1 : 1;
- float val_x = Math::abs(drag_slave_speed.x);
+ float sgn_x = drag_node_speed.x < 0 ? -1 : 1;
+ float val_x = Math::abs(drag_node_speed.x);
val_x -= 1000 * get_physics_process_delta_time();
if (val_x < 0) {
turnoff = true;
}
- drag_slave_speed.x = sgn_x * val_x;
+ drag_node_speed.x = sgn_x * val_x;
} else {
@@ -384,29 +385,29 @@ void ScrollBar::_notification(int p_what) {
set_value(pos.y);
- float sgn_y = drag_slave_speed.y < 0 ? -1 : 1;
- float val_y = Math::abs(drag_slave_speed.y);
+ float sgn_y = drag_node_speed.y < 0 ? -1 : 1;
+ float val_y = Math::abs(drag_node_speed.y);
val_y -= 1000 * get_physics_process_delta_time();
if (val_y < 0) {
turnoff = true;
}
- drag_slave_speed.y = sgn_y * val_y;
+ drag_node_speed.y = sgn_y * val_y;
}
if (turnoff) {
set_physics_process_internal(false);
- drag_slave_touching = false;
- drag_slave_touching_deaccel = false;
+ drag_node_touching = false;
+ drag_node_touching_deaccel = false;
}
} else {
if (time_since_motion == 0 || time_since_motion > 0.1) {
- Vector2 diff = drag_slave_accum - last_drag_slave_accum;
- last_drag_slave_accum = drag_slave_accum;
- drag_slave_speed = diff / get_physics_process_delta_time();
+ Vector2 diff = drag_node_accum - last_drag_node_accum;
+ last_drag_node_accum = drag_node_accum;
+ drag_node_speed = diff / get_physics_process_delta_time();
}
time_since_motion += get_physics_process_delta_time();
@@ -544,15 +545,15 @@ float ScrollBar::get_custom_step() const {
return custom_step;
}
-void ScrollBar::_drag_slave_exit() {
+void ScrollBar::_drag_node_exit() {
- if (drag_slave) {
- drag_slave->disconnect("gui_input", this, "_drag_slave_input");
+ if (drag_node) {
+ drag_node->disconnect("gui_input", this, "_drag_node_input");
}
- drag_slave = NULL;
+ drag_node = NULL;
}
-void ScrollBar::_drag_slave_input(const Ref<InputEvent> &p_input) {
+void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) {
Ref<InputEventMouseButton> mb = p_input;
@@ -563,43 +564,30 @@ void ScrollBar::_drag_slave_input(const Ref<InputEvent> &p_input) {
if (mb->is_pressed()) {
- if (drag_slave_touching) {
- set_physics_process_internal(false);
- drag_slave_touching_deaccel = false;
- drag_slave_touching = false;
- drag_slave_speed = Vector2();
- drag_slave_accum = Vector2();
- last_drag_slave_accum = Vector2();
- drag_slave_from = Vector2();
- }
+ drag_node_speed = Vector2();
+ drag_node_accum = Vector2();
+ last_drag_node_accum = Vector2();
+ drag_node_from = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0);
- if (true) {
- drag_slave_speed = Vector2();
- drag_slave_accum = Vector2();
- last_drag_slave_accum = Vector2();
- //drag_slave_from=Vector2(h_scroll->get_val(),v_scroll->get_val());
- drag_slave_from = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0);
+ drag_node_touching = OS::get_singleton()->has_touchscreen_ui_hint();
+ drag_node_touching_deaccel = false;
+ time_since_motion = 0;
- drag_slave_touching = OS::get_singleton()->has_touchscreen_ui_hint();
- drag_slave_touching_deaccel = false;
+ if (drag_node_touching) {
+ set_physics_process_internal(true);
time_since_motion = 0;
- if (drag_slave_touching) {
- set_physics_process_internal(true);
- time_since_motion = 0;
- }
}
} else {
- if (drag_slave_touching) {
+ if (drag_node_touching) {
- if (drag_slave_speed == Vector2()) {
- drag_slave_touching_deaccel = false;
- drag_slave_touching = false;
+ if (drag_node_speed == Vector2()) {
+ drag_node_touching_deaccel = false;
+ drag_node_touching = false;
set_physics_process_internal(false);
} else {
-
- drag_slave_touching_deaccel = true;
+ drag_node_touching_deaccel = true;
}
}
}
@@ -609,60 +597,54 @@ void ScrollBar::_drag_slave_input(const Ref<InputEvent> &p_input) {
if (mm.is_valid()) {
- if (drag_slave_touching && !drag_slave_touching_deaccel) {
+ if (drag_node_touching && !drag_node_touching_deaccel) {
Vector2 motion = Vector2(mm->get_relative().x, mm->get_relative().y);
- drag_slave_accum -= motion;
- Vector2 diff = drag_slave_from + drag_slave_accum;
+ drag_node_accum -= motion;
+ Vector2 diff = drag_node_from + drag_node_accum;
if (orientation == HORIZONTAL)
set_value(diff.x);
- /*
- else
- drag_slave_accum.x=0;
- */
+
if (orientation == VERTICAL)
set_value(diff.y);
- /*
- else
- drag_slave_accum.y=0;
- */
+
time_since_motion = 0;
}
}
}
-void ScrollBar::set_drag_slave(const NodePath &p_path) {
+void ScrollBar::set_drag_node(const NodePath &p_path) {
if (is_inside_tree()) {
- if (drag_slave) {
- drag_slave->disconnect("gui_input", this, "_drag_slave_input");
- drag_slave->disconnect("tree_exiting", this, "_drag_slave_exit");
+ if (drag_node) {
+ drag_node->disconnect("gui_input", this, "_drag_node_input");
+ drag_node->disconnect("tree_exiting", this, "_drag_node_exit");
}
}
- drag_slave = NULL;
- drag_slave_path = p_path;
+ drag_node = NULL;
+ drag_node_path = p_path;
if (is_inside_tree()) {
if (has_node(p_path)) {
Node *n = get_node(p_path);
- drag_slave = Object::cast_to<Control>(n);
+ drag_node = Object::cast_to<Control>(n);
}
- if (drag_slave) {
- drag_slave->connect("gui_input", this, "_drag_slave_input");
- drag_slave->connect("tree_exiting", this, "_drag_slave_exit", varray(), CONNECT_ONESHOT);
+ if (drag_node) {
+ drag_node->connect("gui_input", this, "_drag_node_input");
+ drag_node->connect("tree_exiting", this, "_drag_node_exit", varray(), CONNECT_ONESHOT);
}
}
}
-NodePath ScrollBar::get_drag_slave() const {
+NodePath ScrollBar::get_drag_node() const {
- return drag_slave_path;
+ return drag_node_path;
}
void ScrollBar::set_smooth_scroll_enabled(bool p_enable) {
@@ -678,8 +660,8 @@ void ScrollBar::_bind_methods() {
ClassDB::bind_method(D_METHOD("_gui_input"), &ScrollBar::_gui_input);
ClassDB::bind_method(D_METHOD("set_custom_step", "step"), &ScrollBar::set_custom_step);
ClassDB::bind_method(D_METHOD("get_custom_step"), &ScrollBar::get_custom_step);
- ClassDB::bind_method(D_METHOD("_drag_slave_input"), &ScrollBar::_drag_slave_input);
- ClassDB::bind_method(D_METHOD("_drag_slave_exit"), &ScrollBar::_drag_slave_exit);
+ ClassDB::bind_method(D_METHOD("_drag_node_input"), &ScrollBar::_drag_node_input);
+ ClassDB::bind_method(D_METHOD("_drag_node_exit"), &ScrollBar::_drag_node_exit);
ADD_SIGNAL(MethodInfo("scrolling"));
@@ -691,13 +673,13 @@ ScrollBar::ScrollBar(Orientation p_orientation) {
orientation = p_orientation;
highlight = HIGHLIGHT_NONE;
custom_step = -1;
- drag_slave = NULL;
+ drag_node = NULL;
drag.active = false;
- drag_slave_speed = Vector2();
- drag_slave_touching = false;
- drag_slave_touching_deaccel = false;
+ drag_node_speed = Vector2();
+ drag_node_touching = false;
+ drag_node_touching_deaccel = false;
scrolling = false;
target_scroll = 0;