color_picker.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*************************************************************************/
  2. /* color_picker.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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_PICKER_H
  31. #define COLOR_PICKER_H
  32. #include "scene/gui/box_container.h"
  33. #include "scene/gui/button.h"
  34. #include "scene/gui/check_button.h"
  35. #include "scene/gui/label.h"
  36. #include "scene/gui/line_edit.h"
  37. #include "scene/gui/popup.h"
  38. #include "scene/gui/slider.h"
  39. #include "scene/gui/spin_box.h"
  40. #include "scene/gui/texture_rect.h"
  41. #include "scene/gui/tool_button.h"
  42. class ColorPicker : public BoxContainer {
  43. GDCLASS(ColorPicker, BoxContainer);
  44. private:
  45. Control *screen;
  46. Control *uv_edit;
  47. Control *w_edit;
  48. TextureRect *sample;
  49. TextureRect *preset;
  50. Button *bt_add_preset;
  51. List<Color> presets;
  52. ToolButton *btn_pick;
  53. CheckButton *btn_mode;
  54. HSlider *scroll[4];
  55. SpinBox *values[4];
  56. Label *labels[4];
  57. Button *text_type;
  58. LineEdit *c_text;
  59. bool edit_alpha;
  60. Size2i ms;
  61. bool text_is_constructor;
  62. Color color;
  63. bool raw_mode_enabled;
  64. bool deferred_mode_enabled;
  65. bool updating;
  66. bool changing_color;
  67. float h, s, v;
  68. Color last_hsv;
  69. void _html_entered(const String &p_html);
  70. void _value_changed(double);
  71. void _update_controls();
  72. void _update_color();
  73. void _update_presets();
  74. void _update_text_value();
  75. void _text_type_toggled();
  76. void _sample_draw();
  77. void _hsv_draw(int p_which, Control *c);
  78. void _uv_input(const Ref<InputEvent> &p_event);
  79. void _w_input(const Ref<InputEvent> &p_event);
  80. void _preset_input(const Ref<InputEvent> &p_event);
  81. void _screen_input(const Ref<InputEvent> &p_event);
  82. void _add_preset_pressed();
  83. void _screen_pick_pressed();
  84. void _focus_enter();
  85. void _focus_exit();
  86. void _html_focus_exit();
  87. protected:
  88. void _notification(int);
  89. static void _bind_methods();
  90. public:
  91. void set_edit_alpha(bool p_show);
  92. bool is_editing_alpha() const;
  93. void set_pick_color(const Color &p_color);
  94. Color get_pick_color() const;
  95. void add_preset(const Color &p_color);
  96. void erase_preset(const Color &p_color);
  97. PoolColorArray get_presets() const;
  98. void set_raw_mode(bool p_enabled);
  99. bool is_raw_mode() const;
  100. void set_deferred_mode(bool p_enabled);
  101. bool is_deferred_mode() const;
  102. void set_focus_on_line_edit();
  103. ColorPicker();
  104. };
  105. class ColorPickerButton : public Button {
  106. GDCLASS(ColorPickerButton, Button);
  107. PopupPanel *popup;
  108. ColorPicker *picker;
  109. Color color;
  110. bool edit_alpha;
  111. void _color_changed(const Color &p_color);
  112. void _modal_closed();
  113. virtual void pressed();
  114. void _update_picker();
  115. protected:
  116. void _notification(int);
  117. static void _bind_methods();
  118. public:
  119. void set_pick_color(const Color &p_color);
  120. Color get_pick_color() const;
  121. void set_edit_alpha(bool p_show);
  122. bool is_editing_alpha() const;
  123. ColorPicker *get_picker();
  124. PopupPanel *get_popup();
  125. ColorPickerButton();
  126. };
  127. #endif // COLOR_PICKER_H