Main MRPT website > C++ reference
MRPT logo
CBaseGUIWindow.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
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/utils/TPixelCoord.h>
00036 #include <mrpt/gui/keycodes.h>
00037 
00038 #include <mrpt/gui/link_pragmas.h>
00039 
00040 
00041 namespace mrpt
00042 {
00043         namespace gui
00044         {
00045                 using namespace mrpt::utils;
00046 
00047                 class CWindowDialog;
00048                 class CWindowDialogPlots;
00049                 class C3DWindowDialog;
00050 
00051                 DEFINE_SERIALIZABLE_PRE_CUSTOM_LINKAGE( CBaseGUIWindow, GUI_IMPEXP )
00052 
00053                 /** The base class for GUI window classes.
00054                   *
00055                   *   This class can be observed (see mrpt::utils::CObserver) for the following events (see mrpt::utils::mrptEvent):
00056                   *   - mrpt::gui::mrptEventWindowChar
00057                   *   - mrpt::gui::mrptEventWindowResize
00058                   *   - mrpt::gui::mrptEventMouseDown
00059                   *
00060                   *  See derived classes to check if they emit other additional events.
00061                   *
00062                   *  IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread,
00063                   *    so all your code in the handler must be thread safe.
00064                   * \ingroup mrpt_gui_grp
00065                   */
00066                 class GUI_IMPEXP CBaseGUIWindow :
00067                         public mrpt::utils::CObject,
00068                         public mrpt::utils::CObservable
00069                 {
00070                         // This must be added to any CSerializable derived class:
00071                         DEFINE_VIRTUAL_SERIALIZABLE( CBaseGUIWindow )
00072 
00073                         friend class CWindowDialog;
00074                         friend class C3DWindowDialog;
00075                         friend class CWindowDialogPlots;
00076 
00077                 private:
00078                         const int       m_CMD_CREATE_WIN;  //!< can be 200,300,400... See WxSubsystem
00079                         const int       m_CMD_DESTROY_WIN;  //!< can be 299,399,499... See WxSubsystem
00080                         void*           m_winobj_voidptr;
00081 
00082                 protected:
00083                         synch::CSemaphore       m_semThreadReady;       //!< This semaphore will be signaled when the wx window is built and ready.
00084                         synch::CSemaphore       m_semWindowDestroyed; //!< This semaphore will be signaled when the wx window is destroyed.
00085                         std::string                     m_caption;      //!< The caption of the window
00086                         void_ptr_noncopy        m_hwnd; //!< The window handle
00087 
00088                         /* Auxiliary */
00089                         volatile bool             m_keyPushed;
00090                         volatile int              m_keyPushedCode;
00091                         volatile mrptKeyModifier  m_keyPushedModifier;
00092 
00093                         void createWxWindow(unsigned int initialWidth, unsigned int initialHeight); //!< Must be called by child classes just within the constructor.
00094                         void destroyWxWindow(); //!< Must be called by child classes in their destructors. The code cannot be put into this class' destructor.
00095 
00096                 public:
00097                         void * getWxObject() { return m_hwnd.get(); } //!< Read-only access to the wxDialog object.
00098                         void notifyChildWindowDestruction();    //!< Called by wx main thread to set m_hwnd to NULL.
00099                         void notifySemThreadReady();    //!< Called by wx main thread to signal the semaphore that the wx window is built and ready.
00100 
00101                 public:
00102                         /** CMD_DESTROY_WIN can be 299,399,499... See WxSubsystem */
00103 
00104                         CBaseGUIWindow(void* winobj_voidptr, int CMD_CREATE_WIN, int CMD_DESTROY_WIN, const std::string &initial_caption = std::string() );
00105                         virtual ~CBaseGUIWindow();
00106 
00107                         /** Returns false if the user has already closed the window.
00108                           */
00109                         bool isOpen();
00110 
00111                         /** Resizes the window, stretching the image to fit into the display area.
00112                          */
00113                         virtual void  resize( unsigned int width, unsigned int height ) = 0;
00114 
00115                         /** Changes the position of the window on the screen.
00116                          */
00117                         virtual void  setPos( int x, int y ) = 0;
00118 
00119                         /** Changes the window title text.
00120                           */
00121                         virtual void setWindowTitle( const std::string &str )=0;
00122 
00123                         /** Gets the last x,y pixel coordinates of the mouse. \return False if the window is closed. */
00124                         virtual bool getLastMousePosition(int &x, int &y) const = 0;
00125 
00126                         /** Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true) */
00127                         virtual void setCursorCross(bool cursorIsCross) = 0;
00128 
00129                         /** Waits for any key to be pushed on the image or the console, and returns the key code.
00130                           *  This method remove key strokes previous to its call, so it will always wait. To get
00131                           *   the latest pushed key, see
00132                           *
00133                           * \param ignoreControlKeys If set to false, any push of shift, cmd, control, etc... will make this method to return.
00134                           * \param out_pushModifier If set to !=NULL, the modifiers of the key stroke will be saved here.
00135                           * \return The virtual key code, as defined in mrptKeyCode (a replication of wxWidgets key codes).
00136                           *
00137                           * \sa getPushedKey, Key codes in the enum mrptKeyCode
00138                           */
00139                         int  waitForKey(bool ignoreControlKeys = true, mrptKeyModifier *out_pushModifier=NULL);
00140 
00141                         /** Returns true if a key has been pushed, without blocking waiting for a new key being pushed.
00142                           * \sa waitForKey, clearKeyHitFlag
00143                           */
00144                         bool  keyHit() const { return m_keyPushed; }
00145 
00146                         /** Assure that "keyHit" will return false until the next pushed key.
00147                           * \sa keyHit, waitForKey
00148                           */
00149                         void  clearKeyHitFlag() { m_keyPushed = false; }
00150 
00151                         /** Returns the latest pushed key, or 0 if there is no new key stroke.
00152                           * \param out_pushModifier If set to !=NULL, the modifiers of the key stroke will be saved here.
00153                           * \return The virtual key code, as defined in <mrpt/gui/keycodes.h> (a replication of wxWidgets key codes).
00154                           *
00155                           * \sa keyHit, waitForKey
00156                           */
00157                         int getPushedKey(mrptKeyModifier *out_pushModifier=NULL);
00158 
00159 
00160                 }; // End of class def.
00161 
00162 
00163                 /** @name Events common to all GUI windows:
00164                         @{  */
00165 
00166                 /**  An event sent by a window upon a char pressed by the user.
00167                   *
00168                   *  IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread,
00169                   *    so all your code in the handler must be thread safe.
00170                   */
00171                 class GUI_IMPEXP mrptEventWindowChar : public mrptEvent
00172                 {
00173                 protected:
00174                         virtual void do_nothing() { } //!< Just to allow this class to be polymorphic
00175                 public:
00176                         inline mrptEventWindowChar(
00177                                 CBaseGUIWindow *obj,
00178                                 int     _char_code,
00179                                 mrptKeyModifier _key_mod
00180                                 ) : source_object(obj), char_code(_char_code), key_modifiers(_key_mod) { }
00181 
00182                         CBaseGUIWindow *source_object;
00183                         int                     char_code; //!< The virtual key code, as defined in <mrpt/gui/keycodes.h> (a replication of wxWidgets key codes).
00184                         mrptKeyModifier key_modifiers; //!< Modifiers (Shift, Control, etc...)
00185                 }; // End of class def.
00186 
00187                 /**  An event sent by a window upon resize.
00188                   *
00189                   *  IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread,
00190                   *    so all your code in the handler must be thread safe.
00191                   */
00192                 class GUI_IMPEXP mrptEventWindowResize : public mrptEvent
00193                 {
00194                 protected:
00195                         virtual void do_nothing() { } //!< Just to allow this class to be polymorphic
00196                 public:
00197                         inline mrptEventWindowResize(
00198                                 CBaseGUIWindow *obj,
00199                                 size_t _new_width,
00200                                 size_t _new_height) : source_object(obj), new_width(_new_width), new_height(_new_width) { }
00201 
00202                         CBaseGUIWindow *source_object;
00203                         size_t new_width, new_height;
00204                 }; // End of class def.
00205 
00206                 /**  An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates.
00207                   *
00208                   *  IMPORTANTE NOTICE: Event handlers in your observer class will be invoked from the wxWidgets internal MRPT thread,
00209                   *    so all your code in the handler must be thread safe.
00210                   *
00211                   * \sa mrptEventMouseDown
00212                   */
00213                 class GUI_IMPEXP mrptEventMouseDown : public mrptEvent
00214                 {
00215                 protected:
00216                         virtual void do_nothing() { } //!< Just to allow this class to be polymorphic
00217                 public:
00218                         inline mrptEventMouseDown (
00219                                 CBaseGUIWindow *obj,
00220                                 mrpt::utils::TPixelCoord  _coords,
00221                                 bool   _leftButton,
00222                                 bool   _rightButton
00223                                 ) : source_object(obj), coords(_coords), leftButton(_leftButton), rightButton(_rightButton)
00224                         { }
00225 
00226                         CBaseGUIWindow *source_object;
00227                         mrpt::utils::TPixelCoord  coords;
00228                         bool   leftButton;
00229                         bool   rightButton;
00230                 }; // End of class def.
00231 
00232                 /**  @} */
00233 
00234         } // End of namespace
00235 
00236 } // End of namespace
00237 
00238 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011