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-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 "camera_editor_plugin.h"
31 #include "spatial_editor_plugin.h"
32 
_notification(int p_what)33 void CameraEditor::_notification(int p_what) {
34 
35 	switch (p_what) {
36 
37 		/*		case NOTIFICATION_PROCESS: {
38 
39 			if (preview->is_pressed() && node)
40 				node->call("make_current");
41 
42 		} break;*/
43 	}
44 }
_node_removed(Node * p_node)45 void CameraEditor::_node_removed(Node *p_node) {
46 
47 	if (p_node == node) {
48 		node = NULL;
49 		SpatialEditor::get_singleton()->set_custom_camera(NULL);
50 		hide();
51 	}
52 }
53 
_pressed()54 void CameraEditor::_pressed() {
55 
56 	Node *sn = (node && preview->is_pressed()) ? node : NULL;
57 	SpatialEditor::get_singleton()->set_custom_camera(sn);
58 }
59 
_bind_methods()60 void CameraEditor::_bind_methods() {
61 
62 	ObjectTypeDB::bind_method(_MD("_pressed"), &CameraEditor::_pressed);
63 }
64 
edit(Node * p_camera)65 void CameraEditor::edit(Node *p_camera) {
66 
67 	node = p_camera;
68 
69 	if (!node) {
70 		preview->set_pressed(false);
71 		SpatialEditor::get_singleton()->set_custom_camera(NULL);
72 	} else {
73 
74 		if (preview->is_pressed())
75 			SpatialEditor::get_singleton()->set_custom_camera(p_camera);
76 		else
77 			SpatialEditor::get_singleton()->set_custom_camera(NULL);
78 	}
79 }
80 
CameraEditor()81 CameraEditor::CameraEditor() {
82 
83 	preview = memnew(Button);
84 	add_child(preview);
85 
86 	preview->set_text(TTR("Preview"));
87 	preview->set_toggle_mode(true);
88 	preview->set_anchor(MARGIN_LEFT, Control::ANCHOR_END);
89 	preview->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END);
90 	preview->set_margin(MARGIN_LEFT, 60);
91 	preview->set_margin(MARGIN_RIGHT, 0);
92 	preview->set_margin(MARGIN_TOP, 0);
93 	preview->set_margin(MARGIN_BOTTOM, 10);
94 	preview->connect("pressed", this, "_pressed");
95 }
96 
edit(Object * p_object)97 void CameraEditorPlugin::edit(Object *p_object) {
98 
99 	SpatialEditor::get_singleton()->set_can_preview(p_object->cast_to<Camera>());
100 	//camera_editor->edit(p_object->cast_to<Node>());
101 }
102 
handles(Object * p_object) const103 bool CameraEditorPlugin::handles(Object *p_object) const {
104 
105 	return p_object->is_type("Camera");
106 }
107 
make_visible(bool p_visible)108 void CameraEditorPlugin::make_visible(bool p_visible) {
109 
110 	if (p_visible) {
111 		//	SpatialEditor::get_singleton()->set_can_preview(p_object->cast_to<Camera>());
112 
113 	} else {
114 
115 		SpatialEditor::get_singleton()->set_can_preview(NULL);
116 	}
117 }
118 
CameraEditorPlugin(EditorNode * p_node)119 CameraEditorPlugin::CameraEditorPlugin(EditorNode *p_node) {
120 
121 	editor = p_node;
122 	/*	camera_editor = memnew( CameraEditor );
123 	editor->get_viewport()->add_child(camera_editor);
124 
125 	camera_editor->set_anchor(MARGIN_LEFT,Control::ANCHOR_END);
126 	camera_editor->set_anchor(MARGIN_RIGHT,Control::ANCHOR_END);
127 	camera_editor->set_margin(MARGIN_LEFT,60);
128 	camera_editor->set_margin(MARGIN_RIGHT,0);
129 	camera_editor->set_margin(MARGIN_TOP,0);
130 	camera_editor->set_margin(MARGIN_BOTTOM,10);
131 
132 
133 	camera_editor->hide();
134 */
135 }
136 
~CameraEditorPlugin()137 CameraEditorPlugin::~CameraEditorPlugin() {
138 }
139