コード例 #1
0
ファイル: Player.cs プロジェクト: gigiwotou/GameEdit2
        public void Draw(AnimationTrack track, SpriteBatch spBatch)
        {
            System.Drawing.Drawing2D.Matrix worldMatrix = new System.Drawing.Drawing2D.Matrix();
            worldMatrix = track.CachedMatrix;

            // fetch the image out.
            Microsoft.Xna.Framework.Rectangle rect;
            Texture2D texture = GetTexture(track, out rect);

            System.Drawing.Drawing2D.Matrix finalTransform = mViewMatrix.Clone();
            finalTransform.Multiply(worldMatrix);
            float[] gM = finalTransform.Elements;

            Microsoft.Xna.Framework.Matrix xM = new Microsoft.Xna.Framework.Matrix();

            xM.M11 = gM[0];
            xM.M12 = gM[1];
            xM.M21 = gM[2];
            xM.M22 = gM[3];
            xM.M41 = gM[4];
            xM.M42 = gM[5];
            xM.M33 = 1;
            xM.M44 = 1;
            Microsoft.Xna.Framework.Rectangle dRect = new Microsoft.Xna.Framework.Rectangle();
            dRect.X = 100;
            dRect.Y = 100;
            dRect.Width = rect.Width;
            dRect.Height = rect.Height;

            spBatch.Begin(SpriteSortMode.Immediate,BlendState.AlphaBlend,SamplerState.LinearClamp,DepthStencilState.None,RasterizerState.CullCounterClockwise,null,xM);
            spBatch.Draw(texture, dRect, rect, Microsoft.Xna.Framework.Color.White);
            spBatch.End();
        }
コード例 #2
0
        public AnimationTrackControl(AnimationControl parent, AnimationTrack animTrack)
        {
            InitializeComponent();

            mParent = parent;
            mAnimTrack = animTrack;

            CreateAnimKeys();
        }
コード例 #3
0
        private void OnAddAnimTrackClicked(object sender, EventArgs e)
        {
            Animation animation = listView3.Tag as Animation;
            if (animation == null)
                return;

            AnimationTrack animTrack = new AnimationTrack();
            SettingDlg dlg = new SettingDlg("New Animation Track", animTrack);
            if (dlg.ShowDialog() != DialogResult.OK)
                return;

            animation.AnimTracks.Add(animTrack);

            ShowAnimation(animation);

            listView3.Items[listView3.Items.Count - 1].Selected = true;
        }
コード例 #4
0
 AnimationTrackControl GetAnimTrackControl(AnimationTrack track)
 {
     foreach (Control control in panel1.Controls)
     {
         if (control.Tag == track)
             return control as AnimationTrackControl;
     }
     return null;
 }
コード例 #5
0
        void ShowAnimationTrack(AnimationTrack animTrack)
        {
            listView4.Items.Clear();
            listView4.Tag = animTrack;

            foreach (AnimationKey animKey in animTrack.AnimKeys)
            {
                ListViewItem lvItem = listView4.Items.Add(animKey.Time.ToString());
                lvItem.Tag = animKey;
            }
        }
コード例 #6
0
        void ShowAnimTracks(TreeNodeCollection nodes, AnimationTrack track)
        {
            TreeNode node = nodes.Add(track.Name);
            node.Checked = track.Enabled;
            node.Tag = track;

            int nodeY = node.Bounds.Y;
            int nodeHeight = node.TreeView.ItemHeight;

            AnimationTrackControl trackControl = new AnimationTrackControl(this, track);
            trackControl.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Left;
            trackControl.Location = new Point(0, nodeY - 1);
            trackControl.Size = new Size(panel1.Width, nodeHeight + 1);
            trackControl.Tag = track;

            panel1.Controls.Add(trackControl);

            track.FlushImage();

            if (track.AnimTracks.Count > 0)
                ShowAnimTracks(node.Nodes, track.AnimTracks);
        }
コード例 #7
0
 public void SelectAnimationTrack(AnimationTrack track)
 {
     TreeNode node = SelectAnimationTrack(treeView1.Nodes, track);
     if (node != null)
         treeView1.SelectedNode = node;
 }
コード例 #8
0
        PointF[] GetHelperPoints(AnimationTrack track)
        {
            Matrix worldMatrix = track.CachedMatrix;
            Matrix finalTransform = mViewMatrix.Clone();
            finalTransform.Multiply(worldMatrix);

            // fetch the image out.
            System.Drawing.Image texture = GetTexture(track);
            PointF[] helperPoints = new PointF[]{
                new PointF(-texture.Width * 0.5f, -texture.Height * 0.5f), // top-left
                new PointF(+texture.Width * 0.5f, -texture.Height * 0.5f), // top-right
                new PointF(+texture.Width * 0.5f, +texture.Height * 0.5f), // bottom-right
                new PointF(-texture.Width * 0.5f, +texture.Height * 0.5f), // bottom-left
                new PointF(track.CachedKey.Center.X / track.CachedKey.Scale.X,
                    track.CachedKey.Center.Y / track.CachedKey.Scale.Y)};

            finalTransform.TransformPoints(helperPoints);

            return helperPoints;
        }
コード例 #9
0
        TreeNode SelectAnimationTrack(TreeNodeCollection nodes, AnimationTrack track)
        {
            foreach (TreeNode node in nodes)
            {
                if (node.Tag == track)
                    return node;

                if (node.Nodes.Count > 0)
                {
                    TreeNode childNode = SelectAnimationTrack(node.Nodes, track);
                    if (childNode != null)
                        return childNode;
                }
            }
            return null;
        }
コード例 #10
0
 public void EditAnimation(Animation anim)
 {
     mAnimation = anim;
     mAnimTrack = null;
     SetTimePosition(0);
 }
コード例 #11
0
        void Draw(AnimationTrack track, Graphics g)
        {
            Matrix worldMatrix = track.CachedMatrix;

            // fetch the image out.
            System.Drawing.Image texture = GetTexture(track);

            Matrix finalTransform = mViewMatrix.Clone();
            finalTransform.Multiply(worldMatrix);
            g.Transform = finalTransform;

            // draw the image.
            g.DrawImage(texture, new PointF(-texture.Width * 0.5f, -texture.Height * 0.5f));
        }
コード例 #12
0
        void ProcessMouseRotate(AnimationTrack track, PointF pre, PointF cur)
        {
            // fetch the center position.
            Matrix worldMatrix = track.CachedMatrix;
            Matrix finalTransform = mViewMatrix.Clone();
            finalTransform.Multiply(worldMatrix);

            AnimationKey defaultKey = track.CachedKey;
            PointF center = Transform(finalTransform, new PointF(defaultKey.Center.X / defaultKey.Scale.X, defaultKey.Center.Y / defaultKey.Scale.Y));

            double angle = MathHelper.AngleBetween(cur, center, pre);
            defaultKey.Rotate += (float)(angle * 180.0f / Math.PI);
        }
コード例 #13
0
        void ProcessMouseScale(AnimationTrack track, PointF pre, PointF cur, bool scaleX)
        {
            PointF[] baseLine = new PointF[] { PointF.Empty, PointF.Empty };
            if (scaleX)
                baseLine[1].Y = 100;
            else
                baseLine[1].X = 100;

            Matrix worldMatrix = track.CachedMatrix;
            Matrix finalTransform = mViewMatrix.Clone();
            finalTransform.Multiply(worldMatrix);
            finalTransform.TransformPoints(baseLine);

            double preDis = MathHelper.LinePointDist(baseLine[0], baseLine[1], pre, false);
            double curDis = MathHelper.LinePointDist(baseLine[0], baseLine[1], cur, false);
            float deltaMove = (float)(curDis - preDis);

            AnimationKey defaultKey = track.CachedKey;
            System.Drawing.Image texture = GetTexture(mAnimTrack);
            if (scaleX)
            {
                float preWidth = texture.Width * defaultKey.Scale.X;
                float curWidth = preWidth + deltaMove;
                float newScale = curWidth / texture.Width;
                defaultKey.Scale = new PointF(newScale, defaultKey.Scale.Y);
            }
            else
            {
                float preHeight = texture.Height * defaultKey.Scale.Y;
                float curHeight = preHeight + deltaMove;
                float newScale = curHeight / texture.Height;
                defaultKey.Scale = new PointF(defaultKey.Scale.X, newScale);
            }
        }
コード例 #14
0
        void ProcessMouseMove(AnimationTrack track, PointF pre, PointF cur)
        {
            Matrix parent = track.ParentMatrix.Clone();
            parent.Invert();

            SizeF delta = new SizeF(cur.X - pre.X, cur.Y - pre.Y);
            AnimationKey defaultKey = mAnimTrack.CachedKey;

            delta = Transform(parent, delta);
            defaultKey.Location += new SizeF(delta.Width, delta.Height);
        }
コード例 #15
0
 void ProcessMouseCenter(AnimationTrack track, PointF pre, PointF cur)
 {
     PointF delta = cur - new SizeF(pre.X, pre.Y);
     AnimationKey defaultKey = mAnimTrack.CachedKey;
     defaultKey.Center += new SizeF(delta.X, delta.Y);
 }
コード例 #16
0
        System.Drawing.Image GetTexture(AnimationTrack track)
        {
            GameData.Image image = track.CachedImage;
            System.Drawing.Image texture = image != null ? image.Imageset.Tag as System.Drawing.Image : null;

            if (texture != null)
            {
                Bitmap srcBitmap1 = new Bitmap(texture);
                Rectangle rect1 = new Rectangle(image.X, image.Y, image.Width, image.Height);
                texture = srcBitmap1.Clone(rect1, srcBitmap1.PixelFormat);

                int row = track.ImageRow;
                int col = track.ImageColum;
                int start = track.ImageStart;
                int offset = (int)track.CachedKey.ImageIndexOffset;

                Bitmap srcBitmap = new Bitmap(texture);
                int width = texture.Width / col;
                int height = texture.Height / row;
                int remainder;
                int quotient = Math.DivRem(offset, col, out remainder);
                if (quotient >= row)
                    quotient = row - 1;

                int x = remainder * width;
                int y = quotient * height;

                Rectangle rect = new Rectangle(x, y, width, height);
                texture = srcBitmap.Clone(rect, srcBitmap.PixelFormat);

                return texture;
            }
            return Resources.Missing;
        }
