gradient_texture_2d_editor_plugin.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**************************************************************************/
  2. /* gradient_texture_2d_editor_plugin.h */
  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. #ifndef GRADIENT_TEXTURE_2D_EDITOR_PLUGIN_H
  31. #define GRADIENT_TEXTURE_2D_EDITOR_PLUGIN_H
  32. #include "editor/editor_inspector.h"
  33. #include "editor/plugins/editor_plugin.h"
  34. class Button;
  35. class EditorSpinSlider;
  36. class GradientTexture2D;
  37. class GradientTexture2DEdit : public Control {
  38. GDCLASS(GradientTexture2DEdit, Control);
  39. enum Handle {
  40. HANDLE_NONE,
  41. HANDLE_FROM,
  42. HANDLE_TO
  43. };
  44. Ref<GradientTexture2D> texture;
  45. bool snap_enabled = false;
  46. int snap_count = 0;
  47. TextureRect *checkerboard = nullptr;
  48. Handle hovered = HANDLE_NONE;
  49. Handle grabbed = HANDLE_NONE;
  50. Point2 initial_grab_pos;
  51. Size2 handle_size;
  52. Point2 offset;
  53. Size2 size;
  54. Point2 _get_handle_pos(const Handle p_handle);
  55. Handle get_handle_at(const Vector2 &p_pos);
  56. void set_fill_pos(const Vector2 &p_pos);
  57. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  58. void _draw();
  59. protected:
  60. void _notification(int p_what);
  61. public:
  62. void set_texture(Ref<GradientTexture2D> &p_texture);
  63. void set_snap_enabled(bool p_snap_enabled);
  64. void set_snap_count(int p_snap_count);
  65. GradientTexture2DEdit();
  66. };
  67. class GradientTexture2DEditor : public VBoxContainer {
  68. GDCLASS(GradientTexture2DEditor, VBoxContainer);
  69. Ref<GradientTexture2D> texture;
  70. Button *reverse_button = nullptr;
  71. Button *snap_button = nullptr;
  72. EditorSpinSlider *snap_count_edit = nullptr;
  73. GradientTexture2DEdit *texture_editor_rect = nullptr;
  74. void _reverse_button_pressed();
  75. void _set_snap_enabled(bool p_enabled);
  76. void _set_snap_count(int p_snap_count);
  77. protected:
  78. void _notification(int p_what);
  79. public:
  80. static const int DEFAULT_SNAP;
  81. void set_texture(Ref<GradientTexture2D> &p_texture);
  82. GradientTexture2DEditor();
  83. };
  84. class EditorInspectorPluginGradientTexture2D : public EditorInspectorPlugin {
  85. GDCLASS(EditorInspectorPluginGradientTexture2D, EditorInspectorPlugin);
  86. public:
  87. virtual bool can_handle(Object *p_object) override;
  88. virtual void parse_begin(Object *p_object) override;
  89. };
  90. class GradientTexture2DEditorPlugin : public EditorPlugin {
  91. GDCLASS(GradientTexture2DEditorPlugin, EditorPlugin);
  92. public:
  93. GradientTexture2DEditorPlugin();
  94. };
  95. #endif // GRADIENT_TEXTURE_2D_EDITOR_PLUGIN_H