Graphics.hpp
Go to the documentation of this file.
1 
2 
3 
4 #ifndef GOSU_GRAPHICS_HPP
5 #define GOSU_GRAPHICS_HPP
6 
7 #include <Gosu/Fwd.hpp>
8 #include <Gosu/Color.hpp>
9 #include <Gosu/GraphicsBase.hpp>
10 #include <Gosu/TR1.hpp>
11 #include <memory>
12 
13 namespace Gosu
14 {
16  unsigned screenWidth();
17 
19  unsigned screenHeight();
20 
24  unsigned const MAX_TEXTURE_SIZE = 1024;
25 
26  #ifdef GOSU_IS_MAC
27  struct Transform
28  {
29  double value[16];
30  bool operator==(const Transform &other) { for (int i = 0; i < 16; ++i) if ((*this)[i] != other[i]) return false; return true; }
31  const double &operator[](std::size_t idx) const { return value[idx]; }
32  double &operator[](std::size_t idx) { return value[idx]; }
33  };
34  #else
35  typedef std::tr1::array<double, 16> Transform;
36  #endif
37  Transform translate(double x, double y);
38  Transform rotate(double angle, double aroundX = 0, double aroundY = 0);
39  Transform scale(double factor);
40  Transform scale(double factorX, double factorY, double fromX = 0, double fromY = 0);
41 
45  class Graphics
46  {
47  struct Impl;
48  const std::auto_ptr<Impl> pimpl;
49 
50  public:
51  Graphics(unsigned physicalWidth, unsigned physicalHeight, bool fullscreen);
52  ~Graphics();
53 
54  // Undocumented until I have thought about this...
55  void setResolution(unsigned virtualWidth, unsigned virtualHeight);
56  // End of Undocumented
57 
58  unsigned width() const;
59  unsigned height() const;
60  bool fullscreen() const;
61 
64  bool begin(Color clearWithColor = Color::BLACK);
66  void end();
69  void flush();
70 
73  void beginGL();
75  void endGL();
82  void scheduleGL(const std::tr1::function<void()>& functor, ZPos z);
83 
85  void beginClipping(double x, double y, double width, double height);
87  void endClipping();
88 
90  void beginRecording();
96  std::auto_ptr<Gosu::ImageData> endRecording(int width, int height);
97 
99  void pushTransform(const Transform& transform);
101  void popTransform();
102 
107  void drawLine(double x1, double y1, Color c1,
108  double x2, double y2, Color c2,
109  ZPos z, AlphaMode mode = amDefault);
110 
111  void drawTriangle(double x1, double y1, Color c1,
112  double x2, double y2, Color c2,
113  double x3, double y3, Color c3,
114  ZPos z, AlphaMode mode = amDefault);
115 
116  void drawQuad(double x1, double y1, Color c1,
117  double x2, double y2, Color c2,
118  double x3, double y3, Color c3,
119  double x4, double y4, Color c4,
120  ZPos z, AlphaMode mode = amDefault);
121 
124  std::auto_ptr<ImageData> createImage(const Bitmap& src,
125  unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
126  unsigned borderFlags);
127  };
128 }
129 
130 #endif