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

« back to all changes in this revision

Viewing changes to bear-engine/lib/src/generic_items/code/camera_toggle.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 camera_toggle.cpp
 
26
 * \brief Implementation of the bear::camera_toggle class.
 
27
 * \author Julien Jorge
 
28
 */
 
29
#include "generic_items/camera_toggle.hpp"
 
30
 
 
31
#include "engine/level.hpp"
 
32
#include "generic_items/camera.hpp"
 
33
 
 
34
BASE_ITEM_EXPORT( camera_toggle, bear )
 
35
 
 
36
/*----------------------------------------------------------------------------*/
 
37
/**
 
38
 * \brief Constructor.
 
39
 */
 
40
bear::camera_toggle::camera_toggle()
 
41
  : m_starting_smooth_delay(0), m_ending_smooth_delay(0), m_camera(NULL)
 
42
{
 
43
  set_can_move_items(false);
 
44
  set_phantom(true);
 
45
  set_artificial(true);
 
46
} // camera_toggle::camera_toggle()
 
47
 
 
48
/*----------------------------------------------------------------------------*/
 
49
/**
 
50
 * \brief Set a field of type \c <item>.
 
51
 * \param name The name of the field.
 
52
 * \param value The new value of the field.
 
53
 * \return false if the field "name" is unknow, true otherwise.
 
54
 */
 
55
bool bear::camera_toggle::set_item_field
 
56
( const std::string& name, engine::base_item* value )
 
57
{
 
58
  bool ok = true;
 
59
 
 
60
  if (name == "camera_toggle.camera")
 
61
    m_camera = value;
 
62
  else
 
63
    ok = super::set_item_field(name, value);
 
64
 
 
65
  return ok;
 
66
} // camera_toggle::set_item_field()
 
67
 
 
68
/*----------------------------------------------------------------------------*/
 
69
/**
 
70
 * \brief Set a field of type \c <real>.
 
71
 * \param name The name of the field.
 
72
 * \param value The new value of the field.
 
73
 * \return false if the field "name" is unknow, true otherwise.
 
74
 */
 
75
bool bear::camera_toggle::set_real_field
 
76
( const std::string& name, double value )
 
77
{
 
78
  bool ok = true;
 
79
 
 
80
  if (name == "camera_toggle.starting_transition_duration")
 
81
    m_starting_smooth_delay = value;
 
82
  else  if (name == "camera_toggle.ending_transition_duration")
 
83
    m_ending_smooth_delay = value;
 
84
  else
 
85
    ok = super::set_real_field(name,value);
 
86
 
 
87
  return ok;
 
88
} // camera_toggle::set_real_field()
 
89
 
 
90
/*----------------------------------------------------------------------------*/
 
91
/**
 
92
 * \brief Tell if the item is well initialized.
 
93
 */
 
94
bool bear::camera_toggle::is_valid() const
 
95
{
 
96
  // We allow the camera to be NULL only if the toggle has been toggled on, in
 
97
  // which case he can have taken the NULL camera of the level.
 
98
  return ((m_camera != (camera*)NULL) || is_on() )
 
99
    && (m_starting_smooth_delay >= 0)
 
100
    && (m_ending_smooth_delay >= 0) && super::is_valid();
 
101
} // camera_toggle::is_valid()
 
102
 
 
103
/*----------------------------------------------------------------------------*/
 
104
/**
 
105
 * \brief Initialise the item in its off state.
 
106
 */
 
107
void bear::camera_toggle::build_off()
 
108
{
 
109
  // nothing to do
 
110
} // camera_toggle::build_off()
 
111
 
 
112
/*----------------------------------------------------------------------------*/
 
113
/**
 
114
 * \brief Activate the camera.
 
115
 * \param activator (ignored) The item that activates the toggle, if any.
 
116
 */
 
117
void bear::camera_toggle::on_toggle_on( engine::base_item* activator )
 
118
{
 
119
  switch_camera();
 
120
} // camera_toggle::on_toggle_on()
 
121
 
 
122
/*----------------------------------------------------------------------------*/
 
123
/**
 
124
 * \brief Restore the old camera.
 
125
 * \param activator (ignored) The item that activates the toggle, if any.
 
126
 */
 
127
void bear::camera_toggle::on_toggle_off( engine::base_item* activator )
 
128
{
 
129
  switch_camera();
 
130
} // camera_toggle::on_toggle_off()
 
131
 
 
132
/*----------------------------------------------------------------------------*/
 
133
/**
 
134
 * \brief Switch the camera of the level.
 
135
 */
 
136
void bear::camera_toggle::switch_camera()
 
137
{
 
138
  handle_type old_cam = get_level().get_camera();
 
139
 
 
140
  if ( m_camera != (camera*)NULL )
 
141
    {
 
142
      if ( is_on() )
 
143
        {
 
144
          if (m_starting_smooth_delay == 0)
 
145
            m_camera->activate();
 
146
          else
 
147
            m_camera->smooth_activate(m_starting_smooth_delay);
 
148
        }
 
149
      else
 
150
        {
 
151
          if (m_ending_smooth_delay == 0)
 
152
            m_camera->activate();
 
153
          else
 
154
            m_camera->smooth_activate(m_ending_smooth_delay);
 
155
        }
 
156
    }
 
157
 
 
158
  m_camera = old_cam;
 
159
} // camera_toggle::switch_camera()