[Newbies] Re: Constrained Morph dragging

Sebastian Nozzi sebnozzi at gmail.com
Sun Nov 18 13:29:06 UTC 2012

I came up with this... does what I need and I have  no visual
artifacts anymore. Still, I'm not happy for having to override a
private method in order for this to work... :-/

Overridden existing method in my Morph subclass:

privateFullMoveBy: delta
	super privateFullMoveBy: delta.
	(self wantsToConstrainDragging & self isBeingDragged)
		ifTrue: [ self adjustPositionWhileDragging ]

New methods in my Morph subclass:

	^ self owner isHandMorph
	^ true	

	self position: (self constrainedDragPositionFrom: (self topLeft))
constrainedDragPositionFrom: aNonConstrainedPosition
	"Adjust the position to be constrained however you want. In this case
horizontally at y=450"
	^ (aNonConstrainedPosition x) @ 450.

You would need to override only "wantsToConstrainDragging" and

Any critique to the code and/or naming welcome! :-)



More information about the Beginners mailing list