示例#1
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;
            }
        }
示例#2
0
        public void ResetTransform()
        {
            if (transformMatrix != null)
            {
                transformMatrix.Dispose();
            }

            if (list.Count == 1)
            {
                DesignInstance di = instanceManager[list[0]];
                transformMatrix     = di.GetMatrix().SysMatrix();
                center              = di.RotationCenter;
                untransformedBounds = di.Definition.StrokeBounds;//.TranslatedRectangle(-di.Location.X, -di.Location.Y);
            }
            else
            {
                transformMatrix = new Matrix();
                transformMatrix.Translate(StrokeBounds.Left, StrokeBounds.Top, MatrixOrder.Append);
                center = StrokeBounds.LocalCenter;
                //center = StrokeBounds.LocalCenter.Translate(StrokeBounds.Point);
                untransformedBounds = StrokeBounds.TranslatedRectangle(-StrokeBounds.Left, -StrokeBounds.Top);
            }

            isTransformDirty = false;
        }
示例#3
0
        public void ScaleAt(float scaleX, float scaleY, Vex.Point center)
        {
            scaleX = (Math.Abs(scaleX) < .01) ? .01f : scaleX;
            scaleY = (Math.Abs(scaleY) < .01) ? .01f : scaleY;

            Matrix tm = TransformMatrix.Clone();

            tm.Translate(-TransformMatrix.OffsetX, -TransformMatrix.OffsetY, MatrixOrder.Append);
            Matrix itm = tm.Clone();

            itm.Invert();

            foreach (uint id in list)
            {
                DesignInstance inst = instanceManager[id];

                using (Matrix ms = inst.GetMatrix().SysMatrix())
                {
                    ms.Translate(-center.X, -center.Y, MatrixOrder.Append);
                    ms.Multiply(itm, MatrixOrder.Append);
                    ms.Scale(scaleX, scaleY, MatrixOrder.Append);
                    ms.Multiply(tm, MatrixOrder.Append);
                    ms.Translate(center.X, center.Y, MatrixOrder.Append);

                    inst.SetMatrix(ms.VexMatrix());
                }
            }
            tm.Dispose();
            itm.Dispose();

            transformMatrix.ScaleAt(scaleX, scaleY, center.SysPointF());
            isDirty = true;
            MainForm.CurrentStage.InvalidateTransformedSelection();
        }
示例#4
0
 public void DrawOutlineInto(Graphics g, float offsetX, float offsetY)
 {
     foreach (uint id in list)
     {
         DesignInstance inst = instanceManager[id];
         inst.DrawOutlineInto(g, offsetX, offsetY);
     }
 }
示例#5
0
 public DesignInstance[] RemoveInstancesById(uint[] instanceIds)
 {
     DesignInstance[] removedInstances = new DesignInstance[instanceIds.Length];
     for (int i = 0; i < instanceIds.Length; i++)
     {
         uint id = instanceIds[i];
         removedInstances[i] = Remove(id);
     }
     selectedItems.Clear();
     return(removedInstances);
 }
示例#6
0
        public DesignInstance Remove(uint instId)
        {
            selectedItems.Remove(instId);
            DesignInstance di = stage.InstanceManager[instId];

            Vex.IInstance inst = di.Instance;
            timeline.RemoveInstance(inst);
            stage.InstanceManager.RemoveInstance(di);
            SnapStore.RemoveInstance(di);
            BondStore.RemoveBondsForInstance(instId);
            return(di);
        }
示例#7
0
        private void TranslateElement(uint id, float newBoundsLeft, float newBoundsTop)
        {
            DesignInstance inst = instanceManager[id];

            using (Matrix mr = inst.GetMatrix().SysMatrix())
            {
                mr.Translate(newBoundsLeft - inst.StrokeBounds.Left, newBoundsTop - inst.StrokeBounds.Top, MatrixOrder.Append);
                inst.SetMatrix(mr.VexMatrix());
            }

            isDirty = true;
        }
