2
// C++ Implementation: Position2DAdapter
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2007
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.
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.
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.//
27
#include "Position2DAdapter.h"
28
#include <wfmath/vector.h>
29
#include <wfmath/atlasconv.h>
39
Position2DAdapter::Position2DAdapter(const ::Atlas::Message::Element& element, CEGUI::Window* xWindow, CEGUI::Window* yWindow)
40
: AdapterBase(element), mXWindow(xWindow), mYWindow(yWindow)
43
addGuiEventConnection(mXWindow->subscribeEvent(CEGUI::Window::EventTextChanged, CEGUI::Event::Subscriber(&Position2DAdapter::window_TextChanged, this)));
46
addGuiEventConnection(mYWindow->subscribeEvent(CEGUI::Window::EventTextChanged, CEGUI::Event::Subscriber(&Position2DAdapter::window_TextChanged, this)));
48
updateGui(mOriginalElement);
52
Position2DAdapter::~Position2DAdapter()
56
void Position2DAdapter::updateGui(const ::Atlas::Message::Element& element)
58
AdapterSelfUpdateContext context(*this);
59
WFMath::Vector<2> vector(element);
60
// axisBox.fromAtlas(element.asList());
62
mXWindow->setText(toString(vector.x()));
65
mYWindow->setText(toString(vector.y()));
69
bool Position2DAdapter::window_TextChanged(const CEGUI::EventArgs& e)
72
EventValueChanged.emit();
77
void Position2DAdapter::fillElementFromGui()
79
WFMath::Vector<2> vector;
81
vector.x() = atof(mXWindow->getText().c_str());
84
vector.y() = atof(mYWindow->getText().c_str());
86
mEditedElement = vector.toAtlas();
89
bool Position2DAdapter::_hasChanges()
91
WFMath::Vector<2> originalValue;
92
originalValue.fromAtlas(mOriginalElement);
93
WFMath::Vector<2> newValue;
94
newValue.fromAtlas(getValue());
95
return originalValue != newValue;