1 /*************************************************************************/
2 /*  camera_editor_plugin.cpp                                             */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2020 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 
31 #include "camera_editor_plugin.h"
32 
33 #include "spatial_editor_plugin.h"
34 
_node_removed(Node * p_node)35 void CameraEditor::_node_removed(Node *p_node) {
36 
37 	if (p_node == node) {
38 		node = NULL;
39 		SpatialEditor::get_singleton()->set_custom_camera(NULL);
40 		hide();
41 	}
42 }
43 
_pressed()44 void CameraEditor::_pressed() {
45 
46 	Node *sn = (node && preview->is_pressed()) ? node : NULL;
47 	SpatialEditor::get_singleton()->set_custom_camera(sn);
48 }
49 
_bind_methods()50 void CameraEditor::_bind_methods() {
51 
52 	ClassDB::bind_method(D_METHOD("_pressed"), &CameraEditor::_pressed);
53 }
54 
edit(Node * p_camera)55 void CameraEditor::edit(Node *p_camera) {
56 
57 	node = p_camera;
58 
59 	if (!node) {
60 		preview->set_pressed(false);
61 		SpatialEditor::get_singleton()->set_custom_camera(NULL);
62 	} else {
63 
64 		if (preview->is_pressed())
65 			SpatialEditor::get_singleton()->set_custom_camera(p_camera);
66 		else
67 			SpatialEditor::get_singleton()->set_custom_camera(NULL);
68 	}
69 }
70 
CameraEditor()71 CameraEditor::CameraEditor() {
72 
73 	preview = memnew(Button);
74 	add_child(preview);
75 
76 	preview->set_text(TTR("Preview"));
77 	preview->set_toggle_mode(true);
78 	preview->set_anchor(MARGIN_LEFT, Control::ANCHOR_END);
79 	preview->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END);
80 	preview->set_margin(MARGIN_LEFT, -60);
81 	preview->set_margin(MARGIN_RIGHT, 0);
82 	preview->set_margin(MARGIN_TOP, 0);
83 	preview->set_margin(MARGIN_BOTTOM, 10);
84 	preview->connect("pressed", this, "_pressed");
85 }
86 
edit(Object * p_object)87 void CameraEditorPlugin::edit(Object *p_object) {
88 
89 	SpatialEditor::get_singleton()->set_can_preview(Object::cast_to<Camera>(p_object));
90 	//camera_editor->edit(Object::cast_to<Node>(p_object));
91 }
92 
handles(Object * p_object) const93 bool CameraEditorPlugin::handles(Object *p_object) const {
94 
95 	return p_object->is_class("Camera");
96 }
97 
make_visible(bool p_visible)98 void CameraEditorPlugin::make_visible(bool p_visible) {
99 
100 	if (p_visible) {
101 		//SpatialEditor::get_singleton()->set_can_preview(Object::cast_to<Camera>(p_object));
102 	} else {
103 		SpatialEditor::get_singleton()->set_can_preview(NULL);
104 	}
105 }
106 
CameraEditorPlugin(EditorNode * p_node)107 CameraEditorPlugin::CameraEditorPlugin(EditorNode *p_node) {
108 
109 	editor = p_node;
110 	/*	camera_editor = memnew( CameraEditor );
111 	editor->get_viewport()->add_child(camera_editor);
112 
113 	camera_editor->set_anchor(MARGIN_LEFT,Control::ANCHOR_END);
114 	camera_editor->set_anchor(MARGIN_RIGHT,Control::ANCHOR_END);
115 	camera_editor->set_margin(MARGIN_LEFT,60);
116 	camera_editor->set_margin(MARGIN_RIGHT,0);
117 	camera_editor->set_margin(MARGIN_TOP,0);
118 	camera_editor->set_margin(MARGIN_BOTTOM,10);
119 
120 
121 	camera_editor->hide();
122 */
123 }
124 
~CameraEditorPlugin()125 CameraEditorPlugin::~CameraEditorPlugin() {
126 }
127