Skip to content

Commit

Permalink
chore: small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Feb 16, 2024
1 parent 5b1d20e commit 723ec67
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/painter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ export default class Painter extends Component<IOptions> {

this.resizeSensor.addListener(this.onResize)

this.zoom.on('change', (ratio) => {
this.currentTool.onZoom(ratio)
this.zoom.on('change', () => {
this.currentTool.onZoom()
this.resetViewport()
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/painter/tools/Brush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ export default class Brush extends Tool {
this.commitDraw(this.ctx)
}
}
onZoom(ratio: number) {
super.onZoom(ratio)
onZoom() {
super.onZoom()
this.cursorCircle.render()
}
private draw(x: number, y: number) {
Expand Down
4 changes: 2 additions & 2 deletions src/painter/tools/Eraser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export default class Eraser extends Tool {
onAfterRenderLayer(layer: Layer) {
this.getTool().onAfterRenderLayer(layer)
}
onZoom(ratio: number) {
super.onZoom(ratio)
onZoom() {
super.onZoom()
this.cursorCircle.render()
}
private getTool(): Brush | Pencil {
Expand Down
4 changes: 2 additions & 2 deletions src/painter/tools/Pencil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ export default class Pencil extends Tool {
this.commitDraw(this.ctx)
}
}
onZoom(ratio: number) {
super.onZoom(ratio)
onZoom() {
super.onZoom()
this.cursorCircle.render()
}
protected renderToolbar() {
Expand Down
9 changes: 4 additions & 5 deletions src/painter/tools/Tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import $ from 'licia/$'
import h from 'licia/h'
import Emitter from 'licia/Emitter'
import types from 'licia/types'
import Zoom from './Zoom'
import { eventPage } from '../../share/util'
import LunaToolbar from 'luna-toolbar'

Expand All @@ -24,7 +25,6 @@ export default class Tool extends Emitter {
protected toolbar: LunaToolbar
protected options: types.PlainObj<any> = {}
protected isUsing = false
private zoomRatio = 1
constructor(painter: Painter) {
super()
this.painter = painter
Expand Down Expand Up @@ -101,9 +101,6 @@ export default class Tool extends Emitter {
})
}
}
onZoom(ratio: number) {
this.zoomRatio = ratio
}
/* eslint-disable @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars */
onMouseEnter(e: any) {
this.$cursor.css({
Expand All @@ -115,6 +112,7 @@ export default class Tool extends Emitter {
opacity: 0,
})
}
onZoom() {}
onAfterRenderLayer(layer: Layer) {}
protected renderToolbar() {
this.toolbar.clear()
Expand All @@ -125,7 +123,8 @@ export default class Tool extends Emitter {
const pageX = eventPage('x', e)
const pageY = eventPage('y', e)

const ratio = this.zoomRatio
const zoom = this.painter.getTool('zoom') as Zoom
const ratio = zoom.getRatio()
const x = Math.floor((pageX - offset.left) / ratio)
const y = Math.floor((pageY - offset.top) / ratio)

Expand Down
2 changes: 1 addition & 1 deletion src/painter/tools/Zoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class Zoom extends Tool {
})
viewport.scrollLeft = target.scrollLeft
viewport.scrollTop = target.scrollTop
this.emit('change', this.ratio)
this.emit('change')
})
.on('end', () => {
this.isZooming = false
Expand Down

0 comments on commit 723ec67

Please sign in to comment.