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