Commit b30f871b authored by Jan Möbius's avatar Jan Möbius

Dennis:

Added gl based cursor painting.



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@6801 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 3b50bb26
......@@ -204,6 +204,20 @@ void Core::readApplicationOptions(INIFile& _ini) {
OpenFlipper::Options::anaglyphRightEyeColorMatrix(set);
}
//============================================================================
// Load stereo mouse picking behavior
//============================================================================
bool stereoMousePick = false;
if ( _ini.get_entry( stereoMousePick, "Options" , "StereoMousePick") )
OpenFlipper::Options::stereoMousePick(stereoMousePick);
//============================================================================
// Load gl mouse painting behavior
//============================================================================
bool glMouse = false;
if ( _ini.get_entry( glMouse, "Options" , "GlMouse") )
OpenFlipper::Options::glMouse(glMouse);
//============================================================================
// Load the setting for the loger window
//============================================================================
......@@ -625,6 +639,10 @@ void Core::writeApplicationOptions(INIFile& _ini) {
_ini.add_entry("Options" , "CustomAnaglyphLeftEye", OpenFlipper::Options::anaglyphLeftEyeColorMatrix() );
_ini.add_entry("Options" , "CustomAnaglyphRightEye", OpenFlipper::Options::anaglyphRightEyeColorMatrix() );
_ini.add_entry("Options", "StereoMousePick", OpenFlipper::Options::stereoMousePick() );
_ini.add_entry("Options", "GlMouse", OpenFlipper::Options::glMouse() );
}
emit saveOnExit(_ini);
......
......@@ -82,6 +82,9 @@ void Core::applyOptions(){
// Logger
coreWidget_->showLogger( OpenFlipper::Options::loggerState() );
// gl mouse cursor
coreWidget_->setGlCursor( OpenFlipper::Options::glMouse() );
// Prepare Picking Debugger Flag
ACG::SceneGraph::PickTarget target;
if ( OpenFlipper::Options::pickingRenderMode() == "PICK_ANYHING") {
......
......@@ -136,6 +136,9 @@ static float focalDistance_ = 0.5;
static std::vector<float> anaglyphLeftEyeColors_ = std::vector<float> (9, 0.0);
static std::vector<float> anaglyphRightEyeColors_ = std::vector<float> (9, 0.0);
/// mouse cursor depth picking in stereo mode
static bool stereoMousePick_ = true;
/// Store the synchronization mode
static bool synchronization_ = false;
......@@ -175,6 +178,9 @@ static bool drawModesInContextMenu_ = true;
/// Set if a grid should be drawn in every viewer
static bool gridVisible_ = false;
/// Should OpenGL be used to draw the mouse cursor
static bool glMouse_ = true;
/// Store the toolbox gui Mode mode
static bool hideToolbox_ = false;
......@@ -623,6 +629,15 @@ std::vector<float> anaglyphRightEyeColorMatrix( )
return anaglyphRightEyeColors_;
}
/// Enables/Disables mouse cursor depth picking during stereo mode
void stereoMousePick( bool _stereoMousePick ) {
stereoMousePick_ = _stereoMousePick;
}
/// mouse cursor depth picking during stereo mode
bool stereoMousePick( ) {
return stereoMousePick_;
}
/// Store synchronization mode setting
void synchronization( bool _synchronization ) {
......@@ -755,6 +770,15 @@ unsigned int examinerWidgets() {
return 1;
}
/// Store Gl based cursor painting
void glMouse( bool _glMouse ) {
glMouse_ = _glMouse;
}
/// Should the mouse cursor be painted with gl
bool glMouse( ) {
return glMouse_;
}
/// Set to current
void loggerState( LoggerState _state) {
......
......@@ -487,6 +487,14 @@ bool dataDir(QString _dir);
DLLEXPORT
std::vector<float> anaglyphRightEyeColorMatrix( );
/// Enables/Disables mouse cursor depth picking during stereo mode
DLLEXPORT
void stereoMousePick( bool _stereoPick );
/// mouse cursor depth picking during stereo mode
DLLEXPORT
bool stereoMousePick( );
/// Store synchronization setting
DLLEXPORT
void synchronization( bool _synchronization );
......@@ -591,6 +599,14 @@ bool dataDir(QString _dir);
DLLEXPORT
void gridVisible(bool _visible);
/// Store Gl based cursor painting
DLLEXPORT
void glMouse( bool _glMouse );
/// Should the mouse cursor be painted with gl
DLLEXPORT
bool glMouse( );
/** @} */
//===========================================================================
......
......@@ -64,6 +64,8 @@
#include <OpenFlipper/widgets/videoCaptureDialog/VideoCaptureDialog.hh>
#include <OpenFlipper/widgets/glWidget/CursorPainter.hh>
#define WIDGET_HEIGHT 800
#define WIDGET_WIDTH 800
......@@ -86,6 +88,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
logWidget_(0),
recentFilesMenu_(0),
helpMenu_(0),
cursorPainter_(0),
sceneGraphDialog_(0),
fileMenu_(0),
viewMenu_(0),
......@@ -175,7 +178,10 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
glView_->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
glView_->setScene(glScene_);
// gl widget as parent to make sure that the CursorPainter will be deleted before
cursorPainter_ = new CursorPainter (glWidget_);
cursorPainter_->setEnabled (OpenFlipper::Options::glMouse ());
glScene_->setCursorPainter (cursorPainter_);
centerWidget_ = new QGraphicsWidget;
glScene_->addItem(centerWidget_);
......@@ -244,6 +250,8 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
baseLayout_->addItem(examinerWidget, 0);
cursorPainter_->registerViewer (examinerWidget);
} else {
......@@ -270,6 +278,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
// Initialize all examiners
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
examiner_widgets_[i]->sceneGraph( PluginFunctions::getSceneGraphRootNode() );
cursorPainter_->registerViewer (examiner_widgets_[i]);
}
baseLayout_->addItem(examiner_widgets_[0],0);
......@@ -918,6 +927,13 @@ void CoreWidget::slotActivateExaminer()
}
}
//-----------------------------------------------------------------------------
/// Use native or gl painted cursor
void CoreWidget::setGlCursor ( bool _state )
{
cursorPainter_->setEnabled (_state);
}
//=============================================================================
......@@ -344,6 +344,9 @@ public:
/// Show or hide toolbox
void showToolbox( bool _state );
/// Use native or gl painted cursor
void setGlCursor ( bool _state );
private:
OpenFlipper::Options::LoggerState loggerState_;
......@@ -464,6 +467,9 @@ public:
/// Toolbar showed in pickmode
QtPickToolbar* pickToolbar_;
/// Cursor handling
CursorPainter* cursorPainter_;
// widget showing the scenegraph
ACG::QtWidgets::QtSceneGraphDialog* sceneGraphDialog_;
......
......@@ -56,6 +56,7 @@
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/widgets/glWidget/CursorPainter.hh>
//-----------------------------------------------------------------------------
......@@ -102,6 +103,24 @@ void CoreWidget::setActionMode(const Viewer::ActionMode _am){
}
}
// update cursor
switch ( _am )
{
case Viewer::ExamineMode:
case Viewer::LightMode:
cursorPainter_->setCursor(Qt::PointingHandCursor);
break;
case Viewer::PickingMode:
cursorPainter_->setCursor(Qt::ArrowCursor);
if (pick_mode_idx_ != -1) {
cursorPainter_->setCursor(pick_modes_[pick_mode_idx_].cursor);
}
break;
case Viewer::QuestionMode:
cursorPainter_->setCursor(Qt::WhatsThisCursor);
break;
}
//update Viewers
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
......@@ -115,25 +134,14 @@ void CoreWidget::setActionMode(const Viewer::ActionMode _am){
{
case Viewer::ExamineMode:
{
examiner_widgets_[i]->setCursor(Qt::PointingHandCursor);
pickToolbar_->detachToolbar ();
break;
}
case Viewer::LightMode:
{
examiner_widgets_[i]->setCursor(Qt::PointingHandCursor);
break;
}
case Viewer::PickingMode:
{
examiner_widgets_[i]->setCursor(Qt::ArrowCursor);
if (pick_mode_idx_ != -1) {
examiner_widgets_[i]->trackMouse(pick_modes_[pick_mode_idx_].tracking);
examiner_widgets_[i]->setCursor(pick_modes_[pick_mode_idx_].cursor);
if (pick_modes_[pick_mode_idx_].toolbar)
pickToolbar_->attachToolbar (pick_modes_[pick_mode_idx_].toolbar);
else
......@@ -143,12 +151,9 @@ void CoreWidget::setActionMode(const Viewer::ActionMode _am){
break;
}
case Viewer::QuestionMode:
{
examiner_widgets_[i]->setCursor(Qt::WhatsThisCursor);
default:
break;
}
}
}
......@@ -280,8 +285,7 @@ void CoreWidget::pickMode( int _id )
// adjust Cursor
if ( pickingMode() )
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
examiner_widgets_[i]->setCursor( pick_modes_[pick_mode_idx_].cursor);
cursorPainter_->setCursor( pick_modes_[pick_mode_idx_].cursor);
// emit signal
emit(signalPickModeChanged(pick_mode_name_));
......@@ -321,8 +325,7 @@ void CoreWidget::setPickModeCursor(const std::string& _name, QCursor _cursor)
//switch cursor if pickMode is active
if (pick_mode_name_ == _name && pickingMode() )
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
examiner_widgets_[i]->setCursor(_cursor);
cursorPainter_->setCursor(_cursor);
break;
}
}
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS CursorPainter - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include <QPixmap>
#include <QImage>
#include <QBitmap>
#include <OpenFlipper/common/GlobalOptions.hh>
#include "CursorPainter.hh"
#include "QtBaseViewer.hh"
//== NAMESPACES ===============================================================
CursorPainter::CursorPainter (QObject *_parent) :
QObject(_parent),
cursor_(),
initialized_(false),
enabled_(false),
mouseIn_(false),
texture_(0),
hasCursor_(false)
{
}
//-----------------------------------------------------------------------------
CursorPainter::~CursorPainter ()
{
if (initialized_)
{
glDeleteTextures (1, &texture_);
}
}
//-----------------------------------------------------------------------------
void CursorPainter::setCursor (const QCursor &_cursor)
{
cursor_ = _cursor;
cursorToTexture ();
if (!(initialized_ && enabled_ && hasCursor_))
foreach (glViewer *v, views_)
v->setCursor (cursor_);
}
//-----------------------------------------------------------------------------
void CursorPainter::initializeGL()
{
if (initialized_)
return;
initialized_ = true;
// setup cursor texture
glGenTextures (1, &texture_);
glBindTexture (GL_TEXTURE_2D, texture_);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glBindTexture (GL_TEXTURE_2D, 0);
cursorToTexture ();
if (enabled_ && hasCursor_)
{
foreach (glViewer *v, views_)
v->setCursor (Qt::BlankCursor);
}
else
{
foreach (glViewer *v, views_)
v->setCursor (cursor_);
}
}
//-----------------------------------------------------------------------------
void CursorPainter::registerViewer(glViewer * _viewer)
{
views_.append (_viewer);
_viewer->setCursorPainter (this);
}
//-----------------------------------------------------------------------------
void CursorPainter::paintCursor (ACG::GLState *_state)
{
if (!initialized_)
return;
if (!enabled())
return;
// project (0, 0, 0) to get its position on the screen
ACG::Vec3d zPos = _state->project (ACG::Vec3d (0.0, 0.0, 0.0));
// unproject the result translated by 1px in x and y
zPos = _state->unproject (ACG::Vec3d (zPos[0] + 1, zPos[1] + 1, zPos[2]));
// this gives us the size of one pixel in the current scene transformation
// now we can paint the cursor always with the same width/height
float xscale = zPos[0];
float yscale = -zPos[1];
glPushAttrib (GL_ALL_ATTRIB_BITS);
glDisable (GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// bind texture
glEnable (GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, texture_);
glColor4f (1.0, 1.0, 1.0, 1.0);
float x1 = -xOff_ * xscale;
float x2 = (32 - xOff_) * xscale;
float y1 = -yOff_ * yscale;
float y2 = (32 - yOff_) * yscale;
// draw cursor quad
glBegin (GL_QUADS);
glTexCoord2f (0, 0);
glVertex3f (x1, y1, 0);
glTexCoord2f (0, 1);
glVertex3f (x1, y2, 0);
glTexCoord2f (1, 1);
glVertex3f (x2, y2, 0);
glTexCoord2f (1, 0);
glVertex3f (x2, y1, 0);
glEnd ();
glPopAttrib ();
}
//-----------------------------------------------------------------------------
void CursorPainter::updateCursorPosition (QPointF _scenePos)
{
cursorPos_ = _scenePos;
setMouseIn (true);
}
//-----------------------------------------------------------------------------
QPointF CursorPainter::cursorPosition()
{
return cursorPos_;
}
//-----------------------------------------------------------------------------
void CursorPainter::setEnabled(bool _enabled)
{
enabled_ = _enabled;
if (initialized_)
{
if (_enabled)
{
foreach (glViewer *v, views_)
v->setCursor (Qt::BlankCursor);
}
else
{
foreach (glViewer *v, views_)
v->setCursor (cursor_);
}
}
}
//-----------------------------------------------------------------------------
bool CursorPainter::enabled()
{
return initialized_ && enabled_ && hasCursor_ && mouseIn_;
}
//-----------------------------------------------------------------------------
void CursorPainter::cursorToTexture()
{
if (!initialized_)
return;
unsigned char buf[4096];
QImage cImg;
hasCursor_ = false;
switch (cursor_.shape())
{
case Qt::ArrowCursor:
cImg.load (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"cursor_arrow.png");
xOff_ = 0;
yOff_ = 0;
break;
case Qt::PointingHandCursor:
cImg.load (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"cursor_hand.png");
xOff_ = 7;
yOff_ = 1;
break;
default:
return;
}
if (cImg.width () != 32 || cImg.height () != 32)
return;
// convert ARGB QImage to RGBA for gl
int index = 0;
for (int y = 0; y < cImg.height (); y++)
for (int x = 0; x < cImg.width (); x++)
{
QRgb pix = cImg.pixel (x, y);
buf[index] = qRed (pix);
buf[index+1] = qGreen (pix);
buf[index+2] = qBlue (pix);
buf[index+3] = qAlpha (pix);
index += 4;
}
glEnable (GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, texture_);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0,
GL_RGBA, GL_UNSIGNED_BYTE, buf);
glBindTexture (GL_TEXTURE_2D, 0);
glDisable (GL_TEXTURE_2D);
hasCursor_ = true;
}
//-----------------------------------------------------------------------------
void CursorPainter::setMouseIn(bool _in)
{
mouseIn_ = _in;
}
//-----------------------------------------------------------------------------
QRectF CursorPainter::cursorBoundingBox()
{
return QRectF (-xOff_, -yOff_, 32, 32);
}
//=============================================================================
//=============================================================================
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
#ifndef CURSORPAINTER_HH
#define CURSORPAINTER_HH
//== INCLUDES =================================================================
#include <QObject>
#include <QCursor>
#include <QVector>
#include <QRectF>
#include <ACG/GL/GLState.hh>
#include <OpenFlipper/common/GlobalDefines.hh>
//== NAMESPACES ===============================================================
//== FORWARDDECLARATIONS ======================================================
class glViewer;
//== CLASS DEFINITION =========================================================
/** Class that paints the cursor using gl calls
*/
class DLLEXPORT CursorPainter : public QObject
{
Q_OBJECT
public:
/// Constructor
CursorPainter (QObject *_parent = 0);
/// Destructor
~CursorPainter ();
/// Sets the current used cursor
void setCursor (const QCursor &_cursor);
/// Needs to be called after the gl context has been set up to initialize internal values
void initializeGL ();
/// Add a glViewer that will use this CursorPainter
void registerViewer (glViewer *_viewer);
/// Cursor painting function. The _state has to be setup that 0,0,0 is at the cursor position.
void paintCursor (ACG::GLState *_state);
/// Sets the current cursor position
void updateCursorPosition (QPointF _scenePos);
/// Return the current cursor position
QPointF cursorPosition ();
/// Enabled/Disables gl cursor painting
void setEnabled (bool _enabled);
/// Returns true if cursor painting is enabled and compatible cursor is set
bool enabled ();
/// Inform the cursor painter about mouse enter / leave
void setMouseIn (bool _in);
/// Bounding box of the cursor
QRectF cursorBoundingBox ();
private:
// Create a texture for the cursor
void cursorToTexture ();
private:
QCursor cursor_;
QPointF cursorPos_;
bool initialized_;
QVector<glViewer *> views_;
bool enabled_;
bool mouseIn_;
// x and y offset between click position and texture (hotspot)
int xOff_;
int yOff_;
GLuint texture_;
bool hasCursor_;
};
//=============================================================================
#endif
//=============================================================================
......@@ -54,6 +54,7 @@
#include "QtBaseViewer.hh"
#include "QtGLViewerLayout.hh"
#include "CursorPainter.hh"
#include <ACG/QtWidgets/QtWheel.hh>
#include <ACG/Scenegraph/DrawModes.hh>
#include <ACG/GL/gl.hh>
......@@ -139,6 +140,8 @@ glViewer::glViewer( QGraphicsScene* _scene,
blending_(true),
glScene_(_scene),
glWidget_(_glWidget),
cursorPainter_(0),
cursorPositionValid_(false),
clickEvent_(QEvent::MouseButtonPress, QPoint (), Qt::NoButton, Qt::NoButton, Qt::NoModifier),
properties_(_properties),
glstate_(0),
......@@ -649,6 +652,18 @@ void glViewer::drawScene_mono()
}
}
if (cursorPainter_ && cursorPainter_->enabled () && cursorPositionValid_)
{
glstate_->push_modelview_matrix ();
// reset view transformation