Skip to content

Commit

Permalink
added radius brush
Browse files Browse the repository at this point in the history
  • Loading branch information
valteu committed Jul 6, 2024
1 parent 9ede63d commit f828485
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 50 deletions.
105 changes: 105 additions & 0 deletions source/GM-TE/GMTEBrush.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
Class {
#name : #GMTEBrush,
#superclass : #Object,
#instVars : [
'currentBrush',
'radius',
'startMatrixIndex'
],
#category : #'GM-TE-UI'
}

{
#category : #accessing,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48'
}
GMTEBrush >> currentBrush [
^ currentBrush
]

{
#category : #accessing,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48'
}
GMTEBrush >> currentBrush: anObject [
currentBrush := anObject
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 13:17'
}
GMTEBrush >> executeWithMatrixIndex: anIndex [

self startMatrixIndex: anIndex.
^ self currentBrush value.
]

{
#category : #accessing,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48'
}
GMTEBrush >> radius [
^ radius
]

{
#category : #accessing,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48'
}
GMTEBrush >> radius: anObject [
radius := anObject
]

{
#category : #forms,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:50'
}
GMTEBrush >> radiusBrush [

| collection xMin xMax yMin yMax |
self startMatrixIndex ifNil: [^nil].

collection := OrderedCollection new.

xMin := self startMatrixIndex x - self radius.
xMax := self startMatrixIndex x + self radius.
yMin := self startMatrixIndex y - self radius.
yMax := self startMatrixIndex y + self radius.

(xMin to: xMax) do: [:x |
(yMin to: yMax) do: [:y |
(( self startMatrixIndex x - x) squared + ( self startMatrixIndex y - y) squared <= self radius squared) ifTrue: [
collection add: (x@y)
].
].
].

^collection

]

{
#category : #select,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 13:16'
}
GMTEBrush >> selectRadiusBrush [

self currentBrush: [self radiusBrush]
]

{
#category : #accessing,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48'
}
GMTEBrush >> startMatrixIndex [
^ startMatrixIndex
]

