public override void Draw(UISpriteBatch SBatch)
{
if (!Visible) { return; }
if (m_CalcAutoSize)
{
CalculateAutoSize();
}
/** Draw the button as a 3 slice **/
var frame = m_CurrentFrame;
if (Selected)
{
frame = 1;
}
if (m_Disabled)
{
frame = 3;
}
frame = Math.Min(m_ImageStates - 1, frame);
int offset = frame * m_Width;
int vOffset = m_ButtonFrame * m_Height;
if (Width != 0)
{
//TODO: Work out these numbers once & cache them. Invalidate when texture or width changes
/** left **/
base.DrawLocalTexture(SBatch, m_Texture, new Rectangle(offset, vOffset, m_WidthDiv3, m_Height), Vector2.Zero);
/** center **/
base.DrawLocalTexture(SBatch, m_Texture, new Rectangle(offset + m_WidthDiv3, vOffset, m_WidthDiv3, m_Height), new Vector2(m_WidthDiv3, 0), new Vector2( (Width - (m_WidthDiv3 * 2)) / m_WidthDiv3, 1.0f));
/** right **/
base.DrawLocalTexture(SBatch, m_Texture, new Rectangle(offset + (m_Width - m_WidthDiv3), vOffset, m_WidthDiv3, m_Height), new Vector2(Width - m_WidthDiv3, 0));
}
else
{
base.DrawLocalTexture(SBatch, m_Texture, new Rectangle(offset, vOffset, m_Width, m_Height), Vector2.Zero);
}
/**
* Label
*/
if (m_Caption != null && m_CaptionStyle != null)
{
var box =GetBounds();
//Little hack to get slightly better centering on text on buttons
box.Height -= 2;
this.DrawLocalString(SBatch, m_Caption, Vector2.Zero, m_CaptionStyle, box, TextAlignment.Center | TextAlignment.Middle, Rectangle.Empty, m_State);
}
}