# HG changeset patch # User John Tsiombikas # Date 1334374651 -10800 # Node ID 011ac823600ce885218e3687a5e6ce91f6b64833 # Parent f4cc61b5a3eb1e777556b373e549d1b95e74e66f broken up the OpenGL code to multiple source files (untested) diff -r f4cc61b5a3eb -r 011ac823600c .hgignore --- a/.hgignore Sat Apr 14 04:59:14 2012 +0300 +++ b/.hgignore Sat Apr 14 06:37:31 2012 +0300 @@ -12,3 +12,6 @@ \.pdb$ ^ipch \.sdf$ +^moc_.*\.cpp$ +^Makefile$ +^qvolray.app diff -r f4cc61b5a3eb -r 011ac823600c qvolray.pro --- a/qvolray.pro Sat Apr 14 04:59:14 2012 +0300 +++ b/qvolray.pro Sat Apr 14 06:37:31 2012 +0300 @@ -21,6 +21,16 @@ QMAKE_LIBDIR += /opt/local/lib } -# Input -HEADERS += src/sdr.h src/volray.h src/volume.h src/ui.h -SOURCES += src/main.cc src/sdr.c src/volray.cc src/volume.cc src/ui.cc src/demo.cc +# the moc needs to run for these headers +HEADERS = src/ui.h \ + src/ui_maingl.h \ + src/ui_sliceview.h + +SOURCES = src/main.cc \ + src/sdr.c \ + src/volray.cc \ + src/volume.cc \ + src/ui.cc \ + src/ui_maingl.cc \ + src/ui_sliceview.cc \ + src/demo.cc diff -r f4cc61b5a3eb -r 011ac823600c src/ui.cc --- a/src/ui.cc Sat Apr 14 04:59:14 2012 +0300 +++ b/src/ui.cc Sat Apr 14 06:37:31 2012 +0300 @@ -1,21 +1,18 @@ #include #include -#include #include #include "ui.h" static Volume *volume; -static GLView *maingl; -static std::vector glviews; +static MainGLView *maingl; MainWindow::MainWindow() { setWindowTitle("Volume Renderer"); // OpenGL view - maingl = new GLView; - glviews.push_back(maingl); + maingl = new MainGLView; setCentralWidget(maingl); // side-window @@ -68,8 +65,7 @@ { QGroupBox *groupbox = new QGroupBox("Volume slice"); { - GLView *slice_view = new GLView; - glviews.push_back(slice_view); + slice_view = new SliceGLView(maingl); QCheckBox *chk_clip = new QCheckBox("clip"); chk_clip->setChecked(false); @@ -112,72 +108,3 @@ { maingl->updateGL(); } - - -GLView::GLView(QWidget *parent) - : QGLWidget(QGLFormat(QGL::DoubleBuffer), parent) -{ -} - -QSize GLView::minimumSizeHint() const -{ - return QSize(320, 200); -} - -QSize GLView::sizeHint() const -{ - return QSize(1280, 800); -} - -void GLView::initializeGL() -{ - if(!volray_init()) { - exit(0); - } -} - -void GLView::resizeGL(int xsz, int ysz) -{ - volray_resize(xsz, ysz); -} - -void GLView::paintGL() -{ - volray_draw(); -} - -static int button_number(Qt::MouseButton bn) -{ - switch(bn) { - case Qt::LeftButton: - return 0; - case Qt::MidButton: - return 1; - case Qt::RightButton: - return 2; - default: - break; - } - return -1; -} - -void GLView::mousePressEvent(QMouseEvent *ev) -{ - int bn = button_number(ev->button()); - if(bn >= 0) { - volray_mouse(bn, 1, ev->x(), ev->y()); - } -} - -void GLView::mouseReleaseEvent(QMouseEvent *ev) -{ - int bn = button_number(ev->button()); - if(bn >= 0) { - volray_mouse(bn, 0, ev->x(), ev->y()); - } -} - -void GLView::mouseMoveEvent(QMouseEvent *ev) -{ - volray_motion(ev->x(), ev->y()); -} diff -r f4cc61b5a3eb -r 011ac823600c src/ui.h --- a/src/ui.h Sat Apr 14 04:59:14 2012 +0300 +++ b/src/ui.h Sat Apr 14 06:37:31 2012 +0300 @@ -4,6 +4,8 @@ #include #include #include "volray.h" +#include "ui_maingl.h" +#include "ui_sliceview.h" class SideWindow; diff -r f4cc61b5a3eb -r 011ac823600c src/ui_maingl.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ui_maingl.cc Sat Apr 14 06:37:31 2012 +0300 @@ -0,0 +1,71 @@ +#include +#include "ui_maingl.h" +#include "volray.h" + +MainGLView::MainGLView() + : QGLWidget(QGLFormat(QGL::DoubleBuffer), 0) +{ +} + +QSize MainGLView::minimumSizeHint() const +{ + return QSize(320, 200); +} + +QSize MainGLView::sizeHint() const +{ + return QSize(1280, 800); +} + +void MainGLView::initializeGL() +{ + if(!volray_init()) { + exit(0); + } +} + +void MainGLView::resizeGL(int xsz, int ysz) +{ + volray_resize(xsz, ysz); +} + +void MainGLView::paintGL() +{ + volray_draw(); +} + +static int button_number(Qt::MouseButton bn) +{ + switch(bn) { + case Qt::LeftButton: + return 0; + case Qt::MidButton: + return 1; + case Qt::RightButton: + return 2; + default: + break; + } + return -1; +} + +void MainGLView::mousePressEvent(QMouseEvent *ev) +{ + int bn = button_number(ev->button()); + if(bn >= 0) { + volray_mouse(bn, 1, ev->x(), ev->y()); + } +} + +void MainGLView::mouseReleaseEvent(QMouseEvent *ev) +{ + int bn = button_number(ev->button()); + if(bn >= 0) { + volray_mouse(bn, 0, ev->x(), ev->y()); + } +} + +void MainGLView::mouseMoveEvent(QMouseEvent *ev) +{ + volray_motion(ev->x(), ev->y()); +} diff -r f4cc61b5a3eb -r 011ac823600c src/ui_maingl.h --- a/src/ui_maingl.h Sat Apr 14 04:59:14 2012 +0300 +++ b/src/ui_maingl.h Sat Apr 14 06:37:31 2012 +0300 @@ -1,3 +1,6 @@ +#ifndef UI_MAINGL_H_ +#define UI_MAINGL_H_ + #include class MainGLView : public QGLWidget { @@ -18,3 +21,5 @@ QSize minimumSizeHint() const; QSize sizeHint() const; }; + +#endif // UI_MAINGL_H_ diff -r f4cc61b5a3eb -r 011ac823600c src/ui_sliceview.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ui_sliceview.cc Sat Apr 14 06:37:31 2012 +0300 @@ -0,0 +1,25 @@ +#include "ui_sliceview.h" + +SliceGLView::SliceGLView(QGLWidget *share_widget) + : QGLWidget(QGLFormat(QGL::DoubleBuffer), 0, share_widget) +{ +} + +QSize SliceGLView::minimumSizeHint() const +{ + return QSize(160, 160); +} + +void SliceGLView::initializeGL() +{ +} + +void SliceGLView::resizeGL(int xsz, int ysz) +{ + glViewport(0, 0, xsz, ysz); +} + +void SliceGLView::paintGL() +{ + glClear(GL_COLOR_BUFFER_BIT); +} diff -r f4cc61b5a3eb -r 011ac823600c src/ui_sliceview.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ui_sliceview.h Sat Apr 14 06:37:31 2012 +0300 @@ -0,0 +1,20 @@ +#ifndef UI_SLICEVIEW_H_ +#define UI_SLICEVIEW_H_ + +#include + +class SliceGLView : public QGLWidget { +private: + Q_OBJECT + + void initializeGL(); + void resizeGL(int xsz, int ysz); + void paintGL(); + +public: + SliceGLView(QGLWidget *share_widget = 0); + + QSize minimumSizeHint() const; +}; + +#endif // UI_SLICEVIEW_H_