This repository has been archived on 2023-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
MyGameFramework/lib/gwen/controls/gwen_imagepanel.h
Gered c5cdddbeaa initial commit
current versions of all of my basic framework sources, build configurations/scripts, and supporting assets
2013-01-31 12:53:05 -05:00

116 lines
2.2 KiB
C++

/*
GWEN
Copyright (c) 2010 Facepunch Studios
See license in Gwen.h
*/
#pragma once
#ifndef GWEN_CONTROLS_IMAGEPANEL_H
#define GWEN_CONTROLS_IMAGEPANEL_H
#include "../gwen.h"
#include "gwen_base.h"
#include "../gwen_baserender.h"
#include "../gwen_texture.h"
namespace Gwen
{
namespace Controls
{
class GWEN_EXPORT ImagePanel : public Controls::Base
{
public:
GWEN_CONTROL_INLINE( ImagePanel, Controls::Base )
{
SetUV( 0, 0, 1, 1 );
SetMouseInputEnabled( false );
m_DrawColor = Colors::White;
SetStretch( true );
}
virtual ~ImagePanel()
{
m_Texture.Release( GetSkin()->GetRender() );
}
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;
}
virtual void SetImage( const TextObject& imageName )
{
m_Texture.Load( imageName, GetSkin()->GetRender() );
}
virtual void SetImage( const Texture& texture )
{
m_Texture = texture;
}
virtual TextObject& GetImage()
{
return m_Texture.name;
}
virtual int TextureWidth()
{
return m_Texture.width;
}
virtual int TextureHeight()
{
return m_Texture.height;
}
virtual const TextObject& GetImageName()
{
return m_Texture.name;
}
virtual void Render( Skin::Base* skin )
{
skin->GetRender()->SetDrawColor( m_DrawColor );
if ( m_bStretch )
skin->GetRender()->DrawTexturedRect( &m_Texture, GetRenderBounds(), m_uv[0], m_uv[1], m_uv[2], m_uv[3] );
else
skin->GetRender()->DrawTexturedRect( &m_Texture, Gwen::Rect( 0, 0, m_Texture.width, m_Texture.height ), m_uv[0], m_uv[1], m_uv[2], m_uv[3] );
}
virtual void SizeToContents()
{
SetSize( m_Texture.width, m_Texture.height );
}
virtual void SetDrawColor( Gwen::Color color )
{
m_DrawColor = color;
}
virtual bool FailedToLoad()
{
return m_Texture.FailedToLoad();
}
virtual bool GetStretch(){ return m_bStretch; }
virtual void SetStretch( bool b ){ m_bStretch = b; }
protected:
Texture m_Texture;
float m_uv[4];
Gwen::Color m_DrawColor;
bool m_bStretch;
};
}
}
#endif