Skip to content

Commit

Permalink
Merge pull request #682 from pharo-graphics/MouseProcessor
Browse files Browse the repository at this point in the history
Mouse processor: Fix test and clean up code
  • Loading branch information
tinchodias authored Feb 5, 2025
2 parents 8d97b4d + b8be0b6 commit ddebcbf
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 160 deletions.
171 changes: 82 additions & 89 deletions src/Bloc-Examples/BlEventCountingElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -255,110 +255,103 @@ BlEventCountingElement >> initialize [
blurCount := 0.
positionInSpaceChangedCount := 0.

self addEventHandler: (BlEventHandler
self addEventHandler:
(BlEventHandler
on: BlClickEvent
do: [ :anEvent |
anEvent consume.
anEvent currentTarget incrementClickCount ]).
do: [ :anEvent | anEvent currentTarget incrementClickCount ]).

self addEventHandler: (BlEventHandler
self addEventHandler:
(BlEventHandler
on: BlMouseEnterEvent
do: [ :anEvent |
anEvent consume.
anEvent currentTarget incrementMouseEnterCount ]).
do: [ :anEvent | anEvent currentTarget incrementMouseEnterCount ]).

self addEventHandler: (BlEventHandler
self addEventHandler:
(BlEventHandler
on: BlMouseLeaveEvent
do: [ :anEvent |
anEvent consume.
anEvent currentTarget incrementMouseLeaveCount ]).
do: [ :anEvent | anEvent currentTarget incrementMouseLeaveCount ]).

self addEventHandler: (BlEventHandler
self addEventHandler:
(BlEventHandler
on: BlMouseMoveEvent
do: [ :anEvent |
anEvent consume.
anEvent currentTarget incrementMouseMoveCount ]).
do: [ :anEvent | anEvent currentTarget incrementMouseMoveCount ]).

self addEventHandler: (BlEventHandler
self addEventHandler:
(BlEventHandler
on: BlMouseOverEvent
do: [ :anEvent |
anEvent consume.
anEvent currentTarget incrementMouseOverCount ]).
do: [ :anEvent | anEvent currentTarget incrementMouseOverCount ]).

self addEventHandler: (BlEventHandler
self addEventHandler:
(BlEventHandler
on: BlMouseOutEvent
do: [ :anEvent |
anEvent consume.
anEvent currentTarget incrementMouseOutCount ]).
do: [ :anEvent | anEvent currentTarget incrementMouseOutCount ]).

self addEventHandler: (BlEventHandler
self addEventHandler:
(BlEventHandler
on: BlMouseDownEvent
do: [ :anEvent |
anEvent consume.
anEvent currentTarget incrementMouseDownCount ]).
do: [ :anEvent | anEvent currentTarget incrementMouseDownCount ]).

self addEventHandler: (BlEventHandler
self addEventHandler:
(BlEventHandler
on: BlMouseUpEvent
do: [ :anEvent |
anEvent consume.
anEvent currentTarget incrementMouseUpCount ]).

self addEventHandler: (BlEventHandler
on: BlDragStartEvent
do: [ :anEvent |
anEvent consume.
anEvent currentTarget incrementDragStartCount ]).

self addEventHandler: (BlEventHandler
on: BlDragEvent
do: [ :anEvent |
anEvent consume.
anEvent currentTarget incrementDragCount ]).

self addEventHandler: (BlEventHandler
on: BlDragEndEvent
do: [ :anEvent |
anEvent consume.
anEvent currentTarget incrementDragEndCount ]).

self addEventHandler: (BlEventHandler
on: BlDragEnterEvent
do: [ :anEvent |
anEvent consume.
anEvent currentTarget incrementDragEnterCount ]).

self addEventHandler: (BlEventHandler
on: BlDragLeaveEvent
do: [ :anEvent |
anEvent consume.
anEvent currentTarget incrementDragLeaveCount ]).

self addEventHandler: (BlEventHandler
on: BlDropEvent
do: [ :anEvent |
anEvent consume.
anEvent currentTarget incrementDropCount ]).

self addEventHandler: (BlEventHandler
on: BlFocusInEvent
do: [ :anEvent | anEvent currentTarget incrementFocusInCount ]).

self addEventHandler: (BlEventHandler
on: BlFocusOutEvent
do: [ :anEvent | anEvent currentTarget incrementFocusOutCount ]).

self addEventHandler: (BlEventHandler
on: BlFocusEvent
do: [ :anEvent | anEvent currentTarget incrementFocusCount ]).

self addEventHandler: (BlEventHandler
on: BlBlurEvent
do: [ :anEvent | anEvent currentTarget incrementBlurCount ]).

self addEventHandler: (BlEventHandler
on: BlElementPositionInSpaceChangedEvent
do: [ :anEvent |
anEvent currentTarget incrementPositionInSpaceChangedCount ]).
do: [ :anEvent | anEvent currentTarget incrementMouseUpCount ]).

self addEventHandler:
(BlEventHandler
on: BlDragStartEvent
do: [ :anEvent |
anEvent consume. "Need to consume this event to proceed"
anEvent currentTarget incrementDragStartCount ]).

self addEventHandler:
(BlEventHandler
on: BlDragEvent
do: [ :anEvent | anEvent currentTarget incrementDragCount ]).

self addEventHandler:
(BlEventHandler
on: BlDragEndEvent
do: [ :anEvent | anEvent currentTarget incrementDragEndCount ]).

self addEventHandler:
(BlEventHandler
on: BlDragEnterEvent
do: [ :anEvent | anEvent currentTarget incrementDragEnterCount ]).

self addEventHandler:
(BlEventHandler
on: BlDragLeaveEvent
do: [ :anEvent | anEvent currentTarget incrementDragLeaveCount ]).

self addEventHandler:
(BlEventHandler
on: BlDropEvent
do: [ :anEvent | anEvent currentTarget incrementDropCount ]).

self addEventHandler:
(BlEventHandler
on: BlFocusInEvent
do: [ :anEvent | anEvent currentTarget incrementFocusInCount ]).

self addEventHandler:
(BlEventHandler
on: BlFocusOutEvent
do: [ :anEvent | anEvent currentTarget incrementFocusOutCount ]).

self addEventHandler:
(BlEventHandler
on: BlFocusEvent
do: [ :anEvent | anEvent currentTarget incrementFocusCount ]).

self addEventHandler:
(BlEventHandler
on: BlBlurEvent
do: [ :anEvent | anEvent currentTarget incrementBlurCount ]).

self addEventHandler:
(BlEventHandler
on: BlElementPositionInSpaceChangedEvent
do: [ :anEvent |
anEvent currentTarget incrementPositionInSpaceChangedCount ]).

self background: Color veryVeryLightGray
]
Expand Down
60 changes: 30 additions & 30 deletions src/Bloc-Examples/BlMouseProcessorClickTest.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Class {
#name : #BlMouseProcessorClickTest,
#superclass : #TestCase,
#instVars : [
'scripter'
],
#category : #'Bloc-Examples-Event-Scripter'
}

