diff --git a/source/GM-TE/GMTEBrush.class.st b/source/GM-TE/GMTEBrush.class.st new file mode 100644 index 00000000..0a554a76 --- /dev/null +++ b/source/GM-TE/GMTEBrush.class.st @@ -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 +] diff --git a/source/GM-TE/GMTEEditor.class.st b/source/GM-TE/GMTEEditor.class.st index d1cd7307..6bca6e8f 100644 --- a/source/GM-TE/GMTEEditor.class.st +++ b/source/GM-TE/GMTEEditor.class.st @@ -18,7 +18,7 @@ Class { 'associatedMorph', 'commands', 'currentCommand', - 'brushMode' + 'brush' ], #category : #'GM-TE-UI' } @@ -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 ] { @@ -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" @@ -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 ] { diff --git a/source/GM-TE/GMTEEditorTileMap.class.st b/source/GM-TE/GMTEEditorTileMap.class.st index 6cbc7fd9..489dfb71 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' : 'Valentin Teutschbein 7/5/2024 17:39' + #'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 13:13' } GMTEEditorTileMap >> mouseDown: anEvent [ "Implements placement of tiles" @@ -123,7 +123,7 @@ 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 @@ -131,27 +131,24 @@ GMTEEditorTileMap >> mouseDown: anEvent [ { #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. ] { @@ -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' @@ -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 | diff --git a/source/GM-TE/GMTETileMap.class.st b/source/GM-TE/GMTETileMap.class.st index 56ad7bfd..c20af234 100644 --- a/source/GM-TE/GMTETileMap.class.st +++ b/source/GM-TE/GMTETileMap.class.st @@ -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 ] {