From c24224f92c76e75ea7c08be01dacec4ea6ae6047 Mon Sep 17 00:00:00 2001 From: Ivo Zilkenat Date: Wed, 10 Jul 2024 13:14:43 +0200 Subject: [PATCH 01/19] Highlightings get properly deleted after moues leave --- source/GM-TE/GMTEEditorTileMap.class.st | 29 +++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/source/GM-TE/GMTEEditorTileMap.class.st b/source/GM-TE/GMTEEditorTileMap.class.st index ebda3cc3..e2c0ace5 100644 --- a/source/GM-TE/GMTEEditorTileMap.class.st +++ b/source/GM-TE/GMTEEditorTileMap.class.st @@ -80,6 +80,15 @@ GMTEEditorTileMap >> handlesMouseMove: anEvent [ ^ true ] +{ + #category : #'event handling', + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 13:12' +} +GMTEEditorTileMap >> handlesMouseOver: anEvent [ + + ^ true +] + { #category : #initialization, #'squeak_changestamp' : 'Alex M 6/28/2024 20:24' @@ -130,6 +139,15 @@ GMTEEditorTileMap >> mouseDown: anEvent [ ^ true ] +{ + #category : #'event handling', + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 13:14' +} +GMTEEditorTileMap >> mouseLeave: anEvent [ + + self tileSelectionSet clearAllHighlightings +] + { #category : #'event handling', #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:02' @@ -184,17 +202,6 @@ GMTEEditorTileMap >> previousTileStates: anObject [ previousTileStates := anObject ] -{ - #category : #updating, - #'squeak_changestamp' : 'Ivo Zilkenat 6/24/2024 11:35' -} -GMTEEditorTileMap >> rescaleMap [ - "Override super behavior such that highlightings are removed during rescale events" - - self tileSelectionSet clearAllHighlightings. - super rescaleMap -] - { #category : #TODO, #'squeak_changestamp' : 'Alex M 7/3/2024 23:50' From bf93c7ea339de792b2ec4957336b135f6e459bee Mon Sep 17 00:00:00 2001 From: Valentin Teutschbein Date: Wed, 10 Jul 2024 14:03:37 +0200 Subject: [PATCH 02/19] fixed rescaling ordered collection bug --- source/GM-TE/GMTETileMatrixStack.class.st | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/GM-TE/GMTETileMatrixStack.class.st b/source/GM-TE/GMTETileMatrixStack.class.st index bd6f27db..63f8cac9 100644 --- a/source/GM-TE/GMTETileMatrixStack.class.st +++ b/source/GM-TE/GMTETileMatrixStack.class.st @@ -392,7 +392,7 @@ GMTETileMatrixStack >> removeLayersAt: aSet [ { #category : #updating, - #'squeak_changestamp' : 'TW 6/22/2024 01:27' + #'squeak_changestamp' : 'Valentin Teutschbein 7/10/2024 13:59' } GMTETileMatrixStack >> rescaleToWidth: aWidth height: aHeight [ "This will rescale layers be recreating them" @@ -402,7 +402,7 @@ GMTETileMatrixStack >> rescaleToWidth: aWidth height: aHeight [ width: aWidth; height: aHeight. - newLayers := LinkedList new. + newLayers := OrderedCollection new. self doLayers: [:layer | newLayer := layer asRescaledToWidth: aWidth height: aHeight. From 07307c99765ee4e46b54fdf1cb35654c4716f832 Mon Sep 17 00:00:00 2001 From: Jannis Jost Date: Wed, 10 Jul 2024 16:53:07 +0200 Subject: [PATCH 03/19] Input handling --- source/GM-TE/GMTEEditor.class.st | 51 ++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/source/GM-TE/GMTEEditor.class.st b/source/GM-TE/GMTEEditor.class.st index 35bbe5dc..3185e1f8 100644 --- a/source/GM-TE/GMTEEditor.class.st +++ b/source/GM-TE/GMTEEditor.class.st @@ -373,7 +373,7 @@ GMTEEditor >> brushButtons: anObject [ { #category : #building, - #'squeak_changestamp' : 'TW 7/9/2024 18:15' + #'squeak_changestamp' : 'mcjj 7/10/2024 16:51' } GMTEEditor >> buildWith: builder [ "builds the editor with ToolBuilder" @@ -393,7 +393,7 @@ GMTEEditor >> buildWith: builder [ self createInspectorSpecWithBuilder: builder}; closeAction: #onClose; minimumExtent: GMTEEditor editorMinimumExtent). - + self commandBar: (newMorph submorphNamed: 'command bar'). "self commandBar vResizing: #rigid." self tileStore: (newMorph submorphNamed: 'tile store'). @@ -422,7 +422,8 @@ GMTEEditor >> buildWith: builder [ self initializeDefaultTileMapMatrix; - associatedMorph: newMorph. + associatedMorph: newMorph; + setupInputHandlingFor: newMorph. ^ newMorph ] @@ -967,6 +968,15 @@ GMTEEditor >> disableSingleLayerButtons [ GMTEEditor singleLayerActionNames do: [:aString | (self associatedMorph submorphNamed: aString) enabled: false ] ] +{ + #category : #'input handling', + #'squeak_changestamp' : 'mcjj 7/10/2024 16:47' +} +GMTEEditor >> dropKeyboardFocus: anEvent [ + + anEvent hand releaseKeyboardFocus: self associatedMorph +] + { #category : #'as yet unclassified', #'squeak_changestamp' : 'TW 6/25/2024 17:51' @@ -1096,6 +1106,15 @@ GMTEEditor >> getGridWidthAsString [ ^ self getGridWidth asString ] +{ + #category : #'input handling', + #'squeak_changestamp' : 'mcjj 7/10/2024 16:46' +} +GMTEEditor >> getKeyboardFocus: anEvent [ + + anEvent hand newKeyboardFocus: self associatedMorph +] + { #category : #'layer manipulation', #'squeak_changestamp' : 'TW 6/23/2024 21:50' @@ -1163,6 +1182,18 @@ GMTEEditor >> getTileRatioAsString [ ^ self getTileRatio asString ] +{ + #category : #'input handling', + #'squeak_changestamp' : 'mcjj 7/10/2024 16:49' +} +GMTEEditor >> handleKeyStroke: anEvent [ + + | keyValue | + keyValue := anEvent key. + Transcript show: keyValue + "keyValue = $A" +] + { #category : #'menu button functions', #'squeak_changestamp' : 'TW 6/23/2024 20:09' @@ -1985,6 +2016,20 @@ GMTEEditor >> settingsMenu [ builder open: aMenuSpec ] +{ + #category : #'input handling', + #'squeak_changestamp' : 'mcjj 7/10/2024 16:49' +} +GMTEEditor >> setupInputHandlingFor: aMorph [ + + aMorph + on: #mouseMove send: #getKeyboardFocus: to: self; + on: #mouseLeave send: #dropKeyboardFocus: to: self; + on: #keyStroke send: #handleKeyStroke: to: self. + + aMorph eventHandler wantsEveryMouseMove: true +] + { #category : #'layer manipulation', #'squeak_changestamp' : 'jj 6/22/2024 21:43' From 4485bffee3302e58c15c8d88a16cd4eb4340edab Mon Sep 17 00:00:00 2001 From: Aleksander Morgensterns Date: Thu, 11 Jul 2024 00:34:37 +0200 Subject: [PATCH 04/19] reintroduced and expanded onClose --- source/GM-TE/GMTEDeleteLayersCommand.class.st | 2 +- source/GM-TE/GMTEEditTilesCommand.class.st | 60 +++++++--------- source/GM-TE/GMTEEditor.class.st | 70 ++++--------------- source/GM-TE/GMTEEditorTileMap.class.st | 29 +++----- source/GM-TE/GMTETileMatrixStack.class.st | 4 +- source/GM-TE/GMTETilemapSizeCommand.class.st | 2 +- 6 files changed, 55 insertions(+), 112 deletions(-) diff --git a/source/GM-TE/GMTEDeleteLayersCommand.class.st b/source/GM-TE/GMTEDeleteLayersCommand.class.st index 4be78980..a6eafdc3 100644 --- a/source/GM-TE/GMTEDeleteLayersCommand.class.st +++ b/source/GM-TE/GMTEDeleteLayersCommand.class.st @@ -1,6 +1,6 @@ Class { #name : #GMTEDeleteLayersCommand, - #superclass : #GMTETilemapSizeCommand, + #superclass : #GMTEEditTilesCommand, #instVars : [ 'layers' ], diff --git a/source/GM-TE/GMTEEditTilesCommand.class.st b/source/GM-TE/GMTEEditTilesCommand.class.st index 10b268af..1972bc86 100644 --- a/source/GM-TE/GMTEEditTilesCommand.class.st +++ b/source/GM-TE/GMTEEditTilesCommand.class.st @@ -40,18 +40,38 @@ GMTEEditTilesCommand >> currentSprites: anObject [ { #category : #execution, - #'squeak_changestamp' : 'TW 7/2/2024 17:54' + #'squeak_changestamp' : 'Alex M 7/10/2024 13:42' } GMTEEditTilesCommand >> do [ + + self placeTilesFromList: self currentSprites +] + +{ + #category : #initialization, + #'squeak_changestamp' : 'Alex M 6/28/2024 02:45' +} +GMTEEditTilesCommand >> initialize [ + + self + previousSprites: Dictionary new; + currentSprites: Dictionary new +] + +{ + #category : #execution, + #'squeak_changestamp' : 'Alex M 7/10/2024 13:44' +} +GMTEEditTilesCommand >> placeTilesFromList: aList [ | tile sprite layer x y | - self currentSprites keysDo: [ :coordinates | + aList keysDo: [ :coordinates | x := coordinates at: 1. y := coordinates at: 2. layer := coordinates at: 3. tile := self tileMap tileMatrixStack layer: layer at: y at: x. - sprite := self currentSprites at: coordinates. + sprite := aList at: coordinates. tile ifNil: [sprite ifNotNil: [ @@ -61,18 +81,7 @@ GMTEEditTilesCommand >> do [ ifNil: [ self tileMap tileMatrixStack layer: layer at: y at: x put: nil. tile abandon] - ifNotNil: [tile updateSprite: (self currentSprites at: coordinates)]]] -] - -{ - #category : #initialization, - #'squeak_changestamp' : 'Alex M 6/28/2024 02:45' -} -GMTEEditTilesCommand >> initialize [ - - self - previousSprites: Dictionary new; - currentSprites: Dictionary new + ifNotNil: [tile updateSprite: (aList at: coordinates)]]] ] { @@ -109,26 +118,9 @@ GMTEEditTilesCommand >> tileMap: anObject [ { #category : #execution, - #'squeak_changestamp' : 'TW 7/2/2024 17:54' + #'squeak_changestamp' : 'Alex M 7/10/2024 13:43' } GMTEEditTilesCommand >> undo [ - | tile sprite layer x y | - self previousSprites keysDo: [ :coordinates | - x := coordinates at: 1. - y := coordinates at: 2. - layer := coordinates at: 3. - - tile := self tileMap tileMatrixStack layer: layer at: y at: x. - sprite := self previousSprites at: coordinates. - tile - ifNil: [sprite - ifNotNil: [ - tile := tileMap generateTileAtlayer: layer x: x y: y stack: self tileMap tileMatrixStack tileType: GMTETile. - tile updateSprite: sprite]] - ifNotNil: [sprite - ifNil: [ - self tileMap tileMatrixStack layer: layer at: y at: x put: nil. - tile abandon] - ifNotNil: [tile updateSprite: (self previousSprites at: coordinates)]]] + self placeTilesFromList: self previousSprites ] diff --git a/source/GM-TE/GMTEEditor.class.st b/source/GM-TE/GMTEEditor.class.st index 3185e1f8..769d0efe 100644 --- a/source/GM-TE/GMTEEditor.class.st +++ b/source/GM-TE/GMTEEditor.class.st @@ -373,7 +373,7 @@ GMTEEditor >> brushButtons: anObject [ { #category : #building, - #'squeak_changestamp' : 'mcjj 7/10/2024 16:51' + #'squeak_changestamp' : 'TW 7/9/2024 18:15' } GMTEEditor >> buildWith: builder [ "builds the editor with ToolBuilder" @@ -393,7 +393,7 @@ GMTEEditor >> buildWith: builder [ self createInspectorSpecWithBuilder: builder}; closeAction: #onClose; minimumExtent: GMTEEditor editorMinimumExtent). - + self commandBar: (newMorph submorphNamed: 'command bar'). "self commandBar vResizing: #rigid." self tileStore: (newMorph submorphNamed: 'tile store'). @@ -422,8 +422,7 @@ GMTEEditor >> buildWith: builder [ self initializeDefaultTileMapMatrix; - associatedMorph: newMorph; - setupInputHandlingFor: newMorph. + associatedMorph: newMorph. ^ newMorph ] @@ -968,15 +967,6 @@ GMTEEditor >> disableSingleLayerButtons [ GMTEEditor singleLayerActionNames do: [:aString | (self associatedMorph submorphNamed: aString) enabled: false ] ] -{ - #category : #'input handling', - #'squeak_changestamp' : 'mcjj 7/10/2024 16:47' -} -GMTEEditor >> dropKeyboardFocus: anEvent [ - - anEvent hand releaseKeyboardFocus: self associatedMorph -] - { #category : #'as yet unclassified', #'squeak_changestamp' : 'TW 6/25/2024 17:51' @@ -1106,15 +1096,6 @@ GMTEEditor >> getGridWidthAsString [ ^ self getGridWidth asString ] -{ - #category : #'input handling', - #'squeak_changestamp' : 'mcjj 7/10/2024 16:46' -} -GMTEEditor >> getKeyboardFocus: anEvent [ - - anEvent hand newKeyboardFocus: self associatedMorph -] - { #category : #'layer manipulation', #'squeak_changestamp' : 'TW 6/23/2024 21:50' @@ -1182,18 +1163,6 @@ GMTEEditor >> getTileRatioAsString [ ^ self getTileRatio asString ] -{ - #category : #'input handling', - #'squeak_changestamp' : 'mcjj 7/10/2024 16:49' -} -GMTEEditor >> handleKeyStroke: anEvent [ - - | keyValue | - keyValue := anEvent key. - Transcript show: keyValue - "keyValue = $A" -] - { #category : #'menu button functions', #'squeak_changestamp' : 'TW 6/23/2024 20:09' @@ -1518,15 +1487,14 @@ GMTEEditor >> moveLayerUp [ { #category : #building, - #'squeak_changestamp' : 'Alex M 6/28/2024 21:27' + #'squeak_changestamp' : 'Alex M 7/11/2024 00:34' } GMTEEditor >> onClose [ "asks the user whether they want to save their progress" - "self savedSinceModified + self savedSinceModified ifFalse: [(PopUpMenu confirm: 'Save before closing?') - ifTrue: [self exportAsMorph]]" - "COMMENTED FOR EASIER DEBUGGING" + ifTrue: [self exportAsMorph]] ] { @@ -1646,13 +1614,15 @@ GMTEEditor >> ratio: anObject [ { #category : #'command processing', - #'squeak_changestamp' : 'TW 7/2/2024 17:47' + #'squeak_changestamp' : 'Alex M 7/10/2024 14:17' } GMTEEditor >> redo [ (self currentCommand < self commands size) ifTrue: [ - self currentCommand: self currentCommand + 1. + self + savedSinceModified: false; + currentCommand: self currentCommand + 1. (self commands at: self currentCommand) do. self savedSinceModified: false] ] @@ -2016,20 +1986,6 @@ GMTEEditor >> settingsMenu [ builder open: aMenuSpec ] -{ - #category : #'input handling', - #'squeak_changestamp' : 'mcjj 7/10/2024 16:49' -} -GMTEEditor >> setupInputHandlingFor: aMorph [ - - aMorph - on: #mouseMove send: #getKeyboardFocus: to: self; - on: #mouseLeave send: #dropKeyboardFocus: to: self; - on: #keyStroke send: #handleKeyStroke: to: self. - - aMorph eventHandler wantsEveryMouseMove: true -] - { #category : #'layer manipulation', #'squeak_changestamp' : 'jj 6/22/2024 21:43' @@ -2176,14 +2132,16 @@ GMTEEditor >> trayViewer: anObject [ { #category : #'command processing', - #'squeak_changestamp' : 'Alex M 7/10/2024 03:49' + #'squeak_changestamp' : 'Alex M 7/10/2024 14:17' } GMTEEditor >> undo [ self flag: 'DO THIS USING TILEMAP FUNCTIONS'. (self currentCommand > 1) ifTrue: [(self commands at: self currentCommand) undo. - self currentCommand: self currentCommand - 1. + self + savedSinceModified: false; + currentCommand: self currentCommand - 1. ({GMTETilemapSizeCommand. GMTEDeleteLayersCommand} includes: (self commands at: self currentCommand + 1) class) ifTrue: [self redoAllCommandsUntil: self currentCommand]. self savedSinceModified: false] diff --git a/source/GM-TE/GMTEEditorTileMap.class.st b/source/GM-TE/GMTEEditorTileMap.class.st index 36891056..1f47a0f6 100644 --- a/source/GM-TE/GMTEEditorTileMap.class.st +++ b/source/GM-TE/GMTEEditorTileMap.class.st @@ -80,15 +80,6 @@ GMTEEditorTileMap >> handlesMouseMove: anEvent [ ^ true ] -{ - #category : #'event handling', - #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 13:12' -} -GMTEEditorTileMap >> handlesMouseOver: anEvent [ - - ^ true -] - { #category : #initialization, #'squeak_changestamp' : 'Alex M 6/28/2024 20:24' @@ -139,15 +130,6 @@ GMTEEditorTileMap >> mouseDown: anEvent [ ^ true ] -{ - #category : #'event handling', - #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 13:14' -} -GMTEEditorTileMap >> mouseLeave: anEvent [ - - self tileSelectionSet clearAllHighlightings -] - { #category : #'event handling', #'squeak_changestamp' : 'Valentin Teutschbein 7/10/2024 13:06' @@ -202,6 +184,17 @@ GMTEEditorTileMap >> previousTileStates: anObject [ previousTileStates := anObject ] +{ + #category : #updating, + #'squeak_changestamp' : 'Ivo Zilkenat 6/24/2024 11:35' +} +GMTEEditorTileMap >> rescaleMap [ + "Override super behavior such that highlightings are removed during rescale events" + + self tileSelectionSet clearAllHighlightings. + super rescaleMap +] + { #category : #TODO, #'squeak_changestamp' : 'Alex M 7/3/2024 23:50' diff --git a/source/GM-TE/GMTETileMatrixStack.class.st b/source/GM-TE/GMTETileMatrixStack.class.st index 63f8cac9..bd6f27db 100644 --- a/source/GM-TE/GMTETileMatrixStack.class.st +++ b/source/GM-TE/GMTETileMatrixStack.class.st @@ -392,7 +392,7 @@ GMTETileMatrixStack >> removeLayersAt: aSet [ { #category : #updating, - #'squeak_changestamp' : 'Valentin Teutschbein 7/10/2024 13:59' + #'squeak_changestamp' : 'TW 6/22/2024 01:27' } GMTETileMatrixStack >> rescaleToWidth: aWidth height: aHeight [ "This will rescale layers be recreating them" @@ -402,7 +402,7 @@ GMTETileMatrixStack >> rescaleToWidth: aWidth height: aHeight [ width: aWidth; height: aHeight. - newLayers := OrderedCollection new. + newLayers := LinkedList new. self doLayers: [:layer | newLayer := layer asRescaledToWidth: aWidth height: aHeight. diff --git a/source/GM-TE/GMTETilemapSizeCommand.class.st b/source/GM-TE/GMTETilemapSizeCommand.class.st index 7613d036..fe18b4f0 100644 --- a/source/GM-TE/GMTETilemapSizeCommand.class.st +++ b/source/GM-TE/GMTETilemapSizeCommand.class.st @@ -1,6 +1,6 @@ Class { #name : #GMTETilemapSizeCommand, - #superclass : #GMTECommand, + #superclass : #GMTEEditTilesCommand, #instVars : [ 'editor', 'method', From d74333d40759f990aefa73fe3e3b77f3ab11a1c1 Mon Sep 17 00:00:00 2001 From: Joshua Date: Thu, 11 Jul 2024 14:15:23 +0200 Subject: [PATCH 05/19] minor codestyle fixes for brushes --- source/GM-TE/GMTEBrush.class.st | 194 ++++++++++++------------ source/GM-TE/GMTEEditorTileMap.class.st | 25 ++- 2 files changed, 109 insertions(+), 110 deletions(-) diff --git a/source/GM-TE/GMTEBrush.class.st b/source/GM-TE/GMTEBrush.class.st index 5d00dad2..078d9042 100644 --- a/source/GM-TE/GMTEBrush.class.st +++ b/source/GM-TE/GMTEBrush.class.st @@ -46,18 +46,18 @@ GMTEBrush >> currentMatrixIndex: anObject [ { #category : #'as yet unclassified', - #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 08:47' + #'squeak_changestamp' : 'JS 7/11/2024 13:59' } GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [ self currentMatrixIndex: anIndex. self layer: aLayer. - ^ self currentBrush value. + ^ self currentBrush value ] { #category : #forms, - #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:04' + #'squeak_changestamp' : 'JS 7/11/2024 14:07' } GMTEBrush >> fillBrush [ @@ -67,27 +67,27 @@ GMTEBrush >> fillBrush [ visited := Matrix rows: (self layer rowCount) columns: self layer columnCount. collection := OrderedCollection new. - startTile := layer at: self currentMatrixIndex y at: self currentMatrixIndex x. + startTile := self layer at: self currentMatrixIndex y at: self currentMatrixIndex x. - collection add: currentMatrixIndex. + collection add: self currentMatrixIndex. visited at: self currentMatrixIndex y at: self currentMatrixIndex x put: true. self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andCollection: collection. self outputSet: collection asSet. - ^ self outputSet. + ^ self outputSet ] { #category : #forms, - #'squeak_changestamp' : 'JS 7/6/2024 16:46' + #'squeak_changestamp' : 'JS 7/11/2024 13:58' } 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| + borderingOffsets do: [:offset | | newIndex newTile | newIndex := offset + anIndex. ((self layer inBounds: newIndex) and: [(aVisitedMatrix at: newIndex y at: newIndex x) isNil]) ifTrue:[ @@ -97,10 +97,10 @@ GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: aVisitedMatrix at: newIndex y at: newIndex x 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: newIndex. - aVisitedMatrix at: newIndex y at: newIndex x put: true. - self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]]] + (newTile isNil not and: [anOriginTile imageForm bits hash = newTile imageForm bits hash]) ifTrue: [ + aCollection add: newIndex. + aVisitedMatrix at: newIndex y at: newIndex x put: true. + self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]]] ] { @@ -121,12 +121,21 @@ GMTEBrush >> firstMatrixIndex: anObject [ { #category : #forms, - #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:33' + #'squeak_changestamp' : 'JS 7/11/2024 13:59' } GMTEBrush >> initialize [ super initialize. - self resetOutputSet. + self resetOutputSet +] + +{ + #category : #forms, + #'squeak_changestamp' : 'JS 7/11/2024 14:04' +} +GMTEBrush >> isPointInRadius: aPoint [ + self flag: 'to long? - refactor with lineBrush in mind'. + ^(( self currentMatrixIndex x - aPoint x) squared + ( self currentMatrixIndex y - aPoint y) squared <= (self radius - 1) squared) ] { @@ -147,56 +156,50 @@ GMTEBrush >> layer: anObject [ { #category : #forms, - #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:53' + #'squeak_changestamp' : 'JS 7/11/2024 14:09' } GMTEBrush >> lineBrush [ - | radius collection start end deltaX deltaY stepX stepY error error2 x y offsets | - + | radius collection start end deltaX deltaY stepX stepY error error2 x y offsets | + self flag: 'refactor - do instead of collect or select'. radius := self radius - 1. self resetOutputSet. self flag: 'todo: method extraction'. - "Helper method to generate radius offsets" - offsets := OrderedCollection new. - (0-radius to: radius) do: [:dx | - (0-radius to: radius) do: [:dy | - (dx * dx + dy * dy <= (radius * radius)) ifTrue: [ - offsets add: dx @ dy. - ]. - ]. - ]. - - self resetOutputSet. - (self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil]. - - start := self firstMatrixIndex. - end := self currentMatrixIndex. - deltaX := (end x - start x) abs. - deltaY := (end y - start y) abs. - stepX := (start x < end x) ifTrue: [1] ifFalse: [-1]. - stepY := (start y < end y) ifTrue: [1] ifFalse: [-1]. - error := deltaX - deltaY. - x := start x. - y := start y. - - collection := OrderedCollection new. - - [ - | point | - point := x @ y. - offsets do: [:offset | collection add: (point + offset)]. - (x = end x and: [y = end y]) ifTrue: [ - self outputSet: collection asSet. - ^ self outputSet.]. - error2 := 2 * error. - (error2 > (0 - deltaY)) ifTrue: [ - error := error - deltaY. - x := x + stepX. - ]. - (error2 < deltaX) ifTrue: [ - error := error + deltaX. - y := y + stepY. - ]. - ] repeat. + "Helper method to generate radius offsets" + offsets := OrderedCollection new. + (0-radius to: radius) do: [:dx | + (0-radius to: radius) do: [:dy | + ((dx * dx) + (dy * dy) <= (radius * radius)) ifTrue: [offsets add: dx @ dy]]]. + + self resetOutputSet. + (self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil]. + + start := self firstMatrixIndex. + end := self currentMatrixIndex. + deltaX := (end x - start x) abs. + deltaY := (end y - start y) abs. + stepX := (start x < end x) ifTrue: [1] ifFalse: [-1]. + stepY := (start y < end y) ifTrue: [1] ifFalse: [-1]. + error := deltaX - deltaY. + x := start x. + y := start y. + + collection := OrderedCollection new. + + [ + | point | + point := x @ y. + offsets do: [:offset | collection add: (point + offset)]. + (x = end x and: [y = end y]) ifTrue: [ + self outputSet: collection asSet. + ^ self outputSet]. + error2 := 2 * error. + (error2 > (0 - deltaY)) ifTrue: [ + error := error - deltaY. + x := x + stepX]. + (error2 < deltaX) ifTrue: [ + error := error + deltaX. + y := y + stepY] + ] repeat ] @@ -234,71 +237,68 @@ GMTEBrush >> radius: anObject [ { #category : #forms, - #'squeak_changestamp' : 'Valentin Teutschbein 7/10/2024 12:37' + #'squeak_changestamp' : 'JS 7/11/2024 14:06' } GMTEBrush >> radiusBrush [ - | collection xMin xMax yMin yMax | - self currentMatrixIndex ifNil: [^nil]. + | collection xMin xMax yMin yMax | + self currentMatrixIndex ifNil: [^nil]. - collection := OrderedCollection new. + collection := OrderedCollection new. self flag: 'radius offset is bad'. - xMin := self currentMatrixIndex x - (self radius - 1). - xMax := self currentMatrixIndex x + (self radius - 1). - yMin := self currentMatrixIndex y - (self radius - 1). - yMax := self currentMatrixIndex y + (self radius - 1). + xMin := self currentMatrixIndex x - (self radius - 1). + xMax := self currentMatrixIndex x + (self radius - 1). + yMin := self currentMatrixIndex y - (self radius - 1). + yMax := self currentMatrixIndex y + (self radius - 1). - (xMin to: xMax) do: [:x | - (yMin to: yMax) do: [:y | - (( self currentMatrixIndex x - x) squared + ( self currentMatrixIndex y - y) squared <= (self radius - 1) squared) ifTrue: [ - collection add: x@y - ]. - ]. - ]. + self flag: 'select instead of do?'. + (xMin to: xMax) do: [:x | + (yMin to: yMax) do: [:y | + (self isPointInRadius: x @ y) ifTrue: [collection add: x @ y]]]. - collection do: [:i | self outputSet add: i]. + collection do: [:i | + self outputSet add: i]. - ^ self outputSet. + ^ self outputSet ] { #category : #forms, - #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:04' + #'squeak_changestamp' : 'JS 7/11/2024 13:49' } GMTEBrush >> rectangleBrush [ - | collection startRow endRow startCol endCol | + | collection startRow endRow startCol endCol | self resetOutputSet. - (self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil]. - collection := OrderedCollection new. - - "Determine the starting and ending rows and columns" - - 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). - - "Fill the collection with all indices within the rectangle" - startRow to: endRow do: [:row | - startCol to: endCol do: [:col | - collection add: (row@col) - ]. - ]. + (self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil]. + collection := OrderedCollection new. + + "Determine the starting and ending rows and columns" + self flag: 'method extraction'. + 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). + + "Fill the collection with all indices within the rectangle" + startRow to: endRow do: [:row | + startCol to: endCol do: [:col | + collection add: (row @ col)]]. + self outputSet: collection asSet. - ^ self outputSet. + ^ self outputSet ] { #category : #select, - #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:26' + #'squeak_changestamp' : 'JS 7/11/2024 13:43' } GMTEBrush >> resetOutputSet [ - self outputSet: Set new. + self outputSet: Set new ] { diff --git a/source/GM-TE/GMTEEditorTileMap.class.st b/source/GM-TE/GMTEEditorTileMap.class.st index 1f47a0f6..310e5d2e 100644 --- a/source/GM-TE/GMTEEditorTileMap.class.st +++ b/source/GM-TE/GMTEEditorTileMap.class.st @@ -113,18 +113,17 @@ GMTEEditorTileMap >> model: anObject [ { #category : #'event handling', - #'squeak_changestamp' : 'Valentin Teutschbein 7/10/2024 13:07' + #'squeak_changestamp' : 'JS 7/11/2024 14:13' } GMTEEditorTileMap >> mouseDown: anEvent [ "Implements placement of tiles" - | selectedCoordinates activeLayer selectedIndex | + | selectedIndex | self flag: 'refactor; method extraction for "Add tiles to layer" to minimize redundancy with mouseMove?'. self model singleLayerSelected ifFalse: [^nil]. - activeLayer := self model selectedLayers anyOne. selectedIndex := self tileIndexFromPosition: anEvent position. self model brush firstMatrixIndex: selectedIndex. - selectedCoordinates := self model brush executeWithMatrixIndex: selectedIndex andLayer: (self tileMatrixStack layer: activeLayer). + self model brush executeWithMatrixIndex: selectedIndex andLayer: (self tileMatrixStack layer: self model selectedLayers anyOne). anEvent yellowButtonPressed ifTrue: [self tileSelectionSet highlightImage: nil]. ^ true @@ -132,7 +131,7 @@ GMTEEditorTileMap >> mouseDown: anEvent [ { #category : #'event handling', - #'squeak_changestamp' : 'Valentin Teutschbein 7/10/2024 13:06' + #'squeak_changestamp' : 'JS 7/11/2024 14:01' } GMTEEditorTileMap >> mouseMove: anEvent [ "Implements highlighting of tiles when hovering" @@ -149,12 +148,12 @@ GMTEEditorTileMap >> mouseMove: anEvent [ (selectedCoordinates select: [:c | (self tileMatrixStack layer: activeLayer) inBounds: c]) do: [:t| hoveredTileHighlighting := self highlightingTileFromIndex: t. - hoveredTileHighlighting ifNotNil: [self tileSelectionSet highlightTile: hoveredTileHighlighting]]. + hoveredTileHighlighting ifNotNil: [self tileSelectionSet highlightTile: hoveredTileHighlighting]] ] { #category : #'event handling', - #'squeak_changestamp' : 'Valentin Teutschbein 7/10/2024 13:11' + #'squeak_changestamp' : 'JS 7/11/2024 14:11' } GMTEEditorTileMap >> mouseUp: anEvent [ @@ -164,8 +163,8 @@ GMTEEditorTileMap >> mouseUp: anEvent [ activeLayer := self model selectedLayers anyOne. self updateTiles: (indicesToAdd asCollection) inLayer: activeLayer FromEvent: anEvent. self model brush resetOutputSet. - (self previousTileStates size > 0) ifTrue: [self saveTileEditChanges]. - self tileSelectionSet highlightImage: (self model selectedTile). + (self previousTileStates isEmpty) ifFalse: [self saveTileEditChanges]. + self tileSelectionSet highlightImage: (self model selectedTile) ] { @@ -284,12 +283,12 @@ GMTEEditorTileMap >> savePreviousImageFromPosition: aPosition inLayer: aLayer [ { #category : #'command processing', - #'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 11:52' + #'squeak_changestamp' : 'JS 7/11/2024 14:07' } GMTEEditorTileMap >> saveTileEditChanges [ self - model addCommand: (GMTEEditTilesCommand previousTiles: previousTileStates currentTiles: currentTileChanges tilemap: self). + model addCommand: (GMTEEditTilesCommand previousTiles: self previousTileStates currentTiles: self currentTileChanges tilemap: self). self resetTileEditChanges. ] @@ -323,12 +322,12 @@ GMTEEditorTileMap >> updateTileSprite: aTile [ { #category : #updating, - #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:07' + #'squeak_changestamp' : 'JS 7/11/2024 14:01' } GMTEEditorTileMap >> updateTiles: aCoordinateCollection inLayer: aLayer FromEvent: anEvent [ "Add currently selected tile (model) to editable matrix stack at mouse position" | tile | - self flag: 'saveNewImage confict with alex fix?'. + self flag: 'refactor'. (self tileIndexFromPosition: anEvent position) ifNil: [^ nil]. (anEvent redButtonChanged and: [self model selectedTile notNil]) ifTrue: [ From 62c4395f2c46998bd8a893bfd6ab1f5278a829b3 Mon Sep 17 00:00:00 2001 From: Jannis Jost Date: Thu, 11 Jul 2024 16:13:46 +0200 Subject: [PATCH 06/19] Implemented bubbling --- source/GM-TE/GMTEEditor.class.st | 81 +++++++++++-------------- source/GM-TE/GMTEEditorTileMap.class.st | 5 +- 2 files changed, 37 insertions(+), 49 deletions(-) diff --git a/source/GM-TE/GMTEEditor.class.st b/source/GM-TE/GMTEEditor.class.st index 3185e1f8..03517020 100644 --- a/source/GM-TE/GMTEEditor.class.st +++ b/source/GM-TE/GMTEEditor.class.st @@ -373,7 +373,7 @@ GMTEEditor >> brushButtons: anObject [ { #category : #building, - #'squeak_changestamp' : 'mcjj 7/10/2024 16:51' + #'squeak_changestamp' : 'mcjj 7/11/2024 15:51' } GMTEEditor >> buildWith: builder [ "builds the editor with ToolBuilder" @@ -394,6 +394,8 @@ GMTEEditor >> buildWith: builder [ closeAction: #onClose; minimumExtent: GMTEEditor editorMinimumExtent). + newMorph addKeyboardCaptureFilter: self. + self commandBar: (newMorph submorphNamed: 'command bar'). "self commandBar vResizing: #rigid." self tileStore: (newMorph submorphNamed: 'tile store'). @@ -422,8 +424,7 @@ GMTEEditor >> buildWith: builder [ self initializeDefaultTileMapMatrix; - associatedMorph: newMorph; - setupInputHandlingFor: newMorph. + associatedMorph: newMorph. ^ newMorph ] @@ -968,15 +969,6 @@ GMTEEditor >> disableSingleLayerButtons [ GMTEEditor singleLayerActionNames do: [:aString | (self associatedMorph submorphNamed: aString) enabled: false ] ] -{ - #category : #'input handling', - #'squeak_changestamp' : 'mcjj 7/10/2024 16:47' -} -GMTEEditor >> dropKeyboardFocus: anEvent [ - - anEvent hand releaseKeyboardFocus: self associatedMorph -] - { #category : #'as yet unclassified', #'squeak_changestamp' : 'TW 6/25/2024 17:51' @@ -1032,6 +1024,36 @@ GMTEEditor >> exportMenu [ builder open: aMenuSpec ] +{ + #category : #'input handling', + #'squeak_changestamp' : 'mcjj 7/11/2024 15:57' +} +GMTEEditor >> filterEvent: aKeyboardEvent for: anObject [ + | key | + + aKeyboardEvent isKeystroke + ifFalse: [^ aKeyboardEvent]. + + key := aKeyboardEvent key. + + aKeyboardEvent commandKeyPressed ifTrue: [ + aKeyboardEvent shiftPressed + ifTrue: [ + key caseOf: { + [$Z] -> [self redo]. + } otherwise: [^ aKeyboardEvent "no hit"]. + ^ aKeyboardEvent ignore "hit"] + ifFalse: [ + key caseOf: { + [$Z] -> [self undo]. + [$Y] -> [self redo]. + [$R] -> [self rotateSelectedTile]. + } otherwise: [^ aKeyboardEvent "no hit"]. + ^ aKeyboardEvent ignore "hit"]]. + + ^ aKeyboardEvent "no hit" +] + { #category : #accessing, #'squeak_changestamp' : 'TW 7/9/2024 17:14' @@ -1106,15 +1128,6 @@ GMTEEditor >> getGridWidthAsString [ ^ self getGridWidth asString ] -{ - #category : #'input handling', - #'squeak_changestamp' : 'mcjj 7/10/2024 16:46' -} -GMTEEditor >> getKeyboardFocus: anEvent [ - - anEvent hand newKeyboardFocus: self associatedMorph -] - { #category : #'layer manipulation', #'squeak_changestamp' : 'TW 6/23/2024 21:50' @@ -1182,18 +1195,6 @@ GMTEEditor >> getTileRatioAsString [ ^ self getTileRatio asString ] -{ - #category : #'input handling', - #'squeak_changestamp' : 'mcjj 7/10/2024 16:49' -} -GMTEEditor >> handleKeyStroke: anEvent [ - - | keyValue | - keyValue := anEvent key. - Transcript show: keyValue - "keyValue = $A" -] - { #category : #'menu button functions', #'squeak_changestamp' : 'TW 6/23/2024 20:09' @@ -2016,20 +2017,6 @@ GMTEEditor >> settingsMenu [ builder open: aMenuSpec ] -{ - #category : #'input handling', - #'squeak_changestamp' : 'mcjj 7/10/2024 16:49' -} -GMTEEditor >> setupInputHandlingFor: aMorph [ - - aMorph - on: #mouseMove send: #getKeyboardFocus: to: self; - on: #mouseLeave send: #dropKeyboardFocus: to: self; - on: #keyStroke send: #handleKeyStroke: to: self. - - aMorph eventHandler wantsEveryMouseMove: true -] - { #category : #'layer manipulation', #'squeak_changestamp' : 'jj 6/22/2024 21:43' diff --git a/source/GM-TE/GMTEEditorTileMap.class.st b/source/GM-TE/GMTEEditorTileMap.class.st index 36891056..062da3a7 100644 --- a/source/GM-TE/GMTEEditorTileMap.class.st +++ b/source/GM-TE/GMTEEditorTileMap.class.st @@ -172,7 +172,7 @@ GMTEEditorTileMap >> mouseMove: anEvent [ { #category : #'event handling', - #'squeak_changestamp' : 'Valentin Teutschbein 7/10/2024 13:11' + #'squeak_changestamp' : 'mcjj 7/11/2024 11:14' } GMTEEditorTileMap >> mouseUp: anEvent [ @@ -183,7 +183,8 @@ GMTEEditorTileMap >> mouseUp: anEvent [ self updateTiles: (indicesToAdd asCollection) inLayer: activeLayer FromEvent: anEvent. self model brush resetOutputSet. (self previousTileStates size > 0) ifTrue: [self saveTileEditChanges]. - self tileSelectionSet highlightImage: (self model selectedTile). + self tileSelectionSet clearAllHighlightings. + self tileSelectionSet highlightImage: (self model selectedTile) ] { From 7feb0c0e1fa176d706782a852d1fcd505715c5fa Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Thu, 11 Jul 2024 16:27:51 +0200 Subject: [PATCH 07/19] line tool icon --- .squot-materialize | 239 ++++++++++++++++--------------- GMTEIcons/line.png | Bin 0 -> 216 bytes source/GM-TE/GMTEEditor.class.st | 33 ++++- 3 files changed, 149 insertions(+), 123 deletions(-) create mode 100644 GMTEIcons/line.png diff --git a/.squot-materialize b/.squot-materialize index 16c074d9..295d3507 100644 --- a/.squot-materialize +++ b/.squot-materialize @@ -9,31 +9,42 @@ }, SquotTonelMapper { #package : MCPackage { - #name : 'GM-TilemapMakerGui' + #name : 'ToolBuilder-Morphic' }, #path : FSAbsolutePath [ 'source' ] }, - SquotImageMapper { + SquotCypressMapper { + #package : MCPackage { + #name : 'GM-Utilities' + }, #path : FSAbsolutePath [ - 'GMTEIcons', - 'brush.png' - ], - #encoding : Class [ #PNGReadWriter ] + 'source' + ] }, SquotCypressMapper { #package : MCPackage { - #name : 'GM-Test' + #name : 'GM-Core' }, - #path : @7 + #path : FSAbsolutePath [ + 'source' + ] }, - SquotImageMapper { + SquotCypressMapper { + #package : MCPackage { + #name : 'BaselineOfGM' + }, #path : FSAbsolutePath [ - 'GMTEIcons', - 'undo.png' + 'source' + ] + }, + SquotSoundMapper { + #path : FSAbsolutePath [ + 'testingResources', + 'squeak.aiff' ], - #encoding : @10 + #encoding : 'AIFF' }, SquotImageMapper { #path : FSAbsolutePath [ @@ -42,71 +53,85 @@ ], #encoding : Class [ #GIFReadWriter ] }, + SquotPlaintextMapper { + #path : FSAbsolutePath [ + '.github', + 'workflows', + 'main.yml' + ], + #encoding : 'TXT' + }, SquotCypressMapper { #package : MCPackage { - #name : 'GM-Utilities' + #name : 'GM-DemoGame' }, #path : FSAbsolutePath [ 'source' ] }, - SquotTonelMapper { - #package : MCPackage { - #name : 'GM-ToolBuilder' - }, + SquotPlaintextMapper { #path : FSAbsolutePath [ - 'source' - ] + '.smalltalk.ston' + ], + #encoding : 'TXT' }, SquotImageMapper { #path : FSAbsolutePath [ 'GMTEIcons', - 'trash.png' + 'merge.png' ], - #encoding : @10 + #encoding : Class [ #PNGReadWriter ] }, SquotPlaintextMapper { #path : FSAbsolutePath [ - '.github', - 'workflows', - 'main.yml' + 'README.md' + ], + #encoding : 'TXT' + }, + SquotPlaintextMapper { + #path : FSAbsolutePath [ + 'testingResources', + 'test' ], #encoding : 'TXT' }, SquotImageMapper { #path : FSAbsolutePath [ 'GMTEIcons', - 'up.png' + 'broom.png' ], - #encoding : @10 + #encoding : @31 }, SquotTonelMapper { #package : MCPackage { - #name : 'ToolBuilder-Kernel' + #name : 'GM-TilemapMakerGui' }, #path : @7 }, SquotImageMapper { #path : FSAbsolutePath [ - 'testingResources', - 'squeak.png' + 'GMTEIcons', + 'rectangle.png' ], - #encoding : @10 + #encoding : @31 }, - SquotCypressMapper { + SquotTonelMapper { #package : MCPackage { - #name : 'BaselineOfGM' + #name : 'GM-TE' }, - #path : FSAbsolutePath [ - 'source' - ] + #path : @4 }, - SquotImageMapper { + SquotTonelMapper { + #package : MCPackage { + #name : 'ToolBuilder-Kernel' + }, + #path : @7 + }, + SquotPlaintextMapper { #path : FSAbsolutePath [ - 'GMTEIcons', - 'rename.png' + '.squot' ], - #encoding : @10 + #encoding : 'TXT' }, SquotPlaintextMapper { #path : FSAbsolutePath [ @@ -117,27 +142,34 @@ SquotImageMapper { #path : FSAbsolutePath [ 'GMTEIcons', - 'down.png' + 'eye.png' ], - #encoding : @10 + #encoding : @31 + }, + SquotImageMapper { + #path : FSAbsolutePath [ + 'GMTEIcons', + 'add.png' + ], + #encoding : @31 }, SquotPlaintextMapper { #path : FSAbsolutePath [ - '.squot' + 'testingResources', + 'test.txt' ], #encoding : 'TXT' }, - SquotCypressMapper { - #package : MCPackage { - #name : 'GM-TestFixtures' - }, + SquotImageMapper { #path : FSAbsolutePath [ - 'source' - ] + 'GMTEIcons', + 'line.png' + ], + #encoding : @31 }, SquotCypressMapper { #package : MCPackage { - #name : 'GM-Core' + #name : 'GM-AcceptanceTest' }, #path : FSAbsolutePath [ 'source' @@ -146,82 +178,57 @@ SquotImageMapper { #path : FSAbsolutePath [ 'GMTEIcons', - 'fill.png' + 'rename.png' ], - #encoding : @10 + #encoding : @31 }, SquotTonelMapper { #package : MCPackage { - #name : 'ToolBuilder-Morphic' + #name : 'GM-ToolBuilder' }, - #path : @7 + #path : FSAbsolutePath [ + 'source' + ] }, SquotSoundMapper { #path : FSAbsolutePath [ 'testingResources', - 'squeak.aiff' + 'squeak.wav' ], - #encoding : 'AIFF' + #encoding : 'WAV' }, SquotImageMapper { #path : FSAbsolutePath [ 'GMTEIcons', - 'merge.png' - ], - #encoding : @10 - }, - SquotSoundMapper { - #path : FSAbsolutePath [ - 'testingResources', - 'squeak.wav' + 'brush.png' ], - #encoding : 'WAV' + #encoding : @31 }, SquotCypressMapper { #package : MCPackage { - #name : 'GM-DemoGame' + #name : 'GM-Test' }, - #path : FSAbsolutePath [ - 'source' - ] - }, - SquotPlaintextMapper { - #path : FSAbsolutePath [ - 'README.md' - ], - #encoding : 'TXT' + #path : @7 }, SquotTonelMapper { #package : MCPackage { - #name : 'GM-TE' + #name : 'GM-TilemapMakerCore' }, - #path : @4 + #path : @7 }, - SquotPlaintextMapper { + SquotImageMapper { #path : FSAbsolutePath [ 'testingResources', - 'test' + 'squeak.png' ], - #encoding : 'TXT' + #encoding : @31 }, SquotImageMapper { #path : FSAbsolutePath [ 'GMTEIcons', - 'broom.png' - ], - #encoding : @10 - }, - SquotPlaintextMapper { - #path : FSAbsolutePath [ - '.smalltalk.ston' - ], - #encoding : 'TXT' - }, - SquotBlobMapper { - #path : FSAbsolutePath [ - 'map.morph' + 'down.png' ], - #encoding : 'bin' + #encoding : @31 }, SquotBlobMapper { #path : FSAbsolutePath [ @@ -229,27 +236,27 @@ ], #encoding : 'bin' }, - SquotImageMapper { - #path : FSAbsolutePath [ - 'GMTEIcons', - 'eye.png' - ], - #encoding : @10 - }, SquotCypressMapper { #package : MCPackage { - #name : 'GM-AcceptanceTest' + #name : 'GM-TestFixtures' }, #path : FSAbsolutePath [ 'source' ] }, + SquotImageMapper { + #path : FSAbsolutePath [ + 'GMTEIcons', + 'undo.png' + ], + #encoding : @31 + }, SquotImageMapper { #path : FSAbsolutePath [ 'GMTEIcons', 'redo.png' ], - #encoding : @10 + #encoding : @31 }, SquotPlaintextMapper { #path : FSAbsolutePath [ @@ -257,31 +264,31 @@ ], #encoding : 'TXT' }, + SquotBlobMapper { + #path : FSAbsolutePath [ + 'map.morph' + ], + #encoding : 'bin' + }, SquotImageMapper { #path : FSAbsolutePath [ 'GMTEIcons', - 'rectangle.png' + 'fill.png' ], - #encoding : @10 + #encoding : @31 }, SquotImageMapper { #path : FSAbsolutePath [ 'GMTEIcons', - 'add.png' + 'up.png' ], - #encoding : @10 + #encoding : @31 }, - SquotTonelMapper { - #package : MCPackage { - #name : 'GM-TilemapMakerCore' - }, - #path : @7 - }, - SquotPlaintextMapper { + SquotImageMapper { #path : FSAbsolutePath [ - 'testingResources', - 'test.txt' + 'GMTEIcons', + 'trash.png' ], - #encoding : 'TXT' + #encoding : @31 } ] \ No newline at end of file diff --git a/GMTEIcons/line.png b/GMTEIcons/line.png new file mode 100644 index 0000000000000000000000000000000000000000..d9dec7982fbf9d21645010a79bf521948a0b0dba GIT binary patch literal 216 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1|;R|J2nET`JOJ0Ar)~?Z*Al~pupo2cx;jP z!8dXZLWW$d8&$;vFS%R&^9&EPO$-lkxxDA@?mf@ec6FS#-t#*!*yW6P((|(?l*{^N z+9W+W=b@Z7@3UYHi~K?N52R2>;yaIjTiDm}MOa{BDU(vt)8E^j`2<&XMp~x%3KlYZ XGl#c4()_U)=u`$zS3j3^P6> createTilestoreSpecWithBuilder: aBuilder [ { #category : #building, - #'squeak_changestamp' : 'Alex M 7/10/2024 02:12' + #'squeak_changestamp' : 'tw 7/11/2024 16:26' } GMTEEditor >> createToolBarSpecWithBuilder: aBuilder [ "creates the spec for the tool bar" @@ -800,7 +800,7 @@ GMTEEditor >> createToolBarSpecWithBuilder: aBuilder [ name: 'undo'; description: 'Undo'; model: self; - frame: (LayoutFrame fractions: (0 @ 0 corner: (1 / 6) @ 1) offsets: nil); + frame: (LayoutFrame fractions: (0 @ 0 corner: (1 / 7) @ 1) offsets: nil); action: #undo; project: 'GameMecha'; path: '/GMTEIcons/undo.png'. @@ -809,7 +809,7 @@ GMTEEditor >> createToolBarSpecWithBuilder: aBuilder [ name: 'redo'; description: 'Redo'; model: self; - frame: (LayoutFrame fractions: ((1 / 6) @ 0 corner: (2 / 6) @ 1) offsets: nil); + frame: (LayoutFrame fractions: ((1 / 7) @ 0 corner: (2 / 7) @ 1) offsets: nil); action: #redo; project: 'GameMecha'; path: '/GMTEIcons/redo.png'. @@ -818,17 +818,27 @@ GMTEEditor >> createToolBarSpecWithBuilder: aBuilder [ name: 'radiusBrush'; description: 'Brush'; model: self; - frame: (LayoutFrame fractions: ((2 / 6) @ 0 corner: (3 / 6) @ 1) offsets: nil); + frame: (LayoutFrame fractions: ((2 / 7) @ 0 corner: (3 / 7) @ 1) offsets: nil); action: #selectRadiusBrush; project: 'GameMecha'; buttonGroup: self brushButtons; path: '/GMTEIcons/brush.png'. + (aBuilder pluggableImageButtonSpec new) + name: 'lineBrush'; + description: 'Line Tool'; + model: self; + frame: (LayoutFrame fractions: ((3 / 7) @ 0 corner: (4 / 7) @ 1) offsets: nil); + action: #selectLineBrush; + project: 'GameMecha'; + buttonGroup: self brushButtons; + path: '/GMTEIcons/line.png'. + (aBuilder pluggableImageButtonSpec new) name: 'fillBrush'; description: 'Fill Tool'; model: self; - frame: (LayoutFrame fractions: ((3 / 6) @ 0 corner: (4 / 6) @ 1) offsets: nil); + frame: (LayoutFrame fractions: ((4 / 7) @ 0 corner: (5 / 7) @ 1) offsets: nil); action: #selectFillBrush; project: 'GameMecha'; buttonGroup: self brushButtons; @@ -838,7 +848,7 @@ GMTEEditor >> createToolBarSpecWithBuilder: aBuilder [ name: 'rectangleBrush'; description: 'Rectangle Tool'; model: self; - frame: (LayoutFrame fractions: ((4 / 6) @ 0 corner: (5 / 6) @ 1) offsets: nil); + frame: (LayoutFrame fractions: ((5 / 7) @ 0 corner: (6 / 7) @ 1) offsets: nil); action: #selectRectangleBrush; project: 'GameMecha'; buttonGroup: self brushButtons; @@ -849,7 +859,7 @@ GMTEEditor >> createToolBarSpecWithBuilder: aBuilder [ getter: #getBrushRadiusAsString setter: #setBrushRadiusFromText: model: self - frame:(LayoutFrame fractions: ((4.5 / 6) @ 0 corner: 0.95 @ 1) offsets: (20 @ 0 corner: 0 @ 0)). + frame:(LayoutFrame fractions: ((5.5 / 7) @ 0 corner: 0.95 @ 1) offsets: (20 @ 0 corner: 0 @ 0)). }; @@ -1786,6 +1796,15 @@ GMTEEditor >> selectLayer: anIndex [ ] +{ + #category : #'menu button functions', + #'squeak_changestamp' : 'tw 7/11/2024 16:23' +} +GMTEEditor >> selectLineBrush [ + + self brush selectLineBrush +] + { #category : #accessing, #'squeak_changestamp' : 'jj 6/22/2024 21:35' From fca03adc533d117a9dbc6922ffe7c07282ec4b30 Mon Sep 17 00:00:00 2001 From: Joshua Date: Thu, 11 Jul 2024 16:30:00 +0200 Subject: [PATCH 08/19] first refactoring --- source/GM-TE/GMTEBrush.class.st | 156 ++++++++++++++++---------------- 1 file changed, 80 insertions(+), 76 deletions(-) diff --git a/source/GM-TE/GMTEBrush.class.st b/source/GM-TE/GMTEBrush.class.st index 078d9042..6ed05f44 100644 --- a/source/GM-TE/GMTEBrush.class.st +++ b/source/GM-TE/GMTEBrush.class.st @@ -12,6 +12,21 @@ Class { #category : #'GM-TE-UI' } +{ + #category : #forms, + #'squeak_changestamp' : 'JS 7/11/2024 15:40' +} +GMTEBrush >> calculateOffsetsForRadius: aRadius [ + + |offsets| + offsets := OrderedCollection new. + (0-radius to: radius) do: [:dx | + (0-radius to: radius) do: [:dy | + ((dx squared + dy squared) <= aRadius squared) ifTrue: [offsets add: dx @ dy]]]. + + ^offsets +] + { #category : #accessing, #'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48' @@ -129,15 +144,6 @@ GMTEBrush >> initialize [ self resetOutputSet ] -{ - #category : #forms, - #'squeak_changestamp' : 'JS 7/11/2024 14:04' -} -GMTEBrush >> isPointInRadius: aPoint [ - self flag: 'to long? - refactor with lineBrush in mind'. - ^(( self currentMatrixIndex x - aPoint x) squared + ( self currentMatrixIndex y - aPoint y) squared <= (self radius - 1) squared) -] - { #category : #accessing, #'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 14:51' @@ -156,51 +162,32 @@ GMTEBrush >> layer: anObject [ { #category : #forms, - #'squeak_changestamp' : 'JS 7/11/2024 14:09' + #'squeak_changestamp' : 'JS 7/11/2024 16:16' } GMTEBrush >> lineBrush [ - | radius collection start end deltaX deltaY stepX stepY error error2 x y offsets | - self flag: 'refactor - do instead of collect or select'. - radius := self radius - 1. - self resetOutputSet. - self flag: 'todo: method extraction'. - "Helper method to generate radius offsets" - offsets := OrderedCollection new. - (0-radius to: radius) do: [:dx | - (0-radius to: radius) do: [:dy | - ((dx * dx) + (dy * dy) <= (radius * radius)) ifTrue: [offsets add: dx @ dy]]]. + | offsets | self resetOutputSet. (self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil]. + + offsets := self calculateOffsetsForRadius: self offsetCorrectedRadius. + + (self rasterizeLineBetweenAStart: self firstMatrixIndex andAnEnd: self currentMatrixIndex) do: [:point | + offsets do: [:offset | + self outputSet add: (point + offset)]]. - start := self firstMatrixIndex. - end := self currentMatrixIndex. - deltaX := (end x - start x) abs. - deltaY := (end y - start y) abs. - stepX := (start x < end x) ifTrue: [1] ifFalse: [-1]. - stepY := (start y < end y) ifTrue: [1] ifFalse: [-1]. - error := deltaX - deltaY. - x := start x. - y := start y. + ^(self outputSet) - collection := OrderedCollection new. +] - [ - | point | - point := x @ y. - offsets do: [:offset | collection add: (point + offset)]. - (x = end x and: [y = end y]) ifTrue: [ - self outputSet: collection asSet. - ^ self outputSet]. - error2 := 2 * error. - (error2 > (0 - deltaY)) ifTrue: [ - error := error - deltaY. - x := x + stepX]. - (error2 < deltaX) ifTrue: [ - error := error + deltaX. - y := y + stepY] - ] repeat +{ + #category : #accessing, + #'squeak_changestamp' : 'JS 7/11/2024 16:16' +} +GMTEBrush >> offsetCorrectedRadius [ + "In order to display a more intuitive radius for the user, we need to offset it by 1 for the calculations" + ^ self radius - 1 ] { @@ -237,27 +224,17 @@ GMTEBrush >> radius: anObject [ { #category : #forms, - #'squeak_changestamp' : 'JS 7/11/2024 14:06' + #'squeak_changestamp' : 'JS 7/11/2024 16:14' } GMTEBrush >> radiusBrush [ - | collection xMin xMax yMin yMax | + | offsets | self currentMatrixIndex ifNil: [^nil]. - collection := OrderedCollection new. - self flag: 'radius offset is bad'. - xMin := self currentMatrixIndex x - (self radius - 1). - xMax := self currentMatrixIndex x + (self radius - 1). - yMin := self currentMatrixIndex y - (self radius - 1). - yMax := self currentMatrixIndex y + (self radius - 1). - - self flag: 'select instead of do?'. - (xMin to: xMax) do: [:x | - (yMin to: yMax) do: [:y | - (self isPointInRadius: x @ y) ifTrue: [collection add: x @ y]]]. + offsets := self calculateOffsetsForRadius: self offsetCorrectedRadius. - collection do: [:i | - self outputSet add: i]. + offsets do: [:i | + self outputSet add: (self currentMatrixIndex + i)]. ^ self outputSet @@ -265,28 +242,55 @@ GMTEBrush >> radiusBrush [ { #category : #forms, - #'squeak_changestamp' : 'JS 7/11/2024 13:49' + #'squeak_changestamp' : 'JS 7/11/2024 16:16' +} +GMTEBrush >> rasterizeLineBetweenAStart: aStartPoint andAnEnd: anEndPoint [ + "implementation of Bresenhams Line Algorithm" + + | collection deltaX deltaY stepX stepY error error2 x y | + + self flag: 'todo: method extraction? - Ich glaube geht schlecht'. + + 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]. + error := deltaX - deltaY. + x := aStartPoint x. + y := aStartPoint y. + + collection := OrderedCollection new. + + [ + | point | + point := x @ y. + collection add: point. + (x = anEndPoint x and: [y = anEndPoint y]) ifTrue: [ + ^collection]. + error2 := 2 * error. + (error2 > (0 - deltaY)) ifTrue: [ + error := error - deltaY. + x := x + stepX]. + (error2 < deltaX) ifTrue: [ + error := error + deltaX. + y := y + stepY] + ] repeat + +] + +{ + #category : #forms, + #'squeak_changestamp' : 'JS 7/11/2024 16:29' } GMTEBrush >> rectangleBrush [ - | collection startRow endRow startCol endCol | self resetOutputSet. (self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil]. - collection := OrderedCollection new. - "Determine the starting and ending rows and columns" - self flag: 'method extraction'. - 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). - - "Fill the collection with all indices within the rectangle" - startRow to: endRow do: [:row | - startCol to: endCol do: [:col | - collection add: (row @ col)]]. - - self outputSet: collection asSet. + self flag: 'besser machen?'. + (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)]]. ^ self outputSet From af9212d02d785dd1420bcc69c1a2c246b5debe52 Mon Sep 17 00:00:00 2001 From: Ivo Zilkenat Date: Thu, 11 Jul 2024 16:55:07 +0200 Subject: [PATCH 09/19] Progress on zooming --- source/GM-TE/GMTETileMap.class.st | 98 +++++++++++++++++++++++++++---- source/GM-TE/GMTEView.class.st | 80 ++++++++++++++++++++++++- 2 files changed, 163 insertions(+), 15 deletions(-) diff --git a/source/GM-TE/GMTETileMap.class.st b/source/GM-TE/GMTETileMap.class.st index 647a97ac..11ad8354 100644 --- a/source/GM-TE/GMTETileMap.class.st +++ b/source/GM-TE/GMTETileMap.class.st @@ -90,6 +90,24 @@ GMTETileMap class >> tileWidth: aWidth tileHeight: aHeight padding: aPadding siz tileSizeRatio: aRatio ] +{ + #category : #'view-conversion', + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 22:20' +} +GMTETileMap >> absPointToViewCenter: aPoint [ + + ^ (self absPointToViewFraction: aPoint) - (self view extent / 2) +] + +{ + #category : #'view-conversion', + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 22:19' +} +GMTETileMap >> absPointToViewFraction: aPoint [ + + ^aPoint / self extent +] + { #category : #accessing, #'squeak_changestamp' : 'Ivo Zilkenat 6/19/2024 22:28' @@ -193,6 +211,17 @@ GMTETileMap >> borderTileWidth: anObject [ borderTileWidth := anObject ] +{ + #category : #view, + #'squeak_changestamp' : 'Ivo Zilkenat 7/11/2024 00:08' +} +GMTETileMap >> centerViewAt: aPoint [ + "Note: center must induce legal view (non-overlapping)" + + self view moveTo: (self inViewPointToViewCenter: aPoint). + self updateMap +] + { #category : #conversion, #'squeak_changestamp' : 'Ivo Zilkenat 6/24/2024 11:09' @@ -477,9 +506,36 @@ GMTETileMap >> highlightingTileFromIndex: anIndex [ ^ self tileMatrixStackHighlighting layer: 1 at: anIndex y at: anIndex x ] +{ + #category : #'view-conversion', + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 22:58' +} +GMTETileMap >> inViewPointToAbs: aPoint [ + + ^ (self viewOriginInPxl - self topLeft) + (aPoint / self viewScaleFactor) +] + +{ + #category : #'view-conversion', + #'squeak_changestamp' : 'Ivo Zilkenat 7/11/2024 00:01' +} +GMTETileMap >> inViewPointToViewCenter: aPoint [ + + ^ (self inViewPointToViewFraction: aPoint) - (self view extent / 2) +] + +{ + #category : #'view-conversion', + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 22:30' +} +GMTETileMap >> inViewPointToViewFraction: aPoint [ + + ^ self absPointToViewFraction: (self inViewPointToAbs: aPoint) +] + { #category : #initialization, - #'squeak_changestamp' : 'Ivo Zilkenat 7/9/2024 11:47' + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 18:15' } GMTETileMap >> initialize [ @@ -488,7 +544,7 @@ GMTETileMap >> initialize [ color: Color lightGray; clipSubmorphs: true; forceMapSizeRatio: false; - view: (GMTEView origin: 0 @ 0 extent: 1 @ 1); + view: GMTEView new; "TODO: spike solution. Size 1@1 sets quadratic base image. Generic resizing not working yet" "TODO: default background tiles (must not exist but practical as a visual indicator)" @@ -690,6 +746,16 @@ GMTETileMap >> rescaleMatrixStacks [ self generateHighlightingTiles] ] +{ + #category : #view, + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 18:47' +} +GMTETileMap >> resetView [ + + self view reset. + self updateMap +] + { #category : #conversion, #'squeak_changestamp' : 'Ivo Zilkenat 6/24/2024 11:11' @@ -721,7 +787,7 @@ GMTETileMap >> revertCorrectedTilePositionMap: aPoint [ ] { - #category : #view, + #category : #'view-conversion', #'squeak_changestamp' : 'Ivo Zilkenat 7/2/2024 20:49' } GMTETileMap >> revertViewCorrectedTilePosition: aPoint [ @@ -731,7 +797,7 @@ GMTETileMap >> revertViewCorrectedTilePosition: aPoint [ ] { - #category : #view, + #category : #'view-conversion', #'squeak_changestamp' : 'Ivo Zilkenat 7/2/2024 20:47' } GMTETileMap >> revertViewCorrectedTilePositionMap: aPoint [ @@ -1193,7 +1259,7 @@ GMTETileMap >> view: anObject [ ] { - #category : #view, + #category : #'view-conversion', #'squeak_changestamp' : 'Ivo Zilkenat 7/2/2024 20:36' } GMTETileMap >> viewCorrectedTileExtent: anExtent [ @@ -1203,7 +1269,7 @@ GMTETileMap >> viewCorrectedTileExtent: anExtent [ ] { - #category : #view, + #category : #'view-conversion', #'squeak_changestamp' : 'Ivo Zilkenat 7/2/2024 20:36' } GMTETileMap >> viewCorrectedTilePosition: aPoint [ @@ -1213,22 +1279,20 @@ GMTETileMap >> viewCorrectedTilePosition: aPoint [ ] { - #category : #view, - #'squeak_changestamp' : 'Ivo Zilkenat 7/2/2024 20:36' + #category : #'view-conversion', + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 17:50' } GMTETileMap >> viewOriginInPxl [ - "Note: given that view has same ratio as tileMap" ^ self extent * self view origin + self topLeft ] { - #category : #view, - #'squeak_changestamp' : 'Ivo Zilkenat 7/2/2024 19:47' + #category : #'view-conversion', + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 17:50' } GMTETileMap >> viewScaleFactor [ - "Note: given that view has same ratio as tileMap" ^ 1 / (self view extent x) @@ -1253,3 +1317,13 @@ GMTETileMap >> vigenerateBackgroundTiles [ ] + +{ + #category : #view, + #'squeak_changestamp' : 'Ivo Zilkenat 7/11/2024 00:33' +} +GMTETileMap >> zoomInAt: aPoint [ + + self view shrinkBy: 0.1. + self centerViewAt: aPoint +] diff --git a/source/GM-TE/GMTEView.class.st b/source/GM-TE/GMTEView.class.st index 2b5353c5..9d55a807 100644 --- a/source/GM-TE/GMTEView.class.st +++ b/source/GM-TE/GMTEView.class.st @@ -4,6 +4,22 @@ Class { #category : #'GM-TE-TileMap' } +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 18:17' +} +GMTEView >> enlargeBy: aFloat [ + + | newExtent | + newExtent := (self extent + (aFloat@aFloat)). + + self flag: 'magic number'. + ((newExtent x > 1) or: [newExtent y > 1]) ifTrue: [^ nil]. + (self isOverlappingOrigin: self origin withExtent: newExtent) ifTrue: [^ nil]. + + self extent: newExtent +] + { #category : #'as yet unclassified', #'squeak_changestamp' : 'Ivo Zilkenat 7/2/2024 20:20' @@ -15,22 +31,80 @@ GMTEView >> extent: anExtent [ { #category : #initialization, - #'squeak_changestamp' : 'Ivo Zilkenat 7/2/2024 19:41' + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 18:15' } GMTEView >> initialize [ "Note: Viewport origin & extent interpreted as fraction of reference view (e.g. Morph)" super initialize. + self reset ] { #category : #'as yet unclassified', - #'squeak_changestamp' : 'Ivo Zilkenat 7/2/2024 20:14' + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 18:05' +} +GMTEView >> isOverlappingOrigin: anOrigin withExtent: anExtent [ + + | corner | + corner := anOrigin + anExtent. + ^ (corner x > 1) or: [corner y > 1] +] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 18:20' +} +GMTEView >> moveTo: anOrigin [ + "Set origin but also respect view not overlapping reference view" + + (self isOverlappingOrigin: anOrigin withExtent: self extent) ifTrue: [^ nil]. + + self origin: anOrigin +] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 18:33' } GMTEView >> origin: aPoint [ - self setOrigin: aPoint corner: self corner + self setOrigin: aPoint corner: (aPoint + self corner) +] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 18:33' +} +GMTEView >> reset [ + + self setOrigin: 0 @ 0 corner: 1 @ 1. + +] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 18:16' +} +GMTEView >> shrinkBy: aFloat [ + + | newExtent | + newExtent := (self extent - (aFloat@aFloat)). + + self flag: 'magic number'. + ((newExtent x <= 0.1) or: [newExtent y <= 0.1]) ifTrue: [^ nil]. + + self extent: newExtent +] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Ivo Zilkenat 7/10/2024 22:53' +} +GMTEView >> size: aFraction [ + + self extent: (aFraction @ aFraction) ] From ec11500cc13d22e6f136aaf669a17cce6938bbc5 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Thu, 11 Jul 2024 17:18:51 +0200 Subject: [PATCH 10/19] moved toolbar down --- source/GM-TE/GMTEEditor.class.st | 54 +++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/source/GM-TE/GMTEEditor.class.st b/source/GM-TE/GMTEEditor.class.st index 9a7814aa..750c25e9 100644 --- a/source/GM-TE/GMTEEditor.class.st +++ b/source/GM-TE/GMTEEditor.class.st @@ -75,6 +75,26 @@ GMTEEditor class >> getVisibilityIndicator: aBoolean [ ifFalse: [^ ' (h)'] ] +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'tw 7/11/2024 17:03' +} +GMTEEditor class >> hLayoutFrame: intI ofN: intN vSymmetric: aFloat [ + + ^ self hLayoutFrame: intI ofN: intN vUp: aFloat down: aFloat +] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'tw 7/11/2024 17:05' +} +GMTEEditor class >> hLayoutFrame: intI ofN: intN vUp: aFloat down: anotherFloat [ + + "useful for building buttons, maybe move this to instance? TODO FLAG" + + ^ LayoutFrame fractions: ((intI - 1 / intN @ aFloat) corner: (intI / intN @ (1 - anotherFloat))) +] + { #category : #constants, #'squeak_changestamp' : 'TW 7/9/2024 11:28' @@ -214,6 +234,15 @@ GMTEEditor class >> tileMapMinPaddingSize [ ^ 0 ] +{ + #category : #constants, + #'squeak_changestamp' : 'tw 7/11/2024 16:52' +} +GMTEEditor class >> toolBarVSpace [ + + ^ 0.1 +] + { #category : #'command processing', #'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 11:56' @@ -737,7 +766,7 @@ GMTEEditor >> createLayersSpecWithBuilder: aBuilder [ { #category : #building, - #'squeak_changestamp' : 'jj 6/22/2024 20:44' + #'squeak_changestamp' : 'tw 7/11/2024 16:46' } GMTEEditor >> createTileViewerSpecWithBuilder: aBuilder [ "creates the spec for the tile viewer" @@ -757,8 +786,7 @@ GMTEEditor >> createTileViewerSpecWithBuilder: aBuilder [ layout: #horizontal; model:self; frame: (LayoutFrame - fractions: (0@0 corner: 1@1) - offsets: (0@30 corner: 0@ 0)) + fractions: (0 @ 0 corner: 1 @ 0.9)) }; minimumExtent:150@150; @@ -788,7 +816,7 @@ GMTEEditor >> createTilestoreSpecWithBuilder: aBuilder [ { #category : #building, - #'squeak_changestamp' : 'tw 7/11/2024 16:26' + #'squeak_changestamp' : 'tw 7/11/2024 17:05' } GMTEEditor >> createToolBarSpecWithBuilder: aBuilder [ "creates the spec for the tool bar" @@ -796,13 +824,13 @@ GMTEEditor >> createToolBarSpecWithBuilder: aBuilder [ ^ (aBuilder pluggablePanelSpec new) name: 'toolbar'; model: self; - frame: (LayoutFrame fractions: (0@0 corner: 1@0) offsets:(0@0 corner: 0@30)); + frame: (LayoutFrame fractions: (0.05@0.9 corner: 0.95@1)); children: { (aBuilder pluggableImageButtonSpec new) name: 'undo'; description: 'Undo'; model: self; - frame: (LayoutFrame fractions: (0 @ 0 corner: (1 / 7) @ 1) offsets: nil); + frame: (GMTEEditor hLayoutFrame: 1 ofN: 7 vSymmetric: GMTEEditor toolBarVSpace); action: #undo; project: 'GameMecha'; path: '/GMTEIcons/undo.png'. @@ -811,7 +839,7 @@ GMTEEditor >> createToolBarSpecWithBuilder: aBuilder [ name: 'redo'; description: 'Redo'; model: self; - frame: (LayoutFrame fractions: ((1 / 7) @ 0 corner: (2 / 7) @ 1) offsets: nil); + frame: (GMTEEditor hLayoutFrame: 2 ofN: 7 vSymmetric: GMTEEditor toolBarVSpace); action: #redo; project: 'GameMecha'; path: '/GMTEIcons/redo.png'. @@ -820,7 +848,7 @@ GMTEEditor >> createToolBarSpecWithBuilder: aBuilder [ name: 'radiusBrush'; description: 'Brush'; model: self; - frame: (LayoutFrame fractions: ((2 / 7) @ 0 corner: (3 / 7) @ 1) offsets: nil); + frame: (GMTEEditor hLayoutFrame: 3 ofN: 7 vSymmetric: GMTEEditor toolBarVSpace); action: #selectRadiusBrush; project: 'GameMecha'; buttonGroup: self brushButtons; @@ -830,7 +858,7 @@ GMTEEditor >> createToolBarSpecWithBuilder: aBuilder [ name: 'lineBrush'; description: 'Line Tool'; model: self; - frame: (LayoutFrame fractions: ((3 / 7) @ 0 corner: (4 / 7) @ 1) offsets: nil); + frame: (GMTEEditor hLayoutFrame: 4 ofN: 7 vSymmetric: GMTEEditor toolBarVSpace); action: #selectLineBrush; project: 'GameMecha'; buttonGroup: self brushButtons; @@ -840,7 +868,7 @@ GMTEEditor >> createToolBarSpecWithBuilder: aBuilder [ name: 'fillBrush'; description: 'Fill Tool'; model: self; - frame: (LayoutFrame fractions: ((4 / 7) @ 0 corner: (5 / 7) @ 1) offsets: nil); + frame: (GMTEEditor hLayoutFrame: 5 ofN: 7 vSymmetric: GMTEEditor toolBarVSpace); action: #selectFillBrush; project: 'GameMecha'; buttonGroup: self brushButtons; @@ -850,7 +878,7 @@ GMTEEditor >> createToolBarSpecWithBuilder: aBuilder [ name: 'rectangleBrush'; description: 'Rectangle Tool'; model: self; - frame: (LayoutFrame fractions: ((5 / 7) @ 0 corner: (6 / 7) @ 1) offsets: nil); + frame: (GMTEEditor hLayoutFrame: 6 ofN: 7 vSymmetric: GMTEEditor toolBarVSpace); action: #selectRectangleBrush; project: 'GameMecha'; buttonGroup: self brushButtons; @@ -861,11 +889,9 @@ GMTEEditor >> createToolBarSpecWithBuilder: aBuilder [ getter: #getBrushRadiusAsString setter: #setBrushRadiusFromText: model: self - frame:(LayoutFrame fractions: ((5.5 / 7) @ 0 corner: 0.95 @ 1) offsets: (20 @ 0 corner: 0 @ 0)). + frame: ((GMTEEditor hLayoutFrame: 7 ofN: 7 vSymmetric: GMTEEditor toolBarVSpace)). }; - - verticalResizing: #shrinkWrap; yourself ] From 4a3595883e15ffa4d31efa7ef0eb39501c29190e Mon Sep 17 00:00:00 2001 From: Ivo Zilkenat Date: Thu, 11 Jul 2024 17:19:29 +0200 Subject: [PATCH 11/19] Readded mouseLeave --- source/GM-TE/GMTEEditorTileMap.class.st | 29 +++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/source/GM-TE/GMTEEditorTileMap.class.st b/source/GM-TE/GMTEEditorTileMap.class.st index 00ac43bf..a30c6f4c 100644 --- a/source/GM-TE/GMTEEditorTileMap.class.st +++ b/source/GM-TE/GMTEEditorTileMap.class.st @@ -80,6 +80,15 @@ GMTEEditorTileMap >> handlesMouseMove: anEvent [ ^ true ] +{ + #category : #'event handling', + #'squeak_changestamp' : 'Ivo Zilkenat 7/11/2024 17:14' +} +GMTEEditorTileMap >> handlesMouseOver: anEvent [ + + ^ true +] + { #category : #initialization, #'squeak_changestamp' : 'Alex M 6/28/2024 20:24' @@ -131,7 +140,18 @@ GMTEEditorTileMap >> mouseDown: anEvent [ { #category : #'event handling', - #'squeak_changestamp' : 'JS 7/11/2024 14:01' + #'squeak_changestamp' : 'Ivo Zilkenat 7/11/2024 17:18' +} +GMTEEditorTileMap >> mouseLeave: anEvent [ + + self tileSelectionSet clearAllHighlightings. + + ^ true +] + +{ + #category : #'event handling', + #'squeak_changestamp' : 'Ivo Zilkenat 7/11/2024 17:01' } GMTEEditorTileMap >> mouseMove: anEvent [ "Implements highlighting of tiles when hovering" @@ -146,9 +166,10 @@ GMTEEditorTileMap >> mouseMove: anEvent [ selectedCoordinates ifNil: [^ nil]. - (selectedCoordinates select: [:c | (self tileMatrixStack layer: activeLayer) inBounds: c]) do: [:t| - hoveredTileHighlighting := self highlightingTileFromIndex: t. - hoveredTileHighlighting ifNotNil: [self tileSelectionSet highlightTile: hoveredTileHighlighting]] + (selectedCoordinates select: [:c | + (self tileMatrixStack layer: activeLayer) inBounds: c]) do: [:t | + hoveredTileHighlighting := self highlightingTileFromIndex: t. + hoveredTileHighlighting ifNotNil: [self tileSelectionSet highlightTile: hoveredTileHighlighting]] ] { From 449925e1ecda4c3368c75dc7274b5402189bb11f Mon Sep 17 00:00:00 2001 From: Valentin Teutschbein Date: Thu, 11 Jul 2024 17:25:13 +0200 Subject: [PATCH 12/19] brush refactoring ... --- source/GM-TE/GMTEBrush.class.st | 73 ++++++++++++++++----------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/source/GM-TE/GMTEBrush.class.st b/source/GM-TE/GMTEBrush.class.st index 6ed05f44..292073e4 100644 --- a/source/GM-TE/GMTEBrush.class.st +++ b/source/GM-TE/GMTEBrush.class.st @@ -12,6 +12,15 @@ Class { #category : #'GM-TE-UI' } +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:01' +} +GMTEBrush class >> borderingOffsets [ + + ^ {(-1)@0. 0@(-1). 1@0. 0@1} +] + { #category : #forms, #'squeak_changestamp' : 'JS 7/11/2024 15:40' @@ -61,10 +70,11 @@ GMTEBrush >> currentMatrixIndex: anObject [ { #category : #'as yet unclassified', - #'squeak_changestamp' : 'JS 7/11/2024 13:59' + #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:10' } GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [ + anIndex ifNil: [^ nil]. self currentMatrixIndex: anIndex. self layer: aLayer. ^ self currentBrush value @@ -72,50 +82,45 @@ GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [ { #category : #forms, - #'squeak_changestamp' : 'JS 7/11/2024 14:07' + #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:10' } GMTEBrush >> fillBrush [ - | collection startTile visited | + | startTile visited | self resetOutputSet. - self currentMatrixIndex ifNil: [^nil]. visited := Matrix rows: (self layer rowCount) columns: self layer columnCount. - collection := OrderedCollection new. startTile := self layer at: self currentMatrixIndex y at: self currentMatrixIndex x. - collection add: self currentMatrixIndex. + self outputSet add: self currentMatrixIndex. visited at: self currentMatrixIndex y at: self currentMatrixIndex x put: true. - self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andCollection: collection. - self outputSet: collection asSet. + self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andSet: self outputSet. ^ self outputSet ] { #category : #forms, - #'squeak_changestamp' : 'JS 7/11/2024 13:58' + #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:05' } -GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile andCollection: aCollection [ +GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile andSet: aSet [ - | borderingOffsets | self flag: 'REFACTOR!'. - borderingOffsets := {(-1)@0. 0@(-1). 1@0. 0@1}. - borderingOffsets do: [:offset | + GMTEBrush borderingOffsets do: [:offset | | newIndex newTile | 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. anOriginTile - ifNil: [newTile ifNil: [aCollection add: newIndex. + ifNil: [newTile ifNil: [aSet add: newIndex. aVisitedMatrix at: newIndex y at: newIndex x put: true. - self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]] + self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andSet: aSet]] ifNotNil: [ (newTile isNil not and: [anOriginTile imageForm bits hash = newTile imageForm bits hash]) ifTrue: [ - aCollection add: newIndex. + aSet add: newIndex. aVisitedMatrix at: newIndex y at: newIndex x put: true. - self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]]] + self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andSet: aSet]]]] ] { @@ -162,18 +167,15 @@ GMTEBrush >> layer: anObject [ { #category : #forms, - #'squeak_changestamp' : 'JS 7/11/2024 16:16' + #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:11' } GMTEBrush >> lineBrush [ - | offsets | self resetOutputSet. - (self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil]. - - offsets := self calculateOffsetsForRadius: self offsetCorrectedRadius. - + self firstMatrixIndex ifNil: [^nil]. + (self rasterizeLineBetweenAStart: self firstMatrixIndex andAnEnd: self currentMatrixIndex) do: [:point | - offsets do: [:offset | + (self calculateOffsetsForRadius: self offsetCorrectedRadius) do: [:offset | self outputSet add: (point + offset)]]. ^(self outputSet) @@ -208,32 +210,29 @@ GMTEBrush >> outputSet: anObject [ { #category : #accessing, - #'squeak_changestamp' : 'Valentin Teutschbein 7/6/2024 12:48' + #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:11' } GMTEBrush >> radius [ + ^ radius ] { #category : #accessing, - #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:08' + #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:15' } -GMTEBrush >> radius: anObject [ - radius := anObject +GMTEBrush >> radius: aNumber [ + + radius := aNumber ] { #category : #forms, - #'squeak_changestamp' : 'JS 7/11/2024 16:14' + #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:09' } GMTEBrush >> radiusBrush [ - | offsets | - self currentMatrixIndex ifNil: [^nil]. - - offsets := self calculateOffsetsForRadius: self offsetCorrectedRadius. - - offsets do: [:i | + (self calculateOffsetsForRadius: self offsetCorrectedRadius) do: [:i | self outputSet add: (self currentMatrixIndex + i)]. ^ self outputSet @@ -280,12 +279,12 @@ GMTEBrush >> rasterizeLineBetweenAStart: aStartPoint andAnEnd: anEndPoint [ { #category : #forms, - #'squeak_changestamp' : 'JS 7/11/2024 16:29' + #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:09' } GMTEBrush >> rectangleBrush [ self resetOutputSet. - (self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil]. + self firstMatrixIndex ifNil: [^ nil]. self flag: 'besser machen?'. (self currentMatrixIndex x min: self firstMatrixIndex x) to: (self currentMatrixIndex x max: self firstMatrixIndex x) do: [:row | From 14d1c9c1be7e0142303744d841f6dd095cb091aa Mon Sep 17 00:00:00 2001 From: Aleksander Morgensterns Date: Thu, 11 Jul 2024 17:40:29 +0200 Subject: [PATCH 13/19] fixed empty delete save request bug --- source/GM-TE/GMTEEditorTileMap.class.st | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/GM-TE/GMTEEditorTileMap.class.st b/source/GM-TE/GMTEEditorTileMap.class.st index 00ac43bf..08972342 100644 --- a/source/GM-TE/GMTEEditorTileMap.class.st +++ b/source/GM-TE/GMTEEditorTileMap.class.st @@ -324,7 +324,7 @@ GMTEEditorTileMap >> updateTileSprite: aTile [ { #category : #updating, - #'squeak_changestamp' : 'JS 7/11/2024 14:01' + #'squeak_changestamp' : 'Alex M 7/11/2024 17:39' } GMTEEditorTileMap >> updateTiles: aCoordinateCollection inLayer: aLayer FromEvent: anEvent [ "Add currently selected tile (model) to editable matrix stack at mouse position" @@ -347,16 +347,16 @@ GMTEEditorTileMap >> updateTiles: aCoordinateCollection inLayer: aLayer FromEven ifTrue: [ aCoordinateCollection do: [:c | | tilePos | - self savePreviousImageFromMatrixCoordinate: c inLayer: aLayer. ((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. tilePos := tile position. tile abandon. self tileMatrixStack layer: aLayer at: c y at: c x put: nil. - self saveNewImageFromPosition: tilePos inLayer: aLayer]. + self saveNewImageFromPosition: tilePos inLayer: aLayer. + self model savedSinceModified: false]. ] - ]. - self model savedSinceModified: false] + ]] ] From 0cab5113bf284f5a8d27158d65ff60059c871bbf Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Thu, 11 Jul 2024 17:57:21 +0200 Subject: [PATCH 14/19] removed tilesizeratio from inspector --- source/GM-TE/GMTEEditor.class.st | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/source/GM-TE/GMTEEditor.class.st b/source/GM-TE/GMTEEditor.class.st index 750c25e9..b18a27a5 100644 --- a/source/GM-TE/GMTEEditor.class.st +++ b/source/GM-TE/GMTEEditor.class.st @@ -637,7 +637,7 @@ GMTEEditor >> createCommandBarSpecWithBuilder: aBuilder [ { #category : #building, - #'squeak_changestamp' : 'jj 6/22/2024 20:42' + #'squeak_changestamp' : 'tw 7/11/2024 17:48' } GMTEEditor >> createInspectorSpecWithBuilder: aBuilder [ "creates the spec for the inspector tab" @@ -652,8 +652,6 @@ GMTEEditor >> createInspectorSpecWithBuilder: aBuilder [ children: { self createAttributeSpecWithBuilder: aBuilder descriptor: 'Padding:' getter: #getPaddingAsString setter: #setPadding: model: self. - self createAttributeSpecWithBuilder: aBuilder descriptor: 'Tile Ratio:' getter: #getTileRatioAsString setter: #setTileRatio: model: self. - self createAttributeSpecWithBuilder: aBuilder descriptor: 'Grid Width:' getter: #getGridWidthAsString setter: #setGridWidth: model: self. self createAttributeSpecWithBuilder: aBuilder descriptor: 'Grid Height:' getter: #getGridHeightAsString setter: #setGridHeight: model: self From 624629ab92c5986f5bdcb4af69799cdc7dd306f2 Mon Sep 17 00:00:00 2001 From: Aleksander Morgensterns Date: Thu, 11 Jul 2024 18:07:56 +0200 Subject: [PATCH 15/19] fixed wrong resizing of layers --- source/GM-TE/GMTEEditor.class.st | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/GM-TE/GMTEEditor.class.st b/source/GM-TE/GMTEEditor.class.st index 750c25e9..076cb7de 100644 --- a/source/GM-TE/GMTEEditor.class.st +++ b/source/GM-TE/GMTEEditor.class.st @@ -665,7 +665,7 @@ GMTEEditor >> createInspectorSpecWithBuilder: aBuilder [ { #category : #building, - #'squeak_changestamp' : 'Alex M 7/10/2024 02:14' + #'squeak_changestamp' : 'Alex M 7/11/2024 18:04' } GMTEEditor >> createLayersSpecWithBuilder: aBuilder [ "creates the spec for layer viewer" @@ -673,6 +673,7 @@ GMTEEditor >> createLayersSpecWithBuilder: aBuilder [ ^ (aBuilder pluggablePanelSpec new) name: 'layer viewer'; model: self; + minimumExtent:150 @ 150; frame: (LayoutFrame fractions: (0.8 @ 0.25 corner: 1 @ 1)); children: { @@ -766,7 +767,7 @@ GMTEEditor >> createLayersSpecWithBuilder: aBuilder [ { #category : #building, - #'squeak_changestamp' : 'tw 7/11/2024 16:46' + #'squeak_changestamp' : 'Alex M 7/11/2024 18:04' } GMTEEditor >> createTileViewerSpecWithBuilder: aBuilder [ "creates the spec for the tile viewer" @@ -789,7 +790,7 @@ GMTEEditor >> createTileViewerSpecWithBuilder: aBuilder [ fractions: (0 @ 0 corner: 1 @ 0.9)) }; - minimumExtent:150@150; + minimumExtent:150 @ 150; yourself ] From 73fe24a7a7cde39cd273f3d91efea286c76dae00 Mon Sep 17 00:00:00 2001 From: Jannis Jost Date: Thu, 11 Jul 2024 18:27:42 +0200 Subject: [PATCH 16/19] Rotating works great --- source/GM-TE/GMTEEditor.class.st | 6 ++++-- source/GM-TE/GMTETileSelectionSet.class.st | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/source/GM-TE/GMTEEditor.class.st b/source/GM-TE/GMTEEditor.class.st index bba90be5..e40eb6cf 100644 --- a/source/GM-TE/GMTEEditor.class.st +++ b/source/GM-TE/GMTEEditor.class.st @@ -1756,12 +1756,14 @@ GMTEEditor >> resetSelectedLayers [ { #category : #TODO, - #'squeak_changestamp' : 'Alex M 6/25/2024 18:26' + #'squeak_changestamp' : 'mcjj 7/11/2024 17:52' } GMTEEditor >> rotateSelectedTile [ self selectedTile: (self selectedTile rotateBy: #right centerAt: (self selectedTile extent / 2)). - self tileMap tileSelectionSet highlightImage: self selectedTile + self tileMap tileSelectionSet removeAllHighlightings. + self tileMap tileSelectionSet highlightImage: self selectedTile. + self tileMap tileSelectionSet applyAllHighlightings ] { diff --git a/source/GM-TE/GMTETileSelectionSet.class.st b/source/GM-TE/GMTETileSelectionSet.class.st index 51ad30b8..44228e7d 100644 --- a/source/GM-TE/GMTETileSelectionSet.class.st +++ b/source/GM-TE/GMTETileSelectionSet.class.st @@ -7,6 +7,17 @@ Class { #category : #'GM-TE-TileMap' } +{ + #category : #highlighting, + #'squeak_changestamp' : 'mcjj 7/11/2024 17:11' +} +GMTETileSelectionSet >> applyAllHighlightings [ + + self do: [:tile | + self applyHighlightingVisuals: tile] + +] + { #category : #highlighting, #'squeak_changestamp' : 'Ivo Zilkenat 6/24/2024 11:51' @@ -71,6 +82,17 @@ GMTETileSelectionSet >> initialize: n [ ] +{ + #category : #highlighting, + #'squeak_changestamp' : 'mcjj 7/11/2024 17:52' +} +GMTETileSelectionSet >> removeAllHighlightings [ + "Remove applied highlightings if any" + + self do: [:tile | + self removeHighlightingVisuals: tile] +] + { #category : #highlighting, #'squeak_changestamp' : 'Ivo Zilkenat 6/24/2024 11:51' From 9beb79eae0d965d3029d8cec517fae602a1fef87 Mon Sep 17 00:00:00 2001 From: Joshua Date: Thu, 11 Jul 2024 18:31:27 +0200 Subject: [PATCH 17/19] improved code a bit --- source/GM-TE/GMTEBrush.class.st | 34 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/source/GM-TE/GMTEBrush.class.st b/source/GM-TE/GMTEBrush.class.st index 292073e4..a97ea5c2 100644 --- a/source/GM-TE/GMTEBrush.class.st +++ b/source/GM-TE/GMTEBrush.class.st @@ -102,25 +102,24 @@ GMTEBrush >> fillBrush [ { #category : #forms, - #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:05' + #'squeak_changestamp' : 'JS 7/11/2024 18:28' } GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile andSet: aSet [ - self flag: 'REFACTOR!'. + GMTEBrush borderingOffsets do: [:offset | - | newIndex newTile | + | 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. - anOriginTile - ifNil: [newTile ifNil: [aSet add: newIndex. + + 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. aVisitedMatrix at: newIndex y at: newIndex x put: true. - self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andSet: aSet]] - ifNotNil: [ - (newTile isNil not and: [anOriginTile imageForm bits hash = newTile imageForm bits hash]) ifTrue: [ - aSet 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 andSet: aSet]]] ] { @@ -241,12 +240,12 @@ GMTEBrush >> radiusBrush [ { #category : #forms, - #'squeak_changestamp' : 'JS 7/11/2024 16:16' + #'squeak_changestamp' : 'JS 7/11/2024 18:26' } GMTEBrush >> rasterizeLineBetweenAStart: aStartPoint andAnEnd: anEndPoint [ "implementation of Bresenhams Line Algorithm" - | collection deltaX deltaY stepX stepY error error2 x y | + | linePointsCollection deltaX deltaY stepX stepY error error2 x y | self flag: 'todo: method extraction? - Ich glaube geht schlecht'. @@ -258,14 +257,14 @@ GMTEBrush >> rasterizeLineBetweenAStart: aStartPoint andAnEnd: anEndPoint [ x := aStartPoint x. y := aStartPoint y. - collection := OrderedCollection new. + linePointsCollection := OrderedCollection new. [ | point | point := x @ y. - collection add: point. + linePointsCollection add: point. (x = anEndPoint x and: [y = anEndPoint y]) ifTrue: [ - ^collection]. + ^linePointsCollection]. error2 := 2 * error. (error2 > (0 - deltaY)) ifTrue: [ error := error - deltaY. @@ -279,14 +278,13 @@ GMTEBrush >> rasterizeLineBetweenAStart: aStartPoint andAnEnd: anEndPoint [ { #category : #forms, - #'squeak_changestamp' : 'Valentin Teutschbein 7/11/2024 17:09' + #'squeak_changestamp' : 'JS 7/11/2024 17:34' } GMTEBrush >> rectangleBrush [ self resetOutputSet. self firstMatrixIndex ifNil: [^ nil]. - self flag: 'besser machen?'. (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)]]. From 1f9e8985b2740518924a50b6ab647754c2110118 Mon Sep 17 00:00:00 2001 From: Jannis Jost Date: Fri, 12 Jul 2024 00:21:52 +0200 Subject: [PATCH 18/19] i love squeak can't even handle shi(f)t --- source/GM-TE/GMTEEditor.class.st | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/source/GM-TE/GMTEEditor.class.st b/source/GM-TE/GMTEEditor.class.st index 5a785de9..fedd96b3 100644 --- a/source/GM-TE/GMTEEditor.class.st +++ b/source/GM-TE/GMTEEditor.class.st @@ -1061,7 +1061,7 @@ GMTEEditor >> exportMenu [ { #category : #'input handling', - #'squeak_changestamp' : 'mcjj 7/11/2024 15:57' + #'squeak_changestamp' : 'mcjj 7/12/2024 00:19' } GMTEEditor >> filterEvent: aKeyboardEvent for: anObject [ | key | @@ -1069,22 +1069,15 @@ GMTEEditor >> filterEvent: aKeyboardEvent for: anObject [ aKeyboardEvent isKeystroke ifFalse: [^ aKeyboardEvent]. - key := aKeyboardEvent key. - + key := aKeyboardEvent keyCharacter. + aKeyboardEvent commandKeyPressed ifTrue: [ - aKeyboardEvent shiftPressed - ifTrue: [ - key caseOf: { - [$Z] -> [self redo]. - } otherwise: [^ aKeyboardEvent "no hit"]. - ^ aKeyboardEvent ignore "hit"] - ifFalse: [ - key caseOf: { - [$Z] -> [self undo]. - [$Y] -> [self redo]. - [$R] -> [self rotateSelectedTile]. - } otherwise: [^ aKeyboardEvent "no hit"]. - ^ aKeyboardEvent ignore "hit"]]. + key caseOf: { + [$z] -> [self undo]. + [$y] -> [self redo]. + [$r] -> [self rotateSelectedTile]. + } otherwise: [^ aKeyboardEvent "no hit"]. + ^ aKeyboardEvent ignore "hit"]. ^ aKeyboardEvent "no hit" ] From 42b77fe94144550d2fa45d651f0872e25bfd6dea Mon Sep 17 00:00:00 2001 From: Joshua Date: Fri, 12 Jul 2024 11:33:26 +0200 Subject: [PATCH 19/19] method extraction --- source/GM-TE/GMTEEditorTileMap.class.st | 75 ++++++++++++++----------- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/source/GM-TE/GMTEEditorTileMap.class.st b/source/GM-TE/GMTEEditorTileMap.class.st index 430f16ec..5de7b5f5 100644 --- a/source/GM-TE/GMTEEditorTileMap.class.st +++ b/source/GM-TE/GMTEEditorTileMap.class.st @@ -62,6 +62,24 @@ GMTEEditorTileMap >> currentTileChanges: anObject [ currentTileChanges := anObject ] +{ + #category : #updating, + #'squeak_changestamp' : 'JS 7/12/2024 11:30' +} +GMTEEditorTileMap >> deleteTiles: aCoordinateCollection inLayer: aLayer [ + "delete tiles from editable matrix stack at given indices" + + | tile | + aCoordinateCollection 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. + tile abandon. + self tileMatrixStack layer: aLayer at: c y at: c x put: nil. + self saveNewImageFromPosition: tile position inLayer: aLayer]]]. +] + { #category : #'event handling', #'squeak_changestamp' : 'jj 6/23/2024 13:35' @@ -190,6 +208,24 @@ GMTEEditorTileMap >> mouseUp: anEvent [ ] +{ + #category : #updating, + #'squeak_changestamp' : 'JS 7/12/2024 11:30' +} +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 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]. + self updateTileSprite: tile. + self saveNewImageFromPosition: tile position inLayer: aLayer]]. + +] + { #category : #accessing, #'squeak_changestamp' : 'Alex M 6/28/2024 19:44' @@ -345,39 +381,14 @@ GMTEEditorTileMap >> updateTileSprite: aTile [ { #category : #updating, - #'squeak_changestamp' : 'Alex M 7/11/2024 17:39' + #'squeak_changestamp' : 'JS 7/12/2024 11:31' } GMTEEditorTileMap >> updateTiles: aCoordinateCollection inLayer: aLayer FromEvent: anEvent [ - "Add currently selected tile (model) to editable matrix stack at mouse position" - | tile | - self flag: 'refactor'. + (self tileIndexFromPosition: anEvent position) ifNil: [^ nil]. - (anEvent redButtonChanged and: [self model selectedTile notNil]) - ifTrue: [ - aCoordinateCollection do: [:c | - self savePreviousImageFromMatrixCoordinate: 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]. - self updateTileSprite: tile. - self saveNewImageFromPosition: tile position inLayer: aLayer] - ]. - self model savedSinceModified: false]. - (anEvent yellowButtonChanged) - ifTrue: [ - aCoordinateCollection do: [:c | - | tilePos | - ((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. - tilePos := tile position. - tile abandon. - self tileMatrixStack layer: aLayer at: c y at: c x put: nil. - self saveNewImageFromPosition: tilePos inLayer: aLayer. - self model savedSinceModified: false]. - ] - ]] + + (anEvent redButtonChanged and: [self model selectedTile notNil]) ifTrue: [self placeTiles: aCoordinateCollection inLayer: aLayer]. + (anEvent yellowButtonChanged) ifTrue: [self deleteTiles: aCoordinateCollection inLayer: aLayer]. + + self model savedSinceModified: false ]