From d295d53b4a31191522627a3b40e3f367cfbc05a6 Mon Sep 17 00:00:00 2001 From: Kongfa Waroros Date: Wed, 17 Feb 2021 12:30:56 +0700 Subject: [PATCH] Add interpolation bar on each channel in ColorPicker --- doc/classes/ColorPicker.xml | 3 + editor/editor_themes.cpp | 1 + editor/icons/ColorPickerBarArrow.svg | 1 + scene/gui/color_picker.cpp | 90 ++++++++++++++++++ scene/gui/color_picker.h | 1 + scene/resources/default_theme/bar_arrow.png | Bin 0 -> 208 bytes .../resources/default_theme/default_theme.cpp | 1 + scene/resources/default_theme/theme_data.h | 4 + 8 files changed, 101 insertions(+) create mode 100644 editor/icons/ColorPickerBarArrow.svg create mode 100644 scene/resources/default_theme/bar_arrow.png diff --git a/doc/classes/ColorPicker.xml b/doc/classes/ColorPicker.xml index aea3542867a..2fc4313e47d 100644 --- a/doc/classes/ColorPicker.xml +++ b/doc/classes/ColorPicker.xml @@ -91,6 +91,9 @@ The icon for the "Add Preset" button. + + The texture for the arrow grabber. + Custom texture for the hue selection slider on the right. diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 3d40c145f2f..fe748b81c38 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -1283,6 +1283,7 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_icon("add_preset", "ColorPicker", theme->get_icon("Add", "EditorIcons")); theme->set_icon("preset_bg", "ColorPicker", theme->get_icon("GuiMiniCheckerboard", "EditorIcons")); theme->set_icon("overbright_indicator", "ColorPicker", theme->get_icon("OverbrightIndicator", "EditorIcons")); + theme->set_icon("bar_arrow", "ColorPicker", theme->get_icon("ColorPickerBarArrow", "EditorIcons")); theme->set_icon("bg", "ColorPickerButton", theme->get_icon("GuiMiniCheckerboard", "EditorIcons")); diff --git a/editor/icons/ColorPickerBarArrow.svg b/editor/icons/ColorPickerBarArrow.svg new file mode 100644 index 00000000000..9d034106ee6 --- /dev/null +++ b/editor/icons/ColorPickerBarArrow.svg @@ -0,0 +1 @@ + diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index e8586b72e93..bddbe30f531 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -113,6 +113,24 @@ void ColorPicker::_update_controls() { btn_hsv->set_disabled(false); } + if (raw_mode_enabled) { + for (int i = 0; i < 3; i++) { + scroll[i]->add_theme_icon_override("grabber", Ref()); + scroll[i]->add_theme_icon_override("grabber_highlight", Ref()); + scroll[i]->add_theme_style_override("slider", Ref()); + scroll[i]->add_theme_style_override("grabber_area", Ref()); + scroll[i]->add_theme_style_override("grabber_area_highlight", Ref()); + } + } else { + for (int i = 0; i < 3; i++) { + scroll[i]->add_theme_icon_override("grabber", get_theme_icon("bar_arrow")); + scroll[i]->add_theme_icon_override("grabber_highlight", get_theme_icon("bar_arrow")); + scroll[i]->add_theme_style_override("slider", Ref(memnew(StyleBoxEmpty))); + scroll[i]->add_theme_style_override("grabber_area", Ref(memnew(StyleBoxEmpty))); + scroll[i]->add_theme_style_override("grabber_area_highlight", Ref(memnew(StyleBoxEmpty))); + } + } + if (edit_alpha) { values[3]->show(); scroll[3]->show(); @@ -243,6 +261,9 @@ void ColorPicker::_update_color(bool p_update_sliders) { sample->update(); uv_edit->update(); w_edit->update(); + for (int i = 0; i < 4; i++) { + scroll[i]->update(); + } updating = false; } @@ -456,6 +477,69 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) { } } +void ColorPicker::_slider_draw(int p_which) { + Vector pos; + pos.resize(4); + Vector col; + col.resize(4); + Size2 size = scroll[p_which]->get_size(); + Color left_color; + Color right_color; +#ifdef TOOLS_ENABLED + const real_t margin = 4 * EDSCALE; +#else + const real_t margin = 4; +#endif + + if (p_which == 3) { + scroll[p_which]->draw_texture_rect(get_theme_icon("preset_bg", "ColorPicker"), Rect2(Point2(0, margin), Size2(size.x, margin)), true); + + left_color = color; + left_color.a = 0; + right_color = color; + right_color.a = 1; + } else { + if (raw_mode_enabled) { + return; + } + if (hsv_mode_enabled) { + if (p_which == 0) { + Ref hue = get_theme_icon("color_hue", "ColorPicker"); + scroll[p_which]->draw_set_transform(Point2(), -Math_PI / 2, Size2(1.0, 1.0)); + scroll[p_which]->draw_texture_rect(hue, Rect2(Vector2(margin * -2, 0), Vector2(scroll[p_which]->get_size().x, margin)), false, Color(1, 1, 1), true); + return; + } + Color s_col; + Color v_col; + s_col.set_hsv(h, 0, v); + left_color = (p_which == 1) ? s_col : Color(0, 0, 0); + s_col.set_hsv(h, 1, v); + v_col.set_hsv(h, s, 1); + right_color = (p_which == 1) ? s_col : v_col; + } else { + left_color = Color( + p_which == 0 ? 0 : color.r, + p_which == 1 ? 0 : color.g, + p_which == 2 ? 0 : color.b); + right_color = Color( + p_which == 0 ? 1 : color.r, + p_which == 1 ? 1 : color.g, + p_which == 2 ? 1 : color.b); + } + } + + col.set(0, left_color); + col.set(1, right_color); + col.set(2, right_color); + col.set(3, left_color); + pos.set(0, Vector2(0, margin)); + pos.set(1, Vector2(size.x, margin)); + pos.set(2, Vector2(size.x, margin * 2)); + pos.set(3, Vector2(0, margin * 2)); + + scroll[p_which]->draw_polygon(pos, col); +} + void ColorPicker::_uv_input(const Ref &p_event) { Ref bev = p_event; @@ -799,10 +883,16 @@ ColorPicker::ColorPicker() : scroll[i]->set_h_size_flags(SIZE_EXPAND_FILL); scroll[i]->connect("value_changed", callable_mp(this, &ColorPicker::_value_changed)); + scroll[i]->connect("draw", callable_mp(this, &ColorPicker::_slider_draw), make_binds(i)); vbr->add_child(hbc); } labels[3]->set_text("A"); + scroll[3]->add_theme_icon_override("grabber", get_theme_icon("bar_arrow")); + scroll[3]->add_theme_icon_override("grabber_highlight", get_theme_icon("bar_arrow")); + scroll[3]->add_theme_style_override("slider", Ref(memnew(StyleBoxEmpty))); + scroll[3]->add_theme_style_override("grabber_area", Ref(memnew(StyleBoxEmpty))); + scroll[3]->add_theme_style_override("grabber_area_highlight", Ref(memnew(StyleBoxEmpty))); HBoxContainer *hhb = memnew(HBoxContainer); vbr->add_child(hhb); diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index 7915527bc09..24e1746c417 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -91,6 +91,7 @@ private: void _text_type_toggled(); void _sample_draw(); void _hsv_draw(int p_which, Control *c); + void _slider_draw(int p_which); void _uv_input(const Ref &p_event); void _w_input(const Ref &p_event); diff --git a/scene/resources/default_theme/bar_arrow.png b/scene/resources/default_theme/bar_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..7cf146b8dad407ec518fde7b9bf1ebb285496a56 GIT binary patch literal 208 zcmeAS@N?(olHy`uVBq!ia0vp^0zfRn!2%@pvP=H}DVB6cUq=Rpjs4tz5?O(K#^NA% zCx&(BWL^R}oCO|{#S9F52SAuH>slu#P%zcg#W6(VeDa_34e|zk3amXAD*uDy4|2bo zA1onpqgZ8MQfNVZbE4>CJ!a;^yw417o|fQ}JN9?}u>-uOudI_B|LBOY@@q-lx+oK{ z@&aS{2Z7*Ojg5^9gZ4EyHh#3%%UmI3#UjE`eanP#_g1?cpoI*cu6{1-oD!M &theme, const Ref &default_font, const theme->set_icon("color_sample", "ColorPicker", make_icon(color_picker_sample_png)); theme->set_icon("preset_bg", "ColorPicker", make_icon(mini_checkerboard_png)); theme->set_icon("overbright_indicator", "ColorPicker", make_icon(overbright_indicator_png)); + theme->set_icon("bar_arrow", "ColorPicker", make_icon(bar_arrow_png)); theme->set_icon("bg", "ColorPickerButton", make_icon(mini_checkerboard_png)); diff --git a/scene/resources/default_theme/theme_data.h b/scene/resources/default_theme/theme_data.h index b905c9db693..6b78ba7933e 100644 --- a/scene/resources/default_theme/theme_data.h +++ b/scene/resources/default_theme/theme_data.h @@ -14,6 +14,10 @@ static const unsigned char arrow_right_png[] = { 0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa, 0x0, 0x0, 0x0, 0xd, 0x49, 0x48, 0x44, 0x52, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0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 0xee, 0x9f, 0x53, 0x18, 0x18, 0xd8, 0x73, 0x24, 0xbe, 0x62, 0x55, 0x70, 0x5f, 0x83, 0x61, 0x15, 0xa3, 0x2e, 0x3, 0x3, 0xc3, 0xd, 0xe6, 0x30, 0xd9, 0xcb, 0x18, 0xa, 0x1e, 0xc6, 0xfd, 0x9f, 0xc6, 0xc0, 0xd, 0x35, 0xea, 0x3b, 0x63, 0x81, 0xfc, 0x2c, 0x14, 0x5, 0xf, 0x2a, 0x18, 0xda, 0xd1, 0x1c, 0x50, 0xa9, 0xd0, 0x1, 0x57, 0xf0, 0x10, 0x53, 0x9a, 0x81, 0x81, 0x81, 0xa1, 0x52, 0xbe, 0x83, 0x81, 0x81, 0xf1, 0x3f, 0x2e, 0x69, 0xa8, 0x12, 0x3a, 0x4, 0x14, 0x0, 0x7b, 0xda, 0x34, 0x1, 0xbb, 0xb5, 0x3e, 0x6c, 0x0, 0x0, 0x0, 0x0, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 +}; + static const unsigned char bookmark_png[] = { 0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa, 0x0, 0x0, 0x0, 0xd, 0x49, 0x48, 0x44, 0x52, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0, 0x10, 0x8, 0x6, 0x0, 0x0, 0x0, 0x1f, 0xf3, 0xff, 0x61, 0x0, 0x0, 0x0, 0x4, 0x73, 0x42, 0x49, 0x54, 0x8, 0x8, 0x8, 0x8, 0x7c, 0x8, 0x64, 0x88, 0x0, 0x0, 0x0, 0x57, 0x49, 0x44, 0x41, 0x54, 0x38, 0x8d, 0xed, 0x93, 0x31, 0xa, 0xc0, 0x30, 0xc, 0x3, 0xa5, 0xd0, 0xff, 0x7f, 0x59, 0x1d, 0x8a, 0x42, 0x8, 0x9, 0x95, 0xc9, 0xd2, 0xa1, 0x9a, 0x8c, 0xf1, 0xdd, 0x62, 0x1b, 0x38, 0xc, 0x87, 0x5a, 0x5, 0xae, 0x79, 0xde, 0x2, 0x1, 0x80, 0x94, 0x39, 0x48, 0x76, 0x49, 0x17, 0xa4, 0xf0, 0x24, 0x61, 0x2b, 0x51, 0x8b, 0xfc, 0x82, 0xcf, 0xb, 0x48, 0x7a, 0xdf, 0x75, 0x81, 0xf, 0xe5, 0x29, 0xf7, 0x92, 0x6b, 0x3, 0x1a, 0x1e, 0xda, 0x7c, 0x3d, 0x77, 0x21, 0x7b, 0xa8, 0x74, 0x2e, 0xcb, 0xd, 0xc8, 0x75, 0x13, 0x28, 0x9, 0xed, 0xc2, 0xc8, 0x0, 0x0, 0x0, 0x0, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 };