particle_process_material_editor_plugin.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**************************************************************************/
  2. /* particle_process_material_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 PARTICLE_PROCESS_MATERIAL_EDITOR_PLUGIN_H
  31. #define PARTICLE_PROCESS_MATERIAL_EDITOR_PLUGIN_H
  32. #include "editor/editor_properties.h"
  33. #include "editor/plugins/editor_plugin.h"
  34. class Button;
  35. class EditorSpinSlider;
  36. class Label;
  37. class ParticleProcessMaterial;
  38. class Range;
  39. class VBoxContainer;
  40. class ParticleProcessMaterialMinMaxPropertyEditor : public EditorProperty {
  41. GDCLASS(ParticleProcessMaterialMinMaxPropertyEditor, EditorProperty);
  42. enum class Hover {
  43. NONE,
  44. LEFT,
  45. RIGHT,
  46. MIDDLE,
  47. };
  48. enum class Drag {
  49. NONE,
  50. LEFT,
  51. RIGHT,
  52. MIDDLE,
  53. SCALE,
  54. };
  55. enum class Mode {
  56. RANGE,
  57. MIDPOINT,
  58. };
  59. Ref<Texture2D> range_slider_left_icon;
  60. Ref<Texture2D> range_slider_right_icon;
  61. Color background_color;
  62. Color normal_color;
  63. Color hovered_color;
  64. Color drag_color;
  65. Color midpoint_color;
  66. Control *range_edit_widget = nullptr;
  67. Button *toggle_mode_button = nullptr;
  68. Range *min_range = nullptr;
  69. Range *max_range = nullptr;
  70. EditorSpinSlider *min_edit = nullptr;
  71. EditorSpinSlider *max_edit = nullptr;
  72. Vector2 edit_size;
  73. Vector2 margin;
  74. Vector2 usable_area;
  75. Vector2 property_range;
  76. bool mouse_inside = false;
  77. Hover hover = Hover::NONE;
  78. Drag drag = Drag::NONE;
  79. float drag_from_value = 0.0;
  80. float drag_midpoint = 0.0;
  81. float drag_origin = 0.0;
  82. Mode slider_mode = Mode::RANGE;
  83. void _update_sizing();
  84. void _range_edit_draw();
  85. void _range_edit_gui_input(const Ref<InputEvent> &p_event);
  86. void _set_mouse_inside(bool p_inside);
  87. float _get_min_ratio() const;
  88. float _get_max_ratio() const;
  89. float _get_left_offset() const;
  90. float _get_right_offset() const;
  91. Rect2 _get_middle_rect() const;
  92. void _set_clamped_values(float p_min, float p_max);
  93. void _sync_property();
  94. void _update_mode();
  95. void _toggle_mode(bool p_edit_mode);
  96. void _update_slider_values();
  97. void _sync_sliders(float, const EditorSpinSlider *p_changed_slider);
  98. float _get_max_spread() const;
  99. protected:
  100. void _notification(int p_what);
  101. public:
  102. void setup(float p_min, float p_max, float p_step, bool p_allow_less, bool p_allow_greater, bool p_degrees);
  103. virtual void update_property() override;
  104. ParticleProcessMaterialMinMaxPropertyEditor();
  105. };
  106. class EditorInspectorParticleProcessMaterialPlugin : public EditorInspectorPlugin {
  107. GDCLASS(EditorInspectorParticleProcessMaterialPlugin, EditorInspectorPlugin);
  108. public:
  109. virtual bool can_handle(Object *p_object) override;
  110. virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide = false) override;
  111. };
  112. #endif // PARTICLE_PROCESS_MATERIAL_EDITOR_PLUGIN_H