Expand All @@ -13,13 +16,20 @@ BlMouseProcessorClickTest >> newScripterElement [
yourself
]

{ #category : #running }
BlMouseProcessorClickTest >> setUp [

super setUp.

scripter := BlDevScripter new.
scripter element: self newScripterElement
]

{ #category : #tests }
BlMouseProcessorClickTest >> testClick [

| aScripter |
aScripter := self testMouseEnter.

aScripter substeps: 'Click' do: [ :aStep |
scripter substeps: 'Click' do: [ :aStep |
aStep mouseMove by: 70 @ 60. "enter"
aStep mouseDown.
aStep mouseUp.

Expand All @@ -38,80 +48,70 @@ BlMouseProcessorClickTest >> testClick [
aStep check
label: 'Check last click event has correct target';
satisfies: [ :aMouseProcessor |
aMouseProcessor lastClickEvent target = aScripter element ];
aMouseProcessor lastClickEvent target = scripter element ];
onMouseProcessor.

aStep check
label: 'Check element was clicked';
satisfies: [ :anElement | anElement clickCount = 1 ];
onSelf ].
aScripter syncContinue.

^ aScripter
scripter syncPlay
]

{ #category : #tests }
BlMouseProcessorClickTest >> testMouseDown [

| aScripter |
aScripter := self testMouseEnter.

aScripter substeps: 'Click' do: [ :aStep |
scripter substeps: 'Click' do: [ :aStep |
aStep mouseMove by: 70 @ 60. "enter"
aStep mouseDown.

aStep check
label: 'Check previous mouse down event';
value: [ :aMouseProcessor |
aMouseProcessor lastMouseDownEvent target ]
equals: [ aScripter element ];
equals: [ scripter element ];
onMouseProcessor.

aStep check
label: 'Check last over target is the element';
value: [ :aMouseProcessor | aMouseProcessor lastOverTarget ]
equals: [ aScripter element ];
equals: [ scripter element ];
onMouseProcessor.

aStep check
label: 'Check entered targets';
value: [ :aMouseProcessor | aMouseProcessor enteredTargets ]
equals: [
{
aScripter element.
aScripter root } ];
scripter element.
scripter root } ];
onMouseProcessor ].

^ aScripter syncContinue
scripter syncPlay
]

{ #category : #tests }
BlMouseProcessorClickTest >> testMouseEnter [

| aScripter |
aScripter := BlDevScripter new.
aScripter element: self newScripterElement.

aScripter substeps: 'Mouse Enter' do: [ :aStep |
aStep mouseMove by: 30 @ 30.

aStep mouseMove by: 70 @ 60.
scripter substeps: 'Mouse Enter' do: [ :aStep |
aStep mouseMove by: 30 @ 30. "outside"
aStep mouseMove by: 70 @ 60. "inside"

aStep check
label: 'Check last over target is the element';
value: [ :aMouseProcessor | aMouseProcessor lastOverTarget ]
equals: [ aScripter element ];
equals: [ scripter element ];
onMouseProcessor.

aStep check
label: 'Check entered targets';
value: [ :aMouseProcessor | aMouseProcessor enteredTargets ]
equals: [
{
aScripter element.
aScripter root } ];
scripter element.
scripter root } ];
onMouseProcessor ].

aScripter syncContinue.

^ aScripter
scripter syncPlay
]
6 changes: 3 additions & 3 deletions src/Bloc-Tests/BlMouseProcessorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ BlMouseProcessorTest >> secondaryMouseUpEvent [
]

{ #category : #running }
BlMouseProcessorTest >> setUp [
BlMouseProcessorTest >> setUp [

super setUp.
mouseProcessor := BlMouseProcessor space: BlSpace new.
mouseProcessor := BlMouseProcessor space: BlSpace new
]

{ #category : #tests }
Expand Down Expand Up @@ -120,7 +120,7 @@ BlMouseProcessorTest >> testMouseProcessorInitializedEmptyAndWithCorrectSpace [
aMouseProcessor := BlMouseProcessor space: aSpace.

self assert: aMouseProcessor space equals: aSpace.
self assert: aMouseProcessor pressedButtons isEmpty.
self assert: aMouseProcessor pressedButtons isEmpty
]

{ #category : #tests }
Expand Down
Loading

0 comments on commit ddebcbf

Please sign in to comment.