コード例 #17
0
ファイル: Player.cs プロジェクト: gigiwotou/GameEdit2
        Texture2D GetTexture(AnimationTrack track, out Microsoft.Xna.Framework.Rectangle rect1)
        {
            GameData.Image image = track.CachedImage;
            Texture2D texture = image != null ? image.Imageset.Tag as Texture2D : null;
            if (texture != null)
            {
                int row = track.ImageRow;
                int col = track.ImageColum;
                int start = track.ImageStart;
                int offset = (int)track.CachedKey.ImageIndexOffset;

                int width = image.Width / col;
                int height = image.Height / row;
                int remainder;
                int quotient = Math.DivRem(offset, col, out remainder);
                if (quotient >= row)
                    quotient = row - 1;

                int x = remainder * width;
                int y = quotient * height;
                rect1 = new Microsoft.Xna.Framework.Rectangle(image.X + x, image.Y + y, width, height);
                return texture;
            }
            Texture2D t2d = mGame.Content.Load<Texture2D>("Missing");
            rect1 = new Microsoft.Xna.Framework.Rectangle(0, 0, t2d.Width, t2d.Height);
            return mGame.Content.Load<Texture2D>("Missing");
        }
コード例 #18
0
        private void OnAddAnimTrackClicked(object sender, EventArgs e)
        {
            AnimationTrack newTrack = new AnimationTrack();
            newTrack.Name = "NewTrack" + mAnimation.AnimTracks.Count;

            if (treeView1.SelectedNode != null)
            {
                AnimationTrack parent = treeView1.SelectedNode.Tag as AnimationTrack;
                parent.AnimTracks.Add(newTrack);

                ShowAnimTracks(treeView1.SelectedNode.Nodes, newTrack);
            }
            else
            {
                mAnimation.AnimTracks.Add(newTrack);

                ShowAnimTracks(treeView1.Nodes, newTrack);
            }

            Refresh();
        }
コード例 #19
0
 public void SelectAnimationTrack(Animation anim, AnimationTrack track)
 {
     mAnimation = anim;
     mAnimTrack = track;
     SetTimePosition(0);
 }
コード例 #20
0
        void DrawHelper(AnimationTrack track, Graphics g)
        {
            PointF[] helperPoints = GetHelperPoints(track);

            // helper bounds.
            PointF[] helperBound = new PointF[] {
                helperPoints[0],
                helperPoints[1],
                helperPoints[2],
                helperPoints[3],
                helperPoints[0]};

            // helper corner bounds.
            RectangleF[] helperRects = new RectangleF[]{
                new RectangleF( // top-left
                    helperPoints[0].X - HelperKitWidth * 0.5f, helperPoints[0].Y - HelperKitWidth * 0.5f,
                    HelperKitWidth, HelperKitWidth),
                new RectangleF( // top-right
                    helperPoints[1].X - HelperKitWidth * 0.5f, helperPoints[1].Y - HelperKitWidth * 0.5f,
                    HelperKitWidth, HelperKitWidth),
                new RectangleF( // bottom-left
                    helperPoints[2].X - HelperKitWidth * 0.5f, helperPoints[2].Y - HelperKitWidth * 0.5f,
                    HelperKitWidth, HelperKitWidth),
                new RectangleF( // bottom-right
                    helperPoints[3].X - HelperKitWidth * 0.5f, helperPoints[3].Y - HelperKitWidth * 0.5f,
                    HelperKitWidth, HelperKitWidth)};

            // helper center.
            PointF[] helperCenter = new PointF[] {
                helperPoints[4] - new SizeF(-HelperKitWidth, 0),
                helperPoints[4] - new SizeF(0, +HelperKitWidth),
                helperPoints[4] - new SizeF(+HelperKitWidth, 0),
                helperPoints[4] - new SizeF(0, -HelperKitWidth),
                helperPoints[4] - new SizeF(-HelperKitWidth, 0),
                helperPoints[4] - new SizeF(+HelperKitWidth, 0),
                helperPoints[4] - new SizeF(0, +HelperKitWidth),
                helperPoints[4] - new SizeF(0, -HelperKitWidth)};

            // draw the image.
            g.Transform = new Matrix();
            g.DrawLines(mHelperPen, helperBound);
            g.DrawRectangles(mHelperPen, helperRects);
            g.DrawLines(mHelperPen, helperCenter);
        }