private void updateAnchorInfo() { if (spriteWindow.ShowAnchor >= 0) { SpriteAnchorFrame frame = sprite.Strip.Anchors[spriteWindow.ShowAnchor].Frames[sprite.FrameIndex]; valDistance.Text = frame.Length.ToString() + "px"; valAngle.Text = frame.Angle.ToString() + "°"; } }
protected override SpriteStrip Read(ContentReader input, SpriteStrip sprite) { if (sprite == null) { sprite = new SpriteStrip(); } // Get version, useful if the content structure changes int version = input.ReadInt32(); sprite.Name = input.ReadString(); sprite.Origin.X = input.ReadInt32(); sprite.Origin.Y = input.ReadInt32(); sprite.BoundingBox.Left = input.ReadInt32(); sprite.BoundingBox.Right = input.ReadInt32(); sprite.BoundingBox.Top = input.ReadInt32(); sprite.BoundingBox.Bottom = input.ReadInt32(); sprite.Size.Width = input.ReadInt32(); sprite.Size.Height = input.ReadInt32(); sprite.FrameCount = input.ReadInt32(); sprite.AnimationSpeed = input.ReadInt32(); // Framespeeds int frameCount = input.ReadInt32(); for (int i = 0; i < frameCount; i++) { sprite.FrameSpeeds.Add(input.ReadInt32()); } // Anchors int anchorCount = input.ReadInt32(); for (int i = 0; i < anchorCount; i++) { SpriteAnchor anchor = new SpriteAnchor(); anchor.Name = input.ReadString(); int anchorFrameCount = input.ReadInt32(); for (int j = 0; j < anchorFrameCount; j++) { SpriteAnchorFrame frame = new SpriteAnchorFrame(); frame.X1 = input.ReadInt32(); frame.Y1 = input.ReadInt32(); frame.X2 = input.ReadInt32(); frame.Y2 = input.ReadInt32(); frame.Angle = input.ReadInt32(); frame.Length = input.ReadInt32(); frame.Visible = input.ReadBoolean(); anchor.Frames.Add(frame); } sprite.Anchors.Add(anchor); } return(sprite); }
private void SpriteWindow_MouseMove(object sender, MouseEventArgs e) { ignoreBoundingBoxChange = true; System.Windows.Point mousePos = e.GetPosition(spriteWindow); if (keySpace) { if (e.LeftButton == MouseButtonState.Pressed) { spriteWindow.OffsetX += ((int)mousePos.X - mouseXPrev); spriteWindow.OffsetY += ((int)mousePos.Y - mouseYPrev); mouseXPrev = (int)mousePos.X; mouseYPrev = (int)mousePos.Y; } } else { System.Drawing.Point point = new System.Drawing.Point(((int)mousePos.X - spriteWindow.OffsetX) / spriteWindow.ZoomLevel, ((int)mousePos.Y - spriteWindow.OffsetY) / spriteWindow.ZoomLevel); valMouseX.Text = point.X.ToString(); valMouseY.Text = point.Y.ToString(); spriteWindow.MousePos = point; if (e.RightButton == MouseButtonState.Pressed) { sprite.Strip.BoundingBox.Right = point.X; sprite.Strip.BoundingBox.Bottom = point.Y; numBoundingBoxX2.Value = point.X; numBoundingBoxY2.Value = point.Y; UpdateBBOxGUIValues(); } else if (e.LeftButton == MouseButtonState.Pressed) { if (spriteWindow.ShowAnchor >= 0) { SpriteAnchorFrame frame = sprite.Strip.Anchors[spriteWindow.ShowAnchor].Frames[sprite.FrameIndex]; frame.X2 = point.X; frame.Y2 = point.Y; valDistance.Text = frame.CalculateLength().ToString() + "px"; valAngle.Text = frame.CalculateAngle().ToString() + "°"; } } } ignoreBoundingBoxChange = false; }
protected override void Draw(GameTime gameTime) { base.Draw(gameTime); GraphicsDevice.Clear(bgColor); spriteBatch.Begin(samplerState: SamplerState.PointClamp); //spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone); //spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, null); if (SpriteEdited != null) { if (spriteFrames.Count > SpriteEdited.FrameIndex) { DrawSprite(spriteFrames[SpriteEdited.FrameIndex], OffsetX, OffsetY, zoomLevel); } if (ShowBoundingBox) { spriteBatch.Draw(texRectangle.Texture, new Rectangle(OffsetX + ScreenValue(SpriteEdited.Strip.BoundingBox.Left), OffsetY + ScreenValue(SpriteEdited.Strip.BoundingBox.Top), ScreenValue(SpriteEdited.Strip.BoundingBox.Right) - ScreenValue(SpriteEdited.Strip.BoundingBox.Left) + zoomLevel, ScreenValue(SpriteEdited.Strip.BoundingBox.Bottom) - ScreenValue(SpriteEdited.Strip.BoundingBox.Top) + zoomLevel), new Color(255, 255, 255, 255) * 0.3f); } if (texOrigin != null && ShowOrigin) { spriteBatch.Draw(texOrigin.Texture, new Rectangle(OffsetX + ScreenValue(SpriteEdited.Strip.Origin.X) - texOrigin.XCenter * zoomLevel, OffsetY + ScreenValue(SpriteEdited.Strip.Origin.Y) - texOrigin.YCenter * zoomLevel, texOrigin.Texture.Width * zoomLevel, texOrigin.Texture.Height * zoomLevel), new Color(255, 255, 255, 255) * 0.6f); } if (texAnchor1 != null && ShowAnchor >= 0) { SpriteAnchorFrame frame = SpriteEdited.Strip.Anchors[ShowAnchor].Frames[SpriteEdited.FrameIndex]; spriteBatch.Draw(texAnchor2.Texture, new Rectangle(OffsetX + ScreenValue(frame.X2) - texAnchor2.XCenter * zoomLevel, OffsetY + ScreenValue(frame.Y2) - texAnchor2.YCenter * zoomLevel, texAnchor2.Texture.Width * zoomLevel, texAnchor2.Texture.Height * zoomLevel), new Color(255, 255, 255, 255) * 0.6f); spriteBatch.Draw(texAnchor1.Texture, new Rectangle(OffsetX + ScreenValue(frame.X1) - texAnchor1.XCenter * zoomLevel, OffsetY + ScreenValue(frame.Y1) - texAnchor2.YCenter * zoomLevel, texAnchor1.Texture.Width * zoomLevel, texAnchor1.Texture.Height * zoomLevel), new Color(255, 255, 255, 255) * 0.6f); } if (texCursor != null) { DrawSprite(texCursor.Texture, OffsetX + ScreenValue(MousePos.X) - texCursor.XCenter * zoomLevel, OffsetY + ScreenValue(MousePos.Y) - texCursor.YCenter * zoomLevel, zoomLevel); } //spriteBatch.Draw(texCursor.Texture, new Rectangle(OffsetX + ScreenValue(MousePos.X) - texCursor.XCenter * zoomLevel, OffsetY + ScreenValue(MousePos.Y) - texCursor.YCenter * zoomLevel, texCursor.Texture.Width * zoomLevel, texCursor.Texture.Height * zoomLevel), new Color(255, 255, 255, 255)); } spriteBatch.End(); }
private void SpriteWindow_MouseDown(object sender, MouseButtonEventArgs e) { ignoreOriginChange = true; ignoreBoundingBoxChange = true; System.Windows.Point mousePos = e.GetPosition(spriteWindow); if (keySpace) { mouseXPrev = (int)mousePos.X; mouseYPrev = (int)mousePos.Y; if (e.RightButton == MouseButtonState.Pressed) { spriteWindow.OffsetX = 0; spriteWindow.OffsetY = 0; } } else { System.Drawing.Point point = new System.Drawing.Point(((int)mousePos.X - spriteWindow.OffsetX) / spriteWindow.ZoomLevel, ((int)mousePos.Y - spriteWindow.OffsetY) / spriteWindow.ZoomLevel); if (e.RightButton == MouseButtonState.Pressed) { sprite.Strip.BoundingBox.Left = point.X; sprite.Strip.BoundingBox.Right = point.X; sprite.Strip.BoundingBox.Top = point.Y; sprite.Strip.BoundingBox.Bottom = point.Y; numBoundingBoxX1.Value = point.X; numBoundingBoxY1.Value = point.Y; numBoundingBoxX2.Value = point.X; numBoundingBoxY2.Value = point.Y; UpdateBBOxGUIValues(); spriteWindow.ShowBoundingBox = true; btnShowBoundingBox.Content = "Hide"; } else if (e.LeftButton == MouseButtonState.Pressed) { if (spriteWindow.ShowOrigin) { sprite.Strip.Origin.X = point.X; sprite.Strip.Origin.Y = point.Y; numOriginX.Value = point.X; numOriginY.Value = point.Y; } else if (spriteWindow.ShowAnchor >= 0) { SpriteAnchorFrame frame = sprite.Strip.Anchors[spriteWindow.ShowAnchor].Frames[sprite.FrameIndex]; frame.X1 = point.X; frame.Y1 = point.Y; frame.X2 = point.X; frame.Y2 = point.Y; frame.Angle = 0; frame.Length = 0; valDistance.Text = frame.Length.ToString() + "px"; valAngle.Text = frame.Angle.ToString() + "°"; } } } ignoreOriginChange = false; ignoreBoundingBoxChange = false; }