diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-09-11 11:28:01 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-09-11 11:28:01 -0300 |
commit | 95eb7466df890dcbed9eb8e8bda15bd9235db9c0 (patch) | |
tree | 6c23afb3abef8e539c42d1024a0fa213bc98692b | |
parent | 1bf684cea274db7c58b3f62a77ad4de3980c14dc (diff) |
-Added a ColorFrame control, kind of like Texture but for color.
-Added dropping nodes to text editor for them to become a path
-Fixed issues with font not properly being set in code editor
-rw-r--r-- | scene/gui/color_rect.cpp | 36 | ||||
-rw-r--r-- | scene/gui/color_rect.h | 22 | ||||
-rw-r--r-- | scene/gui/control.cpp | 2 | ||||
-rw-r--r-- | scene/gui/panel.h | 2 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 3 | ||||
-rw-r--r-- | scene/register_scene_types.cpp | 2 | ||||
-rw-r--r-- | tools/editor/code_editor.cpp | 6 | ||||
-rw-r--r-- | tools/editor/icons/icon_color_frame.png | bin | 0 -> 360 bytes | |||
-rw-r--r-- | tools/editor/plugins/script_text_editor.cpp | 146 | ||||
-rw-r--r-- | tools/editor/plugins/script_text_editor.h | 5 |
10 files changed, 220 insertions, 4 deletions
diff --git a/scene/gui/color_rect.cpp b/scene/gui/color_rect.cpp new file mode 100644 index 0000000000..a0e4df66b5 --- /dev/null +++ b/scene/gui/color_rect.cpp @@ -0,0 +1,36 @@ +#include "color_rect.h" + + + + +void ColorFrame::set_frame_color(const Color& p_color) { + + color=p_color; + update(); +} + +Color ColorFrame::get_frame_color() const{ + + return color; +} + +void ColorFrame::_notification(int p_what) { + + if (p_what==NOTIFICATION_DRAW) { + draw_rect(Rect2(Point2(),get_size()),color); + } +} + +void ColorFrame::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("set_frame_color","color"),&ColorFrame::set_frame_color); + ObjectTypeDB::bind_method(_MD("get_frame_color"),&ColorFrame::get_frame_color); + + ADD_PROPERTY(PropertyInfo(Variant::COLOR,"color"),_SCS("set_frame_color"),_SCS("get_frame_color") ); +} + +ColorFrame::ColorFrame() { + + color=Color(1,1,1); +} + diff --git a/scene/gui/color_rect.h b/scene/gui/color_rect.h new file mode 100644 index 0000000000..3816d44052 --- /dev/null +++ b/scene/gui/color_rect.h @@ -0,0 +1,22 @@ +#ifndef COLORRECT_H +#define COLORRECT_H + +#include "scene/gui/control.h" + +class ColorFrame : public Control { + OBJ_TYPE(ColorFrame,Control) + + Color color; +protected: + + void _notification(int p_what); + static void _bind_methods(); +public: + + void set_frame_color(const Color& p_color); + Color get_frame_color() const; + + ColorFrame(); +}; + +#endif // COLORRECT_H diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index c120be65d0..269bd09b17 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1924,7 +1924,7 @@ void Control::_propagate_theme_changed(CanvasItem *p_at,Control *p_owner,bool p_ if (p_assign) { c->data.theme_owner=p_owner; } - c->_notification(NOTIFICATION_THEME_CHANGED); + c->notification(NOTIFICATION_THEME_CHANGED); c->update(); } } diff --git a/scene/gui/panel.h b/scene/gui/panel.h index efa9ebcaa0..9e2e7df7f0 100644 --- a/scene/gui/panel.h +++ b/scene/gui/panel.h @@ -45,4 +45,6 @@ public: }; + + #endif diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 4756fdee26..87df8c076e 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -34,6 +34,7 @@ #include "globals.h" #include "message_queue.h" +#include "scene/main/viewport.h" #define TAB_PIXELS @@ -1651,7 +1652,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { const InputEventMouseMotion &mm=p_input_event.mouse_motion; - if (mm.button_mask&BUTTON_MASK_LEFT) { + if (mm.button_mask&BUTTON_MASK_LEFT && get_viewport()->gui_get_drag_data()==Variant()) { //ignore if dragging if (selection.selecting_mode!=Selection::MODE_NONE) { diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index d22c3bad14..104aeb2b5e 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -55,6 +55,7 @@ #include "scene/gui/option_button.h" #include "scene/gui/color_picker.h" #include "scene/gui/texture_frame.h" +#include "scene/gui/color_rect.h" #include "scene/gui/patch_9_frame.h" #include "scene/gui/menu_button.h" #include "scene/gui/check_box.h" @@ -339,6 +340,7 @@ void register_scene_types() { OS::get_singleton()->yield(); //may take time to init ObjectTypeDB::register_type<TextureFrame>(); + ObjectTypeDB::register_type<ColorFrame>(); ObjectTypeDB::register_type<Patch9Frame>(); ObjectTypeDB::register_type<TabContainer>(); ObjectTypeDB::register_type<Tabs>(); diff --git a/tools/editor/code_editor.cpp b/tools/editor/code_editor.cpp index 9bf7d05ae8..9240e3527c 100644 --- a/tools/editor/code_editor.cpp +++ b/tools/editor/code_editor.cpp @@ -1128,8 +1128,10 @@ void CodeTextEditor::_update_font() { font_overridden = true; } } - if(!font_overridden) + if(!font_overridden) { + text_editor->add_font_override("font",get_font("source","EditorFonts")); + } } void CodeTextEditor::_on_settings_change() { @@ -1168,7 +1170,7 @@ void CodeTextEditor::_notification(int p_what) { _load_theme_settings(); emit_signal("load_theme_settings"); } - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what==NOTIFICATION_THEME_CHANGED) { _update_font(); } } diff --git a/tools/editor/icons/icon_color_frame.png b/tools/editor/icons/icon_color_frame.png Binary files differnew file mode 100644 index 0000000000..a82eefc10a --- /dev/null +++ b/tools/editor/icons/icon_color_frame.png diff --git a/tools/editor/plugins/script_text_editor.cpp b/tools/editor/plugins/script_text_editor.cpp index 57cf8cbea3..69f4c9d9a6 100644 --- a/tools/editor/plugins/script_text_editor.cpp +++ b/tools/editor/plugins/script_text_editor.cpp @@ -30,6 +30,7 @@ #include "tools/editor/editor_settings.h" #include "os/keyboard.h" #include "tools/editor/script_editor_debugger.h" +#include "tools/editor/editor_node.h" Vector<String> ScriptTextEditor::get_functions() { @@ -920,6 +921,10 @@ void ScriptTextEditor::_bind_methods() { ObjectTypeDB::bind_method("_edit_option",&ScriptTextEditor::_edit_option); ObjectTypeDB::bind_method("_goto_line",&ScriptTextEditor::_goto_line); + ObjectTypeDB::bind_method("get_drag_data_fw",&ScriptTextEditor::get_drag_data_fw); + ObjectTypeDB::bind_method("can_drop_data_fw",&ScriptTextEditor::can_drop_data_fw); + ObjectTypeDB::bind_method("drop_data_fw",&ScriptTextEditor::drop_data_fw); + ADD_SIGNAL(MethodInfo("name_changed")); ADD_SIGNAL(MethodInfo("request_help_search",PropertyInfo(Variant::STRING,"topic"))); } @@ -957,6 +962,144 @@ void ScriptTextEditor::set_debugger_active(bool p_active) { } + +Variant ScriptTextEditor::get_drag_data_fw(const Point2& p_point,Control* p_from) { + + return Variant(); +} + +bool ScriptTextEditor::can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const{ + + Dictionary d = p_data; + if (d.has("type") && + ( + + String(d["type"])=="resource" || + String(d["type"])=="files" || + String(d["type"])=="nodes" + ) ) { + + + return true; + } + + + return false; + +} + +#ifdef TOOLS_ENABLED + +static Node* _find_script_node(Node* p_edited_scene,Node* p_current_node,const Ref<Script> &script) { + + if (p_edited_scene!=p_current_node && p_current_node->get_owner()!=p_edited_scene) + return NULL; + + Ref<Script> scr = p_current_node->get_script(); + + if (scr.is_valid() && scr==script) + return p_current_node; + + for(int i=0;i<p_current_node->get_child_count();i++) { + Node *n = _find_script_node(p_edited_scene,p_current_node->get_child(i),script); + if (n) + return n; + } + + return NULL; +} + +#else + +static Node* _find_script_node(Node* p_edited_scene,Node* p_current_node,const Ref<Script> &script) { + + return NULL; +} +#endif + + + + +void ScriptTextEditor::drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from){ + + Dictionary d = p_data; + + if (d.has("type") && String(d["type"])=="resource") { + + Ref<Resource> res = d["resource"]; + if (!res.is_valid()) { + return; + } + + if (res->get_path().is_resource_file()) { + EditorNode::get_singleton()->show_warning("Only resources from filesystem can be dropped."); + return; + } + + code_editor->get_text_edit()->insert_text_at_cursor(res->get_path()); + + } + + if (d.has("type") && String(d["type"])=="files") { + + + Array files = d["files"]; + + String text_to_drop; + for(int i=0;i<files.size();i++) { + + if (i>0) + text_to_drop+=","; + text_to_drop+="\""+String(files[i]).c_escape()+"\""; + + } + + code_editor->get_text_edit()->insert_text_at_cursor(text_to_drop); + + } + + if (d.has("type") && String(d["type"])=="nodes") { + + Node* sn = _find_script_node(get_tree()->get_edited_scene_root(),get_tree()->get_edited_scene_root(),script); + + + if (!sn) { + EditorNode::get_singleton()->show_warning("Can't drop nodes because script '"+get_name()+"' is not used in this scene."); + return; + } + + + Array nodes = d["nodes"]; + String text_to_drop; + for(int i=0;i<nodes.size();i++) { + + if (i>0) + text_to_drop+=","; + + NodePath np = nodes[i]; + Node *node = get_node(np); + if (!node) { + continue; + } + + + + String path = sn->get_path_to(node); + text_to_drop+="\""+path.c_escape()+"\""; + + + } + + code_editor->get_text_edit()->insert_text_at_cursor(text_to_drop); + + + } + + + +} + + ScriptTextEditor::ScriptTextEditor() { code_editor = memnew( CodeTextEditor ); @@ -1039,6 +1182,9 @@ ScriptTextEditor::ScriptTextEditor() { goto_line_dialog = memnew(GotoLineDialog); add_child(goto_line_dialog); + + + code_editor->get_text_edit()->set_drag_forwarding(this); } static ScriptEditorBase * create_editor(const Ref<Script>& p_script) { diff --git a/tools/editor/plugins/script_text_editor.h b/tools/editor/plugins/script_text_editor.h index 247fd97e81..c311a21131 100644 --- a/tools/editor/plugins/script_text_editor.h +++ b/tools/editor/plugins/script_text_editor.h @@ -98,6 +98,11 @@ protected: void _edit_option(int p_op); void _goto_line(int p_line) { goto_line(p_line); } + + Variant get_drag_data_fw(const Point2& p_point,Control* p_from); + bool can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const; + void drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from); + public: virtual void apply_code(); |