Exemplo n.º 1
0
        public VectorBox boundingBox()
        {
            Vector    A    = pos;
            Vector    B    = pos + X;
            Vector    C    = pos + X + Y;
            Vector    D    = pos + Y;
            double    minX = min4(A.x, B.x, C.x, D.x);
            double    minY = min4(A.y, B.y, C.y, D.y);
            double    maxX = max4(A.x, B.x, C.x, D.x);
            double    maxY = max4(A.y, B.y, C.y, D.y);
            VectorBox v    = new VectorBox(Vector.V(minX, minY), maxX - minX, maxY - minY);

            return(v);
        }
Exemplo n.º 2
0
        private void getNamedPoints(RTIO io, out Vector pstart, out Vector pstop,
                                    out Vector textpos, out Vector textdir)
        {
            Vector     pos  = Vector.Zero;
            Vector     dir  = Vector.Zero;
            VectorRect vr   = VectorRect.Empty;
            int        rank = 0;

            io.getPosAndDir(ref pos, ref dir, ref vr, ref rank);
            pstart = owner.toScreen(pos);
            VectorBox vx = GraphicsUtil.sizeText(owner.netNameFont, _name, 2, -1, -1);

            pstop = pstart + dir * owner.scale * (vx.boundingDim().x + 20);
            if (dir.x < 0)
            {
                textpos = pstop - dir * owner.scale * 10;
                textdir = -dir;
            }
            else
            {
                textpos = pstart + dir * owner.scale * 10;
                textdir = dir;
            }
        }
Exemplo n.º 3
0
 public VectorBox(VectorBox v)
 {
     pos = v.pos;
     X   = v.X;
     Y   = v.Y;
 }
Exemplo n.º 4
0
        public RectangleF boundingBoxRF()
        {
            VectorBox v = boundingBox();

            return(new RectangleF(v.pos.PointF, (v.X + v.Y).SizeF));
        }
Exemplo n.º 5
0
        // Just simulate Rendering an return the size Box
        public static VectorBox sizeText(Vector pos, Font f, double scale, string txt, int bx, double space, int ax, int ay, Vector dir)
        {
            if (txt == null)
            {
                return(new VectorBox(pos, new Vector(0, 0), new Vector(0, 0)));
            }
            if (dir.Len == 0)
            {
                dir = new Vector(1, 0);
            }
            txt = txt.Replace('|', '\n');

            if (gp == null)
            {
                gp = new GraphicsPath();
            }
            else
            {
                gp.Reset();
            }
            // GraphicsPath gp = new GraphicsPath();

            // String Internal Alignment
            StringFormat sf = new StringFormat();

            if (bx < 0)
            {
                sf.Alignment = StringAlignment.Near;
            }
            else if (bx > 0)
            {
                sf.Alignment = StringAlignment.Far;
            }
            else
            {
                sf.Alignment = StringAlignment.Center;
            }

            gp.AddString(txt, f.FontFamily, (int)f.Style, f.Height, new PointF(0, 0), sf);

            RectangleF bb = gp.GetBounds();

            bb.Inflate(new SizeF((float)space, (float)space));

            double w  = bb.Width;
            double h  = bb.Height;
            double cx = bb.Left + w / 2;
            double cy = bb.Top + h / 2;

            Matrix mtx = new Matrix();

            mtx.Translate((float)-cx, (float)-cy); // Center

            VectorBox vb = new VectorBox();

            vb.X   = new Vector(bb.Width, 0);
            vb.Y   = new Vector(0, bb.Height);
            vb.pos = -vb.X / 2 - vb.Y / 2;

            if (ax < 0)
            {
                mtx.Translate((float)w / 2, 0, MatrixOrder.Append);
                vb.translate(new Vector(w / 2, 0));
            }
            else if (ax > 0)
            {
                mtx.Translate((float)-w / 2, 0, MatrixOrder.Append);
                vb.translate(new Vector(-w / 2, 0));
            }

            if (ay < 0)
            {
                mtx.Translate(0, (float)-h / 2, MatrixOrder.Append);
                vb.translate(new Vector(0, -h / 2));
            }
            else if (ay > 0)
            {
                mtx.Translate(0, (float)h / 2, MatrixOrder.Append);
                vb.translate(new Vector(0, h / 2));
            }

            // Rotate
            mtx.Rotate((float)(dir.Phi * 180 / Math.PI), MatrixOrder.Append);
            vb.rot(dir.Phi);

            mtx.Scale((float)scale, (float)scale, MatrixOrder.Append);
            vb.scale(scale);

            // Translate to final position
            mtx.Translate((float)pos.x, (float)pos.y, MatrixOrder.Append);
            vb.translate(pos);

            // gp.Dispose();


            return(vb);
        }