コード例 #1
0
        private void SnapVerticalsForDrag(IRect originalRect)
        {
            var topSnapped    = false;
            var bottomSnapped = false;


            var snappedBottom = SnapVertical(originalRect.Bottom);
            var snappedTop    = SnapVertical(originalRect.Top);

            if (originalRect.Top != snappedTop)
            {
                topSnapped = true;
            }
            if (originalRect.Bottom != snappedBottom)
            {
                bottomSnapped = true;
            }

            if (topSnapped)
            {
                Snappable.Top = snappedTop;
            }
            else if (bottomSnapped)
            {
                Snappable.Top = snappedBottom - originalRect.Height;
            }
            else
            {
                Snappable.Top = originalRect.Top;
            }
        }
コード例 #2
0
        private void SnapVerticalsForDrag(IRect originalRect)
        {
            var topSnapped = false;
            var bottomSnapped = false;

            
            var snappedBottom = SnapVertical(originalRect.Bottom);
            var snappedTop = SnapVertical(originalRect.Top);

            if (originalRect.Top != snappedTop)
            {
                topSnapped = true;
            }
            if (originalRect.Bottom != snappedBottom)
            {
                bottomSnapped = true;
            }

            if (topSnapped)
            {
                Snappable.Top = snappedTop;
                
            }
            else if (bottomSnapped)
            {
                Snappable.Top = snappedBottom - originalRect.Height;
                
            }
            else
            {
                Snappable.Top = originalRect.Top;                
            }
        }
コード例 #3
0
ファイル: GeomUtils.cs プロジェクト: mkonicek/dipl
 public static void InflateRect(IRect rect, double padding)
 {
     rect.Left -= padding;
     rect.Top -= padding;
     rect.Width += padding * 2;
     rect.Height += padding * 2;
 }
コード例 #4
0
ファイル: CssTests.cs プロジェクト: nagyist/savagesvg
        public void TestRectValue()
        {
            CssStyleDeclaration csd = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[1]).Style;
            CssValue            val = (CssValue)csd.GetPropertyCssValue("rect");

            Assert.IsTrue(val is CssPrimitiveValue);
            CssPrimitiveValue primValue = (CssPrimitiveValue)csd.GetPropertyCssValue("rect");

            Assert.AreEqual("rect(10cm 23px 45px 89px)", primValue.CssText);
            Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType);
            Assert.AreEqual(CssPrimitiveType.Rect, primValue.PrimitiveType);
            IRect rect = primValue.GetRectValue();

            ICssPrimitiveValue rectValue = rect.Top;

            Assert.AreEqual(100, rectValue.GetFloatValue(CssPrimitiveType.Mm));
            Assert.AreEqual(CssPrimitiveType.Cm, rectValue.PrimitiveType);

            rectValue = rect.Right;
            Assert.AreEqual(23, rectValue.GetFloatValue(CssPrimitiveType.Px));
            Assert.AreEqual(CssPrimitiveType.Px, rectValue.PrimitiveType);

            rectValue = rect.Bottom;
            Assert.AreEqual(45, rectValue.GetFloatValue(CssPrimitiveType.Px));
            Assert.AreEqual(CssPrimitiveType.Px, rectValue.PrimitiveType);

            rectValue = rect.Left;
            Assert.AreEqual(89, rectValue.GetFloatValue(CssPrimitiveType.Px));
            Assert.AreEqual(CssPrimitiveType.Px, rectValue.PrimitiveType);
        }
コード例 #5
0
ファイル: RectShape.cs プロジェクト: zyouhua/weilai
 public RectShape()
 {
     mIndex = default(int);
     mLabelShape = null;
     mRectStream = null;
     mRect = null;
 }
コード例 #6
0
ファイル: GeomUtils.cs プロジェクト: kleinux/SharpDevelop
        public static Point2D?LineRectIntersection(IPoint lineStart, IPoint lineEnd, IRect rect)
        {
            double vx     = lineEnd.X - lineStart.X;
            double vy     = lineEnd.Y - lineStart.Y;
            double right  = rect.Left + rect.Width;
            double bottom = rect.Top + rect.Height;

            var isectTop = isectHoriz(lineStart, vx, vy, rect.Top, rect.Left, right);

            if (isectTop != null)
            {
                return(isectTop);
            }
            var isectBottom = isectHoriz(lineStart, vx, vy, bottom, rect.Left, right);

            if (isectBottom != null)
            {
                return(isectBottom);
            }
            var isectLeft = isectVert(lineStart, vx, vy, rect.Left, rect.Top, bottom);

            if (isectLeft != null)
            {
                return(isectLeft);
            }
            var isectRight = isectVert(lineStart, vx, vy, right, rect.Top, bottom);

            if (isectRight != null)
            {
                return(isectRight);
            }

            return(null);
        }
