Пример #1
0
        private void DistributeVertically(List <Bond> bondChain, Dictionary <uint, Vex.Rectangle> transforms)
        {
            Vex.Rectangle diFirst          = transforms[bondChain[0].SourceInstanceId];
            Vex.Rectangle diLast           = transforms[bondChain[bondChain.Count - 1].SourceInstanceId];
            float         firstHeight      = diFirst.Height;
            float         lastHeight       = diLast.Height;
            float         fillHeight       = diLast.Top - (diFirst.Top + diFirst.Height);
            float         remainingHeights = 0;

            for (int i = 1; i < bondChain.Count - 1; i++)
            {
                DesignInstance di = MainForm.CurrentInstanceManager[bondChain[i].SourceInstanceId];
                remainingHeights += di.StrokeBounds.Height;
            }

            float spacing = (fillHeight - remainingHeights) / (bondChain.Count - 1);

            float curLoc = diFirst.Top;

            for (int i = 0; i < bondChain.Count - 1; i++)
            {
                uint          id = bondChain[i].SourceInstanceId;
                Vex.Rectangle r  = transforms[id];

                transforms[id] = new Vex.Rectangle(r.Left, curLoc, r.Width, r.Height);

                curLoc += spacing + r.Height;
            }
        }
Пример #2
0
        public void CalculateBounds()
        {
            if (definition is Vex.Timeline)
            {
                Vex.Timeline vt = (Vex.Timeline)definition;

                Vex.Rectangle bounds    = Vex.Rectangle.Empty;
                float         top       = int.MaxValue;
                float         left      = int.MaxValue;
                uint[]        instances = vt.GetInstanceIds();
                foreach (uint id in instances)
                {
                    DesignInstance inst = MainForm.CurrentInstanceManager[id];
                    if (inst != null && inst.Instance.GetTransformAtTime(0) != null)
                    {
                        if (bounds.IsEmpty)
                        {
                            bounds = inst.StrokeBounds;
                        }
                        else
                        {
                            bounds = inst.StrokeBounds.Union(bounds);// Rectangle.Union(bounds, inst.Bounds);
                        }

                        left = Math.Min(left, inst.Location.X);
                        top  = Math.Min(top, inst.Location.Y);
                    }
                }

                this.Definition.StrokeBounds = bounds;
            }
        }
Пример #3
0
        private Bitmap CreateRenderBitmap(Vex.Rectangle bounds, Matrix m)
        {
            if (g != null)
            {
                g.Dispose();
            }
            RectangleF sysBounds = bounds.SysRectangleF();
            SizeF      absSize   = GetAbsTransformedSize(sysBounds, m);

            Bitmap img = new Bitmap(
                (int)absSize.Width + 1,
                (int)absSize.Height + 1);

            img.SetResolution(96, 96);

            g = Graphics.FromImage(img);
            g.SmoothingMode      = SmoothingMode.AntiAlias;
            g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
            g.CompositingMode    = CompositingMode.SourceOver;
            g.CompositingQuality = CompositingQuality.AssumeLinear;

            g.Transform = m;

            return(img);
        }
Пример #4
0
 public DrawImage(Image image, uint pathId)
 {
     Id = image.Id;
     ExportName = image.Name;
     SourceRectangle = image.StrokeBounds;
     Path = image.Path;
 }
Пример #5
0
        private void DistributeHorizontally(List <Bond> bondChain, Dictionary <uint, Vex.Rectangle> transforms)
        {
            Vex.Rectangle diFirst         = transforms[bondChain[0].SourceInstanceId];
            Vex.Rectangle diLast          = transforms[bondChain[bondChain.Count - 1].SourceInstanceId];
            float         firstWidth      = diFirst.Width;
            float         lastWidth       = diLast.Width;
            float         fillWidth       = diLast.Left - (diFirst.Left + diFirst.Width);
            float         remainingWidths = 0;

            for (int i = 1; i < bondChain.Count - 1; i++)
            {
                DesignInstance di = MainForm.CurrentInstanceManager[bondChain[i].SourceInstanceId];
                remainingWidths += di.StrokeBounds.Width;
            }

            float spacing = (fillWidth - remainingWidths) / (bondChain.Count - 1);

            float curLoc = diFirst.Left;

            for (int i = 0; i < bondChain.Count - 1; i++)
            {
                uint          id = bondChain[i].SourceInstanceId;
                Vex.Rectangle r  = transforms[id];

                transforms[id] = new Vex.Rectangle(curLoc, r.Top, r.Width, r.Height);

                curLoc += spacing + r.Width;
            }
        }
