private void GetDrawingRec()
{
int portWidth = _grahpics.Viewport.Width;
int portHeight = _grahpics.Viewport.Height;
#region Case both width and height are specified
if (_relWidth != null && _relHeight != null)
{
int width = (int)(portWidth * _relWidth);
int height = (int)(portHeight * _relHeight);
int x = (int)(portWidth * _relPosition.X - (float)width * (.5f + .5f * _panning.X));
int y = (int)(portHeight * _relPosition.Y - (float)height * (.5f + .5f * _panning.Y));
_rec = new Rectangle(
x,
y,
width,
height);
CheckOverride();
return;
}
#endregion
#region Case only width is specified
if (_relWidth != null && _relHeight == null)
{
float spriteAspectRatio = (float)_sprite.Height / (float)_sprite.Width;
int width = (int)(portWidth * _relWidth);
int height = (int)(portWidth * _relWidth * spriteAspectRatio);
int x = (int)(portWidth * _relPosition.X - (float)width * (.5f + .5f * _panning.X));
int y = (int)(portHeight * _relPosition.Y - (float)height * (.5f + .5f * _panning.Y));
_rec = new Rectangle(
x,
y,
width,
height);
CheckOverride();
return;
}
#endregion
#region Case only height is specified
if (_relWidth == null && _relHeight != null)
{
float spriteAspectRatio = _sprite.Width / _sprite.Height;
int width = (int)(portHeight * _relHeight * spriteAspectRatio);
int height = (int)(portHeight * _relHeight);
int x = (int)(portWidth * _relPosition.X - (float)width * (.5f + .5f * _panning.X));
int y = (int)(portHeight * _relPosition.Y - (float)height * (.5f + .5f * _panning.Y));
_rec = new Rectangle(
x,
y,
width,
height);
CheckOverride();
return;
}
#endregion
throw new Exception("Sprite dimensions not specified.");
}