Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
OpenWalnut Core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
44
Issues
44
List
Boards
Labels
Service Desk
Milestones
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
598337fe
Commit
598337fe
authored
Jul 21, 2017
by
Alexander Wiebel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD] functionaltiy to obtain continuous notifications of the mouse position in a ceratain viewer
parent
1ca11f52
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
230 additions
and
0 deletions
+230
-0
src/core/graphicsEngine/WGEViewer.cpp
src/core/graphicsEngine/WGEViewer.cpp
+9
-0
src/core/graphicsEngine/WGEViewer.h
src/core/graphicsEngine/WGEViewer.h
+13
-0
src/core/graphicsEngine/WMouseLocationHandler.cpp
src/core/graphicsEngine/WMouseLocationHandler.cpp
+68
-0
src/core/graphicsEngine/WMouseLocationHandler.h
src/core/graphicsEngine/WMouseLocationHandler.h
+140
-0
No files found.
src/core/graphicsEngine/WGEViewer.cpp
View file @
598337fe
...
...
@@ -49,6 +49,7 @@
#include "WGEZoomTrackballManipulator.h"
#include "WGraphicsEngine.h"
#include "WPickHandler.h"
#include "WMouseLocationHandler.h"
#include "exceptions/WGEInitFailed.h"
#include "core/common/WConditionOneShot.h"
...
...
@@ -82,6 +83,9 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int
m_View
->
getCamera
()
->
setGraphicsContext
(
m_GraphicsWindow
.
get
()
);
m_mouseLocationHandler
=
new
WMouseLocationHandler
(
name
);
m_View
->
addEventHandler
(
m_mouseLocationHandler
);
switch
(
projectionMode
)
{
case
(
WGECamera
::
ORTHOGRAPHIC
):
...
...
@@ -258,6 +262,11 @@ osg::ref_ptr< WPickHandler > WGEViewer::getPickHandler()
return
m_pickHandler
;
}
osg
::
ref_ptr
<
WMouseLocationHandler
>
WGEViewer
::
getMouseLocationHandler
()
{
return
m_mouseLocationHandler
;
}
void
WGEViewer
::
reset
()
{
m_View
->
home
();
...
...
src/core/graphicsEngine/WGEViewer.h
View file @
598337fe
...
...
@@ -56,6 +56,7 @@
class
WGEGroupNode
;
#include "WGEScreenCapture.h"
class
WPickHandler
;
class
WMouseLocationHandler
;
#include "animation/WGEAnimationManipulator.h"
#include "WGEViewerEffectHorizon.h"
...
...
@@ -218,6 +219,13 @@ public:
*/
osg
::
ref_ptr
<
WPickHandler
>
getPickHandler
();
/**
* Getter for the mouse loection handler
*
* \return the mouse location handler
*/
osg
::
ref_ptr
<
WMouseLocationHandler
>
getMouseLocationHandler
();
/**
* Queries the OpenGL vendor info.
*
...
...
@@ -347,6 +355,11 @@ protected:
*/
osg
::
ref_ptr
<
WPickHandler
>
m_pickHandler
;
/**
* Pointer to the mouse location handler of the viewer.
*/
osg
::
ref_ptr
<
WMouseLocationHandler
>
m_mouseLocationHandler
;
/**
* reference to the scene which is displayed by viewer
*/
...
...
src/core/graphicsEngine/WMouseLocationHandler.cpp
0 → 100644
View file @
598337fe
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2017 OpenWalnut Community, Hochschule Worms
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut 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.
//
// OpenWalnut 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 Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include "WMouseLocationHandler.h"
#include "../common/WAssert.h"
WMouseLocationHandler
::
WMouseLocationHandler
()
:
m_mouseLocation
(
WMouseLocationInfo
()
),
m_viewerName
(
""
)
{
}
WMouseLocationHandler
::
WMouseLocationHandler
(
std
::
string
viewerName
)
:
m_mouseLocation
(
WMouseLocationInfo
()
),
m_viewerName
(
viewerName
)
{
}
WMouseLocationHandler
::~
WMouseLocationHandler
()
{
}
boost
::
signals2
::
signal
<
void
(
WMouseLocationHandler
::
WMouseLocationInfo
)
>*
WMouseLocationHandler
::
getLocationSignal
()
{
return
&
m_locationSignal
;
}
bool
WMouseLocationHandler
::
handle
(
const
osgGA
::
GUIEventAdapter
&
ea
,
osgGA
::
GUIActionAdapter
&
/* aa */
)
{
float
x
=
ea
.
getX
();
float
y
=
ea
.
getY
();
WMouseLocationInfo
locationInfo
;
locationInfo
=
WMouseLocationInfo
(
m_viewerName
,
std
::
make_pair
(
x
,
y
)
);
m_mouseLocation
=
locationInfo
;
m_locationSignal
(
getLocationInfo
()
);
return
false
;
}
WMouseLocationHandler
::
WMouseLocationInfo
WMouseLocationHandler
::
getLocationInfo
()
{
return
m_mouseLocation
;
}
src/core/graphicsEngine/WMouseLocationHandler.h
0 → 100644
View file @
598337fe
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut 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.
//
// OpenWalnut 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 Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WMOUSELOCATIONHANDLER_H
#define WMOUSELOCATIONHANDLER_H
#include <string>
#include <utility>
#include <boost/signals2/signal.hpp>
#include <osgViewer/View>
#include "../common/math/linearAlgebra/WVectorFixed.h"
/**
* Class to handle providing information about pixel position of mouse.
*/
class
WMouseLocationHandler
:
public
osgGA
::
GUIEventHandler
{
public:
/**
* Constructor that initalizes members with sensible defaults.
*/
WMouseLocationHandler
();
/**
* Constructor that initalizes members with sensible defaults and sets the name of the viewer
*
* \param viewerName name of the viewer
*/
explicit
WMouseLocationHandler
(
std
::
string
viewerName
);
/**
* Deals with the events found by the osg.
* \param ea Event class for storing Keyboard, mouse and window events.
* \param aa Interface by which GUIEventHandlers may request actions of the GUI system
*
* \return true if the event was handled.
*/
bool
handle
(
const
osgGA
::
GUIEventAdapter
&
ea
,
osgGA
::
GUIActionAdapter
&
aa
);
/**
* This class holds the information about the mouse pointer location in a certain viewe.
*/
class
WMouseLocationInfo
{
public:
/**
* Initializing members.
*
* \param viewerName Name of the osg::viewer to which the infos belong
* \param pixelCoords The pixel position of the mouse pointer in the viewer.
*/
WMouseLocationInfo
(
std
::
string
viewerName
,
std
::
pair
<
float
,
float
>
pixelCoords
)
:
m_viewerName
(
viewerName
),
m_pixelCoords
(
pixelCoords
)
{
}
/**
* Default initializing members.
*/
WMouseLocationInfo
()
:
m_viewerName
(
""
),
m_pixelCoords
(
std
::
make_pair
(
0.0
,
0.0
)
)
{
}
/**
* Obtain the mouse location in pixel coordinates
*
* \return The position of the mouse pointer in the viewer.
*/
inline
WVector2d
getPixel
()
const
{
WVector2d
pos
;
pos
[
0
]
=
m_pixelCoords
.
first
;
pos
[
1
]
=
m_pixelCoords
.
second
;
return
pos
;
}
private:
std
::
string
m_viewerName
;
//!< name of the viewer
std
::
pair
<
float
,
float
>
m_pixelCoords
;
//!< Pixel coordinates of the mouse.
};
/**
* returns the m_locationSignal to for registering to it.
*/
boost
::
signals2
::
signal
<
void
(
WMouseLocationInfo
)
>*
getLocationSignal
();
/**
* Gives information about the mouse location.
*
* \return info the location information
*/
WMouseLocationInfo
getLocationInfo
();
protected:
/**
* Virtual destructor needed because of virtual function.
*
* This desctructor is protected to avoid accidentally deleting
* an instance of WMouseLocationHandler.
* This follows the philosophy of OSG to avoid problems in multithreaded
* environments, since these pointers are used deep in the OSG where
* a deletion could cause a segfault.
*/
virtual
~
WMouseLocationHandler
();
private:
boost
::
signals2
::
signal
<
void
(
WMouseLocationInfo
)
>
m_locationSignal
;
//!< One can register to this signal to receive location events.
WMouseLocationInfo
m_mouseLocation
;
//!< Representation of mouse location
std
::
string
m_viewerName
;
//!< which viewer sends the signal
};
#endif // WMOUSELOCATIONHANDLER_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment