camera_editor_plugin.cpp 4.7 KB

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