Code Search for Developers
 
 
  

Binder.cpp from palisma2d at Krugle


Show Binder.cpp syntax highlighted

/**
**************************************************************************************
*Palisma - Secrets of the Illuminati is an open-source 2D RPG                        *
*Copyright (C) 2006, Tony Sparks                                                     *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#include "StdAfx.h"
#include "Binder.h"
#include "../shared/stringutil.h"
#include <stdlib.h>
#include "../kernel.h"

extern Kernel* g_kernel;

Binder::Binder(void)
{
}


/** Bind a key to an action */
void Binder::Bind( int key, const std::string function)
{
    m_bindings[key] = function;
}
/** Unbind a key from an action */
void Binder::UnBind( int key )
{
    std::map<int, std::string >::iterator it = m_bindings.begin();
    for(; it != m_bindings.end(); it++ )
    {
        if ( it->first == key ) {
            m_bindings.erase( it );
            return;
        }
    }
}
/** Unbind all keys */
void Binder::UnBindAll()
{
    m_bindings.clear();
}
/** Execute the key bind, if any */
void Binder::Exec( int key )
{
    // first test to see if it is a valid bind
    if ( m_bindings.find( key ) != m_bindings.end() )
    {
        // exec the string
        g_kernel->GetConsole()->Exec( m_bindings[key] );
    }
}

Binder::~Binder(void)
{
    //UnBindAll();
}






See more files for this project here

palisma2d

The University of Wisconsin-Parkside Developers Union first product. More info to come. Code name Palisma.

Project homepage: http://code.google.com/p/palisma2d/
Programming language(s): C,C++
License: gpl2

  Binder.cpp
  Binder.h
  IInput.h
  Input.cpp
  Input.h
  InputBuffer.cpp
  InputBuffer.h
  KeyConverter.cpp
  KeyConverter.h
  stdafx.cpp
  stdafx.h