Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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
19#include <mrpt/gui/keycodes.h>
20#include <mrpt/gui/gui_frwds.h>
21
23
24namespace 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,
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
#define DEFINE_MRPT_OBJECT_POST_CUSTOM_LINKAGE(class_name, _LINKAGE_)
Definition: CObject.h:207
#define DEFINE_MRPT_OBJECT_PRE_CUSTOM_LINKAGE(class_name, _LINKAGE_)
Definition: CObject.h:206
#define DEFINE_VIRTUAL_SERIALIZABLE(class_name)
This declaration must be inserted in virtual CSerializable classes definition:
The base class for GUI window classes.
virtual void setPos(int x, int y)=0
Changes the position of the window on the screen.
virtual bool getLastMousePosition(int &x, int &y) const =0
Gets the last x,y pixel coordinates of the mouse.
void notifyChildWindowDestruction()
Called by wx main thread to set m_hwnd to NULL.
bool keyHit() const
Returns true if a key has been pushed, without blocking waiting for a new key being pushed.
bool isOpen()
Returns false if the user has already closed the window.
virtual void setCursorCross(bool cursorIsCross)=0
Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true)
void clearKeyHitFlag()
Assure that "keyHit" will return false until the next pushed key.
virtual void resize(unsigned int width, unsigned int height)=0
Resizes the window, stretching the image to fit into the display area.
int getPushedKey(mrptKeyModifier *out_pushModifier=NULL)
Returns the latest pushed key, or 0 if there is no new key stroke.
int waitForKey(bool ignoreControlKeys=true, mrptKeyModifier *out_pushModifier=NULL)
Waits for any key to be pushed on the image or the console, and returns the key code.
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... See WxSubsystem.
void notifySemThreadReady()
Called by wx main thread to signal the semaphore that the wx window is built and ready.
virtual void setWindowTitle(const std::string &str)=0
Changes the window title text.
An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates.
virtual void do_nothing() MRPT_OVERRIDE
Just to allow this class to be polymorphic.
mrpt::utils::TPixelCoord coords
mrptEventMouseDown(CBaseGUIWindow *obj, mrpt::utils::TPixelCoord _coords, bool _leftButton, bool _rightButton)
An event sent by a window upon a char pressed by the user.
mrptKeyModifier key_modifiers
Modifiers (Shift, Control, etc...)
virtual void do_nothing() MRPT_OVERRIDE
Just to allow this class to be polymorphic.
int char_code
The virtual key code, as defined in <mrpt/gui/keycodes.h> (a replication of wxWidgets key codes).
mrptEventWindowChar(CBaseGUIWindow *obj, int _char_code, mrptKeyModifier _key_mod)
An event sent by a window upon when it's about to be closed, either manually by the user or programat...
mrptEventWindowClosed(CBaseGUIWindow *obj, bool _allow_close=true)
virtual void do_nothing() MRPT_OVERRIDE
Just to allow this class to be polymorphic.
An event sent by a window upon resize.
mrptEventWindowResize(CBaseGUIWindow *obj, size_t _new_width, size_t _new_height)
virtual void do_nothing() MRPT_OVERRIDE
Just to allow this class to be polymorphic.
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:35
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition: mrpt_macros.h:28
mrptKeyModifier
Definition: keycodes.h:159
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
STL namespace.
A pair (x,y) of pixel coordinates (integer resolution).
Definition: TPixelCoord.h:38



Page generated by Doxygen 1.9.6 for MRPT 1.4.0 SVN: at Tue Jan 17 22:27:43 UTC 2023