1 /*************************************************************************/
2 /*  stream_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 "stream_editor_plugin.h"
31 
_notification(int p_what)32 void StreamEditor::_notification(int p_what) {
33 
34 	if (p_what == NOTIFICATION_ENTER_TREE) {
35 		play->set_icon(get_icon("Play", "EditorIcons"));
36 		stop->set_icon(get_icon("Stop", "EditorIcons"));
37 	}
38 }
_node_removed(Node * p_node)39 void StreamEditor::_node_removed(Node *p_node) {
40 
41 	if (p_node == node) {
42 		node = NULL;
43 		hide();
44 	}
45 }
46 
_play()47 void StreamEditor::_play() {
48 
49 	node->call("play");
50 }
51 
_stop()52 void StreamEditor::_stop() {
53 
54 	node->call("stop");
55 }
56 
_bind_methods()57 void StreamEditor::_bind_methods() {
58 
59 	ObjectTypeDB::bind_method(_MD("_play"), &StreamEditor::_play);
60 	ObjectTypeDB::bind_method(_MD("_stop"), &StreamEditor::_stop);
61 }
62 
edit(Node * p_stream)63 void StreamEditor::edit(Node *p_stream) {
64 
65 	node = p_stream;
66 }
StreamEditor()67 StreamEditor::StreamEditor() {
68 
69 	play = memnew(Button);
70 
71 	play->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_END, 60);
72 	play->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, 40);
73 	play->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, 0);
74 	play->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_BEGIN, 0);
75 
76 	add_child(play);
77 
78 	stop = memnew(Button);
79 
80 	stop->set_pos(Point2(35, 5));
81 	stop->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_END, 30);
82 	stop->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, 10);
83 	stop->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, 0);
84 	stop->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_BEGIN, 0);
85 	add_child(stop);
86 
87 	play->connect("pressed", this, "_play");
88 	stop->connect("pressed", this, "_stop");
89 }
90 
edit(Object * p_object)91 void StreamEditorPlugin::edit(Object *p_object) {
92 
93 	stream_editor->edit(p_object->cast_to<Node>());
94 }
95 
handles(Object * p_object) const96 bool StreamEditorPlugin::handles(Object *p_object) const {
97 
98 	return p_object->is_type("StreamPlayer") || p_object->is_type("SpatialStreamPlayer");
99 }
100 
make_visible(bool p_visible)101 void StreamEditorPlugin::make_visible(bool p_visible) {
102 
103 	if (p_visible) {
104 		stream_editor->show();
105 		stream_editor->set_fixed_process(true);
106 	} else {
107 
108 		stream_editor->hide();
109 		stream_editor->set_fixed_process(false);
110 		stream_editor->edit(NULL);
111 	}
112 }
113 
StreamEditorPlugin(EditorNode * p_node)114 StreamEditorPlugin::StreamEditorPlugin(EditorNode *p_node) {
115 
116 	editor = p_node;
117 	stream_editor = memnew(StreamEditor);
118 	editor->get_viewport()->add_child(stream_editor);
119 
120 	stream_editor->set_anchor(MARGIN_LEFT, Control::ANCHOR_END);
121 	stream_editor->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END);
122 	stream_editor->set_margin(MARGIN_LEFT, 60);
123 	stream_editor->set_margin(MARGIN_RIGHT, 0);
124 	stream_editor->set_margin(MARGIN_TOP, 0);
125 	stream_editor->set_margin(MARGIN_BOTTOM, 10);
126 
127 	stream_editor->hide();
128 }
129 
~StreamEditorPlugin()130 StreamEditorPlugin::~StreamEditorPlugin() {
131 }
132