TButton


Croquet-Teapot

Comment:

TButton is an active frame that tracks user events to initiate actions. When the user's pointer is over a child frame of a TButton it is highlighted. When it is clicked, a message can be sent to a target. TButton can have two different child frames to show a boolean state.

Hierarchy:

ProtoObject
Object
TObject
TFrame
TGroup
TButton

Summary:

instance variables:

action action2 animateTime color deltaSpin doSpin enable frame frame2 local persist spin switch target target2

methods:

instance class
accessing action events initialize stepping
testing
accessing class initialization

Detail:

instance variables:

action
action2
animateTime
color
deltaSpin
doSpin
enable
frame
frame2
local
persist
spin
switch
target
target2

instance methods:

accessing
color: col

	color _ col.
	frame colorize: color.
	frame2 ifNotNil:[frame2 colorize: color.].
fadeDelay

	^2500.0  "2.5 seconds"
local:bool


	local _ bool.
persist


	^ persist.
spin: bool


	spin _ bool.
	doSpin _ 0.
switch


	^ switch.

action
disable

	persist ifFalse:[
		animateTime ifNil: [
			animateTime := self fadeDelta asFloat / self fadeDelay.
			self future: self fadeDelta deferRelative: 0.0 perform: #doFade.
		].
	].
doFade

	"reduce color alpha"
	| pct |
	animateTime ifNil: [^self].
	pct := color at: 4.
	pct := pct - animateTime.
	pct >= 0.0 ifTrue: [
		color at: 4 put: pct.
		self color: color.
		self future: self fadeDelta deferRelative: 0.0 perform: #doFade.
	] ifFalse: [
		frame solidVisibleTree: false. 
		frame2 ifNotNil:[frame2 solidVisibleTree: false.].
	].
	Croquet commit.
