events in morphic

Michael Rueger m.rueger at acm.org
Mon Jun 26 05:46:00 UTC 2000



Bert Freudenberg wrote:
> 
> On Sat, 24 Jun 2000 cole at griffoninc.com wrote:
> 
> > First can someone quickly tell me how to add a doublclick option to a
> > new morph.
> 
> Take a look at the DoubleClickExample morph.


Attached is an updated version of the DoubleClickExample which actually
uses the additional event handler entries for double click and drag.

Michael


-- 
 "To improve is to change, to be perfect is to change often." 
                                            Winston Churchill
+------------------------------------------------------------+
| Michael Rueger    m.rueger at acm.org      ++1 (310) 937 7196 |
+------------------------------------------------------------+
-------------- next part --------------
'From Squeak2.8 of 18 June 2000 [latest update: #2342] on 25 June 2000 at 4:07:56 pm'!
RectangleMorph subclass: #DoubleClickExample
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-Demo'!
!DoubleClickExample commentStamp: '<historical>' prior: 0!
Illustrates the double-click capabilities of Morphic.

If you have a kind of morph you wish to have respond specially to a double-click, it should:

(1)  Respond "true" to #handlesMouseDown:

(2)  In its mouseDown: method, send #waitForClicksOrDrag:event: to the hand.

(3)  Reimplement #click: to react to single-clicked mouse-down.

(4)  Reimplement #doubleClick: to make the appropriate response to a double-click.

(5)  Reimplement #drag: to react to non-clicks.  This message is sent continuously until the button is released.  You can check the event argument to react differently on the first, intermediate, and last calls.!


!DoubleClickExample methodsFor: 'initialization' stamp: 'mir 6/25/2000 16:07'!
initialize
	super initialize.
	self color: Color red.
	self
		on: #startDrag send: #startDrag: to: self;
		on: #doubleClick send: #doubleClick: to: self.
! !


!DoubleClickExample methodsFor: 'event handling' stamp: 'sw 9/28/1999 16:51'!
balloonText
	^ 
'Double-click on me to change my color; 
single-click on me to change border color;
hold mouse down within me to grow 
(if I''m red) or shrink (if I''m blue).'! !

!DoubleClickExample methodsFor: 'event handling' stamp: 'sw 9/28/1999 16:46'!
click: evt
	self showBalloon: 'click'.
	self borderColor: (self borderColor = Color black ifTrue: [Color yellow] ifFalse: [Color black])
! !

!DoubleClickExample methodsFor: 'event handling' stamp: 'bf 9/28/1999 20:55'!
doubleClick: evt
	self showBalloon: 'doubleClick'.
	self color: ((color = Color blue) ifTrue: [Color red] ifFalse: [Color blue])
! !

!DoubleClickExample methodsFor: 'event handling' stamp: 'mir 6/12/2000 17:53'!
startDrag: evt
	"We'll get a mouseDown first, some mouseMoves, and a mouseUp event last"
	| oldCenter |
	evt isMouseDown ifTrue:
		[self showBalloon: 'drag (mouse down)'.
		self world displayWorld.
		(Delay forMilliseconds: 750) wait].
	evt isMouseUp ifTrue:
		[self showBalloon: 'drag (mouse up)'].
	(evt isMouseUp or: [evt isMouseDown]) ifFalse:
		[self showBalloon: 'drag (mouse still down)'].
	(self containsPoint: evt cursorPoint)
		ifFalse: [^ self].

	oldCenter _ self center.
	color = Color red
		ifTrue:
			[self extent: self extent + (1 at 1)]
		ifFalse:
			[self extent: ((self extent - (1 at 1)) max: (16 at 16))].
	self center: oldCenter! !


More information about the Squeak-dev mailing list