color_mode.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. #pragma once
  31. #include "scene/gui/color_picker.h"
  32. class GradientTexture2D;
  33. class ColorMode {
  34. public:
  35. ColorPicker *color_picker = nullptr;
  36. virtual String get_name() const = 0;
  37. virtual int get_slider_count() const { return 3; }
  38. virtual float get_slider_step() const = 0;
  39. virtual float get_spinbox_arrow_step() const { return get_slider_step(); }
  40. virtual String get_slider_label(int idx) const = 0;
  41. virtual float get_slider_max(int idx) const = 0;
  42. virtual bool get_allow_greater() const { return false; }
  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. ColorMode(ColorPicker *p_color_picker);
  49. virtual ~ColorMode() {}
  50. };
  51. class ColorModeHSV : public ColorMode {
  52. public:
  53. String labels[3] = { "H", "S", "V" };
  54. float slider_max[4] = { 359, 100, 100, 255 };
  55. float cached_hue = 0.0;
  56. float cached_saturation = 0.0;
  57. virtual String get_name() const override { return "HSV"; }
  58. virtual float get_slider_step() const override { return 1.0; }
  59. virtual String get_slider_label(int idx) const override;
  60. virtual float get_slider_max(int idx) const override;
  61. virtual float get_slider_value(int idx) const override;
  62. virtual Color get_color() const override;
  63. virtual void _value_changed() override;
  64. virtual void slider_draw(int p_which) override;
  65. ColorModeHSV(ColorPicker *p_color_picker) :
  66. ColorMode(p_color_picker) {}
  67. };
  68. class ColorModeRGB : public ColorMode {
  69. public:
  70. String labels[3] = { "R", "G", "B" };
  71. virtual String get_name() const override { return "RGB"; }
  72. virtual float get_slider_step() const override { return 1; }
  73. virtual String get_slider_label(int idx) const override;
  74. virtual float get_slider_max(int idx) const override { return 255; }
  75. virtual bool get_allow_greater() const override { return true; }
  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 bool get_allow_greater() const override { return true; }
  92. virtual float get_slider_value(int idx) const override;
  93. virtual Color get_color() const override;
  94. virtual void slider_draw(int p_which) override;
  95. virtual bool apply_theme() const override;
  96. ColorModeRAW(ColorPicker *p_color_picker) :
  97. ColorMode(p_color_picker) {}
  98. };
  99. class ColorModeOKHSL : public ColorMode {
  100. public:
  101. String labels[3] = { "H", "S", "L" };
  102. float slider_max[4] = { 359, 100, 100, 255 };
  103. float cached_hue = 0.0;
  104. float cached_saturation = 0.0;
  105. Ref<GradientTexture2D> hue_texture;
  106. virtual String get_name() const override { return "OKHSL"; }
  107. virtual float get_slider_step() const override { return 1.0; }
  108. virtual String get_slider_label(int idx) const override;
  109. virtual float get_slider_max(int idx) const override;
  110. virtual float get_slider_value(int idx) const override;
  111. virtual Color get_color() const override;
  112. virtual void _value_changed() override;
  113. virtual void slider_draw(int p_which) override;
  114. ColorModeOKHSL(ColorPicker *p_color_picker) :
  115. ColorMode(p_color_picker) {}
  116. };