diff --git a/source/GM-TE/GMTEBrush.class.st b/source/GM-TE/GMTEBrush.class.st index 0a554a76..7dd5889a 100644 --- a/source/GM-TE/GMTEBrush.class.st +++ b/source/GM-TE/GMTEBrush.class.st @@ -4,7 +4,9 @@ Class { #instVars : [ 'currentBrush', 'radius', - 'startMatrixIndex' + 'firstMatrixIndex', + 'startMatrixIndex', + 'layer' ], #category : #'GM-TE-UI' } @@ -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' @@ -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' diff --git a/source/GM-TE/GMTEEditorTileMap.class.st b/source/GM-TE/GMTEEditorTileMap.class.st index 855b2d02..befd4d51 100644 --- a/source/GM-TE/GMTEEditorTileMap.class.st +++ b/source/GM-TE/GMTEEditorTileMap.class.st @@ -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" @@ -122,7 +122,7 @@ 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 @@ -130,7 +130,7 @@ GMTEEditorTileMap >> mouseDown: anEvent [ { #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" @@ -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. diff --git a/source/GM-TE/GMTETileMatrixLayer.class.st b/source/GM-TE/GMTETileMatrixLayer.class.st index 96ddfb73..aa335343 100644 --- a/source/GM-TE/GMTETileMatrixLayer.class.st +++ b/source/GM-TE/GMTETileMatrixLayer.class.st @@ -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'