import * as React from "react"; import {Glyph} from "./Glyph"; import {RectF} from "../../drawing/Unit"; import {DesignerStyleSettings} from "../DesignerStyleSettings"; import {Edges, ItemSelectionType, SelectionBorderGlyphType, SelectionRules,BorderStatus} from "./Enums"; import {SelectionGlyphBase} from "./SelectionGlyphBase"; import {ReportItemBase} from "../../items/ReportItemBase"; import {Behavior} from "./Behavior"; import {Cursor} from "../../drawing/Cursor"; import {LineObjectPool} from "../../drawing/KonvaObjectPools"; import {BorderDrawer} from "../designer/decorates/BorderDrawer"; import {BoxItem} from "../../items/BoxItem"; export class ItemFrameGlyph extends Glyph { private _bounds: RectF; private _edges: Edges; private _borderSize: number; private _selType:ItemSelectionType; private _borderStatus: BorderStatus; private _item:ReportItemBase; private _layer:any; private _previousX:number; private _previousY:number; private _needDisplay = false; private _itemId:string; constructor(item:ReportItemBase, bounds:RectF, edges:Edges, borderSize:number, selType:ItemSelectionType, itemLock: BorderStatus) { super(null); this._item = item; this._bounds = bounds; this._edges = edges; this._borderSize = borderSize; this._selType = selType; this._borderStatus = itemLock; } dispose() { if (this._layer) { this._layer = null; } super.dispose(); } get item(): ReportItemBase { return this._item; } get strokeColor() { if(this._borderStatus == BorderStatus.OverLapped) { return DesignerStyleSettings.OverlappedColor.cssa(); } else if (this._selType === ItemSelectionType.NotSelected) { return DesignerStyleSettings.SelectionHalfColor.cssa(); } else if(this._borderStatus == BorderStatus.Locked) { return DesignerStyleSettings.SelectionLockColor.cssa(); } return DesignerStyleSettings.SelectionColor.cssa(); } get bounds():RectF { return this._bounds; } set bounds(value:RectF) { if (! this._bounds.equals(value)) { this._bounds = value; this._needDisplay = true; } } get edges():Edges { return this._edges; } set edges(value:Edges) { if (this._edges !== value) { this._edges = value; this._needDisplay = true; } } get borderSize():number { return this._borderSize; } set borderSize(value:number) { if (this._borderSize !== value) { this._borderSize = value; this._needDisplay = true; } } get selType():ItemSelectionType { return this._selType; } set selType(value:ItemSelectionType) { if (this._selType !== value) { this._selType = value; this._needDisplay = true; } } get borderStatus():BorderStatus { return this._borderStatus; } set borderStatus(value:BorderStatus) { if (this._borderStatus !== value) { this._borderStatus = value; this._needDisplay = true; } } render(parentNode):void { this.renderLayer(parentNode); } @BorderDrawer renderBorder(parentNode, bounds:RectF):any { } private offsetLayer() { const bounds = this.bounds; const offsetX = bounds.x - this._previousX; const offsetY = bounds.y - this._previousY; if (offsetX !== 0 || offsetY !== 0) { this._layer.getCanvas()._canvas.style.left = offsetX + 'px'; this._layer.getCanvas()._canvas.style.top = offsetY + 'px'; } } private renderLayer(parentNode) { let {x, y, width, height} = this.bounds; x += this.borderSize === 1 ? 0.5 : 0; y += this.borderSize === 1 ? 0.5 : 0; if ((this.edges & Edges.Top) === Edges.Top) { const rectNode = LineObjectPool.get({ points: [x, y, x + width, y], stroke: this.strokeColor, strokeWidth: this.borderSize, }); parentNode.add(rectNode); } if ((this.edges & Edges.Right) === Edges.Right) { const rectNode = LineObjectPool.get({ points: [x + width, y, x + width, y + height], stroke: this.strokeColor, strokeWidth: this.borderSize, }); parentNode.add(rectNode); } if ((this.edges & Edges.Bottom) === Edges.Bottom) { const rectNode = LineObjectPool.get({ points: [x, y + height, x + width, y + height], stroke: this.strokeColor, strokeWidth: this.borderSize, }); parentNode.add(rectNode); } if ((this.edges & Edges.Left) === Edges.Left) { const rectNode = LineObjectPool.get({ points: [x, y, x, y + height], stroke: this.strokeColor, strokeWidth: this.borderSize, }); parentNode.add(rectNode); } // const props = { // x: bounds.x, // y: bounds.y, // width: bounds.width, // height: bounds.height, // stroke: this.strokeColor, // strokeWidth: this.borderSize, // }; // // // const node = new Konva.Rect(props); // const node = RectObjectPool.get(props); // parentNode.add(node); if (this._item instanceof BoxItem) { this.renderBorder(parentNode, this.bounds); } } setItemId(itemId: string) { this._itemId = itemId; } } export class SelectionBorderGlyph extends SelectionGlyphBase { private _borderType: SelectionBorderGlyphType; constructor(item:ReportItemBase, bounds:RectF, rules:SelectionRules, borderType:SelectionBorderGlyphType, borderStyle: BorderStatus, behavior:Behavior) { super(item, RectF.Empty, Cursor.Default, SelectionRules.None, behavior); this.initialize(bounds, rules, borderType,borderStyle); } protected initialize(bounds:RectF, rules:SelectionRules, borderType:SelectionBorderGlyphType,borderStyle: BorderStatus ):void { this.bounds = SelectionBorderGlyph.getBoundsForSelectionType(bounds , borderType , DesignerStyleSettings.SelectionBorderHitArea); if( borderStyle == BorderStatus.Locked) { this.cursor = Cursor.Default; return ; } this._borderType = borderType; switch (borderType) { case SelectionBorderGlyphType.Top: if ((rules & SelectionRules.TopSizeable) != SelectionRules.None) { this.cursor = Cursor.SizeNS; this.rules = SelectionRules.TopSizeable; } break; case SelectionBorderGlyphType.Bottom: if ((rules & SelectionRules.BottomSizeable) != SelectionRules.None) { this.cursor = Cursor.SizeNS; this.rules = SelectionRules.BottomSizeable; } break; case SelectionBorderGlyphType.Left: if ((rules & SelectionRules.LeftSizeable) != SelectionRules.None) { this.cursor = Cursor.SizeWE; this.rules = SelectionRules.LeftSizeable; } break; case SelectionBorderGlyphType.Right: if ((rules & SelectionRules.RightSizeable) != SelectionRules.None) { this.cursor = Cursor.SizeWE; this.rules = SelectionRules.RightSizeable; } break; } } static getBoundsForSelectionType(originalBounds:RectF, type:SelectionBorderGlyphType, borderSize:number):RectF { const bounds = RectF.Empty.clone(); const borderSizeHalf = borderSize / 2.0; switch (type) { case SelectionBorderGlyphType.Top: { return new RectF(originalBounds.left - borderSizeHalf , originalBounds.top - borderSizeHalf , originalBounds.width + (2 * borderSizeHalf) , borderSize); } case SelectionBorderGlyphType.Bottom: { return new RectF(originalBounds.left - borderSizeHalf , originalBounds.bottom - borderSizeHalf , originalBounds.width + (2 * borderSizeHalf) , borderSize); } case SelectionBorderGlyphType.Left: { return new RectF(originalBounds.left - borderSizeHalf , originalBounds.top - borderSizeHalf , borderSize , originalBounds.height + (2 * borderSizeHalf)); } case SelectionBorderGlyphType.Right: { return new RectF(originalBounds.right - borderSizeHalf , originalBounds.top - borderSizeHalf , borderSize , originalBounds.height + (2 * borderSizeHalf)); } case SelectionBorderGlyphType.Body: { return originalBounds; } } return bounds; } get borderType(): SelectionBorderGlyphType { return this._borderType; } }