Skip to content

Commit

Permalink
bucket fill bugged?
Browse files Browse the repository at this point in the history
  • Loading branch information
valteu committed Jul 6, 2024
1 parent 7191579 commit e6a2ed4
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 7 deletions.
78 changes: 75 additions & 3 deletions source/GM-TE/GMTEBrush.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Class {
#instVars : [
'currentBrush',
'radius',
'startMatrixIndex'
'firstMatrixIndex',
'startMatrixIndex',
'layer'
],
#category : #'GM-TE-UI'
}
Expand All @@ -27,14 +29,75 @@ GMTEBrush >> currentBrush: anObject [

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

self startMatrixIndex: anIndex.
self layer: aLayer.
^ self currentBrush value.
]

{
#category : #forms,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 16:26'
}
GMTEBrush >> fillBrush [

| collection startTile visited |
self startMatrixIndex ifNil: [^nil].
visited := Matrix rows: (self layer rowCount) columns: self layer columnCount.
collection := OrderedCollection new.
startTile := layer at: self startMatrixIndex x at: self startMatrixIndex y.
collection add: startMatrixIndex.
visited at: self startMatrixIndex x at: self startMatrixIndex y put: true.
self fillDfsWithVisited: visited andIndex: self startMatrixIndex andOriginTile: startTile andCollection: collection.

^ collection

]

{
#category : #forms,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 16:24'
}
GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile andCollection: aCollection [

| borderingOffsets |
self flag: 'REFACTOR!'.
borderingOffsets := {(-1)@0. 0@(-1). 1@0. 0@1}.
borderingOffsets do: [: offset|
| newIndex newTile |
newIndex := offset + anIndex.
((self layer inBounds: newIndex) and: [(aVisitedMatrix at: newIndex x at: newIndex y) isNil]) ifTrue:[
newTile := self layer at: newIndex x at: newIndex y.
anOriginTile
ifNil: [newTile ifNil: [aCollection add: newIndex.
aVisitedMatrix at: newIndex x at: newIndex y put: true.
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]
ifNotNil: [
(newTile isNil not and: [anOriginTile imageForm bits hash = newTile imageForm bits hash])
ifTrue: [aCollection add: newTile.
aVisitedMatrix at: newIndex x at: newIndex y put: true.
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]]]
]

{
#category : #accessing,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 14:51'
}
GMTEBrush >> layer [
^ layer
]

{
#category : #accessing,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 14:51'
}
GMTEBrush >> layer: anObject [
layer := anObject
]

{
#category : #accessing,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48'
Expand Down Expand Up @@ -79,6 +142,15 @@ GMTEBrush >> radiusBrush [

]

{
#category : #select,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 15:47'
}
GMTEBrush >> selectFillBrush [

self currentBrush: [self fillBrush]
]

{
#category : #select,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 13:16'
Expand Down
8 changes: 4 additions & 4 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' : 'JS 7/6/2024 14:23'
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 14:54'
}
GMTEEditorTileMap >> mouseDown: anEvent [
"Implements placement of tiles"
Expand All @@ -122,15 +122,15 @@ GMTEEditorTileMap >> mouseDown: anEvent [
self model singleLayerSelected ifFalse: [^nil].
activeLayer := self model selectedLayers anyOne.

selectedCoordinates := self model brush executeWithMatrixIndex: (self tileIndexFromPosition: anEvent position).
selectedCoordinates := self model brush executeWithMatrixIndex: (self tileIndexFromPosition: anEvent position) andLayer: (self tileMatrixStack layer: activeLayer).
self updateTiles: selectedCoordinates inLayer: activeLayer FromEvent: anEvent.

^ true
]

{
#category : #'event handling',
#'squeak_changestamp' : 'JS 7/6/2024 14:31'
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 15:22'
}
GMTEEditorTileMap >> mouseMove: anEvent [
"Implements highlighting of tiles when hovering"
Expand All @@ -139,7 +139,7 @@ GMTEEditorTileMap >> mouseMove: anEvent [
self model singleLayerSelected ifFalse: [^ nil].

activeLayer := self model selectedLayers anyOne.
selectedCoordinates := self model brush executeWithMatrixIndex: (self tileIndexFromPosition: anEvent position).
selectedCoordinates := self model brush executeWithMatrixIndex: (self tileIndexFromPosition: anEvent position) andLayer: (self tileMatrixStack layer: activeLayer).

self tileSelectionSet clearAllHighlightings.

Expand Down
10 changes: 10 additions & 0 deletions source/GM-TE/GMTETileMatrixLayer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ GMTETileMatrixLayer >> asRescaledToWidth: aWidth height: aHeight [

]

{
#category : #accessing,
#'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 16:14'
}
GMTETileMatrixLayer >> at: row at: column [

(self inBounds: row@column) ifFalse: [^ nil].
^ super at: row at: column
]

{
#category : #comparing,
#'squeak_changestamp' : 'Ivo Zilkenat 6/24/2024 11:39'
Expand Down

0 comments on commit e6a2ed4

Please sign in to comment.