qvolray

diff src/ui_maingl.cc @ 27:011ac823600c

broken up the OpenGL code to multiple source files (untested)
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Apr 2012 06:37:31 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/ui_maingl.cc	Sat Apr 14 06:37:31 2012 +0300
     1.3 @@ -0,0 +1,71 @@
     1.4 +#include <QtGui>
     1.5 +#include "ui_maingl.h"
     1.6 +#include "volray.h"
     1.7 +
     1.8 +MainGLView::MainGLView()
     1.9 +	: QGLWidget(QGLFormat(QGL::DoubleBuffer), 0)
    1.10 +{
    1.11 +}
    1.12 +
    1.13 +QSize MainGLView::minimumSizeHint() const
    1.14 +{
    1.15 +	return QSize(320, 200);
    1.16 +}
    1.17 +
    1.18 +QSize MainGLView::sizeHint() const
    1.19 +{
    1.20 +	return QSize(1280, 800);
    1.21 +}
    1.22 +
    1.23 +void MainGLView::initializeGL()
    1.24 +{
    1.25 +	if(!volray_init()) {
    1.26 +		exit(0);
    1.27 +	}
    1.28 +}
    1.29 +
    1.30 +void MainGLView::resizeGL(int xsz, int ysz)
    1.31 +{
    1.32 +	volray_resize(xsz, ysz);
    1.33 +}
    1.34 +
    1.35 +void MainGLView::paintGL()
    1.36 +{
    1.37 +	volray_draw();
    1.38 +}
    1.39 +
    1.40 +static int button_number(Qt::MouseButton bn)
    1.41 +{
    1.42 +	switch(bn) {
    1.43 +	case Qt::LeftButton:
    1.44 +		return 0;
    1.45 +	case Qt::MidButton:
    1.46 +		return 1;
    1.47 +	case Qt::RightButton:
    1.48 +		return 2;
    1.49 +	default:
    1.50 +		break;
    1.51 +	}
    1.52 +	return -1;
    1.53 +}
    1.54 +
    1.55 +void MainGLView::mousePressEvent(QMouseEvent *ev)
    1.56 +{
    1.57 +	int bn = button_number(ev->button());
    1.58 +	if(bn >= 0) {
    1.59 +		volray_mouse(bn, 1, ev->x(), ev->y());
    1.60 +	}
    1.61 +}
    1.62 +
    1.63 +void MainGLView::mouseReleaseEvent(QMouseEvent *ev)
    1.64 +{
    1.65 +	int bn = button_number(ev->button());
    1.66 +	if(bn >= 0) {
    1.67 +		volray_mouse(bn, 0, ev->x(), ev->y());
    1.68 +	}
    1.69 +}
    1.70 +
    1.71 +void MainGLView::mouseMoveEvent(QMouseEvent *ev)
    1.72 +{
    1.73 +	volray_motion(ev->x(), ev->y());
    1.74 +}