Skip to content

Commit

Permalink
Adds basic mouse and drop event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeAtHPI committed Dec 4, 2023
1 parent 0adb935 commit 07e07d9
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 45 deletions.
4 changes: 2 additions & 2 deletions packages/Sandblocks-Babylonian/SBExampleGridsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ SBExampleGridsView >> buildExampleFor: aNumber [
]

{ #category : #updating }
SBExampleGridsView >> gridObjects [
SBExampleGridsView >> gridSize [

^ self multiverse activeExamples
^ self multiverse activeExamples size
]

{ #category : #initialization }
Expand Down
4 changes: 2 additions & 2 deletions packages/Sandblocks-Babylonian/SBGridResultsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SBGridResultsView >> clean [
]

{ #category : #updating }
SBGridResultsView >> gridObjects [
SBGridResultsView >> gridSize [

self subclassResponsibility
]
Expand Down Expand Up @@ -50,7 +50,7 @@ SBGridResultsView >> newGridContainer [
SBGridResultsView >> updateContainerWidth [

gridContainer width:
self gridObjects size safeSquareRoot ceiling
self gridSize safeSquareRoot ceiling
* (gridContainer lastSubmorph fullBounds width
+ (2 * gridContainer cellInset)
+ (2 * gridContainer cellGap)
Expand Down
99 changes: 81 additions & 18 deletions packages/Sandblocks-Babylonian/SBInputBroadcaster.class.st
Original file line number Diff line number Diff line change
@@ -1,17 +1,61 @@
Class {
#name : #SBInputBroadcaster,
#superclass : #Morph,
#superclass : #SBBlock,
#instVars : [
'listeners'
'listeners',
'mice',
'miceContainers'
],
#category : #'Sandblocks-Babylonian'
}

{ #category : #input }
SBInputBroadcaster >> absorbsInput: anEvent [

^ true
]

{ #category : #accessing }
SBInputBroadcaster >> addListener: aMorph [

self listeners add: aMorph.
self mice add: CircleMorph newPin.

"adding mice as our own morphs will cause rattling"
self containers add: (Morph new
color: Color transparent;
extent: aMorph extent).
self containers last addMorph: aMorph.
self containers last addMorph: mice last.

^ self containers last

]

{ #category : #accessing }
SBInputBroadcaster >> containers [

^ miceContainers
]

{ #category : #events }
SBInputBroadcaster >> filterEvent: anEvent for: aMorph [

self flag: #todo. "Die Position im Morph in den listener transformieren"
self listeners do: [:aListener | aListener processEvent: (anEvent copy position: aListener position)].
self listeners withIndexDo: [:aListener :i | | targetPosition newEvent |
targetPosition := self translatedPositionOf: anEvent from: aMorph to: aListener.
newEvent := anEvent copy.

anEvent isDropEvent
ifTrue: [newEvent translateTo: targetPosition]
ifFalse: [newEvent translateBy: targetPosition - anEvent position].

aListener processEvent: newEvent.
(self mice at: i) position: targetPosition.

(aListener containsPoint: targetPosition)
ifTrue: [(self mice at: i) show]
ifFalse: [(self mice at: i) hide]].

^ anEvent
]

Expand All @@ -20,7 +64,7 @@ SBInputBroadcaster >> handleMouseOver: anEvent [

super handleMouseOver: anEvent.
anEvent hand newKeyboardFocus: self.

self sandblockEditor selectNoInput: self.
]

{ #category : #'event handling' }
Expand All @@ -36,20 +80,15 @@ SBInputBroadcaster >> initialize [
super initialize.

listeners := OrderedCollection new.
mice := OrderedCollection new.
miceContainers := OrderedCollection new.

self
addEventCaptureFilter: self;
addKeyboardCaptureFilter: self;
"addMouseCaptureFilter: self;"
extent: 300@200;
color: Color veryLightGray;
changeTableLayout;
listDirection: #topToBottom;
wrapCentering: #center;
listCentering: #center;
addMorph: (StringMorph new
contents: 'Enter Input here';
color: Color white;
yourself)
addMouseCaptureFilter: self;
canDrag: false;
color: Color veryLightGray

]

Expand All @@ -60,7 +99,31 @@ SBInputBroadcaster >> listeners [
]

{ #category : #accessing }
SBInputBroadcaster >> listeners: aCollectionOfMorphs [
SBInputBroadcaster >> mice [

^ mice
]

{ #category : #'events-processing' }
SBInputBroadcaster >> mouseEnter: anEvent [

super mouseEnter: anEvent.
anEvent hand newKeyboardFocus: self.
]

listeners := aCollectionOfMorphs.
{ #category : #events }
SBInputBroadcaster >> translatedPositionOf: anEvent from: anOriginMorph to: aTargetMorph [

| localAbsPoint localRelPoint targetAbsPoint |
localAbsPoint := anEvent position - anOriginMorph position.
localRelPoint := localAbsPoint / anOriginMorph extent.
targetAbsPoint := (localRelPoint * aTargetMorph extent) + aTargetMorph position.

^ targetAbsPoint rounded
]

{ #category : #'event handling' }
SBInputBroadcaster >> wantsKeyboardFocus [

^ true
]
55 changes: 34 additions & 21 deletions packages/Sandblocks-Babylonian/SBLiveView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,36 @@ Class {
#category : #'Sandblocks-Babylonian'
}

{ #category : #'as yet unclassified' }
{ #category : #building }
SBLiveView >> buildAllPossibleResults [

self multiverse universes do: [:aUniverse | self buildPreviewFor: aUniverse activePermutation]
]

{ #category : #'as yet unclassified' }
{ #category : #building }
SBLiveView >> buildBrodcaster [

self block addMorphBack: (SBRow new
gridContainer addMorphBack: (self containerRow cellPositioning: #center;
addAllMorphsBack: {
self containerRow listDirection: #topToBottom;
addAllMorphsBack: {
SBOwnTextMorph new contents: 'Event Broadcaster'.
broadcaster := SBInputBroadcaster new}.
LineMorph from: 0@0 to: 0@50 color: Color black width: 2}).

"gridContainer addMorphBack: (SBRow new
changeTableLayout;
hResizing: #spaceFill;
wrapCentering: #center;
listCentering: #center;
cellPositioning: #center;
addMorph: (broadcaster := SBInputBroadcaster new))
addMorph: (broadcaster := SBInputBroadcaster new))"

self updateContainerWidth.

]

{ #category : #'as yet unclassified' }
{ #category : #building }
SBLiveView >> buildPreviewFor: aPermutation [

gridContainer addMorphBack: (self containerRow cellPositioning: #center;
Expand All @@ -40,7 +51,7 @@ SBLiveView >> buildPreviewFor: aPermutation [
self updateContainerWidth.
]

{ #category : #'as yet unclassified' }
{ #category : #building }
SBLiveView >> buildSetUpRow [

self block addMorph: (SBRow new
Expand All @@ -54,27 +65,27 @@ SBLiveView >> buildSetUpRow [
balloonText: 'Toggle stepping';
on: #click send: #toggleStepping to: self);
addMorphBack: (SBStringMorph new contents: 'Setup:');
addMorphBack: (([Morph new] asSandblock statements first) width: 200))
addMorphBack: ([Morph new] asSandblock width: 200))
]

{ #category : #'as yet unclassified' }
{ #category : #actions }
SBLiveView >> clean [

self block submorphs allButFirst copy do: #delete.

gridContainer := self newGridContainer.
]

{ #category : #'as yet unclassified' }
{ #category : #actions }
SBLiveView >> evaluateSetUp [

^ self setUpMorph evaluate
^ self setUpMorph evaluate value
]

{ #category : #'as yet unclassified' }
SBLiveView >> gridObjects [
{ #category : #updating }
SBLiveView >> gridSize [

^ self multiverse universes
^ self multiverse universes size + 1
]

{ #category : #initialization }
Expand All @@ -86,40 +97,40 @@ SBLiveView >> initialize [
self buildSetUpRow.
]

{ #category : #'as yet unclassified' }
{ #category : #accessing }
SBLiveView >> listeners [

^ broadcaster listeners
]

{ #category : #'as yet unclassified' }
{ #category : #initialization }
SBLiveView >> newRegisteredListenerFor: aPermutation [

| listener |
| listener container |
listener := self evaluateSetUp.
broadcaster listeners add: listener.
container := broadcaster addListener: listener.

listener allMorphsDo: [:aSubMorph |
SBExploriants objectToPermutation at: aSubMorph put: aPermutation].

^ listener
^ container

]

{ #category : #'as yet unclassified' }
{ #category : #accessing }
SBLiveView >> setUpMorph [

^ self block firstSubmorph "setup row" lastSubmorph
]

{ #category : #'as yet unclassified' }
{ #category : #actions }
SBLiveView >> toggleStepping [

self listeners do: [:aMorph |
aMorph isStepping ifFalse: [aMorph startStepping] ifTrue: [aMorph stopStepping]]
]

{ #category : #'as yet unclassified' }
{ #category : #actions }
SBLiveView >> visualize [

self clean.
Expand All @@ -128,4 +139,6 @@ SBLiveView >> visualize [
self block addMorphBack: self updateButton.
self block addMorphBack: gridContainer.
self buildAllPossibleResults.

broadcaster extent: self listeners last extent.
]
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ SBPermutationGridsView >> buildPermutationFor: aSBUniverse [
]

{ #category : #updating }
SBPermutationGridsView >> gridObjects [
SBPermutationGridsView >> gridSize [

^ self multiverse universes
^ self multiverse universes size
]

{ #category : #initialization }
Expand Down

0 comments on commit 07e07d9

Please sign in to comment.