mirror of
https://github.com/Redot-Engine/redot-engine.git
synced 2025-12-06 07:17:42 -05:00
Merge pull request #101546 from bruvzg/portal_color_picker
[Linux] Implement native color picker.
This commit is contained in:
@@ -61,7 +61,10 @@ void ColorPicker::_notification(int p_what) {
|
||||
|
||||
case NOTIFICATION_READY: {
|
||||
// FIXME: The embedding check is needed to fix a bug in single-window mode (GH-93718).
|
||||
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_SCREEN_CAPTURE) && !get_tree()->get_root()->is_embedding_subwindows()) {
|
||||
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_COLOR_PICKER)) {
|
||||
btn_pick->set_tooltip_text(ETR("Pick a color from the screen."));
|
||||
btn_pick->connect(SceneStringName(pressed), callable_mp(this, &ColorPicker::_pick_button_pressed_native));
|
||||
} else if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_SCREEN_CAPTURE) && !get_tree()->get_root()->is_embedding_subwindows()) {
|
||||
btn_pick->set_tooltip_text(ETR("Pick a color from the screen."));
|
||||
btn_pick->connect(SceneStringName(pressed), callable_mp(this, &ColorPicker::_pick_button_pressed));
|
||||
} else {
|
||||
@@ -2098,6 +2101,26 @@ void ColorPicker::_add_preset_pressed() {
|
||||
emit_signal(SNAME("preset_added"), color);
|
||||
}
|
||||
|
||||
void ColorPicker::_pick_button_pressed_native() {
|
||||
if (!DisplayServer::get_singleton()->color_picker(callable_mp(this, &ColorPicker::_native_cb))) {
|
||||
// Fallback to default/legacy picker.
|
||||
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_SCREEN_CAPTURE) && !get_tree()->get_root()->is_embedding_subwindows()) {
|
||||
_pick_button_pressed();
|
||||
} else {
|
||||
_pick_button_pressed_legacy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ColorPicker::_native_cb(bool p_status, const Color &p_color) {
|
||||
if (p_status) {
|
||||
set_pick_color(p_color);
|
||||
if (!deferred_mode_enabled) {
|
||||
emit_signal(SNAME("color_changed"), color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ColorPicker::_pick_button_pressed() {
|
||||
is_picking_color = true;
|
||||
pre_picking_color = color;
|
||||
|
||||
Reference in New Issue
Block a user