BaseRender.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. GWEN
  3. Copyright (c) 2010 Facepunch Studios
  4. See license in Gwen.h
  5. */
  6. #pragma once
  7. #ifndef GWEN_BASERENDER_H
  8. #define GWEN_BASERENDER_H
  9. #include "Gwen/Structures.h"
  10. namespace Gwen
  11. {
  12. struct Font;
  13. struct Texture;
  14. namespace Renderer
  15. {
  16. class Base;
  17. class ICacheToTexture
  18. {
  19. public:
  20. virtual void Initialize() = 0;
  21. virtual void ShutDown() = 0;
  22. virtual void SetupCacheTexture( Gwen::Controls::Base* control ) = 0;
  23. virtual void FinishCacheTexture( Gwen::Controls::Base* control ) = 0;
  24. virtual void DrawCachedControlTexture( Gwen::Controls::Base* control ) = 0;
  25. virtual void CreateControlCacheTexture( Gwen::Controls::Base* control ) = 0;
  26. virtual void UpdateControlCacheTexture( Gwen::Controls::Base* control ) = 0;
  27. virtual void SetRenderer( Gwen::Renderer::Base* renderer ) = 0;
  28. };
  29. class GWEN_EXPORT Base
  30. {
  31. public:
  32. Base();
  33. virtual ~Base();
  34. virtual void Begin(){};
  35. virtual void End(){};
  36. virtual void SetDrawColor( Color color ){};
  37. virtual void DrawLine( int x, int y, int a, int b ){};
  38. virtual void DrawFilledRect( Gwen::Rect rect ){};;
  39. virtual void StartClip(){};
  40. virtual void EndClip(){};
  41. virtual void LoadTexture( Gwen::Texture* pTexture ){};
  42. virtual void FreeTexture( Gwen::Texture* pTexture ){};
  43. virtual void DrawTexturedRect( Gwen::Texture* pTexture, Gwen::Rect pTargetRect, float u1=0.0f, float v1=0.0f, float u2=1.0f, float v2=1.0f ){};
  44. virtual void DrawMissingImage( Gwen::Rect pTargetRect );
  45. virtual ICacheToTexture* GetCTT() { return NULL; }
  46. virtual void LoadFont( Gwen::Font* pFont ){};
  47. virtual void FreeFont( Gwen::Font* pFont ){};
  48. virtual void RenderText( Gwen::Font* pFont, Gwen::Point pos, const Gwen::UnicodeString& text );
  49. virtual Gwen::Point MeasureText( Gwen::Font* pFont, const Gwen::UnicodeString& text );
  50. //
  51. // No need to implement these functions in your derived class, but if
  52. // you can do them faster than the default implementation it's a good idea to.
  53. //
  54. virtual void DrawLinedRect( Gwen::Rect rect );
  55. virtual void DrawPixel( int x, int y );
  56. virtual void DrawShavedCornerRect( Gwen::Rect rect, bool bSlight = false );
  57. virtual Gwen::Point MeasureText( Gwen::Font* pFont, const Gwen::String& text );
  58. virtual void RenderText( Gwen::Font* pFont, Gwen::Point pos, const Gwen::String& text );
  59. virtual void Resize(int width, int height)=0;
  60. public:
  61. //
  62. // Translate a panel's local drawing coordinate
  63. // into view space, taking Offset's into account.
  64. //
  65. void Translate( int& x, int& y );
  66. void Translate( Gwen::Rect& rect );
  67. //
  68. // Set the rendering offset. You shouldn't have to
  69. // touch these, ever.
  70. //
  71. void SetRenderOffset( const Gwen::Point& offset ){ m_RenderOffset = offset; }
  72. void AddRenderOffset( const Gwen::Rect& offset ){ m_RenderOffset.x += offset.x; m_RenderOffset.y += offset.y; }
  73. const Gwen::Point& GetRenderOffset() const { return m_RenderOffset; }
  74. private:
  75. Gwen::Point m_RenderOffset;
  76. public:
  77. void SetClipRegion( Gwen::Rect rect );
  78. void AddClipRegion( Gwen::Rect rect );
  79. bool ClipRegionVisible();
  80. const Gwen::Rect& ClipRegion() const;
  81. private:
  82. Gwen::Rect m_rectClipRegion;
  83. public:
  84. void SetScale( float fScale ){ m_fScale = fScale; }
  85. float Scale() const { return m_fScale; }
  86. float m_fScale;
  87. };
  88. }
  89. }
  90. #endif