color_picker.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*************************************************************************/
  2. /* color_picker.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef COLOR_PICKER_H
  30. #define COLOR_PICKER_H
  31. #include "scene/gui/slider.h"
  32. #include "scene/gui/line_edit.h"
  33. #include "scene/gui/spin_box.h"
  34. #include "scene/gui/label.h"
  35. #include "scene/gui/button.h"
  36. #include "scene/gui/popup.h"
  37. #include "scene/gui/box_container.h"
  38. #include "scene/gui/option_button.h"
  39. class ColorPicker : public HBoxContainer {
  40. OBJ_TYPE(ColorPicker,HBoxContainer);
  41. public:
  42. enum Mode {
  43. MODE_RGB,
  44. MODE_HSV,
  45. MODE_RAW
  46. };
  47. private:
  48. Mode mode;
  49. OptionButton *mode_box;
  50. Control *color_box;
  51. HSlider *scroll[4];
  52. SpinBox *values[4];
  53. Label *labels[4];
  54. Label *html_num;
  55. LineEdit *html;
  56. bool edit_alpha;
  57. Size2i ms;
  58. Color color;
  59. bool updating;
  60. void _html_entered(const String& p_html);
  61. void _value_changed(double);
  62. void _update_controls();
  63. void _update_color();
  64. void _color_box_draw();
  65. protected:
  66. void _notification(int);
  67. static void _bind_methods();
  68. public:
  69. void set_edit_alpha(bool p_show);
  70. bool is_editing_alpha() const;
  71. void set_color(const Color& p_color);
  72. Color get_color() const;
  73. void set_mode(Mode p_mode);
  74. Mode get_mode() const;
  75. ColorPicker();
  76. };
  77. VARIANT_ENUM_CAST( ColorPicker::Mode );
  78. class ColorPickerButton : public Button {
  79. OBJ_TYPE(ColorPickerButton,Button);
  80. PopupPanel *popup;
  81. ColorPicker *picker;
  82. void _color_changed(const Color& p_color);
  83. virtual void pressed();
  84. protected:
  85. void _notification(int);
  86. static void _bind_methods();
  87. public:
  88. void set_color(const Color& p_color);
  89. Color get_color() const;
  90. void set_edit_alpha(bool p_show);
  91. bool is_editing_alpha() const;
  92. ColorPickerButton();
  93. };
  94. #endif // COLOR_PICKER_H