2
* Copyright Staffan Gimåker 2008-2009.
6
* This file is part of peekabot.
8
* peekabot is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* peekabot is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "ObjectEntityProxy.hh"
23
#include "Renderer.hh"
24
#include "../SceneAction.hh"
25
#include "../Scene.hh"
26
#include "../ObjectEntity.hh"
29
using namespace peekabot;
30
using namespace peekabot::renderer;
31
using namespace peekabot::renderer::api;
34
ObjectEntityProxy::ObjectEntityProxy(Renderer &renderer)
35
: EntityProxy(renderer)
40
void ObjectEntityProxy::set_transformation(const Matrix4f &mtow)
42
class SetTransformation : public SceneAction
45
SetTransformation(EntityID id, const Matrix4f &mtow)
46
: m_id(id), m_mtow(mtow) {}
48
virtual void execute(SceneAction::Context &context)
50
context.scene().get_entity<ObjectEntity>(
51
m_id)->set_transformation(m_mtow);
56
const Matrix4f m_mtow;
59
dispatch(new SetTransformation(entity_id(), mtow));
63
void ObjectEntityProxy::set_color(const RGBColor &color)
65
class SetColor : public SceneAction
68
SetColor(EntityID id, const RGBColor &color)
69
: m_id(id), m_color(color) {}
71
virtual void execute(SceneAction::Context &context)
73
context.scene().get_entity<ObjectEntity>(
74
m_id)->set_color(m_color);
79
const RGBColor m_color;
82
dispatch(new SetColor(entity_id(), color));
86
void ObjectEntityProxy::set_opacity(float alpha)
88
class SetOpacity : public SceneAction
91
SetOpacity(EntityID id, float alpha) : m_id(id), m_alpha(alpha) {}
93
virtual void execute(SceneAction::Context &context)
95
context.scene().get_entity<ObjectEntity>(
96
m_id)->set_opacity(m_alpha);
104
dispatch(new SetOpacity(entity_id(), alpha));
108
void ObjectEntityProxy::set_layer(uint32_t layer)
110
class SetLayer : public SceneAction
113
SetLayer(EntityID id, uint32_t layer) : m_id(id), m_layer(layer) {}
115
virtual void execute(SceneAction::Context &context)
117
context.scene().get_entity<ObjectEntity>(m_id)->set_layer(m_layer);
122
const uint32_t m_layer;
125
dispatch(new SetLayer(entity_id(), layer));
129
void ObjectEntityProxy::set_name(uint32_t name)
131
class SetName : public SceneAction
134
SetName(EntityID id, uint32_t name) : m_id(id), m_name(name) {}
136
virtual void execute(SceneAction::Context &context)
138
context.scene().get_entity<ObjectEntity>(m_id)->set_name(m_name);
143
const uint32_t m_name;
146
dispatch(new SetName(entity_id(), name));
150
void ObjectEntityProxy::set_visibility(bool visible)
152
class SetVisibility : public SceneAction
155
SetVisibility(EntityID id, bool visible) :
156
m_id(id), m_visible(visible) {}
158
virtual void execute(SceneAction::Context &context)
160
context.scene().get_entity<ObjectEntity>(
161
m_id)->set_visibility(m_visible);
166
const bool m_visible;
169
dispatch(new SetVisibility(entity_id(), visible));
173
void ObjectEntityProxy::set_selected(bool is_selected)
175
class SetSelected : public SceneAction
178
SetSelected(EntityID id, bool is_selected)
179
: m_id(id), m_is_selected(is_selected) {}
181
virtual void execute(SceneAction::Context &context)
183
context.scene().get_entity<ObjectEntity>(
184
m_id)->set_selected(m_is_selected);
189
const bool m_is_selected;
192
dispatch(new SetSelected(entity_id(), is_selected));
196
void ObjectEntityProxy::set_has_selected_ancestor(bool has_selected_ancestor)
198
class SetHasSelectedAncestor : public SceneAction
201
SetHasSelectedAncestor(EntityID id, bool has_selected_ancestor)
202
: m_id(id), m_has_selected_ancestor(has_selected_ancestor) {}
204
virtual void execute(SceneAction::Context &context)
206
context.scene().get_entity<ObjectEntity>(
207
m_id)->set_has_selected_ancestor(m_has_selected_ancestor);
212
const bool m_has_selected_ancestor;
215
dispatch(new SetHasSelectedAncestor(entity_id(), has_selected_ancestor));
219
void ObjectEntityProxy::set_parent(EntityID parent_id)
221
class SetParent : public SceneAction
224
SetParent(EntityID id, EntityID parent_id)
225
: m_id(id), m_parent_id(parent_id) {}
227
virtual void execute(SceneAction::Context &context)
229
context.scene().get_entity<ObjectEntity>(m_id)->set_parent(
230
context.scene().get_entity<ObjectEntity>(m_parent_id));
234
const EntityID m_id, m_parent_id;
237
dispatch(new SetParent(entity_id(), parent_id));
241
void ObjectEntityProxy::set_parent(const ObjectEntityProxy &e)
243
set_parent(e.entity_id());