Skip to content

Commit

Permalink
+ change API of GLPainter
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Oct 22, 2014
1 parent 8fb5962 commit 621aebd
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/Gui/Flag.cpp
Expand Up @@ -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
Expand Down
81 changes: 39 additions & 42 deletions src/Gui/GLPainter.cpp
Expand Up @@ -26,6 +26,7 @@
#ifndef _PreComp_
#endif

#include <QGLWidget>
#include "GLPainter.h"
#include "View3DInventorViewer.h"
#include <Base/Console.h>
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
}

22 changes: 13 additions & 9 deletions src/Gui/GLPainter.h
Expand Up @@ -36,6 +36,9 @@
#include <Base/BaseClass.h>
#include <QPoint>

class QPaintDevice;
class QGLWidget;

namespace Gui {
class View3DInventorViewer;
class GuiExport GLPainter
Expand All @@ -44,7 +47,7 @@ class GuiExport GLPainter
GLPainter();
virtual ~GLPainter();

bool begin(View3DInventorViewer*);
bool begin(QPaintDevice * device);
bool end();
bool isActive() const;

Expand All @@ -68,7 +71,7 @@ class GuiExport GLPainter
//@}

private:
View3DInventorViewer* viewer;
QGLWidget* viewer;
GLfloat depthrange[2];
GLdouble projectionmatrix[16];
GLint width, height;
Expand All @@ -92,44 +95,45 @@ class GuiExport GLGraphicsItem : public Base::BaseClass

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();
};

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;
bool working, closed;
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();
};
Expand Down
1 change: 0 additions & 1 deletion src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
Expand Up @@ -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>
Expand Down

0 comments on commit 621aebd

Please sign in to comment.