src/canvas.cpp

changeset 1436
241d3e452b32
parent 1405
d2bf2e59a3ef
child 1437
1a77c6156db7
equal deleted inserted replaced
1435:b8dc3620e5db 1436:241d3e452b32
23 #include "primitives.h" 23 #include "primitives.h"
24 #include "algorithms/geometry.h" 24 #include "algorithms/geometry.h"
25 #include "generics/ring.h" 25 #include "generics/ring.h"
26 26
27 Canvas::Canvas(LDDocument* document, QWidget* parent) : 27 Canvas::Canvas(LDDocument* document, QWidget* parent) :
28 GLRenderer {document, parent}, 28 gl::Renderer {document, parent},
29 m_document {*document}, 29 m_document {*document},
30 m_currentEditMode {AbstractEditMode::createByType (this, EditModeType::Select)} {} 30 m_currentEditMode {AbstractEditMode::createByType (this, EditModeType::Select)} {}
31 31
32 Canvas::~Canvas() 32 Canvas::~Canvas()
33 { 33 {
34 delete m_currentEditMode; 34 delete m_currentEditMode;
35 } 35 }
36 36
37 void Canvas::overpaint(QPainter& painter) 37 void Canvas::overpaint(QPainter& painter)
38 { 38 {
39 GLRenderer::overpaint(painter); 39 gl::Renderer::overpaint(painter);
40 QFontMetrics metrics {QFont {}}; 40 QFontMetrics metrics {QFont {}};
41 41
42 if (camera() != Camera::Free) 42 if (camera() != gl::FreeCamera)
43 { 43 {
44 // Paint the coordinates onto the screen. 44 // Paint the coordinates onto the screen.
45 Vertex idealized = currentCamera().idealize(m_position3D); 45 Vertex idealized = currentCamera().idealize(m_position3D);
46 QString text = format(tr("X: %1, Y: %2, Z: %3, %4"), m_position3D[X], m_position3D[Y], m_position3D[Z], 46 QString text = format(tr("X: %1, Y: %2, Z: %3, %4"), m_position3D[X], m_position3D[Y], m_position3D[Z],
47 idealized.toString(true)); 47 idealized.toString(true));
184 } 184 }
185 185
186 glEnd(); 186 glEnd();
187 glDisable(GL_LINE_STIPPLE); 187 glDisable(GL_LINE_STIPPLE);
188 188
189 if (this->camera() < Camera::Free) 189 if (this->camera() < gl::FreeCamera)
190 { 190 {
191 GLfloat cullz = this->cullValues[static_cast<int>(this->camera())]; 191 GLfloat cullz = this->cullValues[static_cast<int>(this->camera())];
192 QMatrix4x4 matrix = { 192 QMatrix4x4 matrix = {
193 1, 0, 0, cullz, 193 1, 0, 0, cullz,
194 0, 1, 0, 0, 194 0, 1, 0, 0,
211 211
212 delete m_currentEditMode; 212 delete m_currentEditMode;
213 m_currentEditMode = AbstractEditMode::createByType(this, a); 213 m_currentEditMode = AbstractEditMode::createByType(this, a);
214 214
215 // If we cannot use the free camera, use the top one instead. 215 // If we cannot use the free camera, use the top one instead.
216 if (camera() == Camera::Free and not m_currentEditMode->allowFreeCamera()) 216 if (camera() == gl::FreeCamera and not m_currentEditMode->allowFreeCamera())
217 setCamera(Camera::Top); 217 setCamera(gl::TopCamera);
218 218
219 m_window->updateEditModeActions(); 219 m_window->updateEditModeActions();
220 update(); 220 update();
221 } 221 }
222 222
257 } 257 }
258 258
259 void Canvas::keyReleaseEvent(QKeyEvent* event) 259 void Canvas::keyReleaseEvent(QKeyEvent* event)
260 { 260 {
261 m_currentEditMode->keyReleased(event); 261 m_currentEditMode->keyReleased(event);
262 GLRenderer::keyReleaseEvent(event); 262 gl::Renderer::keyReleaseEvent(event);
263 } 263 }
264 264
265 void Canvas::mouseMoveEvent(QMouseEvent* event) 265 void Canvas::mouseMoveEvent(QMouseEvent* event)
266 { 266 {
267 // Calculate 3d position of the cursor 267 // Calculate 3d position of the cursor
268 m_position3D = currentCamera().convert2dTo3d(mousePosition(), grid()); 268 m_position3D = currentCamera().convert2dTo3d(mousePosition(), grid());
269 269
270 if (not m_currentEditMode->mouseMoved(event)) 270 if (not m_currentEditMode->mouseMoved(event))
271 GLRenderer::mouseMoveEvent(event); 271 gl::Renderer::mouseMoveEvent(event);
272 } 272 }
273 273
274 void Canvas::mouseReleaseEvent(QMouseEvent *event) 274 void Canvas::mouseReleaseEvent(QMouseEvent *event)
275 { 275 {
276 AbstractEditMode::MouseEventData data; 276 AbstractEditMode::MouseEventData data;
277 data.ev = event; 277 data.ev = event;
278 data.mouseMoved = mouseHasMoved(); 278 data.mouseMoved = mouseHasMoved();
279 data.keymods = keyboardModifiers(); 279 data.keymods = keyboardModifiers();
280 data.releasedButtons = lastButtons() & ~event->buttons(); 280 data.releasedButtons = lastButtons() & ~event->buttons();
281 m_currentEditMode->mouseReleased(data); 281 m_currentEditMode->mouseReleased(data);
282 GLRenderer::mouseReleaseEvent(event); 282 gl::Renderer::mouseReleaseEvent(event);
283 } 283 }
284 284
285 void Canvas::mousePressEvent(QMouseEvent *event) 285 void Canvas::mousePressEvent(QMouseEvent *event)
286 { 286 {
287 if (m_currentEditMode->mousePressed(event)) 287 if (m_currentEditMode->mousePressed(event))
288 event->accept(); 288 event->accept();
289 289
290 GLRenderer::mousePressEvent(event); 290 gl::Renderer::mousePressEvent(event);
291 } 291 }
292 292
293 const Vertex& Canvas::position3D() const 293 const Vertex& Canvas::position3D() const
294 { 294 {
295 return m_position3D; 295 return m_position3D;
296 } 296 }
297 297
298 void Canvas::drawPoint(QPainter& painter, QPointF pos, QColor color) const 298 void Canvas::drawPoint(QPainter& painter, QPointF pos, QColor color) const
299 { 299 {
300 int pointSize = 8; 300 int pointSize = 8;
301 QPen pen = thinBorderPen; 301 QPen pen = gl::thinBorderPen;
302 pen.setWidth(1); 302 pen.setWidth(1);
303 painter.setPen(pen); 303 painter.setPen(pen);
304 painter.setBrush(color); 304 painter.setBrush(color);
305 painter.drawEllipse(pos.x() - pointSize / 2, pos.y() - pointSize / 2, pointSize, pointSize); 305 painter.drawEllipse(pos.x() - pointSize / 2, pos.y() - pointSize / 2, pointSize, pointSize);
306 } 306 }
316 painter.drawText (pos.x(), pos.y() - 8, pos3d.toString (true)); 316 painter.drawText (pos.x(), pos.y() - 8, pos3d.toString (true));
317 } 317 }
318 318
319 QPen Canvas::linePen() const 319 QPen Canvas::linePen() const
320 { 320 {
321 QPen linepen = thinBorderPen; 321 QPen linepen = gl::thinBorderPen;
322 linepen.setWidth(2); 322 linepen.setWidth(2);
323 linepen.setColor(luma(backgroundColor()) < 40 ? Qt::white : Qt::black); 323 linepen.setColor(luma(backgroundColor()) < 40 ? Qt::white : Qt::black);
324 return linepen; 324 return linepen;
325 } 325 }
326 326
372 */ 372 */
373 } 373 }
374 374
375 double Canvas::currentCullValue() const 375 double Canvas::currentCullValue() const
376 { 376 {
377 if (this->camera() < Camera::Free) 377 if (this->camera() < gl::FreeCamera)
378 return far - this->cullValues[static_cast<int>(this->camera())]; 378 return gl::far - this->cullValues[static_cast<int>(this->camera())];
379 else 379 else
380 return 0.0; 380 return 0.0;
381 } 381 }
382 382
383 void Canvas::setCullValue(double value) 383 void Canvas::setCullValue(double value)
384 { 384 {
385 if (this->camera() < Camera::Free) 385 if (this->camera() < gl::FreeCamera)
386 this->cullValues[static_cast<int>(this->camera())] = far - value; 386 this->cullValues[static_cast<int>(this->camera())] = gl::far - value;
387 } 387 }
388 388
389 void Canvas::clearCurrentCullValue() 389 void Canvas::clearCurrentCullValue()
390 { 390 {
391 if (this->camera() < Camera::Free) 391 if (this->camera() < gl::FreeCamera)
392 this->cullValues[static_cast<int>(this->camera())] = 0.0; 392 this->cullValues[static_cast<int>(this->camera())] = 0.0;
393 } 393 }

mercurial