Skip to content

Commit

Permalink
inactive buttons get greyed out
Browse files Browse the repository at this point in the history
  • Loading branch information
RedToxyl committed Jun 25, 2024
1 parent 9e5541a commit afc8749
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 61 deletions.
74 changes: 67 additions & 7 deletions source/GM-TE/GMTEEditor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Class {
'inspector',
'morphBuilders',
'backgroundTile',
'tileMap'
'tileMap',
'associatedMorph'
],
#category : #'GM-TE-UI'
}
Expand Down Expand Up @@ -105,6 +106,15 @@ GMTEEditor class >> register [
TheWorldMenu registerOpenCommand: {'TileMap Editor'. {GMTEEditor. #new}}
]

{
#category : #constants,
#'squeak_changestamp' : 'TW 6/25/2024 15:53'
}
GMTEEditor class >> singleLayerActionNames [

^ {'buttonMoveLayerDown' . 'buttonMoveLayerUp' . 'buttonRenameLayer'}
]

{
#category : #constants,
#'squeak_changestamp' : 'jj 6/23/2024 17:33'
Expand Down Expand Up @@ -172,6 +182,24 @@ GMTEEditor >> anyLayerSelected [
^ (self selectedLayers size > 0)
]

{
#category : #accessing,
#'squeak_changestamp' : 'TW 6/25/2024 15:55'
}
GMTEEditor >> associatedMorph [

^ associatedMorph
]

{
#category : #accessing,
#'squeak_changestamp' : 'TW 6/25/2024 15:55'
}
GMTEEditor >> associatedMorph: anObject [

associatedMorph := anObject.
]

{
#category : #accessing,
#'squeak_changestamp' : 'jj 6/22/2024 21:51'
Expand Down Expand Up @@ -215,7 +243,7 @@ GMTEEditor >> blendSelectedLayers [

{
#category : #building,
#'squeak_changestamp' : 'jj 6/23/2024 17:29'
#'squeak_changestamp' : 'TW 6/25/2024 15:56'
}
GMTEEditor >> buildWith: builder [
"builds the editor with ToolBuilder"
Expand Down Expand Up @@ -262,7 +290,9 @@ GMTEEditor >> buildWith: builder [
borderWidth: 2;
borderColor: tileStore borderColor.

self initializeDefaultTileMapMatrix.
self
initializeDefaultTileMapMatrix;
associatedMorph: newMorph.

^ newMorph
]
Expand Down Expand Up @@ -430,7 +460,7 @@ GMTEEditor >> createInspectorSpecWithBuilder: aBuilder [

{
#category : #building,
#'squeak_changestamp' : 'jj 6/23/2024 23:48'
#'squeak_changestamp' : 'TW 6/25/2024 15:50'
}
GMTEEditor >> createLayersSpecWithBuilder: aBuilder [
"creates the spec for layer viewer"
Expand All @@ -448,55 +478,63 @@ GMTEEditor >> createLayersSpecWithBuilder: aBuilder [
(aBuilder pluggableImageButtonSpec new)
model:self;
action: #addLayer;
name: 'buttonAddLayer';
frame: (LayoutFrame fractions: (0 @ 0 corner: 1 @ 0.125));
project: 'GameMecha';
path: '/GMTEIcons/add.png'.

(aBuilder pluggableImageButtonSpec new)
model:self;
action: #moveLayerDown;
name: 'buttonMoveLayerDown';
frame: (LayoutFrame fractions: (0 @ 0.125 corner: 1 @ 0.25));
project: 'GameMecha';
path: '/GMTEIcons/up.png'.

(aBuilder pluggableImageButtonSpec new)
model:self;
action: #moveLayerUp;
name: 'buttonMoveLayerUp';
frame: (LayoutFrame fractions: (0 @ 0.25 corner: 1 @ 0.375));
project: 'GameMecha';
path: '/GMTEIcons/down.png'.

(aBuilder pluggableImageButtonSpec new)
model: self;
action: #renameLayer;
name: 'buttonRenameLayer';
frame: (LayoutFrame fractions: (0 @ 0.375 corner: 1 @ 0.5));
project: 'GameMecha';
path: '/GMTEIcons/rename.png'.

(aBuilder pluggableImageButtonSpec new)
model:self;
action:#resetSelectedLayers;
name: 'buttonResetLayers';
frame: (LayoutFrame fractions: (0 @ 0.5 corner: 1 @ 0.625));
project: 'GameMecha';
path: '/GMTEIcons/broom.png'.

(aBuilder pluggableImageButtonSpec new)
model:self;
action: #blendSelectedLayers;
name: 'buttonBlendLayers';
frame: (LayoutFrame fractions: (0 @ 0.625 corner: 1 @ 0.75));
project: 'GameMecha';
path: '/GMTEIcons/merge.png'.

(aBuilder pluggableImageButtonSpec new)
model:self;
action: #deleteSelectedLayers;
name: 'buttonDeleteLayers';
frame: (LayoutFrame fractions: (0 @ 0.75 corner: 1 @ 0.875));
project: 'GameMecha';
path: '/GMTEIcons/trash.png'.

(aBuilder pluggableImageButtonSpec new)
model:self;
action: #toggleSelectedLayerVisibility;
name: 'buttonToggleVisibilityLayers';
frame: (LayoutFrame fractions: (0 @ 0.875 corner: 1 @ 1));
project: 'GameMecha';
path: '/GMTEIcons/eye.png'}.
Expand Down Expand Up @@ -626,7 +664,7 @@ GMTEEditor >> deselectAllLayers [

{
#category : #accessing,
#'squeak_changestamp' : 'jj 6/22/2024 20:47'
#'squeak_changestamp' : 'TW 6/25/2024 16:02'
}
GMTEEditor >> deselectLayer: anIndex [
"deletes the layer with the provided index"
Expand All @@ -636,6 +674,7 @@ GMTEEditor >> deselectLayer: anIndex [
(self selectedLayers includes: anIndex)
ifTrue: [
self selectedLayers remove: anIndex.
self singleLayerSelected ifTrue: [self enableSingleLayerButtons].
self
changed: #selectedLayers;
changed: #layerAt:]
Expand All @@ -654,6 +693,24 @@ GMTEEditor >> deselectTile [
self tileMap tileSelectionSet highlightImage: nil
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'TW 6/25/2024 15:57'
}
GMTEEditor >> disableSingleLayerButtons [

GMTEEditor singleLayerActionNames do: [:aString | (self associatedMorph submorphNamed: aString) enabled: false ]
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'TW 6/25/2024 15:57'
}
GMTEEditor >> enableSingleLayerButtons [

GMTEEditor singleLayerActionNames do: [:aString | (self associatedMorph submorphNamed: aString) enabled: true ]
]

{
#category : #'menu button functions',
#'squeak_changestamp' : 'jj 6/22/2024 20:48'
Expand Down Expand Up @@ -894,7 +951,7 @@ GMTEEditor >> importMenu [

{
#category : #initialization,
#'squeak_changestamp' : 'TW 6/23/2024 20:14'
#'squeak_changestamp' : 'TW 6/25/2024 15:45'
}
GMTEEditor >> initialize [
"starts the tile editor"
Expand Down Expand Up @@ -1309,12 +1366,15 @@ GMTEEditor >> selectAllLayers [

{
#category : #accessing,
#'squeak_changestamp' : 'jj 6/22/2024 21:33'
#'squeak_changestamp' : 'TW 6/25/2024 17:01'
}
GMTEEditor >> selectLayer: anIndex [
"select the layer with anIndex"

self selectedLayers add: anIndex.
self singleLayerSelected
ifTrue: [self enableSingleLayerButtons]
ifFalse: [self disableSingleLayerButtons].
self
changed: #selectedLayers;
changed: #layerAt:
Expand Down
78 changes: 55 additions & 23 deletions source/GM-TE/GMTEImageButton.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Class {
'actionSelector',
'arguments',
'linkedButtons',
'stateSprites'
'stateSprites',
'enabled'
],
#category : #'GM-TE-UI',
#'squeak_changestamp' : '<historical>'
Expand Down Expand Up @@ -55,6 +56,15 @@ GMTEImageButton >> arguments: aCollection [
arguments := aCollection asArray copy
]

{
#category : #accessing,
#'squeak_changestamp' : 'TW 6/25/2024 15:28'
}
GMTEImageButton >> basicEnabled: anObject [

enabled := anObject
]

{
#category : #accessing,
#'squeak_changestamp' : 'jj 6/22/2024 16:48'
Expand Down Expand Up @@ -102,6 +112,31 @@ GMTEImageButton >> dyeSprite: anImage with: aColor [
yourself
]

{
#category : #accessing,
#'squeak_changestamp' : 'TW 6/25/2024 15:23'
}
GMTEImageButton >> enabled [

^ enabled
]

{
#category : #accessing,
#'squeak_changestamp' : 'TW 6/25/2024 15:33'
}
GMTEImageButton >> enabled: aBoolean [

aBoolean
ifTrue: [
self basicEnabled: true.
self setImageMode: 'unpressed']
ifFalse: [
self basicEnabled: false.
self setImageMode: 'disabled']

]

{
#category : #'event handling',
#'squeak_changestamp' : 'jj 6/22/2024 16:48'
Expand Down Expand Up @@ -131,7 +166,7 @@ GMTEImageButton >> handlesMouseOver: anEvent [

{
#category : #initialization,
#'squeak_changestamp' : 'TW 6/22/2024 01:13'
#'squeak_changestamp' : 'TW 6/25/2024 15:39'
}
GMTEImageButton >> initialize [

Expand Down Expand Up @@ -160,10 +195,12 @@ GMTEImageButton >> linkedButtons: aCollection [

{
#category : #'event handling',
#'squeak_changestamp' : 'jj 6/22/2024 16:49'
#'squeak_changestamp' : 'TW 6/25/2024 15:42'
}
GMTEImageButton >> mouseDown: anEvent [

self enabled ifFalse: [^ nil].

super mouseDown: anEvent.
anEvent yellowButtonPressed ifTrue: [^ self].

Expand All @@ -172,28 +209,34 @@ GMTEImageButton >> mouseDown: anEvent [

{
#category : #'event handling',
#'squeak_changestamp' : 'Alex M 6/21/2024 20:38'
#'squeak_changestamp' : 'TW 6/25/2024 15:41'
}
GMTEImageButton >> mouseLeave: anEvent [

self enabled ifFalse: [^ nil].

self updateVisualState: anEvent
]

{
#category : #'event handling',
#'squeak_changestamp' : 'Alex M 6/21/2024 20:34'
#'squeak_changestamp' : 'TW 6/25/2024 15:41'
}
GMTEImageButton >> mouseMove: anEvent [

self enabled ifFalse: [^ nil].

self updateVisualState: anEvent
]

{
#category : #'event handling',
#'squeak_changestamp' : 'Alex M 6/21/2024 20:41'
#'squeak_changestamp' : 'TW 6/25/2024 15:42'
}
GMTEImageButton >> mouseUp: anEvent [

self enabled ifFalse: [^ nil].

(self containsPoint: anEvent cursorPoint)
ifTrue: [self doButtonAction]
ifFalse: [self mouseLeave: anEvent].
Expand All @@ -213,22 +256,11 @@ GMTEImageButton >> select [

{
#category : #accessing,
#'squeak_changestamp' : 'TW 6/23/2024 18:47'
#'squeak_changestamp' : 'TW 6/25/2024 15:39'
}
GMTEImageButton >> setImageMode: aString [

(aString == #pressed)
ifTrue: [
self fullResolutionSprite: (self stateSprites at: 'pressed')]
ifFalse: [
(aString == #unpressed)
ifTrue: [
self fullResolutionSprite: (self stateSprites at: 'unpressed')]
ifFalse: [
(aString == #hovered)
ifTrue: [self fullResolutionSprite: (self stateSprites at: 'hovered')]
ifFalse: [^ nil]]].

self fullResolutionSprite: (self stateSprites at: aString).
self extent: self extent
]

Expand Down Expand Up @@ -271,13 +303,13 @@ GMTEImageButton >> target: anObject [

{
#category : #'visual properties',
#'squeak_changestamp' : 'Alex M 6/22/2024 01:44'
#'squeak_changestamp' : 'TW 6/25/2024 15:41'
}
GMTEImageButton >> updateVisualState: anEvent [

(self containsPoint: Sensor cursorPoint)
ifTrue: [ anEvent redButtonPressed
ifTrue: [self setImageMode: #pressed]
ifFalse:[self setImageMode: #hovered]]
ifFalse: [self setImageMode: #unpressed]
ifTrue: [self setImageMode: 'pressed']
ifFalse:[self setImageMode: 'hovered']]
ifFalse: [self setImageMode: 'unpressed']
]
File renamed without changes.
Loading

0 comments on commit afc8749

Please sign in to comment.