Пример #6
0
 public Rectangle Union(Rectangle r)
 {
     float lf = Math.Min(this.Point.X, r.Point.X);
     float tp = Math.Min(this.Point.Y, r.Point.Y);
     float rt = Math.Max(this.Point.X + this.Size.Width, r.Point.X + r.Size.Width);
     float bt = Math.Max(this.Point.Y + this.Size.Height, r.Point.Y + r.Size.Height);
     return new Rectangle(lf, tp, rt - lf, bt - tp);
 }
Пример #7
0
 public static Rectangle SysRectangle(this Vex.Rectangle r)
 {
     return(new Rectangle(
                (int)Math.Floor(r.Left),
                (int)Math.Floor(r.Top),
                (int)Math.Ceiling(r.Width),
                (int)Math.Ceiling(r.Height)));
 }
Пример #8
0
        public DrawSymbol(Symbol symbol)
        {
            Id = symbol.Id;
            ExportName = symbol.Name;
            StrokeBounds = symbol.StrokeBounds;

            ParseShapes(symbol.Shapes);
        }
Пример #9
0
 public PointF[] GetTransformedPoints()
 {
     Vex.Rectangle tb  = UntransformedBounds;
     PointF[]      pts = tb.SysPointFs();
     using (Matrix m = GetSysMatrix().Clone())
     {
         m.TransformPoints(pts);
     }
     return(pts);
 }
Пример #10
0
 public PointF[] GetTransformedPoints(Matrix globalMatrix)
 {
     Vex.Rectangle tb  = UntransformedBounds;
     PointF[]      pts = tb.SysPointFs();
     using (Matrix m = GetSysMatrix().Clone())
     {
         m.Multiply(globalMatrix, MatrixOrder.Append);
         m.TransformPoints(pts);
     }
     return(pts);
 }
Пример #11
0
 public SysDraw.Bitmap GetCachedBitmap()
 {
     if (image == null)
     {
         SysDraw.Image img = SysDraw.Image.FromFile(Path);
         image = new SysDraw.Bitmap(img);
         image.SetResolution(96, 96);
         StrokeBounds = new Vex.Rectangle(0, 0, image.Width, image.Height);
     }
     return image;
 }
Пример #12
0
        public static PointF[] SysPointFs(this Vex.Rectangle r)
        {
            PointF[] result = new PointF[4];

            result[0] = new PointF(r.Left, r.Top);
            result[1] = new PointF(r.Right, r.Top);
            result[2] = new PointF(r.Right, r.Bottom);
            result[3] = new PointF(r.Left, r.Bottom);

            return(result);
        }
Пример #13
0
        public void CalcuateBounds()
        {
            float left = float.MaxValue;
            float right = float.MinValue;
            float top = float.MaxValue;
            float bottom = float.MinValue;
            for (int i = 0; i < ShapeData.Count; i++)
            {
                ShapeData[i].CheckExtremas(ref left, ref right, ref top, ref bottom);
            }

            bounds = new Rectangle(left, top, right - left, bottom - top);
        }
Пример #14
0
        public void ConstrainBounds(IEnumerable <uint> sourceIds, ref Vex.Rectangle bounds, ChainType chainType)
        {
            HashSet <uint> tested            = new HashSet <uint>();
            HashSet <uint> alreadyDiscovered = new HashSet <uint>();
            List <Bond>    guideBonds        = new List <Bond>();

            AppendJoinedRelations(sourceIds, tested, alreadyDiscovered, guideBonds);
            foreach (Bond b in guideBonds)
            {
                if (!chainType.IsHorizontal() && b.Next.SourceAttachment.IsVGuide())
                {
                    bounds = bounds.Intersect(MainForm.CurrentInstanceManager[b.SourceInstanceId].StrokeBounds);
                }
                else if (chainType.IsHorizontal() && b.Next.SourceAttachment.IsHGuide())
                {
                    bounds = bounds.Intersect(MainForm.CurrentInstanceManager[b.SourceInstanceId].StrokeBounds);
                }
            }
        }
Пример #15
0
 private RectangleF GetRectangleF(Vex.Rectangle rect)
 {
     return(new RectangleF(rect.Point.X, rect.Point.Y, rect.Size.Width, rect.Size.Height));
 }
Пример #16
0
 public static RectangleF SysRectangleF(this Vex.Rectangle r)
 {
     return(new RectangleF(r.Left, r.Top, r.Width, r.Height));
 }
