4
Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
6
This program is free software; you can redistribute it and/or modify it
7
under the terms of the GNU General Public License as published by the
8
Free Software Foundation; either version 2 of the License, or (at your
9
option) any later version.
11
This program is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16
You should have received a copy of the GNU General Public License along
17
with this program; if not, write to the Free Software Foundation, Inc.,
18
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
contact: plee-the-bear@gamned.org
22
Please add the tag [Bear] in the subject of your mails.
25
* \file strip_effect.cpp
26
* \brief Implementation of the bear::engine::strip_effect class.
27
* \author Julien Jorge
29
#include "engine/transition_effect/strip_effect.hpp"
31
#include "engine/level.hpp"
32
#include "visual/scene_rectangle.hpp"
36
/*----------------------------------------------------------------------------*/
40
bear::engine::strip_effect::strip_effect()
41
: m_strip_in_duration(1), m_full_duration(0), m_strip_out_duration(0),
42
m_elapsed_time(0), m_opacity(1), m_height(100)
44
m_color.components.red = 0;
45
m_color.components.green = 0;
46
m_color.components.blue = 0;
47
m_color.components.alpha =
48
std::numeric_limits<visual::color_type::component_type>::max();
49
} // strip_effect::strip_effect()
51
/*----------------------------------------------------------------------------*/
53
* \brief Tell if the effect is finished.
55
bool bear::engine::strip_effect::is_finished() const
58
>= m_strip_in_duration + m_full_duration + m_strip_out_duration;
59
} // strip_effect::is_finished()
61
/*----------------------------------------------------------------------------*/
63
* \brief Adjust the components of the effect.
64
* \param elapsed_time Elapsed time since the last call.
66
bear::universe::time_type
67
bear::engine::strip_effect::progress( universe::time_type elapsed_time )
69
universe::time_type result(0);
71
if ( !get_layer().get_level().is_paused() )
73
const universe::time_type total_time
74
( m_strip_in_duration + m_full_duration + m_strip_out_duration );
76
if ( m_elapsed_time + elapsed_time >= total_time )
78
if ( m_elapsed_time < total_time )
79
result = m_elapsed_time + elapsed_time - total_time;
81
result = elapsed_time;
84
m_elapsed_time += elapsed_time;
88
} // strip_effect::progress()
90
/*----------------------------------------------------------------------------*/
92
* \brief Render the components of the effect.
93
* \param e (out) The scene elements.
95
void bear::engine::strip_effect::render( scene_element_list& e ) const
97
visual::coordinate_type h(m_height);
100
>= m_strip_in_duration + m_full_duration + m_strip_out_duration )
103
if ( m_elapsed_time < m_strip_in_duration )
104
h = m_height * m_elapsed_time / m_strip_in_duration;
105
else if ( m_elapsed_time > m_strip_in_duration + m_full_duration )
107
* ( 1 - ( (m_elapsed_time - m_strip_in_duration - m_full_duration)
108
/ m_strip_out_duration ) );
111
( visual::scene_rectangle
113
visual::rectangle_type(0, 0, get_layer().get_size().x, h) ) );
115
( visual::scene_rectangle
116
( 0, get_layer().get_size().y - h, m_color,
117
visual::rectangle_type(0, 0, get_layer().get_size().x, h) ) );
118
} // strip_effect::render()
120
/*----------------------------------------------------------------------------*/
122
* \brief Set the durations of the effect.
123
* \param in How long the fade in is.
124
* \param full How long the full intensity is kept.
125
* \param out How long the fade out is.
127
void bear::engine::strip_effect::set_duration
128
( universe::time_type in, universe::time_type full, universe::time_type out )
130
m_strip_in_duration = in;
131
m_full_duration = full;
132
m_strip_out_duration = out;
133
} // strip_effect::set_duration()
135
/*----------------------------------------------------------------------------*/
137
* \brief Set the color of the effect.
138
* \param r Intensity of the red component in [0, 1].
139
* \param g Intensity of the green component in [0, 1].
140
* \param b Intensity of the blue component in [0, 1].
142
void bear::engine::strip_effect::set_color( double r, double g, double b )
144
const visual::color_type::component_type comp_max
145
( std::numeric_limits<visual::color_type::component_type>::max() );
147
m_color.components.red = r * comp_max;
148
m_color.components.green = g * comp_max;
149
m_color.components.blue = b * comp_max;
150
} // strip_effect::set_color()
152
/*----------------------------------------------------------------------------*/
154
* \brief Set the maximum intensity of the effect.
155
* \param o The maximum opacity [0, 1].
157
void bear::engine::strip_effect::set_opacity( double o )
165
} // strip_effect::set_opacity()
167
/*----------------------------------------------------------------------------*/
169
* \brief Set the height of the strips.
170
* \param h The height of the strips.
172
void bear::engine::strip_effect::set_strip_height( visual::coordinate_type h )
175
} // strip_effect::set_strip_height()