Adopt mouse selection to quarter widget
Quarter Widget soes not allow to switch of multisampling on the fly, therefore we need to use glgraphicsitem instead of direct opengl xor rendering for mouse selection
This commit is contained in:
@@ -204,12 +204,14 @@ Rubberband::Rubberband(Gui::View3DInventorViewer* v) : viewer(v)
|
||||
{
|
||||
x_old = y_old = x_new = y_new = 0;
|
||||
working = false;
|
||||
stipple = true;
|
||||
}
|
||||
|
||||
Rubberband::Rubberband()
|
||||
{
|
||||
x_old = y_old = x_new = y_new = 0;
|
||||
working = false;
|
||||
stipple = true;
|
||||
}
|
||||
|
||||
Rubberband::~Rubberband()
|
||||
@@ -234,6 +236,20 @@ void Rubberband::setCoords(int x1, int y1, int x2, int y2)
|
||||
y_new = y2;
|
||||
}
|
||||
|
||||
void Rubberband::setLineStipple(bool on)
|
||||
{
|
||||
stipple = on;
|
||||
}
|
||||
|
||||
|
||||
void Rubberband::setColor(float r, float g, float b, float a)
|
||||
{
|
||||
rgb_a = a;
|
||||
rgb_b = b;
|
||||
rgb_g = g;
|
||||
rgb_r = r;
|
||||
}
|
||||
|
||||
void Rubberband::paintGL()
|
||||
{
|
||||
if(!working)
|
||||
@@ -242,7 +258,7 @@ void Rubberband::paintGL()
|
||||
const SbViewportRegion vp = viewer->getSoRenderManager()->getViewportRegion();
|
||||
SbVec2s size = vp.getViewportSizePixels();
|
||||
|
||||
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
|
||||
glOrtho(0, size[0], size[1], 0, 0, 100);
|
||||
@@ -253,14 +269,13 @@ void Rubberband::paintGL()
|
||||
glLineWidth(4.0);
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
|
||||
glRecti(x_old, y_old, x_new, y_new);
|
||||
glColor4f(0.0, 0.0, 1.0, 1.0);
|
||||
glLineStipple(3, 0xAAAA);
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
|
||||
glLineWidth(4.0);
|
||||
glColor4f(0.0, 0.0, 1.0, 1.0);
|
||||
glLineStipple(3, 0xAAAA);
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
glColor4f(rgb_r, rgb_g, rgb_b, rgb_a);
|
||||
if(stipple) {
|
||||
glLineStipple(3, 0xAAAA);
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
}
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glVertex2i(x_old, y_old);
|
||||
glVertex2i(x_old, y_new);
|
||||
@@ -269,7 +284,115 @@ void Rubberband::paintGL()
|
||||
glEnd();
|
||||
|
||||
glLineWidth(1.0);
|
||||
glDisable(GL_LINE_STIPPLE);
|
||||
|
||||
if(stipple)
|
||||
glDisable(GL_LINE_STIPPLE);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
Polyline::Polyline(Gui::View3DInventorViewer* v) : viewer(v)
|
||||
{
|
||||
x_new = y_new = 0;
|
||||
working = false;
|
||||
closed = true;
|
||||
line = 2.0;
|
||||
}
|
||||
|
||||
Polyline::Polyline()
|
||||
{
|
||||
x_new = y_new = 0;
|
||||
working = false;
|
||||
closed = true;
|
||||
line = 2.0;
|
||||
}
|
||||
|
||||
Polyline::~Polyline()
|
||||
{
|
||||
}
|
||||
|
||||
void Polyline::setWorking(bool on)
|
||||
{
|
||||
working = on;
|
||||
}
|
||||
|
||||
bool Polyline::isWorking()
|
||||
{
|
||||
return working;
|
||||
};
|
||||
|
||||
void Polyline::setViewer(View3DInventorViewer* v)
|
||||
{
|
||||
viewer = v;
|
||||
}
|
||||
|
||||
|
||||
void Polyline::setCoords(int x, int y)
|
||||
{
|
||||
x_new = x;
|
||||
y_new = y;
|
||||
}
|
||||
|
||||
void Polyline::setColor(int r, int g, int b, int a)
|
||||
{
|
||||
rgb_a = a;
|
||||
rgb_b = b;
|
||||
rgb_g = g;
|
||||
rgb_r = r;
|
||||
}
|
||||
|
||||
void Polyline::setClosed(bool c)
|
||||
{
|
||||
closed = c;
|
||||
}
|
||||
|
||||
void Polyline::setLineWidth(float l)
|
||||
{
|
||||
line = l;
|
||||
}
|
||||
|
||||
|
||||
void Polyline::addNode(QPoint p)
|
||||
{
|
||||
_cNodeVector.push_back(p);
|
||||
}
|
||||
void Polyline::clear()
|
||||
{
|
||||
_cNodeVector.clear();
|
||||
}
|
||||
void Polyline::paintGL()
|
||||
{
|
||||
if(!working)
|
||||
return;
|
||||
|
||||
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);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glLineWidth(line);
|
||||
glColor4f(rgb_r, rgb_g, rgb_b, rgb_a);
|
||||
glBegin(GL_LINE_LOOP);
|
||||
|
||||
QPoint start = _cNodeVector.front();
|
||||
|
||||
for(std::vector<QPoint>::iterator it = _cNodeVector.begin(); it != _cNodeVector.end(); ++it) {
|
||||
glVertex2i(it->x(), it->y());
|
||||
}
|
||||
|
||||
if(_cNodeVector.size() > 0)
|
||||
glVertex2i(x_new, y_new);
|
||||
|
||||
glEnd();
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#endif
|
||||
|
||||
#include <Base/BaseClass.h>
|
||||
#include <QPoint>
|
||||
|
||||
namespace Gui {
|
||||
class View3DInventorViewer;
|
||||
@@ -93,17 +94,45 @@ class GuiExport Rubberband : public Gui::GLGraphicsItem
|
||||
{
|
||||
Gui::View3DInventorViewer* viewer;
|
||||
int x_old, y_old, x_new, y_new;
|
||||
bool working;
|
||||
float rgb_r, rgb_g, rgb_b, rgb_a;
|
||||
bool working, stipple;
|
||||
public:
|
||||
Rubberband(Gui::View3DInventorViewer* v);
|
||||
Rubberband();
|
||||
~Rubberband();
|
||||
void setWorking(bool on);
|
||||
void setLineStipple(bool on);
|
||||
bool isWorking();
|
||||
void setViewer(Gui::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;
|
||||
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();
|
||||
~Polyline();
|
||||
void setWorking(bool on);
|
||||
bool isWorking();
|
||||
void setViewer(Gui::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 clear();
|
||||
void paintGL();
|
||||
};
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -28,6 +28,7 @@
|
||||
#include <Inventor/SbLinear.h>
|
||||
#include <Inventor/SbVec2f.h>
|
||||
#include <QCursor>
|
||||
#include "GLPainter.h"
|
||||
|
||||
// forwards
|
||||
class QMouseEvent;
|
||||
@@ -47,7 +48,7 @@ class View3DInventorViewer;
|
||||
/**
|
||||
* The mouse selection base class
|
||||
* In derived classes you must implement the methods @ref initialize() and @ref terminate()
|
||||
* For all drawing stuff you just have to reimplement the @ref draw() method.
|
||||
* For all drawing stuff you just have to reimplement the @ref draw() method.
|
||||
* In general you need not to do anything else.
|
||||
* \author Werner Mayer and Jürgen Riegel
|
||||
*/
|
||||
@@ -57,33 +58,43 @@ public:
|
||||
enum { Continue=0, Restart=1, Finish=2, Cancel=3 };
|
||||
|
||||
AbstractMouseSelection();
|
||||
virtual ~AbstractMouseSelection(void){}
|
||||
virtual ~AbstractMouseSelection(void) {}
|
||||
/// implement this in derived classes
|
||||
virtual void initialize() = 0;
|
||||
/// implement this in derived classes
|
||||
virtual void terminate () = 0;
|
||||
virtual void terminate() = 0;
|
||||
void grabMouseModel(Gui::View3DInventorViewer*);
|
||||
void releaseMouseModel(void);
|
||||
const std::vector<SbVec2s>& getPositions() const { return _clPoly; }
|
||||
SbBool isInner() const { return m_bInner; }
|
||||
const std::vector<SbVec2s>& getPositions() const {
|
||||
return _clPoly;
|
||||
}
|
||||
SbBool isInner() const {
|
||||
return m_bInner;
|
||||
}
|
||||
|
||||
void redraw();
|
||||
|
||||
/** @name Mouse events*/
|
||||
//@{
|
||||
int handleEvent(const SoEvent * const ev, const SbViewportRegion& vp);
|
||||
int handleEvent(const SoEvent* const ev, const SbViewportRegion& vp);
|
||||
//@}
|
||||
|
||||
protected:
|
||||
virtual int mouseButtonEvent( const SoMouseButtonEvent * const e, const QPoint& pos ){ return 0; };
|
||||
virtual int locationEvent ( const SoLocation2Event * const e, const QPoint& pos ){ return 0; };
|
||||
virtual int keyboardEvent ( const SoKeyboardEvent * const e ) { return 0; };
|
||||
virtual int mouseButtonEvent(const SoMouseButtonEvent* const e, const QPoint& pos) {
|
||||
return 0;
|
||||
};
|
||||
virtual int locationEvent(const SoLocation2Event* const e, const QPoint& pos) {
|
||||
return 0;
|
||||
};
|
||||
virtual int keyboardEvent(const SoKeyboardEvent* const e) {
|
||||
return 0;
|
||||
};
|
||||
|
||||
/// drawing stuff
|
||||
virtual void draw (){};
|
||||
virtual void draw() {};
|
||||
|
||||
protected:
|
||||
Gui::View3DInventorViewer*_pcView3D;
|
||||
Gui::View3DInventorViewer* _pcView3D;
|
||||
QCursor m_cPrevCursor;
|
||||
int m_iXold, m_iYold;
|
||||
int m_iXnew, m_iYnew;
|
||||
@@ -103,7 +114,7 @@ class GuiExport BaseMouseSelection : public AbstractMouseSelection
|
||||
{
|
||||
public:
|
||||
BaseMouseSelection();
|
||||
virtual ~BaseMouseSelection(){}
|
||||
virtual ~BaseMouseSelection() {};
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
@@ -119,24 +130,19 @@ public:
|
||||
PolyPickerSelection();
|
||||
virtual ~PolyPickerSelection();
|
||||
|
||||
/// set the new mouse cursor
|
||||
virtual void initialize();
|
||||
/// do nothing
|
||||
virtual void terminate();
|
||||
|
||||
protected:
|
||||
virtual int mouseButtonEvent( const SoMouseButtonEvent * const e, const QPoint& pos );
|
||||
virtual int locationEvent ( const SoLocation2Event * const e, const QPoint& pos );
|
||||
virtual int keyboardEvent ( const SoKeyboardEvent * const e );
|
||||
virtual int mouseButtonEvent(const SoMouseButtonEvent* const e, const QPoint& pos);
|
||||
virtual int locationEvent(const SoLocation2Event* const e, const QPoint& pos);
|
||||
virtual int keyboardEvent(const SoKeyboardEvent* const e);
|
||||
|
||||
/// draw the polygon
|
||||
virtual void draw ();
|
||||
virtual void draw();
|
||||
virtual int popupMenu();
|
||||
|
||||
protected:
|
||||
std::vector<QPoint> _cNodeVector;
|
||||
int m_iRadius, m_iNodes;
|
||||
bool m_bWorking;
|
||||
Gui::Polyline polyline;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
@@ -162,39 +168,19 @@ protected:
|
||||
* The brush selection class
|
||||
* \author Werner Mayer
|
||||
*/
|
||||
class GuiExport BrushSelection : public BaseMouseSelection
|
||||
class GuiExport BrushSelection : public PolyPickerSelection
|
||||
{
|
||||
public:
|
||||
BrushSelection();
|
||||
virtual ~BrushSelection();
|
||||
~BrushSelection();
|
||||
|
||||
/// set the new mouse cursor
|
||||
virtual void initialize();
|
||||
/// do nothing
|
||||
virtual void terminate();
|
||||
|
||||
// Settings
|
||||
void setColor(float r, float g, float b, float a=0);
|
||||
void setLineWidth(float);
|
||||
void setClosed(bool);
|
||||
void setLineWidth(float l);
|
||||
void setClosed(bool c);
|
||||
void setColor(float r, float g, float b, float a = 1.0);
|
||||
|
||||
protected:
|
||||
virtual int mouseButtonEvent( const SoMouseButtonEvent * const e, const QPoint& pos );
|
||||
virtual int locationEvent ( const SoLocation2Event * const e, const QPoint& pos );
|
||||
virtual int keyboardEvent ( const SoKeyboardEvent * const e );
|
||||
|
||||
/// draw the polygon
|
||||
virtual void draw ();
|
||||
virtual int popupMenu();
|
||||
|
||||
protected:
|
||||
std::vector<QPoint> _cNodeVector;
|
||||
int m_iNodes;
|
||||
bool m_bWorking;
|
||||
bool m_bClose;
|
||||
|
||||
private:
|
||||
float r,g,b,a,l;
|
||||
virtual int locationEvent(const SoLocation2Event* const e, const QPoint& pos);
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
@@ -204,37 +190,7 @@ private:
|
||||
* Draws a rectangle for selection
|
||||
* \author Werner Mayer
|
||||
*/
|
||||
class GuiExport RectangleSelection : public BaseMouseSelection
|
||||
{
|
||||
public:
|
||||
RectangleSelection();
|
||||
virtual ~RectangleSelection();
|
||||
|
||||
/// do nothing
|
||||
virtual void initialize();
|
||||
/// do nothing
|
||||
virtual void terminate();
|
||||
|
||||
protected:
|
||||
virtual int mouseButtonEvent( const SoMouseButtonEvent * const e, const QPoint& pos );
|
||||
virtual int locationEvent ( const SoLocation2Event * const e, const QPoint& pos );
|
||||
virtual int keyboardEvent ( const SoKeyboardEvent * const e );
|
||||
|
||||
/// draw the rectangle
|
||||
virtual void draw ();
|
||||
|
||||
private:
|
||||
bool m_bWorking;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The selection mouse model class
|
||||
* Draws a rectangle for selection
|
||||
* \author Werner Mayer
|
||||
*/
|
||||
class GuiExport RubberbandSelection : public BaseMouseSelection
|
||||
class GuiExport RubberbandSelection : public BaseMouseSelection
|
||||
{
|
||||
public:
|
||||
RubberbandSelection();
|
||||
@@ -246,16 +202,29 @@ public:
|
||||
virtual void terminate();
|
||||
|
||||
protected:
|
||||
virtual int mouseButtonEvent( const SoMouseButtonEvent * const e, const QPoint& pos );
|
||||
virtual int locationEvent ( const SoLocation2Event * const e, const QPoint& pos );
|
||||
virtual int keyboardEvent ( const SoKeyboardEvent * const e );
|
||||
virtual int mouseButtonEvent(const SoMouseButtonEvent* const e, const QPoint& pos);
|
||||
virtual int locationEvent(const SoLocation2Event* const e, const QPoint& pos);
|
||||
virtual int keyboardEvent(const SoKeyboardEvent* const e);
|
||||
|
||||
/// draw the rectangle
|
||||
virtual void draw ();
|
||||
virtual void draw();
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private* d;
|
||||
protected:
|
||||
Gui::Rubberband rubberband;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The selection mouse model class
|
||||
* Draws a rectangle for selection
|
||||
* \author Werner Mayer
|
||||
*/
|
||||
class GuiExport RectangleSelection : public RubberbandSelection
|
||||
{
|
||||
public:
|
||||
RectangleSelection();
|
||||
virtual ~RectangleSelection();
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
@@ -265,7 +234,7 @@ private:
|
||||
* Draws a rectangle for box zooming
|
||||
* \author Werner Mayer
|
||||
*/
|
||||
class GuiExport BoxZoomSelection : public RubberbandSelection
|
||||
class GuiExport BoxZoomSelection : public RubberbandSelection
|
||||
{
|
||||
public:
|
||||
BoxZoomSelection();
|
||||
|
||||
@@ -1226,13 +1226,15 @@ SbBool NavigationStyle::processEvent(const SoEvent * const ev)
|
||||
else if (hd==AbstractMouseSelection::Finish) {
|
||||
pcPolygon = mouseSelection->getPositions();
|
||||
clipInner = mouseSelection->isInner();
|
||||
delete mouseSelection; mouseSelection = 0;
|
||||
delete mouseSelection;
|
||||
mouseSelection = 0;
|
||||
syncWithEvent(ev);
|
||||
return NavigationStyle::processSoEvent(ev);
|
||||
}
|
||||
else if (hd==AbstractMouseSelection::Cancel) {
|
||||
pcPolygon.clear();
|
||||
delete mouseSelection; mouseSelection = 0;
|
||||
delete mouseSelection;
|
||||
mouseSelection = 0;
|
||||
syncWithEvent(ev);
|
||||
return NavigationStyle::processSoEvent(ev);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user