Skip to content

Commit

Permalink
refactor: brush rename
Browse files Browse the repository at this point in the history
  • Loading branch information
gnlow committed Dec 31, 2023
1 parent efa7c42 commit e4b8383
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/Entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,9 @@ export class Entry {
return str
}
start_drawing(obj: EntryBrush) {
const { graphics, lineListener } = obj.getBrush(graphics => {
const { graphics, lineListener } = obj.getStrokeBrush(graphics => {
obj.addSibling(this, graphics, 0)
obj.hasBrush = true
obj.hasStrokeBrush = true
})
graphics.moveTo(
obj.pixiSprite.x,
Expand Down Expand Up @@ -582,9 +582,9 @@ export class Entry {
obj.brushTransparency = n
}
brush_erase_all(obj: EntryBrush) {
obj._brushGraphics?.destroy()
delete obj._brushGraphics
obj.hasBrush = false
obj._strokeBrush?.destroy()
delete obj._strokeBrush
obj.hasStrokeBrush = false
this.stop_drawing(obj)
}

Expand Down
32 changes: 16 additions & 16 deletions src/obj/EntryBrush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ export abstract class EntryBrush extends EntryContainer {
sprite._brushTransparency = this._brushTransparency
}

hasBrush = false
_brushGraphics?: Graphics
hasStrokeBrush = false
_strokeBrush?: Graphics
_lineListener?: () => void
getBrush(onGraphicsInit?: (graphics: Graphics) => void) {
if (!this._brushGraphics) {
this._brushGraphics = new Graphics()
getStrokeBrush(onGraphicsInit?: (graphics: Graphics) => void) {
if (!this._strokeBrush) {
this._strokeBrush = new Graphics()
this.strokeColor = this.strokeColor
this.strokeThickness = this.strokeThickness
this.brushTransparency = this.brushTransparency

this._lineListener = () => {
this._brushGraphics!.lineTo(
this._strokeBrush!.lineTo(
this.pixiSprite.x,
this.pixiSprite.y,
)
this._brushGraphics!.stroke()
this._strokeBrush!.stroke()
}
onGraphicsInit?.(this._brushGraphics)
onGraphicsInit?.(this._strokeBrush)
}
return {
graphics: this._brushGraphics!,
graphics: this._strokeBrush!,
lineListener: this._lineListener!,
}
}
Expand All @@ -47,8 +47,8 @@ export abstract class EntryBrush extends EntryContainer {
/*
https://github.com/pixijs/pixijs/blob/v8.0.0-beta.11/src/scene/graphics/shared/utils/convertFillInputToFillStyle.ts#L92
*/
if (this._brushGraphics) {
this._brushGraphics.strokeStyle.color = Color.shared.setValue(color).toNumber()
if (this._strokeBrush) {
this._strokeBrush.strokeStyle.color = Color.shared.setValue(color).toNumber()
}
}

Expand All @@ -58,8 +58,8 @@ export abstract class EntryBrush extends EntryContainer {
}
set strokeThickness(n: number) {
this._strokeThickness = n
if (this._brushGraphics) {
this._brushGraphics.strokeStyle.width = n
if (this._strokeBrush) {
this._strokeBrush.strokeStyle.width = n
}
}

Expand All @@ -69,8 +69,8 @@ export abstract class EntryBrush extends EntryContainer {
}
set brushTransparency(n: number) {
this._brushTransparency = n
if (this._brushGraphics) {
this._brushGraphics.alpha = 1 - n / 100
if (this._strokeBrush) {
this._strokeBrush.alpha = 1 - n / 100
}
}
addSibling(
Expand All @@ -84,7 +84,7 @@ export abstract class EntryBrush extends EntryContainer {
target,
myPos
+ relativePos
+ (this.hasBrush ? -1 : 0)
+ (this.hasStrokeBrush ? -1 : 0)
)
}
}

0 comments on commit e4b8383

Please sign in to comment.