Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color picker update #230

Open
wants to merge 5 commits into
base: blazium-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/classes/ColorPicker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,6 @@
<theme_item name="color_hue" data_type="icon" type="Texture2D">
Custom texture for the hue selection slider on the right.
</theme_item>
<theme_item name="color_okhsl_hue" data_type="icon" type="Texture2D">
Custom texture for the H slider in the OKHSL color mode.
</theme_item>
<theme_item name="expanded_arrow" data_type="icon" type="Texture2D">
The icon for color preset drop down menu when expanded.
</theme_item>
Expand All @@ -203,6 +200,9 @@
<theme_item name="picker_cursor" data_type="icon" type="Texture2D">
The image displayed over the color box/circle (depending on the [member picker_shape]), marking the currently selected color.
</theme_item>
<theme_item name="picker_cursor_bg" data_type="icon" type="Texture2D">
The fill image displayed behind the picker cursor.
</theme_item>
<theme_item name="sample_bg" data_type="icon" type="Texture2D">
Background panel for the color preview box (visible when the color is translucent).
</theme_item>
Expand Down
2 changes: 1 addition & 1 deletion editor/icons/PickerCursor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions editor/icons/PickerCursorBg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions editor/themes/editor_theme_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,7 @@ void EditorThemeManager::_populate_standard_styles(const Ref<EditorTheme> &p_the
p_theme->set_icon("overbright_indicator", "ColorPicker", p_theme->get_icon(SNAME("OverbrightIndicator"), EditorStringName(EditorIcons)));
p_theme->set_icon("bar_arrow", "ColorPicker", p_theme->get_icon(SNAME("ColorPickerBarArrow"), EditorStringName(EditorIcons)));
p_theme->set_icon("picker_cursor", "ColorPicker", p_theme->get_icon(SNAME("PickerCursor"), EditorStringName(EditorIcons)));
p_theme->set_icon("picker_cursor_bg", "ColorPicker", p_theme->get_icon(SNAME("PickerCursorBg"), EditorStringName(EditorIcons)));

// ColorPickerButton.
p_theme->set_icon("bg", "ColorPickerButton", p_theme->get_icon(SNAME("GuiMiniCheckerboard"), EditorStringName(EditorIcons)));
Expand Down
29 changes: 25 additions & 4 deletions scene/gui/color_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include "core/math/color.h"
#include "scene/gui/slider.h"
#include "thirdparty/misc/ok_color.h"
#include "scene/resources/gradient_texture.h"

ColorMode::ColorMode(ColorPicker *p_color_picker) {
color_picker = p_color_picker;
Expand Down Expand Up @@ -395,8 +395,29 @@ void ColorModeOKHSL::slider_draw(int p_which) {
slider->draw_polygon(pos, col);

if (p_which == 0) { // H
Ref<Texture2D> hue = color_picker->theme_cache.color_okhsl_hue;
slider->draw_texture_rect(hue, Rect2(Vector2(), Vector2(size.x, margin)), false, Color::from_hsv(0, 0, color.get_ok_hsl_l() * 2.0, color.get_ok_hsl_s()));
return;
const int precision = 7;

Ref<Gradient> hue_gradient;
hue_gradient.instantiate();
PackedFloat32Array offsets;
offsets.resize(precision);
PackedColorArray colors;
colors.resize(precision);

for (int i = 0; i < precision; i++) {
float h = i / float(precision - 1);
offsets.write[i] = h;
colors.write[i] = Color::from_ok_hsl(h, color.get_ok_hsl_s(), color.get_ok_hsl_l());
}
hue_gradient->set_offsets(offsets);
hue_gradient->set_colors(colors);
hue_gradient->set_interpolation_color_space(Gradient::ColorSpace::GRADIENT_COLOR_SPACE_OKLAB);
if (hue_texture.is_null()) {
hue_texture.instantiate();
hue_texture->set_width(800);
hue_texture->set_height(6);
}
hue_texture->set_gradient(hue_gradient);
slider->draw_texture_rect(hue_texture, Rect2(Vector2(), Vector2(size.x, margin)), false);
}
}
24 changes: 12 additions & 12 deletions scene/gui/color_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,31 @@

#include "scene/gui/color_picker.h"

struct Color;
class GradientTexture2D;

class ColorMode {
public:
ColorPicker *color_picker = nullptr;

virtual String get_name() const = 0;

virtual int get_slider_count() const { return 3; };
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 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 bool can_allow_greater() const { return false; }
virtual float get_slider_value(int idx) const = 0;

virtual Color get_color() const = 0;

virtual void _value_changed(){};
virtual void _value_changed() {}

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(){};
virtual ~ColorMode() {}
};

class ColorModeHSV : public ColorMode {
Expand All @@ -82,7 +81,7 @@ class ColorModeHSV : public ColorMode {
virtual void slider_draw(int p_which) override;

ColorModeHSV(ColorPicker *p_color_picker) :
ColorMode(p_color_picker){};
ColorMode(p_color_picker) {}
};

class ColorModeRGB : public ColorMode {
Expand All @@ -103,7 +102,7 @@ class ColorModeRGB : public ColorMode {
virtual void slider_draw(int p_which) override;

ColorModeRGB(ColorPicker *p_color_picker) :
ColorMode(p_color_picker){};
ColorMode(p_color_picker) {}
};

class ColorModeRAW : public ColorMode {
Expand All @@ -124,7 +123,7 @@ class ColorModeRAW : public ColorMode {
virtual void slider_draw(int p_which) override;

ColorModeRAW(ColorPicker *p_color_picker) :
ColorMode(p_color_picker){};
ColorMode(p_color_picker) {}
};

class ColorModeOKHSL : public ColorMode {
Expand All @@ -133,6 +132,7 @@ class ColorModeOKHSL : public ColorMode {
float slider_max[4] = { 359, 100, 100, 255 };
float cached_hue = 0.0;
float cached_saturation = 0.0;
Ref<GradientTexture2D> hue_texture = nullptr;

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

Expand All @@ -148,9 +148,9 @@ class ColorModeOKHSL : public ColorMode {
virtual void slider_draw(int p_which) override;

ColorModeOKHSL(ColorPicker *p_color_picker) :
ColorMode(p_color_picker){};
ColorMode(p_color_picker) {}

~ColorModeOKHSL(){};
~ColorModeOKHSL() {}
};

#endif // COLOR_MODE_H
Loading
Loading