summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/base_button.cpp5
-rw-r--r--scene/gui/base_button.h2
-rw-r--r--scene/gui/control.cpp2
-rw-r--r--scene/gui/rich_text_label.cpp3
-rw-r--r--scene/gui/scroll_bar.cpp247
-rw-r--r--scene/gui/scroll_bar.h20
-rw-r--r--scene/gui/scroll_container.cpp2
7 files changed, 275 insertions, 6 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index 2e03871063..ac2417d539 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -276,6 +276,10 @@ bool BaseButton::is_pressed() const {
return toggle_mode?status.pressed:status.press_attempt;
}
+bool BaseButton::is_hovered() const {
+
+ return status.hovering;
+}
BaseButton::DrawMode BaseButton::get_draw_mode() const {
@@ -337,6 +341,7 @@ void BaseButton::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_input_event"),&BaseButton::_input_event);
ObjectTypeDB::bind_method(_MD("set_pressed","pressed"),&BaseButton::set_pressed);
ObjectTypeDB::bind_method(_MD("is_pressed"),&BaseButton::is_pressed);
+ ObjectTypeDB::bind_method(_MD("is_hovered"),&BaseButton::is_hovered);
ObjectTypeDB::bind_method(_MD("set_toggle_mode","enabled"),&BaseButton::set_toggle_mode);
ObjectTypeDB::bind_method(_MD("is_toggle_mode"),&BaseButton::is_toggle_mode);
ObjectTypeDB::bind_method(_MD("set_disabled","disabled"),&BaseButton::set_disabled);
diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h
index 65563ddc03..a2c640b9cf 100644
--- a/scene/gui/base_button.h
+++ b/scene/gui/base_button.h
@@ -83,6 +83,8 @@ public:
bool is_pressed() const; ///< return wether button is pressed (toggled in)
bool is_pressing() const; ///< return wether button is pressed (toggled in)
+ bool is_hovered() const;
+
void set_pressed(bool p_pressed); ///only works in toggle mode
void set_toggle_mode(bool p_on);
bool is_toggle_mode() const;
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 4b4b4b3c73..6878793360 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -1002,7 +1002,7 @@ void Control::_window_input_event(InputEvent p_event) {
}
- p_event.mouse_button.global_x = pos.x;
+ p_event.mouse_button.global_x = pos.x;
p_event.mouse_button.global_y = pos.y;
pos = window->focus_inv_xform.xform(pos);
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 241d66fce4..94df42fc8f 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -1561,8 +1561,9 @@ RichTextLabel::RichTextLabel() {
scroll_active=true;
scroll_w=0;
- vscroll = memnew( VScrollBar );
+ vscroll = memnew( VScrollBar );
add_child(vscroll);
+ vscroll->set_drag_slave(String(".."));
vscroll->set_step(1);
vscroll->set_anchor_and_margin( MARGIN_TOP, ANCHOR_BEGIN, 0);
vscroll->set_anchor_and_margin( MARGIN_BOTTOM, ANCHOR_END, 0);
diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp
index fdd30c5f60..c661a804b3 100644
--- a/scene/gui/scroll_bar.cpp
+++ b/scene/gui/scroll_bar.cpp
@@ -29,7 +29,7 @@
#include "scroll_bar.h"
#include "os/keyboard.h"
#include "print_string.h"
-
+#include "os/os.h"
bool ScrollBar::focus_by_default=false;
@@ -293,6 +293,117 @@ void ScrollBar::_notification(int p_what) {
}
+ if (p_what==NOTIFICATION_ENTER_SCENE) {
+
+
+ if (has_node(drag_slave_path)) {
+ Node *n = get_node(drag_slave_path);
+ drag_slave=n->cast_to<Control>();
+ }
+
+ if (drag_slave) {
+ drag_slave->connect("input_event",this,"_drag_slave_input");
+ drag_slave->connect("exit_scene",this,"_drag_slave_exit",varray(),CONNECT_ONESHOT);
+ }
+
+
+ }
+ if (p_what==NOTIFICATION_EXIT_SCENE) {
+
+ if (drag_slave) {
+ drag_slave->disconnect("input_event",this,"_drag_slave_input");
+ drag_slave->disconnect("exit_scene",this,"_drag_slave_exit");
+ }
+
+ drag_slave=NULL;
+
+ }
+
+ if (p_what==NOTIFICATION_FIXED_PROCESS) {
+
+ if (drag_slave_touching) {
+
+ if (drag_slave_touching_deaccel) {
+
+ Vector2 pos = Vector2(orientation==HORIZONTAL?get_val():0,orientation==VERTICAL?get_val():0);
+ pos+=drag_slave_speed*get_fixed_process_delta_time();
+
+ bool turnoff=false;
+
+ if (orientation==HORIZONTAL) {
+
+ if (pos.x<0) {
+ pos.x=0;
+ turnoff=true;
+ }
+
+ if (pos.x > (get_max()-get_page())) {
+ pos.x=get_max()-get_page();
+ turnoff=true;
+ }
+
+ set_val(pos.x);
+
+ float sgn_x = drag_slave_speed.x<0? -1 : 1;
+ float val_x = Math::abs(drag_slave_speed.x);
+ val_x-=1000*get_fixed_process_delta_time();
+
+ if (val_x<0) {
+ turnoff=true;
+ }
+
+ drag_slave_speed.x=sgn_x*val_x;
+
+ } else {
+
+
+ if (pos.y<0) {
+ pos.y=0;
+ turnoff=true;
+ }
+
+ if (pos.y > (get_max()-get_page())) {
+ pos.y=get_max()-get_page();
+ turnoff=true;
+ }
+
+ set_val(pos.y);
+
+ float sgn_y = drag_slave_speed.y<0? -1 : 1;
+ float val_y = Math::abs(drag_slave_speed.y);
+ val_y-=1000*get_fixed_process_delta_time();
+
+ if (val_y<0) {
+ turnoff=true;
+ }
+ drag_slave_speed.y=sgn_y*val_y;
+ }
+
+
+ if (turnoff) {
+ set_fixed_process(false);
+ drag_slave_touching=false;
+ drag_slave_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_fixed_process_delta_time();
+ }
+
+ time_since_motion+=get_fixed_process_delta_time();
+ }
+ }
+
+
+ }
+
if (p_what==NOTIFICATION_MOUSE_EXIT) {
hilite=HILITE_NONE;
@@ -432,6 +543,131 @@ float ScrollBar::get_custom_step() const {
}
+void ScrollBar::_drag_slave_exit() {
+
+ if (drag_slave) {
+ drag_slave->disconnect("input_event",this,"_drag_slave_input");
+ }
+ drag_slave=NULL;
+}
+
+
+void ScrollBar::_drag_slave_input(const InputEvent& p_input) {
+
+ switch(p_input.type) {
+
+ case InputEvent::MOUSE_BUTTON: {
+
+ const InputEventMouseButton &mb=p_input.mouse_button;
+
+ if (mb.button_index!=1)
+ break;
+
+ if (mb.pressed) {
+
+ if (drag_slave_touching) {
+ set_fixed_process(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();
+ }
+
+ 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_val():0,orientation==VERTICAL?get_val():0);
+
+ drag_slave_touching=OS::get_singleton()->has_touchscreen_ui_hint();
+ drag_slave_touching_deaccel=false;
+ time_since_motion=0;
+ if (drag_slave_touching) {
+ set_fixed_process(true);
+ time_since_motion=0;
+
+ }
+ }
+
+ } else {
+
+ if (drag_slave_touching) {
+
+ if (drag_slave_speed==Vector2()) {
+ drag_slave_touching_deaccel=false;
+ drag_slave_touching=false;
+ set_fixed_process(false);
+ } else {
+
+ drag_slave_touching_deaccel=true;
+ }
+ }
+ }
+ } break;
+ case InputEvent::MOUSE_MOTION: {
+
+ const InputEventMouseMotion &mm=p_input.mouse_motion;
+
+ if (drag_slave_touching && ! drag_slave_touching_deaccel) {
+
+ Vector2 motion = Vector2(mm.relative_x,mm.relative_y);
+
+ drag_slave_accum-=motion;
+ Vector2 diff = drag_slave_from+drag_slave_accum;
+
+ if (orientation==HORIZONTAL)
+ set_val(diff.x);
+ //else
+ // drag_slave_accum.x=0;
+ if (orientation==VERTICAL)
+ set_val(diff.y);
+ //else
+ // drag_slave_accum.y=0;
+ time_since_motion=0;
+ }
+
+ } break;
+ }
+}
+
+void ScrollBar::set_drag_slave(const NodePath& p_path) {
+
+ if (is_inside_scene()) {
+
+ if (drag_slave) {
+ drag_slave->disconnect("input_event",this,"_drag_slave_input");
+ drag_slave->disconnect("exit_scene",this,"_drag_slave_exit");
+ }
+ }
+
+ drag_slave=NULL;
+ drag_slave_path=p_path;
+
+ if (is_inside_scene()) {
+
+ if (has_node(p_path)) {
+ Node *n = get_node(p_path);
+ drag_slave=n->cast_to<Control>();
+ }
+
+ if (drag_slave) {
+ drag_slave->connect("input_event",this,"_drag_slave_input");
+ drag_slave->connect("exit_scene",this,"_drag_slave_exit",varray(),CONNECT_ONESHOT);
+ }
+ }
+}
+
+NodePath ScrollBar::get_drag_slave() const{
+
+
+ return drag_slave_path;
+}
+
+
+
#if 0
void ScrollBar::mouse_button(const Point2& p_pos, int b.button_index,bool b.pressed,int p_modifier_mask) {
@@ -571,6 +807,8 @@ void ScrollBar::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_input_event"),&ScrollBar::_input_event);
ObjectTypeDB::bind_method(_MD("set_custom_step","step"),&ScrollBar::set_custom_step);
ObjectTypeDB::bind_method(_MD("get_custom_step"),&ScrollBar::get_custom_step);
+ ObjectTypeDB::bind_method(_MD("_drag_slave_input"),&ScrollBar::_drag_slave_input);
+ ObjectTypeDB::bind_method(_MD("_drag_slave_exit"),&ScrollBar::_drag_slave_exit);
ADD_PROPERTY( PropertyInfo(Variant::REAL,"custom_step",PROPERTY_HINT_RANGE,"-1,4096"), _SCS("set_custom_step"),_SCS("get_custom_step"));
@@ -584,9 +822,14 @@ ScrollBar::ScrollBar(Orientation p_orientation)
orientation=p_orientation;
hilite=HILITE_NONE;
custom_step=-1;
+ drag_slave=NULL;
drag.active=false;
-
+
+ drag_slave_speed=Vector2();
+ drag_slave_touching=false;
+ drag_slave_touching_deaccel=false;
+
if (focus_by_default)
set_focus_mode( FOCUS_ALL );
diff --git a/scene/gui/scroll_bar.h b/scene/gui/scroll_bar.h
index 663d3ecd85..ad3d1a7f58 100644
--- a/scene/gui/scroll_bar.h
+++ b/scene/gui/scroll_bar.h
@@ -70,7 +70,22 @@ class ScrollBar : public Range {
double get_grabber_offset() const;
static void set_can_focus_by_default(bool p_can_focus);
-
+
+ Node* drag_slave;
+ NodePath drag_slave_path;
+
+ Vector2 drag_slave_speed;
+ Vector2 drag_slave_accum;
+ Vector2 drag_slave_from;
+ Vector2 last_drag_slave_accum;
+ float last_drag_slave_time;
+ float time_since_motion;
+ bool drag_slave_touching;
+ bool drag_slave_touching_deaccel;
+ bool click_handled;
+
+ void _drag_slave_exit();
+ void _drag_slave_input(const InputEvent& p_input);
void _input_event(InputEvent p_event);
protected:
@@ -83,6 +98,9 @@ public:
void set_custom_step(float p_custom_step);
float get_custom_step() const;
+ void set_drag_slave(const NodePath& p_path);
+ NodePath get_drag_slave() const;
+
virtual Size2 get_minimum_size() const;
ScrollBar(Orientation p_orientation=VERTICAL);
~ScrollBar();
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index 817833083e..c8f9ed16b5 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -235,7 +235,7 @@ void ScrollContainer::_notification(int p_what) {
}
if (pos.y<0) {
- pos.x=0;
+ pos.y=0;
turnoff_v=true;
}
if (pos.y > (v_scroll->get_max()-v_scroll->get_page())) {