|
@@ -394,17 +394,39 @@ void ColorPicker::_update_text_value() {
|
|
|
}
|
|
|
|
|
|
void ColorPicker::_sample_draw() {
|
|
|
- const Rect2 r = Rect2(Point2(), Size2(uv_edit->get_size().width, sample->get_size().height * 0.95));
|
|
|
+ // Covers the right half of the sample if the old color is being displayed,
|
|
|
+ // or the whole sample if it's not being displayed.
|
|
|
+ Rect2 rect_new;
|
|
|
+
|
|
|
+ if (display_old_color) {
|
|
|
+ rect_new = Rect2(Point2(uv_edit->get_size().width * 0.5, 0), Size2(uv_edit->get_size().width * 0.5, sample->get_size().height * 0.95));
|
|
|
+
|
|
|
+ // Draw both old and new colors for easier comparison (only if spawned from a ColorPickerButton).
|
|
|
+ const Rect2 rect_old = Rect2(Point2(), Size2(uv_edit->get_size().width * 0.5, sample->get_size().height * 0.95));
|
|
|
+
|
|
|
+ if (display_old_color && old_color.a < 1.0) {
|
|
|
+ sample->draw_texture_rect(get_icon("preset_bg", "ColorPicker"), rect_old, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ sample->draw_rect(rect_old, old_color);
|
|
|
+
|
|
|
+ if (old_color.r > 1 || old_color.g > 1 || old_color.b > 1) {
|
|
|
+ // Draw an indicator to denote that the old color is "overbright" and can't be displayed accurately in the preview.
|
|
|
+ sample->draw_texture(get_icon("overbright_indicator", "ColorPicker"), Point2());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ rect_new = Rect2(Point2(), Size2(uv_edit->get_size().width, sample->get_size().height * 0.95));
|
|
|
+ }
|
|
|
|
|
|
if (color.a < 1.0) {
|
|
|
- sample->draw_texture_rect(get_icon("preset_bg", "ColorPicker"), r, true);
|
|
|
+ sample->draw_texture_rect(get_icon("preset_bg", "ColorPicker"), rect_new, true);
|
|
|
}
|
|
|
|
|
|
- sample->draw_rect(r, color);
|
|
|
+ sample->draw_rect(rect_new, color);
|
|
|
|
|
|
if (color.r > 1 || color.g > 1 || color.b > 1) {
|
|
|
- // Draw an indicator to denote that the color is "overbright" and can't be displayed accurately in the preview
|
|
|
- sample->draw_texture(get_icon("overbright_indicator", "ColorPicker"), Point2());
|
|
|
+ // Draw an indicator to denote that the new color is "overbright" and can't be displayed accurately in the preview
|
|
|
+ sample->draw_texture(get_icon("overbright_indicator", "ColorPicker"), Point2(uv_edit->get_size().width * 0.5, 0));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -886,6 +908,13 @@ ColorPicker::ColorPicker() :
|
|
|
|
|
|
/////////////////
|
|
|
|
|
|
+void ColorPickerButton::_about_to_show() {
|
|
|
+ set_pressed(true);
|
|
|
+ if (picker) {
|
|
|
+ picker->set_old_color(color);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void ColorPickerButton::_color_changed(const Color &p_color) {
|
|
|
color = p_color;
|
|
|
update();
|
|
@@ -943,6 +972,18 @@ Color ColorPickerButton::get_pick_color() const {
|
|
|
return color;
|
|
|
}
|
|
|
|
|
|
+void ColorPicker::set_old_color(const Color &p_color) {
|
|
|
+ old_color = p_color;
|
|
|
+}
|
|
|
+
|
|
|
+void ColorPicker::set_display_old_color(bool p_enabled) {
|
|
|
+ display_old_color = p_enabled;
|
|
|
+}
|
|
|
+
|
|
|
+bool ColorPicker::is_displaying_old_color() const {
|
|
|
+ return display_old_color;
|
|
|
+}
|
|
|
+
|
|
|
void ColorPickerButton::set_edit_alpha(bool p_show) {
|
|
|
edit_alpha = p_show;
|
|
|
if (picker) {
|
|
@@ -972,10 +1013,11 @@ void ColorPickerButton::_update_picker() {
|
|
|
add_child(popup);
|
|
|
picker->connect("color_changed", this, "_color_changed");
|
|
|
popup->connect("modal_closed", this, "_modal_closed");
|
|
|
- popup->connect("about_to_show", this, "set_pressed", varray(true));
|
|
|
+ popup->connect("about_to_show", this, "_about_to_show");
|
|
|
popup->connect("popup_hide", this, "set_pressed", varray(false));
|
|
|
picker->set_pick_color(color);
|
|
|
picker->set_edit_alpha(edit_alpha);
|
|
|
+ picker->set_display_old_color(true);
|
|
|
emit_signal("picker_created");
|
|
|
}
|
|
|
}
|
|
@@ -987,6 +1029,7 @@ void ColorPickerButton::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("get_popup"), &ColorPickerButton::get_popup);
|
|
|
ClassDB::bind_method(D_METHOD("set_edit_alpha", "show"), &ColorPickerButton::set_edit_alpha);
|
|
|
ClassDB::bind_method(D_METHOD("is_editing_alpha"), &ColorPickerButton::is_editing_alpha);
|
|
|
+ ClassDB::bind_method(D_METHOD("_about_to_show"), &ColorPickerButton::_about_to_show);
|
|
|
ClassDB::bind_method(D_METHOD("_color_changed"), &ColorPickerButton::_color_changed);
|
|
|
ClassDB::bind_method(D_METHOD("_modal_closed"), &ColorPickerButton::_modal_closed);
|
|
|
|