コード例 #7
0
ファイル: Extensions.cs プロジェクト: UIKit0/VisualDesigner
        public static void SetTopKeepingBottom(this IRect rect, double top)
        {
            var bottom = rect.Bottom;

            rect.Y      = top;
            rect.Height = bottom - top;
        }
コード例 #8
0
        private void SnapHorizontalsForDrag(IRect originalRect)
        {
            var leftSnapped  = false;
            var rightSnapped = false;

            var snappedLeft  = SnapHorizontal(originalRect.Left);
            var snappedRight = SnapHorizontal(originalRect.Right);

            if (originalRect.Left != snappedLeft)
            {
                leftSnapped = true;
            }
            if (originalRect.Right != snappedRight)
            {
                rightSnapped = true;
            }

            if (leftSnapped)
            {
                Snappable.Left = snappedLeft;
            }
            else if (rightSnapped)
            {
                Snappable.Left = snappedRight - originalRect.Width;
            }
            else
            {
                Snappable.Left = originalRect.Left;
            }
        }
コード例 #9
0
ファイル: Extensions.cs プロジェクト: UIKit0/VisualDesigner
        public static void SetLeftKeepingRight(this IRect rect, double left)
        {
            var right = rect.Right;

            rect.X     = left;
            rect.Width = right - left;
        }
コード例 #10
0
        private void SnapHorizontalsForDrag(IRect originalRect)
        {
            var leftSnapped = false;
            var rightSnapped = false;

            var snappedLeft = SnapHorizontal(originalRect.Left);
            var snappedRight = SnapHorizontal(originalRect.Right);

            if (originalRect.Left != snappedLeft)
            {
                leftSnapped = true;
            }
            if (originalRect.Right != snappedRight)
            {
                rightSnapped = true;
            }

            if (leftSnapped)
            {
                Snappable.Left = snappedLeft;                
            }
            else if (rightSnapped)
            {
                Snappable.Left = snappedRight - originalRect.Width;                

            }
            else
            {
                Snappable.Left = originalRect.Left;                
            }    
        }
コード例 #11
0
        public void SetSourceRectForDrag(IRect originalRect)
        {
            SnapHorizontalsForDrag(originalRect);
            SnapVerticalsForDrag(originalRect);

            SourceRectangleFiltered();
        }
コード例 #12
0
    public static void GetEdge(IRect rect, int index, out Vector3 from, out Vector3 to)
    {
        var point = rect.GetRectInfo();

        switch (index)
        {
        case 0:
            from = point[0];
            to   = point[1];
            break;

        case 1:
            from = point[1];
            to   = point[2];
            break;

        case 2:
            from = point[2];
            to   = point[3];
            break;

        default:
            from = point[3];
            to   = point[0];
            break;
        }
    }
コード例 #13
0
        public void SetSourceRectForDrag(IRect originalRect)
        {
            SnapHorizontalsForDrag(originalRect);
            SnapVerticalsForDrag(originalRect);

            SourceRectangleFiltered();
        }
コード例 #14
0
ファイル: RectShape.cs プロジェクト: zyouhua/nvwa
 public void _initRect(IRect nRect)
 {
     ShapeDescriptorSingleton shapeDescriptorSingleton_ = __singleton<ShapeDescriptorSingleton>._instance();
     mRectStream = shapeDescriptorSingleton_._rectDescriptor(nRect._styleName());
     mRect = nRect;
     mRect.m_tGetRect += this._getRect2I;
     mRect.m_tJoinPoint += this._rectJoinPoint;
 }
コード例 #15
0
 public Box(IRect original)
 {
     this.rect   = new Rectangle();
     this.Left   = original.Left;
     this.Top    = original.Top;
     this.Width  = original.Width;
     this.Height = original.Height;
 }
コード例 #16
0
ファイル: Box.cs プロジェクト: hpsa/SharpDevelop
		public Box(IRect original)
		{
			this.rect = new Rectangle();
			this.Left = original.Left;
			this.Top = original.Top;
			this.Width = original.Width;
			this.Height = original.Height;
		}
コード例 #17
0
ファイル: Extensions.cs プロジェクト: UIKit0/VisualDesigner
        public static IPoint GetHandlePoint(this IRect rect, ISize parentSize)
        {
            var middleThumb = rect.MiddlePoint();

            var propX = MathOperations.SquareRounding(middleThumb.X, parentSize.Width, 3) / 3D;
            var propY = MathOperations.SquareRounding(middleThumb.Y, parentSize.Height, 3) / 3D;

            return(new Point(propX, propY));
        }
