camera_editor_plugin.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. void CameraEditor::_node_removed(Node *p_node) {
  33. if (p_node == node) {
  34. node = NULL;
  35. SpatialEditor::get_singleton()->set_custom_camera(NULL);
  36. hide();
  37. }
  38. }
  39. void CameraEditor::_pressed() {
  40. Node *sn = (node && preview->is_pressed()) ? node : NULL;
  41. SpatialEditor::get_singleton()->set_custom_camera(sn);
  42. }
  43. void CameraEditor::_bind_methods() {
  44. ClassDB::bind_method(D_METHOD("_pressed"), &CameraEditor::_pressed);
  45. }
  46. void CameraEditor::edit(Node *p_camera) {
  47. node = p_camera;
  48. if (!node) {
  49. preview->set_pressed(false);
  50. SpatialEditor::get_singleton()->set_custom_camera(NULL);
  51. } else {
  52. if (preview->is_pressed())
  53. SpatialEditor::get_singleton()->set_custom_camera(p_camera);
  54. else
  55. SpatialEditor::get_singleton()->set_custom_camera(NULL);
  56. }
  57. }
  58. CameraEditor::CameraEditor() {
  59. preview = memnew(Button);
  60. add_child(preview);
  61. preview->set_text(TTR("Preview"));
  62. preview->set_toggle_mode(true);
  63. preview->set_anchor(MARGIN_LEFT, Control::ANCHOR_END);
  64. preview->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END);
  65. preview->set_margin(MARGIN_LEFT, -60);
  66. preview->set_margin(MARGIN_RIGHT, 0);
  67. preview->set_margin(MARGIN_TOP, 0);
  68. preview->set_margin(MARGIN_BOTTOM, 10);
  69. preview->connect("pressed", this, "_pressed");
  70. }
  71. void CameraEditorPlugin::edit(Object *p_object) {
  72. SpatialEditor::get_singleton()->set_can_preview(Object::cast_to<Camera>(p_object));
  73. //camera_editor->edit(Object::cast_to<Node>(p_object));
  74. }
  75. bool CameraEditorPlugin::handles(Object *p_object) const {
  76. return p_object->is_class("Camera");
  77. }
  78. void CameraEditorPlugin::make_visible(bool p_visible) {
  79. if (p_visible) {
  80. //SpatialEditor::get_singleton()->set_can_preview(Object::cast_to<Camera>(p_object));
  81. } else {
  82. SpatialEditor::get_singleton()->set_can_preview(NULL);
  83. }
  84. }
  85. CameraEditorPlugin::CameraEditorPlugin(EditorNode *p_node) {
  86. editor = p_node;
  87. /* camera_editor = memnew( CameraEditor );
  88. editor->get_viewport()->add_child(camera_editor);
  89. camera_editor->set_anchor(MARGIN_LEFT,Control::ANCHOR_END);
  90. camera_editor->set_anchor(MARGIN_RIGHT,Control::ANCHOR_END);
  91. camera_editor->set_margin(MARGIN_LEFT,60);
  92. camera_editor->set_margin(MARGIN_RIGHT,0);
  93. camera_editor->set_margin(MARGIN_TOP,0);
  94. camera_editor->set_margin(MARGIN_BOTTOM,10);
  95. camera_editor->hide();
  96. */
  97. }
  98. CameraEditorPlugin::~CameraEditorPlugin() {
  99. }