+ change API of GLPainter
This commit is contained in:
parent
8fb596221f
commit
621aebdbef
|
@ -207,7 +207,7 @@ void Flag::drawLine (View3DInventorViewer* v, int tox, int toy)
|
|||
if (false) fromx += width();
|
||||
|
||||
GLPainter p;
|
||||
p.begin(v);
|
||||
p.begin(v->getGLWidget());
|
||||
p.setDrawBuffer(GL_BACK);
|
||||
|
||||
// the line
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#ifndef _PreComp_
|
||||
#endif
|
||||
|
||||
#include <QGLWidget>
|
||||
#include "GLPainter.h"
|
||||
#include "View3DInventorViewer.h"
|
||||
#include <Base/Console.h>
|
||||
|
@ -43,19 +44,21 @@ GLPainter::~GLPainter()
|
|||
end();
|
||||
}
|
||||
|
||||
bool GLPainter::begin(View3DInventorViewer* v)
|
||||
bool GLPainter::begin(QPaintDevice * device)
|
||||
{
|
||||
if(viewer)
|
||||
if (viewer)
|
||||
return false;
|
||||
|
||||
viewer = v;
|
||||
viewer = dynamic_cast<QGLWidget*>(device);
|
||||
if (!viewer)
|
||||
return false;
|
||||
|
||||
// Make current context
|
||||
SbVec2s view = viewer->getSoRenderManager()->getSize();
|
||||
this->width = view[0];
|
||||
this->height = view[1];
|
||||
QSize view = viewer->size();
|
||||
this->width = view.width();
|
||||
this->height = view.height();
|
||||
|
||||
static_cast<QGLWidget*>(viewer->viewport())->makeCurrent();
|
||||
viewer->makeCurrent();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
|
@ -85,17 +88,17 @@ bool GLPainter::begin(View3DInventorViewer* v)
|
|||
|
||||
bool GLPainter::end()
|
||||
{
|
||||
if(!viewer)
|
||||
if (!viewer)
|
||||
return false;
|
||||
|
||||
glFlush();
|
||||
|
||||
if(this->logicOp) {
|
||||
if (this->logicOp) {
|
||||
this->logicOp = false;
|
||||
glDisable(GL_COLOR_LOGIC_OP);
|
||||
}
|
||||
|
||||
if(this->lineStipple) {
|
||||
if (this->lineStipple) {
|
||||
this->lineStipple = false;
|
||||
glDisable(GL_LINE_STIPPLE);
|
||||
}
|
||||
|
@ -166,41 +169,41 @@ void GLPainter::resetLineStipple()
|
|||
// Draw routines
|
||||
void GLPainter::drawRect(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
if(!viewer)
|
||||
if (!viewer)
|
||||
return;
|
||||
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glVertex3i(x1, this->height-y1, 0);
|
||||
glVertex3i(x2, this->height-y1, 0);
|
||||
glVertex3i(x2, this->height-y2, 0);
|
||||
glVertex3i(x1, this->height-y2, 0);
|
||||
glVertex3i(x1, this->height-y1, 0);
|
||||
glVertex3i(x2, this->height-y1, 0);
|
||||
glVertex3i(x2, this->height-y2, 0);
|
||||
glVertex3i(x1, this->height-y2, 0);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void GLPainter::drawLine(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
if(!viewer)
|
||||
if (!viewer)
|
||||
return;
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glVertex3i(x1, this->height-y1, 0);
|
||||
glVertex3i(x2, this->height-y2, 0);
|
||||
glVertex3i(x1, this->height-y1, 0);
|
||||
glVertex3i(x2, this->height-y2, 0);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void GLPainter::drawPoint(int x, int y)
|
||||
{
|
||||
if(!viewer)
|
||||
if (!viewer)
|
||||
return;
|
||||
|
||||
glBegin(GL_POINTS);
|
||||
glVertex3i(x, this->height-y, 0);
|
||||
glVertex3i(x, this->height-y, 0);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
|
||||
|
||||
Rubberband::Rubberband(Gui::View3DInventorViewer* v) : viewer(v)
|
||||
Rubberband::Rubberband(View3DInventorViewer* v) : viewer(v)
|
||||
{
|
||||
x_old = y_old = x_new = y_new = 0;
|
||||
working = false;
|
||||
|
@ -241,7 +244,6 @@ void Rubberband::setLineStipple(bool on)
|
|||
stipple = on;
|
||||
}
|
||||
|
||||
|
||||
void Rubberband::setColor(float r, float g, float b, float a)
|
||||
{
|
||||
rgb_a = a;
|
||||
|
@ -252,15 +254,13 @@ void Rubberband::setColor(float r, float g, float b, float a)
|
|||
|
||||
void Rubberband::paintGL()
|
||||
{
|
||||
if(!working)
|
||||
if (!working)
|
||||
return;
|
||||
|
||||
const SbViewportRegion vp = viewer->getSoRenderManager()->getViewportRegion();
|
||||
SbVec2s size = vp.getViewportSizePixels();
|
||||
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
|
||||
glOrtho(0, size[0], size[1], 0, 0, 100);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
@ -272,7 +272,7 @@ void Rubberband::paintGL()
|
|||
|
||||
glLineWidth(4.0);
|
||||
glColor4f(rgb_r, rgb_g, rgb_b, rgb_a);
|
||||
if(stipple) {
|
||||
if (stipple) {
|
||||
glLineStipple(3, 0xAAAA);
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
}
|
||||
|
@ -284,14 +284,14 @@ void Rubberband::paintGL()
|
|||
glEnd();
|
||||
|
||||
glLineWidth(1.0);
|
||||
|
||||
if(stipple)
|
||||
|
||||
if (stipple)
|
||||
glDisable(GL_LINE_STIPPLE);
|
||||
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
Polyline::Polyline(Gui::View3DInventorViewer* v) : viewer(v)
|
||||
Polyline::Polyline(View3DInventorViewer* v) : viewer(v)
|
||||
{
|
||||
x_new = y_new = 0;
|
||||
working = false;
|
||||
|
@ -319,14 +319,13 @@ void Polyline::setWorking(bool on)
|
|||
bool Polyline::isWorking()
|
||||
{
|
||||
return working;
|
||||
};
|
||||
}
|
||||
|
||||
void Polyline::setViewer(View3DInventorViewer* v)
|
||||
{
|
||||
viewer = v;
|
||||
}
|
||||
|
||||
|
||||
void Polyline::setCoords(int x, int y)
|
||||
{
|
||||
x_new = x;
|
||||
|
@ -351,29 +350,28 @@ void Polyline::setLineWidth(float l)
|
|||
line = l;
|
||||
}
|
||||
|
||||
|
||||
void Polyline::addNode(QPoint p)
|
||||
void Polyline::addNode(const QPoint& p)
|
||||
{
|
||||
_cNodeVector.push_back(p);
|
||||
}
|
||||
|
||||
void Polyline::clear()
|
||||
{
|
||||
_cNodeVector.clear();
|
||||
}
|
||||
|
||||
void Polyline::paintGL()
|
||||
{
|
||||
if(!working)
|
||||
if (!working)
|
||||
return;
|
||||
|
||||
if(_cNodeVector.empty())
|
||||
if (_cNodeVector.empty())
|
||||
return;
|
||||
|
||||
const SbViewportRegion vp = viewer->getSoRenderManager()->getViewportRegion();
|
||||
SbVec2s size = vp.getViewportSizePixels();
|
||||
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
|
||||
glOrtho(0, size[0], size[1], 0, 0, 100);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
@ -385,14 +383,13 @@ void Polyline::paintGL()
|
|||
|
||||
QPoint start = _cNodeVector.front();
|
||||
|
||||
for(std::vector<QPoint>::iterator it = _cNodeVector.begin(); it != _cNodeVector.end(); ++it) {
|
||||
for (std::vector<QPoint>::iterator it = _cNodeVector.begin(); it != _cNodeVector.end(); ++it) {
|
||||
glVertex2i(it->x(), it->y());
|
||||
}
|
||||
|
||||
if(_cNodeVector.size() > 0)
|
||||
if (!_cNodeVector.empty())
|
||||
glVertex2i(x_new, y_new);
|
||||
|
||||
glEnd();
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,9 @@
|
|||
#include <Base/BaseClass.h>
|
||||
#include <QPoint>
|
||||
|
||||
class QPaintDevice;
|
||||
class QGLWidget;
|
||||
|
||||
namespace Gui {
|
||||
class View3DInventorViewer;
|
||||
class GuiExport GLPainter
|
||||
|
@ -44,7 +47,7 @@ public:
|
|||
GLPainter();
|
||||
virtual ~GLPainter();
|
||||
|
||||
bool begin(View3DInventorViewer*);
|
||||
bool begin(QPaintDevice * device);
|
||||
bool end();
|
||||
bool isActive() const;
|
||||
|
||||
|
@ -68,7 +71,7 @@ public:
|
|||
//@}
|
||||
|
||||
private:
|
||||
View3DInventorViewer* viewer;
|
||||
QGLWidget* viewer;
|
||||
GLfloat depthrange[2];
|
||||
GLdouble projectionmatrix[16];
|
||||
GLint width, height;
|
||||
|
@ -92,18 +95,19 @@ public:
|
|||
|
||||
class GuiExport Rubberband : public Gui::GLGraphicsItem
|
||||
{
|
||||
Gui::View3DInventorViewer* viewer;
|
||||
View3DInventorViewer* viewer;
|
||||
int x_old, y_old, x_new, y_new;
|
||||
float rgb_r, rgb_g, rgb_b, rgb_a;
|
||||
bool working, stipple;
|
||||
|
||||
public:
|
||||
Rubberband(Gui::View3DInventorViewer* v);
|
||||
Rubberband(View3DInventorViewer* v);
|
||||
Rubberband();
|
||||
~Rubberband();
|
||||
void setWorking(bool on);
|
||||
void setLineStipple(bool on);
|
||||
bool isWorking();
|
||||
void setViewer(Gui::View3DInventorViewer* v);
|
||||
void setViewer(View3DInventorViewer* v);
|
||||
void setCoords(int x1, int y1, int x2, int y2);
|
||||
void setColor(float r, float g, float b, float a);
|
||||
void paintGL();
|
||||
|
@ -111,7 +115,7 @@ public:
|
|||
|
||||
class Polyline : public Gui::GLGraphicsItem
|
||||
{
|
||||
Gui::View3DInventorViewer* viewer;
|
||||
View3DInventorViewer* viewer;
|
||||
std::vector<QPoint> _cNodeVector;
|
||||
int x_new, y_new;
|
||||
float rgb_r, rgb_g, rgb_b, rgb_a, line;
|
||||
|
@ -119,17 +123,17 @@ class Polyline : public Gui::GLGraphicsItem
|
|||
GLPainter p;
|
||||
|
||||
public:
|
||||
Polyline(Gui::View3DInventorViewer* v);
|
||||
Polyline(View3DInventorViewer* v);
|
||||
Polyline();
|
||||
~Polyline();
|
||||
void setWorking(bool on);
|
||||
bool isWorking();
|
||||
void setViewer(Gui::View3DInventorViewer* v);
|
||||
void setViewer(View3DInventorViewer* v);
|
||||
void setCoords(int x, int y);
|
||||
void setColor(int r, int g, int b, int a=0);
|
||||
void setLineWidth(float l);
|
||||
void setClosed(bool c);
|
||||
void addNode(QPoint p);
|
||||
void addNode(const QPoint& p);
|
||||
void clear();
|
||||
void paintGL();
|
||||
};
|
||||
|
|
|
@ -82,7 +82,6 @@
|
|||
#include <Gui/Document.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/GLPainter.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/Utilities.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
|
|
Loading…
Reference in New Issue
Block a user