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
An event sent by a window upon resize.
const int m_CMD_CREATE_WIN
can be 200,300,400...
An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates. ...
const GLshort * coords
Definition: glext.h:7386
int getPushedKey(mrptKeyModifier *out_pushModifier=nullptr)
Returns the latest pushed key, or 0 if there is no new key stroke.
mrptEventMouseMove(CBaseGUIWindow *obj, mrpt::img::TPixelCoord _coords, bool _leftButton, bool _rightButton)
mrpt::void_ptr_noncopy m_hwnd
The window handle.
std::string m_caption
The caption of the window.
virtual void setWindowTitle(const std::string &str)=0
Changes the window title text.
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:33
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.
mrptEventWindowResize(CBaseGUIWindow *obj, size_t _new_width, size_t _new_height)
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...
The wx dialog for gui::CDisplayWindowPlots.
Definition: WxSubsystem.h:440
mrptKeyModifier
Definition: keycodes.h:159
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
virtual void setCursorCross(bool cursorIsCross)=0
Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true) ...
An event sent by a window upon when it&#39;s about to be closed, either manually by the user or programma...
An event sent by a window when the mouse is moved over it.
GLenum GLsizei width
Definition: glext.h:3531
void notifyChildWindowDestruction()
Called by wx main thread to set m_hwnd to NULL.
virtual void do_nothing() override
Just to allow this class to be polymorphic.
virtual void setPos(int x, int y)=0
Changes the position of the window on the screen.
void * getWxObject()
Read-only access to the wxDialog object.
virtual void do_nothing() override
Just to allow this class to be polymorphic.
bool isOpen()
Returns false if the user has already closed the window.
virtual void do_nothing() override
Just to allow this class to be polymorphic.
bool keyHit() const
Returns true if a key has been pushed, without blocking waiting for a new key being pushed...
A pair (x,y) of pixel coordinates (integer resolution).
Definition: TPixelCoord.h:39
The wx dialog for gui::CDisplayWindow.
Definition: WxSubsystem.h:331
const int m_CMD_DESTROY_WIN
can be 299,399,499...
An event sent by a window upon a char pressed by the user.
Inherit from this class for those objects capable of being observed by a CObserver class...
Definition: CObservable.h:33
std::promise< void > m_threadReady
This semaphore will be signaled when the wx window is built and ready.
GLsizei const GLchar ** string
Definition: glext.h:4101
mrptEventMouseDown(CBaseGUIWindow *obj, mrpt::img::TPixelCoord _coords, bool _leftButton, bool _rightButton)
volatile mrptKeyModifier m_keyPushedModifier
mrptEventWindowClosed(CBaseGUIWindow *obj, bool _allow_close=true)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
virtual void do_nothing() override
Just to allow this class to be polymorphic.
virtual void do_nothing() override
Just to allow this class to be polymorphic.
mrpt::img::TPixelCoord coords
mrptKeyModifier key_modifiers
Modifiers (Shift, Control, etc...)
virtual void resize(unsigned int width, unsigned int height)=0
Resizes the window, stretching the image to fit into the display area.
mrptEventWindowChar(CBaseGUIWindow *obj, int _char_code, mrptKeyModifier _key_mod)
virtual bool getLastMousePosition(int &x, int &y) const =0
Gets the last x,y pixel coordinates of the mouse.
void destroyWxWindow()
Must be called by child classes in their destructors.
GLenum GLint GLint y
Definition: glext.h:3538
void createWxWindow(unsigned int initialWidth, unsigned int initialHeight)
Must be called by child classes just within the constructor.
GLenum GLint x
Definition: glext.h:3538
GLenum GLsizei GLsizei height
Definition: glext.h:3554
mrpt::img::TPixelCoord coords
void notifySemThreadReady()
Called by wx main thread to signal the semaphore that the wx window is built and ready.
std::promise< void > m_windowDestroyed
This semaphore will be signaled when the wx window is destroyed.
int char_code
The virtual key code, as defined in <mrpt/gui/keycodes.h> (a replication of wxWidgets key codes)...
The base class for GUI window classes.
void clearKeyHitFlag()
Assure that "keyHit" will return false until the next pushed key.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019