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