color_picker.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*************************************************************************/
  2. /* color_picker.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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 updating;
  65. bool changing_color;
  66. float h, s, v;
  67. Color last_hsv;
  68. void _html_entered(const String &p_html);
  69. void _value_changed(double);
  70. void _update_controls();
  71. void _update_color();
  72. void _update_presets();
  73. void _update_text_value();
  74. void _text_type_toggled();
  75. void _sample_draw();
  76. void _hsv_draw(int p_which, Control *c);
  77. void _uv_input(const Ref<InputEvent> &p_event);
  78. void _w_input(const Ref<InputEvent> &p_event);
  79. void _preset_input(const Ref<InputEvent> &p_event);
  80. void _screen_input(const Ref<InputEvent> &p_event);
  81. void _add_preset_pressed();
  82. void _screen_pick_pressed();
  83. protected:
  84. void _notification(int);
  85. static void _bind_methods();
  86. public:
  87. void set_edit_alpha(bool p_show);
  88. bool is_editing_alpha() const;
  89. void set_pick_color(const Color &p_color);
  90. Color get_pick_color() const;
  91. void add_preset(const Color &p_color);
  92. void set_raw_mode(bool p_enabled);
  93. bool is_raw_mode() const;
  94. void set_focus_on_line_edit();
  95. ColorPicker();
  96. };
  97. class ColorPickerButton : public Button {
  98. GDCLASS(ColorPickerButton, Button);
  99. PopupPanel *popup;
  100. ColorPicker *picker;
  101. void _color_changed(const Color &p_color);
  102. virtual void pressed();
  103. protected:
  104. void _notification(int);
  105. static void _bind_methods();
  106. public:
  107. void set_pick_color(const Color &p_color);
  108. Color get_pick_color() const;
  109. void set_edit_alpha(bool p_show);
  110. bool is_editing_alpha() const;
  111. ColorPicker *get_picker();
  112. ColorPickerButton();
  113. };
  114. #endif // COLOR_PICKER_H