import * as React from "react"; import {observer} from "mobx-react/index"; import {Layer, Rect, Stage, Group, Line} from 'react-konva'; import {DesignerStyleSettings} from "../DesignerStyleSettings"; import {SnapGridService} from "../behavior/SnapGridService"; import {DesignerHost} from "../DesignerHost"; interface SnapGridLayerProps { width: number; height: number; } @observer export class SnapGridLayer extends React.Component { private _snapGridService: SnapGridService; private static colorOne; private static colorFive; private static colorTen; private _host: DesignerHost; constructor(props:any, context:any) { super(props, context); this._host = DesignerHost.instance(); const color = DesignerStyleSettings.SnapGridColor; SnapGridLayer.colorOne = color.alpha(36 / 255.0).cssa(); SnapGridLayer.colorFive = color.alpha(100 / 255.0).cssa(); SnapGridLayer.colorTen = color.alpha(180 / 255.0).cssa(); this._snapGridService = this._host.getService(SnapGridService); } static getLineColor(index: number):string { if (index % 10 === 0) { return SnapGridLayer.colorTen; } if (index % 5 === 0) { return SnapGridLayer.colorFive; } return SnapGridLayer.colorOne; } render():JSX.Element { const showSnapGrid = this._host.designReport.showSnapGrid; if (! showSnapGrid) { return ; } return ( {this.drawRulers()} {this.drawGridLines()} ) } drawRulers() { const rulerWidth = this._host.designReport.rulerWidth; const {width, height} = this._host.designReport.viewPortSize; const rulers = []; rulers.push(); rulers.push(); return rulers; } drawGridLines() { const snapInfo = this._snapGridService.snapGridInfo; const {width, height } = snapInfo; const gridSize = snapInfo.gridSize; const rulerWidth = this._host.designReport.rulerWidth; const startX = Math.floor(snapInfo.x + rulerWidth) + 5 + 0.5; const startY = Math.floor(snapInfo.y + rulerWidth) + 5 + 0.5; const lines = []; // 画垂直线 let i = snapInfo.startIndexX; for (let x = startX; (width - x) > 0.01; x += gridSize, i++) { lines.push( ) } // 画水平线 let j = snapInfo.startIndexY; for (let y = startY; (height - y) > 0.01; y += gridSize, j++) { lines.push( ) } return lines; } }