Compare commits

...

3 Commits

Author SHA1 Message Date
Luo Zhihao
0602f22dc0
Merge 95f5ce6dbf into 9e6098432a 2024-11-20 17:32:57 +01:00
LuoZhihao
95f5ce6dbf fix broken icon when running 2024-11-20 19:36:57 +08:00
LuoZhihao
e3ebbdd963 ColorPicker: add intensity slider in raw mode for hdr 2024-11-18 19:48:03 +08:00
3 changed files with 42 additions and 20 deletions

View File

@ -210,26 +210,36 @@ void ColorModeHSV::slider_draw(int p_which) {
}
String ColorModeRAW::get_slider_label(int idx) const {
ERR_FAIL_INDEX_V_MSG(idx, 3, String(), "Couldn't get slider label.");
ERR_FAIL_INDEX_V_MSG(idx, 4, String(), "Couldn't get slider label.");
return labels[idx];
}
float ColorModeRAW::get_slider_max(int idx) const {
ERR_FAIL_INDEX_V_MSG(idx, 4, 0, "Couldn't get slider max value.");
ERR_FAIL_INDEX_V_MSG(idx, 5, 0, "Couldn't get slider max value.");
return slider_max[idx];
}
float ColorModeRAW::get_slider_value(int idx) const {
ERR_FAIL_INDEX_V_MSG(idx, 4, 0, "Couldn't get slider value.");
return color_picker->get_pick_color().components[idx];
ERR_FAIL_INDEX_V_MSG(idx, 5, 0, "Couldn't get slider value.");
Color color = color_picker->get_pick_color();
float intensity = MAX(1, MAX(MAX(color.r, color.g), color.b));
if (idx == 3) {
return Math::log2(intensity);
} else if (idx == 4) {
return color.a;
} else {
return color.components[idx] / intensity;
}
}
Color ColorModeRAW::get_color() const {
Vector<float> values = color_picker->get_active_slider_values();
Color color;
for (int i = 0; i < 4; i++) {
color.components[i] = values[i];
float intensity = Math::pow(2, values[3]);
for (int i = 0; i < 3; i++) {
color.components[i] = values[i] * intensity;
}
color.a = values[4];
return color;
}

View File

@ -105,11 +105,12 @@ public:
class ColorModeRAW : public ColorMode {
public:
String labels[3] = { "R", "G", "B" };
float slider_max[4] = { 100, 100, 100, 1 };
String labels[4] = { "R", "G", "B", "I" };
float slider_max[5] = { 1, 1, 1, 5, 1 };
virtual String get_name() const override { return "RAW"; }
virtual int get_slider_count() const override { return 4; }
virtual float get_slider_step() const override { return 0.001; }
virtual float get_spinbox_arrow_step() const override { return 0.01; }
virtual String get_slider_label(int idx) const override;

View File

@ -579,7 +579,7 @@ void ColorPicker::_reset_sliders_theme() {
}
void ColorPicker::_html_submitted(const String &p_html) {
if (updating || text_is_constructor || !c_text->is_visible()) {
if (updating || text_is_constructor || !c_text->is_editable()) {
return;
}
@ -717,7 +717,7 @@ void ColorPicker::_text_type_toggled() {
c_text->set_editable(true);
c_text->set_tooltip_text(ETR("Enter a hex code (\"#ff0000\") or named color (\"red\")."));
}
_update_color();
_update_text_value();
}
Color ColorPicker::get_pick_color() const {
@ -1047,25 +1047,36 @@ bool ColorPicker::is_deferred_mode() const {
}
void ColorPicker::_update_text_value() {
bool text_visible = true;
if (text_is_constructor) {
bool is_rgb_valid = color.r <= 1 && color.g <= 1 && color.b <= 1 && color.r >= 0 && color.g >= 0 && color.b >= 0;
if (text_is_constructor || !is_rgb_valid) {
String t = "Color(" + String::num(color.r, 3) + ", " + String::num(color.g, 3) + ", " + String::num(color.b, 3);
if (edit_alpha && color.a < 1) {
t += ", " + String::num(color.a, 3) + ")";
} else {
t += ")";
}
text_type->set_text("");
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
text_type->set_button_icon(get_editor_theme_icon(SNAME("Script")));
if (!is_rgb_valid) {
text_type->set_disabled(true);
}
}
#endif
c_text->set_text(t);
}
if (color.r > 1 || color.g > 1 || color.b > 1 || color.r < 0 || color.g < 0 || color.b < 0) {
text_visible = false;
} else if (!text_is_constructor) {
c_text->set_editable(false);
} else {
text_type->set_text("#");
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
text_type->set_button_icon(nullptr);
text_type->set_disabled(false);
}
#endif
c_text->set_text(color.to_html(edit_alpha && color.a < 1));
c_text->set_editable(true);
}
text_type->set_visible(text_visible);
c_text->set_visible(text_visible);
}
void ColorPicker::_sample_input(const Ref<InputEvent> &p_event) {