public static void RenderLinePrimitive(LinePrimitive linePrimitive, SpriteBatch spriteBatch, IPositionedSizedObject ipso, SystemManagers managers, bool isDotted) { linePrimitive.Position.X = ipso.GetAbsoluteX(); linePrimitive.Position.Y = ipso.GetAbsoluteY(); Renderer renderer; if (managers != null) { renderer = managers.Renderer; } else { renderer = Renderer.Self; } Texture2D textureToUse = renderer.SinglePixelTexture; if (isDotted) { textureToUse = renderer.DottedLineTexture; } linePrimitive.Render(spriteBatch, managers, textureToUse, .2f * renderer.Camera.Zoom); }
public static bool HasCursorOver(this IPositionedSizedObject ipso, float x, float y) { float absoluteX = ipso.GetAbsoluteX(); float absoluteY = ipso.GetAbsoluteY(); return (x > absoluteX && y > absoluteY && x < absoluteX + ipso.Width && y < absoluteY + ipso.Height); }
private void SetLineRectangleAroundIpso(LineRectangle rectangle, IPositionedSizedObject pso) { float adjustedSelectionBorder = SelectionBorder / Renderer.Self.Camera.Zoom; rectangle.Visible = true; rectangle.X = pso.GetAbsoluteX() - adjustedSelectionBorder; rectangle.Y = pso.GetAbsoluteY() - adjustedSelectionBorder; rectangle.Width = pso.Width + adjustedSelectionBorder * 2; rectangle.Height = pso.Height + adjustedSelectionBorder * 2; }
public void SetValuesFrom(IPositionedSizedObject ipso) { this.mX = ipso.GetAbsoluteX(); this.mY = ipso.GetAbsoluteY(); this.mWidth = ipso.Width; this.mHeight = ipso.Height; if (ipso is GraphicalUiElement) { var asGue = ipso as GraphicalUiElement; SetOriginXPosition(asGue); } UpdateToProperties(); }
public static void Render(SystemManagers managers, SpriteBatch spriteBatch, IPositionedSizedObject ipso, Texture2D texture, Color color, Rectangle?sourceRectangle = null, bool flipHorizontal = false, bool flipVertical = false, float rotationInDegrees = 0, bool treat0AsFullDimensions = false ) { Renderer renderer = null; if (managers == null) { renderer = Renderer.Self; } else { renderer = managers.Renderer; } Texture2D textureToUse = texture; if (textureToUse == null) { textureToUse = LoaderManager.Self.InvalidTexture; if (textureToUse == null) { return; } } SpriteEffects effects = SpriteEffects.None; if (flipHorizontal) { effects |= SpriteEffects.FlipHorizontally; } if (flipVertical) { effects |= SpriteEffects.FlipVertically; } if ((ipso.Width > 0 && ipso.Height > 0) || treat0AsFullDimensions == false) { Vector2 scale = Vector2.One; if (textureToUse == null) { scale = new Vector2(ipso.Width, ipso.Height); } else { float ratioWidth = 1; float ratioHeight = 1; if (sourceRectangle.HasValue) { ratioWidth = sourceRectangle.Value.Width / (float)textureToUse.Width; ratioHeight = sourceRectangle.Value.Height / (float)textureToUse.Height; } scale = new Vector2(ipso.Width / (ratioWidth * textureToUse.Width), ipso.Height / (ratioHeight * textureToUse.Height)); } if (textureToUse != null && textureToUse.IsDisposed) { throw new ObjectDisposedException("Texture is disposed. Texture name: " + textureToUse.Name + ", sprite scale: " + scale); } spriteBatch.Draw(textureToUse, new Vector2(ipso.GetAbsoluteX(), ipso.GetAbsoluteY()), sourceRectangle, color, Microsoft.Xna.Framework.MathHelper.TwoPi * -rotationInDegrees / 360.0f, Vector2.Zero, scale, effects, 0); } else { int width = textureToUse.Width; int height = textureToUse.Height; if (sourceRectangle != null && sourceRectangle.HasValue) { width = sourceRectangle.Value.Width; height = sourceRectangle.Value.Height; } Rectangle destinationRectangle = new Rectangle( (int)(ipso.GetAbsoluteX()), (int)(ipso.GetAbsoluteY()), width, height); spriteBatch.Draw(textureToUse, destinationRectangle, sourceRectangle, color, rotationInDegrees / 360.0f, Vector2.Zero, effects, 0 ); } }
public static float GetAbsoluteRight(this IPositionedSizedObject ipso) { return(ipso.GetAbsoluteX() + ipso.Width); }
public static float GetAbsoluteLeft(this IPositionedSizedObject ipso) { return(ipso.GetAbsoluteX()); }
public static void Render(SystemManagers managers, SpriteBatch spriteBatch, IPositionedSizedObject ipso, Texture2D texture, Color color, Rectangle? sourceRectangle = null, bool flipHorizontal = false, bool flipVertical = false, float rotationInDegrees = 0, bool treat0AsFullDimensions = false ) { Renderer renderer = null; if (managers == null) { renderer = Renderer.Self; } else { renderer = managers.Renderer; } Texture2D textureToUse = texture; if (textureToUse == null) { textureToUse = LoaderManager.Self.InvalidTexture; if (textureToUse == null) { return; } } SpriteEffects effects = SpriteEffects.None; if (flipHorizontal) { effects |= SpriteEffects.FlipHorizontally; } if (flipVertical) { effects |= SpriteEffects.FlipVertically; } if ((ipso.Width > 0 && ipso.Height > 0) || treat0AsFullDimensions == false) { Vector2 scale = Vector2.One; if (textureToUse == null) { scale = new Vector2(ipso.Width, ipso.Height); } else { float ratioWidth = 1; float ratioHeight = 1; if (sourceRectangle.HasValue) { ratioWidth = sourceRectangle.Value.Width / (float)textureToUse.Width; ratioHeight = sourceRectangle.Value.Height / (float)textureToUse.Height; } scale = new Vector2(ipso.Width / (ratioWidth * textureToUse.Width), ipso.Height / (ratioHeight * textureToUse.Height)); } if (textureToUse != null && textureToUse.IsDisposed) { throw new ObjectDisposedException("Texture is disposed. Texture name: " + textureToUse.Name + ", sprite scale: " + scale); } spriteBatch.Draw(textureToUse, new Vector2(ipso.GetAbsoluteX(), ipso.GetAbsoluteY()), sourceRectangle, color, Microsoft.Xna.Framework.MathHelper.TwoPi * -rotationInDegrees/360.0f, Vector2.Zero, scale, effects, 0); } else { int width = textureToUse.Width; int height = textureToUse.Height; if (sourceRectangle != null && sourceRectangle.HasValue) { width = sourceRectangle.Value.Width; height = sourceRectangle.Value.Height; } Rectangle destinationRectangle = new Rectangle( (int)(ipso.GetAbsoluteX()), (int)(ipso.GetAbsoluteY()), width, height); spriteBatch.Draw(textureToUse, destinationRectangle, sourceRectangle, color, rotationInDegrees/360.0f, Vector2.Zero, effects, 0 ); } }