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  std::unique_ptr<Impl> pimpl;
28 
29  public:
30  Graphics(unsigned physical_width, unsigned physical_height);
31  ~Graphics();
32 
33  void set_resolution(unsigned logical_width, unsigned logical_height,
34  double black_bar_width = 0, double black_bar_height = 0);
35 
36  unsigned width() const;
37  unsigned height() const;
38 
41  void frame(const std::function<void ()>& f);
42 
46  static void flush();
47 
50  static void gl(const std::function<void ()>& f);
51 
56  static void gl(ZPos z, const std::function<void ()>& f);
57 
59  static void clip_to(double x, double y, double width, double height,
60  const std::function<void ()>& f);
61 
65  static Gosu::Image render(int width, int height, const std::function<void ()>& f,
66  unsigned image_flags = 0);
67 
69  static Gosu::Image record(int width, int height, const std::function<void ()>& f);
70 
72  static void transform(const Transform& transform,
73  const std::function<void ()>& f);
74 
79  static void draw_line(double x1, double y1, Color c1,
80  double x2, double y2, Color c2,
81  ZPos z, AlphaMode mode = AM_DEFAULT);
82 
83  static void draw_triangle(double x1, double y1, Color c1,
84  double x2, double y2, Color c2,
85  double x3, double y3, Color c3,
86  ZPos z, AlphaMode mode = AM_DEFAULT);
87 
88  static void draw_quad(double x1, double y1, Color c1,
89  double x2, double y2, Color c2,
90  double x3, double y3, Color c3,
91  double x4, double y4, Color c4,
92  ZPos z, AlphaMode mode = AM_DEFAULT);
93 
94  static void draw_rect(double x, double y, double width, double height,
95  Color c, ZPos z, AlphaMode mode = AM_DEFAULT);
96 
98  void set_physical_resolution(unsigned physical_width, unsigned physical_height);
99 
101  static void schedule_draw_op(const DrawOp& op);
102 
104  static std::unique_ptr<ImageData> create_image(const Bitmap& src,
105  unsigned src_x, unsigned src_y,
106  unsigned src_width, unsigned src_height,
107  unsigned image_flags);
108  };
109 }
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)
static Gosu::Image record(int width, int height, const std::function< void()> &f)
Records a macro and returns it as an Image.
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...
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
A two-dimensional array area of pixels, each represented by a Color value.
Definition: Bitmap.hpp:14
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.
Provides functionality for drawing rectangular images.
Definition: Image.hpp:16
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).
void set_resolution(unsigned logical_width, unsigned logical_height, double black_bar_width=0, double black_bar_height=0)
static Gosu::Image render(int width, int height, const std::function< void()> &f, unsigned image_flags=0)
Renders everything drawn in f onto a new Image of size (width, height).
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.