Skip to content

Commit

Permalink
ColorPicker update
Browse files Browse the repository at this point in the history
  • Loading branch information
WhalesState committed Feb 11, 2024
1 parent 40fc059 commit 7249081
Show file tree
Hide file tree
Showing 14 changed files with 441 additions and 476 deletions.
6 changes: 3 additions & 3 deletions doc/classes/ColorPicker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
<member name="sliders_visible" type="bool" setter="set_sliders_visible" getter="are_sliders_visible" default="true">
If [code]true[/code], the color sliders are visible.
</member>
<member name="wheel_visible" type="bool" setter="set_wheel_visible" getter="is_wheel_visible" default="true">
If [code]true[/code], the color wheel is visible.
</member>
</members>
<signals>
<signal name="color_changed">
Expand Down Expand Up @@ -136,9 +139,6 @@
<constant name="SHAPE_OKHSL_CIRCLE" value="3" enum="PickerShapeType">
HSL OK Color Model circle color space.
</constant>
<constant name="SHAPE_NONE" value="4" enum="PickerShapeType">
The color space shape and the shape select button are hidden. Can't be selected from the shapes popup.
</constant>
</constants>
<theme_items>
<theme_item name="center_slider_grabbers" data_type="constant" type="int" default="1">
Expand Down
21 changes: 9 additions & 12 deletions editor/editor_themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_color("clear_button_color", "LineEdit", font_color);
theme->set_color("clear_button_color_pressed", "LineEdit", accent_color);

theme->set_constant("minimum_character_width", "LineEdit", 4);
theme->set_constant("minimum_character_width", "LineEdit", 3);
theme->set_constant("outline_size", "LineEdit", 0);
theme->set_constant("caret_width", "LineEdit", 1);

Expand Down Expand Up @@ -2132,13 +2132,16 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_color("files_disabled", "FileDialog", font_disabled_color);

// ColorPicker
theme->set_constant("margin", "ColorPicker", default_margin_size);
theme->set_constant("sv_width", "ColorPicker", 256 * EDSCALE);
theme->set_constant("sv_height", "ColorPicker", 256 * EDSCALE);
theme->set_constant("h_width", "ColorPicker", 30 * EDSCALE);
theme->set_constant("label_width", "ColorPicker", 10 * EDSCALE);
theme->set_constant("margin_left", "ColorPicker", 2 * EDSCALE);
theme->set_constant("margin_top", "ColorPicker", 2 * EDSCALE);
theme->set_constant("margin_right", "ColorPicker", 2 * EDSCALE);
theme->set_constant("margin_bottom", "ColorPicker", 2 * EDSCALE);
theme->set_constant("sv_width", "ColorPicker", 264 * EDSCALE);
theme->set_constant("sv_height", "ColorPicker", 264 * EDSCALE);
theme->set_constant("h_width", "ColorPicker", 24 * EDSCALE);
theme->set_constant("center_slider_grabbers", "ColorPicker", 1);
theme->set_icon("screen_picker", "ColorPicker", theme->get_icon(SNAME("ColorPick"), EditorStringName(EditorIcons)));
theme->set_icon("modes_icon", "ColorPicker", theme->get_icon(SNAME("GuiTabMenuHl"), EditorStringName(EditorIcons)));
theme->set_icon("shape_circle", "ColorPicker", theme->get_icon(SNAME("PickerShapeCircle"), EditorStringName(EditorIcons)));
theme->set_icon("shape_rect", "ColorPicker", theme->get_icon(SNAME("PickerShapeRectangle"), EditorStringName(EditorIcons)));
theme->set_icon("shape_rect_wheel", "ColorPicker", theme->get_icon(SNAME("PickerShapeRectangleWheel"), EditorStringName(EditorIcons)));
Expand All @@ -2157,12 +2160,6 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_icon("preset_bg", "ColorPresetButton", theme->get_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons)));
theme->set_icon("overbright_indicator", "ColorPresetButton", theme->get_icon(SNAME("OverbrightIndicator"), EditorStringName(EditorIcons)));

// Information on 3D viewport
Ref<StyleBoxFlat> style_info_3d_viewport = style_default->duplicate();
style_info_3d_viewport->set_bg_color(style_info_3d_viewport->get_bg_color() * Color(1, 1, 1, 0.5));
style_info_3d_viewport->set_border_width_all(0);
theme->set_stylebox("Information3dViewport", EditorStringName(EditorStyles), style_info_3d_viewport);

