~ubuntu-branches/ubuntu/trusty/plee-the-bear/trusty-proposed

« back to all changes in this revision

Viewing changes to bear-engine/core/src/engine/transition_effect/code/strip_effect.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Bear Engine
 
3
 
 
4
  Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
 
5
 
 
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.
 
10
 
 
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
 
14
  more details.
 
15
 
 
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
 
19
 
 
20
  contact: plee-the-bear@gamned.org
 
21
 
 
22
  Please add the tag [Bear] in the subject of your mails.
 
23
*/
 
24
/**
 
25
 * \file strip_effect.cpp
 
26
 * \brief Implementation of the bear::engine::strip_effect class.
 
27
 * \author Julien Jorge
 
28
 */
 
29
#include "engine/transition_effect/strip_effect.hpp"
 
30
 
 
31
#include "engine/level.hpp"
 
32
#include "visual/scene_rectangle.hpp"
 
33
 
 
34
#include <limits>
 
35
 
 
36
/*----------------------------------------------------------------------------*/
 
37
/**
 
38
 * \brief Constructor.
 
39
 */
 
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)
 
43
{
 
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()
 
50
 
 
51
/*----------------------------------------------------------------------------*/
 
52
/**
 
53
 * \brief Tell if the effect is finished.
 
54
 */
 
55
bool bear::engine::strip_effect::is_finished() const
 
56
{
 
57
  return m_elapsed_time
 
58
    >= m_strip_in_duration + m_full_duration + m_strip_out_duration;
 
59
} // strip_effect::is_finished()
 
60
 
 
61
/*----------------------------------------------------------------------------*/
 
62
/**
 
63
 * \brief Adjust the components of the effect.
 
64
 * \param elapsed_time Elapsed time since the last call.
 
65
 */
 
66
bear::universe::time_type
 
67
bear::engine::strip_effect::progress( universe::time_type elapsed_time )
 
68
{
 
69
  universe::time_type result(0);
 
70
 
 
71
  if ( !get_layer().get_level().is_paused() )
 
72
    {
 
73
      const universe::time_type total_time
 
74
        ( m_strip_in_duration + m_full_duration + m_strip_out_duration );
 
75
 
 
76
      if ( m_elapsed_time + elapsed_time >= total_time )
 
77
        {
 
78
          if ( m_elapsed_time < total_time )
 
79
            result = m_elapsed_time + elapsed_time - total_time;
 
80
          else
 
81
            result = elapsed_time;
 
82
        }
 
83
 
 
84
      m_elapsed_time += elapsed_time;
 
85
    }
 
86
 
 
87
  return result;
 
88
} // strip_effect::progress()
 
89
 
 
90
/*----------------------------------------------------------------------------*/
 
91
/**
 
92
 * \brief Render the components of the effect.
 
93
 * \param e (out) The scene elements.
 
94
 */
 
95
void bear::engine::strip_effect::render( scene_element_list& e ) const
 
96
{
 
97
  visual::coordinate_type h(m_height);
 
98
 
 
99
  if ( m_elapsed_time
 
100
       >= m_strip_in_duration + m_full_duration + m_strip_out_duration )
 
101
    return;
 
102
 
 
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 )
 
106
    h = m_height
 
107
      * ( 1 - ( (m_elapsed_time - m_strip_in_duration - m_full_duration)
 
108
                / m_strip_out_duration ) );
 
109
 
 
110
  e.push_back
 
111
    ( visual::scene_rectangle
 
112
      ( 0, 0, m_color,
 
113
        visual::rectangle_type(0, 0, get_layer().get_size().x, h) ) );
 
114
  e.push_back
 
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()
 
119
 
 
120
/*----------------------------------------------------------------------------*/
 
121
/**
 
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.
 
126
 */
 
127
void bear::engine::strip_effect::set_duration
 
128
( universe::time_type in, universe::time_type full, universe::time_type out )
 
129
{
 
130
  m_strip_in_duration = in;
 
131
  m_full_duration = full;
 
132
  m_strip_out_duration = out;
 
133
} // strip_effect::set_duration()
 
134
 
 
135
/*----------------------------------------------------------------------------*/
 
136
/**
 
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].
 
141
 */
 
142
void bear::engine::strip_effect::set_color( double r, double g, double b )
 
143
{
 
144
  const visual::color_type::component_type comp_max
 
145
    ( std::numeric_limits<visual::color_type::component_type>::max() );
 
146
 
 
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()
 
151
 
 
152
/*----------------------------------------------------------------------------*/
 
153
/**
 
154
 * \brief Set the maximum intensity of the effect.
 
155
 * \param o The maximum opacity [0, 1].
 
156
 */
 
157
void bear::engine::strip_effect::set_opacity( double o )
 
158
{
 
159
  if ( o < 0 )
 
160
    o = 0;
 
161
  else if ( o > 1 )
 
162
    o = 1;
 
163
 
 
164
  m_opacity = o;
 
165
} // strip_effect::set_opacity()
 
166
 
 
167
/*----------------------------------------------------------------------------*/
 
168
/**
 
169
 * \brief Set the height of the strips.
 
170
 * \param h The height of the strips.
 
171
 */
 
172
void bear::engine::strip_effect::set_strip_height( visual::coordinate_type h )
 
173
{
 
174
  m_height = h;
 
175
} // strip_effect::set_strip_height()