using System;
using System.Drawing;
namespace Gwen.Control
{
///
/// Image container.
///
public class ImagePanel : Base
{
private readonly Texture m_Texture;
private readonly float[] m_uv;
private Color m_DrawColor;
///
/// Initializes a new instance of the class.
///
/// Parent control.
public ImagePanel(Base parent)
: base(parent)
{
m_uv = new float[4];
m_Texture = new Texture(Skin.Renderer);
SetUV(0, 0, 1, 1);
MouseInputEnabled = false;
m_DrawColor = Color.White;
}
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
public override void Dispose()
{
m_Texture.Dispose();
base.Dispose();
}
///
/// Sets the texture coordinates of the image.
///
public virtual void SetUV(float u1, float v1, float u2, float v2)
{
m_uv[0] = u1;
m_uv[1] = v1;
m_uv[2] = u2;
m_uv[3] = v2;
}
///
/// Texture name.
///
public String ImageName
{
get { return m_Texture.Name; }
set { m_Texture.Load(value); }
}
///
/// Renders the control using specified skin.
///
/// Skin to use.
protected override void Render(Skin.Base skin)
{
base.Render(skin);
skin.Renderer.DrawColor = m_DrawColor;
skin.Renderer.DrawTexturedRect(m_Texture, RenderBounds, m_uv[0], m_uv[1], m_uv[2], m_uv[3]);
}
///
/// Sizes the control to its contents.
///
public virtual void SizeToContents()
{
SetSize(m_Texture.Width, m_Texture.Height);
}
}
}