diff options
author | Stijn Buys <ingar@osirion.org> | 2012-02-25 16:56:25 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2012-02-25 16:56:25 +0000 |
commit | e10c0a7602c612993e6b99348bab507b7def0881 (patch) | |
tree | 2d863e946024fc3560221bedcddb149b253b4918 /src/manipulator.cc | |
parent | 01f671303b75f3e4c683e3ff47b7ee120f0cda12 (diff) |
Add entity manipulator widget, added support for editing entity angles.
Diffstat (limited to 'src/manipulator.cc')
-rw-r--r-- | src/manipulator.cc | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/manipulator.cc b/src/manipulator.cc new file mode 100644 index 0000000..33585a9 --- /dev/null +++ b/src/manipulator.cc @@ -0,0 +1,59 @@ +/* + manipulator.cc + This file is part of the Project::OSiRiON world editor + and is distributed under the terms and conditions of + the GNU General Public License version 2 +*/ + +#include "manipulator.h" + +#include <QtGui> +#include <QPainter> +#include <QMouseEvent> +#include <QDebug> + +namespace editor +{ + +Manipulator::Manipulator(QWidget *parent) : QWidget(parent) +{ + manipulator_mode = None; + manipulator_yaw = 0; +} + +void Manipulator::setSize(const QWidget *widget) +{ + const int s = 16; + setGeometry( + widget->x() - s, + widget->y() -s, + widget->width() + 2 * s, + widget->height() + 2 * s + ); +} + +void Manipulator::paintEvent(QPaintEvent *event) +{ + if (mode() == None) + return; + + QColor green; + green.setRgb(0, 156, 0); + QPen pen(green, 1, Qt::SolidLine); + QPainter painter(this); + + painter.setPen(pen); + painter.drawEllipse(0, 0, width() - 1 , height() - 1); + + const int r = width() / 2; + const float dx = r * sin(manipulator_yaw * M_PI / 180.0f); + const float dy = r * cos(manipulator_yaw * M_PI / 180.0f); + painter.drawLine(width() /2, height() /2, width() /2 - dx, height() /2 - dy); +} + +void Manipulator::setProperties(const EntityProperties *properties) +{ + manipulator_yaw = properties->yaw(); +} + +} // namespace editor |