Beispiel #1
0
        public DesignTimeline(StageView stage, Vex.Instance inst) : base(stage, inst)
        {
            selectedItems = new InstanceGroup(stage.InstanceManager);

            SnapStore  = new SnapStore(this);
            BondStore  = new BondStore(this);
            Guidelines = new Guidelines(this);
        }
Beispiel #2
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);
        }
Beispiel #3
0
 // filtered meaning remove annotations like box2d bounding boxes
 private void DrawFilteredTimeline(Vex.Timeline tl, uint frame)
 {
     for (int i = 0; i < tl.InstanceCount; i++)
     {
         Vex.Instance inst = (Vex.Instance)tl.InstanceAt(i);
         if (inst.GetTransformAtTime(frame) != null)
         {
             Vex.IDefinition idef = stage.Library[inst.DefinitionId].Definition;
             if (idef is Vex.Symbol || idef is Vex.Timeline)
             {
                 GraphicsState gs = g.Save();
                 using (Matrix nm = inst.GetTransformAtTime(0).Matrix.GetDrawing2DMatrix())
                 {
                     nm.Multiply(g.Transform, MatrixOrder.Append);
                     g.Transform = nm;
                     if (idef is Vex.Symbol)
                     {
                         DrawFilteredSymbol((Vex.Symbol)idef);
                     }
                     else
                     {
                         DrawFilteredTimeline((Vex.Timeline)idef, frame);
                     }
                 }
                 g.Restore(gs);
             }
             else if (idef is Vex.Text)
             {
                 DrawText((Vex.Text)idef, inst.Transformations[0].Matrix);
             }
             else if (idef is Vex.Image)
             {
                 Matrix pm = g.Transform.Clone();
                 Matrix nm = inst.GetTransformAtTime(0).Matrix.GetDrawing2DMatrix();
                 nm.Multiply(pm, MatrixOrder.Append);
                 g.Transform = nm;
                 DrawImage(stage.BitmapCache.GetBitmap(idef));
                 g.Transform = pm;
             }
         }
     }
 }
        private void WriteTransformsDefs(IDefinition s, Instance inst, string fullName)
        {
            //<Canvas.RenderTransform>
            //<TransformGroup>
            //  <RotateTransform x:Name="inst_rt_0r" Angle="0" />
            //  <SkewTransform x:Name="inst_rt_0k" AngleX="0" AngleY="0"/>
            //  <ScaleTransform x:Name="inst_rt_0s" ScaleX="1" ScaleY="1" />
            //  <TranslateTransform x:Name="inst_rt_0t" X="35" Y="26" />
            //</TransformGroup>
            //</Canvas.RenderTransform>

            IDefinition def = v.Definitions[s.Id];
            //string defName = instancePrefix + GetInstanceName(inst);

            Rectangle r = s.StrokeBounds;
            Matrix m = inst.Transformations[0].Matrix;
            MatrixComponents mt = m.GetMatrixComponents();

            bool multiTransform = true;// inst.Transformations.Count > 1;
            bool hasRot = !(mt.Rotation == 0);
            bool hasSkew = !(mt.Shear == 0);
            bool hasScale = !(mt.ScaleX == 1 && mt.ScaleY == 1);
            bool hasTranslate = !(mt.TranslateX == 0 && mt.TranslateY == 0 && r.Point.X == 0 && r.Point.Y == 0);

            if (multiTransform || hasRot || hasSkew || hasScale || hasTranslate)
            {
                xw.WriteStartElement("Canvas.RenderTransform");
                xw.WriteStartElement("TransformGroup");

                if (multiTransform || hasRot)
                {
                    xw.WriteStartElement("RotateTransform");
                    xw.WriteStartAttribute("x:Name");
                    xw.WriteValue(fullName + "r");
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("Angle");
                    //xw.WriteValue(mt.Rotation);
                    xw.WriteValue(0);
                    xw.WriteEndAttribute();
                    xw.WriteEndElement();
                }

                if (multiTransform || hasSkew)
                {
                    xw.WriteStartElement("SkewTransform");
                    xw.WriteStartAttribute("x:Name");
                    xw.WriteValue(fullName + "k");
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("AngleX");
                    //xw.WriteValue(mt.Shear);
                    xw.WriteValue(0);
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("AngleY");
                    xw.WriteValue(0);
                    xw.WriteEndAttribute();
                    xw.WriteEndElement();
                }

                if (multiTransform || hasScale)
                {
                    xw.WriteStartElement("ScaleTransform");
                    xw.WriteStartAttribute("x:Name");
                    xw.WriteValue(fullName + "s");
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("ScaleX");
                    //xw.WriteValue(mt.ScaleX);
                    xw.WriteValue(1);
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("ScaleY");
                    //xw.WriteValue(mt.ScaleY);
                    xw.WriteValue(1);
                    xw.WriteEndAttribute();
                    xw.WriteEndElement();
                }

                if (multiTransform || hasTranslate)
                {
                    xw.WriteStartElement("TranslateTransform");
                    xw.WriteStartAttribute("x:Name");
                    xw.WriteValue(fullName + "t");
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("X");
                    //xw.WriteValue(mt.TranslateX + r.Point.X);
                    xw.WriteValue(0);
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("Y");
                    //xw.WriteValue(mt.TranslateY + r.Point.Y);
                    xw.WriteValue(0);
                    xw.WriteEndAttribute();
                    xw.WriteEndElement();
                }

                xw.WriteEndElement(); //TransformGroup
                xw.WriteEndElement(); //Canvas.RenderTransform
            }
        }
Beispiel #5
0
		private void ParsePlaceObjectTag(PlaceObjectTag tag)
		{
			uint curTime = (uint)((curFrame * (1 / swf.Header.FrameRate)) * 1000);
            uint totalTime = GetDuration(this.curTimeline.FrameCount);

			Vex.Matrix mx = ParseMatrix(tag.Matrix);
			float alpha = 1;

			Instance inst = new Instance();
			inst.DefinitionId = tag.Character;
			inst.StartTime = curTime;
			inst.EndTime = totalTime;
            inst.Depth = (int)tag.Depth;

            // error from flashDevelop files
            if (curDepthChart.ContainsKey(tag.Depth))
            {
                curDepthChart.Remove(tag.Depth);
            }
			curDepthChart.Add(tag.Depth, inst);
			this.curTimeline.AddInstance(inst);

			if (tag.HasColorTransform && (tag.ColorTransform.HasAddTerms || tag.ColorTransform.HasMultTerms))
			{
				int addMult = tag.ColorTransform.AMultTerm + tag.ColorTransform.AAddTerm;
				alpha = addMult < 0 ? 0 : addMult / 256F;
			}
            ColorTransform c = tag.ColorTransform;
            Vex.ColorTransform ct = new Vex.ColorTransform(c.RAddTerm, c.RMultTerm, c.GAddTerm, c.GMultTerm, c.BAddTerm, c.BMultTerm, c.AAddTerm, c.AMultTerm);

			inst.Transformations.Add(new Transform(curTime, totalTime, mx, alpha, ct));
		}
