优化性能,分三层渲染
This commit is contained in:
parent
37c34d7991
commit
fcac5386e0
59
painter.js
59
painter.js
@ -73,16 +73,19 @@ Component({
|
|||||||
},
|
},
|
||||||
|
|
||||||
doAction(newVal) {
|
doAction(newVal) {
|
||||||
this.hasIdViews.map(view => {
|
if (newVal && newVal.css) {
|
||||||
if (view.id === newVal.id) {
|
if (Array.isArray(this.touchedView.css)) {
|
||||||
if (Array.isArray(view.css)) {
|
this.touchedView.css = [...this.touchedView.css, newVal.css]
|
||||||
view.css = [...view.css, newVal.css]
|
|
||||||
} else {
|
} else {
|
||||||
view.css = [view.css, newVal.css]
|
this.touchedView.css = [this.touchedView.css, newVal.css]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
const draw = {
|
||||||
const pen = new Pen(this.globalContext, this.currentPalette);
|
width: this.currentPalette.width,
|
||||||
|
height: this.currentPalette.height,
|
||||||
|
views: [this.touchedView]
|
||||||
|
}
|
||||||
|
const pen = new Pen(this.globalContext, draw);
|
||||||
pen.paint();
|
pen.paint();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -96,26 +99,58 @@ Component({
|
|||||||
} = event.touches[0]
|
} = event.touches[0]
|
||||||
this.startX = x
|
this.startX = x
|
||||||
this.startY = y
|
this.startY = y
|
||||||
for (let view of this.hasIdViews.reverse()) {
|
const totalLayerCount = this.currentPalette.views.length
|
||||||
|
let findedIndex = -1;
|
||||||
|
this.touchedView = {}
|
||||||
|
for (let i = totalLayerCount - 1; i >= 0; i--) {
|
||||||
|
const view = this.currentPalette.views[i]
|
||||||
if (x > view.rect.left && y > view.rect.top && x < view.rect.right && y < view.rect.bottom) {
|
if (x > view.rect.left && y > view.rect.top && x < view.rect.right && y < view.rect.bottom) {
|
||||||
if (view.id) {
|
if (view.id) {
|
||||||
this.touchedView = view
|
this.touchedView = view
|
||||||
this.triggerEvent('viewTouchStart', {
|
this.triggerEvent('touchStart', {
|
||||||
id: view.id,
|
id: view.id,
|
||||||
css: view.css
|
css: view.css,
|
||||||
|
rect: view.rect
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
findedIndex = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (findedIndex < 0) {
|
||||||
|
// 证明点击了背景
|
||||||
|
this.triggerEvent('touchStart', {})
|
||||||
|
} else if (this.touchedView.id) {
|
||||||
|
const bottomLayers = this.currentPalette.views.slice(0, findedIndex)
|
||||||
|
const topLayers = this.currentPalette.views.slice(findedIndex + 1)
|
||||||
|
const bottomDraw = {
|
||||||
|
width: this.currentPalette.width,
|
||||||
|
height: this.currentPalette.height,
|
||||||
|
background: this.currentPalette.background,
|
||||||
|
views: bottomLayers
|
||||||
|
}
|
||||||
|
new Pen(wx.createCanvasContext('bottom', this), bottomDraw).paint();
|
||||||
|
|
||||||
|
const topDraw = {
|
||||||
|
width: this.currentPalette.width,
|
||||||
|
height: this.currentPalette.height,
|
||||||
|
views: topLayers
|
||||||
|
}
|
||||||
|
new Pen(wx.createCanvasContext('top', this), topDraw).paint();
|
||||||
|
|
||||||
|
this.doAction()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onTouchEnd() {
|
onTouchEnd() {
|
||||||
this.touchedView = {}
|
this.touchedView = {}
|
||||||
|
this.triggerEvent('touchEnd')
|
||||||
},
|
},
|
||||||
|
|
||||||
onTouchCancel() {
|
onTouchCancel() {
|
||||||
this.touchedView = {}
|
this.touchedView = {}
|
||||||
|
this.triggerEvent('touchCancel')
|
||||||
},
|
},
|
||||||
|
|
||||||
onTouchMove(event) {
|
onTouchMove(event) {
|
||||||
@ -140,6 +175,10 @@ Component({
|
|||||||
id: this.touchedView.id,
|
id: this.touchedView.id,
|
||||||
css
|
css
|
||||||
})
|
})
|
||||||
|
this.triggerEvent('touchMove',{
|
||||||
|
id: this.touchedView.id,
|
||||||
|
css
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
startPaint() {
|
startPaint() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user