qvolray

annotate src/ui_maingl.cc @ 36:70b937008134

demo :)
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 15 Apr 2012 07:19:01 +0300
parents
children
rev   line source
nuclear@27 1 #include <QtGui>
nuclear@27 2 #include "ui_maingl.h"
nuclear@27 3 #include "volray.h"
nuclear@27 4
nuclear@27 5 MainGLView::MainGLView()
nuclear@27 6 : QGLWidget(QGLFormat(QGL::DoubleBuffer), 0)
nuclear@27 7 {
nuclear@27 8 }
nuclear@27 9
nuclear@27 10 QSize MainGLView::minimumSizeHint() const
nuclear@27 11 {
nuclear@27 12 return QSize(320, 200);
nuclear@27 13 }
nuclear@27 14
nuclear@27 15 QSize MainGLView::sizeHint() const
nuclear@27 16 {
nuclear@27 17 return QSize(1280, 800);
nuclear@27 18 }
nuclear@27 19
nuclear@27 20 void MainGLView::initializeGL()
nuclear@27 21 {
nuclear@27 22 if(!volray_init()) {
nuclear@27 23 exit(0);
nuclear@27 24 }
nuclear@27 25 }
nuclear@27 26
nuclear@27 27 void MainGLView::resizeGL(int xsz, int ysz)
nuclear@27 28 {
nuclear@27 29 volray_resize(xsz, ysz);
nuclear@27 30 }
nuclear@27 31
nuclear@27 32 void MainGLView::paintGL()
nuclear@27 33 {
nuclear@27 34 volray_draw();
nuclear@27 35 }
nuclear@27 36
nuclear@27 37 static int button_number(Qt::MouseButton bn)
nuclear@27 38 {
nuclear@27 39 switch(bn) {
nuclear@27 40 case Qt::LeftButton:
nuclear@27 41 return 0;
nuclear@27 42 case Qt::MidButton:
nuclear@27 43 return 1;
nuclear@27 44 case Qt::RightButton:
nuclear@27 45 return 2;
nuclear@27 46 default:
nuclear@27 47 break;
nuclear@27 48 }
nuclear@27 49 return -1;
nuclear@27 50 }
nuclear@27 51
nuclear@27 52 void MainGLView::mousePressEvent(QMouseEvent *ev)
nuclear@27 53 {
nuclear@27 54 int bn = button_number(ev->button());
nuclear@27 55 if(bn >= 0) {
nuclear@27 56 volray_mouse(bn, 1, ev->x(), ev->y());
nuclear@27 57 }
nuclear@27 58 }
nuclear@27 59
nuclear@27 60 void MainGLView::mouseReleaseEvent(QMouseEvent *ev)
nuclear@27 61 {
nuclear@27 62 int bn = button_number(ev->button());
nuclear@27 63 if(bn >= 0) {
nuclear@27 64 volray_mouse(bn, 0, ev->x(), ev->y());
nuclear@27 65 }
nuclear@27 66 }
nuclear@27 67
nuclear@27 68 void MainGLView::mouseMoveEvent(QMouseEvent *ev)
nuclear@27 69 {
nuclear@27 70 volray_motion(ev->x(), ev->y());
nuclear@27 71 }