diff options
author | Mariano Suligoy <marianognu.easyrpg@gmail.com> | 2017-06-18 17:16:54 -0300 |
---|---|---|
committer | Mariano Suligoy <desarrollo@hnader.com.ar> | 2017-06-19 09:23:57 -0300 |
commit | f5185e7ba67a2c09db64e03b3fcd85add7e5dea8 (patch) | |
tree | a12db0c1815b5a1fbb01dcabc9d7cab22e36d5aa | |
parent | 33bf180067eb0beb1a514adcdfb6a59cc5f4ac55 (diff) |
Fix ColorPicker's screen pick functionality
-rw-r--r-- | editor/property_editor.cpp | 3 | ||||
-rw-r--r-- | scene/gui/color_picker.cpp | 38 | ||||
-rw-r--r-- | scene/gui/color_picker.h | 1 |
3 files changed, 23 insertions, 19 deletions
diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 3d3fecc8f9..da26c84e45 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -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 ); }*/ } + if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST) { + hide(); + } } void CustomPropertyEditor::_menu_option(int p_which) { diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index bc1b16bea8..ee6af21dbd 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -48,7 +48,15 @@ void ColorPicker::_notification(int p_what) { btn_pick->set_icon(get_icon("screen_picker", "ColorPicker")); _update_color(); - } + } break; + + case MainLoop::NOTIFICATION_WM_QUIT_REQUEST: { + if (screen != NULL) { + if (screen->is_visible()) { + screen->hide(); + } + } + } break; } } @@ -84,9 +92,6 @@ void ColorPicker::set_pick_color(const Color &p_color) { if (!is_inside_tree()) 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(); } @@ -427,19 +432,12 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &ev) { Viewport *r = get_tree()->get_root(); if (!r->get_visible_rect().has_point(Point2(mev->get_global_position().x, mev->get_global_position().y))) return; - Ref<Image> img; //= r->get_screen_capture(); - if (!img.is_null()) { - last_capture = img; - //r->queue_screen_capture(); - } - if (last_capture.is_valid() && !last_capture->empty()) { - 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); - + Ref<Image> img = r->get_texture()->get_data(); + if (img.is_valid() && !img->empty()) { + img->lock(); + 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); + img->unlock(); set_pick_color(c); } } @@ -456,11 +454,11 @@ void ColorPicker::_screen_pick_pressed() { r->add_child(screen); screen->set_as_toplevel(true); screen->set_area_as_parent_rect(); + screen->set_default_cursor_shape(CURSOR_POINTING_HAND); screen->connect("gui_input", this, "_screen_input"); } screen->raise(); screen->show_modal(); - // r->queue_screen_capture(); } void ColorPicker::_bind_methods() { @@ -632,6 +630,10 @@ void ColorPickerButton::_notification(int p_what) { Ref<StyleBox> normal = get_stylebox("normal"); 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) { diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index ca47c3a5f4..de624fd029 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -47,7 +47,6 @@ class ColorPicker : public BoxContainer { private: Control *screen; - Ref<Image> last_capture; Control *uv_edit; Control *w_edit; TextureRect *sample; |