1 /*
2 	GWEN
3 	Copyright (c) 2011 Facepunch Studios
4 	See license in Gwen.h
5 */
6 
7 #ifndef GWEN_RENDERERS_GDIPLUS_H
8 #define GWEN_RENDERERS_GDIPLUS_H
9 
10 #include "Gwen/Gwen.h"
11 #include "Gwen/BaseRender.h"
12 
13 /*
14 
15  GDI(plus) is pretty slow for rendering GWEN, because we're
16  re-rendering everything on redraw.
17 
18  Therefore its usage should be as a test - rather than production.
19 
20  // Note: For this to work you should be including
21 
22  #include <gdiplus.h>
23 
24  // Which we don't do in the header, for the sake of usability
25 
26 */
27 
28 namespace Gwen
29 {
30 namespace Renderer
31 {
32 class GDIPlus : public Gwen::Renderer::Base
33 {
34 public:
35 	GDIPlus(HWND pHWND);
36 	~GDIPlus();
37 
38 	virtual void Begin();
39 	virtual void End();
40 
41 	virtual void SetDrawColor(Gwen::Color color);
42 
43 	virtual void DrawLine(int x, int y, int a, int b);
44 	virtual void DrawFilledRect(Gwen::Rect rect);
45 
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 	void StartClip();
52 	void EndClip();
53 
54 	void DrawTexturedRect(Gwen::Texture* pTexture, Gwen::Rect pTargetRect, float u1 = 0.0f, float v1 = 0.0f, float u2 = 1.0f, float v2 = 1.0f);
55 	void LoadTexture(Gwen::Texture* pTexture);
56 	void FreeTexture(Gwen::Texture* pTexture);
57 
58 protected:
59 	int m_iWidth;
60 	int m_iHeight;
61 
62 	Gdiplus::Color m_Colour;
63 
64 	HWND m_HWND;
65 	HDC m_hDC;
66 	ULONG_PTR m_gdiplusToken;
67 
68 	Gdiplus::Graphics* graphics;
69 };
70 
71 class GDIPlusBuffered : public GDIPlus
72 {
73 public:
74 	GDIPlusBuffered(HWND pHWND);
75 	~GDIPlusBuffered();
76 
77 	virtual void Begin();
78 	virtual void End();
79 
80 private:
81 	void CreateBackbuffer();
82 	void DestroyBackbuffer();
83 
84 	Gdiplus::Bitmap* m_Bitmap;
85 };
86 }  // namespace Renderer
87 }  // namespace Gwen
88 #endif
89