ImagePanel.h 1.5 KB

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