1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
/*!
@file
@author Albert Semenov
@date 01/2009
*/
#ifndef BASE_GRAPH_NODE_H_
#define BASE_GRAPH_NODE_H_
#include <MyGUI.h>
#include "BaseGraphConnection.h"
#include "IGraphController.h"
namespace wraps
{
class BaseGraphNode :
public BaseLayout
{
public:
BaseGraphNode(const std::string& _layout) :
BaseLayout("", nullptr),
mLayout(_layout),
mView(nullptr)
{
}
//
EnumeratorConnection getConnectionEnumerator() const
{
return EnumeratorConnection(mListConnection);
}
bool isAnyConnection() const
{
EnumeratorConnection point = getConnectionEnumerator();
while (point.next())
{
if (point->isAnyConnection())
return true;
}
return false;
}
BaseGraphConnection* getConnectionByName(const std::string& _name, const std::string& _type = "")
{
EnumeratorConnection point = getConnectionEnumerator();
while (point.next())
{
if (point->getName() == _name && (_type.empty() || point->getType() == _type))
{
return point.current();
}
}
return nullptr;
}
const MyGUI::IntCoord& getCoord()
{
return mMainWidget->getCoord();
}
void setCoord(const MyGUI::IntCoord& _coord)
{
mMainWidget->setCoord(_coord);
mView->changePosition(this);
}
MyGUI::IntPoint getPosition()
{
return mMainWidget->getPosition();
}
void setPosition(const MyGUI::IntPoint& _point)
{
mMainWidget->setPosition(_point);
mView->changePosition(this);
}
const MyGUI::IntPoint& getAbsolutePosition()
{
return mMainWidget->getAbsolutePosition();
}
void setAbsolutePosition(const MyGUI::IntPoint& _point)
{
setPosition(MyGUI::IntPoint(_point.left - mMainWidget->getParent()->getAbsoluteLeft(), _point.top - mMainWidget->getParent()->getAbsoluteTop()));
}
/*internal:*/
void _initialise(MyGUI::Widget* _parent, IGraphController* _view)
{
mView = _view;
if ( ! mLayout.empty())
{
BaseLayout::initialise(mLayout, _parent);
}
initialise();
MyGUI::Window* window = mMainWidget->castType<MyGUI::Window>(false);
if (window != nullptr)
{
window->eventWindowChangeCoord += MyGUI::newDelegate(this, &BaseGraphNode::notifyWindowChangeCoord);
window->eventWindowButtonPressed += MyGUI::newDelegate(this, &BaseGraphNode::notifyWindowButtonPressed);
}
//
mMainWidget->setWidgetStyle(MyGUI::WidgetStyle::Overlapped);
}
void _shutdown()
{
BaseLayout::shutdown();
shutdown();
}
protected:
virtual void initialise() = 0;
virtual void shutdown() = 0;
void notifyWindowChangeCoord(MyGUI::Window* _sender)
{
MyGUI::IntCoord coord = _sender->getCoord();
if ((coord.left < 0) || (coord.top < 0))
{
if (coord.left < 0) coord.left = 0;
if (coord.top < 0) coord.top = 0;
_sender->setCoord(coord);
}
mView->changePosition(this);
}
void notifyWindowButtonPressed(MyGUI::Window* _sender, const std::string& _name)
{
if (_name == "close")
mView->close(this);
}
template <typename T>
void assignBase(T * & _widget, const std::string& _name, bool _throw = true)
{
BaseLayout::assignBase<T>(_widget, _name, _throw);
mListConnection.push_back(_widget);
addConnection(_widget);
}
private:
void addConnection(BaseGraphConnection* _connection)
{
_connection->_setOwnerNode(this);
_connection->_getMainWidget()->eventMouseButtonPressed += MyGUI::newDelegate(this, &BaseGraphNode::notifyMouseButtonPressed);
_connection->_getMainWidget()->eventMouseButtonReleased += MyGUI::newDelegate(this, &BaseGraphNode::notifyMouseButtonReleased);
_connection->_getMainWidget()->eventMouseDrag += MyGUI::newDelegate(this, &BaseGraphNode::notifyMouseDrag);
_connection->_getMainWidget()->setUserData(_connection);
}
void notifyMouseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
{
if (_id == MyGUI::MouseButton::Left)
mView->startDrag(*_sender->getUserData<BaseGraphConnection*>());
}
void notifyMouseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
{
mView->stopDrag(*_sender->getUserData<BaseGraphConnection*>());
}
void notifyMouseDrag(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
{
if (_id == MyGUI::MouseButton::Left)
mView->updateDrag(*_sender->getUserData<BaseGraphConnection*>());
}
private:
std::string mLayout;
VectorConnection mListConnection;
IGraphController* mView;
};
} // namespace wraps
#endif // BASE_GRAPH_NODE_H_
|