示例#8
0
        public void InsertExistingOnUndo(int depth, DesignInstance di)
        {
            depth = Math.Max(0, Math.Min(timeline.InstanceCount, depth));
            timeline.InsertInstance(depth, di.Instance);
            if (!stage.InstanceManager.Contains(di.InstanceHash))
            {
                stage.InstanceManager.AddInstance(di);
            }

            di.ParentInstanceId = InstanceHash;
            SnapStore.AddInstance(di);
        }
示例#9
0
        public DesignInstance Add(uint definitionId, Vex.Point location)
        {
            DesignInstance si = stage.CreateInstance(definitionId, location);

            if (si != null)
            {
                timeline.AddInstance(si.Instance);
                si.ParentInstanceId = InstanceHash;
                selectedItems.Clear();
                selectedItems.Add(si.InstanceHash);
                SnapStore.AddInstance(si);
            }
            return(si);
        }
示例#10
0
        public void DrawTranslated(Graphics g, uint id, float newLocX, float newLocY)
        {
            Matrix m = g.Transform;

            DesignInstance inst = instanceManager[id];

            using (Matrix mr = inst.GetMatrix().SysMatrix())
            {
                mr.Translate(newLocX - inst.Location.X, newLocY - inst.Location.Y, MatrixOrder.Append);
                mr.Multiply(m, MatrixOrder.Append);
                g.Transform = mr;
                inst.DrawOutlineIntoRaw(g, 0, 0);
            }

            g.Transform = m;
        }
示例#11
0
        public void RotateAt(float angle, Vex.Point center)
        {
            foreach (uint id in list)
            {
                DesignInstance inst = instanceManager[id];
                using (Matrix mr = inst.GetMatrix().SysMatrix())
                {
                    mr.RotateAt(angle, center.SysPointF(), MatrixOrder.Append);
                    inst.SetMatrix(mr.VexMatrix());
                }
            }

            transformMatrix.RotateAt(angle, center.SysPointF(), MatrixOrder.Append);
            isDirty = true;
            MainForm.CurrentStage.InvalidateTransformedSelection();
        }
示例#12
0
 public uint[] AddRange(uint[] libraryIds, Vex.Point[] locations)
 {
     uint[] selIds = new uint[libraryIds.Length];
     for (int i = 0; i < libraryIds.Length; i++)
     {
         DesignInstance si = stage.CreateInstance(libraryIds[i], locations[i]);
         if (si != null)
         {
             timeline.AddInstance(si.Instance);
             si.ParentInstanceId = InstanceHash;
             selIds[i]           = si.InstanceHash;
             SnapStore.AddInstance(si);
         }
     }
     return(selIds);
 }
示例#13
0
        public static DesignInstance LoadFromPath(StageView stage, string type, string dataPath)
        {
            DesignInstance result = null;

            FileStream    fs = new FileStream(dataPath, FileMode.Open);
            XmlSerializer xs = new XmlSerializer(typeof(Vex.Instance));

            Vex.Instance inst = (Vex.Instance)xs.Deserialize(fs);
            fs.Close();

            result = stage.CreateInstance(inst);
            if (result != null)
            {
                result.HasSaveableChanges = false;
            }
            return(result);
        }
示例#14
0
        public void DrawRotated(Graphics g, float angle, Vex.Point center)
        {
            Matrix m = g.Transform;

            foreach (uint id in list)
            {
                DesignInstance inst = instanceManager[id];
                using (Matrix mr = inst.GetMatrix().SysMatrix())
                {
                    mr.RotateAt(angle, center.SysPointF(), MatrixOrder.Append);
                    mr.Multiply(m, MatrixOrder.Append);
                    g.Transform = mr;
                    inst.DrawOutlineIntoRaw(g, 0, 0);
                }
            }
            g.Transform = m;
        }
