whiteboard/src/Background.js

36 lines
714 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 背景
export default class Background {
constructor(app) {
this.app = app
}
// 设置背景
set() {
if (this.app.state.backgroundColor) {
this.addBackgroundColor()
} else {
this.remove()
}
}
// 添加背景颜色
addBackgroundColor() {
this.app.container.style.backgroundColor = this.app.state.backgroundColor
}
// 移除背景
remove() {
this.app.container.style.backgroundColor = ''
}
// 在canvas内设置背景颜色非css样式
canvasAddBackgroundColor(ctx, width, height, backgroundColor) {
// 背景颜色
ctx.save()
ctx.rect(0, 0, width, height)
ctx.fillStyle = backgroundColor
ctx.fill()
ctx.restore()
}
}