[squeak-dev] Fwd: Which methods must I override to enable drag&drop?

Stéphane Rollandin lecteur at zogotounga.net
Tue Mar 28 08:11:12 UTC 2023


> Can someone answer this question on Stack Overflow?

It is not straightforward indeed; attached is a minimal implementation 
for a draggable morph - just my take on this.

	DMorph example "doIt"

The green morph can be dragged around freely, while still being owned by 
the blue one.


Stef
-------------- next part --------------
'From Squeak6.0 of 15 August 2022 [latest update: #22111] on 28 March 2023 at 10:05:26 am'!
Morph subclass: #DMorph
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-Example'!

!DMorph methodsFor: 'as yet unclassified' stamp: 'spfa 3/28/2023 10:03'!
handlesMouseDown: evt
	
	^ true! !

!DMorph methodsFor: 'as yet unclassified' stamp: 'spfa 3/28/2023 10:01'!
mouseDown: event

	self setProperty: #isBeingDragged toValue: true.
	self setProperty: #relativePosition toValue: (self position - self currentHand position).
	
	event hand 
		waitForClicksOrDrag: self 
		event: event 
		selectors: { nil. nil. nil. #startDrag: }
		threshold: HandMorph dragThreshold.! !

!DMorph methodsFor: 'as yet unclassified' stamp: 'spfa 3/28/2023 10:02'!
mouseMove: event

	(self hasProperty: #isBeingDragged) ifFalse: [^ self].
	self position: (self valueOfProperty: #relativePosition) + self currentHand position.! !

!DMorph methodsFor: 'as yet unclassified' stamp: 'spfa 3/28/2023 09:56'!
mouseUp: event

	self removeProperty: #isBeingDragged! !

!DMorph methodsFor: 'as yet unclassified' stamp: 'spfa 3/28/2023 10:01'!
startDrag: anItem with: anObject

! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

DMorph class
	instanceVariableNames: ''!

!DMorph class methodsFor: 'as yet unclassified' stamp: 'spfa 3/28/2023 10:05'!
example

	"DMorph example"

	| bigm |

	bigm := Morph new extent: 500 at 500.
	bigm addMorph: (self new color: Color green).
	bigm openInHand! !


More information about the Squeak-dev mailing list