diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/3d/spatial.cpp | 14 | ||||
-rw-r--r-- | scene/3d/spatial.h | 6 | ||||
-rw-r--r-- | scene/gui/rich_text_label.cpp | 3 | ||||
-rw-r--r-- | scene/gui/scroll_bar.cpp | 228 | ||||
-rw-r--r-- | scene/gui/scroll_bar.h | 10 | ||||
-rw-r--r-- | scene/gui/scroll_container.cpp | 2 | ||||
-rw-r--r-- | scene/main/node.cpp | 20 | ||||
-rw-r--r-- | scene/main/node.h | 10 |
8 files changed, 277 insertions, 16 deletions
diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index de1fd7e8c0..c52503870f 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -494,6 +494,17 @@ Ref<World> Spatial::get_world() const { } +#ifdef TOOLS_ENABLED +void Spatial::set_import_transform(const Transform& p_transform) { + data.import_transform=p_transform; +} + +Transform Spatial::get_import_transform() const { + + return data.import_transform; +} +#endif + void Spatial::_bind_methods() { @@ -517,6 +528,9 @@ void Spatial::_bind_methods() { #ifdef TOOLS_ENABLED ObjectTypeDB::bind_method(_MD("_update_gizmo"), &Spatial::_update_gizmo); + ObjectTypeDB::bind_method(_MD("_set_import_transform"), &Spatial::set_import_transform); + ObjectTypeDB::bind_method(_MD("_get_import_transform"), &Spatial::get_import_transform); + ADD_PROPERTY( PropertyInfo(Variant::TRANSFORM,"_import_transform",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_import_transform"),_SCS("_get_import_transform")); #endif ObjectTypeDB::bind_method(_MD("update_gizmo"), &Spatial::update_gizmo); diff --git a/scene/3d/spatial.h b/scene/3d/spatial.h index e10629f7de..e1119be515 100644 --- a/scene/3d/spatial.h +++ b/scene/3d/spatial.h @@ -95,6 +95,7 @@ class Spatial : public Node { Ref<SpatialGizmo> gizmo; bool gizmo_disabled; bool gizmo_dirty; + Transform import_transform; #endif } data; @@ -158,6 +159,11 @@ public: Transform get_relative_transform(const Node *p_parent) const; +#ifdef TOOLS_ENABLED + void set_import_transform(const Transform& p_transform) ; + Transform get_import_transform() const; +#endif + Spatial(); ~Spatial(); 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 b13fdabea9..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; @@ -434,34 +545,119 @@ 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 (drag_slave) { - drag_slave->disconnect("input_event",this,"_drag_slave_input"); - drag_slave->disconnect("exit_scene",this,"_drag_slave_exit"); + 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 (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); - } + 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{ @@ -629,7 +825,11 @@ ScrollBar::ScrollBar(Orientation p_orientation) 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 0c20982083..ad3d1a7f58 100644 --- a/scene/gui/scroll_bar.h +++ b/scene/gui/scroll_bar.h @@ -74,6 +74,16 @@ class ScrollBar : public Range { 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); 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())) { diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 042666988a..b90fd489b3 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1698,6 +1698,20 @@ Array Node::_get_children() const { return arr; } +#ifdef TOOLS_ENABLED +void Node::set_import_path(const NodePath& p_import_path) { + + + data.import_path=p_import_path; +} + +NodePath Node::get_import_path() const { + + return data.import_path; +} + +#endif + void Node::_bind_methods() { @@ -1760,6 +1774,12 @@ void Node::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_viewport"),&Node::get_viewport); ObjectTypeDB::bind_method(_MD("queue_free"),&Node::queue_delete); +#ifdef TOOLS_ENABLED + ObjectTypeDB::bind_method(_MD("_set_import_path","import_path"),&Node::set_import_path); + ObjectTypeDB::bind_method(_MD("_get_import_path"),&Node::get_import_path); + ADD_PROPERTY( PropertyInfo(Variant::NODE_PATH,"_import_path",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_import_path"),_SCS("_get_import_path")); + +#endif BIND_CONSTANT( NOTIFICATION_ENTER_SCENE ); BIND_CONSTANT( NOTIFICATION_EXIT_SCENE ); diff --git a/scene/main/node.h b/scene/main/node.h index 32c5d8ef38..f1ecf497e0 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -82,6 +82,9 @@ private: StringName name; SceneMainLoop *scene; bool inside_scene; +#ifdef TOOLS_ENABLED + NodePath import_path; //path used when imported, used by scene editors to keep tracking +#endif Viewport *viewport; @@ -269,11 +272,18 @@ public: void queue_delete(); +//shitty hacks for speed static void set_human_readable_collision_renaming(bool p_enabled); static void init_node_hrcr(); void force_parent_owned() { data.parent_owned=true; } //hack to avoid duplicate nodes +#ifdef TOOLS_ENABLED + void set_import_path(const NodePath& p_import_path); //path used when imported, used by scene editors to keep tracking + NodePath get_import_path() const; +#endif + + _FORCE_INLINE_ Viewport *get_viewport() const { return data.viewport; } /* CANVAS */ |