@@ -68,7 +68,13 @@ class TakeFocus is TargetedEvent { }
6868
6969# | An event that occurs at a particular screen location
7070class LocalizedEvent is Event {
71- method overlaps-widget ($ widget --> Bool : D ) { ... }
71+ # Calculations relative to widget as a whole
72+ method overlaps-widget ($ widget --> Bool : D ) { ... }
73+ method relative-to ($ widget ) { ... }
74+
75+ # Calculations relative to widget's content area
76+ method overlaps-content-area ($ widget --> Bool : D ) { ... }
77+ method relative-to-content-area ($ widget ) { ... }
7278}
7379
7480
@@ -89,7 +95,25 @@ class MouseEvent is LocalizedEvent {
8995 my $ rel-x = $ . mouse . x - 1 - $ widget . x-offset;
9096 my $ rel-y = $ . mouse . y - 1 - $ widget . y-offset;
9197
92- ($ rel-x , $ rel-y )
98+ ($ rel-x , $ rel-y , $ widget . w , $ widget . h)
99+ }
100+
101+ # | Determine whether this mouse event overlapped a particular widget
102+ method overlaps-content-area ($ widget --> Bool : D ) {
103+ my $ rect = $ widget . content-rect;
104+ my $ rel-x = $ . mouse . x - 1 - $ widget . x-offset - $ rect [0 ];
105+ my $ rel-y = $ . mouse . y - 1 - $ widget . y-offset - $ rect [1 ];
106+
107+ 0 <= $ rel-x < $ rect [2 ] && 0 <= $ rel-y < $ rect [3 ]
108+ }
109+
110+ # | Compute coordinates relative to a given widget's local origin
111+ method relative-to-content-area ($ widget ) {
112+ my $ rect = $ widget . content-rect;
113+ my $ rel-x = $ . mouse . x - 1 - $ widget . x-offset - $ rect [0 ];
114+ my $ rel-y = $ . mouse . y - 1 - $ widget . y-offset - $ rect [1 ];
115+
116+ ($ rel-x , $ rel-y , $ rect [2 ], $ rect [3 ])
93117 }
94118}
95119
0 commit comments