Beispiel #6
0
        private void EnsureDefinition(Instance inst, IDefinition def)
        {
            DefinitionKind dk = (DefinitionKind)def.UserData;
            bool addInst = (inst != null);
            Matrix m = (inst == null) ? Matrix.Identity : inst.Transformations[0].Matrix;

            if ((dk & DefinitionKind.Ignore) == 0)
            {
                if (((dk & DefinitionKind.JointMarker) != 0) && (inst != null))
                {
                    V2DJointKind jointKind = jointKindMap[jointKinds.IndexOf(def.Name)];
                    ParseJoint(jointKind, inst);
                }
                else if (((dk & DefinitionKind.ShapeMarker) != 0) && (inst != null))
                {
                    if (!parentStack.Peek().Definition.IsDefined)
                    {
                        parentStack.Peek().Definition.AddShapes(curVo, def, m);
                    }
                }

                if ((dk & DefinitionKind.TextField) != 0)
                {
                    Text txt = (Text)def;
                    if (def.Name == null)
                    {
                        def.Name = "$tx_" + def.Id;
                    }
                    Definition2D d2d = GetTextDefinition(m, txt);
                    if (txt.TextRuns.Count > 0 && !txt.TextRuns[0].isEditable)
                    {
                        AddSymbolImage(def);
                    }

                    if (addInst)
                    {
                        AddInstance(inst, def);
                    }
                }

                if ((dk & DefinitionKind.Timeline) != 0)
                {
                    Definition2D d2d = GetDefinition2D(m, def);

                    Instance2D i2d;
                    if (addInst)
                    {
                        i2d = AddInstance(inst, def);
                    }
                    else
                    {
                        i2d = CreateInstance2D(def);
                    }
                    parentStack.Push(i2d);
                    ParseTimeline((Timeline)def);
                    i2d.Definition.IsDefined = true;
                    parentStack.Pop();
                }

                if ((dk & DefinitionKind.Symbol) != 0)
                {
                    // todo: this is just adding images
                    //Body2D b2d = CreateBody2D(inst, def);
                    if (def.Name == null)
                    {
                        def.Name = "$sym_" + def.Id;
                    }
                    Definition2D d2d = GetDefinition2D(m, def);
                    AddSymbolImage(def);

                    if (addInst)
                    {
                        AddInstance(inst, def);
                    }
                }

                if ((dk & DefinitionKind.Vex2D) != 0)
                {
                    Definition2D d2d = GetDefinition2D(m, def);

                    if (!isDefined.Contains(def.Id))
                    {
                        isDefined.Add(def.Id);
                        d2d.AddShapes(curVo, def, m);
                        //parentStack.Peek().Definition.AddShapes(curVo, def, m);
                    }

                    Instance2D i2d;
                    if (addInst)
                    {
                        i2d = AddInstance(inst, def);
                    }
                    else
                    {
                        i2d = CreateInstance2D(def);
                    }

                    parentStack.Push(i2d);
                    ParseTimeline((Timeline)def);
                    i2d.Definition.IsDefined = true;
                    parentStack.Pop();
                }
            }

            if (!isDefined.Contains(def.Id))
            {
                isDefined.Add(def.Id);
            }
        }
Beispiel #7
0
 private Instance2D AddInstance(Instance inst, IDefinition def)
 {
     Instance2D result = null;
     if (inst != null)
     {
         result = CreateInstance2D(inst, def);
         if (!parentStack.Peek().Definition.IsDefined)
         {
             parentStack.Peek().Definition.Children.Add(result);
         }
     }
     return result;
 }
Beispiel #8
0
		protected void WriteOpenMask(IDefinition def, Instance instance)
		{
			//<Canvas x:Name="mask0">   
			 // <Canvas.Clip >     
			 //       <PathGeometry x:Name="inst_rt_0" Figures="M -10.000,111.000 L 62.000,46.000... " />
			 // </Canvas.Clip>  
			//</Canvas>

			xw.WriteStartElement("Canvas"); // this will be closed when the mask depth level is equaled

			//string name = GetInstanceName(instance) + VexObject.MaskPrefix + instance.Depth;
			string name = instancePrefix + instName;
			xw.WriteStartAttribute("x:Name");
			xw.WriteValue(name);
			xw.WriteEndAttribute();

			xw.WriteStartElement("Canvas.Clip");
			xw.WriteStartElement("PathGeometry");

			if (def is Symbol)
			{
				Point offset = new Point(0, 0);
				if (instance.Transformations.Count > 0)
				{
					offset.X = instance.Transformations[0].Matrix.TranslateX;
					offset.Y = instance.Transformations[0].Matrix.TranslateY;
				}
				WriteClipPoints(((Symbol)def).Shapes, offset);
			}

			xw.WriteEndElement(); // PathGeometry
			xw.WriteEndElement(); // Canvas.Clip

			//one more element to close at end of clipping
		}
Beispiel #9
0
        private V2DInstance CreateInstance(Instance inst, V2DDefinition def)
        {
            V2DInstance result = new V2DInstance();

            result.InstanceName = inst.Name;
            result.Definition = def;
            result.DefinitionName = def.Name;
            result.Depth = (int)inst.Depth;
            result.StartFrame = curVo.GetFrameFromMillisecondsGetFrame(inst.StartTime);
            result.TotalFrames = curVo.GetFrameFromMillisecondsGetFrame(inst.EndTime - inst.StartTime);
            Matrix m = inst.Transformations[0].Matrix;
            result.UserData = m;
            AddSymbolImage(inst, def);

            curDef.Instances.Add(result);
            return result;
        }
