stream_editor_plugin.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*************************************************************************/
  2. /* stream_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. #include "stream_editor_plugin.h"
  31. void StreamEditor::_notification(int p_what) {
  32. if (p_what == NOTIFICATION_ENTER_TREE) {
  33. play->set_icon(get_icon("Play", "EditorIcons"));
  34. stop->set_icon(get_icon("Stop", "EditorIcons"));
  35. }
  36. }
  37. void StreamEditor::_node_removed(Node *p_node) {
  38. if (p_node == node) {
  39. node = NULL;
  40. hide();
  41. }
  42. }
  43. void StreamEditor::_play() {
  44. node->call("play");
  45. }
  46. void StreamEditor::_stop() {
  47. node->call("stop");
  48. }
  49. void StreamEditor::_bind_methods() {
  50. ObjectTypeDB::bind_method(_MD("_play"), &StreamEditor::_play);
  51. ObjectTypeDB::bind_method(_MD("_stop"), &StreamEditor::_stop);
  52. }
  53. void StreamEditor::edit(Node *p_stream) {
  54. node = p_stream;
  55. }
  56. StreamEditor::StreamEditor() {
  57. play = memnew(Button);
  58. play->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_END, 60);
  59. play->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, 40);
  60. play->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, 0);
  61. play->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_BEGIN, 0);
  62. add_child(play);
  63. stop = memnew(Button);
  64. stop->set_pos(Point2(35, 5));
  65. stop->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_END, 30);
  66. stop->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, 10);
  67. stop->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, 0);
  68. stop->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_BEGIN, 0);
  69. add_child(stop);
  70. play->connect("pressed", this, "_play");
  71. stop->connect("pressed", this, "_stop");
  72. }
  73. void StreamEditorPlugin::edit(Object *p_object) {
  74. stream_editor->edit(p_object->cast_to<Node>());
  75. }
  76. bool StreamEditorPlugin::handles(Object *p_object) const {
  77. return p_object->is_type("StreamPlayer") || p_object->is_type("SpatialStreamPlayer");
  78. }
  79. void StreamEditorPlugin::make_visible(bool p_visible) {
  80. if (p_visible) {
  81. stream_editor->show();
  82. stream_editor->set_fixed_process(true);
  83. } else {
  84. stream_editor->hide();
  85. stream_editor->set_fixed_process(false);
  86. stream_editor->edit(NULL);
  87. }
  88. }
  89. StreamEditorPlugin::StreamEditorPlugin(EditorNode *p_node) {
  90. editor = p_node;
  91. stream_editor = memnew(StreamEditor);
  92. editor->get_viewport()->add_child(stream_editor);
  93. stream_editor->set_anchor(MARGIN_LEFT, Control::ANCHOR_END);
  94. stream_editor->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END);
  95. stream_editor->set_margin(MARGIN_LEFT, 60);
  96. stream_editor->set_margin(MARGIN_RIGHT, 0);
  97. stream_editor->set_margin(MARGIN_TOP, 0);
  98. stream_editor->set_margin(MARGIN_BOTTOM, 10);
  99. stream_editor->hide();
  100. }
  101. StreamEditorPlugin::~StreamEditorPlugin() {
  102. }