Skip to content

Commit

Permalink
+BlDirectEventDispatcher>>hasEventFilterSuchThat: (the same for event…
Browse files Browse the repository at this point in the history
… handlers already exists - hasEventHandlerSuchThat: )

+BlElement>>allowMousePickOutsideEvent, preventMousePickOutsideEvent and shouldHandleMousePickOutsideEvent to help manage MousePickOutsideEvent
  • Loading branch information
plantec committed Oct 20, 2023
1 parent 9c1f600 commit ac7368b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
11 changes: 11 additions & 0 deletions src/Bloc/BlDirectEventDispatcher.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ BlDirectEventDispatcher >> handlersDo: aBlock [
handlers ifNotNil: [ :aRegistry | aRegistry handlers do: aBlock ]
]

{ #category : 'api - accessing' }
BlDirectEventDispatcher >> hasEventFilterSuchThat: aBlock [
<return: #Boolean>

self filtersDo: [ :eachfilter |
(aBlock value: eachfilter)
ifTrue: [ ^ true ] ].

^ false
]

{ #category : 'api - testing' }
BlDirectEventDispatcher >> hasFilter: anEventHandler [
^ filters
Expand Down
30 changes: 26 additions & 4 deletions src/Bloc/BlElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ BlElement >> allowMouseEvents [
flags addShouldHandleMouseEvents.
]

{ #category : 'event handling' }
BlElement >> allowMousePickOutsideEvent [

self userData at: #shouldHandleMousePickOutsideEvent put: true
]

{ #category : 'layout' }
BlElement >> applyLayoutIn: aBlBounds [

Expand Down Expand Up @@ -1412,12 +1418,16 @@ BlElement >> dispatchMousePickedOutside: aMouseOutsideEvent [
I am recursively dispatched top-down through the scene graph and the whole composition tree of the elements"

aMouseOutsideEvent isConsumed ifTrue: [ ^ self ].
aMouseOutsideEvent lastMouseDownEvent ifNotNil: [ :downEvent |
downEvent target = self ifTrue: [ ^ self ] ].
self children do: [ :aChildElement |
aChildElement dispatchMousePickedOutside: aMouseOutsideEvent clone].
aChildElement dispatchMousePickedOutside: aMouseOutsideEvent clone ].
" Am I allowed to manage mouse pick outside ?"
self shouldHandleMousePickOutsideEvent ifFalse: [ ^ self ].
" does my bounds contains the event position, if so, the picked point is inside myself "
(self containsGlobalPoint: aMouseOutsideEvent originalEvent position) ifTrue: [ ^ self ].
self dispatchEvent: aMouseOutsideEvent.

(self containsGlobalPoint: aMouseOutsideEvent originalEvent position)
ifTrue: [ ^ self ].
self dispatchEvent: aMouseOutsideEvent
]

{ #category : 'children dispatching' }
Expand Down Expand Up @@ -3279,6 +3289,12 @@ BlElement >> preventMouseEvents [
flags clearShouldHandleMouseEvents.
]

{ #category : 'event handling' }
BlElement >> preventMousePickOutsideEvent [

self userData at: #shouldHandleMousePickOutsideEvent put: false
]

{ #category : 'children accessing' }
BlElement >> previousSiblingDo: aBlock [
"Evaluate aBlock with the previous child in my parent before me if there is one"
Expand Down Expand Up @@ -3740,6 +3756,12 @@ BlElement >> shouldHandleMouseEvents [
^ flags hasShouldHandleMouseEvents
]

{ #category : 'event handling' }
BlElement >> shouldHandleMousePickOutsideEvent [

^ self userData at: #shouldHandleMousePickOutsideEvent ifAbsentPut: [ false ]
]

{ #category : 'api - opening' }
BlElement >> showSpace: aSpace [
self hasParent
Expand Down
15 changes: 14 additions & 1 deletion src/Bloc/BlMousePickOutsideEvent.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Class {
#name : 'BlMousePickOutsideEvent',
#superclass : 'BlElementEvent',
#instVars : [
'originalEvent'
'originalEvent',
'lastMouseDownEvent'
],
#category : 'Bloc-Events-Type-Element',
#package : 'Bloc',
Expand Down Expand Up @@ -33,6 +34,18 @@ BlMousePickOutsideEvent >> asMouseOutsideEvent [
^ self
]

{ #category : 'accessing' }
BlMousePickOutsideEvent >> lastMouseDownEvent [

^ lastMouseDownEvent
]

{ #category : 'accessing' }
BlMousePickOutsideEvent >> lastMouseDownEvent: aBlEvent [

lastMouseDownEvent := aBlEvent
]

{ #category : 'accessing' }
BlMousePickOutsideEvent >> originalEvent [

Expand Down
4 changes: 2 additions & 2 deletions src/Bloc/BlSpace.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1095,10 +1095,10 @@ BlSpace >> findMousePickTargetFromEvent: anEvent [
:found | " test found because if the result is the root then it means that no element has been found "
found ~~ self root ifTrue: [ " ok, dispatch outside event through all the space elements "
" dispatch the mouse outside event to all alements of the scene graph "
self dispatchMousePickedOutside: (anEvent newCopyFor: found) asMouseOutsideEvent.
self dispatchMousePickedOutside: ((anEvent newCopyFor: found) asMouseOutsideEvent lastMouseDownEvent: self mouseProcessor lastMouseDownEvent; yourself).
^ found ] ].
" no element found at all: all elements receive a outside event"
self dispatchMousePickedOutside: anEvent clone asMouseOutsideEvent.
self dispatchMousePickedOutside: (anEvent clone asMouseOutsideEvent lastMouseDownEvent: self mouseProcessor lastMouseDownEvent; yourself).
^ nil
]

Expand Down

0 comments on commit ac7368b

Please sign in to comment.