From cdb5cfd5a2d11e10df7ffa9fb4f162ab37f5371c Mon Sep 17 00:00:00 2001 From: Valentin Teutschbein Date: Tue, 9 Jul 2024 22:55:37 +0200 Subject: [PATCH] added line brush with radius --- GMTEIcons/redo.png | Bin 1227 -> 1227 bytes GMTEIcons/undo.png | Bin 1227 -> 1227 bytes source/GM-TE/GMTEBrush.class.st | 64 +++++++++++++++++++++++++++++++ source/GM-TE/GMTEEditor.class.st | 4 +- 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/GMTEIcons/redo.png b/GMTEIcons/redo.png index 28d411a4e9ac846a11c3b4561adbaa61d6d81bc3..e39b6c33be7672e840865370b34299e91ba0c8ab 100644 GIT binary patch delta 36 rcmX@jd75*A;pU%=28@%K8kzt9|G)VoqXm%7!}5Kf_qENs%<~ulA>a=; literal 1227 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=3?wxlRx~p(Ff#=Bgt!8^V893?fs9c!1VZ5d z|Nqda8>J`+fv+A6i$E#9B*-tA0T`x(4N%}UlC^rQ^Ii?qRORX77*Y}U^r|CYg949B z;J?56Z`*o1Wq+udxut9OyJVcMaAeS5b5QyMNB#%4d+)ae*L^m~c+IK8`a?_FPRAxKd%A1o)e`^ZkM4=Tv$fVu g`7__+v+Sjb%)Ua*VeAs`gg{RBboFyt=akR{0FIB}k^lez diff --git a/GMTEIcons/undo.png b/GMTEIcons/undo.png index facd074b081821f4d15fde3b8e22a86e35a3ca12..7e81921bb7fe650e49d2d68bd7f1ac90dccb8f07 100644 GIT binary patch delta 36 rcmX@jd75*A;pU%=28@%K8kzt9|G)VoqXm%7!}5Kf_qENs%<~ulA>a=; literal 1227 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=3?wxlRx~p(Ff#=Bgt!8^V893?fs9c!1VZ5d z|Nqda8>J`+fv+A6i$E#9B*-tA0T`x(4N%}UlC^rQ^Ii?qRORX77*Y}U^r|;kgMk3c z#VddH-zx18@KHAv5P6$=D4OTYa$C^@+?g9#bR30E4hn5x@!in!yFyUmb48)6&T{u!;mrU5 diff --git a/source/GM-TE/GMTEBrush.class.st b/source/GM-TE/GMTEBrush.class.st index 95036485..ee4ac87e 100644 --- a/source/GM-TE/GMTEBrush.class.st +++ b/source/GM-TE/GMTEBrush.class.st @@ -145,6 +145,61 @@ GMTEBrush >> layer: anObject [ layer := anObject ] +{ + #category : #forms, + #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:53' +} +GMTEBrush >> lineBrush [ + | radius collection start end deltaX deltaY stepX stepY error error2 x y offsets | + + 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. + +] + { #category : #accessing, #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:18' @@ -255,6 +310,15 @@ GMTEBrush >> selectFillBrush [ self currentBrush: [self fillBrush] ] +{ + #category : #select, + #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:27' +} +GMTEBrush >> selectLineBrush [ + + self currentBrush: [self lineBrush] +] + { #category : #select, #'squeak_changestamp' : 'TW 7/9/2024 19:18' diff --git a/source/GM-TE/GMTEEditor.class.st b/source/GM-TE/GMTEEditor.class.st index 93ef3c13..3af3f074 100644 --- a/source/GM-TE/GMTEEditor.class.st +++ b/source/GM-TE/GMTEEditor.class.st @@ -1237,7 +1237,7 @@ GMTEEditor >> initialize [ { #category : #initialization, - #'squeak_changestamp' : 'TW 7/9/2024 19:42' + #'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:40' } GMTEEditor >> initializeBrush [ "starts the tile editor" @@ -1246,7 +1246,7 @@ GMTEEditor >> initializeBrush [ brush: GMTEBrush new; selectRadiusBrush; initializeBrushButton; - setBrushRadius: 0 + setBrushRadius: 1 ] {