Main MRPT website > C++ reference for MRPT 1.9.9
CBaseGUIWindow.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
12 #include <mrpt/system/mrptEvent.h>
15 #include <mrpt/img/TPixelCoord.h>
16 #include <mrpt/gui/keycodes.h>
17 #include <mrpt/gui/gui_frwds.h>
18 
19 #include <mutex>
20 #include <future>
21 
22 namespace mrpt
23 {
24 namespace gui
25 {
26 /** The base class for GUI window classes.
27  *
28  * This class can be observed (see mrpt::system::CObserver) for the following
29  * events (see mrpt::system::mrptEvent):
30  * - mrpt::gui::mrptEventWindowChar
31  * - mrpt::gui::mrptEventWindowResize
32  * - mrpt::gui::mrptEventMouseDown
33  * - mrpt::gui::mrptEventWindowClosed
34  *
35  * See derived classes to check if they emit other additional events.
36  *
37  * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked
38  * from the wxWidgets internal MRPT thread,
39  * so all your code in the handler must be thread safe.
40  * \ingroup mrpt_gui_grp
41  */
43 {
44  friend class CWindowDialog;
45  friend class C3DWindowDialog;
46  friend class CWindowDialogPlots;
47 
48  private:
49  /** can be 200,300,400... See WxSubsystem */
50  const int m_CMD_CREATE_WIN;
51  /** can be 299,399,499... See WxSubsystem */
52  const int m_CMD_DESTROY_WIN;
54 
55  protected:
56  /** This semaphore will be signaled when the wx window is built and ready.
57  */
58  mutable std::promise<void> m_threadReady;
59  /** This semaphore will be signaled when the wx window is destroyed. */
60  mutable std::promise<void> m_windowDestroyed;
61  /** The caption of the window */
63  /** The window handle */
65 
66  /* Auxiliary */
67  volatile bool m_keyPushed;
68  volatile int m_keyPushedCode;
70 
71  /** Must be called by child classes just within the constructor. */
72  void createWxWindow(unsigned int initialWidth, unsigned int initialHeight);
73  /** Must be called by child classes in their destructors. The code cannot be
74  * put into this class' destructor. */
75  void destroyWxWindow();
76 
77  public:
78  /** Read-only access to the wxDialog object. */
79  void* getWxObject() { return m_hwnd.get(); }
80  /** Called by wx main thread to set m_hwnd to NULL. */
82  /** Called by wx main thread to signal the semaphore that the wx window is
83  * built and ready. */
84  void notifySemThreadReady();
85 
86  public:
87  /** CMD_DESTROY_WIN can be 299,399,499... See WxSubsystem */
88 
90  void* winobj_voidptr, int CMD_CREATE_WIN, int CMD_DESTROY_WIN,
91  const std::string& initial_caption = std::string());
92  virtual ~CBaseGUIWindow();
93 
94  /** Returns false if the user has already closed the window.
95  */
96  bool isOpen();
97 
98  /** Resizes the window, stretching the image to fit into the display area.
99  */
100  virtual void resize(unsigned int width, unsigned int height) = 0;
101 
102  /** Changes the position of the window on the screen.
103  */
104  virtual void setPos(int x, int y) = 0;
105 
106  /** Changes the window title text.
107  */
108  virtual void setWindowTitle(const std::string& str) = 0;
109 
110  /** Gets the last x,y pixel coordinates of the mouse. \return False if the
111  * window is closed. */
112  virtual bool getLastMousePosition(int& x, int& y) const = 0;
113 
114  /** Set cursor style to default (cursorIsCross=false) or to a cross
115  * (cursorIsCross=true) */
116  virtual void setCursorCross(bool cursorIsCross) = 0;
117 
118  /** Waits for any key to be pushed on the image or the console, and returns
119  * the key code.
120  * This method remove key strokes previous to its call, so it will always
121  * wait. To get
122  * the latest pushed key, see
123  *
124  * \param ignoreControlKeys If set to false, any push of shift, cmd,
125  * control, etc... will make this method to return.
126  * \param out_pushModifier If set to !=nullptr, the modifiers of the key
127  * stroke will be saved here.
128  * \return The virtual key code, as defined in mrptKeyCode (a replication
129  * of wxWidgets key codes).
130  *
131  * \sa getPushedKey, Key codes in the enum mrptKeyCode
132  */
133  int waitForKey(
134  bool ignoreControlKeys = true,
135  mrptKeyModifier* out_pushModifier = nullptr);
136 
137  /** Returns true if a key has been pushed, without blocking waiting for a
138  * new key being pushed.
139  * \sa waitForKey, clearKeyHitFlag
140  */
141  bool keyHit() const { return m_keyPushed; }
142  /** Assure that "keyHit" will return false until the next pushed key.
143  * \sa keyHit, waitForKey
144  */
145  void clearKeyHitFlag() { m_keyPushed = false; }
146  /** Returns the latest pushed key, or 0 if there is no new key stroke.
147  * \param out_pushModifier If set to !=nullptr, the modifiers of the key
148  * stroke will be saved here.
149  * \return The virtual key code, as defined in <mrpt/gui/keycodes.h> (a
150  * replication of wxWidgets key codes).
151  *
152  * \sa keyHit, waitForKey
153  */
154  int getPushedKey(mrptKeyModifier* out_pushModifier = nullptr);
155 
156 }; // End of class def.
157 
158 /** @name Events common to all GUI windows:
159  @{ */
160 
161 /** An event sent by a window upon a char pressed by the user.
162  *
163  * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked
164  * from the wxWidgets internal MRPT thread,
165  * so all your code in the handler must be thread safe.
166  */
168 {
169  protected:
170  /** Just to allow this class to be polymorphic */
171  virtual void do_nothing() override {}
172  public:
174  CBaseGUIWindow* obj, int _char_code, mrptKeyModifier _key_mod)
175  : source_object(obj), char_code(_char_code), key_modifiers(_key_mod)
176  {
177  }
178 
180  /** The virtual key code, as defined in <mrpt/gui/keycodes.h> (a replication
181  * of wxWidgets key codes). */
183  /** Modifiers (Shift, Control, etc...) */
185 }; // End of class def.
186 
187 /** An event sent by a window upon resize.
188  *
189  * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked
190  * from the wxWidgets internal MRPT thread,
191  * so all your code in the handler must be thread safe.
192  */
194 {
195  protected:
196  /** Just to allow this class to be polymorphic */
197  virtual void do_nothing() override {}
198  public:
200  CBaseGUIWindow* obj, size_t _new_width, size_t _new_height)
201  : source_object(obj), new_width(_new_width), new_height(_new_height)
202  {
203  }
204 
207 }; // End of class def.
208 
209 /** An event sent by a window upon a mouse click, giving the (x,y) pixel
210  * coordinates.
211  *
212  * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked
213  * from the wxWidgets internal MRPT thread,
214  * so all your code in the handler must be thread safe.
215  *
216  * \sa mrptEventMouseMove
217  */
219 {
220  protected:
221  /** Just to allow this class to be polymorphic */
222  virtual void do_nothing() override {}
223  public:
225  CBaseGUIWindow* obj, mrpt::img::TPixelCoord _coords, bool _leftButton,
226  bool _rightButton)
227  : source_object(obj),
228  coords(_coords),
229  leftButton(_leftButton),
230  rightButton(_rightButton)
231  {
232  }
233 
238 }; // End of class def.
239 
240 /** An event sent by a window when the mouse is moved over it.
241  * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked
242  * from the wxWidgets internal MRPT thread,
243  * so all your code in the handler must be thread safe.
244  * \sa mrptEventMouseDown
245  */
247 {
248  protected:
249  /** Just to allow this class to be polymorphic */
250  virtual void do_nothing() override {}
251  public:
253  CBaseGUIWindow* obj, mrpt::img::TPixelCoord _coords, bool _leftButton,
254  bool _rightButton)
255  : source_object(obj),
256  coords(_coords),
257  leftButton(_leftButton),
258  rightButton(_rightButton)
259  {
260  }
261 
266 }; // End of class def.
267 
268 /** An event sent by a window upon when it's about to be closed, either
269  * manually by the user or programmatically.
270  * The event field member \a allow_close is default by default, but can be
271  * set to false in the event callback
272  * to forbid the window to be closed by the user. If the event corresponds to
273  * a programatic close, this field is ignored.
274  *
275  * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked
276  * from the wxWidgets internal MRPT thread,
277  * so all your code in the handler must be thread safe.
278  *
279  * \sa CBaseGUIWindow
280  */
282 {
283  protected:
284  /** Just to allow this class to be polymorphic */
285  virtual void do_nothing() override {}
286  public:
287  inline mrptEventWindowClosed(CBaseGUIWindow* obj, bool _allow_close = true)
288  : source_object(obj), allow_close(_allow_close)
289  {
290  }
293 }; // End of class def.
294 
295 /** @} */
296 
297 } // namespace gui
298 } // namespace mrpt
mrpt::gui::mrptEventWindowClosed::allow_close
bool allow_close
Definition: CBaseGUIWindow.h:292
mrpt::gui::CBaseGUIWindow::m_keyPushedCode
volatile int m_keyPushedCode
Definition: CBaseGUIWindow.h:68
mrpt::system::mrptEvent
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:33
keycodes.h
mrpt::gui::CBaseGUIWindow::createWxWindow
void createWxWindow(unsigned int initialWidth, unsigned int initialHeight)
Must be called by child classes just within the constructor.
Definition: CBaseGUIWindow.cpp:42
mrpt::gui::mrptEventMouseDown::rightButton
bool rightButton
Definition: CBaseGUIWindow.h:237
mrpt::gui::CWindowDialog
The wx dialog for gui::CDisplayWindow.
Definition: WxSubsystem.h:331
gui_frwds.h
mrptEvent.h
mrpt::gui::CBaseGUIWindow::m_CMD_DESTROY_WIN
const int m_CMD_DESTROY_WIN
can be 299,399,499...
Definition: CBaseGUIWindow.h:52
mrpt::gui::CBaseGUIWindow::m_keyPushedModifier
volatile mrptKeyModifier m_keyPushedModifier
Definition: CBaseGUIWindow.h:69
mrpt::gui::mrptEventWindowResize::do_nothing
virtual void do_nothing() override
Just to allow this class to be polymorphic.
Definition: CBaseGUIWindow.h:197
mrpt::gui::CBaseGUIWindow::setCursorCross
virtual void setCursorCross(bool cursorIsCross)=0
Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true)
obj
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
mrpt::gui::mrptEventWindowClosed::source_object
CBaseGUIWindow * source_object
Definition: CBaseGUIWindow.h:291
mrpt::gui::mrptEventMouseMove::rightButton
bool rightButton
Definition: CBaseGUIWindow.h:265
mrpt::gui::mrptEventMouseMove
An event sent by a window when the mouse is moved over it.
Definition: CBaseGUIWindow.h:246
mrpt::gui::CBaseGUIWindow::m_CMD_CREATE_WIN
const int m_CMD_CREATE_WIN
can be 200,300,400...
Definition: CBaseGUIWindow.h:50
mrpt::gui::mrptEventWindowChar
An event sent by a window upon a char pressed by the user.
Definition: CBaseGUIWindow.h:167
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::gui::mrptEventWindowResize::new_height
size_t new_height
Definition: CBaseGUIWindow.h:206
mrpt::gui::mrptEventWindowResize
An event sent by a window upon resize.
Definition: CBaseGUIWindow.h:193
mrpt::gui::CBaseGUIWindow::m_windowDestroyed
std::promise< void > m_windowDestroyed
This semaphore will be signaled when the wx window is destroyed.
Definition: CBaseGUIWindow.h:60
mrpt::gui::CBaseGUIWindow::clearKeyHitFlag
void clearKeyHitFlag()
Assure that "keyHit" will return false until the next pushed key.
Definition: CBaseGUIWindow.h:145
mrpt::gui::mrptEventMouseDown::leftButton
bool leftButton
Definition: CBaseGUIWindow.h:236
mrpt::gui::CBaseGUIWindow::notifySemThreadReady
void notifySemThreadReady()
Called by wx main thread to signal the semaphore that the wx window is built and ready.
Definition: CBaseGUIWindow.cpp:217
mrpt::gui::CBaseGUIWindow
The base class for GUI window classes.
Definition: CBaseGUIWindow.h:42
mrpt::gui::mrptEventMouseDown
An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates.
Definition: CBaseGUIWindow.h:218
mrpt::gui::CBaseGUIWindow::isOpen
bool isOpen()
Returns false if the user has already closed the window.
Definition: CBaseGUIWindow.cpp:213
CObservable.h
mrpt::gui::CBaseGUIWindow::resize
virtual void resize(unsigned int width, unsigned int height)=0
Resizes the window, stretching the image to fit into the display area.
mrpt::gui::CBaseGUIWindow::getPushedKey
int getPushedKey(mrptKeyModifier *out_pushModifier=nullptr)
Returns the latest pushed key, or 0 if there is no new key stroke.
Definition: CBaseGUIWindow.cpp:190
mrpt::gui::CBaseGUIWindow::m_caption
std::string m_caption
The caption of the window.
Definition: CBaseGUIWindow.h:62
mrpt::gui::mrptEventMouseDown::source_object
CBaseGUIWindow * source_object
Definition: CBaseGUIWindow.h:234
mrpt::gui::mrptEventMouseMove::mrptEventMouseMove
mrptEventMouseMove(CBaseGUIWindow *obj, mrpt::img::TPixelCoord _coords, bool _leftButton, bool _rightButton)
Definition: CBaseGUIWindow.h:252
mrpt::gui::CBaseGUIWindow::m_hwnd
mrpt::void_ptr_noncopy m_hwnd
The window handle.
Definition: CBaseGUIWindow.h:64
mrpt::gui::C3DWindowDialog
Definition: WxSubsystem.h:395
mrpt::gui::mrptEventWindowChar::mrptEventWindowChar
mrptEventWindowChar(CBaseGUIWindow *obj, int _char_code, mrptKeyModifier _key_mod)
Definition: CBaseGUIWindow.h:173
mrpt::gui::mrptEventWindowResize::source_object
CBaseGUIWindow * source_object
Definition: CBaseGUIWindow.h:205
mrpt::gui::mrptEventWindowChar::key_modifiers
mrptKeyModifier key_modifiers
Modifiers (Shift, Control, etc...)
Definition: CBaseGUIWindow.h:184
mrpt::gui::CBaseGUIWindow::setWindowTitle
virtual void setWindowTitle(const std::string &str)=0
Changes the window title text.
mrpt::gui::mrptEventMouseMove::coords
mrpt::img::TPixelCoord coords
Definition: CBaseGUIWindow.h:263
mrpt::gui::mrptEventWindowChar::char_code
int char_code
The virtual key code, as defined in <mrpt/gui/keycodes.h> (a replication of wxWidgets key codes).
Definition: CBaseGUIWindow.h:182
mrpt::gui::CBaseGUIWindow::notifyChildWindowDestruction
void notifyChildWindowDestruction()
Called by wx main thread to set m_hwnd to NULL.
Definition: CBaseGUIWindow.cpp:152
height
GLenum GLsizei GLsizei height
Definition: glext.h:3554
mrpt::gui::mrptEventMouseDown::do_nothing
virtual void do_nothing() override
Just to allow this class to be polymorphic.
Definition: CBaseGUIWindow.h:222
mrpt::gui::CBaseGUIWindow::getLastMousePosition
virtual bool getLastMousePosition(int &x, int &y) const =0
Gets the last x,y pixel coordinates of the mouse.
mrpt::gui::mrptEventWindowClosed::do_nothing
virtual void do_nothing() override
Just to allow this class to be polymorphic.
Definition: CBaseGUIWindow.h:285
safe_pointers.h
mrpt::gui::mrptEventWindowClosed::mrptEventWindowClosed
mrptEventWindowClosed(CBaseGUIWindow *obj, bool _allow_close=true)
Definition: CBaseGUIWindow.h:287
mrpt::gui::mrptEventMouseMove::do_nothing
virtual void do_nothing() override
Just to allow this class to be polymorphic.
Definition: CBaseGUIWindow.h:250
mrpt::gui::mrptEventMouseDown::mrptEventMouseDown
mrptEventMouseDown(CBaseGUIWindow *obj, mrpt::img::TPixelCoord _coords, bool _leftButton, bool _rightButton)
Definition: CBaseGUIWindow.h:224
mrpt::gui::CBaseGUIWindow::~CBaseGUIWindow
virtual ~CBaseGUIWindow()
Definition: CBaseGUIWindow.cpp:101
width
GLenum GLsizei width
Definition: glext.h:3531
mrpt::gui::CBaseGUIWindow::m_threadReady
std::promise< void > m_threadReady
This semaphore will be signaled when the wx window is built and ready.
Definition: CBaseGUIWindow.h:58
mrpt::gui::mrptEventMouseDown::coords
mrpt::img::TPixelCoord coords
Definition: CBaseGUIWindow.h:235
mrpt::gui::mrptKeyModifier
mrptKeyModifier
Definition: keycodes.h:159
mrpt::gui::CBaseGUIWindow::m_keyPushed
volatile bool m_keyPushed
Definition: CBaseGUIWindow.h:67
mrpt::gui::mrptEventWindowResize::new_width
size_t new_width
Definition: CBaseGUIWindow.h:206
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::gui::mrptEventMouseMove::leftButton
bool leftButton
Definition: CBaseGUIWindow.h:264
mrpt::gui::CBaseGUIWindow::keyHit
bool keyHit() const
Returns true if a key has been pushed, without blocking waiting for a new key being pushed.
Definition: CBaseGUIWindow.h:141
mrpt::gui::CBaseGUIWindow::m_winobj_voidptr
void * m_winobj_voidptr
Definition: CBaseGUIWindow.h:53
mrpt::img::TPixelCoord
A pair (x,y) of pixel coordinates (integer resolution).
Definition: TPixelCoord.h:39
mrpt::gui::mrptEventWindowChar::do_nothing
virtual void do_nothing() override
Just to allow this class to be polymorphic.
Definition: CBaseGUIWindow.h:171
mrpt::gui::CBaseGUIWindow::getWxObject
void * getWxObject()
Read-only access to the wxDialog object.
Definition: CBaseGUIWindow.h:79
mrpt::gui::CBaseGUIWindow::destroyWxWindow
void destroyWxWindow()
Must be called by child classes in their destructors.
Definition: CBaseGUIWindow.cpp:105
CSerializable.h
TPixelCoord.h
mrpt::gui::mrptEventWindowClosed
An event sent by a window upon when it's about to be closed, either manually by the user or programma...
Definition: CBaseGUIWindow.h:281
mrpt::gui::CBaseGUIWindow::waitForKey
int waitForKey(bool ignoreControlKeys=true, mrptKeyModifier *out_pushModifier=nullptr)
Waits for any key to be pushed on the image or the console, and returns the key code.
Definition: CBaseGUIWindow.cpp:156
mrpt::gui::CBaseGUIWindow::setPos
virtual void setPos(int x, int y)=0
Changes the position of the window on the screen.
mrpt::gui::CWindowDialogPlots
The wx dialog for gui::CDisplayWindowPlots.
Definition: WxSubsystem.h:440
mrpt::gui::mrptEventMouseMove::source_object
CBaseGUIWindow * source_object
Definition: CBaseGUIWindow.h:262
y
GLenum GLint GLint y
Definition: glext.h:3538
mrpt::system::CObservable
Inherit from this class for those objects capable of being observed by a CObserver class.
Definition: CObservable.h:33
mrpt::gui::CBaseGUIWindow::CBaseGUIWindow
CBaseGUIWindow(void *winobj_voidptr, int CMD_CREATE_WIN, int CMD_DESTROY_WIN, const std::string &initial_caption=std::string())
CMD_DESTROY_WIN can be 299,399,499...
Definition: CBaseGUIWindow.cpp:25
x
GLenum GLint x
Definition: glext.h:3538
coords
const GLshort * coords
Definition: glext.h:7386
mrpt::non_copiable_ptr_basic::get
T *& get()
Definition: safe_pointers.h:146
mrpt::non_copiable_ptr_basic< void >
mrpt::gui::mrptEventWindowResize::mrptEventWindowResize
mrptEventWindowResize(CBaseGUIWindow *obj, size_t _new_width, size_t _new_height)
Definition: CBaseGUIWindow.h:199
mrpt::gui::mrptEventWindowChar::source_object
CBaseGUIWindow * source_object
Definition: CBaseGUIWindow.h:179



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST