Exemple #1
0
        public CustomLayer(string Name, StickCustom custom, Canvas _Canvas)
        {
            name = Name;

            fig = custom;
            fig.parentLayer = this;

            theCanvas = _Canvas;
            tweenFig = new StickCustom(true);

            type = 4;

            firstKF = 0;
            lastKF = 19;

            keyFrames = new List<KeyFrame>();

            custObjectFrame first = new custObjectFrame(firstKF), last = new custObjectFrame(lastKF);

            foreach (StickJoint j in first.Joints)
                j.ParentFigure = fig;

            foreach (StickJoint j in last.Joints)
                j.ParentFigure = fig;

            keyFrames.Add(first);
            keyFrames.Add(last);
        }
Exemple #2
0
        public void recieveStickFigure(StickCustom figure, bool lean)
        {
            /*
            CustomLayer c = (CustomLayer)Timeline.layers[Timeline.layer_sel];

            List<StickJoint> ps = figure.Joints;
            c.fig = figure;

            int[] positions = new int[ps.Count];
            for (int a = 0;a < ps.Count;a++)
            {
                StickJoint p = ps[a].parent;
                if (p != null)
                {
                    positions[a] = ps.IndexOf(p);
                }
                else
                {
                    positions[a] = -1;
                }
            }

            c.keyFrames[c.selectedFrame].Joints = ps;
            foreach (StickJoint j in c.keyFrames[c.selectedFrame].Joints)
                j.ParentFigure = c.fig;

            c.tweenFig = new StickCustom(figure, true);
            c.tweenFig.Joints = custObjectFrame.createClone(ps);
            foreach (StickJoint j in c.tweenFig.Joints)
                j.ParentFigure = c.tweenFig;

            Timeline.layer_sel = Timeline.layer_cnt - 1;
            Program.TimelineForm.setFrame(c.firstKF);
            Program.TimelineForm.Invalidate();
             */
        }
Exemple #3
0
        public static List<StickJoint> Read(string file)
        {
            int nCount;
            LegacyFigure fig = new LegacyFigure();

            LegacyJoint pJoint;
            LegacyTJointBitmap bmp;

            BinaryReader bin = new BinaryReader(File.Open(file, FileMode.Open));

            fig.DrawMode = bin.ReadInt32();
            fig.Tension = bin.ReadSingle();
            fig.CurveWidth = bin.ReadInt32();
            fig.JointCount = bin.ReadInt32();
            nCount = bin.ReadInt32();
            for (int i = 0;i < nCount;i++)
            {
                pJoint = new LegacyJoint();
                pJoint.Read(bin, fig);
            }

            fig.PoseCount = bin.ReadInt32();
            fig.Alpha = 1 - (fig.PoseCount / 255);
            fig.BitmapCount = bin.ReadInt32();
            for (int i = 0;i < fig.BitmapCount;i++)
            {
                bmp = new LegacyTJointBitmap();
                bmp.Load(bin);
                fig.Bitmaps.Add(bmp);
            }

            List<StickJoint> x = new List<StickJoint>();
            StickCustom cust = new StickCustom();

            foreach (LegacyJoint j in fig.Joints)
                x.Add(new StickJoint(j));

            for (int i = 0;i < fig.Joints.Count;i++)
                for (int j = 0;j < fig.Joints[i].children.Count;j++)
                {
                    StickJoint lj = x[fig.Joints.IndexOf(fig.Joints[i].children[j])];
                    x[i].children.Add(lj);
                    lj.parent = x[i];
                }

            for (int z = 0;z < fig.Bitmaps.Count; z++)
                for (int i = 0;i < x.Count;i++)
                {
                    x[i].bitmaps.Add(fig.Bitmaps[z].bitmap);
                    x[i].Bitmap_names.Add(fig.Bitmaps[z].name);
                    x[i].Bitmap_Offsets.Add(new Point(fig.Joints[i].BitmapXOffs, fig.Joints[i].BitmapYOffs));
                    x[i].Bitmap_Rotations.Add(Math.Abs(Convert.ToInt32(fig.Joints[i].BitmapRotation)));

                    x[i].Bitmap_IDs.Add(z);
                    Functions.AssignGlid(x[i], x[i].bitmaps.IndexOf(fig.Bitmaps[z].bitmap));
                }

            return x;
        }
