From e10c0a7602c612993e6b99348bab507b7def0881 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 25 Feb 2012 16:56:25 +0000 Subject: Add entity manipulator widget, added support for editing entity angles. --- src/manipulator.cc | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/manipulator.cc (limited to 'src/manipulator.cc') 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 +#include +#include +#include + +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 -- cgit v1.2.3