1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-19 19:53:53 +00:00

Move SDL mappigs to the separate file

This commit is contained in:
Andrei Kortunov 2020-04-08 11:43:45 +04:00
parent 3c09d05615
commit 1560e71f4e
6 changed files with 104 additions and 84 deletions

View file

@ -25,7 +25,7 @@ add_openmw_dir (mwrender
) )
add_openmw_dir (mwinput add_openmw_dir (mwinput
inputmanagerimp sensormanager actions actions inputmanagerimp sdlmappings sensormanager
) )
add_openmw_dir (mwgui add_openmw_dir (mwgui

View file

@ -54,8 +54,6 @@ namespace MWBase
virtual std::string getActionDescription (int action) = 0; virtual std::string getActionDescription (int action) = 0;
virtual std::string getActionKeyBindingName (int action) = 0; virtual std::string getActionKeyBindingName (int action) = 0;
virtual std::string getActionControllerBindingName (int action) = 0; virtual std::string getActionControllerBindingName (int action) = 0;
virtual std::string sdlControllerAxisToString(int axis) = 0;
virtual std::string sdlControllerButtonToString(int button) = 0;
///Actions available for binding to keyboard buttons ///Actions available for binding to keyboard buttons
virtual std::vector<int> getActionKeySorting() = 0; virtual std::vector<int> getActionKeySorting() = 0;
///Actions available for binding to controller buttons ///Actions available for binding to controller buttons

View file

@ -31,6 +31,7 @@
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/actorutil.hpp"
#include "sdlmappings.hpp"
#include "sensormanager.hpp" #include "sensormanager.hpp"
namespace MWInput namespace MWInput
@ -1705,65 +1706,6 @@ namespace MWInput
return "#{sNone}"; return "#{sNone}";
} }
std::string InputManager::sdlControllerButtonToString(int button)
{
switch(button)
{
case SDL_CONTROLLER_BUTTON_A:
return "A Button";
case SDL_CONTROLLER_BUTTON_B:
return "B Button";
case SDL_CONTROLLER_BUTTON_BACK:
return "Back Button";
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
return "DPad Down";
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
return "DPad Left";
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
return "DPad Right";
case SDL_CONTROLLER_BUTTON_DPAD_UP:
return "DPad Up";
case SDL_CONTROLLER_BUTTON_GUIDE:
return "Guide Button";
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
return "Left Shoulder";
case SDL_CONTROLLER_BUTTON_LEFTSTICK:
return "Left Stick Button";
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
return "Right Shoulder";
case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
return "Right Stick Button";
case SDL_CONTROLLER_BUTTON_START:
return "Start Button";
case SDL_CONTROLLER_BUTTON_X:
return "X Button";
case SDL_CONTROLLER_BUTTON_Y:
return "Y Button";
default:
return "Button " + std::to_string(button);
}
}
std::string InputManager::sdlControllerAxisToString(int axis)
{
switch(axis)
{
case SDL_CONTROLLER_AXIS_LEFTX:
return "Left Stick X";
case SDL_CONTROLLER_AXIS_LEFTY:
return "Left Stick Y";
case SDL_CONTROLLER_AXIS_RIGHTX:
return "Right Stick X";
case SDL_CONTROLLER_AXIS_RIGHTY:
return "Right Stick Y";
case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
return "Left Trigger";
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
return "Right Trigger";
default:
return "Axis " + std::to_string(axis);
}
}
std::vector<int> InputManager::getActionKeySorting() std::vector<int> InputManager::getActionKeySorting()
{ {
std::vector<int> ret; std::vector<int> ret;
@ -2010,18 +1952,6 @@ namespace MWInput
loadControllerDefaults(true); loadControllerDefaults(true);
} }
MyGUI::MouseButton InputManager::sdlButtonToMyGUI(Uint8 button)
{
//The right button is the second button, according to MyGUI
if(button == SDL_BUTTON_RIGHT)
button = SDL_BUTTON_MIDDLE;
else if(button == SDL_BUTTON_MIDDLE)
button = SDL_BUTTON_RIGHT;
//MyGUI's buttons are 0 indexed
return MyGUI::MouseButton::Enum(button - 1);
}
void InputManager::setPlayer (MWWorld::Player* player) void InputManager::setPlayer (MWWorld::Player* player)
{ {
mPlayer = player; mPlayer = player;

View file

@ -39,11 +39,6 @@ namespace ICS
class InputControlSystem; class InputControlSystem;
} }
namespace MyGUI
{
struct MouseButton;
}
namespace Files namespace Files
{ {
struct ConfigurationManager; struct ConfigurationManager;
@ -230,11 +225,6 @@ namespace MWInput
void convertMousePosForMyGUI(int& x, int& y); void convertMousePosForMyGUI(int& x, int& y);
MyGUI::MouseButton sdlButtonToMyGUI(Uint8 button);
virtual std::string sdlControllerAxisToString(int axis);
virtual std::string sdlControllerButtonToString(int button);
void resetIdleTime(); void resetIdleTime();
void updateIdleTime(float dt); void updateIdleTime(float dt);

View file

@ -0,0 +1,81 @@
#include "sdlmappings.hpp"
#include <MyGUI_MouseButton.h>
#include <SDL_gamecontroller.h>
#include <SDL_mouse.h>
namespace MWInput
{
std::string sdlControllerButtonToString(int button)
{
switch(button)
{
case SDL_CONTROLLER_BUTTON_A:
return "A Button";
case SDL_CONTROLLER_BUTTON_B:
return "B Button";
case SDL_CONTROLLER_BUTTON_BACK:
return "Back Button";
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
return "DPad Down";
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
return "DPad Left";
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
return "DPad Right";
case SDL_CONTROLLER_BUTTON_DPAD_UP:
return "DPad Up";
case SDL_CONTROLLER_BUTTON_GUIDE:
return "Guide Button";
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
return "Left Shoulder";
case SDL_CONTROLLER_BUTTON_LEFTSTICK:
return "Left Stick Button";
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
return "Right Shoulder";
case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
return "Right Stick Button";
case SDL_CONTROLLER_BUTTON_START:
return "Start Button";
case SDL_CONTROLLER_BUTTON_X:
return "X Button";
case SDL_CONTROLLER_BUTTON_Y:
return "Y Button";
default:
return "Button " + std::to_string(button);
}
}
std::string sdlControllerAxisToString(int axis)
{
switch(axis)
{
case SDL_CONTROLLER_AXIS_LEFTX:
return "Left Stick X";
case SDL_CONTROLLER_AXIS_LEFTY:
return "Left Stick Y";
case SDL_CONTROLLER_AXIS_RIGHTX:
return "Right Stick X";
case SDL_CONTROLLER_AXIS_RIGHTY:
return "Right Stick Y";
case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
return "Left Trigger";
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
return "Right Trigger";
default:
return "Axis " + std::to_string(axis);
}
}
MyGUI::MouseButton sdlButtonToMyGUI(Uint8 button)
{
//The right button is the second button, according to MyGUI
if(button == SDL_BUTTON_RIGHT)
button = SDL_BUTTON_MIDDLE;
else if(button == SDL_BUTTON_MIDDLE)
button = SDL_BUTTON_RIGHT;
//MyGUI's buttons are 0 indexed
return MyGUI::MouseButton::Enum(button - 1);
}
}

View file

@ -0,0 +1,21 @@
#ifndef MWINPUT_SDLMAPPINGS_H
#define MWINPUT_SDLMAPPINGS_H
#include <string>
#include <SDL_types.h>
namespace MyGUI
{
struct MouseButton;
}
namespace MWInput
{
std::string sdlControllerButtonToString(int button);
std::string sdlControllerAxisToString(int axis);
MyGUI::MouseButton sdlButtonToMyGUI(Uint8 button);
}
#endif