00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2011 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef CBaseGUIWindow_H 00029 #define CBaseGUIWindow_H 00030 00031 #include <mrpt/synch.h> 00032 #include <mrpt/utils/CSerializable.h> 00033 #include <mrpt/utils/CObservable.h> 00034 #include <mrpt/utils/safe_pointers.h> 00035 #include <mrpt/gui/keycodes.h> 00036 00037 #include <mrpt/gui/link_pragmas.h> 00038 00039 00040 namespace mrpt 00041 { 00042 namespace gui 00043 { 00044 using namespace mrpt::utils; 00045 00046 class CWindowDialog; 00047 class CWindowDialogPlots; 00048 class C3DWindowDialog; 00049 00050 DEFINE_SERIALIZABLE_PRE_CUSTOM_LINKAGE( CBaseGUIWindow, GUI_IMPEXP ) 00051 00052 /** The base class for GUI window classes. 00053 * 00054 * This class can be observed (see mrpt::utils::CObserver) for the following events (see mrpt::utils::mrptEvent): 00055 * - mrpt::gui::mrptEventWindowChar 00056 * - mrpt::gui::mrptEventWindowResize 00057 * - mrpt::gui::mrptEventMouseDown 00058 * 00059 * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread, 00060 * so all your code in the handler must be thread safe. 00061 * 00062 */ 00063 class GUI_IMPEXP CBaseGUIWindow : 00064 public mrpt::utils::CObject, 00065 public mrpt::utils::CObservable 00066 { 00067 // This must be added to any CSerializable derived class: 00068 DEFINE_VIRTUAL_SERIALIZABLE( CBaseGUIWindow ) 00069 00070 friend class CWindowDialog; 00071 friend class C3DWindowDialog; 00072 friend class CWindowDialogPlots; 00073 00074 private: 00075 const int m_CMD_CREATE_WIN; //!< can be 200,300,400... See WxSubsystem 00076 const int m_CMD_DESTROY_WIN; //!< can be 299,399,499... See WxSubsystem 00077 void* m_winobj_voidptr; 00078 00079 protected: 00080 synch::CSemaphore m_semThreadReady; //!< This semaphore will be signaled when the wx window is built and ready. 00081 synch::CSemaphore m_semWindowDestroyed; //!< This semaphore will be signaled when the wx window is destroyed. 00082 std::string m_caption; //!< The caption of the window 00083 void_ptr_noncopy m_hwnd; //!< The window handle 00084 00085 /* Auxiliary */ 00086 volatile bool m_keyPushed; 00087 volatile int m_keyPushedCode; 00088 volatile mrptKeyModifier m_keyPushedModifier; 00089 00090 void createWxWindow(unsigned int initialWidth, unsigned int initialHeight); //!< Must be called by child classes just within the constructor. 00091 00092 public: 00093 void * getWxObject() { return m_hwnd.get(); } //!< Read-only access to the wxDialog object. 00094 void notifyChildWindowDestruction(); //!< Called by wx main thread to set m_hwnd to NULL. 00095 void notifySemThreadReady(); //!< Called by wx main thread to signal the semaphore that the wx window is built and ready. 00096 00097 public: 00098 /** CMD_DESTROY_WIN can be 299,399,499... See WxSubsystem */ 00099 00100 CBaseGUIWindow(void* winobj_voidptr, int CMD_CREATE_WIN, int CMD_DESTROY_WIN, const std::string &initial_caption = std::string() ); 00101 virtual ~CBaseGUIWindow(); 00102 00103 /** Returns false if the user has already closed the window. 00104 */ 00105 bool isOpen(); 00106 00107 /** Resizes the window, stretching the image to fit into the display area. 00108 */ 00109 virtual void resize( unsigned int width, unsigned int height ) = 0; 00110 00111 /** Changes the position of the window on the screen. 00112 */ 00113 virtual void setPos( int x, int y ) = 0; 00114 00115 /** Changes the window title text. 00116 */ 00117 virtual void setWindowTitle( const std::string &str )=0; 00118 00119 /** Gets the last x,y pixel coordinates of the mouse. \return False if the window is closed. */ 00120 virtual bool getLastMousePosition(int &x, int &y) const = 0; 00121 00122 /** Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true) */ 00123 virtual void setCursorCross(bool cursorIsCross) = 0; 00124 00125 /** Waits for any key to be pushed on the image or the console, and returns the key code. 00126 * This method remove key strokes previous to its call, so it will always wait. To get 00127 * the latest pushed key, see 00128 * 00129 * \param ignoreControlKeys If set to false, any push of shift, cmd, control, etc... will make this method to return. 00130 * \param out_pushModifier If set to !=NULL, the modifiers of the key stroke will be saved here. 00131 * \return The virtual key code, as defined in mrptKeyCode (a replication of wxWidgets key codes). 00132 * 00133 * \sa getPushedKey, Key codes in the enum mrptKeyCode 00134 */ 00135 int waitForKey(bool ignoreControlKeys = true, mrptKeyModifier *out_pushModifier=NULL); 00136 00137 /** Returns true if a key has been pushed, without blocking waiting for a new key being pushed. 00138 * \sa waitForKey, clearKeyHitFlag 00139 */ 00140 bool keyHit() const { return m_keyPushed; } 00141 00142 /** Assure that "keyHit" will return false until the next pushed key. 00143 * \sa keyHit, waitForKey 00144 */ 00145 void clearKeyHitFlag() { m_keyPushed = false; } 00146 00147 /** Returns the latest pushed key, or 0 if there is no new key stroke. 00148 * \param out_pushModifier If set to !=NULL, the modifiers of the key stroke will be saved here. 00149 * \return The virtual key code, as defined in <mrpt/gui/keycodes.h> (a replication of wxWidgets key codes). 00150 * 00151 * \sa keyHit, waitForKey 00152 */ 00153 int getPushedKey(mrptKeyModifier *out_pushModifier=NULL); 00154 00155 00156 }; // End of class def. 00157 00158 00159 /** @name Events common to all GUI windows: 00160 @{ */ 00161 00162 /** An event sent by a window upon a char pressed by the user. 00163 * 00164 * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread, 00165 * so all your code in the handler must be thread safe. 00166 */ 00167 class GUI_IMPEXP mrptEventWindowChar : public mrptEvent 00168 { 00169 protected: 00170 virtual void do_nothing() { } //!< Just to allow this class to be polymorphic 00171 public: 00172 inline mrptEventWindowChar( 00173 CBaseGUIWindow *obj, 00174 int _char_code, 00175 mrptKeyModifier _key_mod 00176 ) : source_object(obj), char_code(_char_code), key_modifiers(_key_mod) { } 00177 00178 CBaseGUIWindow *source_object; 00179 int char_code; //!< The virtual key code, as defined in <mrpt/gui/keycodes.h> (a replication of wxWidgets key codes). 00180 mrptKeyModifier key_modifiers; //!< Modifiers (Shift, Control, etc...) 00181 }; // End of class def. 00182 00183 /** An event sent by a window upon resize. 00184 * 00185 * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread, 00186 * so all your code in the handler must be thread safe. 00187 */ 00188 class GUI_IMPEXP mrptEventWindowResize : public mrptEvent 00189 { 00190 protected: 00191 virtual void do_nothing() { } //!< Just to allow this class to be polymorphic 00192 public: 00193 inline mrptEventWindowResize( 00194 CBaseGUIWindow *obj, 00195 size_t _new_width, 00196 size_t _new_height) : source_object(obj), new_width(_new_width), new_height(_new_width) { } 00197 00198 CBaseGUIWindow *source_object; 00199 size_t new_width, new_height; 00200 }; // End of class def. 00201 00202 /** An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates. 00203 * 00204 * IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread, 00205 * so all your code in the handler must be thread safe. 00206 * 00207 * \sa mrptEventMouseDown 00208 */ 00209 class GUI_IMPEXP mrptEventMouseDown : public mrptEvent 00210 { 00211 protected: 00212 virtual void do_nothing() { } //!< Just to allow this class to be polymorphic 00213 public: 00214 inline mrptEventMouseDown ( 00215 CBaseGUIWindow *obj, 00216 mrpt::utils::TPixelCoord _coords, 00217 bool _leftButton, 00218 bool _rightButton 00219 ) : source_object(obj), coords(_coords), leftButton(_leftButton), rightButton(_rightButton) 00220 { } 00221 00222 CBaseGUIWindow *source_object; 00223 mrpt::utils::TPixelCoord coords; 00224 bool leftButton; 00225 bool rightButton; 00226 }; // End of class def. 00227 00228 /** @} */ 00229 00230 } // End of namespace 00231 00232 } // End of namespace 00233 00234 #endif
Page generated by Doxygen 1.7.1 for MRPT 0.9.4 SVN: at Mon Jan 10 23:33:19 UTC 2011 |