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  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of Willow Garage, Inc. nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  * Author: Suat Gedikli (gedikli@willowgarage.com)
00037  *
00038  */
00039 
00040 #ifndef PCL_VISUALIZATION_KEYBOARD_EVENT_H_
00041 #define PCL_VISUALIZATION_KEYBOARD_EVENT_H_
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 Mon Oct 6 2014 03:15:32