/** * Created by guopeng on 16/8/3. */ import * as React from "react"; import {ReportItemDesigner} from "./ReportItemDesigner"; import CheckboxItem from "../../items/CheckboxItem"; import {RectF, SizeF} from "../../drawing/Unit"; import {autobind} from "core-decorators"; import {GroupObjectPool} from "../../drawing/KonvaObjectPools"; const Konva = require("konva"); interface Props { } export default class CheckboxDesigner extends ReportItemDesigner { private imageObj; render(bounds: RectF): any { const width = bounds.width; const height = bounds.height; const rootProps = { x: bounds.x, y: bounds.y, width: width, height: height } const item = this.item as CheckboxItem; const props = { width: width, height: height } const groupNode = GroupObjectPool.get(rootProps); const imageNode = new Konva.Image(props); groupNode.add(imageNode); this.renderImage(imageNode, item); return groupNode; } renderImage(imageNode, item: CheckboxItem){ if(!this.imageObj){ this.imageObj = new Image(); } let imageObj = this.imageObj; if(item.changed){ this.imageObj.onload = () => { imageNode.image(imageObj); imageNode.parent.draw(); } }else{ imageNode.image(imageObj); } if(item.checked){ imageObj.src = "http://www.iconsvg.com/Public/1333158603401453568/%E5%A4%8D%E9%80%89%E6%A1%86_checkbox2.svg"; }else{ imageObj.src = "http://www.iconsvg.com/Public/1333158603401453568/%E5%A4%8D%E9%80%89%E6%A1%86_checkbox3.svg"; } // if(item.checked){ // imageObj.src = ' '; // }else{ // } }