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