color_mode.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**************************************************************************/
  2. /* color_mode.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 COLOR_MODE_H
  31. #define COLOR_MODE_H
  32. #include "scene/gui/color_picker.h"
  33. class GradientTexture2D;
  34. class ColorMode {
  35. public:
  36. ColorPicker *color_picker = nullptr;
  37. virtual String get_name() const = 0;
  38. virtual int get_slider_count() const { return 3; }
  39. virtual float get_slider_step() const = 0;
  40. virtual float get_spinbox_arrow_step() const { return get_slider_step(); }
  41. virtual String get_slider_label(int idx) const = 0;
  42. virtual float get_slider_max(int idx) const = 0;
  43. virtual float get_slider_value(int idx) const = 0;
  44. virtual Color get_color() const = 0;
  45. virtual void _value_changed() {}
  46. virtual void slider_draw(int p_which) = 0;
  47. virtual bool apply_theme() const { return false; }
  48. virtual ColorPicker::PickerShapeType get_shape_override() const { return ColorPicker::SHAPE_MAX; }
  49. ColorMode(ColorPicker *p_color_picker);
  50. virtual ~ColorMode() {}
  51. };
  52. class ColorModeHSV : public ColorMode {
  53. public:
  54. String labels[3] = { "H", "S", "V" };
  55. float slider_max[4] = { 359, 100, 100, 255 };
  56. float cached_hue = 0.0;
  57. float cached_saturation = 0.0;
  58. virtual String get_name() const override { return "HSV"; }
  59. virtual float get_slider_step() const override { return 1.0; }
  60. virtual String get_slider_label(int idx) const override;
  61. virtual float get_slider_max(int idx) const override;
  62. virtual float get_slider_value(int idx) const override;
  63. virtual Color get_color() const override;
  64. virtual void _value_changed() override;
  65. virtual void slider_draw(int p_which) override;
  66. ColorModeHSV(ColorPicker *p_color_picker) :
  67. ColorMode(p_color_picker) {}
  68. };
  69. class ColorModeRGB : public ColorMode {
  70. public:
  71. String labels[3] = { "R", "G", "B" };
  72. virtual String get_name() const override { return "RGB"; }
  73. virtual float get_slider_step() const override { return 1; }
  74. virtual String get_slider_label(int idx) const override;
  75. virtual float get_slider_max(int idx) const override;
  76. virtual float get_slider_value(int idx) const override;
  77. virtual Color get_color() const override;
  78. virtual void slider_draw(int p_which) override;
  79. ColorModeRGB(ColorPicker *p_color_picker) :
  80. ColorMode(p_color_picker) {}
  81. };
  82. class ColorModeRAW : public ColorMode {
  83. public:
  84. String labels[3] = { "R", "G", "B" };
  85. float slider_max[4] = { 100, 100, 100, 1 };
  86. virtual String get_name() const override { return "RAW"; }
  87. virtual float get_slider_step() const override { return 0.001; }
  88. virtual float get_spinbox_arrow_step() const override { return 0.01; }
  89. virtual String get_slider_label(int idx) const override;
  90. virtual float get_slider_max(int idx) const override;
  91. virtual float get_slider_value(int idx) const override;
  92. virtual Color get_color() const override;
  93. virtual void slider_draw(int p_which) override;
  94. virtual bool apply_theme() const override;
  95. ColorModeRAW(ColorPicker *p_color_picker) :
  96. ColorMode(p_color_picker) {}
  97. };
  98. class ColorModeOKHSL : public ColorMode {
  99. public:
  100. String labels[3] = { "H", "S", "L" };
  101. float slider_max[4] = { 359, 100, 100, 255 };
  102. float cached_hue = 0.0;
  103. float cached_saturation = 0.0;
  104. Ref<GradientTexture2D> hue_texture = nullptr;
  105. virtual String get_name() const override { return "OKHSL"; }
  106. virtual float get_slider_step() const override { return 1.0; }
  107. virtual String get_slider_label(int idx) const override;
  108. virtual float get_slider_max(int idx) const override;
  109. virtual float get_slider_value(int idx) const override;
  110. virtual Color get_color() const override;
  111. virtual void _value_changed() override;
  112. virtual void slider_draw(int p_which) override;
  113. virtual ColorPicker::PickerShapeType get_shape_override() const override { return ColorPicker::SHAPE_OKHSL_CIRCLE; }
  114. ColorModeOKHSL(ColorPicker *p_color_picker) :
  115. ColorMode(p_color_picker) {}
  116. ~ColorModeOKHSL() {}
  117. };
  118. #endif // COLOR_MODE_H