import * as React from "react"; import {RectF, PointF} from "../../drawing/Unit"; // import {Rect} from 'react-konva'; import {DesignerStyleSettings} from "../DesignerStyleSettings"; import {GrabHandleGlyphType, SelectionRules} from "./Enums"; import {SelectionGlyphBase} from "./SelectionGlyphBase"; import {ReportItemBase} from "../../items/ReportItemBase"; import {Behavior} from "./Behavior"; import {Cursor} from "../../drawing/Cursor"; import {RectObjectPool, LineObjectPool} from "../../drawing/KonvaObjectPools"; const Konva = require('konva'); class GrabHandleBaseGlyph extends SelectionGlyphBase { constructor(item:ReportItemBase, bounds:RectF, handleType:GrabHandleGlyphType, behavior:Behavior) { super(item, RectF.Empty, Cursor.Default, SelectionRules.None, behavior); this.initialize(bounds, handleType); } protected initialize(rc:RectF, handleType:GrabHandleGlyphType):void { this.cursor = Cursor.Default; switch (handleType) { case GrabHandleGlyphType.TopLeft: this.bounds = new RectF(rc.x - DesignerStyleSettings.HandleSize , rc.y - DesignerStyleSettings.HandleSize , DesignerStyleSettings.HandleSize , DesignerStyleSettings.HandleSize); this.cursor = Cursor.SizeNWSE; this.rules = SelectionRules.LeftSizeable | SelectionRules.TopSizeable; break; case GrabHandleGlyphType.TopRight: this.bounds = new RectF(rc.right , rc.y - DesignerStyleSettings.HandleSize , DesignerStyleSettings.HandleSize , DesignerStyleSettings.HandleSize); this.cursor = Cursor.SizeNESW; this.rules = SelectionRules.RightSizeable | SelectionRules.TopSizeable; break; case GrabHandleGlyphType.BottomLeft: this.bounds = new RectF(rc.x - DesignerStyleSettings.HandleSize , rc.bottom , DesignerStyleSettings.HandleSize , DesignerStyleSettings.HandleSize); this.cursor = Cursor.SizeNESW; this.rules = SelectionRules.LeftSizeable | SelectionRules.BottomSizeable; break; case GrabHandleGlyphType.BottomRight: this.bounds = new RectF(rc.right , rc.bottom , DesignerStyleSettings.HandleSize , DesignerStyleSettings.HandleSize); this.cursor = Cursor.SizeNWSE; this.rules = SelectionRules.RightSizeable | SelectionRules.BottomSizeable; break; case GrabHandleGlyphType.Top: if (rc.width >= 2 * DesignerStyleSettings.HandleSize) { this.bounds = new RectF(rc.x + (rc.width - DesignerStyleSettings.HandleSize) / 2 , rc.y - DesignerStyleSettings.HandleSize , DesignerStyleSettings.HandleSize , DesignerStyleSettings.HandleSize); this.cursor = Cursor.SizeNS; this.rules = SelectionRules.TopSizeable; } break; case GrabHandleGlyphType.Bottom: if (rc.width >= 2 * DesignerStyleSettings.HandleSize) { this.bounds = new RectF(rc.x + (rc.width - DesignerStyleSettings.HandleSize) / 2 , rc.bottom , DesignerStyleSettings.HandleSize , DesignerStyleSettings.HandleSize); this.cursor = Cursor.SizeNS; this.rules = SelectionRules.BottomSizeable; } break; case GrabHandleGlyphType.Left: if (rc.height >= 2 * DesignerStyleSettings.HandleSize) { this.bounds = new RectF(rc.x - DesignerStyleSettings.HandleSize , rc.y + (rc.height - DesignerStyleSettings.HandleSize) / 2 , DesignerStyleSettings.HandleSize , DesignerStyleSettings.HandleSize); this.cursor = Cursor.SizeWE; this.rules = SelectionRules.LeftSizeable; } break; case GrabHandleGlyphType.Right: if (rc.height >= 2 * DesignerStyleSettings.HandleSize) { this.bounds = new RectF(rc.right , rc.y + (rc.height - DesignerStyleSettings.HandleSize) / 2 , DesignerStyleSettings.HandleSize , DesignerStyleSettings.HandleSize); this.cursor = Cursor.SizeWE; this.rules = SelectionRules.RightSizeable; } break; } } } export class GrabNormalGlyph extends GrabHandleBaseGlyph { private _primary:boolean; constructor(item:ReportItemBase, bounds:RectF, handleType:GrabHandleGlyphType, behavior:Behavior, primary:boolean) { super(item, bounds, handleType, behavior); this._primary = primary; } render(parentNode):void { const rc = this.bounds; const props = { x: rc.x, y: rc.y, width: rc.width, height: rc.height, fill: this._primary ? DesignerStyleSettings.SelectionColor.cssa() : 'rgba(255, 255, 255, 1)', stroke: DesignerStyleSettings.SelectionColor.cssa(), strokeWidth: 1, }; // parentNode.add(new Konva.Rect(props)); parentNode.add(RectObjectPool.get(props)); } } export class GrabLockGlyph extends GrabHandleBaseGlyph { private _primary: boolean; constructor(item: ReportItemBase, bounds: RectF, handleType:GrabHandleGlyphType, behavior: Behavior, primary?: boolean) { super(item, bounds, handleType, behavior); this.cursor = Cursor.Default; this.rules = SelectionRules.None; } hitTest(pt:PointF):Cursor { return null; } render(parentNode): void { const rc = this.bounds; const props = { points: [rc.x, rc.y, rc.x+6, rc.y+6,rc.x+4, rc.y+4, rc.x+6, rc.y, rc.x, rc.y+7], stroke: DesignerStyleSettings.SelectionLockColor.cssa(), strokeWidth: 3, lineJoin: 'round' }; parentNode.add(LineObjectPool.get(props)); } }