X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcanvas.cpp;h=4c31c6c8896efab5eeb25986d64a6fe782648848;hb=2692ba4d0e192b4c481b89b2f180b2b924853720;hp=39081b07554366626e61bf7185117f5f61994e32;hpb=a960f8b2a8e7b20f80ec7294e87f555151d35557;p=fstl diff --git a/src/canvas.cpp b/src/canvas.cpp index 39081b0..4c31c6c 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -10,7 +10,7 @@ Canvas::Canvas(const QGLFormat& format, QWidget *parent) : QGLWidget(format, parent), mesh(NULL), - scale(1), tilt(90), yaw(0) + scale(1), tilt(90), yaw(0), status(" ") { // Nothing to do here } @@ -35,6 +35,12 @@ void Canvas::load_mesh(Mesh* m) delete m; } +void Canvas::set_status(const QString &s) +{ + status = s; + update(); +} + void Canvas::initializeGL() { mesh_shader.addShaderFromSourceFile(QGLShader::Vertex, ":/gl/mesh.vert"); @@ -42,19 +48,27 @@ void Canvas::initializeGL() mesh_shader.link(); backdrop = new Backdrop(); - - glClearColor(0.0, 0.0, 0.0, 0.0); - glEnable(GL_DEPTH_TEST); } -void Canvas::paintGL() +void Canvas::paintEvent(QPaintEvent *event) { + Q_UNUSED(event); + + glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glEnable(GL_DEPTH_TEST); backdrop->draw(); if (mesh) draw_mesh(); + + if (status.isNull()) return; + + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.drawText(10, height() - 10, status); } + void Canvas::draw_mesh() { mesh_shader.bind(); @@ -94,11 +108,11 @@ QMatrix4x4 Canvas::view_matrix() const QMatrix4x4 m; if (width() > height()) { - m.scale(height() / float(width()), 1, 0.5); + m.scale(-height() / float(width()), 1, 0.5); } else { - m.scale(1, width() / float(height()), 0.5); + m.scale(-1, width() / float(height()), 0.5); } return m; } @@ -126,7 +140,7 @@ void Canvas::mouseMoveEvent(QMouseEvent* event) { auto p = event->pos(); auto d = p - mouse_pos; - yaw = fmod(yaw + d.x(), 360); + yaw = fmod(yaw - d.x(), 360); tilt = fmax(0, fmin(180, tilt - d.y())); mouse_pos = p; update();