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(); }
public AnimationTrackControl(AnimationControl parent, AnimationTrack animTrack) { InitializeComponent(); mParent = parent; mAnimTrack = animTrack; CreateAnimKeys(); }
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; }
AnimationTrackControl GetAnimTrackControl(AnimationTrack track) { foreach (Control control in panel1.Controls) { if (control.Tag == track) return control as AnimationTrackControl; } return null; }
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; } }
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); }
public void SelectAnimationTrack(AnimationTrack track) { TreeNode node = SelectAnimationTrack(treeView1.Nodes, track); if (node != null) treeView1.SelectedNode = node; }
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; }
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; }
public void EditAnimation(Animation anim) { mAnimation = anim; mAnimTrack = null; SetTimePosition(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)); }
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); }
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); } }
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); }
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); }
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; }
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"); }
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(); }
public void SelectAnimationTrack(Animation anim, AnimationTrack track) { mAnimation = anim; mAnimTrack = track; SetTimePosition(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); }