diff --git a/source/GM-TE/GMTEBrush.class.st b/source/GM-TE/GMTEBrush.class.st index a97ea5c2..8f6a8d69 100644 --- a/source/GM-TE/GMTEBrush.class.st +++ b/source/GM-TE/GMTEBrush.class.st @@ -1,3 +1,6 @@ +" +A GMTEBrush is responsible for returning a set of indices that are selected by the user and selecting the interchangeable algorithm for the execution. +" Class { #name : #GMTEBrush, #superclass : #Object, @@ -9,7 +12,8 @@ Class { 'firstMatrixIndex', 'outputSet' ], - #category : #'GM-TE-UI' + #category : #'GM-TE-UI', + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:49' } { @@ -22,54 +26,58 @@ GMTEBrush class >> borderingOffsets [ ] { - #category : #forms, - #'squeak_changestamp' : 'JS 7/11/2024 15:40' + #category : #brushHelper, + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 14:03' } GMTEBrush >> calculateOffsetsForRadius: aRadius [ |offsets| offsets := OrderedCollection new. - (0-radius to: radius) do: [:dx | - (0-radius to: radius) do: [:dy | + (0-self radius to: self radius) do: [:dx | + (0-self radius to: self radius) do: [:dy | ((dx squared + dy squared) <= aRadius squared) ifTrue: [offsets add: dx @ dy]]]. - ^offsets + ^ offsets ] { #category : #accessing, - #'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:40' } GMTEBrush >> currentBrush [ + ^ currentBrush ] { #category : #accessing, - #'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:40' } -GMTEBrush >> currentBrush: anObject [ - currentBrush := anObject +GMTEBrush >> currentBrush: aBrush [ + + currentBrush := aBrush ] { #category : #accessing, - #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 08:47' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:41' } GMTEBrush >> currentMatrixIndex [ + ^ currentMatrixIndex ] { #category : #accessing, - #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 08:47' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:41' } -GMTEBrush >> currentMatrixIndex: anObject [ - currentMatrixIndex := anObject +GMTEBrush >> currentMatrixIndex: anIndex [ + + currentMatrixIndex := anIndex ] { - #category : #'as yet unclassified', + #category : #execute, #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:10' } GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [ @@ -81,8 +89,8 @@ GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [ ] { - #category : #forms, - #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:10' + #category : #brushes, + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:26' } GMTEBrush >> fillBrush [ @@ -95,51 +103,49 @@ GMTEBrush >> fillBrush [ self outputSet add: self currentMatrixIndex. visited at: self currentMatrixIndex y at: self currentMatrixIndex x put: true. - self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andSet: self outputSet. + self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile. ^ self outputSet ] { - #category : #forms, - #'squeak_changestamp' : 'JS 7/11/2024 18:28' + #category : #brushHelper, + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:32' } -GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile andSet: aSet [ - self flag: 'REFACTOR!'. - +GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile [ + + | newIndex newTile | GMTEBrush borderingOffsets do: [:offset | - | newIndex newTile tilesNil tilesSame | newIndex := offset + anIndex. ((self layer inBounds: newIndex) and: [(aVisitedMatrix at: newIndex y at: newIndex x) isNil]) ifTrue:[ newTile := self layer at: newIndex y at: newIndex x. - tilesNil := (anOriginTile isNil) and: [newTile isNil]. - tilesSame := (anOriginTile isNil not and: [newTile isNil not]) and: [anOriginTile imageForm bits hash = newTile imageForm bits hash]. - - (tilesNil or: tilesSame) ifTrue: [ - aSet add: newIndex. + (self tile: anOriginTile equalsTile: newTile) ifTrue: [ + self outputSet add: newIndex. aVisitedMatrix at: newIndex y at: newIndex x put: true. - self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andSet: aSet]]] + self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile]]] ] { #category : #accessing, - #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 08:49' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:41' } GMTEBrush >> firstMatrixIndex [ + ^ firstMatrixIndex ] { #category : #accessing, - #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 08:49' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:42' } -GMTEBrush >> firstMatrixIndex: anObject [ - firstMatrixIndex := anObject +GMTEBrush >> firstMatrixIndex: anIndex [ + + firstMatrixIndex := anIndex ] { - #category : #forms, + #category : #initialization, #'squeak_changestamp' : 'JS 7/11/2024 13:59' } GMTEBrush >> initialize [ @@ -150,34 +156,36 @@ GMTEBrush >> initialize [ { #category : #accessing, - #'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 14:51' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:42' } GMTEBrush >> layer [ + ^ layer ] { #category : #accessing, - #'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 14:51' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:42' } -GMTEBrush >> layer: anObject [ - layer := anObject +GMTEBrush >> layer: aLayer [ + + layer := aLayer ] { - #category : #forms, - #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:11' + #category : #brushes, + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:53' } GMTEBrush >> lineBrush [ self resetOutputSet. - self firstMatrixIndex ifNil: [^nil]. + self firstMatrixIndex ifNil: [^ nil]. - (self rasterizeLineBetweenAStart: self firstMatrixIndex andAnEnd: self currentMatrixIndex) do: [:point | + (self rasterizeLineBetweenStart: self firstMatrixIndex andEnd: self currentMatrixIndex) do: [:index | (self calculateOffsetsForRadius: self offsetCorrectedRadius) do: [:offset | - self outputSet add: (point + offset)]]. + self outputSet add: (index + offset)]]. - ^(self outputSet) + ^ self outputSet ] @@ -193,18 +201,20 @@ GMTEBrush >> offsetCorrectedRadius [ { #category : #accessing, - #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:18' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:43' } GMTEBrush >> outputSet [ + ^ outputSet ] { #category : #accessing, - #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:18' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:43' } -GMTEBrush >> outputSet: anObject [ - outputSet := anObject +GMTEBrush >> outputSet: aSet [ + + outputSet := aSet ] { @@ -218,15 +228,15 @@ GMTEBrush >> radius [ { #category : #accessing, - #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:15' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:43' } -GMTEBrush >> radius: aNumber [ +GMTEBrush >> radius: aRadius [ - radius := aNumber + radius := aRadius ] { - #category : #forms, + #category : #brushes, #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:09' } GMTEBrush >> radiusBrush [ @@ -239,62 +249,64 @@ GMTEBrush >> radiusBrush [ ] { - #category : #forms, - #'squeak_changestamp' : 'JS 7/11/2024 18:26' + #category : #brushHelper, + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:52' } -GMTEBrush >> rasterizeLineBetweenAStart: aStartPoint andAnEnd: anEndPoint [ +GMTEBrush >> rasterizeLineBetweenStart: aStartIndex andEnd: anEndIndex [ "implementation of Bresenhams Line Algorithm" - | linePointsCollection deltaX deltaY stepX stepY error error2 x y | + | lineIndexCollection deltaX deltaY stepX stepY error error2 x y index | - self flag: 'todo: method extraction? - Ich glaube geht schlecht'. + self flag: 'repeat formatting'. - deltaX := (anEndPoint x - aStartPoint x) abs. - deltaY := (anEndPoint y - aStartPoint y) abs. - stepX := (aStartPoint x < anEndPoint x) ifTrue: [1] ifFalse: [-1]. - stepY := (aStartPoint y < anEndPoint y) ifTrue: [1] ifFalse: [-1]. + deltaX := (anEndIndex x - aStartIndex x) abs. + deltaY := (anEndIndex y - aStartIndex y) abs. + stepX := (aStartIndex x < anEndIndex x) ifTrue: [1] ifFalse: [-1]. + stepY := (aStartIndex y < anEndIndex y) ifTrue: [1] ifFalse: [-1]. error := deltaX - deltaY. - x := aStartPoint x. - y := aStartPoint y. + x := aStartIndex x. + y := aStartIndex y. - linePointsCollection := OrderedCollection new. + lineIndexCollection := OrderedCollection new. - [ - | point | - point := x @ y. - linePointsCollection add: point. - (x = anEndPoint x and: [y = anEndPoint y]) ifTrue: [ - ^linePointsCollection]. + [ index := x @ y. + lineIndexCollection add: index. + (x = anEndIndex x and: [y = anEndIndex y]) ifTrue: [^ lineIndexCollection]. error2 := 2 * error. (error2 > (0 - deltaY)) ifTrue: [ error := error - deltaY. x := x + stepX]. (error2 < deltaX) ifTrue: [ error := error + deltaX. - y := y + stepY] - ] repeat + y := y + stepY]] repeat ] { - #category : #forms, - #'squeak_changestamp' : 'JS 7/11/2024 17:34' + #category : #brushes, + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:57' } GMTEBrush >> rectangleBrush [ + | endCol endRow startCol startRow | self resetOutputSet. self firstMatrixIndex ifNil: [^ nil]. - (self currentMatrixIndex x min: self firstMatrixIndex x) to: (self currentMatrixIndex x max: self firstMatrixIndex x) do: [:row | - (self currentMatrixIndex y min: self firstMatrixIndex y) to: (self currentMatrixIndex y max: self firstMatrixIndex y) do: [:col | - self outputSet add: (row @ col)]]. + startRow := (self currentMatrixIndex x min: self firstMatrixIndex x). + endRow := (self currentMatrixIndex x max: self firstMatrixIndex x). + startCol := (self currentMatrixIndex y min: self firstMatrixIndex y). + endCol := (self currentMatrixIndex y max: self firstMatrixIndex y). + + startRow to: endRow do: [:row | + startCol to: endCol do: [:col | + self outputSet add: (row@col)]]. ^ self outputSet ] { - #category : #select, + #category : #brushHelper, #'squeak_changestamp' : 'JS 7/11/2024 13:43' } GMTEBrush >> resetOutputSet [ @@ -337,3 +349,16 @@ GMTEBrush >> selectRectangleBrush [ self currentBrush: [self rectangleBrush] ] + +{ + #category : #brushHelper, + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 13:31' +} +GMTEBrush >> tile: aTile equalsTile: anotherTile [ + + | tilesNil tilesSame | + tilesNil := (aTile isNil) and: [anotherTile isNil]. + tilesSame := (aTile isNil not and: [anotherTile isNil not]) and: [aTile imageForm bits hash = anotherTile imageForm bits hash]. + + ^ (tilesNil or: [tilesSame]) +] diff --git a/source/GM-TE/GMTEEditorTileMap.class.st b/source/GM-TE/GMTEEditorTileMap.class.st index 5de7b5f5..dcc54e73 100644 --- a/source/GM-TE/GMTEEditorTileMap.class.st +++ b/source/GM-TE/GMTEEditorTileMap.class.st @@ -22,59 +22,37 @@ GMTEEditorTileMap class >> tileWidth: aWidth tileHeight: aHeight padding: aPaddi model: aModel ] -{ - #category : #TODO, - #'squeak_changestamp' : 'Valentin Teutschbein 7/5/2024 17:07' -} -GMTEEditorTileMap >> calculateTileCollectionFromPosition: aPos andLayer: aLayer [ - - | index rawCollection resultCollection | - self flag: 'remove method'. - index := self tileIndexFromPosition: aPos. - index ifNil: [^ nil]. - rawCollection := OrderedCollection new. - resultCollection := OrderedCollection new. - self flag: 'Add different algos'. - rawCollection add: (self tileMatrixStack layer: aLayer at: index y at: index x). - self halt. - - rawCollection add: (self tileMatrixStack layer: aLayer at: index y at: ((index x)+1)). - rawCollection do: [:t | - t ifNil: [resultCollection add: (self generateTileAtlayer: aLayer x: index x y: index y stack: self tileMatrixStack tileType: GMTETile)]. - t ifNotNil: [resultCollection add: t] - ]. - ^ resultCollection -] - { #category : #accessing, - #'squeak_changestamp' : 'Alex M 6/28/2024 19:28' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 14:15' } GMTEEditorTileMap >> currentTileChanges [ + ^ currentTileChanges ] { #category : #accessing, - #'squeak_changestamp' : 'Alex M 6/28/2024 19:28' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 14:18' } -GMTEEditorTileMap >> currentTileChanges: anObject [ - currentTileChanges := anObject +GMTEEditorTileMap >> currentTileChanges: aTileDictionary [ + + currentTileChanges := aTileDictionary ] { #category : #updating, - #'squeak_changestamp' : 'JS 7/12/2024 11:30' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 14:21' } -GMTEEditorTileMap >> deleteTiles: aCoordinateCollection inLayer: aLayer [ +GMTEEditorTileMap >> deleteTiles: anIndexSet inLayer: aLayer [ "delete tiles from editable matrix stack at given indices" | tile | - aCoordinateCollection do: [:c | + anIndexSet do: [:c | ((self tileMatrixStack layer: aLayer) inBounds: c) ifTrue: [ tile := self tileMatrixStack layer: aLayer at: c y at: c x. tile ifNotNil: [ - self savePreviousImageFromMatrixCoordinate: c inLayer: aLayer. + self savePreviousImageFromIndex: c inLayer: aLayer. tile abandon. self tileMatrixStack layer: aLayer at: c y at: c x put: nil. self saveNewImageFromPosition: tile position inLayer: aLayer]]]. @@ -210,14 +188,14 @@ GMTEEditorTileMap >> mouseUp: anEvent [ { #category : #updating, - #'squeak_changestamp' : 'JS 7/12/2024 11:30' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 14:21' } GMTEEditorTileMap >> placeTiles: aCoordinateCollection inLayer: aLayer [ "Add currently selected tile (model) to editable matrix stack at given indices" | tile | aCoordinateCollection do: [:c | - self savePreviousImageFromMatrixCoordinate: c inLayer: aLayer. + self savePreviousImageFromIndex: c inLayer: aLayer. ((self tileMatrixStack layer: aLayer) inBounds: c) ifTrue: [ tile := self tileMatrixStack layer: aLayer at: c y at: c x. tile ifNil: [ tile := self generateTileAtlayer: aLayer x: c x y: c y stack: tileMatrixStack tileType: GMTETile]. @@ -228,18 +206,20 @@ GMTEEditorTileMap >> placeTiles: aCoordinateCollection inLayer: aLayer [ { #category : #accessing, - #'squeak_changestamp' : 'Alex M 6/28/2024 19:44' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 14:16' } GMTEEditorTileMap >> previousTileStates [ + ^ previousTileStates ] { #category : #accessing, - #'squeak_changestamp' : 'Alex M 6/28/2024 19:44' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 14:18' } -GMTEEditorTileMap >> previousTileStates: anObject [ - previousTileStates := anObject +GMTEEditorTileMap >> previousTileStates: aTileDictionary [ + + previousTileStates := aTileDictionary ] { @@ -282,9 +262,9 @@ GMTEEditorTileMap >> resetTileEditChanges [ { #category : #'command processing', - #'squeak_changestamp' : 'Alex M 7/6/2024 01:31' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 14:20' } -GMTEEditorTileMap >> saveNewImageFromCoordinate: aCoordinate inLayer: aLayer [ +GMTEEditorTileMap >> saveNewImageFromIndex: aCoordinate inLayer: aLayer [ | tile | tile := self tileMatrixStack layer: aLayer at: aCoordinate y at: aCoordinate x. @@ -296,18 +276,18 @@ GMTEEditorTileMap >> saveNewImageFromCoordinate: aCoordinate inLayer: aLayer [ { #category : #'command processing', - #'squeak_changestamp' : 'Alex M 7/6/2024 01:34' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 14:20' } GMTEEditorTileMap >> saveNewImageFromPosition: aPosition inLayer: aLayer [ - self saveNewImageFromCoordinate: (self tileIndexFromPosition: aPosition) inLayer: aLayer + self saveNewImageFromIndex: (self tileIndexFromPosition: aPosition) inLayer: aLayer ] { #category : #'command processing', - #'squeak_changestamp' : 'Alex M 7/6/2024 01:54' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 14:20' } -GMTEEditorTileMap >> savePreviousImageFromCoordinate: aCoordinate inLayer: aLayer [ +GMTEEditorTileMap >> savePreviousImageFromIndex: aCoordinate inLayer: aLayer [ | tile | tile := self tileMatrixStack layer: aLayer at: aCoordinate y at: aCoordinate x. @@ -319,25 +299,11 @@ GMTEEditorTileMap >> savePreviousImageFromCoordinate: aCoordinate inLayer: aLaye { #category : #'command processing', - #'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 11:46' -} -GMTEEditorTileMap >> savePreviousImageFromMatrixCoordinate: aCoordinate inLayer: aLayer [ - | tile | - - tile := self tileMatrixStack layer: aLayer at: aCoordinate y at: aCoordinate x. - - tile - ifNil: [self previousTileStates at: {aCoordinate x. aCoordinate y. aLayer} ifAbsentPut: nil] - ifNotNil: [self previousTileStates at: {aCoordinate x. aCoordinate y. aLayer} ifAbsentPut: tile fullResolutionSprite] -] - -{ - #category : #'command processing', - #'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 11:58' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 14:20' } GMTEEditorTileMap >> savePreviousImageFromPosition: aPosition inLayer: aLayer [ - self savePreviousImageFromCoordinate: (self tileIndexFromPosition: aPosition) inLayer: aLayer + self savePreviousImageFromIndex: (self tileIndexFromPosition: aPosition) inLayer: aLayer ] { @@ -362,11 +328,11 @@ GMTEEditorTileMap >> tileSelectionSet [ { #category : #accessing, - #'squeak_changestamp' : 'TW 6/22/2024 01:25' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 14:16' } -GMTEEditorTileMap >> tileSelectionSet: anObject [ +GMTEEditorTileMap >> tileSelectionSet: aSet [ - tileSelectionSet := anObject + tileSelectionSet := aSet ] { @@ -381,14 +347,14 @@ GMTEEditorTileMap >> updateTileSprite: aTile [ { #category : #updating, - #'squeak_changestamp' : 'JS 7/12/2024 11:31' + #'squeak_changestamp' : 'Valentin Teutschbein 7/12/2024 14:13' } -GMTEEditorTileMap >> updateTiles: aCoordinateCollection inLayer: aLayer FromEvent: anEvent [ +GMTEEditorTileMap >> updateTiles: anIndexSet inLayer: aLayer FromEvent: anEvent [ (self tileIndexFromPosition: anEvent position) ifNil: [^ nil]. - (anEvent redButtonChanged and: [self model selectedTile notNil]) ifTrue: [self placeTiles: aCoordinateCollection inLayer: aLayer]. - (anEvent yellowButtonChanged) ifTrue: [self deleteTiles: aCoordinateCollection inLayer: aLayer]. + (anEvent redButtonChanged and: [self model selectedTile notNil]) ifTrue: [self placeTiles: anIndexSet inLayer: aLayer]. + (anEvent yellowButtonChanged) ifTrue: [self deleteTiles: anIndexSet inLayer: aLayer]. self model savedSinceModified: false ]