示例#15
0
        public void EnsureSnaps()
        {
            if (!SnapStore.HasSnaps && (Guidelines.Count > 0 || this.Count > 0))
            {
                uint[] instIds = InstanceIds;
                for (int i = 0; i < instIds.Length; i++)
                {
                    DesignInstance di = stage.InstanceManager[instIds[i]];
                    SnapStore.AddInstance(di);
                }

                Guide[] guides = Guidelines.Guides;
                for (int i = 0; i < guides.Length; i++)
                {
                    SnapStore.AddInstance(guides[i]);
                }
            }
        }
示例#16
0
        public void GetFullMatrix(out Matrix m)
        {
            if (stage.InstanceManager.Contains(ParentInstanceId))
            {
                DesignInstance parent = stage.InstanceManager[ParentInstanceId];
                m = parent.GetMatrix().SysMatrix();
                m.Invert();
            }
            else
            {
                m = new SysMatrix();
            }

            using (Matrix lm = instance.GetTransformAtTime(0).Matrix.SysMatrix())
            {
                lm.Invert();
                m.Multiply(lm, MatrixOrder.Append);
            }
        }
示例#17
0
        public void DrawScaled(Graphics g, float scaleX, float scaleY, Vex.Point center)
        {
            Matrix m = g.Transform;

            scaleX = (Math.Abs(scaleX) < .01) ? .01f : scaleX;
            scaleY = (Math.Abs(scaleY) < .01) ? .01f : scaleY;

            Matrix tm = TransformMatrix.Clone();

            tm.Translate(-TransformMatrix.OffsetX, -TransformMatrix.OffsetY, MatrixOrder.Append);
            Matrix itm = tm.Clone();

            itm.Invert();

            foreach (uint id in list)
            {
                DesignInstance inst = instanceManager[id];

                using (Matrix ms = inst.GetMatrix().SysMatrix())
                {
                    ms.Translate(-center.X, -center.Y, MatrixOrder.Append);
                    ms.Multiply(itm, MatrixOrder.Append);
                    ms.Scale(scaleX, scaleY, MatrixOrder.Append);
                    ms.Multiply(tm, MatrixOrder.Append);
                    ms.Translate(center.X, center.Y, MatrixOrder.Append);

                    ms.Multiply(m, MatrixOrder.Append);
                    g.Transform = ms;
                    inst.DrawOutlineIntoRaw(g, 0, 0);
                }
            }

            tm.Dispose();
            itm.Dispose();

            g.Transform = m;
        }
示例#18
0
        public void DrawOutlineAndBonds(uint id, float newBoundsLeft, float newBoundsTop)
        {
            DesignInstance di   = stage.CurrentEditItem[id];
            PointF         diff = new PointF(newBoundsLeft - di.StrokeBounds.Left, newBoundsTop - di.StrokeBounds.Top);

            // draw outlines
            if (diff != PointF.Empty)
            {
                GraphicsState gs = graphicHolder.Save();
                graphicHolder.Transform = stage.CameraMatrix;
                stage.Selection.DrawTranslated(graphicHolder, id, newBoundsLeft, newBoundsTop);
                graphicHolder.Restore(gs);
            }

            // draw bonds
            PointF[] pts = di.GetTransformedPoints(stage.CameraMatrix);

            PointF[] tps = new PointF[] { diff };
            stage.CameraMatrix.TransformVectors(tps);
            pts.TranslatePoints(tps[0].X, tps[0].Y);
            PointF[] bondPoints = pts.GetMidpointsAndCenter();

            DrawBondHandles(stage.CurrentEditItem, bondPoints, id);
        }
示例#19
0
        public Vex.Rectangle CalculateBounds(uint[] instances, out Vex.Point topLeft)
        {
            Vex.Rectangle bounds = Vex.Rectangle.Empty;
            float         top    = int.MaxValue;
            float         left   = int.MaxValue;

            foreach (uint id in instances)
            {
                DesignInstance inst = instanceManager[id];
                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);
            }
            topLeft = new Vex.Point(left, top);
            return(bounds);
        }