Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 33585a9ddd1f0d27dfdf04ec223f8cfa9ffd16e9 (plain)
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
/*
   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