Skip to content

Commit

Permalink
New mrpt::gui event: mrptEventMouseMove
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Oct 8, 2017
1 parent 45129df commit b136888
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 5 deletions.
2 changes: 2 additions & 0 deletions doc/doxygen-pages/changeLog_doc.h
Expand Up @@ -18,6 +18,8 @@
- \ref mrpt_base_grp - \ref mrpt_base_grp
- Fix potential uninitialized value in CRobot2DPoseEstimator::getLatestRobotPose() - Fix potential uninitialized value in CRobot2DPoseEstimator::getLatestRobotPose()
- MRPT_getCompilationDate() returns time as well - MRPT_getCompilationDate() returns time as well
- \ref mrpt_gui_grp
- mrpt::gui::mrptEventMouseMove: Added new mrpt::gui windows event type.
- Smart pointers: - Smart pointers:
- All mrpt::utils::CObject derived classes: - All mrpt::utils::CObject derived classes:
- In MRPT <=1.5.3, there was a typedef `Foo::SmartPtr` => `FooPtr`. - In MRPT <=1.5.3, there was a typedef `Foo::SmartPtr` => `FooPtr`.
Expand Down
26 changes: 25 additions & 1 deletion libs/gui/include/mrpt/gui/CBaseGUIWindow.h
Expand Up @@ -187,7 +187,7 @@ namespace mrpt
* IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread, * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread,
* so all your code in the handler must be thread safe. * so all your code in the handler must be thread safe.
* *
* \sa mrptEventMouseDown * \sa mrptEventMouseMove
*/ */
class GUI_IMPEXP mrptEventMouseDown : public mrpt::utils::mrptEvent class GUI_IMPEXP mrptEventMouseDown : public mrpt::utils::mrptEvent
{ {
Expand All @@ -208,6 +208,30 @@ namespace mrpt
bool rightButton; bool rightButton;
}; // End of class def. }; // End of class def.


/** An event sent by a window when the mouse is moved over it.
* IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread,
* so all your code in the handler must be thread safe.
* \sa mrptEventMouseDown
*/
class GUI_IMPEXP mrptEventMouseMove : public mrpt::utils::mrptEvent
{
protected:
virtual void do_nothing() MRPT_OVERRIDE { } //!< Just to allow this class to be polymorphic
public:
inline mrptEventMouseMove(
CBaseGUIWindow *obj,
mrpt::utils::TPixelCoord _coords,
bool _leftButton,
bool _rightButton
) : source_object(obj), coords(_coords), leftButton(_leftButton), rightButton(_rightButton)
{ }

CBaseGUIWindow *source_object;
mrpt::utils::TPixelCoord coords;
bool leftButton;
bool rightButton;
}; // End of class def.

/** An event sent by a window upon when it's about to be closed, either manually by the user or programatically. /** An event sent by a window upon when it's about to be closed, either manually by the user or programatically.
* The event field member \a allow_close is default by default, but can be set to false in the event callback * The event field member \a allow_close is default by default, but can be set to false in the event callback
* to forbid the window to be closed by the user. If the event corresponds to a programatic close, this field is ignored. * to forbid the window to be closed by the user. If the event corresponds to a programatic close, this field is ignored.
Expand Down
1 change: 1 addition & 0 deletions libs/gui/include/mrpt/gui/WxSubsystem.h
Expand Up @@ -341,6 +341,7 @@ namespace mrpt
void OnKeyDown(wxKeyEvent& event); void OnKeyDown(wxKeyEvent& event);
void OnResize(wxSizeEvent& event); void OnResize(wxSizeEvent& event);
void OnMouseDown(wxMouseEvent& event); void OnMouseDown(wxMouseEvent& event);
void OnMouseMove(wxMouseEvent& event);


DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; // end class CWindowDialog }; // end class CWindowDialog
Expand Down
18 changes: 16 additions & 2 deletions libs/gui/src/CDisplayWindow.cpp
Expand Up @@ -185,6 +185,7 @@ CWindowDialog::CWindowDialog(


m_image->Connect(wxEVT_LEFT_DOWN,(wxObjectEventFunction)&CWindowDialog::OnMouseDown,NULL,this); m_image->Connect(wxEVT_LEFT_DOWN,(wxObjectEventFunction)&CWindowDialog::OnMouseDown,NULL,this);
m_image->Connect(wxEVT_RIGHT_DOWN,(wxObjectEventFunction)&CWindowDialog::OnMouseDown,NULL,this); m_image->Connect(wxEVT_RIGHT_DOWN,(wxObjectEventFunction)&CWindowDialog::OnMouseDown,NULL,this);
m_image->Connect(wxEVT_MOTION, (wxObjectEventFunction)&CWindowDialog::OnMouseMove, NULL, this);


// Increment number of windows: // Increment number of windows:
//int winCount = //int winCount =
Expand Down Expand Up @@ -249,7 +250,7 @@ void CWindowDialog::OnChar(wxKeyEvent& event)
void CWindowDialog::OnResize(wxSizeEvent& event) void CWindowDialog::OnResize(wxSizeEvent& event)
{ {
// Send the event: // Send the event:
if (m_win2D) if (m_win2D && m_win2D->hasSubscribers())
{ {
try { try {
m_win2D->publishEvent( mrptEventWindowResize(m_win2D,event.GetSize().GetWidth(),event.GetSize().GetHeight())); m_win2D->publishEvent( mrptEventWindowResize(m_win2D,event.GetSize().GetWidth(),event.GetSize().GetHeight()));
Expand All @@ -261,7 +262,7 @@ void CWindowDialog::OnResize(wxSizeEvent& event)
void CWindowDialog::OnMouseDown(wxMouseEvent& event) void CWindowDialog::OnMouseDown(wxMouseEvent& event)
{ {
// Send the event: // Send the event:
if (m_win2D) if (m_win2D && m_win2D->hasSubscribers())
{ {
try { try {
m_win2D->publishEvent( mrptEventMouseDown(m_win2D, TPixelCoord(event.GetX(), event.GetY()), event.LeftDown(), event.RightDown() ) ); m_win2D->publishEvent( mrptEventMouseDown(m_win2D, TPixelCoord(event.GetX(), event.GetY()), event.LeftDown(), event.RightDown() ) );
Expand All @@ -270,6 +271,19 @@ void CWindowDialog::OnMouseDown(wxMouseEvent& event)
event.Skip(); // so it's processed by the wx system! event.Skip(); // so it's processed by the wx system!
} }


void CWindowDialog::OnMouseMove(wxMouseEvent& event)
{
// Send the event:
if (m_win2D && m_win2D->hasSubscribers())
{
try {
m_win2D->publishEvent(mrptEventMouseMove(m_win2D, TPixelCoord(event.GetX(), event.GetY()), event.LeftDown(), event.RightDown()));
}
catch (...) {}
}
event.Skip(); // so it's processed by the wx system!
}



// Menu: Close // Menu: Close
void CWindowDialog::OnMenuClose(wxCommandEvent& event) void CWindowDialog::OnMenuClose(wxCommandEvent& event)
Expand Down
17 changes: 16 additions & 1 deletion libs/gui/src/CDisplayWindow3D.cpp
Expand Up @@ -86,6 +86,7 @@ namespace mrpt


void OnCharCustom( wxKeyEvent& event ); void OnCharCustom( wxKeyEvent& event );
void OnMouseDown(wxMouseEvent& event); void OnMouseDown(wxMouseEvent& event);
void OnMouseMove(wxMouseEvent& event);


void OnPreRender(); void OnPreRender();
void OnPostRender(); void OnPostRender();
Expand All @@ -108,6 +109,7 @@ CMyGLCanvas_DisplayWindow3D::CMyGLCanvas_DisplayWindow3D(


Connect(wxEVT_LEFT_DOWN,(wxObjectEventFunction)&CMyGLCanvas_DisplayWindow3D::OnMouseDown); Connect(wxEVT_LEFT_DOWN,(wxObjectEventFunction)&CMyGLCanvas_DisplayWindow3D::OnMouseDown);
Connect(wxEVT_RIGHT_DOWN,(wxObjectEventFunction)&CMyGLCanvas_DisplayWindow3D::OnMouseDown); Connect(wxEVT_RIGHT_DOWN,(wxObjectEventFunction)&CMyGLCanvas_DisplayWindow3D::OnMouseDown);
Connect(wxEVT_MOTION, (wxObjectEventFunction)&CMyGLCanvas_DisplayWindow3D::OnMouseMove);
} }


void CMyGLCanvas_DisplayWindow3D::display3D_processKeyEvent(CDisplayWindow3D *m_win3D, wxKeyEvent&ev) void CMyGLCanvas_DisplayWindow3D::display3D_processKeyEvent(CDisplayWindow3D *m_win3D, wxKeyEvent&ev)
Expand Down Expand Up @@ -155,7 +157,7 @@ void CMyGLCanvas_DisplayWindow3D::OnCharCustom( wxKeyEvent& ev )
void CMyGLCanvas_DisplayWindow3D::OnMouseDown(wxMouseEvent& event) void CMyGLCanvas_DisplayWindow3D::OnMouseDown(wxMouseEvent& event)
{ {
// Send the event: // Send the event:
if (m_win3D) if (m_win3D && m_win3D->hasSubscribers())
{ {
try { try {
m_win3D->publishEvent( mrptEventMouseDown(m_win3D, TPixelCoord(event.GetX(), event.GetY()), event.LeftDown(), event.RightDown() ) ); m_win3D->publishEvent( mrptEventMouseDown(m_win3D, TPixelCoord(event.GetX(), event.GetY()), event.LeftDown(), event.RightDown() ) );
Expand All @@ -165,6 +167,19 @@ void CMyGLCanvas_DisplayWindow3D::OnMouseDown(wxMouseEvent& event)
event.Skip(); // so it's processed by the wx system! event.Skip(); // so it's processed by the wx system!
} }


void CMyGLCanvas_DisplayWindow3D::OnMouseMove(wxMouseEvent& event)
{
// Send the event:
if (m_win3D && m_win3D->hasSubscribers())
{
try {
m_win3D->publishEvent(mrptEventMouseMove(m_win3D, TPixelCoord(event.GetX(), event.GetY()), event.LeftDown(), event.RightDown()));
}
catch (...) {}
}
event.Skip(); // so it's processed by the wx system!
}



CMyGLCanvas_DisplayWindow3D::~CMyGLCanvas_DisplayWindow3D() CMyGLCanvas_DisplayWindow3D::~CMyGLCanvas_DisplayWindow3D()
{ {
Expand Down
12 changes: 11 additions & 1 deletion libs/gui/src/CDisplayWindowPlots.cpp
Expand Up @@ -265,7 +265,17 @@ void CWindowDialogPlots::OnMouseMove(wxMouseEvent& event)
m_curCursorPos.y = m_plot->p2y(Y); m_curCursorPos.y = m_plot->p2y(Y);
m_last_mouse_point.x = X; m_last_mouse_point.x = X;
m_last_mouse_point.y = Y; m_last_mouse_point.y = Y;
event.Skip();
// Send the event:
if (m_winPlots && m_winPlots->hasSubscribers())
{
try {
m_winPlots->publishEvent(mrptEventMouseMove(m_winPlots, TPixelCoord(event.GetX(), event.GetY()), event.LeftDown(), event.RightDown()));
}
catch (...) {}
}
event.Skip(); // so it's processed by the wx system!

} }


// Add / Modify a 2D plot using a MATLAB-like format string // Add / Modify a 2D plot using a MATLAB-like format string
Expand Down

0 comments on commit b136888

Please sign in to comment.