Gosu
Graphics.hpp
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <Gosu/Fwd.hpp>
7 #include <Gosu/Color.hpp>
8 #include <Gosu/GraphicsBase.hpp>
9 #include <functional>
10 #include <memory>
11 
12 namespace Gosu
13 {
14  struct DrawOp;
15 
19  const unsigned MAX_TEXTURE_SIZE = 1024;
20 
24  class Graphics
25  {
26  struct Impl;
27  // Non-movable (const) to avoid dangling internal references.
28  const std::unique_ptr<Impl> pimpl;
29 
30  public:
31  Graphics(unsigned physical_width, unsigned physical_height);
32  ~Graphics();
33 
34  void set_resolution(unsigned logical_width, unsigned logical_height,
35  double black_bar_width = 0, double black_bar_height = 0);
36 
37  unsigned width() const;
38  unsigned height() const;
39 
42  void frame(const std::function<void ()>& f);
43 
47  static void flush();
48 
51  static void gl(const std::function<void ()>& f);
52 
57  static void gl(ZPos z, const std::function<void ()>& f);
58 
60  static void clip_to(double x, double y, double width, double height,
61  const std::function<void ()>& f);
62 
66  static std::unique_ptr<Gosu::ImageData> record(int width, int height,
67  const std::function<void ()>& f);
68 
70  static void transform(const Transform& transform,
71  const std::function<void ()>& f);
72 
77  static void draw_line(double x1, double y1, Color c1,
78  double x2, double y2, Color c2,
79  ZPos z, AlphaMode mode = AM_DEFAULT);
80 
81  static void draw_triangle(double x1, double y1, Color c1,
82  double x2, double y2, Color c2,
83  double x3, double y3, Color c3,
84  ZPos z, AlphaMode mode = AM_DEFAULT);
85 
86  static void draw_quad(double x1, double y1, Color c1,
87  double x2, double y2, Color c2,
88  double x3, double y3, Color c3,
89  double x4, double y4, Color c4,
90  ZPos z, AlphaMode mode = AM_DEFAULT);
91 
92  static void draw_rect(double x, double y, double width, double height,
93  Color c, ZPos z, AlphaMode mode = AM_DEFAULT);
94 
96  void set_physical_resolution(unsigned physical_width, unsigned physical_height);
97 
99  static void schedule_draw_op(const DrawOp& op);
100 
102  static std::unique_ptr<ImageData> create_image(const Bitmap& src,
103  unsigned src_x, unsigned src_y,
104  unsigned src_width, unsigned src_height,
105  unsigned image_flags);
106  };
107 }
static void draw_rect(double x, double y, double width, double height, Color c, ZPos z, AlphaMode mode=AM_DEFAULT)
Graphics(unsigned physical_width, unsigned physical_height)
The library&#39;s main namespace.
Definition: Audio.hpp:12
static void gl(const std::function< void()> &f)
Finishes all pending Gosu drawing operations and executes the code in f in a clean OpenGL environment...
Contains forward declarations of all of Gosu&#39;s available classes.
Represents an RGBA color value with 8 bits for each channel.
Definition: Color.hpp:16
void set_physical_resolution(unsigned physical_width, unsigned physical_height)
For internal use only.
std::array< double, 16 > Transform
static void schedule_draw_op(const DrawOp &op)
For internal use only.
unsigned width() const
double ZPos
Represents the Z position of something drawn with Gosu&#39;s graphics system.
const unsigned MAX_TEXTURE_SIZE
Returns the maximum size of an texture that will be allocated internally by Gosu. ...
Definition: Graphics.hpp:19
Rectangular area of pixels, each represented by a Color value.
Definition: Bitmap.hpp:19
unsigned height() const
static void clip_to(double x, double y, double width, double height, const std::function< void()> &f)
Renders everything drawn in f clipped to a rectangle on the screen.
Serves as the target of all drawing and provides primitive drawing functionality. ...
Definition: Graphics.hpp:24
AlphaMode
Determines the way colors are combined when one is drawn onto another.
static void flush()
Flushes the Z queue to the screen and starts a new one.
static std::unique_ptr< ImageData > create_image(const Bitmap &src, unsigned src_x, unsigned src_y, unsigned src_width, unsigned src_height, unsigned image_flags)
Turns a portion of a bitmap into something that can be drawn on a Graphics object.
static void draw_quad(double x1, double y1, Color c1, double x2, double y2, Color c2, double x3, double y3, Color c3, double x4, double y4, Color c4, ZPos z, AlphaMode mode=AM_DEFAULT)
Interface of the Color class.
static void transform(const Transform &transform, const std::function< void()> &f)
Pushes one transformation onto the transformation stack.
void frame(const std::function< void()> &f)
Prepares the graphics object for drawing and then runs the rendering code in f.
static void draw_line(double x1, double y1, Color c1, double x2, double y2, Color c2, ZPos z, AlphaMode mode=AM_DEFAULT)
Draws a line from one point to another (last pixel exclusive).
static std::unique_ptr< Gosu::ImageData > record(int width, int height, const std::function< void()> &f)
Records a macro and returns it as an ImageData instance.
void set_resolution(unsigned logical_width, unsigned logical_height, double black_bar_width=0, double black_bar_height=0)
static void draw_triangle(double x1, double y1, Color c1, double x2, double y2, Color c2, double x3, double y3, Color c3, ZPos z, AlphaMode mode=AM_DEFAULT)
Contains general typedefs and enums related to graphics.