Exemple #4
0
        private static void writeCustomFigBlock(Layer l, Stream s)
        {
            List<byte> bytes = new List<byte>();

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

            StickCustom cust = new StickCustom();
            cust.Joints = l.keyFrames[0].Joints;

            CustomFigSaver.saveFigure(bytes, cust);

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

            s.Write(bytes.ToArray(), 0, bytes.Count);
        }
Exemple #5
0
        private static void writeJointBlock(List<byte> bin, StickCustom figure, StickJoint j)
        {
            bin.AddRange(BitConverter.GetBytes(j.location.X));
            bin.AddRange(BitConverter.GetBytes(j.location.Y));

            bin.AddRange(BitConverter.GetBytes(j.color.ToArgb()));
            bin.AddRange(BitConverter.GetBytes(j.handleColor.ToArgb()));
            bin.AddRange(BitConverter.GetBytes(j.defaultHandleColor.ToArgb()));
            bin.AddRange(BitConverter.GetBytes(j.thickness));
            bin.AddRange(BitConverter.GetBytes(j.drawState));
            bin.AddRange(BitConverter.GetBytes(j.drawOrder));
            bin.AddRange(BitConverter.GetBytes(j.visible));
            bin.AddRange(BitConverter.GetBytes(j.handleDrawn));

            bin.AddRange((BitConverter.GetBytes(j.Bitmap_CurrentID)));
            bin.AddRange((BitConverter.GetBytes(j.Bitmap_IDs.Count)));
            for (int i = 0;i < j.Bitmap_IDs.Count;i++)
                bin.AddRange((BitConverter.GetBytes(j.Bitmap_IDs[i])));

            if (!(j.parent == null))
                bin.AddRange((BitConverter.GetBytes(figure.Joints.IndexOf(j.parent))));
            else
                bin.AddRange(BitConverter.GetBytes(-1));
        }
Exemple #6
0
        private static void writeJointBlock(BinaryWriter bin, StickCustom figure, StickJoint j)
        {
            bin.Write(j.location.X);
            bin.Write(j.location.Y);

            bin.Write(j.color.ToArgb());
            bin.Write(j.handleColor.ToArgb());
            bin.Write(j.defaultHandleColor.ToArgb());
            bin.Write(j.thickness);
            bin.Write(j.drawState);
            bin.Write(j.drawOrder);
            bin.Write(j.visible);
            bin.Write(j.handleDrawn);

            bin.Write(j.Bitmap_CurrentID);
            bin.Write(j.Bitmap_IDs.Count);
            for (int i = 0;i < j.Bitmap_IDs.Count;i++)
                bin.Write(j.Bitmap_IDs[i]);

            if (!(j.parent == null))
                bin.Write(figure.Joints.IndexOf(j.parent));
            else
                bin.Write(-1);
        }
Exemple #7
0
        public static bool saveFigure(List<byte> bytes, StickCustom figure)
        {
            bytes.AddRange(tzf.fileSig);
            bytes.AddRange(tzf.curVersion);

            bytes.AddRange(BitConverter.GetBytes(figure.Joints.Count));
            bytes.AddRange(BitConverter.GetBytes(figure.getBitmapCount()));

            try
            {
                foreach (StickJoint joint in figure.Joints)
                    writeJointBlock(bytes, figure, joint);

                foreach (StickJoint joint in figure.Joints)
                    if (joint.Bitmap_IDs.Count > 0)
                        for (int x = 0;x < joint.Bitmap_IDs.Count;x++)
                            writeBitmapBlock(x, joint, bytes);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Saving failed. Error Detail:\n" + ex.Message, "Saving Failed!");

                return false;
            }
            return true;
        }
