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
38class DrawingContext;
39class Renderer;
40class VideoSystem;
41struct DrawingRequest;
42
43class Canvas final
44{
45public:
46 enum Filter { BELOW_LIGHTMAP, ABOVE_LIGHTMAP, ALL };
47
48public:
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));
72 /** Draw text to the center of the screen */
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
85 /** on next update, set color to lightmap's color at position */
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
93private:
94 Vector apply_translate(const Vector& pos) const;
95
96private:
97 DrawingContext& m_context;
98 obstack& m_obst;
99 std::vector<DrawingRequest*> m_requests;
100
101private:
102 Canvas(const Canvas&) = delete;
103 Canvas& operator=(const Canvas&) = delete;
104};
105
106#endif
107
108/* EOF */
109