Merge pull request #9256 from MarianoGnu/master
Fix ColorPicker's screen pick functionality
This commit is contained in:
commit
8928509f09
|
@ -65,6 +65,9 @@ void CustomPropertyEditor::_notification(int p_what) {
|
||||||
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2( 10,10,60, get_size().height-20 ), v );
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2( 10,10,60, get_size().height-20 ), v );
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST) {
|
||||||
|
hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomPropertyEditor::_menu_option(int p_which) {
|
void CustomPropertyEditor::_menu_option(int p_which) {
|
||||||
|
|
|
@ -48,8 +48,16 @@ void ColorPicker::_notification(int p_what) {
|
||||||
btn_pick->set_icon(get_icon("screen_picker", "ColorPicker"));
|
btn_pick->set_icon(get_icon("screen_picker", "ColorPicker"));
|
||||||
|
|
||||||
_update_color();
|
_update_color();
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case MainLoop::NOTIFICATION_WM_QUIT_REQUEST: {
|
||||||
|
if (screen != NULL) {
|
||||||
|
if (screen->is_visible()) {
|
||||||
|
screen->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorPicker::set_focus_on_line_edit() {
|
void ColorPicker::set_focus_on_line_edit() {
|
||||||
|
@ -84,9 +92,6 @@ void ColorPicker::set_pick_color(const Color &p_color) {
|
||||||
if (!is_inside_tree())
|
if (!is_inside_tree())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
return; //it crashes, so returning
|
|
||||||
uv_edit->get_child(0)->cast_to<Control>()->update();
|
|
||||||
w_edit->get_child(0)->cast_to<Control>()->update();
|
|
||||||
_update_color();
|
_update_color();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,19 +432,12 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &ev) {
|
||||||
Viewport *r = get_tree()->get_root();
|
Viewport *r = get_tree()->get_root();
|
||||||
if (!r->get_visible_rect().has_point(Point2(mev->get_global_position().x, mev->get_global_position().y)))
|
if (!r->get_visible_rect().has_point(Point2(mev->get_global_position().x, mev->get_global_position().y)))
|
||||||
return;
|
return;
|
||||||
Ref<Image> img; //= r->get_screen_capture();
|
Ref<Image> img = r->get_texture()->get_data();
|
||||||
if (!img.is_null()) {
|
if (img.is_valid() && !img->empty()) {
|
||||||
last_capture = img;
|
img->lock();
|
||||||
//r->queue_screen_capture();
|
Vector2 ofs = mev->get_global_position() - r->get_visible_rect().get_position();
|
||||||
}
|
Color c = img->get_pixel(ofs.x, r->get_visible_rect().size.height - ofs.y);
|
||||||
if (last_capture.is_valid() && !last_capture->empty()) {
|
img->unlock();
|
||||||
int pw = last_capture->get_format() == Image::FORMAT_RGBA8 ? 4 : 3;
|
|
||||||
int ofs = (mev->get_global_position().y * last_capture->get_width() + mev->get_global_position().x) * pw;
|
|
||||||
|
|
||||||
PoolVector<uint8_t>::Read r = last_capture->get_data().read();
|
|
||||||
|
|
||||||
Color c(r[ofs + 0] / 255.0, r[ofs + 1] / 255.0, r[ofs + 2] / 255.0);
|
|
||||||
|
|
||||||
set_pick_color(c);
|
set_pick_color(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -456,11 +454,11 @@ void ColorPicker::_screen_pick_pressed() {
|
||||||
r->add_child(screen);
|
r->add_child(screen);
|
||||||
screen->set_as_toplevel(true);
|
screen->set_as_toplevel(true);
|
||||||
screen->set_area_as_parent_rect();
|
screen->set_area_as_parent_rect();
|
||||||
|
screen->set_default_cursor_shape(CURSOR_POINTING_HAND);
|
||||||
screen->connect("gui_input", this, "_screen_input");
|
screen->connect("gui_input", this, "_screen_input");
|
||||||
}
|
}
|
||||||
screen->raise();
|
screen->raise();
|
||||||
screen->show_modal();
|
screen->show_modal();
|
||||||
// r->queue_screen_capture();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorPicker::_bind_methods() {
|
void ColorPicker::_bind_methods() {
|
||||||
|
@ -632,6 +630,10 @@ void ColorPickerButton::_notification(int p_what) {
|
||||||
Ref<StyleBox> normal = get_stylebox("normal");
|
Ref<StyleBox> normal = get_stylebox("normal");
|
||||||
draw_rect(Rect2(normal->get_offset(), get_size() - normal->get_minimum_size()), picker->get_pick_color());
|
draw_rect(Rect2(normal->get_offset(), get_size() - normal->get_minimum_size()), picker->get_pick_color());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST) {
|
||||||
|
popup->hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorPickerButton::set_pick_color(const Color &p_color) {
|
void ColorPickerButton::set_pick_color(const Color &p_color) {
|
||||||
|
|
|
@ -47,7 +47,6 @@ class ColorPicker : public BoxContainer {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Control *screen;
|
Control *screen;
|
||||||
Ref<Image> last_capture;
|
|
||||||
Control *uv_edit;
|
Control *uv_edit;
|
||||||
Control *w_edit;
|
Control *w_edit;
|
||||||
TextureRect *sample;
|
TextureRect *sample;
|
||||||
|
|
Loading…
Reference in New Issue