Skip to content

Commit

Permalink
added line brush with radius
Browse files Browse the repository at this point in the history
  • Loading branch information
valteu committed Jul 9, 2024
1 parent c5cbbf3 commit cdb5cfd
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
Binary file modified GMTEIcons/redo.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 GMTEIcons/undo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions source/GM-TE/GMTEBrush.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions source/GM-TE/GMTEEditor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -1246,7 +1246,7 @@ GMTEEditor >> initializeBrush [
brush: GMTEBrush new;
selectRadiusBrush;
initializeBrushButton;
setBrushRadius: 0
setBrushRadius: 1
]

{
Expand Down

0 comments on commit cdb5cfd

Please sign in to comment.