Beispiel #10
0
        public void WriteVisibility(Instance inst)
        {
            //<ObjectAnimationUsingKeyFrames
            //    Storyboard.TargetName="inst3"
            //    Storyboard.TargetProperty="Visibility"
            //    Duration="0:0:.8"
            //    RepeatBehavior="Forever">
            //    <DiscreteObjectKeyFrame KeyTime="0:0:.35"   Value="{x:Static Visibility.Visible}" />
            //</ObjectAnimationUsingKeyFrames>

            Timeline curTL = (timelineStack.Count == 0) ?
                v.Root :
                (Timeline)v.Definitions[timelineStack.Peek().DefinitionId];

            xw.WriteStartElement("ObjectAnimationUsingKeyFrames");

            xw.WriteStartAttribute("Storyboard.TargetName");
            xw.WriteValue(instancePrefix + instName);
            xw.WriteEndAttribute();

            xw.WriteStartAttribute("Storyboard.TargetProperty");
            xw.WriteValue("Visibility");
            xw.WriteEndAttribute();

            xw.WriteStartAttribute("Duration");
            xw.WriteMilliseconds(curTL.Duration);
            xw.WriteEndAttribute();

            xw.WriteStartAttribute("RepeatBehavior");
            xw.WriteValue("Forever");
            xw.WriteEndAttribute();

            if (inst.StartTime > 0)
            {
                xw.WriteStartElement("DiscreteObjectKeyFrame");
                xw.WriteStartAttribute("KeyTime");
                xw.WriteMilliseconds(0);
                xw.WriteEndAttribute();
                xw.WriteStartAttribute("Value");
                xw.WriteValue("{x:Static Visibility.Hidden}");
                xw.WriteEndAttribute();
                xw.WriteEndElement();
            }

            xw.WriteStartElement("DiscreteObjectKeyFrame");
            xw.WriteStartAttribute("KeyTime");
            xw.WriteMilliseconds(inst.StartTime);
            xw.WriteEndAttribute();
            xw.WriteStartAttribute("Value");
            xw.WriteValue("{x:Static Visibility.Visible}");
            xw.WriteEndAttribute();
            xw.WriteEndElement();

            xw.WriteStartElement("DiscreteObjectKeyFrame");
            xw.WriteStartAttribute("KeyTime");
            xw.WriteMilliseconds(inst.EndTime);
            xw.WriteEndAttribute();
            xw.WriteStartAttribute("Value");
            xw.WriteValue("{x:Static Visibility.Hidden}");
            xw.WriteEndAttribute();
            xw.WriteEndElement();

            xw.WriteEndElement();
        }
Beispiel #11
0
        public void WriteStoryboard(IDefinition s, Instance inst)
        {
            // <MatrixAnimationUsingKeyFrames
            //		Storyboard.TargetName="inst_1"
            //		Storyboard.TargetProperty="RenderTransform.Matrix"
            //		RepeatBehavior="Forever" >
            //   <DiscreteMatrixKeyFrame KeyTime="0" Value="1 0 0 1 0 110"/>
            //   <DiscreteMatrixKeyFrame KeyTime="0:0:0.25" Value="1 0 0 1 5 110"/>
            //   <DiscreteMatrixKeyFrame KeyTime="0:0:0.35" Value="1 0 0 1 30 110"/>
            //   <DiscreteMatrixKeyFrame KeyTime="0:0:0.50" Value="1 0 0 1 35 110"/>
            // </MatrixAnimationUsingKeyFrames>

            Timeline curTL = (timelineStack.Count == 0) ?
                v.Root :
                (Timeline)v.Definitions[timelineStack.Peek().DefinitionId];

            // only write transforms if they exist
            // at least the Yahoo avatar tool will write no transforms,
            // and then modify on the instance only
            bool hasOpacity = false;
            bool hasMatrix = true;
            if (inst.Transformations.Count > 0 && inst.Transformations[0].Matrix == Matrix.Empty)
            {
                hasMatrix = false;
            }

            if (hasMatrix)
            {
                xw.WriteStartElement("MatrixAnimationUsingKeyFrames");

                xw.WriteStartAttribute("Storyboard.TargetName");
                xw.WriteValue(instancePrefix + instName);
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Storyboard.TargetProperty");
                xw.WriteValue("RenderTransform.Matrix");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("RepeatBehavior");
                xw.WriteValue("Forever");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Duration");
                xw.WriteMilliseconds(curTL.Duration);
                xw.WriteEndAttribute();

                Rectangle r = s.StrokeBounds;
                for (int i = 0; i < inst.Transformations.Count; i++)
                {
                    // <DiscreteMatrixKeyFrame KeyTime="0:0:0.25" Value="1 0 0 1 5 110"/>

                    Transform t = inst.Transformations[i];

                    if (t.HasAlpha())
                    {
                        hasOpacity = true;
                    }

                    if (t.HasMatrix()) // todo: make vex format hold all matrices, even when not transforming?
                    {
                        xw.WriteStartElement("DiscreteMatrixKeyFrame");

                        xw.WriteStartAttribute("KeyTime");
                        xw.WriteMilliseconds(t.StartTime);
                        xw.WriteEndAttribute();

                        Matrix m = t.Matrix;
                        m.TranslateX += r.Point.X;
                        m.TranslateY += r.Point.Y;

                        xw.WriteStartAttribute("Value");
                        xw.WriteMatrix(m);
                        xw.WriteEndAttribute();

                        xw.WriteEndElement();
                    }
                }
                xw.WriteEndElement();
            }

            if (hasOpacity)
            {
                //<DoubleAnimationUsingKeyFrames
                //Storyboard.TargetName="inst_0"
                //Storyboard.TargetProperty="Opacity"
                //RepeatBehavior="Forever" Duration="0:0:0.166">
                //  <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value=".5" />
                //</DoubleAnimationUsingKeyFrames>

                xw.WriteStartElement("DoubleAnimationUsingKeyFrames");

                xw.WriteStartAttribute("Storyboard.TargetName");
                xw.WriteValue(instancePrefix + instName);
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Storyboard.TargetProperty");
                xw.WriteValue("Opacity");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("RepeatBehavior");
                xw.WriteValue("Forever");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Duration");
                xw.WriteMilliseconds(curTL.Duration);
                xw.WriteEndAttribute();

                float prevAlpha = -1;
                for (int i = 0; i < inst.Transformations.Count; i++)
                {
                    // <DiscreteMatrixKeyFrame KeyTime="0:0:0.25" Value="1 0 0 1 5 110"/>

                    Transform t = inst.Transformations[i];
                    if (t.Alpha != prevAlpha)
                    {
                        xw.WriteStartElement("DiscreteDoubleKeyFrame");

                        xw.WriteStartAttribute("KeyTime");
                        xw.WriteMilliseconds(t.StartTime);
                        xw.WriteEndAttribute();

                        xw.WriteStartAttribute("Value");
                        xw.WriteFloat(t.Alpha);
                        xw.WriteEndAttribute();

                        xw.WriteEndElement();

                        prevAlpha = t.Alpha;
                    }
                }

                xw.WriteEndElement();

            }
        }