Exemple #8
0
        public static bool saveFigure(string path, StickCustom figure)
        {
            BinaryWriter bin = new BinaryWriter(File.Open(path, FileMode.Create));
            bin.Write(tzf.fileSig, 0, tzf.fileSig.Length);
            bin.Write(tzf.curVersion, 0, tzf.curVersion.Length);

            bin.Write(figure.Joints.Count);
            bin.Write(figure.getBitmapCount());

            try
            {
                foreach (StickJoint joint in figure.Joints)
                    writeJointBlock(bin, figure, joint);

                foreach (StickJoint joint in figure.Joints)
                    if (joint.Bitmap_IDs.Count > 0)
                        for (int x = 0;x < joint.Bitmap_IDs.Count;x++)
                            writeBitmapBlock(x, joint, bin);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Saving failed. Error Detail:\n" + ex.Message, "Saving Failed!");
                bin.Close();

                return false;
            }

            bin.Close();
            return true;
        }
Exemple #9
0
        public static StickCustom loadStickFile(byte[] bytes)
        {
            Stream ms = new MemoryStream(bytes);
            BinaryReader bin = new BinaryReader(ms);

            bin.BaseStream.Position += tzf.fileSig.Length + tzf.curVersion.Length;

            int jointCount = bin.ReadInt32();
            int bitmapCount = bin.ReadInt32();

            StickCustom figure = new StickCustom(1);
            figure.drawFig = true;
            figure.drawHandles = true;
            figure.isActiveFig = false;
            List<int> parentList = new List<int>();
            List<T0JointBitmap> bitmapList = new List<T0JointBitmap>();

            for (int i = 0;i < jointCount;i++)
            {
                int x = bin.ReadInt32();
                int y = bin.ReadInt32();

                Color col = Color.FromArgb(bin.ReadInt32());
                Color hCol = Color.FromArgb(bin.ReadInt32());
                Color defHCol = Color.FromArgb(bin.ReadInt32());
                int thickness = bin.ReadInt32();
                int drawState = bin.ReadInt32();
                int drawOrder = bin.ReadInt32();
                bool visible = bin.ReadBoolean();
                bool handleDrawn = bin.ReadBoolean();

                int Bitmap_CurrentID = bin.ReadInt32();
                int bitmapIndexes = bin.ReadInt32();

                List<int> bitmapis = new List<int>();
                for (int z = 0;z < bitmapIndexes;z++)
                    bitmapis.Add(bin.ReadInt32());

                int parentIndex = bin.ReadInt32();

                parentList.Add(parentIndex);

                figure.Joints.Add(new StickJoint("Joint " + i, new Point(x, y), thickness, col, hCol, 0, drawState, false, null, handleDrawn));

                figure.Joints[figure.Joints.Count - 1].Bitmap_CurrentID = Bitmap_CurrentID;
                figure.Joints[figure.Joints.Count - 1].Bitmap_IDs = bitmapis;

                figure.Joints[figure.Joints.Count - 1].drawOrder = drawOrder;
            }

            for (int i = 0;i < bitmapCount;i++)
            {
                int id = bin.ReadInt32();
                int nameCount = bin.ReadInt32();
                byte[] str = bin.ReadBytes(nameCount);
                string name = Functions.GetString(str);

                int Rotation = bin.ReadInt32();
                int OffsetX = bin.ReadInt32();
                int OffsetY = bin.ReadInt32();

                long bytesToRead = bin.ReadInt64();

                byte[] buffer = bin.ReadBytes((int)bytesToRead);

                //bin.Read(buffer, (int)bin.BaseStream.Position, (int)bytesToRead);
                Stream bitmapStream = new MemoryStream(buffer);

                Image bitty = Bitmap.FromStream(bitmapStream);

                bitmapList.Add(new T0JointBitmap(id, name, Rotation, OffsetX, OffsetY, bitty));
            }
            for (int i = 0;i < jointCount;i++)
            {
                foreach (T0JointBitmap bitmap in bitmapList)
                    if (figure.Joints[i].Bitmap_IDs.Contains(bitmap.id + 1))
                        bitmap.ApplyTo(figure.Joints[i]);

                if (parentList[i] != -1)
                    figure.Joints[i].parent = figure.Joints[parentList[i]];
            }

            return figure;
        }