Skip to content

Commit cdb5cfd

Browse files
committed
added line brush with radius
1 parent c5cbbf3 commit cdb5cfd

File tree

4 files changed

+66
-2
lines changed

4 files changed

+66
-2
lines changed

GMTEIcons/redo.png

0 Bytes
Loading

GMTEIcons/undo.png

0 Bytes
Loading

source/GM-TE/GMTEBrush.class.st

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,61 @@ GMTEBrush >> layer: anObject [
145145
layer := anObject
146146
]
147147

148+
{
149+
#category : #forms,
150+
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:53'
151+
}
152+
GMTEBrush >> lineBrush [
153+
| radius collection start end deltaX deltaY stepX stepY error error2 x y offsets |
154+
155+
radius := self radius - 1.
156+
self resetOutputSet.
157+
self flag: 'todo: method extraction'.
158+
"Helper method to generate radius offsets"
159+
offsets := OrderedCollection new.
160+
(0-radius to: radius) do: [:dx |
161+
(0-radius to: radius) do: [:dy |
162+
(dx * dx + dy * dy <= (radius * radius)) ifTrue: [
163+
offsets add: dx @ dy.
164+
].
165+
].
166+
].
167+
168+
self resetOutputSet.
169+
(self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil].
170+
171+
start := self firstMatrixIndex.
172+
end := self currentMatrixIndex.
173+
deltaX := (end x - start x) abs.
174+
deltaY := (end y - start y) abs.
175+
stepX := (start x < end x) ifTrue: [1] ifFalse: [-1].
176+
stepY := (start y < end y) ifTrue: [1] ifFalse: [-1].
177+
error := deltaX - deltaY.
178+
x := start x.
179+
y := start y.
180+
181+
collection := OrderedCollection new.
182+
183+
[
184+
| point |
185+
point := x @ y.
186+
offsets do: [:offset | collection add: (point + offset)].
187+
(x = end x and: [y = end y]) ifTrue: [
188+
self outputSet: collection asSet.
189+
^ self outputSet.].
190+
error2 := 2 * error.
191+
(error2 > (0 - deltaY)) ifTrue: [
192+
error := error - deltaY.
193+
x := x + stepX.
194+
].
195+
(error2 < deltaX) ifTrue: [
196+
error := error + deltaX.
197+
y := y + stepY.
198+
].
199+
] repeat.
200+
201+
]
202+
148203
{
149204
#category : #accessing,
150205
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:18'
@@ -255,6 +310,15 @@ GMTEBrush >> selectFillBrush [
255310
self currentBrush: [self fillBrush]
256311
]
257312

313+
{
314+
#category : #select,
315+
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:27'
316+
}
317+
GMTEBrush >> selectLineBrush [
318+
319+
self currentBrush: [self lineBrush]
320+
]
321+
258322
{
259323
#category : #select,
260324
#'squeak_changestamp' : 'TW 7/9/2024 19:18'

source/GM-TE/GMTEEditor.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ GMTEEditor >> initialize [
12371237

12381238
{
12391239
#category : #initialization,
1240-
#'squeak_changestamp' : 'TW 7/9/2024 19:42'
1240+
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:40'
12411241
}
12421242
GMTEEditor >> initializeBrush [
12431243
"starts the tile editor"
@@ -1246,7 +1246,7 @@ GMTEEditor >> initializeBrush [
12461246
brush: GMTEBrush new;
12471247
selectRadiusBrush;
12481248
initializeBrushButton;
1249-
setBrushRadius: 0
1249+
setBrushRadius: 1
12501250
]
12511251

12521252
{

0 commit comments

Comments
 (0)