Merge branch 'master' of https://git.epicsparrow.com/epicsparrow/sparrowinput
This commit is contained in:
commit
da406827b1
@ -1,53 +1,15 @@
|
|||||||
project(SparrowInput)
|
project(SparrowInput)
|
||||||
cmake_minimum_required(VERSION 2.8)
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
|
||||||
if(WIN32)
|
# choose source file
|
||||||
set(SYSTEM_LIB_PATH "win32")
|
file(GLOB LIB_SRC_LIST src/*.cpp)
|
||||||
else(WIN32)
|
file(GLOB LIB_HEAD_LIST src/*.h)
|
||||||
set(SYSTEM_LIB_PATH "linux")
|
list(REMOVE_ITEM LIB_SRC_LIST src/main.cpp)
|
||||||
endif(WIN32)
|
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}")
|
include(../cmaketemplate/template.cmake)
|
||||||
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}
|
|
||||||
)
|
|
||||||
|
@ -16,10 +16,10 @@ IKeysMap::IKeysMap()
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Binding> IKeysMap::getBindings(int action) const {
|
std::vector<Binding> IKeysMap::getBindings(int action) const {
|
||||||
std::vector<Binding> bindings;
|
std::vector<Binding> bindings;
|
||||||
for (auto binding : keys)
|
for (auto binding : keys)
|
||||||
if (binding.action == action) bindings.push_back(binding);
|
if (binding.action == action) bindings.push_back(binding);
|
||||||
return bindings;
|
return bindings;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Implementation of KeyBindings class
|
/* Implementation of KeyBindings class
|
||||||
@ -33,54 +33,82 @@ KeyBindings::KeyBindings()
|
|||||||
}
|
}
|
||||||
KeyBindings::KeyBindings(const Context &context, const IKeysMap &keysmap)
|
KeyBindings::KeyBindings(const Context &context, const IKeysMap &keysmap)
|
||||||
{
|
{
|
||||||
std::vector<int> actions = context.getActions();
|
std::vector<int> actions = context.getActions();
|
||||||
for (int action : actions){
|
for (int action : actions){
|
||||||
for (Binding binding : keysmap.getBindings(action)){
|
for (Binding binding : keysmap.getBindings(action)){
|
||||||
switch(binding.type){
|
switch(binding.type){
|
||||||
case IKeysMap::PRESSED:
|
case IKeysMap::PRESSED:
|
||||||
setPressedAction(binding.key,binding.action);
|
setPressedAction(binding.key,binding.action);
|
||||||
break;
|
break;
|
||||||
case IKeysMap::RELEASED:
|
case IKeysMap::RELEASED:
|
||||||
setReleasedAction(binding.key,binding.action);
|
setReleasedAction(binding.key,binding.action);
|
||||||
break;
|
break;
|
||||||
case IKeysMap::HOLD:
|
case IKeysMap::HOLD:
|
||||||
setHoldAction(binding.key,binding.action);
|
setHoldAction(binding.key,binding.action);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//raiseError;
|
//raiseError;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int KeyBindings::getPressedAction(int key) const
|
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
|
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
|
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)
|
void KeyBindings::setPressedAction(int key, int action)
|
||||||
{
|
{
|
||||||
bindings_pressed[key]=action;
|
bindings_pressed[key]=action;
|
||||||
}
|
}
|
||||||
void KeyBindings::setReleasedAction(int key, int action)
|
void KeyBindings::setReleasedAction(int key, int action)
|
||||||
{
|
{
|
||||||
bindings_released[key]=action;
|
bindings_released[key]=action;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyBindings::setHoldAction(int key, int action)
|
void KeyBindings::setHoldAction(int key, int action)
|
||||||
{
|
{
|
||||||
bindings_hold[key]=action;
|
bindings_hold[key]=action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Implementation of Context class
|
/* Implementation of Context class
|
||||||
* @author: Thomas Brandého
|
* @author: Thomas Brandého
|
||||||
* @info: This class contains a list of actions available in a given situation (context).
|
* @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()
|
std::string Context::getName()
|
||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
std::vector<int> Context::getActions() const
|
std::vector<int> Context::getActions() const
|
||||||
{
|
{
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user