doSpin

	"spin the button"
	doSpin := doSpin + deltaSpin.
	doSpin <= -360 ifTrue: [doSpin := 0.].
	self rotationAroundY: doSpin.
	doSpin ~= 0 ifTrue: [ self future: self spinDelta deferRelative: 0.0 perform: #doSpin. ].
	Croquet commit.
enable


	self color: TButton overColor.
	switch ifNil:[ frame solidVisibleTree: true. ] ifNotNil:[
		frame solidVisibleTree: switch not.
		frame2 solidVisibleTree: switch.
		].
	animateTime _ nil.
fadeDelta

	^125.0 "1/8 second"
spinDelta

	^125.0 "1/8 second"
target2: trgt action2: act


	target2 _ trgt.
	action2 _ act.
target: trgt action: act


	target _ trgt.
	action _ act.

events
handlesPointerDown: pointer


	^ true.
handlesPointerOver: pointer


	^ true.
persist: bool


	persist _ bool.
	persist ifTrue:[ 	
		self color: TButton overColor.
		self enable.].
	persist ifFalse:[self disable.].
pointerDown: pointer
 

	self color: TButton downColor.
	frame2 ifNotNil:[
		switch ifNotNil:[
			frame solidVisibleTree: switch not.
			frame2 solidVisibleTree: switch.
			] ifNil:[
			frame solidVisibleTree: false.
			frame2 solidVisibleTree: true.
			].
		].
	^ true
pointerEnter: pointer


	self enable.
	self color: TButton hiliteColor.
	spin ifTrue:[
		deltaSpin _ -1.
		doSpin = 0 ifTrue: [self future: self spinDelta deferRelative: 0.0 perform: #doSpin.].
		].
	^ true.
pointerLeave: pointer
 

	self disable.
	persist ifTrue:[self color: TButton overColor.]
	ifFalse:[self color: TButton normColor.].
	spin ifTrue:[
		doSpin > -180 ifTrue:[
			deltaSpin _ deltaSpin negated.].
		].
	^ true
pointerMove: pointer


	pointer doSelect: true.
	(pointer pointerPickTree: self) ifTrue:[ 
		self color: TButton downColor.
		switch ifNotNil:[
			frame solidVisibleTree: switch.
			frame2 solidVisibleTree: switch not.
		] ifNil:[
			frame2 ifNotNil:[
				frame solidVisibleTree: false.
				frame2 solidVisibleTree: true. 
			].
		].
	] ifFalse:[ 
		self color: TButton hiliteColor. 
		switch ifNotNil:[
			frame solidVisibleTree: switch not.
			frame2 solidVisibleTree: switch.
		] ifNil:[
			frame2 ifNotNil:[
				frame solidVisibleTree: true.
				frame2 solidVisibleTree: false. 
			].
		].
	].
	pointer doSelect: false.
	^ true.
pointerOver: pointer


	^ true.
pointerUp: pointer

	| |
	pointer doSelect: true.
	pointer selectedDistance: Float infinity.
	(pointer pointerPickTree: self) ifTrue:[
		switch ifNotNil:[
			local ifFalse:[self switch: switch not.]
			ifTrue:[self switch: switch not.].
			switch ifTrue:[target ifNotNil:[ target perform: action with: pointer.].] 
			ifFalse:[
				target2 ifNotNil:[ target2 perform: action2 with: pointer.].].
		] 
		ifNil:[
			target ifNotNil:[ target perform: action with:pointer.].
			frame solidVisibleTree: true.
			frame2 ifNotNil:[ frame2 solidVisibleTree: false.].
			].
		] ifFalse:[
			switch ifNotNil:[
				frame solidVisibleTree: switch not.
				frame2 solidVisibleTree: switch.
			]ifNil:[
				frame solidVisibleTree: true.
				frame2 ifNotNil:[ frame2 solidVisibleTree: false.].
			].
		].
	pointer doSelect: false.
	persist ifTrue:[ self color: TButton overColor] ifFalse:[self color: TButton normColor].
	^ true.
switch: bool


	switch _ bool.
	(frame visibleTree or:[frame2 visibleTree])ifTrue:[
		frame solidVisibleTree: switch not.
		frame2 solidVisibleTree: switch.
	].

initialize
initializeSwitchWithFrame: fr frame2: fr2

	super initialize.
	frame _ fr.
	frame2 _ fr2.
	frame objectOwner: self.
	frame2 objectOwner: self.
	self addChild: frame.
	self addChild: frame2.
	self color: TButton normColor.
	persist _ false.
	frame solidVisibleTree: false.
	frame2 solidVisibleTree: false.
	animateTime _ nil.
	switch _ false.
	enable _ false.
	spin _ false.
	local _ false.
	^self
initializeWithFrame: fr

	super initialize.
	frame _ fr.
	frame ifNotNil:[ frame objectOwner: self.].
	self addChild: frame.
	self color: TButton normColor.
	persist _ false.
	frame solidVisibleTree: false.
	animateTime _ nil.
	enable _ false.
	switch _ nil.
	spin _ false.
	local _ false.
	^self
initializeWithFrame: fr frame2: fr2

	
	super initialize.
	frame _ fr.
	frame2 _ fr2.
	frame objectOwner: self.
	frame2 objectOwner: self.
	self addChild: frame.
	self addChild: frame2.
	self color: TButton normColor.
	persist _ false.
	frame solidVisibleTree: false.
	frame2 solidVisibleTree: false.
	animateTime _ nil.
	switch _ nil.
	enable _ false.
	spin _ false.
	local _ false.
	^self

testing
isComponent


	^ true.
isSolid


	^ false.

class methods:

accessing
downColor

	
	^ #(0.2 1.0 0.5 0.8) asFloatArray.
hiliteColor

	
	^ #(1.0 1.0 0.2 0.5) asFloatArray.
normColor

	
	^ #(0.5 0.7 0.7 0.5) asFloatArray.
overColor

	
	^ #(0.2 0.5 1.0 0.8) asFloatArray.

^top


- made by Dandelion -