GDIPlus.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. GWEN
  3. Copyright (c) 2011 Facepunch Studios
  4. See license in Gwen.h
  5. */
  6. #ifndef GWEN_RENDERERS_GDIPLUS_H
  7. #define GWEN_RENDERERS_GDIPLUS_H
  8. #include "Gwen/Gwen.h"
  9. #include "Gwen/BaseRender.h"
  10. /*
  11. GDI(plus) is pretty slow for rendering GWEN, because we're
  12. re-rendering everything on redraw.
  13. Therefore its usage should be as a test - rather than production.
  14. // Note: For this to work you should be including
  15. #include <gdiplus.h>
  16. // Which we don't do in the header, for the sake of usability
  17. */
  18. namespace Gwen
  19. {
  20. namespace Renderer
  21. {
  22. class GDIPlus : public Gwen::Renderer::Base
  23. {
  24. public:
  25. GDIPlus( HWND pHWND );
  26. ~GDIPlus();
  27. virtual void Begin();
  28. virtual void End();
  29. virtual void SetDrawColor(Gwen::Color color);
  30. virtual void DrawLine( int x, int y, int a, int b );
  31. virtual void DrawFilledRect( Gwen::Rect rect );
  32. virtual void LoadFont( Gwen::Font* pFont );
  33. virtual void FreeFont( Gwen::Font* pFont );
  34. virtual void RenderText( Gwen::Font* pFont, Gwen::Point pos, const Gwen::UnicodeString& text );
  35. virtual Gwen::Point MeasureText( Gwen::Font* pFont, const Gwen::UnicodeString& text );
  36. void StartClip();
  37. void EndClip();
  38. void DrawTexturedRect( Gwen::Texture* pTexture, Gwen::Rect pTargetRect, float u1=0.0f, float v1=0.0f, float u2=1.0f, float v2=1.0f );
  39. void LoadTexture( Gwen::Texture* pTexture );
  40. void FreeTexture( Gwen::Texture* pTexture );
  41. protected:
  42. int m_iWidth;
  43. int m_iHeight;
  44. Gdiplus::Color m_Colour;
  45. HWND m_HWND;
  46. HDC m_hDC;
  47. ULONG_PTR m_gdiplusToken;
  48. Gdiplus::Graphics* graphics;
  49. };
  50. class GDIPlusBuffered : public GDIPlus
  51. {
  52. public:
  53. GDIPlusBuffered( HWND pHWND );
  54. ~GDIPlusBuffered();
  55. virtual void Begin();
  56. virtual void End();
  57. private:
  58. void CreateBackbuffer();
  59. void DestroyBackbuffer();
  60. Gdiplus::Bitmap* m_Bitmap;
  61. };
  62. }
  63. }
  64. #endif