camera_editor_plugin.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**************************************************************************/
  2. /* camera_editor_plugin.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 = nullptr;
  35. SpatialEditor::get_singleton()->set_custom_camera(nullptr);
  36. hide();
  37. }
  38. }
  39. void CameraEditor::_pressed() {
  40. Node *sn = (node && preview->is_pressed()) ? node : nullptr;
  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(nullptr);
  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(nullptr);
  56. }
  57. }
  58. }
  59. CameraEditor::CameraEditor() {
  60. preview = memnew(Button);
  61. add_child(preview);
  62. preview->set_text(TTR("Preview"));
  63. preview->set_toggle_mode(true);
  64. preview->set_anchor(MARGIN_LEFT, Control::ANCHOR_END);
  65. preview->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END);
  66. preview->set_margin(MARGIN_LEFT, -60);
  67. preview->set_margin(MARGIN_RIGHT, 0);
  68. preview->set_margin(MARGIN_TOP, 0);
  69. preview->set_margin(MARGIN_BOTTOM, 10);
  70. preview->connect("pressed", this, "_pressed");
  71. }
  72. void CameraEditorPlugin::edit(Object *p_object) {
  73. SpatialEditor::get_singleton()->set_can_preview(Object::cast_to<Camera>(p_object));
  74. //camera_editor->edit(Object::cast_to<Node>(p_object));
  75. }
  76. bool CameraEditorPlugin::handles(Object *p_object) const {
  77. return p_object->is_class("Camera");
  78. }
  79. void CameraEditorPlugin::make_visible(bool p_visible) {
  80. if (p_visible) {
  81. //SpatialEditor::get_singleton()->set_can_preview(Object::cast_to<Camera>(p_object));
  82. } else {
  83. SpatialEditor::get_singleton()->set_can_preview(nullptr);
  84. }
  85. }
  86. CameraEditorPlugin::CameraEditorPlugin(EditorNode *p_node) {
  87. editor = p_node;
  88. /* camera_editor = memnew( CameraEditor );
  89. editor->get_viewport()->add_child(camera_editor);
  90. camera_editor->set_anchor(MARGIN_LEFT,Control::ANCHOR_END);
  91. camera_editor->set_anchor(MARGIN_RIGHT,Control::ANCHOR_END);
  92. camera_editor->set_margin(MARGIN_LEFT,60);
  93. camera_editor->set_margin(MARGIN_RIGHT,0);
  94. camera_editor->set_margin(MARGIN_TOP,0);
  95. camera_editor->set_margin(MARGIN_BOTTOM,10);
  96. camera_editor->hide();
  97. */
  98. }
  99. CameraEditorPlugin::~CameraEditorPlugin() {
  100. }