keyboard_event.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010-2011, Willow Garage, Inc.
00006  *  Copyright (c) 2012-, Open Perception, Inc.
00007  *
00008  *  All rights reserved.
00009  *
00010  *  Redistribution and use in source and binary forms, with or without
00011  *  modification, are permitted provided that the following conditions
00012  *  are met:
00013  *
00014  *   * Redistributions of source code must retain the above copyright
00015  *     notice, this list of conditions and the following disclaimer.
00016  *   * Redistributions in binary form must reproduce the above
00017  *     copyright notice, this list of conditions and the following
00018  *     disclaimer in the documentation and/or other materials provided
00019  *     with the distribution.
00020  *   * Neither the name of the copyright holder(s) nor the names of its
00021  *     contributors may be used to endorse or promote products derived
00022  *     from this software without specific prior written permission.
00023  *
00024  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  *  POSSIBILITY OF SUCH DAMAGE.
00036  *
00037  */
00038 
00039 #ifndef PCL_VISUALIZATION_KEYBOARD_EVENT_H_
00040 #define PCL_VISUALIZATION_KEYBOARD_EVENT_H_
00041 
00042 #include <string>
00043 
00044 namespace pcl
00045 {
00046   namespace visualization
00047   {
00049     class KeyboardEvent
00050     {
00051       public:
00053         static const unsigned int Alt   = 1;
00055         static const unsigned int Ctrl  = 2;
00057         static const unsigned int Shift = 4;
00058 
00067         inline KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, 
00068                               bool alt, bool ctrl, bool shift);
00069 
00073         inline bool 
00074         isAltPressed () const;
00075         
00079         inline bool 
00080         isCtrlPressed () const;
00081         
00085         inline bool 
00086         isShiftPressed () const;
00087 
00091         inline unsigned char 
00092         getKeyCode () const;
00093         
00097         inline const std::string& 
00098         getKeySym () const;
00099         
00103         inline bool 
00104         keyDown () const;
00105         
00109         inline bool 
00110         keyUp () const;
00111 
00112       protected:
00113 
00114         bool action_;
00115         unsigned int modifiers_;
00116         unsigned char key_code_;
00117         std::string key_sym_;
00118     };
00119 
00120     KeyboardEvent::KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, 
00121                                   bool alt, bool ctrl, bool shift)
00122       : action_ (action)
00123       , modifiers_ (0)
00124       , key_code_(key)
00125       , key_sym_ (key_sym)
00126     {
00127       if (alt)
00128         modifiers_ = Alt;
00129 
00130       if (ctrl)
00131         modifiers_ |= Ctrl;
00132 
00133       if (shift)
00134         modifiers_ |= Shift;
00135     }
00136 
00137     bool 
00138     KeyboardEvent::isAltPressed () const
00139     {
00140       return (modifiers_ & Alt) != 0;
00141     }
00142 
00143     bool 
00144     KeyboardEvent::isCtrlPressed () const
00145     {
00146       return (modifiers_ & Ctrl) != 0;
00147     }
00148 
00149     bool 
00150     KeyboardEvent::isShiftPressed () const
00151     {
00152       return (modifiers_ & Shift) != 0;
00153     }
00154 
00155     unsigned char 
00156     KeyboardEvent::getKeyCode () const
00157     {
00158       return (key_code_);
00159     }
00160 
00161     const std::string& 
00162     KeyboardEvent::getKeySym () const
00163     {
00164       return (key_sym_);
00165     }
00166 
00167     bool 
00168     KeyboardEvent::keyDown () const
00169     {
00170       return (action_);
00171     }
00172 
00173     bool 
00174     KeyboardEvent::keyUp () const
00175     {
00176       return (!action_);
00177     }  
00178   } // namespace visualization
00179 } // namespace pcl
00180 
00181 #endif  /* PCL_VISUALIZATION_KEYBOARD_EVENT_H_ */
00182 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:25:05