Beispiel #12
0
        public override void WriteInstance(IDefinition s, Instance inst)
        {
            // 	<Rectangle x:Name="inst1" Fill="{StaticResource VisualBrush2}" Width="100" Height="100" Canvas.Left="5" Canvas.Top="5"/>
            //string name = (inst.Name != null && inst.Name != "") ? inst.Name : instancePrefix + instName;

            xw.WriteStartElement("Rectangle");
            xw.WriteStartAttribute("x:Name");
            xw.WriteValue(instancePrefix + instName);
            xw.WriteEndAttribute();

            xw.WriteStartAttribute("Fill");
            xw.WriteString("{StaticResource " + visualBrushPrefix + inst.DefinitionId + "}");
            xw.WriteEndAttribute();

            xw.WriteStartAttribute("Width");
            xw.WriteValue(s.StrokeBounds.Size.Width);
            xw.WriteEndAttribute();

            xw.WriteStartAttribute("Height");
            xw.WriteValue(s.StrokeBounds.Size.Height);
            xw.WriteEndAttribute();

            //RenderTransformOrigin="1,1"
            // bug from yahoo, width and hieght can be zero, when line with no linestyle is applied
            float tx = s.StrokeBounds.Size.Width == 0 ?
                -s.StrokeBounds.Point.X :
                -s.StrokeBounds.Point.X / s.StrokeBounds.Size.Width;
            float ty =  s.StrokeBounds.Size.Height == 0 ?
                -s.StrokeBounds.Point.Y :
                -s.StrokeBounds.Point.Y / s.StrokeBounds.Size.Height;
            xw.WriteStartAttribute("RenderTransformOrigin");
            xw.WriteValue(tx + "," + ty);
            xw.WriteEndAttribute();

            //xw.WriteStartAttribute("Visibility");
            //xw.WriteValue("Hidden");
            //xw.WriteEndAttribute();

            xw.WriteEndElement();
        }
Beispiel #13
0
 public DesignInstance(StageView stage, Vex.Instance inst)
 {
     this.stage = stage;
     instance   = inst;
     Initialize(); // will not set loc if there are already transforms
 }
Beispiel #14
0
		private void ParsePlaceObject2Tag(PlaceObject2Tag tag)
		{
            uint curTime = (uint)((curFrame * (1 / swf.Header.FrameRate)) * 1000);
            uint totalTime = GetDuration(this.curTimeline.FrameCount); 

			Vex.Matrix mx = ParseMatrix(tag.Matrix);
			float alpha = 1;
			Instance inst;
			if (tag.HasCharacter && !tag.Move) // a new symbol at this depth, none preexisting
			{
				inst = new Instance();
				inst.DefinitionId = tag.Character;
				inst.StartTime = curTime;
				inst.EndTime = totalTime;
				inst.Depth = (int)tag.Depth;
				curDepthChart.Add(tag.Depth, inst);
				this.curTimeline.AddInstance(inst);
			}
			else if (!tag.HasCharacter && tag.Move) // an old symbol is modified
			{
				inst = curDepthChart[tag.Depth];
				Transform lastT = inst.Transformations[inst.Transformations.Count - 1];
				lastT.EndTime = curTime;
				inst.EndTime = curTime;
				alpha = lastT.Alpha;
			}
			else if (tag.HasCharacter && tag.Move) // a new symbol replaces an old one
			{
				Instance old = curDepthChart[tag.Depth];
				Transform lastT = old.Transformations[old.Transformations.Count - 1];
				lastT.EndTime = curTime;
				old.EndTime = curTime;

				curDepthChart.Remove(tag.Depth);

				inst = new Instance();
				// note: when replacing old symbol, the previous matrix is used
				if (!tag.HasMatrix)
				{
					mx = lastT.Matrix;
				}
				// as is old color xform
				if (!tag.HasColorTransform)
				{
					alpha = lastT.Alpha; // include rest of xform as it comes
				}
				inst.DefinitionId = tag.Character;
				inst.StartTime = curTime;
				inst.EndTime = totalTime;
                inst.Depth = (int)tag.Depth;

				curDepthChart.Add(tag.Depth, inst);
                this.curTimeline.AddInstance(inst);
			}
			else
			{
				throw new ArgumentException("swf error, no character to modify");
			}
			if (tag.HasColorTransform && (tag.ColorTransform.HasAddTerms || tag.ColorTransform.HasMultTerms))
			{
				int addMult = tag.ColorTransform.AMultTerm + tag.ColorTransform.AAddTerm;
				alpha = addMult < 0 ? 0 : addMult / 256F;
			}

			if (tag.HasClipDepth)
			{
				inst.IsMask = true;
				inst.MaskDepth = tag.ClipDepth;
			}
			if (tag.HasName)
			{
				inst.Name = tag.Name;
            }

            ColorTransform c = tag.ColorTransform;
            Vex.ColorTransform ct = new Vex.ColorTransform(c.RAddTerm, c.RMultTerm, c.GAddTerm, c.GMultTerm, c.BAddTerm, c.BMultTerm, c.AAddTerm, c.AMultTerm);
			inst.Transformations.Add(new Transform(curTime, totalTime, mx, alpha, ct));
		}
