'From Cuis 6.0 [latest update: #5096] on 4 April 2022 at 3:11:06 pm'!
!classDefinition: #PluggableButtonMorph category: 'Morphic-Widgets'!
PluggableMorph subclass: #PluggableButtonMorph
	instanceVariableNames: 'label font icon stateSelector enableSelector actionSelector isPressed mouseIsOver magnifiedIcon actWhen roundButtonStyle iconName secondaryActionSelector stateSelectorArgument mouseOverColor'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-Widgets'!

!PluggableButtonMorph methodsFor: 'accessing' stamp: 'jmv 4/4/2022 14:51:37'!
magnifiedIcon: aForm
	icon _ nil.
	magnifiedIcon _ aForm! !

!PluggableButtonMorph methodsFor: 'accessing' stamp: 'jmv 4/4/2022 15:09:44'!
mouseOverColor: aColor
	"If set, ignore #adoptWidgetsColor: "

	mouseOverColor _ aColor! !

!PluggableButtonMorph methodsFor: 'initialization' stamp: 'jmv 4/4/2022 14:20:33'!
defaultBorderColor
	"answer the default border color/fill style for the receiver"
	^ nil! !

!PluggableButtonMorph methodsFor: 'initialization' stamp: 'jmv 4/4/2022 14:39:39'!
model: anObject stateGetter: getStateSel stateGetterArgument: getStateArg action: actionSel label: aString

	stateSelector _ getStateSel.
	stateSelectorArgument _ getStateArg.
	actionSelector _ actionSel.
	self model: anObject.
	self label: aString! !

!PluggableButtonMorph methodsFor: 'initialization' stamp: 'jmv 4/4/2022 14:40:45'!
stateGetterArgument: getStateArg

	stateSelectorArgument _ getStateArg.! !


!PluggableButtonMorph class methodsFor: 'instance creation' stamp: 'jmv 4/4/2022 14:40:10'!
model: anObject stateGetter: getStateSel stateGetterArgument: getStateArg action: actionSel label: aString
	^ self new
		model: anObject
		stateGetter: getStateSel
		stateGetterArgument: getStateArg
		action: actionSel
		label: aString! !


!PluggableButtonMorph methodsFor: 'accessing' stamp: 'jmv 4/4/2022 15:09:55'!
adoptWidgetsColor: paneColor
	super adoptWidgetsColor: paneColor.
	mouseOverColor ifNil: [
		self color: (Theme current buttonColorFrom: paneColor) ]! !

!PluggableButtonMorph methodsFor: 'drawing' stamp: 'jmv 4/4/2022 15:04:03'!
draw3DLookOn: aCanvas

	| borderStyleSymbol c |
	borderStyleSymbol _ self isPressed ifFalse: [ #raised ] ifTrue: [ #inset ].
	c _ color.
	self mouseIsOver | self isPressed ifTrue: [
		c _ mouseOverColor ifNil: [ c lighter ]].
	c _ self enableColorWith: c.
	aCanvas
		fillRectangle: self morphLocalBounds
		color: c
		borderWidth: borderWidth
		borderStyleSymbol: borderStyleSymbol
		baseColorForBorder: (borderColor ifNil: [ c ]).

	self drawRegularLabelOn: aCanvas! !

!PluggableButtonMorph methodsFor: 'drawing' stamp: 'jmv 4/4/2022 15:08:49'!
drawRoundLookOn: aCanvas
	| r colorForButton rect |
	colorForButton _ self isPressed
		ifFalse: [
			self mouseIsOver
				ifTrue: [	 mouseOverColor ifNil: [ Color h: color hue s: color saturation * 1.3 v: color brightness * 0.9 ]]
				ifFalse: [ color ]]
		ifTrue: [ mouseOverColor ifNil: [ color adjustSaturation: 0.1 brightness: -0.1 ]].

	colorForButton ifNotNil: [
		r _ Theme current roundedButtonRadius.
		rect _ self morphLocalBounds insetBy: `3@3`.
		r _ r min: (rect width min: rect height) * 0.5.
		aCanvas roundRect: rect color: (self enableColorWith: colorForButton) radius: r ].

	Theme current embossedButtonLabels
		ifTrue: [ self drawEmbossedLabelOn: aCanvas ]
		ifFalse: [ self drawRegularLabelOn: aCanvas ].! !

!PluggableButtonMorph methodsFor: 'private' stamp: 'jmv 4/4/2022 14:38:41'!
getState
	"Answer the result of sending the receiver's model the stateSelector message."

	^ stateSelector 
		ifNil: [false]
		ifNotNil: [
			stateSelectorArgument
				ifNil: [	model perform: stateSelector]
				ifNotNil: [	model perform: stateSelector with: stateSelectorArgument]]! !

!PluggableButtonMorph methodsFor: 'private' stamp: 'jmv 4/4/2022 14:52:00'!
magnifiedIcon
	| factor magnifiedExtent w h |

	magnifiedIcon ifNotNil: [ ^magnifiedIcon ].
	icon ifNil: [ ^nil ].
	magnifiedIcon ifNil: [
		magnifiedIcon _ icon.
		w _ icon width.
		h _ icon height.
		w*h = 0 ifFalse: [
			factor _ 1.0 * extent x / w min: 1.0 * extent y / h.
			factor = 1.0 ifFalse: [
				magnifiedExtent _ (icon extent * factor) rounded.
				magnifiedIcon _ icon magnifyTo: magnifiedExtent ]]].
	^magnifiedIcon! !

!PluggableButtonMorph methodsFor: 'geometry' stamp: 'jmv 4/4/2022 14:52:16'!
extentChanged: oldExtent
	"Our extent changed. Must layout submorphs again."

	super extentChanged: oldExtent.
	icon ifNotNil: [
		magnifiedIcon _ nil ]! !

!classDefinition: #PluggableButtonMorph category: 'Morphic-Widgets'!
PluggableMorph subclass: #PluggableButtonMorph
	instanceVariableNames: 'label font icon stateSelector enableSelector actionSelector isPressed mouseIsOver magnifiedIcon actWhen roundButtonStyle iconName secondaryActionSelector stateSelectorArgument mouseOverColor'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-Widgets'!
