supertux
canvas.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 // 2018 Ingo Ruhnke <grumbel@gmail.com>
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef HEADER_SUPERTUX_VIDEO_CANVAS_HPP
19 #define HEADER_SUPERTUX_VIDEO_CANVAS_HPP
20 
21 #include <string>
22 #include <vector>
23 #include <memory>
24 #include <obstack.h>
25 
26 #include "math/rectf.hpp"
27 #include "math/vector.hpp"
28 #include "video/blend.hpp"
29 #include "video/color.hpp"
30 #include "video/drawing_target.hpp"
31 #include "video/font.hpp"
32 #include "video/font_ptr.hpp"
33 #include "video/gl.hpp"
34 #include "video/gradient.hpp"
35 #include "video/layer.hpp"
36 #include "video/paint_style.hpp"
37 
38 class DrawingContext;
39 class Renderer;
40 class VideoSystem;
41 struct DrawingRequest;
42 
43 class Canvas final
44 {
45 public:
46  enum Filter { BELOW_LIGHTMAP, ABOVE_LIGHTMAP, ALL };
47 
48 public:
49  Canvas(DrawingContext& context, obstack& obst);
50  ~Canvas();
51 
52  void draw_surface(const SurfacePtr& surface, const Vector& position, int layer);
53  void draw_surface(const SurfacePtr& surface, const Vector& position, float angle, const Color& color, const Blend& blend,
54  int layer);
55  void draw_surface_part(const SurfacePtr& surface, const Rectf& srcrect, const Rectf& dstrect,
56  int layer, const PaintStyle& style = PaintStyle());
57  void draw_surface_scaled(const SurfacePtr& surface, const Rectf& dstrect,
58  int layer, const PaintStyle& style = PaintStyle());
59  void draw_surface_batch(const SurfacePtr& surface,
60  std::vector<Rectf> srcrects,
61  std::vector<Rectf> dstrects,
62  const Color& color,
63  int layer);
64  void draw_surface_batch(const SurfacePtr& surface,
65  std::vector<Rectf> srcrects,
66  std::vector<Rectf> dstrects,
67  std::vector<float> angles,
68  const Color& color,
69  int layer);
70  void draw_text(const FontPtr& font, const std::string& text,
71  const Vector& position, FontAlignment alignment, int layer, const Color& color = Color(1.0,1.0,1.0));
73  void draw_center_text(const FontPtr& font, const std::string& text,
74  const Vector& position, int layer, const Color& color = Color(1.0,1.0,1.0));
75  void draw_gradient(const Color& from, const Color& to, int layer, const GradientDirection& direction,
76  const Rectf& region, const Blend& blend = Blend());
77  void draw_filled_rect(const Rectf& rect, const Color& color, int layer);
78  void draw_filled_rect(const Rectf& rect, const Color& color, float radius, int layer);
79 
80  void draw_inverse_ellipse(const Vector& pos, const Vector& size, const Color& color, int layer);
81 
82  void draw_line(const Vector& pos1, const Vector& pos2, const Color& color, int layer);
83  void draw_triangle(const Vector& pos1, const Vector& pos2, const Vector& pos3, const Color& color, int layer);
84 
86  void get_pixel(const Vector& position, const std::shared_ptr<Color>& color_out);
87 
88  void clear();
89  void render(Renderer& renderer, Filter filter);
90 
91  DrawingContext& get_context() { return m_context; }
92 
93 private:
94  Vector apply_translate(const Vector& pos) const;
95  float scale() const;
96 
97 private:
98  DrawingContext& m_context;
99  obstack& m_obst;
100  std::vector<DrawingRequest*> m_requests;
101 
102 private:
103  Canvas(const Canvas&) = delete;
104  Canvas& operator=(const Canvas&) = delete;
105 };
106 
107 #endif
108 
109 /* EOF */
Definition: obstack.h:151
Definition: renderer.hpp:30
Definition: drawing_request.hpp:39
Definition: paint_style.hpp:25
Definition: rectf.hpp:31
void get_pixel(const Vector &position, const std::shared_ptr< Color > &color_out)
on next update, set color to lightmap&#39;s color at position
Definition: canvas.cpp:335
Definition: video_system.hpp:37
Definition: color.hpp:26
void draw_center_text(const FontPtr &font, const std::string &text, const Vector &position, int layer, const Color &color=Color(1.0, 1.0, 1.0))
Draw text to the center of the screen.
Definition: canvas.cpp:239
Definition: canvas.hpp:43
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42