Commit dd81fc4d authored by Jan Möbius's avatar Jan Möbius
Browse files

Dennis:

Added gl based cursor painting.



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@6801 383ad7c9-94d9-4d36-a494-682f7c89f535
parent cb2df0fd
...@@ -204,6 +204,20 @@ void Core::readApplicationOptions(INIFile& _ini) { ...@@ -204,6 +204,20 @@ void Core::readApplicationOptions(INIFile& _ini) {
OpenFlipper::Options::anaglyphRightEyeColorMatrix(set); 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 // Load the setting for the loger window
//============================================================================ //============================================================================
...@@ -625,6 +639,10 @@ void Core::writeApplicationOptions(INIFile& _ini) { ...@@ -625,6 +639,10 @@ void Core::writeApplicationOptions(INIFile& _ini) {
_ini.add_entry("Options" , "CustomAnaglyphLeftEye", OpenFlipper::Options::anaglyphLeftEyeColorMatrix() ); _ini.add_entry("Options" , "CustomAnaglyphLeftEye", OpenFlipper::Options::anaglyphLeftEyeColorMatrix() );
_ini.add_entry("Options" , "CustomAnaglyphRightEye", OpenFlipper::Options::anaglyphRightEyeColorMatrix() ); _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); emit saveOnExit(_ini);
......
...@@ -82,6 +82,9 @@ void Core::applyOptions(){ ...@@ -82,6 +82,9 @@ void Core::applyOptions(){
// Logger // Logger
coreWidget_->showLogger( OpenFlipper::Options::loggerState() ); coreWidget_->showLogger( OpenFlipper::Options::loggerState() );
// gl mouse cursor
coreWidget_->setGlCursor( OpenFlipper::Options::glMouse() );
// Prepare Picking Debugger Flag // Prepare Picking Debugger Flag
ACG::SceneGraph::PickTarget target; ACG::SceneGraph::PickTarget target;
if ( OpenFlipper::Options::pickingRenderMode() == "PICK_ANYHING") { if ( OpenFlipper::Options::pickingRenderMode() == "PICK_ANYHING") {
......
...@@ -136,6 +136,9 @@ static float focalDistance_ = 0.5; ...@@ -136,6 +136,9 @@ static float focalDistance_ = 0.5;
static std::vector<float> anaglyphLeftEyeColors_ = std::vector<float> (9, 0.0); static std::vector<float> anaglyphLeftEyeColors_ = std::vector<float> (9, 0.0);
static std::vector<float> anaglyphRightEyeColors_ = 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 /// Store the synchronization mode
static bool synchronization_ = false; static bool synchronization_ = false;
...@@ -175,6 +178,9 @@ static bool drawModesInContextMenu_ = true; ...@@ -175,6 +178,9 @@ static bool drawModesInContextMenu_ = true;
/// Set if a grid should be drawn in every viewer /// Set if a grid should be drawn in every viewer
static bool gridVisible_ = false; static bool gridVisible_ = false;
/// Should OpenGL be used to draw the mouse cursor
static bool glMouse_ = true;
/// Store the toolbox gui Mode mode /// Store the toolbox gui Mode mode
static bool hideToolbox_ = false; static bool hideToolbox_ = false;
...@@ -623,6 +629,15 @@ std::vector<float> anaglyphRightEyeColorMatrix( ) ...@@ -623,6 +629,15 @@ std::vector<float> anaglyphRightEyeColorMatrix( )
return anaglyphRightEyeColors_; 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 /// Store synchronization mode setting
void synchronization( bool _synchronization ) { void synchronization( bool _synchronization ) {
...@@ -755,6 +770,15 @@ unsigned int examinerWidgets() { ...@@ -755,6 +770,15 @@ unsigned int examinerWidgets() {
return 1; 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 /// Set to current
void loggerState( LoggerState _state) { void loggerState( LoggerState _state) {
......
...@@ -487,6 +487,14 @@ bool dataDir(QString _dir); ...@@ -487,6 +487,14 @@ bool dataDir(QString _dir);
DLLEXPORT DLLEXPORT
std::vector<float> anaglyphRightEyeColorMatrix( ); 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 /// Store synchronization setting
DLLEXPORT DLLEXPORT
void synchronization( bool _synchronization ); void synchronization( bool _synchronization );
...@@ -591,6 +599,14 @@ bool dataDir(QString _dir); ...@@ -591,6 +599,14 @@ bool dataDir(QString _dir);
DLLEXPORT DLLEXPORT
void gridVisible(bool _visible); 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 @@ ...@@ -64,6 +64,8 @@
#include <OpenFlipper/widgets/videoCaptureDialog/VideoCaptureDialog.hh> #include <OpenFlipper/widgets/videoCaptureDialog/VideoCaptureDialog.hh>
#include <OpenFlipper/widgets/glWidget/CursorPainter.hh>
#define WIDGET_HEIGHT 800 #define WIDGET_HEIGHT 800
#define WIDGET_WIDTH 800 #define WIDGET_WIDTH 800
...@@ -86,6 +88,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -86,6 +88,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
logWidget_(0), logWidget_(0),
recentFilesMenu_(0), recentFilesMenu_(0),
helpMenu_(0), helpMenu_(0),
cursorPainter_(0),
sceneGraphDialog_(0), sceneGraphDialog_(0),
fileMenu_(0), fileMenu_(0),
viewMenu_(0), viewMenu_(0),
...@@ -175,7 +178,10 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -175,7 +178,10 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
glView_->setViewportUpdateMode(QGraphicsView::FullViewportUpdate); glView_->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
glView_->setScene(glScene_); 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; centerWidget_ = new QGraphicsWidget;
glScene_->addItem(centerWidget_); glScene_->addItem(centerWidget_);
...@@ -244,6 +250,8 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -244,6 +250,8 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
baseLayout_->addItem(examinerWidget, 0); baseLayout_->addItem(examinerWidget, 0);
cursorPainter_->registerViewer (examinerWidget);
} else { } else {
...@@ -270,6 +278,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -270,6 +278,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
// Initialize all examiners // Initialize all examiners
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) { for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
examiner_widgets_[i]->sceneGraph( PluginFunctions::getSceneGraphRootNode() ); examiner_widgets_[i]->sceneGraph( PluginFunctions::getSceneGraphRootNode() );
cursorPainter_->registerViewer (examiner_widgets_[i]);
} }
baseLayout_->addItem(examiner_widgets_[0],0); baseLayout_->addItem(examiner_widgets_[0],0);
...@@ -918,6 +927,13 @@ void CoreWidget::slotActivateExaminer() ...@@ -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: ...@@ -344,6 +344,9 @@ public:
/// Show or hide toolbox /// Show or hide toolbox
void showToolbox( bool _state ); void showToolbox( bool _state );
/// Use native or gl painted cursor
void setGlCursor ( bool _state );
private: private:
OpenFlipper::Options::LoggerState loggerState_; OpenFlipper::Options::LoggerState loggerState_;
...@@ -464,6 +467,9 @@ public: ...@@ -464,6 +467,9 @@ public:
/// Toolbar showed in pickmode /// Toolbar showed in pickmode
QtPickToolbar* pickToolbar_; QtPickToolbar* pickToolbar_;
/// Cursor handling
CursorPainter* cursorPainter_;
// widget showing the scenegraph // widget showing the scenegraph
ACG::QtWidgets::QtSceneGraphDialog* sceneGraphDialog_; ACG::QtWidgets::QtSceneGraphDialog* sceneGraphDialog_;
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include <OpenFlipper/BasePlugin/PluginFunctions.hh> #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh> #include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/widgets/glWidget/CursorPainter.hh>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -102,6 +103,24 @@ void CoreWidget::setActionMode(const Viewer::ActionMode _am){ ...@@ -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 //update Viewers
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) { for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
...@@ -115,25 +134,14 @@ void CoreWidget::setActionMode(const Viewer::ActionMode _am){ ...@@ -115,25 +134,14 @@ void CoreWidget::setActionMode(const Viewer::ActionMode _am){
{ {
case Viewer::ExamineMode: case Viewer::ExamineMode:
{ {
examiner_widgets_[i]->setCursor(Qt::PointingHandCursor);
pickToolbar_->detachToolbar (); pickToolbar_->detachToolbar ();
break; break;
} }
case Viewer::LightMode:
{
examiner_widgets_[i]->setCursor(Qt::PointingHandCursor);
break;
}
case Viewer::PickingMode: case Viewer::PickingMode:
{ {
examiner_widgets_[i]->setCursor(Qt::ArrowCursor);
if (pick_mode_idx_ != -1) { if (pick_mode_idx_ != -1) {
examiner_widgets_[i]->trackMouse(pick_modes_[pick_mode_idx_].tracking); 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) if (pick_modes_[pick_mode_idx_].toolbar)
pickToolbar_->attachToolbar (pick_modes_[pick_mode_idx_].toolbar); pickToolbar_->attachToolbar (pick_modes_[pick_mode_idx_].toolbar);
else else
...@@ -143,12 +151,9 @@ void CoreWidget::setActionMode(const Viewer::ActionMode _am){ ...@@ -143,12 +151,9 @@ void CoreWidget::setActionMode(const Viewer::ActionMode _am){
break; break;
} }
default:
case Viewer::QuestionMode:
{
examiner_widgets_[i]->setCursor(Qt::WhatsThisCursor);
break; break;
}
} }
} }
...@@ -280,8 +285,7 @@ void CoreWidget::pickMode( int _id ) ...@@ -280,8 +285,7 @@ void CoreWidget::pickMode( int _id )
// adjust Cursor // adjust Cursor
if ( pickingMode() ) if ( pickingMode() )
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) cursorPainter_->setCursor( pick_modes_[pick_mode_idx_].cursor);
examiner_widgets_[i]->setCursor( pick_modes_[pick_mode_idx_].cursor);
// emit signal // emit signal
emit(signalPickModeChanged(pick_mode_name_)); emit(signalPickModeChanged(pick_mode_name_));
...@@ -321,8 +325,7 @@ void CoreWidget::setPickModeCursor(const std::string& _name, QCursor _cursor) ...@@ -321,8 +325,7 @@ void CoreWidget::setPickModeCursor(const std::string& _name, QCursor _cursor)
//switch cursor if pickMode is active //switch cursor if pickMode is active
if (pick_mode_name_ == _name && pickingMode() ) if (pick_mode_name_ == _name && pickingMode() )
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) cursorPainter_->setCursor(_cursor);
examiner_widgets_[i]->setCursor(_cursor);
break; 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);