protected override HCShapeLineObj GetObjAt(int x, int y) { HCShapeLineObj vResult = HCShapeLineObj.sloNone; if (HC.PtInRect(new RECT(StartPt.X - PointSize, StartPt.Y - PointSize, StartPt.X + PointSize, StartPt.Y + PointSize), new POINT(x, y))) { vResult = HCShapeLineObj.sloStart; } else if (HC.PtInRect(new RECT(EndPt.X - PointSize, EndPt.Y - PointSize, EndPt.X + PointSize, EndPt.Y + PointSize), new POINT(x, y))) { vResult = HCShapeLineObj.sloEnd; } else { RECT vRect = ClientRect(); vRect.Inflate(PointSize, PointSize); if (HC.PtInRect(vRect, x, y)) // 在边框点宽度外 { vRect.Inflate(-PointSize - PointSize, -PointSize - PointSize); if (!HC.PtInRect(vRect, x, y)) { vResult = HCShapeLineObj.sloLine; } } } return(vResult); }
protected override void SetActive(bool value) { base.SetActive(value); if (!this.Active) { FActiveOjb = HCShapeLineObj.sloNone; } }
public HCShapeLine() : base() { Style = HCShapeStyle.hssLine; FStartPt = new POINT(0, 0); FEndPt = new POINT(0, 0); FWidth = 1; FActiveOjb = HCShapeLineObj.sloNone; FLineStyle = HCPenStyle.psSolid; }
public override bool MouseMove(MouseEventArgs e) { if (StructState == HCStructState.hstcStructing) { FEndPt = new POINT(e.X, e.Y); return(true); } bool vResult = false; if ((e.Button == MouseButtons.Left) && (FActiveOjb != HCShapeLineObj.sloNone)) { vResult = true; switch (FActiveOjb) { case HCShapeLineObj.sloLine: FStartPt.X = FStartPt.X + e.X - FMousePt.X; FStartPt.Y = FStartPt.Y + e.Y - FMousePt.Y; FEndPt.X = FEndPt.X + e.X - FMousePt.X; FEndPt.Y = FEndPt.Y + e.Y - FMousePt.Y; FMousePt.X = e.X; FMousePt.Y = e.Y; break; case HCShapeLineObj.sloStart: FStartPt.X = e.X; FStartPt.Y = e.Y; break; case HCShapeLineObj.sloEnd: FEndPt.X = e.X; FEndPt.Y = e.Y; break; } } else { HCShapeLineObj vLineOjb = GetObjAt(e.X, e.Y); if (Active && ((vLineOjb == HCShapeLineObj.sloStart) || (vLineOjb == HCShapeLineObj.sloEnd))) { this.Cursor = Cursors.Cross; } else if (vLineOjb != HCShapeLineObj.sloNone) { this.Cursor = Cursors.SizeAll; } vResult = vLineOjb != HCShapeLineObj.sloNone; } return(vResult); }
protected override HCShapeLineObj GetObjAt(int x, int y) { HCShapeLineObj vResult = HCShapeLineObj.sloNone; if (HC.PtInRect(new RECT(StartPt.X - PointSize, StartPt.Y - PointSize, StartPt.X + PointSize, StartPt.Y + PointSize), new POINT(x, y))) { vResult = HCShapeLineObj.sloStart; } else if (HC.PtInRect(new RECT(EndPt.X - PointSize, EndPt.Y - PointSize, EndPt.X + PointSize, EndPt.Y + PointSize), new POINT(x, y))) { vResult = HCShapeLineObj.sloEnd; } else { RECT vRect = ClientRect(); vRect.Inflate(PointSize, PointSize); IntPtr vRgn1 = GDI.CreateEllipticRgnIndirect(ref vRect); try { if (GDI.PtInRegion(vRgn1, x, y)) // 在外围 { vRect.Inflate(-PointSize - PointSize, -PointSize - PointSize); IntPtr vRgn2 = GDI.CreateEllipticRgnIndirect(ref vRect); try { if (!GDI.PtInRegion(vRgn2, x, y)) // 不在内围 { vResult = HCShapeLineObj.sloLine; } } finally { GDI.DeleteObject(vRgn2); } } } finally { GDI.DeleteObject(vRgn1); } } return(vResult); }
public override bool MouseDown(MouseEventArgs e) { if (e.Button != MouseButtons.Left) { return(false); } bool vResult = false; if (StructState != HCStructState.hstcStop) // 正在构建 { if (StructState == HCStructState.hstcStart) // 开妈构建 { FStartPt = new POINT(e.X, e.Y); FEndPt = new POINT(e.X, e.Y); StructState = HCStructState.hstcStructing; } else // 构建进行中按下,完成构建 { StructOver(); } vResult = true; } else { HCShapeLineObj vLineObje = GetObjAt(e.X, e.Y); if (FActiveOjb != vLineObje) { FActiveOjb = vLineObje; Active = FActiveOjb != HCShapeLineObj.sloNone; vResult = Active; } else { vResult = vLineObje != HCShapeLineObj.sloNone; } if ((vResult) && (FActiveOjb == HCShapeLineObj.sloLine)) { FMousePt.X = e.X; FMousePt.Y = e.Y; } } return(vResult); }
protected virtual HCShapeLineObj GetObjAt(int x, int y) { HCShapeLineObj vResult = HCShapeLineObj.sloNone; if (HC.PtInRect(new RECT(FStartPt.X - PointSize, FStartPt.Y - PointSize, FStartPt.X + PointSize, FStartPt.Y + PointSize), new POINT(x, y))) { vResult = HCShapeLineObj.sloStart; } else if (HC.PtInRect(new RECT(FEndPt.X - PointSize, FEndPt.Y - PointSize, FEndPt.X + PointSize, FEndPt.Y + PointSize), new POINT(x, y))) { vResult = HCShapeLineObj.sloEnd; } else { POINT[] vPointArr = new POINT[4]; vPointArr[0] = new POINT(FStartPt.X - PointSize, FStartPt.Y); vPointArr[1] = new POINT(FStartPt.X + PointSize, FStartPt.Y); vPointArr[2] = new POINT(FEndPt.X + PointSize, FEndPt.Y); vPointArr[3] = new POINT(FEndPt.X - PointSize, FEndPt.Y); IntPtr vRgn = GDI.CreatePolygonRgn(vPointArr, 4, GDI.WINDING); try { if (GDI.PtInRegion(vRgn, x, y)) { vResult = HCShapeLineObj.sloLine; } } finally { GDI.DeleteObject(vRgn); } } return(vResult); }