@@ -796,53 +796,72 @@ class EditorPropertyLayersGrid : public Control {
796
796
return String ();
797
797
}
798
798
799
- void _gui_input (const Ref<InputEvent> &p_ev) {
800
- const Ref<InputEventMouseMotion> mm = p_ev;
801
- if (mm.is_valid ()) {
802
- bool expand_was_hovered = expand_hovered;
803
- expand_hovered = expand_rect.has_point (mm->get_position ());
804
- if (expand_hovered != expand_was_hovered) {
805
- update ();
806
- }
799
+ void _update_hovered (const Vector2 &p_position) {
800
+ bool expand_was_hovered = expand_hovered;
801
+ expand_hovered = expand_rect.has_point (p_position);
802
+ if (expand_hovered != expand_was_hovered) {
803
+ update ();
804
+ }
807
805
808
- if (!expand_hovered) {
809
- for (int i = 0 ; i < flag_rects.size (); i++) {
810
- if (flag_rects[i].has_point (mm->get_position ())) {
811
- // Used to highlight the hovered flag in the layers grid.
812
- hovered_index = i;
813
- update ();
814
- return ;
815
- }
806
+ if (!expand_hovered) {
807
+ for (int i = 0 ; i < flag_rects.size (); i++) {
808
+ if (flag_rects[i].has_point (p_position)) {
809
+ // Used to highlight the hovered flag in the layers grid.
810
+ hovered_index = i;
811
+ update ();
812
+ return ;
816
813
}
817
814
}
815
+ }
816
+
817
+ // Remove highlight when no square is hovered.
818
+ if (hovered_index != -1 ) {
819
+ hovered_index = -1 ;
820
+ update ();
821
+ }
822
+ }
823
+
824
+ void _on_hover_exit () {
825
+ if (expand_hovered) {
826
+ expand_hovered = false ;
827
+ update ();
828
+ }
829
+ if (hovered_index != -1 ) {
830
+ hovered_index = -1 ;
831
+ update ();
832
+ }
833
+ }
818
834
819
- // Remove highlight when no square is hovered.
820
- if (hovered_index != -1 ) {
821
- hovered_index = -1 ;
822
- update ();
835
+ void _update_flag () {
836
+ if (hovered_index >= 0 ) {
837
+ // Toggle the flag.
838
+ // We base our choice on the hovered flag, so that it always matches the hovered flag.
839
+ if (value & (1 << hovered_index)) {
840
+ value &= ~(1 << hovered_index);
841
+ } else {
842
+ value |= (1 << hovered_index);
823
843
}
824
844
845
+ emit_signal (" flag_changed" , value);
846
+ update ();
847
+ } else if (expand_hovered) {
848
+ expanded = !expanded;
849
+ minimum_size_changed ();
850
+ update ();
851
+ }
852
+ }
853
+
854
+ void _gui_input (const Ref<InputEvent> &p_ev) {
855
+ const Ref<InputEventMouseMotion> mm = p_ev;
856
+ if (mm.is_valid ()) {
857
+ _update_hovered (mm->get_position ());
825
858
return ;
826
859
}
827
860
828
861
const Ref<InputEventMouseButton> mb = p_ev;
829
862
if (mb.is_valid () && mb->get_button_index () == BUTTON_LEFT && mb->is_pressed ()) {
830
- if (hovered_index >= 0 ) {
831
- // Toggle the flag.
832
- // We base our choice on the hovered flag, so that it always matches the hovered flag.
833
- if (value & (1 << hovered_index)) {
834
- value &= ~(1 << hovered_index);
835
- } else {
836
- value |= (1 << hovered_index);
837
- }
838
-
839
- emit_signal (" flag_changed" , value);
840
- update ();
841
- } else if (expand_hovered) {
842
- expanded = !expanded;
843
- minimum_size_changed ();
844
- update ();
845
- }
863
+ _update_hovered (mb->get_position ());
864
+ _update_flag ();
846
865
}
847
866
}
848
867
@@ -974,14 +993,7 @@ class EditorPropertyLayersGrid : public Control {
974
993
} break ;
975
994
976
995
case NOTIFICATION_MOUSE_EXIT: {
977
- if (expand_hovered) {
978
- expand_hovered = false ;
979
- update ();
980
- }
981
- if (hovered_index != -1 ) {
982
- hovered_index = -1 ;
983
- update ();
984
- }
996
+ _on_hover_exit ();
985
997
} break ;
986
998
987
999
default :
0 commit comments