- Your Widget Set For OpenGL
Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Related Pages

uinputmap.hpp

00001 /*************************************************************************** 00002 LibUFO - UI For OpenGL 00003 copyright : (C) 2001-2005 by Johannes Schmidt 00004 email : schmidtjf at users.sourceforge.net 00005 ------------------- 00006 00007 file : include/ufo/uinputmap.hpp 00008 begin : Tue Feb 12 2002 00009 $Id: uinputmap.hpp,v 1.12 2005/05/22 17:54:40 schmidtjf Exp $ 00010 ***************************************************************************/ 00011 00012 /*************************************************************************** 00013 * This library is free software; you can redistribute it and/or * 00014 * modify it under the terms of the GNU Lesser General Public * 00015 * License as published by the Free Software Foundation; either * 00016 * version 2.1 of the License, or (at your option) any later version. * 00017 * * 00018 * This library is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00021 * Lesser General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU Lesser General Public * 00024 * License along with this library; if not, write to the Free Software * 00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 00026 ***************************************************************************/ 00027 00028 #ifndef UINPUTMAP_HPP 00029 #define UINPUTMAP_HPP 00030 00031 #include "uobject.hpp" 00032 00033 #include "ukeystroke.hpp" 00034 #include "signals/ufo_signals.hpp" 00035 #include "events/uactionevent.hpp" 00036 00037 namespace ufo { 00038 00050 class UFO_EXPORT UInputMap : public UObject { 00051 UFO_DECLARE_DYNAMIC_CLASS(UInputMap) 00052 public: 00053 void put(const UKeyStroke & strokeA, const UActionSlot & listenerA); 00054 void remove(const UKeyStroke & strokeA); 00055 UActionSlot * get(const UKeyStroke & strokeA); 00056 00057 void clear(); 00058 private: 00059 typedef std::map<UKeyStroke, UActionSlot> MapType; 00060 MapType m_map; 00061 }; 00062 00063 00067 00068 inline void 00069 UInputMap::put(const UKeyStroke & strokeA, const UActionSlot & listenerA) { 00070 m_map[strokeA] = listenerA; 00071 } 00072 00073 inline void 00074 UInputMap::remove(const UKeyStroke & strokeA) { 00075 m_map.erase(strokeA); 00076 } 00077 00078 inline UActionSlot * 00079 UInputMap::get(const UKeyStroke & strokeA) { 00080 // we have to use == operator as map.find produces wrong results for 00081 // Shift, Alt and Ctrl 00082 for (MapType::iterator iter = m_map.begin(); 00083 iter != m_map.end(); 00084 ++iter) { 00085 if ((*iter).first == strokeA) { 00086 return &((*iter).second); 00087 } 00088 } 00089 /* 00090 MapType::iterator iter; 00091 iter = m_map.find(strokeA); 00092 if (iter != m_map.end()) { 00093 return &((*iter).second); 00094 }*/ 00095 return NULL; 00096 } 00097 00098 inline void 00099 UInputMap::clear() { 00100 m_map.clear(); 00101 } 00102 00103 } // namespace ufo 00104 00105 #endif // UINPUTMAP_HPP

The libUFO Project - written by Johannes Schmidt