Пример #17
0
		private Rectangle ParseSpriteBounds(DefineSpriteTag tag)
		{
			Rectangle result = Rectangle.Empty;
			for (int i = 0; i < tag.FirstFrameObjects.Count; i++)
			{
				PlaceObjectTag o = (PlaceObjectTag)tag.FirstFrameObjects[i];
				// yahoo has forward refs here... guard for now
				uint index = o.Character;
				if (!v.Definitions.ContainsKey(index))
				{
					continue;
				}
				IDefinition def = this.v.Definitions[index];
				Rectangle bnds = def.StrokeBounds;
				if (o.HasMatrix)
				{
					Point[] pts = new Point[] { bnds.Point, new Point(bnds.Point.X + bnds.Size.Width, bnds.Point.Y + bnds.Size.Height) };
					// bugfix: needed to transform the translation from twips
                    Matrix m = new Matrix(o.Matrix.ScaleX, o.Matrix.Rotate0, o.Matrix.Rotate1, o.Matrix.ScaleY, o.Matrix.TranslateX / twips, o.Matrix.TranslateY / twips);
                    m.TransformPoints(pts);
					bnds = new Rectangle(pts[0], new Size(pts[1].X - pts[0].X, pts[1].Y - pts[0].Y));
				}
				if (result == Rectangle.Empty)
				{
					result = bnds; // first placeObject
				}
				else
				{
					result = result.Union(bnds); // second+
				}
			}
			tag.ShapeBounds = new Rect(
				(int)result.Point.X,
				(int)(result.Point.X + result.Size.Width), 
				(int)result.Point.Y, 
				(int)(result.Point.Y + result.Size.Height));
			return result;
		}
Пример #18
0
 public bool Equals(Rectangle o)
 {
     return ((this.Point == o.Point) && (this.Size == o.Size));
 }
Пример #19
0
        public void Execute()
        {
            StageView     stage = MainForm.CurrentStage;
            InstanceGroup sel   = MainForm.CurrentStage.Selection;

            Vex.Rectangle bounds = sel.StrokeBounds;
            uint[]        ids    = sel.SelectedIds;
            offsets = new Vex.Point[ids.Length];

            InstanceManager im      = MainForm.CurrentInstanceManager;
            List <uint>     sortIds = new List <uint>(ids);

            im.SortIndexesByLocation(sortIds, chainType);

            Vex.Point target = Vex.Point.Empty;

            if (chainType == ChainType.DistributedHorizontal)
            {
                float firstWidth      = MainForm.CurrentInstanceManager[sortIds[0]].StrokeBounds.Width;
                float lastWidth       = MainForm.CurrentInstanceManager[sortIds[sortIds.Count - 1]].StrokeBounds.Width;
                float fillWidth       = bounds.Width - firstWidth - lastWidth;
                float remainingWidths = 0;
                for (int i = 1; i < sortIds.Count - 1; i++)
                {
                    DesignInstance di = MainForm.CurrentInstanceManager[sortIds[i]];
                    remainingWidths += di.StrokeBounds.Width;
                }

                float spacing = (fillWidth - remainingWidths) / (sortIds.Count - 1);
                float curLoc  = bounds.Left;

                for (int i = 0; i < sortIds.Count; i++)
                {
                    DesignInstance di     = MainForm.CurrentInstanceManager[sortIds[i]];
                    Vex.Point      offset = new Vex.Point(curLoc - di.StrokeBounds.Left, 0);

                    Vex.Matrix m = di.GetMatrix();
                    m.Translate(offset);
                    stage.SetDesignInstanceMatrix(di, m);

                    curLoc += spacing + di.StrokeBounds.Width;

                    int realIndex = Array.IndexOf(ids, sortIds[i]);
                    offsets[realIndex] = offset;
                }

                target = new Vex.Point(spacing, float.NaN);
            }
            else if (chainType == ChainType.DistributedVertical)
            {
                float firstHeight      = MainForm.CurrentInstanceManager[sortIds[0]].StrokeBounds.Height;
                float lastHeight       = MainForm.CurrentInstanceManager[sortIds[sortIds.Count - 1]].StrokeBounds.Height;
                float fillHeight       = bounds.Height - firstHeight - lastHeight;
                float remainingHeights = 0;
                for (int i = 1; i < sortIds.Count - 1; i++)
                {
                    DesignInstance di = MainForm.CurrentInstanceManager[sortIds[i]];
                    remainingHeights += di.StrokeBounds.Height;
                }

                float spacing = (fillHeight - remainingHeights) / (sortIds.Count - 1);
                float curLoc  = bounds.Top;

                for (int i = 0; i < sortIds.Count; i++)
                {
                    DesignInstance di     = MainForm.CurrentInstanceManager[sortIds[i]];
                    Vex.Point      offset = new Vex.Point(0, curLoc - di.StrokeBounds.Top);

                    Vex.Matrix m = di.GetMatrix();
                    m.Translate(offset);
                    stage.SetDesignInstanceMatrix(di, m);

                    curLoc += spacing + di.StrokeBounds.Height;

                    int realIndex = Array.IndexOf(ids, sortIds[i]);
                    offsets[realIndex] = offset;
                }
                target = new Vex.Point(float.NaN, spacing);
            }
            else
            {
                Vex.Rectangle contrainedBounds = bounds.Clone();
                stage.CurrentEditItem.BondStore.ConstrainBounds(sortIds, ref contrainedBounds, chainType);

                switch (chainType)
                {
                case ChainType.AlignedLeft:
                    target = new Vex.Point(contrainedBounds.Left, float.NaN);
                    break;

                case ChainType.AlignedCenterVertical:
                    target = new Vex.Point(contrainedBounds.Center.X, float.NaN);
                    break;

                case ChainType.AlignedRight:
                    target = new Vex.Point(contrainedBounds.Right, float.NaN);
                    break;

                case ChainType.AlignedTop:
                    target = new Vex.Point(float.NaN, contrainedBounds.Top);
                    break;

                case ChainType.AlignedCenterHorizontal:
                    target = new Vex.Point(float.NaN, contrainedBounds.Center.Y);
                    break;

                case ChainType.AlignedBottom:
                    target = new Vex.Point(float.NaN, contrainedBounds.Bottom);
                    break;
                }

                for (int i = 0; i < sortIds.Count; i++)
                {
                    DesignInstance di     = MainForm.CurrentInstanceManager[sortIds[i]];
                    Vex.Point      offset = Vex.Point.Zero;

                    switch (chainType)
                    {
                    case ChainType.AlignedLeft:
                        offset.X = target.X - di.StrokeBounds.Left;
                        break;

                    case ChainType.AlignedCenterVertical:
                        offset.X = target.X - (di.StrokeBounds.Left + di.StrokeBounds.Width / 2);
                        break;

                    case ChainType.AlignedRight:
                        offset.X = target.X - (di.StrokeBounds.Left + di.StrokeBounds.Width);
                        break;

                    case ChainType.AlignedTop:
                        offset.Y = target.Y - di.StrokeBounds.Top;
                        break;

                    case ChainType.AlignedCenterHorizontal:
                        offset.Y = target.Y - (di.StrokeBounds.Top + di.StrokeBounds.Height / 2);
                        break;

                    case ChainType.AlignedBottom:
                        offset.Y = target.Y - (di.StrokeBounds.Top + di.StrokeBounds.Height);
                        break;
                    }

                    Vex.Matrix m = di.GetMatrix();
                    m.Translate(offset);
                    stage.SetDesignInstanceMatrix(di, m);

                    offsets[i] = offset;
                }
            }

            if (useSmartBonds)
            {
                stage.CurrentEditItem.BondStore.Align(sortIds.ToArray(), chainType, target, addedBonds, previousBonds);
            }

            sel.Update();
            MainForm.CurrentStage.ResetTransformHandles();
            MainForm.CurrentStage.InvalidateTransformedSelection();
        }