// Asset Library.
theme->set_stylebox("bg", "AssetLib", style_empty);
theme->set_stylebox("panel", "AssetLib", style_content_panel);
Expand Down
40 changes: 39 additions & 1 deletion editor/icons/PickerShapeCircle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 39 additions & 1 deletion editor/icons/PickerShapeRectangle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 19 additions & 23 deletions scene/gui/color_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ String ColorModeRGB::get_slider_label(int idx) const {

float ColorModeRGB::get_slider_max(int idx) const {
ERR_FAIL_INDEX_V_MSG(idx, 4, 0, "Couldn't get slider max value.");
Color color = color_picker->get_pick_color();
return next_power_of_2(MAX(255, color.components[idx] * 255.0)) - 1;
return slider_max[idx];
}

float ColorModeRGB::get_slider_value(int idx) const {
Expand Down Expand Up @@ -252,30 +251,27 @@ void ColorModeRAW::slider_draw(int p_which) {
left_color.a = 0;
right_color = color;
right_color.a = 1;

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, 0));
pos.set(1, Vector2(size.x, 0));
pos.set(2, Vector2(size.x, margin));
pos.set(3, Vector2(0, margin));

slider->draw_polygon(pos, 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);
}
}

bool ColorModeRAW::apply_theme() const {
for (int i = 0; i < 4; i++) {
HSlider *slider = color_picker->get_slider(i);
slider->remove_theme_icon_override("grabber");
slider->remove_theme_icon_override("grabber_highlight");
slider->remove_theme_style_override("slider");
slider->remove_theme_constant_override("grabber_offset");
}
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, 0));
pos.set(1, Vector2(size.x, 0));
pos.set(2, Vector2(size.x, margin));
pos.set(3, Vector2(0, margin));

return true;
slider->draw_polygon(pos, col);
}

void ColorModeOKHSL::_value_changed() {
Expand Down
13 changes: 6 additions & 7 deletions scene/gui/color_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class ColorMode {

virtual int get_slider_count() const { return 3; };
virtual float get_slider_step() const = 0;
virtual float get_spinbox_arrow_step() const { return get_slider_step(); };
virtual String get_slider_label(int idx) const = 0;
virtual float get_slider_max(int idx) const = 0;
virtual bool can_allow_greater() const { return false; };
virtual float get_slider_value(int idx) const = 0;

virtual Color get_color() const = 0;
Expand All @@ -54,7 +54,6 @@ class ColorMode {

virtual void slider_draw(int p_which) = 0;
virtual bool apply_theme() const { return false; }
virtual ColorPicker::PickerShapeType get_shape_override() const { return ColorPicker::SHAPE_MAX; }

ColorMode(ColorPicker *p_color_picker);
virtual ~ColorMode(){};
Expand Down Expand Up @@ -87,12 +86,14 @@ class ColorModeHSV : public ColorMode {
class ColorModeRGB : public ColorMode {
public:
String labels[3] = { "R", "G", "B" };
float slider_max[4] = { 255, 255, 255, 255 };

virtual String get_name() const override { return "RGB"; }

virtual float get_slider_step() const override { return 1; }
virtual String get_slider_label(int idx) const override;
virtual float get_slider_max(int idx) const override;
virtual bool can_allow_greater() const override { return true; };
virtual float get_slider_value(int idx) const override;

virtual Color get_color() const override;
Expand All @@ -106,20 +107,19 @@ class ColorModeRGB : public ColorMode {
class ColorModeRAW : public ColorMode {
public:
String labels[3] = { "R", "G", "B" };
float slider_max[4] = { 100, 100, 100, 1 };
float slider_max[4] = { 1, 1, 1, 1 };

virtual String get_name() const override { return "RAW"; }

virtual float get_slider_step() const override { return 0.001; }
virtual float get_spinbox_arrow_step() const override { return 0.01; }
virtual float get_slider_step() const override { return 1.0 / 255.0; }
virtual String get_slider_label(int idx) const override;
virtual float get_slider_max(int idx) const override;
virtual bool can_allow_greater() const override { return true; };
virtual float get_slider_value(int idx) const override;

virtual Color get_color() const override;

virtual void slider_draw(int p_which) override;
virtual bool apply_theme() const override;

ColorModeRAW(ColorPicker *p_color_picker) :
ColorMode(p_color_picker){};
Expand All @@ -144,7 +144,6 @@ class ColorModeOKHSL : public ColorMode {
virtual void _value_changed() override;

virtual void slider_draw(int p_which) override;
virtual ColorPicker::PickerShapeType get_shape_override() const override { return ColorPicker::SHAPE_OKHSL_CIRCLE; }

ColorModeOKHSL(ColorPicker *p_color_picker) :
ColorMode(p_color_picker){};
Expand Down
Loading

0 comments on commit 7249081

Please sign in to comment.