Merge branch 'master' of https://git.epicsparrow.com/epicsparrow/sparrowinput
This commit is contained in:
commit
da406827b1
@ -1,53 +1,15 @@
|
||||
project(SparrowInput)
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
if(WIN32)
|
||||
set(SYSTEM_LIB_PATH "win32")
|
||||
else(WIN32)
|
||||
set(SYSTEM_LIB_PATH "linux")
|
||||
endif(WIN32)
|
||||
# choose source file
|
||||
file(GLOB LIB_SRC_LIST src/*.cpp)
|
||||
file(GLOB LIB_HEAD_LIST src/*.h)
|
||||
list(REMOVE_ITEM LIB_SRC_LIST src/main.cpp)
|
||||
set(EXEC_SRC_LIST src/main.cpp)
|
||||
|
||||
set(LIB_SRC_LIST input.cpp keybindings.cpp textbuffer.cpp)
|
||||
#set compilation option
|
||||
set(IS_LIBRARY True)
|
||||
set(USE_OPENGL True)
|
||||
set(USE_SFML True)
|
||||
|
||||
set(EXECUTABLE_NAME "test${PROJECT_NAME}")
|
||||
set(LIBRARY_NAME ${PROJECT_NAME})
|
||||
|
||||
set(DEPENDENCIES_ROOT ${PROJECT_SOURCE_DIR}/../cpp_dependencies)
|
||||
set(INCLUDE_ROOT ${DEPENDENCIES_ROOT}/include)
|
||||
set(LIB_ROOT ${DEPENDENCIES_ROOT}/lib/${SYSTEM_LIB_PATH})
|
||||
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB_ROOT}) #for SHARED
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB_ROOT}) #for STATIC
|
||||
|
||||
add_library(${LIBRARY_NAME} STATIC ${LIB_SRC_LIST})
|
||||
add_executable(${EXECUTABLE_NAME} main.cpp)
|
||||
add_definitions(-std=c++11)
|
||||
|
||||
include_directories(
|
||||
${INCLUDE_ROOT}
|
||||
)
|
||||
|
||||
find_library(SFML_LIBRARY_WINDOW
|
||||
NAMES
|
||||
sfml-window
|
||||
PATHS
|
||||
${LIB_ROOT}
|
||||
)
|
||||
|
||||
find_library(SFML_LIBRARY_SYSTEM
|
||||
NAMES
|
||||
sfml-system
|
||||
PATHS
|
||||
${LIB_ROOT}
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
${LIBRARY_NAME}
|
||||
${SFML_LIBRARY_WINDOW}
|
||||
${SFML_LIBRARY_SYSTEM}
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
${EXECUTABLE_NAME}
|
||||
${LIBRARY_NAME}
|
||||
)
|
||||
include(../cmaketemplate/template.cmake)
|
||||
|
@ -16,10 +16,10 @@ IKeysMap::IKeysMap()
|
||||
}
|
||||
|
||||
std::vector<Binding> IKeysMap::getBindings(int action) const {
|
||||
std::vector<Binding> bindings;
|
||||
for (auto binding : keys)
|
||||
if (binding.action == action) bindings.push_back(binding);
|
||||
return bindings;
|
||||
std::vector<Binding> bindings;
|
||||
for (auto binding : keys)
|
||||
if (binding.action == action) bindings.push_back(binding);
|
||||
return bindings;
|
||||
}
|
||||
|
||||
/* Implementation of KeyBindings class
|
||||
@ -33,54 +33,82 @@ KeyBindings::KeyBindings()
|
||||
}
|
||||
KeyBindings::KeyBindings(const Context &context, const IKeysMap &keysmap)
|
||||
{
|
||||
std::vector<int> actions = context.getActions();
|
||||
for (int action : actions){
|
||||
for (Binding binding : keysmap.getBindings(action)){
|
||||
switch(binding.type){
|
||||
case IKeysMap::PRESSED:
|
||||
setPressedAction(binding.key,binding.action);
|
||||
break;
|
||||
case IKeysMap::RELEASED:
|
||||
setReleasedAction(binding.key,binding.action);
|
||||
break;
|
||||
case IKeysMap::HOLD:
|
||||
setHoldAction(binding.key,binding.action);
|
||||
break;
|
||||
default:
|
||||
//raiseError;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::vector<int> actions = context.getActions();
|
||||
for (int action : actions){
|
||||
for (Binding binding : keysmap.getBindings(action)){
|
||||
switch(binding.type){
|
||||
case IKeysMap::PRESSED:
|
||||
setPressedAction(binding.key,binding.action);
|
||||
break;
|
||||
case IKeysMap::RELEASED:
|
||||
setReleasedAction(binding.key,binding.action);
|
||||
break;
|
||||
case IKeysMap::HOLD:
|
||||
setHoldAction(binding.key,binding.action);
|
||||
break;
|
||||
default:
|
||||
//raiseError;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int KeyBindings::getPressedAction(int key) const
|
||||
{
|
||||
return bindings_pressed.count(key) == 1? bindings_pressed.at(key) : -1;
|
||||
return bindings_pressed.count(key) == 1? bindings_pressed.at(key) : -1;
|
||||
}
|
||||
int KeyBindings::getReleasedAction(int key) const
|
||||
{
|
||||
return bindings_released.count(key) == 1? bindings_released.at(key) : -1;
|
||||
return bindings_released.count(key) == 1? bindings_released.at(key) : -1;
|
||||
}
|
||||
int KeyBindings::getHoldAction(int key) const
|
||||
{
|
||||
return bindings_hold.count(key) == 1? bindings_hold.at(key) : -1;
|
||||
return bindings_hold.count(key) == 1? bindings_hold.at(key) : -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void KeyBindings::setPressedAction(int key, int action)
|
||||
{
|
||||
bindings_pressed[key]=action;
|
||||
bindings_pressed[key]=action;
|
||||
}
|
||||
void KeyBindings::setReleasedAction(int key, int action)
|
||||
{
|
||||
bindings_released[key]=action;
|
||||
bindings_released[key]=action;
|
||||
}
|
||||
|
||||
void KeyBindings::setHoldAction(int key, int action)
|
||||
{
|
||||
bindings_hold[key]=action;
|
||||
bindings_hold[key]=action;
|
||||
}
|
||||
|
||||
|
||||
/* Implementation of Context class
|
||||
* @author: Thomas Brandého
|
||||
* @info: This class contains a list of actions available in a given situation (context).
|
||||
@ -93,9 +121,10 @@ Context::Context(std::string _name, std::vector<int> _actions): name(_name), act
|
||||
|
||||
std::string Context::getName()
|
||||
{
|
||||
return name;
|
||||
return name;
|
||||
}
|
||||
std::vector<int> Context::getActions() const
|
||||
{
|
||||
return actions;
|
||||
return actions;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user