My Project
GDIEngine.h
1 #pragma once
2 #include <gdiplus.h>
3 #include <map>
4 #include "util/intrusive_ptr.h"
5 
6 namespace Gdiplus
7 {
8  class Image;
9  class Bitmap;
10  class Graphics;
11  class Matrix;
12 }
13 
14 namespace ParaEngine
15 {
16  struct DXUT_SCREEN_VERTEX;
17 
20  {
21  public:
23  CGDIRenderTarget(int nImageSize = 0);
24  virtual ~CGDIRenderTarget();
25 
27  void Init(int nImageSize);
28 
30  void Cleanup();
31 
33  bool IsValid();
34 
36  int GetRenderTargetSize(){return m_nRenderTargetSize;}
37 
38  /* get the graphics interface */
39  Gdiplus::Graphics* GetGraphics() {return m_pGraphics;}
40 
41  /* get the bitmap interface */
42  Gdiplus::Bitmap* GetBitmapSurface(){return m_pBitmapSurface;}
43 
45  Gdiplus::Bitmap* m_pBitmapSurface;
46 
49 
51  Gdiplus::Graphics* m_pGraphics;
52  };
53  typedef ParaIntrusivePtr<CGDIRenderTarget> CGDIRenderTarget_ptr;
54 
57  class CGDIEngine
58  {
59  public:
60  typedef std::map<std::string, Gdiplus::Bitmap*> TextureAsset_Map_Type;
61  typedef std::map<std::string, CGDIRenderTarget_ptr> RenderTarget_Map_Type;
62 
63  CGDIEngine();
64  ~CGDIEngine(void);
65  public:
66  virtual HRESULT Create();
67  virtual HRESULT Destroy();
68 
69  public:
70  //some GUI functions here
71  HRESULT Clear(const Color &color);
72 
74  void SetTransform(const Gdiplus::Matrix * matTransform);
75 
76  // actually no need to be called. since we never present to windows. We only render to render target.
77  bool Begin();
78 
80  bool DrawImage(Gdiplus::Image *image, float x, float y,float width, float height);
81 
84  bool DrawImage(Gdiplus::Image *image, float x, float y,float width, float height, DWORD dwColor);
85 
86  void End();
87 
88  void TestMe();
89 
93  Gdiplus::Bitmap* LoadTexture(const string& filename);
94 
99  Gdiplus::Bitmap* LoadTexture(const string& filename, int nFileFormat);
100 
104  Gdiplus::Bitmap* LoadTexture(const string& filename, const string& fileextension);
105 
109  CGDIRenderTarget_ptr CreateGetRenderTarget(const std::string& sName, int nRenderTargetSize = 256);
110 
114  CGDIRenderTarget_ptr CreateGetRenderTargetBySize(int nRenderTargetSize = 256);
115 
118  bool SetRenderTarget(CGDIRenderTarget_ptr pRenderTarget);
119 
123  bool SaveRenderTarget(const string& filename, int nWidth=256, int nHeight=256, bool bHasAlpha=true, DWORD colorKey = 0);
124  private:
126  bool IsValid();
127 
129  HDC m_hDC;
130 
132  TextureAsset_Map_Type m_textures;
133 
135  RenderTarget_Map_Type m_render_targets;
136 
138  CGDIRenderTarget_ptr m_pRenderTarget;
139 
141  CGDIRenderTarget_ptr m_pDefaultRenderTarget;
142 
144  int m_nRenderTargetSize;
145 
147  Gdiplus::Graphics* m_pGraphics;
148  };
149 }
a gdi render target is a Gdiplus::Bitmap and Gdiplus::Graphics object.
Definition: GDIEngine.h:19
this allows us to create another device, such as in a worker thread to perform some background work w...
Definition: GDIEngine.h:57
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: GDIEngine.h:6
Gdiplus::Bitmap * m_pBitmapSurface
the current render target.
Definition: GDIEngine.h:45
Gdiplus::Graphics * m_pGraphics
the default graphics for the render target.
Definition: GDIEngine.h:51
int GetRenderTargetSize()
get the render target size.
Definition: GDIEngine.h:36
single-threaded reference counted base class for boost::intrusive_ptr all boost::intrusive_ptr<T>, should derive from this class.
Definition: intrusive_ptr.h:75
Definition: ParaColor.h:275
int m_nRenderTargetSize
the current render target size, default to 256 pixels.
Definition: GDIEngine.h:48