Skip to content

Commit

Permalink
Implemented rescaling of Tile Viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivo Zilkenat committed May 20, 2024
1 parent b8c8b89 commit 9fe8bf6
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 81 deletions.
72 changes: 14 additions & 58 deletions source/GM-TE/GMTEEditor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Alex M 5/20/2024 15:46'
#'squeak_changestamp' : 'TW 5/19/2024 17:18'
}
GMTEEditor class >> createCommandBarWithBuilder: aBuilder [
^aBuilder pluggablePanelSpec new
name: 'command bar';
children: {aBuilder pluggableButtonSpec new
name: 'export';
label: 'Export';
frame: (LayoutFrame fractions: (0 @ 0 corner: 0.3 @ 1) offsets: nil).
aBuilder pluggableButtonSpec new
frame: (LayoutFrame fractions: (0.3 @ 0 corner: 0.6 @ 1) offsets: nil);
action: [GMTEEditor loadTileSetWithDimensions: 16@16];
name: 'import';
label: 'Import'.
aBuilder pluggableButtonSpec new
frame: (LayoutFrame fractions: (0.6 @ 0 corner: 0.9 @ 1) offsets: nil);
name: 'openInWorld';
label: 'Open in World'};
frame: (LayoutFrame fractions: (0 @ 0 corner: 1 @ 0.1) offsets: nil);
yourself
Expand All @@ -41,23 +37,23 @@ GMTEEditor class >> createLayersWithBuilder: aBuilder [

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Alex M 5/20/2024 15:44'
#'squeak_changestamp' : 'JS 5/19/2024 17:12'
}
GMTEEditor class >> createTileViewerWithBuilder: aBuilder [
^aBuilder pluggablePanelSpec new
name: 'tile viewer';
name: 'Tile Viewer';
layout: #horizontal;
frame: (LayoutFrame fractions: (0.2 @ 0.1 corner: 0.8 @ 0.8) offsets: nil);
yourself
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Alex M 5/20/2024 16:46'
#'squeak_changestamp' : 'TW 5/19/2024 17:28'
}
GMTEEditor class >> createTilestoreWithBuilder: aBuilder [

^aBuilder pluggableScrollPaneSpec new
^aBuilder pluggablePanelSpec new
frame: ((0 @ 0.1) corner: 0.2 @ 1);
name: 'tile store';
layout: #vertical;
Expand All @@ -83,48 +79,11 @@ GMTEEditor class >> createTrayWithBuilder: aBuilder [

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Alex M 5/20/2024 17:44'
}
GMTEEditor class >> loadTileSetWithDimensions: aPoint [

"Do we really leaves this here or do we create an extra class for"

| fc stream form tile tile_width tile_height image morphs|

fc := FileChooser new.
fc initializeAsSystemWindowWithCaptionPane.
fc setCaption: 'Select a picture file' translated.
fc setSuffixes: {'png' . 'gif' . 'bmp' . 'jpg' . 'jpeg' }.
stream := fc open.

stream ifNil: [^ nil].

form := Form fromBinaryStream: stream.

morphs := OrderedCollection new.

tile_width := aPoint x.
tile_height := aPoint y.
"TODO: refactor into non C-like code"
0 to: (form height - tile_height) by: tile_height do:[:y|
0 to: (form width - tile_width) by: tile_width do: [:x|
tile := form contentsOfArea: (Rectangle origin: x@y extent: tile_width@tile_height).
image := GMTETileSelector new
image: (tile scaledToWidth: 50).
morphs add: image.
].
].

^ morphs.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Alex M 5/20/2024 17:43'
#'squeak_changestamp' : 'Ivo Zilkenat 5/20/2024 19:57'
}
GMTEEditor class >> new [

|builder spec morph tileMatrixMorph tileStore tileViewer commandBar|
|builder spec morph tileMatrixMorph tileStore tileViewer|
super new.
builder := ToolBuilder default.
spec := builder pluggableWindowSpec new
Expand All @@ -138,18 +97,15 @@ GMTEEditor class >> new [
self createLayersWithBuilder: builder};
yourself.
morph := builder build: spec.
commandBar := morph submorphNamed: 'command bar'.
tileStore := morph submorphNamed: 'tile store'.
tileViewer := morph submorphNamed: 'tile viewer'.

"TODO 16 by 16 is a magic number. Where do we store tile dimensions?"
(commandBar submorphNamed: 'import') action: [
"TODO make multiple sprite sets available?"
tileStore morph removeAllMorphs;
addAllMorphs: (GMTEEditor loadTileSetWithDimensions: 16@16).
].
tileViewer := (morph submorphNamed: 'Tile Viewer').

tileStore addMorph: Morph new.
tileStore addMorph: (Morph new
color: Color red;
yourself).

tileMatrixMorph := GMTETileMap tileWidth: 10 tileHeight: 10 padding: 0.0 sizeRatio: 2.
tileMatrixMorph := GMTETileMap tileWidth: 20 tileHeight: 20 padding: 0.15 sizeRatio: 1.

tileViewer addMorph: tileMatrixMorph.

Expand Down
37 changes: 29 additions & 8 deletions source/GM-TE/GMTETileMap.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,23 @@ GMTETileMap >> borderTileWidth: anObject [
]

{
#category : #'import/export',
#'squeak_changestamp' : 'Alex M 5/20/2024 13:15'
#category : #updating,
#'squeak_changestamp' : 'Ivo Zilkenat 5/20/2024 19:49'
}
GMTETileMap >> clearTiles [

self gridTileMatrix do: [:aTile | aTile delete].
]

{
#category : #updating,
#'squeak_changestamp' : 'Ivo Zilkenat 5/20/2024 19:55'
}
GMTETileMap >> exportAsImage [
"Add further options in the future like choosing file format?"
self exportAsPNG
GMTETileMap >> extent: aPoint [

self gridTileMatrix ifNotNil: [self rescaleMap].

super extent: aPoint.
]

{
Expand Down Expand Up @@ -323,16 +334,26 @@ GMTETileMap >> processTiles [

{
#category : #updating,
#'squeak_changestamp' : 'Ivo Zilkenat 5/19/2024 15:57'
#'squeak_changestamp' : 'Ivo Zilkenat 5/20/2024 19:50'
}
GMTETileMap >> rescaleMap [
"comment stating purpose of message"

self rescaleMapWidth: self tileWidth height: self tileHeight padding: self mapPadding
]

{
#category : #updating,
#'squeak_changestamp' : 'Ivo Zilkenat 5/20/2024 19:50'
}
GMTETileMap >> rescaleMapWidth: aWidth height: aHeigth padding: aPadding [
"Rescale map & trigger update"

"Warning: If padding is to small relative to map, divisions by zero can occur"

self gridTileMatrix do: [:aTile | aTile delete].
self clearTiles.
self setDimensionsWidth: aWidth height: aHeigth padding: aPadding.
self updateGrid
self updateMap.

]

Expand Down
15 changes: 0 additions & 15 deletions source/GM-TE/GMTETileSelector.class.st

This file was deleted.

Binary file modified testingResources/squeak.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified testingResources/squeak2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9fe8bf6

Please sign in to comment.