[Q][Drag&Drop] Event handling, PolygonMorph, line drawing questions
Bob Arning
arning at charm.net
Mon Apr 24 04:10:16 UTC 2000
On Mon, 24 Apr 2000 04:47:23 +0200 Stephan Rudlof <sr at evolgo.de> wrote:
>I'm trying to use PolygonMorph (or a similar subclass) to visualize
>drag&drop operations.
>I want to have a line from the drag start point following the hand while
>dragging a Morph to the drop position.
Stephan,
Here is one possibility.
Cheers,
Bob
===== code snippet follows =====
'From Squeak2.8alpha of 13 January 2000 [latest update: #2005] on 24 April 2000 at 12:08:20 am'!
"Change Set: draglines
Date: 24 April 2000
Author: Bob Arning
A simple morph which, when picked up by the hand, draws a line between its original position and its current position"!
Morph subclass: #LineDrawingMorph
instanceVariableNames: 'positionWhenPickedUp myPolygon '
classVariableNames: ''
poolDictionaries: ''
category: 'Test-DragAndDrop'!
!LineDrawingMorph commentStamp: 'RAA 4/23/2000 23:41' prior: 0!
LineDrawingMorph allInstances do: [ :each | each delete].
(PolygonMorph allInstances select: [ :each | each vertices size = 2]) do: [ :each | each delete].
!
!LineDrawingMorph methodsFor: 'as yet unclassified' stamp: 'RAA 4/23/2000 23:38'!
aboutToBeGrabbedBy: aHand
myPolygon _ PolygonMorph
vertices: {self position. self bounds corner}
color: Color red
borderWidth: 1
borderColor: Color blue.
World addMorphFront: myPolygon.! !
!LineDrawingMorph methodsFor: 'as yet unclassified' stamp: 'RAA 4/24/2000 00:08'!
drawOn: aCanvas
myPolygon ifNil: [
^aCanvas fillRectangle: bounds color: Color green "or whatever it should look like"
].
myPolygon vertices at: 2 put: owner position.
myPolygon computeBounds.
! !
!LineDrawingMorph methodsFor: 'as yet unclassified' stamp: 'RAA 4/24/2000 00:05'!
hasTranslucentColor
"cause us to be redrawn by the hand rather than cached"
^true! !
!LineDrawingMorph methodsFor: 'as yet unclassified' stamp: 'RAA 4/24/2000 00:04'!
justDroppedInto: aMorph event: anEvent
myPolygon ifNotNil: [myPolygon delete. myPolygon _ nil].
self changed.! !
More information about the Squeak-dev
mailing list
|