コード例 #18
0
        static void Main(string[] args)
        {
            Drawing drawing = new Drawing();
            //drawing.Draw(); cant do this because explicit implementation
            IRect r = drawing;

            r.Draw();
            ICircle c = drawing;

            c.Draw();
        }
コード例 #19
0
        public Cursor GetCursor(IRect handleRect, IRect parentRect)
        {
            var discretizedHandle          = handleRect.MiddlePoint();
            var edgeSizeOfEquivalentSquare = parentRect.Size.EdgeOfEquivaletSquare();

            var x = Geometrics.LinearProportion(discretizedHandle.X, parentRect.Width, edgeSizeOfEquivalentSquare);
            var y = Geometrics.LinearProportion(discretizedHandle.Y, parentRect.Height, edgeSizeOfEquivalentSquare);

            var equivalentDiscretizedHandle = new Point(x, y);

            return(GetCursorFromPointsInSquare(edgeSizeOfEquivalentSquare, equivalentDiscretizedHandle));
        }
        public Cursor GetCursor(IRect handleRect, IRect parentRect)
        {
            var discretizedHandle = handleRect.MiddlePoint();
            var edgeSizeOfEquivalentSquare = parentRect.Size.EdgeOfEquivaletSquare();

            var x = Geometrics.LinearProportion(discretizedHandle.X, parentRect.Width, edgeSizeOfEquivalentSquare);
            var y = Geometrics.LinearProportion(discretizedHandle.Y, parentRect.Height, edgeSizeOfEquivalentSquare);

            var equivalentDiscretizedHandle = new Point(x, y);

            return GetCursorFromPointsInSquare(edgeSizeOfEquivalentSquare, equivalentDiscretizedHandle);
        }
コード例 #21
0
        public static IPoint GetOpposite(this IPoint a, IRect rect)
        {
            var halfPointX = rect.Left + rect.Width / 2;
            var distanceX = halfPointX - a.X;
            var x = halfPointX + distanceX;

            var halfPointY = rect.Top + rect.Height / 2;
            var distanceY = halfPointY - a.Y;
            var y = halfPointY + distanceY;

            var opposite = new Point(x, y);

            return opposite;
        }
コード例 #22
0
    public bool IsContainRectVertex(IRect rect)
    {
        var testPoints = rect.GetRectInfo();

        for (var i = 0; i < testPoints.Length; ++i)
        {
            var nowPoint = testPoints[i];
            if (IsContainPoint(nowPoint))
            {
                return(true);
            }
        }
        return(false);
    }
コード例 #23
0
ファイル: Geometrics.cs プロジェクト: UIKit0/VisualDesigner
        public static IPoint GetOpposite(this IPoint a, IRect rect)
        {
            var halfPointX = rect.Left + rect.Width / 2;
            var distanceX  = halfPointX - a.X;
            var x          = halfPointX + distanceX;

            var halfPointY = rect.Top + rect.Height / 2;
            var distanceY  = halfPointY - a.Y;
            var y          = halfPointY + distanceY;

            var opposite = new Point(x, y);

            return(opposite);
        }
