1 /*************************************************************************/
2 /*  style_box_editor_plugin.cpp                                          */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md)    */
10 /*                                                                       */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the       */
13 /* "Software"), to deal in the Software without restriction, including   */
14 /* without limitation the rights to use, copy, modify, merge, publish,   */
15 /* distribute, sublicense, and/or sell copies of the Software, and to    */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions:                                             */
18 /*                                                                       */
19 /* The above copyright notice and this permission notice shall be        */
20 /* included in all copies or substantial portions of the Software.       */
21 /*                                                                       */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
29 /*************************************************************************/
30 #include "style_box_editor_plugin.h"
31 
edit(const Ref<StyleBox> & p_stylebox)32 void StyleBoxEditor::edit(const Ref<StyleBox> &p_stylebox) {
33 
34 	if (stylebox.is_valid())
35 		stylebox->disconnect("changed", this, "_sb_changed");
36 	stylebox = p_stylebox;
37 	if (p_stylebox.is_valid()) {
38 		preview->add_style_override("panel", stylebox);
39 		stylebox->connect("changed", this, "_sb_changed");
40 	}
41 }
42 
_sb_changed()43 void StyleBoxEditor::_sb_changed() {
44 
45 	preview->update();
46 }
47 
_bind_methods()48 void StyleBoxEditor::_bind_methods() {
49 
50 	ObjectTypeDB::bind_method("_sb_changed", &StyleBoxEditor::_sb_changed);
51 	//	ObjectTypeDB::bind_method("_import",&StyleBoxEditor::_import);
52 	//	ObjectTypeDB::bind_method("_import_accept",&StyleBoxEditor::_import_accept);
53 	//	ObjectTypeDB::bind_method("_preview_text_changed",&StyleBoxEditor::_preview_text_changed);
54 }
55 
StyleBoxEditor()56 StyleBoxEditor::StyleBoxEditor() {
57 
58 	panel = memnew(Panel);
59 	add_child(panel);
60 	panel->set_area_as_parent_rect();
61 
62 	Label *l = memnew(Label);
63 	l->set_text(TTR("StyleBox Preview:"));
64 	l->set_pos(Point2(5, 5));
65 	panel->add_child(l);
66 
67 	preview = memnew(Panel);
68 	panel->add_child(preview);
69 	preview->set_pos(Point2(50, 50));
70 	preview->set_size(Size2(200, 100));
71 }
72 
edit(Object * p_node)73 void StyleBoxEditorPlugin::edit(Object *p_node) {
74 
75 	if (p_node && p_node->cast_to<StyleBox>()) {
76 		stylebox_editor->edit(p_node->cast_to<StyleBox>());
77 		stylebox_editor->show();
78 	} else
79 		stylebox_editor->hide();
80 }
81 
handles(Object * p_node) const82 bool StyleBoxEditorPlugin::handles(Object *p_node) const {
83 
84 	return p_node->is_type("StyleBox");
85 }
86 
make_visible(bool p_visible)87 void StyleBoxEditorPlugin::make_visible(bool p_visible) {
88 
89 	if (p_visible) {
90 		button->show();
91 		EditorNode::get_singleton()->make_bottom_panel_item_visible(stylebox_editor);
92 
93 	} else {
94 		if (stylebox_editor->is_visible())
95 			EditorNode::get_singleton()->hide_bottom_panel();
96 		button->hide();
97 	}
98 }
99 
StyleBoxEditorPlugin(EditorNode * p_node)100 StyleBoxEditorPlugin::StyleBoxEditorPlugin(EditorNode *p_node) {
101 
102 	stylebox_editor = memnew(StyleBoxEditor);
103 	stylebox_editor->set_custom_minimum_size(Size2(0, 250));
104 
105 	//p_node->get_viewport()->add_child(stylebox_editor);
106 	button = p_node->add_bottom_panel_item("StyleBox", stylebox_editor);
107 	button->hide();
108 }
109