Beispiel #15
0
        private string AddSymbolImage(Instance inst, IDefinition sy)
        {
            string nm = (sy.Name == null) ? "sym_" + sy.Id.ToString() : sy.Name;
            string bmpPath = resourceFolder + @"\" + nm + ".png";

            bmpPath = OutputDirectory + "/" + bmpPath;
            bmpPath = bmpPath.Replace('\\', '/');

            if (!usedImages.ContainsKey(nm))
            {
                usedImages.Add(nm, sy);
            }
            return bmpPath;
        }
        public override void GenerateXamlPart(VexObject v, IDefinition def, out string resultFileName)
        {
            this.v = v;
            this.Log = new StringBuilder();
            string baseFileName = Directory.GetCurrentDirectory() +
                "/" +
                v.Name +
                SILVERLIGHT_SUFFIX +
                "_" + def.Id;

            resultFileName = baseFileName + ".html";
            string xamlFileName = baseFileName + ".xaml";

            xw = new XamlWriter(xamlFileName, Encoding.UTF8);

            xw.WriteComment(headerComment);

            #if(IS_TRIAL)
            // turn off watermarking for small files
            isWatermarking = true;
            xw.WriteComment(trialComment);
            if (v.Definitions.Count < 15)
            {
                isWatermarking = false;
            }
            #else
            isWatermarking = false;
            #endif

            xw.OpenHeaderTag(def.StrokeBounds.Size.Width, def.StrokeBounds.Size.Height, v.BackgroundColor);

            Dictionary<uint, IDefinition> defList = new Dictionary<uint, IDefinition>();
            defList.Add(1, def);
            AddImagesPart(defList, true);

            //WriteTimelineDefiniton(v.Root, true);
            // Write a rectangle to hold this shape
            Instance inst = new Instance();
            inst.Name = instancePrefix + def.Id;
            inst.InstanceId = 1;
            inst.DefinitionId = def.Id;
            inst.Transformations.Add(new Transform(0, 1000, Matrix.Identitiy, 1, ColorTransform.Identity));
            WriteInstance(def, inst, true);

            xw.CloseHeaderTag();

            xw.Close();

            WriteSilverlightHtml(v, resultFileName);
        }
Beispiel #17
0
        private V2DDefinition CreateDefinition(Instance inst, IDefinition def)
        {
            V2DDefinition result = defs.Find(d => d.Name == def.Name);

            if (result == null)
            {
                result = new V2DDefinition();
                result.DefinitionName = def.Name;
                result.LinkageName = def.Name; // todo: find real linkageName
                result.Bounds = def.StrokeBounds;
                result.FrameCount = (int)tlDef.FrameCount;
                //ParseBodyImage(result, def, inst);
            }
            return result;
        }
 public override void WriteInstance(IDefinition s, Instance inst)
 {
     WriteInstance(s, inst, false);
 }
Beispiel #19
0
        private void ParseJoint(V2DJointKind jointKind, Instance inst)
        {
            List<V2DJoint> joints = curDef.Joints; //List<V2DJoint>
            string nm = inst.Name;
            int firstUs = nm.IndexOf('_');
            string jName = (firstUs > -1) ? nm.Substring(0, firstUs) : nm;
            string targName = (firstUs > -1) ? nm.Substring(firstUs + 1) : "";

            Point p = new Point(
                inst.Transformations[0].Matrix.TranslateX,
                inst.Transformations[0].Matrix.TranslateY);

            V2DJoint joint = joints.Find(jt => jt.Name == jName);
            if (joint == null)
            {
                joint = new V2DJoint();
                joint.Name = jName;
                joint.Type = jointKind;
                joint.X2 = p.X;
                joint.Y2 = p.Y;
                if (inst.Transformations.Count > 1) // pulley defined by joints on frame 2
                {
                    joint.GroundAnchor1X = inst.Transformations[1].Matrix.TranslateX;
                    joint.GroundAnchor1Y = inst.Transformations[1].Matrix.TranslateY;
                }
            }
            else
            {
                joint.X2 = p.X;
                joint.Y2 = p.Y;
                if (inst.Transformations.Count > 1) // pulley defined by joints on frame 2
                {
                    joint.GroundAnchor2X = inst.Transformations[1].Matrix.TranslateX;
                    joint.GroundAnchor2Y = inst.Transformations[1].Matrix.TranslateY;
                }
            }
        }
        public void WriteInstance(IDefinition s, Instance inst, bool isPart)
        {
            if (s is Symbol)
            {
                Symbol symbol = (Symbol)s;
                string fullName = GetInstanceName(inst);

                OpenSymbolDefTag(fullName, symbol.StrokeBounds, isPart);

                // don't write transforms when just displaying part of file
                if (!isPart)
                {
                    // write transform defs
                    WriteTransformsDefs(symbol, inst, fullName);

                    // write Storyboard
                    WriteStoryboard(symbol, inst, fullName);
                }
                // write paths
                WriteSymbolDefinition(symbol);

                CloseSymbolDefTag();
            }
            else if (s is SoundInstance)
            {
                WriteSoundInstance((SoundInstance)s);
            }
        }
Beispiel #21
0
		public virtual void WriteTextBlock(Text txt, Instance inst)
		{

			// <Block FontFamily=
			//   FontSize="40"
			//   FontFamily="Georgia"
			//   FontStyle="Italic" FontWeight="Bold"
			//   Canvas.Top="20" Canvas.Left="20"
			//	 Foreground="Red">
			//  test
			// </Block>

			xw.WriteStartElement("Canvas");

			if (inst != null)
			{
				string name = (inst.Name != null && inst.Name != "") ? inst.Name : instancePrefix + instName;
				xw.WriteStartAttribute("x:Name");
				xw.WriteValue(instancePrefix + instName);
				xw.WriteEndAttribute();
			}

			// ***** Can't use spans as that loses centering

			if(txt.TextRuns.Count == 0)
			{
				// todo: need to add edit text box attributes to Text tag, or have EditText tag
				//WriteTextAttributes(tr);
			}
			//else if (txt.TextRuns.Count == 1)
			//{
			//    TextRun tr = txt.TextRuns[0];

			//    xw.WriteStartElement("TextBlock");
			//    xw.WriteAttributeString("Canvas.Left", tr.Left);
			//    xw.WriteAttributeString("Canvas.Top", tr.Top);

			//    WriteTextAttributes(tr);
			//    xw.WriteValue(tr.Text);

			//    xw.WriteEndElement();
			//}
			else // multi text runs
			{
				xw.WriteStartElement("TextBlock");
				for (int i = 0; i < txt.TextRuns.Count; i++)
				{
					TextRun tr = txt.TextRuns[i];

					if (i > 0 && tr.isContinuous)
					{
						xw.WriteStartElement("Span");

						WriteTextAttributes(tr);
						xw.WriteValue(tr.Text);

						xw.WriteEndElement();
					}
					else
					{
						if (i > 0)
						{
							xw.WriteEndElement();
							xw.WriteStartElement("TextBlock");
						}
						xw.WriteAttributeString("Canvas.Left", tr.Left.ToString());
						xw.WriteAttributeString("Canvas.Top", tr.Top.ToString());

						WriteTextAttributes(tr);
						xw.WriteValue(tr.Text);

					}
					//if (tr.isMultiline)
					//{
					//    xw.WriteStartElement("LineBreak");
					//    xw.WriteEndElement();
					//}
				}
				xw.WriteEndElement();
			}


			xw.WriteEndElement(); // Canvas

		}
        public void WriteStoryboard(IDefinition s, Instance inst, string fullName)
        {
            //<Canvas.Triggers>
            //  <EventTrigger RoutedEvent="Canvas.Loaded">
            //    <BeginStoryboard>
            //      <Storyboard>
            //        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="def_6t" Storyboard.TargetProperty="X" Duration="0:0:10">
            //          <DiscreteDoubleKeyFrame Value="0" KeyTime="0:0:0" />
            //          <DiscreteDoubleKeyFrame Value="350" KeyTime="0:0:2" />
            //          <DiscreteDoubleKeyFrame Value="50" KeyTime="0:0:7" />
            //          <DiscreteDoubleKeyFrame Value="200" KeyTime="0:0:8" />
            //        </DoubleAnimationUsingKeyFrames>
            //      </Storyboard>
            //    </BeginStoryboard>
            //  </EventTrigger>
            //</Canvas.Triggers>

            xw.WriteStartElement("Canvas.Triggers");

            xw.WriteStartElement("EventTrigger");
            xw.WriteStartAttribute("RoutedEvent");
            xw.WriteValue("Canvas.Loaded"); // MediaElement.Loaded
            xw.WriteEndAttribute();

            xw.WriteStartElement("BeginStoryboard");
            xw.WriteStartElement("Storyboard");

            // first write appear and disappear info
            // This is now done as opacity is written as Silverlight doesn't support 'Visible'
            // WriteVisibility(inst, fullName);

            // now the transform matrixes - note: silverlight, ugh, does not support matrixes : (
            Rectangle r = s.StrokeBounds;
            Matrix m;
            MatrixComponents mc;
            //string fullName = instancePrefix + GetInstanceName(inst);

            Timeline curTL = (timelineStack.Count == 0) ?
                v.Root :
                (Timeline)v.Definitions[timelineStack.Peek().DefinitionId];

            // only write transforms if they exist
            // at least the Yahoo avatar tool will write no transforms,
            // and then modify on the instance only
            bool hasOpacity = false;
            bool hasMatrix = true;
            if (inst.Transformations.Count > 0 && inst.Transformations[0].Matrix == Matrix.Empty)
            {
                hasMatrix = false;
            }

            if (hasMatrix)
            {
                // <DoubleAnimationUsingKeyFrames Storyboard.TargetName="def_6t" Storyboard.TargetProperty="X" Duration="0:0:10">
                //   <DiscreteDoubleKeyFrame Value="0" KeyTime="0:0:0" />
                //   <DiscreteDoubleKeyFrame Value="350" KeyTime="0:0:2" />
                //   <DiscreteDoubleKeyFrame Value="50" KeyTime="0:0:7" />
                //   <DiscreteDoubleKeyFrame Value="200" KeyTime="0:0:8" />
                // </DoubleAnimationUsingKeyFrames>

                #region ScaleX
                // write scaleX
                xw.WriteStartElement("DoubleAnimationUsingKeyFrames");

                xw.WriteStartAttribute("Storyboard.TargetName");
                xw.WriteValue(fullName + "s");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Storyboard.TargetProperty");
                xw.WriteValue("ScaleX");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("RepeatBehavior");
                xw.WriteValue("Forever");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Duration");
                xw.WriteMilliseconds(curTL.Duration);
                xw.WriteEndAttribute();

                for (int i = 0; i < inst.Transformations.Count; i++)
                {
                    Transform t = inst.Transformations[i];

                    if (t.HasAlpha())
                    {
                        hasOpacity = true;
                    }

                    if (t.HasMatrix())
                    {
                        xw.WriteStartElement("DiscreteDoubleKeyFrame");

                        xw.WriteStartAttribute("KeyTime");
                        xw.WriteMilliseconds(t.StartTime);
                        xw.WriteEndAttribute();

                        m = t.Matrix;
                        mc = m.GetMatrixComponents();

                        xw.WriteStartAttribute("Value");
                        xw.WriteFloat(mc.ScaleX);
                        xw.WriteEndAttribute();

                        xw.WriteEndElement();
                    }
                }
                xw.WriteEndElement();
                #endregion
                #region ScaleY
                // write scaleY
                xw.WriteStartElement("DoubleAnimationUsingKeyFrames");

                xw.WriteStartAttribute("Storyboard.TargetName");
                xw.WriteValue(fullName + "s");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Storyboard.TargetProperty");
                xw.WriteValue("ScaleY");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("RepeatBehavior");
                xw.WriteValue("Forever");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Duration");
                xw.WriteMilliseconds(curTL.Duration);
                xw.WriteEndAttribute();

                for (int i = 0; i < inst.Transformations.Count; i++)
                {
                    Transform t = inst.Transformations[i];

                    if (t.HasAlpha())
                    {
                        hasOpacity = true;
                    }

                    if (t.HasMatrix())
                    {
                        xw.WriteStartElement("DiscreteDoubleKeyFrame");

                        xw.WriteStartAttribute("KeyTime");
                        xw.WriteMilliseconds(t.StartTime);
                        xw.WriteEndAttribute();

                        m = t.Matrix;
                        mc = m.GetMatrixComponents();

                        xw.WriteStartAttribute("Value");
                        xw.WriteFloat(mc.ScaleY);
                        xw.WriteEndAttribute();

                        xw.WriteEndElement();
                    }
                }
                xw.WriteEndElement();
                #endregion
                #region shear
                // write shears
                xw.WriteStartElement("DoubleAnimationUsingKeyFrames");

                xw.WriteStartAttribute("Storyboard.TargetName");
                xw.WriteValue(fullName + "k");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Storyboard.TargetProperty");
                xw.WriteValue("AngleX");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("RepeatBehavior");
                xw.WriteValue("Forever");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Duration");
                xw.WriteMilliseconds(curTL.Duration);
                xw.WriteEndAttribute();

                for (int i = 0; i < inst.Transformations.Count; i++)
                {
                    Transform t = inst.Transformations[i];

                    if (t.HasAlpha())
                    {
                        hasOpacity = true;
                    }

                    if (t.HasMatrix())
                    {
                        xw.WriteStartElement("DiscreteDoubleKeyFrame");

                        xw.WriteStartAttribute("KeyTime");
                        xw.WriteMilliseconds(t.StartTime);
                        xw.WriteEndAttribute();

                        m = t.Matrix;
                        mc = m.GetMatrixComponents();

                        xw.WriteStartAttribute("Value");
                        xw.WriteFloat(mc.Shear);
                        xw.WriteEndAttribute();

                        xw.WriteEndElement();
                    }
                }
                xw.WriteEndElement();
                #endregion
                #region rotate
                // write rotates
                xw.WriteStartElement("DoubleAnimationUsingKeyFrames");

                xw.WriteStartAttribute("Storyboard.TargetName");
                xw.WriteValue(fullName + "r");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Storyboard.TargetProperty");
                xw.WriteValue("Angle");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("RepeatBehavior");
                xw.WriteValue("Forever");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Duration");
                xw.WriteMilliseconds(curTL.Duration);
                xw.WriteEndAttribute();

                for (int i = 0; i < inst.Transformations.Count; i++)
                {
                    Transform t = inst.Transformations[i];

                    if (t.HasAlpha())
                    {
                        hasOpacity = true;
                    }

                    if (t.HasMatrix())
                    {
                        xw.WriteStartElement("DiscreteDoubleKeyFrame");

                        xw.WriteStartAttribute("KeyTime");
                        xw.WriteMilliseconds(t.StartTime);
                        xw.WriteEndAttribute();

                        m = t.Matrix;
                        mc = m.GetMatrixComponents();

                        xw.WriteStartAttribute("Value");
                        xw.WriteFloat(mc.Rotation);
                        xw.WriteEndAttribute();

                        xw.WriteEndElement();
                    }
                }
                xw.WriteEndElement();
                #endregion
                #region TranslateX
                // write TranslateX
                xw.WriteStartElement("DoubleAnimationUsingKeyFrames");

                xw.WriteStartAttribute("Storyboard.TargetName");
                xw.WriteValue(fullName + "t");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Storyboard.TargetProperty");
                xw.WriteValue("X");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("RepeatBehavior");
                xw.WriteValue("Forever");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Duration");
                xw.WriteMilliseconds(curTL.Duration);
                xw.WriteEndAttribute();

                for (int i = 0; i < inst.Transformations.Count; i++)
                {
                    Transform t = inst.Transformations[i];

                    if (t.HasAlpha())
                    {
                        hasOpacity = true;
                    }

                    if (t.HasMatrix())
                    {
                        xw.WriteStartElement("DiscreteDoubleKeyFrame");

                        xw.WriteStartAttribute("KeyTime");
                        xw.WriteMilliseconds(t.StartTime);
                        xw.WriteEndAttribute();

                        m = t.Matrix;
                        mc = m.GetMatrixComponents();

                        xw.WriteStartAttribute("Value");
                        xw.WriteFloat(mc.TranslateX);// + r.Point.X);
                        xw.WriteEndAttribute();

                        xw.WriteEndElement();
                    }
                }
                xw.WriteEndElement();
                #endregion
                #region TranslateY
                // write TranslateY
                xw.WriteStartElement("DoubleAnimationUsingKeyFrames");

                xw.WriteStartAttribute("Storyboard.TargetName");
                xw.WriteValue(fullName + "t");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Storyboard.TargetProperty");
                xw.WriteValue("Y");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("RepeatBehavior");
                xw.WriteValue("Forever");
                xw.WriteEndAttribute();

                xw.WriteStartAttribute("Duration");
                xw.WriteMilliseconds(curTL.Duration);
                xw.WriteEndAttribute();

                for (int i = 0; i < inst.Transformations.Count; i++)
                {
                    Transform t = inst.Transformations[i];

                    if (t.HasAlpha())
                    {
                        hasOpacity = true;
                    }

                    if (t.HasMatrix())
                    {
                        xw.WriteStartElement("DiscreteDoubleKeyFrame");

                        xw.WriteStartAttribute("KeyTime");
                        xw.WriteMilliseconds(t.StartTime);
                        xw.WriteEndAttribute();

                        m = t.Matrix;
                        mc = m.GetMatrixComponents();

                        xw.WriteStartAttribute("Value");
                        xw.WriteFloat(mc.TranslateY);// + r.Point.Y);
                        xw.WriteEndAttribute();

                        xw.WriteEndElement();
                    }
                }
                xw.WriteEndElement();
                #endregion
            }
            WriteVisibility(inst, fullName, hasOpacity);

            xw.WriteEndElement();
            xw.WriteEndElement();
            xw.WriteEndElement();
            xw.WriteEndElement();
        }
Beispiel #23
0
		public abstract void WriteInstance(IDefinition s, Instance inst);
        public override void WriteTextBlock(Text txt, Instance inst)
        {
            xw.WriteStartElement("Canvas");

            if (inst != null)
            {
                string name = (inst.Name != null && inst.Name != "") ? inst.Name : instancePrefix + instName;
                string fullName = instancePrefix + instName;
                xw.WriteStartAttribute("x:Name");
                xw.WriteValue(fullName);
                xw.WriteEndAttribute();

                // write transform defs
                WriteTransformsDefs(v.Definitions[inst.DefinitionId], inst, fullName);

                // write Storyboard
                WriteStoryboard(v.Definitions[inst.DefinitionId], inst, fullName);
            }

            // ***** Can't use spans as that loses centering

            if (txt.TextRuns.Count != 0)
            {
                xw.WriteStartElement("TextBlock");
                for (int i = 0; i < txt.TextRuns.Count; i++)
                {
                    TextRun tr = txt.TextRuns[i];

                    if (i > 0 && tr.isContinuous)
                    {
                        xw.WriteStartElement("Span");

                        WriteTextAttributes(tr);
                        xw.WriteValue(tr.Text);

                        xw.WriteEndElement();
                    }
                    else
                    {
                        if (i > 0)
                        {
                            xw.WriteEndElement();
                            xw.WriteStartElement("TextBlock");
                        }
                        xw.WriteAttributeString("Canvas.Left", tr.Left.ToString());
                        xw.WriteAttributeString("Canvas.Top", tr.Top.ToString());

                        WriteTextAttributes(tr);
                        xw.WriteValue(tr.Text);

                    }
                }
                xw.WriteEndElement();
            }
            xw.WriteEndElement(); // Canvas
        }
Beispiel #25
0
 private Instance2D CreateInstance2D(Instance inst, IDefinition def)
 {
     //MatrixComponents mc = inst.Transformations[0].Matrix.GetMatrixComponents();
     //Instance2D result = new Instance2D(inst.Name, def.Name, mc.TranslateX, mc.TranslateY, (float)(mc.Rotation * Math.PI / 180), mc.ScaleX, mc.ScaleY);
     Instance2D result = new Instance2D(inst.Name, def.Name, 0,0,0,1,1);
     result.Depth = inst.Depth;
     result.Transforms = inst.Transformations;
     result.Definition = definitions.Find(d => d.Id == inst.DefinitionId);
     result.StartFrame = curVo.GetFrameFromMilliseconds(inst.StartTime);
     result.TotalFrames = curVo.GetFrameFromMilliseconds(inst.EndTime) - result.StartFrame - 1; // end frame is last ms of frame, so -1
     return result;
 }
        public void WriteVisibility(Instance inst, string fullName, bool hasOpacity)
        {
            // Note: WriteVisibility visible and opacity in this pass

            //<DoubleAnimationUsingKeyFrames
            //Storyboard.TargetName="inst_0"
            //Storyboard.TargetProperty="Opacity"
            //RepeatBehavior="Forever" Duration="0:0:0.166">
            //  <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value=".5" />
            //</DoubleAnimationUsingKeyFrames>

            Timeline curTL;
            if (timelineStack.Count == 0)
            {
                curTL = v.Root;
            }
            else if (v.Definitions[inst.DefinitionId] is Timeline && timelineStack.Count == 1)
            {
                curTL = v.Root;
            }
            else if (v.Definitions[inst.DefinitionId] is Timeline && timelineStack.Count > 1)
            {
                Instance temp = timelineStack.Pop();
                curTL = (Timeline)v.Definitions[timelineStack.Peek().DefinitionId];
                timelineStack.Push(temp);
            }
            else
            {
                curTL = (Timeline)v.Definitions[timelineStack.Peek().DefinitionId];
            }

            xw.WriteStartElement("DoubleAnimationUsingKeyFrames");

            xw.WriteStartAttribute("Storyboard.TargetName");
            xw.WriteValue(fullName);
            xw.WriteEndAttribute();

            xw.WriteStartAttribute("Storyboard.TargetProperty");
            xw.WriteValue("Opacity");
            xw.WriteEndAttribute();

            xw.WriteStartAttribute("Duration");
            xw.WriteMilliseconds(curTL.Duration);
            xw.WriteEndAttribute();

            xw.WriteStartAttribute("RepeatBehavior");
            xw.WriteValue("Forever");
            xw.WriteEndAttribute();

            if (inst.StartTime > 0)
            {
                xw.WriteStartElement("DiscreteDoubleKeyFrame");
                xw.WriteStartAttribute("KeyTime");
                xw.WriteMilliseconds(0);
                xw.WriteEndAttribute();
                xw.WriteStartAttribute("Value");
                xw.WriteValue(0);
                xw.WriteEndAttribute();
                xw.WriteEndElement();
            }

            if (hasOpacity)
            {
                float prevAlpha = -1;
                for (int i = 0; i < inst.Transformations.Count; i++)
                {
                    Transform t = inst.Transformations[i];
                    if (t.Alpha != prevAlpha)
                    {
                        xw.WriteStartElement("DiscreteDoubleKeyFrame");

                        xw.WriteStartAttribute("KeyTime");
                        xw.WriteMilliseconds(t.StartTime);
                        xw.WriteEndAttribute();

                        xw.WriteStartAttribute("Value");
                        xw.WriteFloat(t.Alpha);
                        xw.WriteEndAttribute();

                        xw.WriteEndElement();

                        prevAlpha = t.Alpha;
                    }
                }
            }
            else
            {
                xw.WriteStartElement("DiscreteDoubleKeyFrame");
                xw.WriteStartAttribute("KeyTime");
                xw.WriteMilliseconds(inst.StartTime);
                xw.WriteEndAttribute();
                xw.WriteStartAttribute("Value");
                xw.WriteValue(1);
                xw.WriteEndAttribute();
                xw.WriteEndElement();
            }

            xw.WriteStartElement("DiscreteDoubleKeyFrame");
            xw.WriteStartAttribute("KeyTime");
            xw.WriteMilliseconds(inst.EndTime);
            xw.WriteEndAttribute();
            xw.WriteStartAttribute("Value");
            xw.WriteValue(0);
            xw.WriteEndAttribute();
            xw.WriteEndElement();

            xw.WriteEndElement();
        }
Beispiel #27
0
        private void ParseJoint(V2DJointKind jointKind, Instance inst)
        {
            Dictionary<string, Joint2D> joints = parentStack.Peek().Definition.Joints;
            string nm = inst.Name;
            int firstUs = nm.IndexOf('_');
            string jName = (firstUs > -1) ? nm.Substring(0, firstUs) : nm;
            string targName = (firstUs > -1) ? nm.Substring(firstUs + 1) : "";

            Matrix m = inst.Transformations[0].Matrix;
            float rot = (float)((m.GetMatrixComponents().Rotation + 90) * Math.PI / 180);

            Point p = new Point(
                inst.Transformations[0].Matrix.TranslateX,
                inst.Transformations[0].Matrix.TranslateY);

            if (joints.ContainsKey(jName))
            {
                joints[jName].AppendData(p, rot);
            }
            else
            {
                joints.Add(jName, new Joint2D(jName, targName, jointKind, p, rot));
            }

            if (inst.Transformations.Count > 1) // pulley defined by joints on frame 2
            {
                joints[jName].Transforms.Add(new Point(
                    inst.Transformations[1].Matrix.TranslateX,
                    inst.Transformations[1].Matrix.TranslateY));
            }
        }
Beispiel #28
0
 public Interval(Instance instance, DateTime startTime, DateTime endTime)
 {
     this.Instance = instance;
     this.StartTime = startTime;
     this.EndTime = endTime;
 }