From af9212d02d785dd1420bcc69c1a2c246b5debe52 Mon Sep 17 00:00:00 2001 From: Ivo Zilkenat Date: Thu, 11 Jul 2024 16:55:07 +0200 Subject: [PATCH 1/2] 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 4a3595883e15ffa4d31efa7ef0eb39501c29190e Mon Sep 17 00:00:00 2001 From: Ivo Zilkenat Date: Thu, 11 Jul 2024 17:19:29 +0200 Subject: [PATCH 2/2] 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]] ] {