1// SuperTux
2// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17#include "video/drawing_context.hpp"
18
19#include <algorithm>
20
21#include "supertux/globals.hpp"
22#include "util/obstackpp.hpp"
23#include "video/drawing_request.hpp"
24#include "video/renderer.hpp"
25#include "video/surface.hpp"
26#include "video/video_system.hpp"
27#include "video/viewport.hpp"
28
29DrawingContext::DrawingContext(VideoSystem& video_system_, obstack& obst, bool overlay) :
30 m_video_system(video_system_),
31 m_obst(obst),
32 m_overlay(overlay),
33 m_viewport(0, 0,
34 m_video_system.get_viewport().get_screen_width(),
35 m_video_system.get_viewport().get_screen_height()),
36 m_ambient_color(Color::WHITE),
37 m_transform_stack(1),
38 m_colormap_canvas(*this, m_obst),
39 m_lightmap_canvas(*this, m_obst)
40{
41}
42
43DrawingContext::~DrawingContext()
44{
45 clear();
46}
47
48void
49DrawingContext::set_ambient_color(Color ambient_color)
50{
51 m_ambient_color = ambient_color;
52}
53
54Rectf
55DrawingContext::get_cliprect() const
56{
57 return Rectf(get_translation().x,
58 get_translation().y,
59 get_translation().x + static_cast<float>(m_viewport.get_width()),
60 get_translation().y + static_cast<float>(m_viewport.get_height()));
61}
62
63void
64DrawingContext::set_flip(Flip flip)
65{
66 transform().flip = flip;
67}
68
69Flip
70DrawingContext::get_flip() const
71{
72 return transform().flip;
73}
74
75void
76DrawingContext::set_alpha(float alpha)
77{
78 transform().alpha = alpha;
79}
80
81float
82DrawingContext::get_alpha() const
83{
84 return transform().alpha;
85}
86
87DrawingTransform&
88DrawingContext::transform()
89{
90 assert(!m_transform_stack.empty());
91 return m_transform_stack.back();
92}
93
94const DrawingTransform&
95DrawingContext::transform() const
96{
97 assert(!m_transform_stack.empty());
98 return m_transform_stack.back();
99}
100
101void
102DrawingContext::push_transform()
103{
104 m_transform_stack.push_back(transform());
105}
106
107void
108DrawingContext::pop_transform()
109{
110 m_transform_stack.pop_back();
111 assert(!m_transform_stack.empty());
112}
113
114/* EOF */
115