texture_layered_editor_plugin.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**************************************************************************/
  2. /* texture_layered_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 TEXTURE_LAYERED_EDITOR_PLUGIN_H
  31. #define TEXTURE_LAYERED_EDITOR_PLUGIN_H
  32. #include "editor/editor_inspector.h"
  33. #include "editor/plugins/editor_plugin.h"
  34. #include "scene/gui/spin_box.h"
  35. #include "scene/resources/shader.h"
  36. #include "scene/resources/texture.h"
  37. class ColorChannelSelector;
  38. class TextureLayeredEditor : public Control {
  39. GDCLASS(TextureLayeredEditor, Control);
  40. SpinBox *layer = nullptr;
  41. Label *info = nullptr;
  42. Ref<TextureLayered> texture;
  43. Ref<Shader> shaders[3];
  44. Ref<ShaderMaterial> materials[3];
  45. float x_rot = 0;
  46. float y_rot = 0;
  47. Control *texture_rect = nullptr;
  48. bool setting = false;
  49. ColorChannelSelector *channel_selector = nullptr;
  50. void _make_shaders();
  51. void _update_material(bool p_texture_changed);
  52. void _layer_changed(double) {
  53. if (!setting) {
  54. _update_material(false);
  55. }
  56. }
  57. void _texture_changed();
  58. void _texture_rect_update_area();
  59. void _texture_rect_draw();
  60. void _update_gui();
  61. void on_selected_channels_changed();
  62. protected:
  63. void _notification(int p_what);
  64. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  65. public:
  66. void edit(Ref<TextureLayered> p_texture);
  67. TextureLayeredEditor();
  68. ~TextureLayeredEditor();
  69. };
  70. class EditorInspectorPluginLayeredTexture : public EditorInspectorPlugin {
  71. GDCLASS(EditorInspectorPluginLayeredTexture, EditorInspectorPlugin);
  72. public:
  73. virtual bool can_handle(Object *p_object) override;
  74. virtual void parse_begin(Object *p_object) override;
  75. };
  76. class TextureLayeredEditorPlugin : public EditorPlugin {
  77. GDCLASS(TextureLayeredEditorPlugin, EditorPlugin);
  78. public:
  79. virtual String get_plugin_name() const override { return "TextureLayered"; }
  80. TextureLayeredEditorPlugin();
  81. };
  82. #endif // TEXTURE_LAYERED_EDITOR_PLUGIN_H