コード例 #24
0
        public static IPoint GetOpposite(this IPoint a, IRect rect)
        {
            var halfPointX = rect.Left + rect.Width / 2;
            var distanceX = halfPointX - a.X;
            var x = halfPointX + distanceX;

            var halfPointY = rect.Top + rect.Height / 2;
            var distanceY = halfPointY - a.Y;
            var y = halfPointY + distanceY;

            var opposite = ServiceLocator.CoreTypesFactory.CreatePoint(x, y);

            return opposite;
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: qusehdgns/c-_inhatc_3_2
        static void Main(string[] args)
        {
            Shape s = new Shape();

            ((IRect)s).Area(20, 20);
            ((ITri)s).Area(20, 20);

            IRect r = s;

            r.Area(20, 20);

            ITri t = s;

            t.Area(20, 20);
        }
コード例 #26
0
        static IEnumerable <RouteVertex> GetRectCorners(IRect rect, double padding)
        {
            double left   = rect.Left - padding;
            double top    = rect.Top - padding;
            double right  = left + rect.Width + 2 * padding;
            double bottom = top + rect.Height + 2 * padding;

            yield return(new RouteVertex(left, top));

            yield return(new RouteVertex(right, top));

            yield return(new RouteVertex(right, bottom));

            yield return(new RouteVertex(left, bottom));
        }
コード例 #27
0
    static void DrawRect(IRect rect, Color color)
    {
        var point = rect.GetRectInfo();

        if (point == null)
        {
            return;
        }

        Gizmos.color = color;
        for (var i = 0; i <= 2; ++i)
        {
            Gizmos.DrawLine(point[i], point[i + 1]);
        }
        Gizmos.DrawLine(point[3], point[0]);
    }
コード例 #28
0
    //b是不是被a包住
    //(用在a的軸向沒有和世界對齊的情況)
    //(另1種作法是把b的4個點轉換到a的local,之後就可以用軸對齊的判定)
    public static bool IsContainCenterPoint(IRect a, IRect b)
    {
        var point = a.GetRectInfo();
        var p1    = point[1];
        var p2    = point[2];
        var p3    = point[3];

        var xDir = (p3 - p2);
        var zDir = (p1 - p2);

        var width  = xDir.magnitude;
        var height = zDir.magnitude;

        var xNormalDir = xDir / width;
        var zNormalDir = zDir / height;

        //只判斷中心點
        var center = b.GetCenter();

        var vec    = center - p2;
        var xValue = Vector3.Dot(vec, xNormalDir);
        var zValue = Vector3.Dot(vec, zNormalDir);

        bool test = xValue > 0 && xValue < width && zValue > 0 && zValue < height;

        return(test);

        /*
         * foreach (var tPoint in testPoint)
         * {
         *  var vec = tPoint - p2;
         *  var xValue = Vector3.Dot(vec, xNormalDir);
         *  var zValue = Vector3.Dot(vec, zNormalDir);
         *
         *  bool test = xValue > 0 && xValue < width && zValue > 0 && zValue < height;
         *  if (!test)
         *      return false;
         * }
         *
         * return true;
         */
    }
コード例 #29
0
    static float GetCornerRounding(IRect rectangle, Corner corner, float defaultRadius)
    {
        Length radiusLength;

        switch (corner)
        {
        case Corner.TopLeft:
            radiusLength = rectangle.RoundingRadius.TopLeft;
            break;

        case Corner.TopRight:
            radiusLength = rectangle.RoundingRadius.TopRight;
            break;

        case Corner.BottomRight:
            radiusLength = rectangle.RoundingRadius.BottomRight;
            break;

        case Corner.BottomLeft:
            radiusLength = rectangle.RoundingRadius.BottomLeft;
            break;

        default:
            return(0);
        }
        float result = (radiusLength.IsUndefined ? defaultRadius : radiusLength.ToTwips()) * 2; //rendering uses diameter

        result = Math.Max(0, result);
        float width = rectangle.Width.ToTwips();

        if (width > 0)
        {
            result = Math.Min(width, result);
        }
        float height = rectangle.Height.ToTwips();

        if (height > 0)
        {
            result = Math.Min(height, result);
        }
        return(result);
    }
コード例 #30
0
    public static bool IsIntersect(IRect a, IRect b)
    {
        //如果任2邊相交
        for (var i = 0; i < 4; ++i)
        {
            Vector3 p0, p1;
            GetEdge(a, i, out p0, out p1);
            for (var k = 0; k < 4; ++k)
            {
                Vector3 p2, p3;
                GetEdge(b, k, out p2, out p3);
                if (GeometryTool.IsIntersect(p0, p1, p2, p3))
                {
                    return(true);
                }
            }
        }

        return(false);
    }
コード例 #31
0
        /// <summary>
        /// Check if the point is in rect area
        /// </summary>
        /// <param name="v1">Target point</param>
        /// <param name="v2">Test rect</param>
        /// <returns></returns>
        public static bool CheckCollider(Vec2 v1, IRect v2)
        {
            Vec2[] point = new Vec2[4]
            {
                new Vec2(v2.x, v2.y),
                new Vec2(v2.x + v2.width, v2.y),
                new Vec2(v2.x + v2.width, v2.y + v2.height),
                new Vec2(v2.x, v2.y + v2.height),
            };
            float[] areas = new float[4]
            {
                GetTriangleArea(v1, point[0], point[1]),
                GetTriangleArea(v1, point[1], point[2]),
                GetTriangleArea(v1, point[2], point[3]),
                GetTriangleArea(v1, point[3], point[0]),
            };
            float fullArea = v2.width * v2.height;
            float Compare  = areas[0] + areas[1] + areas[2] + areas[3];

            return(!(Compare > fullArea));
        }
コード例 #32
0
ファイル: GeomUtils.cs プロジェクト: hpsa/SharpDevelop
		public static Point2D? LineRectIntersection(IPoint lineStart, IPoint lineEnd, IRect rect)
		{
			double vx = lineEnd.X - lineStart.X;
			double vy = lineEnd.Y - lineStart.Y;
			double right = rect.Left + rect.Width;
			double bottom = rect.Top + rect.Height;
			
			var isectTop = IsectHoriz(lineStart, vx, vy, rect.Top, rect.Left, right);
			if (isectTop != null)
				return isectTop;
			var isectBottom = IsectHoriz(lineStart, vx, vy, bottom, rect.Left, right);
			if (isectBottom != null)
				return isectBottom;
			var isectLeft = IsectVert(lineStart, vx, vy, rect.Left, rect.Top, bottom);
			if (isectLeft != null)
				return isectLeft;
			var isectRight = IsectVert(lineStart, vx, vy, right, rect.Top, bottom);
			if (isectRight != null)
				return isectRight;
			
			return null;
		}
コード例 #33
0
        public IEnumerable <IElement> HitTest(IRect rect)
        {
            var canvas           = this;
            var r                = new Rect(new Point(rect.X1, rect.Y1), new Point(rect.X2, rect.Y2));
            var selectedElements = new List <DependencyObject>();
            var rectangle        = new RectangleGeometry(r, 0.0, 0.0);
            var hitTestParams    = new GeometryHitTestParameters(rectangle);
            var resultCallback   = new HitTestResultCallback(result => HitTestResultBehavior.Continue);

            var filterCallback = new HitTestFilterCallback(
                element =>
            {
                if (VisualTreeHelper.GetParent(element) == canvas)
                {
                    selectedElements.Add(element);
                }

                return(HitTestFilterBehavior.Continue);
            });

            VisualTreeHelper.HitTest(canvas, filterCallback, resultCallback, hitTestParams);

            return(selectedElements.Cast <IElement>());
        }
コード例 #34
0
ファイル: Line.cs プロジェクト: zyouhua/weilai
 public virtual void _setBeg(IRect nRect)
 {
     nRect.m_tMovePoint2I += this._begPointOffset;
     nRect.m_tAdjustPoint += this._adjustPoint;
 }
コード例 #35
0
 public bool Intersects(IRect<int> other)
 {
     return Contains(other.Left, other.Top) || Contains(other.Left, other.Bottom) || Contains(other.Right, other.Top) || Contains(other.Right, other.Bottom);
 }
コード例 #36
0
ファイル: Line.cs プロジェクト: zyouhua/nvwa
 public virtual void _setBeg(IRect nRect)
 {
     nRect.m_tMovePoint2I += _begPointOffset;
 }
コード例 #37
0
ファイル: IRect.cs プロジェクト: naninunenoy/AsmdefHelper
 public static Rect AsRect(this IRect rect)
 {
     return(new Rect(rect.PositionX, rect.PositionY, rect.Width, rect.Height));
 }
コード例 #38
0
ファイル: GeomUtils.cs プロジェクト: kleinux/SharpDevelop
 public static Box InflateRect(IRect rect, double padding)
 {
     return(new Box(rect.Left - padding, rect.Top - padding, rect.Width + padding * 2, rect.Height + padding * 2));
 }
コード例 #39
0
ファイル: GeomUtils.cs プロジェクト: hpsa/SharpDevelop
		public static IPoint RectCenter(IRect rect)
		{
			return new Point2D(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2);
		}
コード例 #40
0
ファイル: DeriveShape.cs プロジェクト: zyouhua/nvwa
 public override void _setBeg(IRect nRect)
 {
     mBegClassShape = nRect as ClassShape;
     base._setBeg(mBegClassShape);
 }
コード例 #41
0
ファイル: Line.cs プロジェクト: zyouhua/nvwa
 public virtual void _setEnd(IRect nRect)
 {
     nRect.m_tMovePoint2I += _endPointOffset;
 }
コード例 #42
0
ファイル: GraphicsNode.cs プロジェクト: nagyist/savagesvg
        protected void Clip(GraphicsWrapper gr)
        {
            // todo: should we correct the clipping to adjust to the off-one-pixel drawing?
            gr.TranslateClip(1, 1);

            #region Clip with clip
            // see http://www.w3.org/TR/SVG/masking.html#OverflowAndClipProperties
            if (element is ISvgSvgElement ||
                element is ISvgMarkerElement ||
                element is ISvgSymbolElement ||
                element is ISvgPatternElement)
            {
                // check overflow property
                CssValue overflow = ((SvgElement)element).GetComputedCssValue("overflow", String.Empty) as CssValue;
                // TODO: clip can have "rect(10 10 auto 10)"
                CssPrimitiveValue clip = ((SvgElement)element).GetComputedCssValue("clip", String.Empty) as CssPrimitiveValue;

                string sOverflow = null;

                if (overflow != null || overflow.CssText == "")
                {
                    sOverflow = overflow.CssText;
                }
                else
                {
                    if (this is ISvgSvgElement)
                    {
                        sOverflow = "hidden";
                    }
                }

                if (sOverflow != null)
                {
                    // "If the 'overflow' property has a value other than hidden or scroll, the property has no effect (i.e., a clipping rectangle is not created)."
                    if (sOverflow == "hidden" || sOverflow == "scroll")
                    {
                        RectangleF clipRect = RectangleF.Empty;
                        if (clip != null && clip.PrimitiveType == CssPrimitiveType.Rect)
                        {
                            if (element is ISvgSvgElement)
                            {
                                ISvgSvgElement svgElement = (ISvgSvgElement)element;
                                SvgRect        viewPort   = svgElement.Viewport as SvgRect;
                                clipRect = viewPort.ToRectangleF();
                                IRect clipShape = (Rect)clip.GetRectValue();
                                if (clipShape.Top.PrimitiveType != CssPrimitiveType.Ident)
                                {
                                    clipRect.Y += (float)clipShape.Top.GetFloatValue(CssPrimitiveType.Number);
                                }
                                if (clipShape.Left.PrimitiveType != CssPrimitiveType.Ident)
                                {
                                    clipRect.X += (float)clipShape.Left.GetFloatValue(CssPrimitiveType.Number);
                                }
                                if (clipShape.Right.PrimitiveType != CssPrimitiveType.Ident)
                                {
                                    clipRect.Width = (clipRect.Right - clipRect.X) - (float)clipShape.Right.GetFloatValue(CssPrimitiveType.Number);
                                }
                                if (clipShape.Bottom.PrimitiveType != CssPrimitiveType.Ident)
                                {
                                    clipRect.Height = (clipRect.Bottom - clipRect.Y) - (float)clipShape.Bottom.GetFloatValue(CssPrimitiveType.Number);
                                }
                            }
                        }
                        else if (clip == null || (clip.PrimitiveType == CssPrimitiveType.Ident && clip.GetStringValue() == "auto"))
                        {
                            if (element is ISvgSvgElement)
                            {
                                ISvgSvgElement svgElement = (ISvgSvgElement)element;
                                SvgRect        viewPort   = svgElement.Viewport as SvgRect;
                                clipRect = viewPort.ToRectangleF();
                            }
                            else if (element is ISvgMarkerElement ||
                                     element is ISvgSymbolElement ||
                                     element is ISvgPatternElement)
                            {
                                // TODO: what to do here?
                            }
                        }
                        if (clipRect != RectangleF.Empty)
                        {
                            gr.SetClip(clipRect);
                        }
                    }
                }
            }
            #endregion

            #region Clip with clip-path
            // see: http://www.w3.org/TR/SVG/masking.html#EstablishingANewClippingPath
            if (element is IGraphicsElement ||
                element is IContainerElement)
            {
                CssPrimitiveValue clipPath = ((SvgElement)element).GetComputedCssValue("clip-path", String.Empty) as CssPrimitiveValue;

                if (clipPath != null && clipPath.PrimitiveType == CssPrimitiveType.Uri)
                {
                    string absoluteUri = ((SvgElement)element).ResolveUri(clipPath.GetStringValue());

                    SvgClipPathElement eClipPath = ((SvgDocument)element.OwnerDocument).GetNodeByUri(absoluteUri) as SvgClipPathElement;

                    if (eClipPath != null)
                    {
                        GraphicsPath gpClip = eClipPath.GetGraphicsPath();

                        SvgUnitType pathUnits = (SvgUnitType)eClipPath.ClipPathUnits.AnimVal;

                        if (pathUnits == SvgUnitType.ObjectBoundingBox)
                        {
                            SvgTransformableElement transElement = element as SvgTransformableElement;

                            if (transElement != null)
                            {
                                ISvgRect bbox = transElement.GetBBox();

                                // scale clipping path
                                Matrix matrix = new Matrix();
                                matrix.Scale((float)bbox.Width, (float)bbox.Height);
                                gpClip.Transform(matrix);
                                gr.SetClip(gpClip);

                                // offset clip
                                gr.TranslateClip((float)bbox.X, (float)bbox.Y);
                            }
                            else
                            {
                                throw new NotImplementedException("clip-path with SvgUnitType.ObjectBoundingBox "
                                                                  + "not supported for this type of element: " + element.GetType());
                            }
                        }
                        else
                        {
                            gr.SetClip(gpClip);
                        }
                    }
                }
            }
            #endregion
        }
コード例 #43
0
 public void SetSourceRectForResize(IRect originalRect)
 {
     
 }
コード例 #44
0
ファイル: GeomUtils.cs プロジェクト: hpsa/SharpDevelop
		public static Box InflateRect(IRect rect, double padding)
		{
			return new Box(rect.Left - padding, rect.Top - padding, rect.Width + padding * 2, rect.Height + padding * 2);
		}
コード例 #45
0
ファイル: LineCreater.cs プロジェクト: zyouhua/nvwa
 public LineCreater()
 {
     mBeg = null;
     mEnd = null;
 }
コード例 #46
0
ファイル: GeomUtils.cs プロジェクト: kleinux/SharpDevelop
 public static IPoint RectCenter(IRect rect)
 {
     return(new Point2D(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2));
 }
コード例 #47
0
ファイル: Line.cs プロジェクト: zyouhua/weilai
 public virtual void _setEnd(IRect nRect)
 {
     nRect.m_tMovePoint2I += this._endPointOffset;
     nRect.m_tAdjustPoint += this._adjustPoint;
 }
コード例 #48
0
        /// <summary>
        /// Initializes the RouteGraph by vertices close to corners of all nodes.
        /// </summary>
        /// <param name="boundX">X coordinates of vertices cannot be lower than this value (so that edges stay in boundaries).</param>
        /// <param name="boundY">Y coordinates of vertices cannot be lower than this value (so that edges stay in boundaries).</param>
        public static RouteGraph InitializeVertices(IEnumerable <IRect> nodes, IEnumerable <IEdge> edges, int boundX, int boundY)
        {
            var graph = new RouteGraph();

            // add vertices for node corners
            foreach (var node in nodes)
            {
                graph.Boxes.Add(node);
                foreach (var vertex in GetRectCorners(node, boxPadding))
                {
                    if (vertex.X >= boundX && vertex.Y >= boundY)
                    {
                        graph.Vertices.Add(vertex);
                    }
                }
            }
            // add vertices for egde endpoints
            foreach (var multiEdgeGroup in edges.GroupBy(edge => GetStartEnd(edge)))
            {
                int   multiEdgeCount = multiEdgeGroup.Count();
                IRect fromRect       = multiEdgeGroup.First().From;
                IRect toRect         = multiEdgeGroup.First().To;
                var   sourceCenter   = GeomUtils.RectCenter(fromRect);
                var   targetCenter   = GeomUtils.RectCenter(toRect);
                if (Math.Abs(sourceCenter.X - targetCenter.X) > Math.Abs(sourceCenter.Y - targetCenter.Y) ||
                    (fromRect == toRect))
                {
                    // the line is horizontal
                    double multiEdgeSpanSource  = GetMultiEdgeSpan(fromRect.Height, multiEdgeCount, multiEdgeGap);
                    double multiEdgeSpanTarget  = GetMultiEdgeSpan(toRect.Height, multiEdgeCount, multiEdgeGap);
                    double originSourceCurrentY = sourceCenter.Y - multiEdgeSpanSource / 2;
                    double originTargetCurrentY = targetCenter.Y - multiEdgeSpanTarget / 2;
                    foreach (var edge in multiEdgeGroup)
                    {
                        Point2D sourceOrigin = new Point2D(sourceCenter.X, originSourceCurrentY);
                        Point2D targetOrigin = new Point2D(targetCenter.X, originTargetCurrentY);
                        // Here user could provide custom edgeStart and edgeEnd
                        // inflate boxes a little so that edgeStart and edgeEnd are a little outside of the box (to prevent floating point errors)
                        if (edge.From == edge.To)
                        {
                            // special case - self edge
                            var edgeStart = new Point2D(fromRect.Left + fromRect.Width + 0.01, originSourceCurrentY);
                            var edgeEnd   = new Point2D(fromRect.Left + fromRect.Width / 2, fromRect.Top);
                            graph.AddEdgeEndpointVertices(edge, edgeStart, edgeEnd);
                        }
                        else
                        {
                            var edgeStart = GeomUtils.LineRectIntersection(sourceOrigin, targetOrigin, edge.From.Inflated(1e-3));
                            var edgeEnd   = GeomUtils.LineRectIntersection(sourceOrigin, targetOrigin, edge.To.Inflated(1e-3));
                            graph.AddEdgeEndpointVertices(edge, edgeStart, edgeEnd);
                        }
                        originSourceCurrentY += multiEdgeSpanSource / (multiEdgeCount - 1);
                        originTargetCurrentY += multiEdgeSpanTarget / (multiEdgeCount - 1);
                    }
                }
                else
                {
                    // the line is vertical
                    double multiEdgeSpanSource  = GetMultiEdgeSpan(fromRect.Width, multiEdgeCount, multiEdgeGap);
                    double multiEdgeSpanTarget  = GetMultiEdgeSpan(toRect.Width, multiEdgeCount, multiEdgeGap);
                    double originSourceCurrentX = sourceCenter.X - multiEdgeSpanSource / 2;
                    double originTargetCurrentX = targetCenter.X - multiEdgeSpanTarget / 2;
                    foreach (var edge in multiEdgeGroup)
                    {
                        Point2D sourceOrigin = new Point2D(originSourceCurrentX, sourceCenter.Y);
                        Point2D targetOrigin = new Point2D(originTargetCurrentX, targetCenter.Y);
                        // Here user could provide custom edgeStart and edgeEnd
                        // inflate boxes a little so that edgeStart and edgeEnd are a little outside of the box (to prevent floating point errors)
                        var edgeStart = GeomUtils.LineRectIntersection(sourceOrigin, targetOrigin, edge.From.Inflated(1e-3));
                        var edgeEnd   = GeomUtils.LineRectIntersection(sourceOrigin, targetOrigin, edge.To.Inflated(1e-3));
                        graph.AddEdgeEndpointVertices(edge, edgeStart, edgeEnd);
                        originSourceCurrentX += multiEdgeSpanSource / (multiEdgeCount - 1);
                        originTargetCurrentX += multiEdgeSpanTarget / (multiEdgeCount - 1);
                    }
                }
            }
            return(graph);
        }
コード例 #49
0
ファイル: RouteGraph.cs プロジェクト: Bombadil77/SharpDevelop
		static IEnumerable<RouteVertex> GetRectCorners(IRect rect, double padding)
		{
			double left = rect.Left - padding;
			double top = rect.Top - padding;
			double right = left + rect.Width + 2 * padding;
			double bottom = top + rect.Height + 2 * padding;
			yield return new RouteVertex(left, top);
			yield return new RouteVertex(right, top);
			yield return new RouteVertex(right, bottom);
			yield return new RouteVertex(left, bottom);
		}
コード例 #50
0
ファイル: IRect.cs プロジェクト: naninunenoy/AsmdefHelper
 public static Vector2 GetPositionXY(this IRect rect)
 {
     return(new Vector2(rect.PositionX, rect.PositionY));
 }
コード例 #51
0
ファイル: DeriveShape.cs プロジェクト: zyouhua/nvwa
 public override void _setEnd(IRect nRect)
 {
     mEndClassShape = nRect as ClassShape;
     base._setEnd(mEndClassShape);
 }
コード例 #52
0
ファイル: IRect.cs プロジェクト: naninunenoy/AsmdefHelper
 public static void SetPositionXY(this IRect rect, Vector2 pos)
 {
     rect.PositionX = pos.x;
     rect.PositionY = pos.y;
 }
コード例 #53
0
ファイル: LineCreater.cs プロジェクト: zyouhua/nvwa
 public void _setBeg(IRect nRect)
 {
     mBeg = nRect;
 }
コード例 #54
0
        public IEnumerable<IElement> HitTest(IRect rect)
        {
            var canvas = this;
            var r = new Rect(new Point(rect.X1, rect.Y1), new Point(rect.X2, rect.Y2));
            var selectedElements = new List<DependencyObject>();
            var rectangle = new RectangleGeometry(r, 0.0, 0.0);
            var hitTestParams = new GeometryHitTestParameters(rectangle);
            var resultCallback = new HitTestResultCallback(result => HitTestResultBehavior.Continue);

            var filterCallback = new HitTestFilterCallback(
                element =>
                {
                    if (VisualTreeHelper.GetParent(element) == canvas)
                        selectedElements.Add(element);

                    return HitTestFilterBehavior.Continue;
                });

            VisualTreeHelper.HitTest(canvas, filterCallback, resultCallback, hitTestParams);

            return selectedElements.Cast<IElement>();
        }
コード例 #55
0
ファイル: LineCreater.cs プロジェクト: zyouhua/nvwa
 public void _setEnd(IRect nRect)
 {
     mEnd = nRect;
 }
コード例 #56
0
 public void SetSourceRectForDrag(IRect originalRect)
 {
     
 }