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 "supertux/shrinkfade.hpp" |
18 | |
19 | #include "supertux/globals.hpp" |
20 | #include "video/drawing_context.hpp" |
21 | #include "video/video_system.hpp" |
22 | #include "video/viewport.hpp" |
23 | |
24 | ShrinkFade::ShrinkFade(const Vector& dest_, float fade_time_) : |
25 | m_dest(dest_), |
26 | m_fade_time(fade_time_), |
27 | m_accum_time(0), |
28 | m_initial_size(static_cast<float>(SCREEN_HEIGHT > SCREEN_WIDTH ? SCREEN_HEIGHT : SCREEN_WIDTH)) |
29 | { |
30 | } |
31 | |
32 | void |
33 | ShrinkFade::update(float dt_sec) |
34 | { |
35 | m_accum_time += dt_sec; |
36 | if (m_accum_time > m_fade_time) |
37 | m_accum_time = m_fade_time; |
38 | } |
39 | |
40 | void |
41 | ShrinkFade::draw(DrawingContext& context) |
42 | { |
43 | float progress = m_accum_time / m_fade_time; |
44 | float diameter = 2 * m_initial_size * (1.0f - progress); |
45 | context.color().draw_inverse_ellipse(m_dest, Vector(1.1f * diameter, diameter), |
46 | Color(0, 0, 0), LAYER_GUI + 1); |
47 | } |
48 | |
49 | bool |
50 | ShrinkFade::done() const |
51 | { |
52 | return m_accum_time >= m_fade_time; |
53 | } |
54 | |
55 | /* EOF */ |
56 | |