Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

KeyStroke.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "KeyStroke.h"
00010 
00011 #include "StringTool.h"
00012 
00013 //-----------------------------------------------------------------
00014 /**
00015  * Create new keystroke from event.
00016  */
00017 KeyStroke::KeyStroke(const SDL_keysym &keysym)
00018 {
00019     m_sym = keysym.sym;
00020     m_mod = modStrip(keysym.mod);
00021     m_unicode = keysym.unicode;
00022 }
00023 //-----------------------------------------------------------------
00024 /**
00025  * Create new keystroke.
00026  * NOTE: KMOD_ALT mean (KMOD_LALT and KMOD_RALT),
00027  * i.e. either ALTs pressed!
00028  *
00029  * @param sym SDLKey
00030  * @param mod SDLMod ored
00031  */
00032 KeyStroke::KeyStroke(SDLKey sym, int mod)
00033 {
00034     m_sym = sym;
00035     m_mod = modStrip(mod);
00036     m_unicode = 0;
00037 }
00038 //-----------------------------------------------------------------
00039 /**
00040  * Strip ignored modes.
00041  * KMOD_SHIFT|KMOD_NUM|KMOD_CAPS|KMOD_MODE are ignored.
00042  */
00043     int
00044 KeyStroke::modStrip(int mod)
00045 {
00046     return mod & ~STROKE_IGNORE;
00047 }
00048 //-----------------------------------------------------------------
00049 /**
00050  * KeyStroke comparation.
00051  *
00052  * @param other other keystroke
00053  * @return this < other
00054  */
00055 bool
00056 KeyStroke::less(const KeyStroke &other) const
00057 {
00058     bool result = m_sym < other.m_sym;
00059     if (m_sym == other.m_sym) {
00060         result = m_mod < other.m_mod;
00061     }
00062     return result;
00063 }
00064 //-----------------------------------------------------------------
00065 /**
00066  * Test keyStroke equality.
00067  * KMOD_NUM|KMOD_CAPS|KMOD_MODE are ignored.
00068  *
00069  * @param other other keystroke
00070  * @return this == other
00071  */
00072 bool
00073 KeyStroke::equals(const KeyStroke &other) const
00074 {
00075     return m_sym == other.m_sym &&
00076         m_mod == other.m_mod;
00077 }
00078 //-----------------------------------------------------------------
00079 /**
00080  * Return text fashion.
00081  */
00082 std::string
00083 KeyStroke::toString() const
00084 {
00085     std::string result = SDL_GetKeyName(m_sym);
00086     result.append("+" + StringTool::toString(m_mod));
00087     return result;
00088 }
00089 

Generated on Wed Jun 1 09:54:31 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2