Quark-Renderer ---第五篇
2021SC@SDUSC
总括
在上篇博客中,我们完成了对canvasLayer.js的分析,这篇我们主要对canvas文件夹下的另一篇js文件进行学习。
该文件为CanvasPainter.js,该文件是一个基于w3c canvas接口的canvasPainter类。在该类中,定义了构造函数、refresh()函数、addHover()函数、removeHover()函数、clearHover()函数、refreshHover()函数、_paintList()函数、_compositeManually()函数、_doPaintList()函数以及一些get函数等函数,这次我们主要围绕着这几个函数进行学习研究。
分析
对于该canvasPainter类,他的构造函数无疑是最重要的一个方法。再他的构造函数中,传入了三个参数,分别是host(类型:HTMLDomElement|Canvas|Context)、storage(类型:qrenderer.core.Storage)、options(类型:对象Object)。再构造函数中,分别对对象中的属性进行赋值操作
this.type = 'canvas';
this.dpr = this.options.devicePixelRatio || devicePixelRatio;
this.host = host;
if (this.host.style) {
this.host.style['-webkit-tap-highlight-color'] = 'transparent';
this.host.style['-webkit-user-select'] = this.host.style['user-select'] = this.host