{
#category : #accessing,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48'
}
GMTEBrush >> startMatrixIndex: anObject [
startMatrixIndex := anObject
]
21 changes: 12 additions & 9 deletions source/GM-TE/GMTEEditor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Class {
'associatedMorph',
'commands',
'currentCommand',
'brushMode'
'brush'
],
#category : #'GM-TE-UI'
}
Expand Down Expand Up @@ -273,18 +273,18 @@ GMTEEditor >> blendSelectedLayers [

{
#category : #accessing,
#'squeak_changestamp' : 'Valentin Teutschbein 7/5/2024 15:39'
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:54'
}
GMTEEditor >> brushMode [
^ brushMode
GMTEEditor >> brush [
^ brush
]

{
#category : #accessing,
#'squeak_changestamp' : 'Valentin Teutschbein 7/5/2024 15:39'
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:54'
}
GMTEEditor >> brushMode: anObject [
brushMode := anObject
GMTEEditor >> brush: anObject [
brush := anObject
]

{
Expand Down Expand Up @@ -1047,7 +1047,7 @@ GMTEEditor >> importMenu [

{
#category : #initialization,
#'squeak_changestamp' : 'Alex M 7/3/2024 23:57'
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 13:01'
}
GMTEEditor >> initialize [
"starts the tile editor"
Expand All @@ -1063,7 +1063,10 @@ GMTEEditor >> initialize [
ratio: 1;
savedSinceModified: true;
updateButtonEnabled;
changed: #getLayerList
changed: #getLayerList;
brush: GMTEBrush new.
self brush radius: 1.
self brush selectRadiusBrush
]

{
Expand Down
52 changes: 17 additions & 35 deletions source/GM-TE/GMTEEditorTileMap.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ GMTEEditorTileMap >> model: anObject [

{
#category : #'event handling',
#'squeak_changestamp' : 'Valentin Teutschbein 7/5/2024 17:39'
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 13:13'
}
GMTEEditorTileMap >> mouseDown: anEvent [
"Implements placement of tiles"
Expand All @@ -123,35 +123,32 @@ GMTEEditorTileMap >> mouseDown: anEvent [
ifTrue: [
activeLayer := self model selectedLayers anyOne.

selectedCoordinates := self radiusBrushFromCenter: (self tileIndexFromPosition: anEvent position) withRadius: 1.
selectedCoordinates := self model brush executeWithMatrixIndex: (self tileIndexFromPosition: anEvent position).
self updateTiles: selectedCoordinates inLayer: activeLayer FromEvent: anEvent].

^ true
]

{
#category : #'event handling',
#'squeak_changestamp' : 'Alex M 7/5/2024 21:29'
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 13:17'
}
GMTEEditorTileMap >> mouseMove: anEvent [

self mouseDown: anEvent
"Implements highlighting of tiles when hovering"
"
| hoveredTile hoveredTileHighlighting activeLayer |
self model singleLayerSelected
ifTrue: [activeLayer := self model selectedLayers anyOne.
hoveredTile := self tileFromPosition: anEvent position layer: activeLayer.
hoveredTileHighlighting := self highlightingTileFromPosition: anEvent position.

| hoveredTileHighlighting activeLayer selectedCoordinates |
self model singleLayerSelected ifFalse: [^ nil].

activeLayer := self model selectedLayers anyOne.
selectedCoordinates := self model brush executeWithMatrixIndex: (self tileIndexFromPosition: anEvent position).
selectedCoordinates ifNil: [
self tileSelectionSet clearAllHighlightings.
hoveredTileHighlighting ifNotNil: [self tileSelectionSet highlightTile: hoveredTileHighlighting].
TODO why another ifNil check here?
self updateTile: hoveredTile inLayer: activeLayer FromEvent: anEvent]"
^ nil].
self tileSelectionSet clearAllHighlightings.
selectedCoordinates do: [:c|
hoveredTileHighlighting := self highlightingTileFromIndex: c.
hoveredTileHighlighting ifNotNil: [self tileSelectionSet highlightTile: hoveredTileHighlighting]].
self updateTiles: selectedCoordinates inLayer: activeLayer FromEvent: anEvent.
]

{
Expand Down Expand Up @@ -179,21 +176,6 @@ GMTEEditorTileMap >> previousTileStates: anObject [
previousTileStates := anObject
]

{
#category : #initialization,
#'squeak_changestamp' : 'Alex M 7/5/2024 21:30'
}
GMTEEditorTileMap >> radiusBrushFromCenter: aPos withRadius: aRadius [

|collection|
aPos ifNil: [^nil].
self flag: 'temporary only'.
collection := OrderedCollection new.
collection add: aPos.
collection add: (aPos + (0@1)).
^ collection
]

{
#category : #updating,
#'squeak_changestamp' : 'Ivo Zilkenat 6/24/2024 11:35'
Expand Down Expand Up @@ -333,14 +315,14 @@ GMTEEditorTileMap >> updateTileSprite: aTile [

{
#category : #updating,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 11:41'
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:00'
}
GMTEEditorTileMap >> updateTiles: aCoordinateCollection inLayer: aLayer FromEvent: anEvent [
"Add currently selected tile (model) to editable matrix stack at mouse position"
| tile |

(self tileIndexFromPosition: anEvent position) ifNil: [^ nil].

self flag: 'saveNewImage confict with alex fix?'.
(anEvent redButtonPressed and: [self model selectedTile notNil])
ifTrue: [
aCoordinateCollection do: [:c |
Expand Down
10 changes: 4 additions & 6 deletions source/GM-TE/GMTETileMap.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -466,16 +466,14 @@ GMTETileMap >> hideHighlightingLayer [

{
#category : #accessing,
#'squeak_changestamp' : 'Ivo Zilkenat 6/24/2024 11:08'
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:11'
}
GMTETileMap >> highlightingTileFromPosition: aPoint [
GMTETileMap >> highlightingTileFromIndex: anIndex [
"Answer the sender with a highlighting tile at aPoint if present"

| index |
index := self tileIndexFromPosition: aPoint.
index ifNil: [^ nil].
anIndex ifNil: [^ nil].

^ self tileMatrixStackHighlighting layer: 1 at: index y at: index x
^ self tileMatrixStackHighlighting layer: 1 at: anIndex y at: anIndex x
]

{
Expand Down

0 comments on commit f828485

Please sign in to comment.