Пример #20
0
        public void OpenSymbolDefTag(string key, Rectangle r, bool isPart)
        {
            // <Canvas Width="10" Height="10" RenderTransformOrigin="0,0" Canvas.Left="0" Canvas.Top="0">
            xw.WriteStartElement("Canvas");

            xw.WriteStartAttribute("x:Name");
            xw.WriteValue(key);
            xw.WriteEndAttribute();

            xw.WriteStartAttribute("Width");
            xw.WriteValue(r.Size.Width);
            xw.WriteEndAttribute();

            xw.WriteStartAttribute("Height");
            xw.WriteValue(r.Size.Height);
            xw.WriteEndAttribute();

            //string rt = (-r.Point.X).ToString() + "," + (-r.Point.Y).ToString();
            xw.WriteAttributeString("RenderTransformOrigin", "0,0");
            if (isPart)
            {
                xw.WriteAttributeString("Canvas.Left", (-r.Point.X).ToString());
                xw.WriteAttributeString("Canvas.Top", (-r.Point.Y).ToString());
            }
            else
            {
                xw.WriteAttributeString("Canvas.Left", "0");//r.Point.X.ToString());
                xw.WriteAttributeString("Canvas.Top", "0");//r.Point.Y.ToString());
            }
        }
Пример #21
0
 private void WriteRect(Rectangle r)
 {
     int[] values = new int[]
     {
         (int)(r.Left * DrawObject.twips),
         (int)(r.Top * DrawObject.twips),
         (int)(r.Width * DrawObject.twips),
         (int)(r.Height * DrawObject.twips),
     };
     WriteFourNBitValues(values);
 }