Merge pull request #77705 from MewPurPur/less-code-for-mouse-exit

Use NOTIFICATION_MOUSE_EXIT instead of a signal for a few editor plugins
This commit is contained in:
Rémi Verschelde 2023-06-01 15:52:12 +02:00
commit 42775ff75b
No known key found for this signature in database
GPG Key ID: C3336907360768E1
4 changed files with 12 additions and 22 deletions

View File

@ -51,12 +51,6 @@ CurveEdit::CurveEdit() {
set_clip_contents(true); set_clip_contents(true);
} }
void CurveEdit::_on_mouse_exited() {
hovered_index = -1;
hovered_tangent_index = TANGENT_NONE;
queue_redraw();
}
void CurveEdit::_bind_methods() { void CurveEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_selected_index", "index"), &CurveEdit::set_selected_index); ClassDB::bind_method(D_METHOD("set_selected_index", "index"), &CurveEdit::set_selected_index);
} }
@ -116,8 +110,12 @@ Size2 CurveEdit::get_minimum_size() const {
void CurveEdit::_notification(int p_what) { void CurveEdit::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_ENTER_TREE: { case NOTIFICATION_MOUSE_EXIT: {
connect("mouse_exited", callable_mp(this, &CurveEdit::_on_mouse_exited)); if (hovered_index != -1 || hovered_tangent_index != TANGENT_NONE) {
hovered_index = -1;
hovered_tangent_index = TANGENT_NONE;
queue_redraw();
}
} break; } break;
case NOTIFICATION_THEME_CHANGED: case NOTIFICATION_THEME_CHANGED:
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {

View File

@ -101,8 +101,6 @@ private:
Vector2 get_view_pos(Vector2 p_world_pos) const; Vector2 get_view_pos(Vector2 p_world_pos) const;
Vector2 get_world_pos(Vector2 p_view_pos) const; Vector2 get_world_pos(Vector2 p_view_pos) const;
void _on_mouse_exited();
void _redraw(); void _redraw();
private: private:

View File

@ -39,13 +39,6 @@
#include "scene/gui/flow_container.h" #include "scene/gui/flow_container.h"
#include "scene/gui/separator.h" #include "scene/gui/separator.h"
void GradientTexture2DEdit::_on_mouse_exited() {
if (hovered != HANDLE_NONE) {
hovered = HANDLE_NONE;
queue_redraw();
}
}
Point2 GradientTexture2DEdit::_get_handle_pos(const Handle p_handle) { Point2 GradientTexture2DEdit::_get_handle_pos(const Handle p_handle) {
// Get the handle's mouse position in pixels relative to offset. // Get the handle's mouse position in pixels relative to offset.
return (p_handle == HANDLE_FROM ? texture->get_fill_from() : texture->get_fill_to()).clamp(Vector2(), Vector2(1, 1)) * size; return (p_handle == HANDLE_FROM ? texture->get_fill_from() : texture->get_fill_to()).clamp(Vector2(), Vector2(1, 1)) * size;
@ -168,9 +161,12 @@ void GradientTexture2DEdit::set_snap_count(int p_snap_count) {
void GradientTexture2DEdit::_notification(int p_what) { void GradientTexture2DEdit::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_ENTER_TREE: case NOTIFICATION_MOUSE_EXIT: {
connect("mouse_exited", callable_mp(this, &GradientTexture2DEdit::_on_mouse_exited)); if (hovered != HANDLE_NONE) {
[[fallthrough]]; hovered = HANDLE_NONE;
queue_redraw();
}
} break;
case NOTIFICATION_THEME_CHANGED: { case NOTIFICATION_THEME_CHANGED: {
checkerboard->set_texture(get_theme_icon(SNAME("GuiMiniCheckerboard"), SNAME("EditorIcons"))); checkerboard->set_texture(get_theme_icon(SNAME("GuiMiniCheckerboard"), SNAME("EditorIcons")));
} break; } break;

View File

@ -66,8 +66,6 @@ class GradientTexture2DEdit : public Control {
virtual void gui_input(const Ref<InputEvent> &p_event) override; virtual void gui_input(const Ref<InputEvent> &p_event) override;
void _on_mouse_exited();
void _draw(); void _draw();
protected: protected: