Beispiel #1
0
        private static void writeKeyFramePropertiesBlock(KeyFrame k, Stream s)
        {
            List<byte> bytes = new List<byte>();

            bytes.AddRange(BitConverter.GetBytes((ushort)4));
            if (k.type != 4 && k.type != 3)
            {
                bytes.AddRange(BitConverter.GetBytes(true));
                bytes.Add((byte)k.figColor.A);
                bytes.Add((byte)k.figColor.R);
                bytes.Add((byte)k.figColor.G);
                bytes.Add((byte)k.figColor.B);
            }
            else if (k.type == 3)
            {
                RectFrame x = (RectFrame)k;
                bytes.AddRange(BitConverter.GetBytes(x.filled));
                bytes.Add((byte)x.figColor.A);
                bytes.Add((byte)x.figColor.R);
                bytes.Add((byte)x.figColor.G);
                bytes.Add((byte)x.figColor.B);

                Color outlineColor = k.Joints[0].color;

                bytes.Add((byte)outlineColor.A);
                bytes.Add((byte)outlineColor.R);
                bytes.Add((byte)outlineColor.G);
                bytes.Add((byte)outlineColor.B);
            }
            else
            {
                bytes.AddRange(BitConverter.GetBytes(false));
                bytes.AddRange(new byte[4]);
            }

            if (k.type == 2)
            {
                bytes.Add((byte)k.Joints[0].thickness);
            }

            bytes.InsertRange(0, BitConverter.GetBytes(bytes.Count));

            s.Write(bytes.ToArray(), 0, bytes.Count);
        }
Beispiel #2
0
        public void doDisplay(int pos, bool current = true)
        {
            bool render = false; int imid = -1;
            if (keyFrames == null)
                return;

            //Binary search for the frame that has the specified position
            //Binary searches only work on sorted lists, and since the keyframes are always sorted based on position, this works nicely.
            int end = keyFrames.Count, start = 0, npos = -1;

            if (pos > lastKF || pos < firstKF)
            {
                tweenFig.isDrawn = false;
            }
            else
            {
                while (end >= start)
                {
                    imid = (end + start) >> 1; //equivilent to / 2

                    try
                    {
                        npos = keyFrames[imid].pos;
                    }
                    catch
                    {
                        selectedFrame = -1;
                        break;
                    }

                    if (npos < pos)
                    {
                        start = imid + 1;
                    }
                    else if (npos > pos)
                        end = imid - 1;
                    else
                    {
                        render = true;
                        fig.Joints = keyFrames[imid].Joints;
                        if (fig.type == 3)
                        {
                            fig.figColor = keyFrames[imid].figColor;
                        }

                        if (!(tweenFig == null))
                            tweenFig.drawFig = false;

                        break;
                    }
                }
            }

            if (!render)
            {
                if (pos > firstKF && pos < lastKF)
                {
                    KeyFrame s = keyFrames[start], e = keyFrames[end];

                    adjacentBack = s; adjacentFront = e;

                    float percent = (float)(pos - s.pos) / (e.pos - s.pos);
                    List<StickJoint> ps = e.Joints;
                    tweenFig.drawFig = true;

                    for (int a = 0; a < tweenFig.Joints.Count; a++)
                    {
                        tweenFig.Joints[a].location = ps[a].location;
                        tweenFig.Joints[a].Tween(s.Joints[a], ps[a], percent);
                    }
                }
                else
                {
                    tweenFig.isDrawn = false;
                }
            }

            fig.drawFig = render;
            fig.drawHandles = render & current;
            fig.isActiveFig = true;
            selectedFrame = render ? imid : -1;

            if (current)
            {
                Timeline.frm_selInd = selectedFrame;
                if(fig.type == 3)
                    Canvas.activeFigure.figColor = keyFrames[imid].figColor;
            }
        }
Beispiel #3
0
        private static void writeFrameBlock(KeyFrame f, Stream stream)
        {
            byte type = f.type;
            List<byte> bytes = new List<byte>();

            bytes.AddRange(BitConverter.GetBytes((ushort)2));

            bytes.AddRange(BitConverter.GetBytes(f.pos));
            bytes.InsertRange(0, BitConverter.GetBytes(bytes.Count));

            stream.Write(bytes.ToArray(), 0, bytes.Count);

            writeKeyFramePropertiesBlock(f, stream);

            writePositionsBlock(f.Joints.ToArray(), stream);

            List<byte> b2 = new List<byte>();
            b2.AddRange(BitConverter.GetBytes((int)3));
            b2.AddRange(BitConverter.GetBytes((ushort)3));
            b2.Add(0);

            stream.Write(b2.ToArray(), 0, 7);
        }