style_box_editor_plugin.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*************************************************************************/
  2. /* style_box_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 "style_box_editor_plugin.h"
  31. void StyleBoxEditor::edit(const Ref<StyleBox> &p_stylebox) {
  32. if (stylebox.is_valid())
  33. stylebox->disconnect("changed", this, "_sb_changed");
  34. stylebox = p_stylebox;
  35. if (p_stylebox.is_valid()) {
  36. preview->add_style_override("panel", stylebox);
  37. stylebox->connect("changed", this, "_sb_changed");
  38. }
  39. }
  40. void StyleBoxEditor::_sb_changed() {
  41. preview->update();
  42. }
  43. void StyleBoxEditor::_bind_methods() {
  44. ObjectTypeDB::bind_method("_sb_changed", &StyleBoxEditor::_sb_changed);
  45. // ObjectTypeDB::bind_method("_import",&StyleBoxEditor::_import);
  46. // ObjectTypeDB::bind_method("_import_accept",&StyleBoxEditor::_import_accept);
  47. // ObjectTypeDB::bind_method("_preview_text_changed",&StyleBoxEditor::_preview_text_changed);
  48. }
  49. StyleBoxEditor::StyleBoxEditor() {
  50. panel = memnew(Panel);
  51. add_child(panel);
  52. panel->set_area_as_parent_rect();
  53. Label *l = memnew(Label);
  54. l->set_text(TTR("StyleBox Preview:"));
  55. l->set_pos(Point2(5, 5));
  56. panel->add_child(l);
  57. preview = memnew(Panel);
  58. panel->add_child(preview);
  59. preview->set_pos(Point2(50, 50));
  60. preview->set_size(Size2(200, 100));
  61. }
  62. void StyleBoxEditorPlugin::edit(Object *p_node) {
  63. if (p_node && p_node->cast_to<StyleBox>()) {
  64. stylebox_editor->edit(p_node->cast_to<StyleBox>());
  65. stylebox_editor->show();
  66. } else
  67. stylebox_editor->hide();
  68. }
  69. bool StyleBoxEditorPlugin::handles(Object *p_node) const {
  70. return p_node->is_type("StyleBox");
  71. }
  72. void StyleBoxEditorPlugin::make_visible(bool p_visible) {
  73. if (p_visible) {
  74. button->show();
  75. EditorNode::get_singleton()->make_bottom_panel_item_visible(stylebox_editor);
  76. } else {
  77. if (stylebox_editor->is_visible())
  78. EditorNode::get_singleton()->hide_bottom_panel();
  79. button->hide();
  80. }
  81. }
  82. StyleBoxEditorPlugin::StyleBoxEditorPlugin(EditorNode *p_node) {
  83. stylebox_editor = memnew(StyleBoxEditor);
  84. stylebox_editor->set_custom_minimum_size(Size2(0, 250));
  85. //p_node->get_viewport()->add_child(stylebox_editor);
  86. button = p_node->add_bottom_panel_item("StyleBox", stylebox_editor);
  87. button->hide();
  88. }