Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
ClickCountingMorph
Last updated at 3:27 pm UTC on 30 June 2018
"A morph type used in the active essay Programming Morphs"
"A morph that counts the number of times it is clicked with the red and yellow mouse buttons."

Morph subclass: #ClickCountingMorph
	instanceVariableNames: 'redClicks yellowClicks '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'LearnMorphic'!
!ClickCountingMorph commentStamp: '<historical>' prior: 0!
A morph that counts the number of times it is clicked with the red and yellow mouse buttons.!



!ClickCountingMorph methodsFor: 'initialization' stamp: 'ls 6/12/2001 01:16'!

initialize
	super initialize.
	redClicks := 0.
	yellowClicks := 0.! !



!ClickCountingMorph methodsFor: 'drawing' stamp: 'ls 6/12/2001 01:18'!

drawOn: aCanvas
	aCanvas frameRectangle: self bounds width: 1 color: self color.
	aCanvas text: (redClicks printString, ' red') bounds: (self bounds translateBy: 3@3) font: nil color: self color.
	aCanvas text: (yellowClicks printString, ' yellow') bounds: (self bounds translateBy: 3@13) font: nil color: self color.
! !




!ClickCountingMorph methodsFor: 'event handling' stamp: 'ls 6/12/2001 01:22'!

handlesMouseDown: evt
	"we want to handle all mouse clicks"
	^true! !




!ClickCountingMorph methodsFor: 'event handling' stamp: 'ls 6/12/2001 01:21'!
mouseDown: evt
	"count a new mouse click"
	evt redButtonPressed ifTrue: [
		redClicks := redClicks + 1 ].

	evt yellowButtonChanged ifTrue: [
		yellowClicks := yellowClicks + 1 ].

	"note that our appearance has changed"
	self changed! !