forked from mapmapteam/mapmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DestinationGLCanvas.cpp
158 lines (140 loc) · 4.31 KB
/
DestinationGLCanvas.cpp
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
/*
* DestinationGLCanvas.cpp
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
* (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "DestinationGLCanvas.h"
#include "MainWindow.h"
DestinationGLCanvas::DestinationGLCanvas(MainWindow* mainWindow, QWidget* parent, const QGLWidget * shareWidget)
: MapperGLCanvas(mainWindow, parent, shareWidget),
_displayCrosshair(false),
_svg_test_signal(":/test-signal"),
_brush_test_signal(_svg_test_signal)
{
}
Shape* DestinationGLCanvas::getShapeFromMappingId(uid mappingId)
{
if (mappingId == NULL_UID)
return NULL;
else
return getMainWindow()->getMappingManager().getMappingById(mappingId)->getShape().get();
}
void DestinationGLCanvas::doDraw(QPainter* painter)
{
if (this->displayTestSignal())
{
glPushMatrix();
painter->save();
this->_drawTestSignal(painter);
painter->restore();
glPopMatrix();
return;
}
glPushMatrix();
// Draw the mappings.
QVector<Mapping::ptr> mappings = getMainWindow()->getMappingManager().getVisibleMappings();
for (QVector<Mapping::ptr>::const_iterator it = mappings.begin(); it != mappings.end(); ++it)
{
painter->save();
getMainWindow()->getMapperByMappingId((*it)->getId())->draw(painter);
painter->restore();
}
// Draw the controls of current mapping.
if (displayControls() &&
getMainWindow()->hasCurrentMapping() &&
getCurrentShape() != NULL)
{
painter->save();
const Mapper::ptr& mapper = getMainWindow()->getMapperByMappingId(getMainWindow()->getCurrentMappingId());
if (hasActiveVertex()) {
QList<int> selectedVertices;
selectedVertices.append(getActiveVertexIndex());
mapper->drawControls(painter, &selectedVertices);
}
else
{
mapper->drawControls(painter);
}
painter->restore();
}
glPopMatrix();
// Display crosshair cursor.
if (_displayCrosshair)
{
const QPoint& cursorPosition = this->mapFromGlobal(QCursor::pos());
const QRect& geo = geometry();
if (geo.contains(cursorPosition))
{
painter->setPen(MM::CONTROL_COLOR);
painter->drawLine(cursorPosition.x(), 0, cursorPosition.x(), geo.height());
painter->drawLine(0, cursorPosition.y(), geo.width(), cursorPosition.y());
}
}
}
void DestinationGLCanvas::_drawTestSignal(QPainter* painter)
{
const QRect& geo = geometry();
painter->setPen(MM::CONTROL_COLOR);
int height = geo.height();
int width = geo.width();
int rect_size = 10;
QColor color_0(191, 191, 191);
QColor color_1(128, 128, 128);
QBrush brush_0(color_0);
QBrush brush_1(color_1);
painter->setPen(Qt::NoPen);
for (int x = 0; x < width; x += rect_size)
{
for (int y = 0; y < height; y += rect_size)
{
if (((x + y) % 20) == 0)
{
painter->setBrush(brush_0);
} else {
painter->setBrush(brush_1);
}
painter->drawRect(x, y, rect_size, rect_size);
}
}
painter->fillRect(geo, this->_brush_test_signal);
}
void DestinationGLCanvas::resizeGL(int width, int height)
{
int side_length = width;
if (height < width)
{
side_length = height;
}
(void) side_length; // to get rid of warnings
// TODO: reload SVG with the new size
// TODO: _svg_test_signal.load(":/test-signal");
// TODO: _brush_test_signal(_svg_test_signal)
}
bool DestinationGLCanvas::eventFilter(QObject *target, QEvent *event)
{
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
setActiveVertexIndex(getMainWindow()->getOutputWindow()->getCanvas()->getActiveVertexIndex());
MapperGLCanvas::keyPressEvent(keyEvent);
return true;
}
else
{
return QObject::eventFilter(target, event);
}
}