Beispiel #1
0
        public Rectangle2D GetLogicalAnchor2D()
        {
            Rectangle anchor = GetAnchor2D();

            //if it is a groupped shape see if we need to transform the coordinates
            if (_parent != null)
            {
                Shape top = _parent;
                while (top.GetParent() != null)
                {
                    top = top.GetParent();
                }

                Rectangle clientAnchor = top.GetAnchor2D();
                Rectangle spgrAnchor   = ((ShapeGroup)top).GetCoordinates();

                double scalex = spgrAnchor.Width / clientAnchor.Width;
                double scaley = spgrAnchor.Height / clientAnchor.Height;

                double x      = clientAnchor.X + (anchor.X - spgrAnchor.X) / scalex;
                double y      = clientAnchor.Y + (anchor.Y - spgrAnchor.Y) / scaley;
                double width  = anchor.Width / scalex;
                double height = anchor.Height / scaley;

                anchor = new Rectangle2D.Double(x, y, width, height);
            }

            int angle = GetRotation();

            if (angle != 0)
            {
                double centerX = anchor.X + anchor.Width / 2;
                double centerY = anchor.Y + anchor.Height / 2;

                AffineTransform trans = new AffineTransform();
                trans.translate(centerX, centerY);
                trans.rotate(Math.ToRadians(angle));
                trans.translate(-centerX, -centerY);

                Rectangle2D rect = trans.CreateTransformedShape(anchor).GetBounds2D();
                if ((anchor.Width < anchor.Height && rect.Width > rect.Height) ||
                    (anchor.Width > anchor.Height && rect.Width < rect.Height))
                {
                    trans = new AffineTransform();
                    trans.translate(centerX, centerY);
                    trans.rotate(Math.PI / 2);
                    trans.translate(-centerX, -centerY);
                    anchor = trans.CreateTransformedShape(anchor).GetBounds2D();
                }
            }
            return(anchor);
        }