Skip to content

Commit 9c22ebd

Browse files
committed
fixed tile updating for rectangle brush
1 parent 70c51c9 commit 9c22ebd

File tree

2 files changed

+69
-26
lines changed

2 files changed

+69
-26
lines changed

source/GM-TE/GMTEBrush.class.st

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Class {
66
'radius',
77
'layer',
88
'currentMatrixIndex',
9-
'firstMatrixIndex'
9+
'firstMatrixIndex',
10+
'outputSet'
1011
],
1112
#category : #'GM-TE-UI'
1213
}
@@ -56,11 +57,12 @@ GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [
5657

5758
{
5859
#category : #forms,
59-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 08:47'
60+
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:04'
6061
}
6162
GMTEBrush >> fillBrush [
6263

6364
| collection startTile visited |
65+
self resetOutputSet.
6466
self currentMatrixIndex ifNil: [^nil].
6567

6668
visited := Matrix rows: (self layer rowCount) columns: self layer columnCount.
@@ -71,9 +73,9 @@ GMTEBrush >> fillBrush [
7173
visited at: self currentMatrixIndex y at: self currentMatrixIndex x put: true.
7274

7375
self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andCollection: collection.
76+
self outputSet: collection asSet.
7477

75-
^ collection
76-
78+
^ self outputSet.
7779
]
7880

7981
{
@@ -117,6 +119,16 @@ GMTEBrush >> firstMatrixIndex: anObject [
117119
firstMatrixIndex := anObject
118120
]
119121

122+
{
123+
#category : #forms,
124+
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:33'
125+
}
126+
GMTEBrush >> initialize [
127+
128+
super initialize.
129+
self resetOutputSet.
130+
]
131+
120132
{
121133
#category : #accessing,
122134
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 14:51'
@@ -133,6 +145,22 @@ GMTEBrush >> layer: anObject [
133145
layer := anObject
134146
]
135147

148+
{
149+
#category : #accessing,
150+
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:18'
151+
}
152+
GMTEBrush >> outputSet [
153+
^ outputSet
154+
]
155+
156+
{
157+
#category : #accessing,
158+
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:18'
159+
}
160+
GMTEBrush >> outputSet: anObject [
161+
outputSet := anObject
162+
]
163+
136164
{
137165
#category : #accessing,
138166
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48'
@@ -143,27 +171,27 @@ GMTEBrush >> radius [
143171

144172
{
145173
#category : #accessing,
146-
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48'
174+
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:08'
147175
}
148176
GMTEBrush >> radius: anObject [
149177
radius := anObject
150178
]
151179

152180
{
153181
#category : #forms,
154-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 09:01'
182+
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:11'
155183
}
156184
GMTEBrush >> radiusBrush [
157185

158186
| collection xMin xMax yMin yMax |
159187
self currentMatrixIndex ifNil: [^nil].
160188

161189
collection := OrderedCollection new.
162-
163-
xMin := self currentMatrixIndex x - self radius.
164-
xMax := self currentMatrixIndex x + self radius.
165-
yMin := self currentMatrixIndex y - self radius.
166-
yMax := self currentMatrixIndex y + self radius.
190+
self flag: 'radius offset is bad'.
191+
xMin := self currentMatrixIndex x - (self radius - 1).
192+
xMax := self currentMatrixIndex x + (self radius - 1).
193+
yMin := self currentMatrixIndex y - (self radius - 1).
194+
yMax := self currentMatrixIndex y + (self radius - 1).
167195

168196
(xMin to: xMax) do: [:x |
169197
(yMin to: yMax) do: [:y |
@@ -173,17 +201,20 @@ GMTEBrush >> radiusBrush [
173201
].
174202
].
175203

176-
^collection
204+
collection do: [:i | self outputSet add: i].
205+
206+
^ self outputSet.
177207

178208
]
179209

180210
{
181211
#category : #forms,
182-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 09:09'
212+
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:04'
183213
}
184214
GMTEBrush >> rectangleBrush [
185215

186216
| collection startRow endRow startCol endCol |
217+
self resetOutputSet.
187218
(self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil].
188219
collection := OrderedCollection new.
189220

@@ -200,9 +231,19 @@ GMTEBrush >> rectangleBrush [
200231
collection add: (row@col)
201232
].
202233
].
234+
self outputSet: collection asSet.
203235

204-
^ collection
236+
^ self outputSet.
237+
238+
]
239+
240+
{
241+
#category : #select,
242+
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:26'
243+
}
244+
GMTEBrush >> resetOutputSet [
205245

246+
self outputSet: Set new.
206247
]
207248

208249
{

source/GM-TE/GMTEEditorTileMap.class.st

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ GMTEEditorTileMap >> model: anObject [
113113

114114
{
115115
#category : #'event handling',
116-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 09:26'
116+
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:46'
117117
}
118118
GMTEEditorTileMap >> mouseDown: anEvent [
119119
"Implements placement of tiles"
@@ -125,14 +125,14 @@ GMTEEditorTileMap >> mouseDown: anEvent [
125125
selectedIndex := self tileIndexFromPosition: anEvent position.
126126
self model brush firstMatrixIndex: selectedIndex.
127127
selectedCoordinates := self model brush executeWithMatrixIndex: selectedIndex andLayer: (self tileMatrixStack layer: activeLayer).
128-
self updateTiles: selectedCoordinates inLayer: activeLayer FromEvent: anEvent.
128+
"self updateTiles: selectedCoordinates inLayer: activeLayer FromEvent: anEvent."
129129

130130
^ true
131131
]
132132

133133
{
134134
#category : #'event handling',
135-
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 15:22'
135+
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:02'
136136
}
137137
GMTEEditorTileMap >> mouseMove: anEvent [
138138
"Implements highlighting of tiles when hovering"
@@ -142,7 +142,7 @@ GMTEEditorTileMap >> mouseMove: anEvent [
142142

143143
activeLayer := self model selectedLayers anyOne.
144144
selectedCoordinates := self model brush executeWithMatrixIndex: (self tileIndexFromPosition: anEvent position) andLayer: (self tileMatrixStack layer: activeLayer).
145-
145+
(anEvent redButtonPressed or: [anEvent yellowButtonPressed]) ifFalse: [self model brush resetOutputSet].
146146
self tileSelectionSet clearAllHighlightings.
147147

148148
selectedCoordinates ifNil: [
@@ -151,18 +151,21 @@ GMTEEditorTileMap >> mouseMove: anEvent [
151151
(selectedCoordinates select: [:c | (self tileMatrixStack layer: activeLayer) inBounds: c]) do: [:c|
152152
hoveredTileHighlighting := self highlightingTileFromIndex: c.
153153
hoveredTileHighlighting ifNotNil: [self tileSelectionSet highlightTile: hoveredTileHighlighting]].
154-
155-
self updateTiles: selectedCoordinates inLayer: activeLayer FromEvent: anEvent.
156154
]
157155

158156
{
159157
#category : #'event handling',
160-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 09:04'
158+
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:58'
161159
}
162160
GMTEEditorTileMap >> mouseUp: anEvent [
163161

162+
| indicesToAdd activeLayer |
164163
(self previousTileStates size > 0) ifTrue: [self saveTileEditChanges].
165164
self model brush firstMatrixIndex: nil.
165+
indicesToAdd := self model brush outputSet.
166+
activeLayer := self model selectedLayers anyOne.
167+
self updateTiles: (indicesToAdd asCollection) inLayer: activeLayer FromEvent: anEvent.
168+
self model brush resetOutputSet.
166169
]
167170

168171
{
@@ -320,15 +323,14 @@ GMTEEditorTileMap >> updateTileSprite: aTile [
320323

321324
{
322325
#category : #updating,
323-
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:00'
326+
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:07'
324327
}
325328
GMTEEditorTileMap >> updateTiles: aCoordinateCollection inLayer: aLayer FromEvent: anEvent [
326329
"Add currently selected tile (model) to editable matrix stack at mouse position"
327330
| tile |
328-
329-
(self tileIndexFromPosition: anEvent position) ifNil: [^ nil].
330331
self flag: 'saveNewImage confict with alex fix?'.
331-
(anEvent redButtonPressed and: [self model selectedTile notNil])
332+
(self tileIndexFromPosition: anEvent position) ifNil: [^ nil].
333+
(anEvent redButtonChanged and: [self model selectedTile notNil])
332334
ifTrue: [
333335
aCoordinateCollection do: [:c |
334336
self savePreviousImageFromMatrixCoordinate: c inLayer: aLayer.
@@ -340,7 +342,7 @@ GMTEEditorTileMap >> updateTiles: aCoordinateCollection inLayer: aLayer FromEven
340342
self saveNewImageFromPosition: tile position inLayer: aLayer]
341343
].
342344
self model savedSinceModified: false].
343-
(anEvent yellowButtonPressed)
345+
(anEvent yellowButtonChanged)
344346
ifTrue: [
345347
aCoordinateCollection do: [:c |
346348
| tilePos |

0 commit comments

Comments
 (0)