Main MRPT website > C++ reference for MRPT 1.5.3
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 
12 #include <mrpt/synch/CSemaphore.h>
14 #include <mrpt/utils/mrptEvent.h>
15 #include <mrpt/utils/CObservable.h>
17 #include <mrpt/utils/TPixelCoord.h>
18 #include <mrpt/utils/mrptEvent.h>
19 #include <mrpt/gui/keycodes.h>
20 #include <mrpt/gui/gui_frwds.h>
21 
22 #include <mrpt/gui/link_pragmas.h>
23 
24 namespace mrpt
25 {
26  namespace gui
27  {
29 
30  /** The base class for GUI window classes.
31  *
32  * This class can be observed (see mrpt::utils::CObserver) for the following events (see mrpt::utils::mrptEvent):
33  * - mrpt::gui::mrptEventWindowChar
34  * - mrpt::gui::mrptEventWindowResize
35  * - mrpt::gui::mrptEventMouseDown
36  * - mrpt::gui::mrptEventWindowClosed
37  *
38  * See derived classes to check if they emit other additional events.
39  *
40  * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked 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  public mrpt::utils::CObject,
46  public mrpt::utils::CObservable
47  {
48  // This must be added to any CSerializable derived class:
50 
51  friend class CWindowDialog;
52  friend class C3DWindowDialog;
53  friend class CWindowDialogPlots;
54 
55  private:
56  const int m_CMD_CREATE_WIN; //!< can be 200,300,400... See WxSubsystem
57  const int m_CMD_DESTROY_WIN; //!< can be 299,399,499... See WxSubsystem
58  void* m_winobj_voidptr;
59 
60  protected:
61  synch::CSemaphore m_semThreadReady; //!< This semaphore will be signaled when the wx window is built and ready.
62  synch::CSemaphore m_semWindowDestroyed; //!< This semaphore will be signaled when the wx window is destroyed.
63  std::string m_caption; //!< The caption of the window
64  mrpt::utils::void_ptr_noncopy m_hwnd; //!< The window handle
65 
66  /* Auxiliary */
67  volatile bool m_keyPushed;
68  volatile int m_keyPushedCode;
69  volatile mrptKeyModifier m_keyPushedModifier;
70 
71  void createWxWindow(unsigned int initialWidth, unsigned int initialHeight); //!< Must be called by child classes just within the constructor.
72  void destroyWxWindow(); //!< Must be called by child classes in their destructors. The code cannot be put into this class' destructor.
73 
74  public:
75  void * getWxObject() { return m_hwnd.get(); } //!< Read-only access to the wxDialog object.
76  void notifyChildWindowDestruction(); //!< Called by wx main thread to set m_hwnd to NULL.
77  void notifySemThreadReady(); //!< Called by wx main thread to signal the semaphore that the wx window is built and ready.
78 
79  public:
80  /** CMD_DESTROY_WIN can be 299,399,499... See WxSubsystem */
81 
82  CBaseGUIWindow(void* winobj_voidptr, int CMD_CREATE_WIN, int CMD_DESTROY_WIN, const std::string &initial_caption = std::string() );
83  virtual ~CBaseGUIWindow();
84 
85  /** Returns false if the user has already closed the window.
86  */
87  bool isOpen();
88 
89  /** Resizes the window, stretching the image to fit into the display area.
90  */
91  virtual void resize( unsigned int width, unsigned int height ) = 0;
92 
93  /** Changes the position of the window on the screen.
94  */
95  virtual void setPos( int x, int y ) = 0;
96 
97  /** Changes the window title text.
98  */
99  virtual void setWindowTitle( const std::string &str )=0;
100 
101  /** Gets the last x,y pixel coordinates of the mouse. \return False if the window is closed. */
102  virtual bool getLastMousePosition(int &x, int &y) const = 0;
103 
104  /** Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true) */
105  virtual void setCursorCross(bool cursorIsCross) = 0;
106 
107  /** Waits for any key to be pushed on the image or the console, and returns the key code.
108  * This method remove key strokes previous to its call, so it will always wait. To get
109  * the latest pushed key, see
110  *
111  * \param ignoreControlKeys If set to false, any push of shift, cmd, control, etc... will make this method to return.
112  * \param out_pushModifier If set to !=NULL, the modifiers of the key stroke will be saved here.
113  * \return The virtual key code, as defined in mrptKeyCode (a replication of wxWidgets key codes).
114  *
115  * \sa getPushedKey, Key codes in the enum mrptKeyCode
116  */
117  int waitForKey(bool ignoreControlKeys = true, mrptKeyModifier *out_pushModifier=NULL);
118 
119  /** Returns true if a key has been pushed, without blocking waiting for a new key being pushed.
120  * \sa waitForKey, clearKeyHitFlag
121  */
122  bool keyHit() const { return m_keyPushed; }
123 
124  /** Assure that "keyHit" will return false until the next pushed key.
125  * \sa keyHit, waitForKey
126  */
127  void clearKeyHitFlag() { m_keyPushed = false; }
128 
129  /** Returns the latest pushed key, or 0 if there is no new key stroke.
130  * \param out_pushModifier If set to !=NULL, the modifiers of the key stroke will be saved here.
131  * \return The virtual key code, as defined in <mrpt/gui/keycodes.h> (a replication of wxWidgets key codes).
132  *
133  * \sa keyHit, waitForKey
134  */
135  int getPushedKey(mrptKeyModifier *out_pushModifier=NULL);
136 
137 
138  }; // End of class def.
140 
141 
142  /** @name Events common to all GUI windows:
143  @{ */
144 
145  /** An event sent by a window upon a char pressed by the user.
146  *
147  * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread,
148  * so all your code in the handler must be thread safe.
149  */
150  class GUI_IMPEXP mrptEventWindowChar : public mrpt::utils::mrptEvent
151  {
152  protected:
153  virtual void do_nothing() MRPT_OVERRIDE { } //!< Just to allow this class to be polymorphic
154  public:
156  CBaseGUIWindow *obj,
157  int _char_code,
158  mrptKeyModifier _key_mod
159  ) : source_object(obj), char_code(_char_code), key_modifiers(_key_mod) { }
160 
162  int char_code; //!< The virtual key code, as defined in <mrpt/gui/keycodes.h> (a replication of wxWidgets key codes).
163  mrptKeyModifier key_modifiers; //!< Modifiers (Shift, Control, etc...)
164  }; // End of class def.
165 
166  /** An event sent by a window upon resize.
167  *
168  * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread,
169  * so all your code in the handler must be thread safe.
170  */
172  {
173  protected:
174  virtual void do_nothing() MRPT_OVERRIDE { } //!< Just to allow this class to be polymorphic
175  public:
177  CBaseGUIWindow *obj,
178  size_t _new_width,
179  size_t _new_height) : source_object(obj), new_width(_new_width), new_height(_new_height) { }
180 
182  size_t new_width, new_height;
183  }; // End of class def.
184 
185  /** An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates.
186  *
187  * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread,
188  * so all your code in the handler must be thread safe.
189  *
190  * \sa mrptEventMouseDown
191  */
193  {
194  protected:
195  virtual void do_nothing() MRPT_OVERRIDE { } //!< Just to allow this class to be polymorphic
196  public:
198  CBaseGUIWindow *obj,
199  mrpt::utils::TPixelCoord _coords,
200  bool _leftButton,
201  bool _rightButton
202  ) : source_object(obj), coords(_coords), leftButton(_leftButton), rightButton(_rightButton)
203  { }
204 
209  }; // End of class def.
210 
211  /** An event sent by a window upon when it's about to be closed, either manually by the user or programatically.
212  * The event field member \a allow_close is default by default, but can be set to false in the event callback
213  * to forbid the window to be closed by the user. If the event corresponds to a programatic close, this field is ignored.
214  *
215  * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread,
216  * so all your code in the handler must be thread safe.
217  *
218  * \sa CBaseGUIWindow
219  */
221  {
222  protected:
223  virtual void do_nothing() MRPT_OVERRIDE { } //!< Just to allow this class to be polymorphic
224  public:
226  CBaseGUIWindow *obj,
227  bool _allow_close = true )
228  : source_object(obj), allow_close(_allow_close)
229  { }
232  }; // End of class def.
233 
234  /** @} */
235 
236  } // End of namespace
237 
238 } // End of namespace
239 
240 #endif
An event sent by a window upon resize.
An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates. ...
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:34
A pair (x,y) of pixel coordinates (integer resolution).
Definition: TPixelCoord.h:37
mrptEventWindowResize(CBaseGUIWindow *obj, size_t _new_width, size_t _new_height)
The wx dialog for gui::CDisplayWindowPlots.
Definition: WxSubsystem.h:402
mrptKeyModifier
Definition: keycodes.h:158
STL namespace.
An event sent by a window upon when it&#39;s about to be closed, either manually by the user or programat...
#define DEFINE_VIRTUAL_SERIALIZABLE(class_name)
This declaration must be inserted in virtual CSerializable classes definition:
mrpt::utils::TPixelCoord coords
class BASE_IMPEXP CObject
Definition: CObject.h:26
virtual void do_nothing() MRPT_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:290
virtual void do_nothing() MRPT_OVERRIDE
Just to allow this class to be polymorphic.
virtual void do_nothing() MRPT_OVERRIDE
Just to allow this class to be polymorphic.
An event sent by a window upon a char pressed by the user.
virtual void do_nothing() MRPT_OVERRIDE
Just to allow this class to be polymorphic.
non_copiable_ptr_basic< void > void_ptr_noncopy
mrptEventWindowClosed(CBaseGUIWindow *obj, bool _allow_close=true)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrptEventMouseDown(CBaseGUIWindow *obj, mrpt::utils::TPixelCoord _coords, bool _leftButton, bool _rightButton)
mrptKeyModifier key_modifiers
Modifiers (Shift, Control, etc...)
#define DEFINE_MRPT_OBJECT_PRE_CUSTOM_LINKAGE(class_name, _LINKAGE_)
Definition: CObject.h:210
mrptEventWindowChar(CBaseGUIWindow *obj, int _char_code, mrptKeyModifier _key_mod)
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t x(y+z)
int char_code
The virtual key code, as defined in <mrpt/gui/keycodes.h> (a replication of wxWidgets key codes)...
#define DEFINE_MRPT_OBJECT_POST_CUSTOM_LINKAGE(class_name, _LINKAGE_)
Definition: CObject.h:211
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.13 for MRPT 1.5.3 at Mon Oct 30 10:27:08 UTC 2017