mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Forward color picker preview mouse button events to the window underneath.
This commit is contained in:
parent
568d6286e0
commit
09822ea1a9
2 changed files with 31 additions and 3 deletions
|
|
@ -1695,6 +1695,7 @@ void ColorPicker::_add_preset_pressed() {
|
||||||
|
|
||||||
void ColorPicker::_pick_button_pressed() {
|
void ColorPicker::_pick_button_pressed() {
|
||||||
is_picking_color = true;
|
is_picking_color = true;
|
||||||
|
pre_picking_color = color;
|
||||||
|
|
||||||
if (!picker_window) {
|
if (!picker_window) {
|
||||||
picker_window = memnew(Popup);
|
picker_window = memnew(Popup);
|
||||||
|
|
@ -1748,10 +1749,35 @@ void ColorPicker::_pick_button_pressed() {
|
||||||
|
|
||||||
void ColorPicker::_target_gui_input(const Ref<InputEvent> &p_event) {
|
void ColorPicker::_target_gui_input(const Ref<InputEvent> &p_event) {
|
||||||
const Ref<InputEventMouseButton> mouse_event = p_event;
|
const Ref<InputEventMouseButton> mouse_event = p_event;
|
||||||
if (mouse_event.is_valid() && mouse_event->is_pressed()) {
|
if (mouse_event.is_null()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mouse_event->get_button_index() == MouseButton::LEFT) {
|
||||||
|
if (mouse_event->is_pressed()) {
|
||||||
picker_window->hide();
|
picker_window->hide();
|
||||||
_pick_finished();
|
_pick_finished();
|
||||||
}
|
}
|
||||||
|
} else if (mouse_event->get_button_index() == MouseButton::RIGHT) {
|
||||||
|
set_pick_color(pre_picking_color); // Cancel.
|
||||||
|
is_picking_color = false;
|
||||||
|
set_process_internal(false);
|
||||||
|
picker_window->hide();
|
||||||
|
} else {
|
||||||
|
Window *w = picker_window->get_parent_visible_window();
|
||||||
|
while (w) {
|
||||||
|
Point2i win_mpos = w->get_mouse_position(); // Mouse position local to the window.
|
||||||
|
Size2i win_size = w->get_size();
|
||||||
|
if (win_mpos.x >= 0 && win_mpos.y >= 0 && win_mpos.x <= win_size.x && win_mpos.y <= win_size.y) {
|
||||||
|
// Mouse event inside window bounds, forward this event to the window.
|
||||||
|
Ref<InputEventMouseButton> new_ev = p_event->duplicate();
|
||||||
|
new_ev->set_position(win_mpos);
|
||||||
|
new_ev->set_global_position(win_mpos);
|
||||||
|
w->push_input(new_ev, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
w = w->get_parent_visible_window();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorPicker::_pick_finished() {
|
void ColorPicker::_pick_finished() {
|
||||||
|
|
@ -1760,7 +1786,7 @@ void ColorPicker::_pick_finished() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input::get_singleton()->is_action_just_pressed(SNAME("ui_cancel"))) {
|
if (Input::get_singleton()->is_action_just_pressed(SNAME("ui_cancel"))) {
|
||||||
set_pick_color(old_color);
|
set_pick_color(pre_picking_color);
|
||||||
} else {
|
} else {
|
||||||
emit_signal(SNAME("color_changed"), color);
|
emit_signal(SNAME("color_changed"), color);
|
||||||
}
|
}
|
||||||
|
|
@ -1856,6 +1882,7 @@ void ColorPicker::_pick_button_pressed_legacy() {
|
||||||
if (!is_inside_tree()) {
|
if (!is_inside_tree()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
pre_picking_color = color;
|
||||||
|
|
||||||
if (!picker_window) {
|
if (!picker_window) {
|
||||||
picker_window = memnew(Popup);
|
picker_window = memnew(Popup);
|
||||||
|
|
|
||||||
|
|
@ -211,6 +211,7 @@ private:
|
||||||
|
|
||||||
Color color;
|
Color color;
|
||||||
Color old_color;
|
Color old_color;
|
||||||
|
Color pre_picking_color;
|
||||||
bool is_picking_color = false;
|
bool is_picking_color = false;
|
||||||
|
|
||||||
bool display_old_color = false;
|
bool display_old_color = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue