~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/widgets/adapters/atlas/Position2DAdapter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Implementation: Position2DAdapter
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2007
 
8
//
 
9
// This program is free software; you can redistribute it and/or modify
 
10
// it under the terms of the GNU General Public License as published by
 
11
// the Free Software Foundation; either version 2 of the License, or
 
12
// (at your option) any later version.
 
13
// 
 
14
// This program is distributed in the hope that it will be useful,
 
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
// GNU General Public License for more details.
 
18
// 
 
19
// You should have received a copy of the GNU General Public License
 
20
// along with this program; if not, write to the Free Software
 
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
 
22
//
 
23
#ifdef HAVE_CONFIG_H
 
24
#include "config.h"
 
25
#endif
 
26
 
 
27
#include "Position2DAdapter.h"
 
28
#include <wfmath/vector.h>
 
29
#include <wfmath/atlasconv.h>
 
30
 
 
31
namespace EmberOgre {
 
32
 
 
33
namespace Gui {
 
34
 
 
35
namespace Adapters {
 
36
 
 
37
namespace Atlas {
 
38
 
 
39
Position2DAdapter::Position2DAdapter(const ::Atlas::Message::Element& element, CEGUI::Window* xWindow, CEGUI::Window* yWindow)
 
40
: AdapterBase(element), mXWindow(xWindow), mYWindow(yWindow)
 
41
{
 
42
        if (mXWindow) {
 
43
                addGuiEventConnection(mXWindow->subscribeEvent(CEGUI::Window::EventTextChanged, CEGUI::Event::Subscriber(&Position2DAdapter::window_TextChanged, this))); 
 
44
        }
 
45
        if (mYWindow) {
 
46
                addGuiEventConnection(mYWindow->subscribeEvent(CEGUI::Window::EventTextChanged, CEGUI::Event::Subscriber(&Position2DAdapter::window_TextChanged, this))); 
 
47
        }
 
48
        updateGui(mOriginalElement);
 
49
}
 
50
 
 
51
 
 
52
Position2DAdapter::~Position2DAdapter()
 
53
{
 
54
}
 
55
 
 
56
void Position2DAdapter::updateGui(const ::Atlas::Message::Element& element)
 
57
{
 
58
        AdapterSelfUpdateContext context(*this);
 
59
        WFMath::Vector<2> vector(element);
 
60
//      axisBox.fromAtlas(element.asList());
 
61
        if (mXWindow) {
 
62
                mXWindow->setText(toString(vector.x())); 
 
63
        }
 
64
        if (mYWindow) {
 
65
                mYWindow->setText(toString(vector.y())); 
 
66
        }
 
67
}
 
68
 
 
69
bool Position2DAdapter::window_TextChanged(const CEGUI::EventArgs& e)
 
70
{
 
71
        if (!mSelfUpdate) {
 
72
                EventValueChanged.emit();
 
73
        }
 
74
        return true;
 
75
}
 
76
 
 
77
void Position2DAdapter::fillElementFromGui()
 
78
{
 
79
        WFMath::Vector<2> vector;
 
80
        if (mXWindow) {
 
81
                vector.x() = atof(mXWindow->getText().c_str()); 
 
82
        }
 
83
        if (mYWindow) {
 
84
                vector.y() = atof(mYWindow->getText().c_str()); 
 
85
        }
 
86
        mEditedElement = vector.toAtlas();
 
87
}
 
88
 
 
89
bool Position2DAdapter::_hasChanges()
 
90
{
 
91
        WFMath::Vector<2> originalValue;
 
92
        originalValue.fromAtlas(mOriginalElement);
 
93
        WFMath::Vector<2> newValue;
 
94
        newValue.fromAtlas(getValue());
 
95
        return originalValue != newValue;
 
96
}
 
97
}
 
98
 
 
99
}
 
100
 
 
101
}
 
102
 
 
103
}