Graphics.hpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 #ifndef GOSU_GRAPHICS_HPP
00005 #define GOSU_GRAPHICS_HPP
00006 
00007 #include <Gosu/Fwd.hpp>
00008 #include <Gosu/Color.hpp>
00009 #include <Gosu/GraphicsBase.hpp>
00010 #include <Gosu/TR1.hpp>
00011 #include <memory>
00012 
00013 namespace Gosu
00014 {
00016     unsigned screenWidth();
00017     
00019     unsigned screenHeight();
00020     
00024     unsigned const MAX_TEXTURE_SIZE = 1024;
00025     
00026     #ifdef GOSU_IS_MAC
00027     struct Transform
00028     {
00029         double value[16];
00030         bool operator==(const Transform &other) { for (int i = 0; i < 16; ++i) if ((*this)[i] != other[i]) return false; return true; }
00031         const double &operator[](std::size_t idx) const { return value[idx]; }
00032         double &operator[](std::size_t idx) { return value[idx]; }
00033     };
00034     #else
00035     typedef std::tr1::array<double, 16> Transform;
00036     #endif
00037     Transform translate(double x, double y);
00038     Transform rotate(double angle, double aroundX = 0, double aroundY = 0);
00039     Transform scale(double factor);
00040     Transform scale(double factorX, double factorY, double fromX = 0, double fromY = 0);
00041     
00045     class Graphics
00046     {
00047         struct Impl;
00048         const std::auto_ptr<Impl> pimpl;
00049 
00050     public:
00051         Graphics(unsigned physicalWidth, unsigned physicalHeight, bool fullscreen);
00052         ~Graphics();
00053 
00054         // Undocumented until I have thought about this...
00055         void setResolution(unsigned virtualWidth, unsigned virtualHeight);
00056         // End of Undocumented
00057         
00058         unsigned width() const;
00059         unsigned height() const;
00060         bool fullscreen() const;
00061 
00064         bool begin(Color clearWithColor = Color::BLACK);
00066         void end();
00069         void flush();
00070         
00073         void beginGL();
00075         void endGL();
00082         void scheduleGL(const std::tr1::function<void()>& functor, ZPos z);
00083         
00085         void beginClipping(double x, double y, double width, double height);
00087         void endClipping();
00088         
00090         void beginRecording();
00096         std::auto_ptr<Gosu::ImageData> endRecording(int width, int height);
00097         
00099         void pushTransform(const Transform& transform);
00101         void popTransform();
00102 
00107         void drawLine(double x1, double y1, Color c1,
00108             double x2, double y2, Color c2,
00109             ZPos z, AlphaMode mode = amDefault);
00110 
00111         void drawTriangle(double x1, double y1, Color c1,
00112             double x2, double y2, Color c2,
00113             double x3, double y3, Color c3,
00114             ZPos z, AlphaMode mode = amDefault);
00115 
00116         void drawQuad(double x1, double y1, Color c1,
00117             double x2, double y2, Color c2,
00118             double x3, double y3, Color c3,
00119             double x4, double y4, Color c4,
00120             ZPos z, AlphaMode mode = amDefault);
00121 
00124         std::auto_ptr<ImageData> createImage(const Bitmap& src,
00125             unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
00126             unsigned borderFlags);
00127     };
00128 }
00129 
00130 #endif