1 /* 2 GWEN 3 Copyright (c) 2010 Facepunch Studios 4 See license in Gwen.h 5 */ 6 7 #pragma once 8 #ifndef GWEN_CONTROLS_IMAGEPANEL_H 9 #define GWEN_CONTROLS_IMAGEPANEL_H 10 11 #include "Gwen/Gwen.h" 12 #include "Gwen/Controls/Base.h" 13 #include "Gwen/BaseRender.h" 14 #include "Gwen/Texture.h" 15 16 namespace Gwen 17 { 18 namespace Controls 19 { 20 class GWEN_EXPORT ImagePanel : public Controls::Base 21 { 22 public: GWEN_CONTROL_INLINE(ImagePanel,Controls::Base)23 GWEN_CONTROL_INLINE(ImagePanel, Controls::Base) 24 { 25 SetUV(0, 0, 1, 1); 26 SetMouseInputEnabled(false); 27 m_DrawColor = Colors::White; 28 } 29 ~ImagePanel()30 virtual ~ImagePanel() 31 { 32 m_Texture.Release(GetSkin()->GetRender()); 33 } 34 SetUV(float u1,float v1,float u2,float v2)35 virtual void SetUV(float u1, float v1, float u2, float v2) 36 { 37 m_uv[0] = u1; 38 m_uv[1] = v1; 39 m_uv[2] = u2; 40 m_uv[3] = v2; 41 } 42 SetImage(const TextObject & imageName)43 virtual void SetImage(const TextObject& imageName) 44 { 45 m_Texture.Load(imageName, GetSkin()->GetRender()); 46 } 47 GetImageName()48 virtual const TextObject& GetImageName() 49 { 50 return m_Texture.name; 51 } 52 Render(Skin::Base * skin)53 virtual void Render(Skin::Base* skin) 54 { 55 skin->GetRender()->SetDrawColor(m_DrawColor); 56 skin->GetRender()->DrawTexturedRect(&m_Texture, GetRenderBounds(), m_uv[0], m_uv[1], m_uv[2], m_uv[3]); 57 } 58 SizeToContents()59 virtual void SizeToContents() 60 { 61 SetSize(m_Texture.width, m_Texture.height); 62 } 63 SetDrawColor(Gwen::Color & color)64 virtual void SetDrawColor(Gwen::Color& color) 65 { 66 m_DrawColor = color; 67 } 68 69 Texture m_Texture; 70 float m_uv[4]; 71 Gwen::Color m_DrawColor; 72 }; 73 } // namespace Controls 74 } // namespace Gwen 75 #endif 76