Browse Source

input: add a buttons.inc file with a list of default mouse/joystick button names.

legacy
Sam Hocevar 5 years ago
parent
commit
ae4ff1d27c
8 changed files with 66 additions and 67 deletions
  1. +1
    -1
      src/Makefile.am
  2. +1
    -0
      src/lol-core.vcxproj
  3. +3
    -0
      src/lol-core.vcxproj.filters
  4. +42
    -0
      src/ui/buttons.inc
  5. +2
    -28
      src/ui/d3d9-input.cpp
  6. +10
    -19
      src/ui/input.cpp
  7. +4
    -17
      src/ui/input.h
  8. +3
    -2
      src/ui/sdl-input.cpp

+ 1
- 1
src/Makefile.am View File

@@ -101,7 +101,7 @@ liblol_core_sources = \
\
audio/audio.cpp audio/sample.cpp \
\
ui/input.cpp ui/input.h ui/keys.inc \
ui/input.cpp ui/input.h ui/keys.inc ui/buttons.inc \
ui/controller.cpp ui/controller.h \
ui/gui.cpp ui/gui.h \
\


+ 1
- 0
src/lol-core.vcxproj View File

@@ -287,6 +287,7 @@
<ClInclude Include="textureimage-private.h" />
<ClInclude Include="textureimage.h" />
<ClInclude Include="tileset.h" />
<ClInclude Include="ui\buttons.inc" />
<ClInclude Include="ui\controller.h" />
<ClInclude Include="ui\d3d9-input.h" />
<ClInclude Include="ui\gui.h" />


+ 3
- 0
src/lol-core.vcxproj.filters View File

@@ -521,6 +521,9 @@
<ClInclude Include="textureimage-private.h" />
<ClInclude Include="textureimage.h" />
<ClInclude Include="tileset.h" />
<ClInclude Include="ui\buttons.inc">
<Filter>ui</Filter>
</ClInclude>
<ClInclude Include="ui\controller.h">
<Filter>ui</Filter>
</ClInclude>


+ 42
- 0
src/ui/buttons.inc View File

@@ -0,0 +1,42 @@
//
// Lol Engine
//
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What the Fuck You Want
// to Public License, Version 2, as published by the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
//

#if !defined _BTN
# error buttons.inc included without the _BTN macro
#endif

_BTN(0, Unknown)

// Mouse buttons (FIXME: rename to LeftClick etc.?)
_BTN(1, Left)
_BTN(2, Right)
_BTN(3, Middle)
_BTN(4, Focus)

// Typical game controller buttons
_BTN(5, A)
_BTN(6, B)
_BTN(7, X)
_BTN(8, Y)
_BTN(9, DpadUp)
_BTN(10, DpadDown)
_BTN(11, DpadLeft)
_BTN(12, DpadRight)
_BTN(13, Start)
_BTN(14, Back)
_BTN(15, LeftThumb)
_BTN(16, RightThumb)
_BTN(17, LeftShoulder)
_BTN(18, RightShoulder)

#undef _BTN


+ 2
- 28
src/ui/d3d9-input.cpp View File

@@ -26,20 +26,6 @@
namespace lol
{

static const std::string g_name_xbox_key_dpad_up("DPadUp");
static const std::string g_name_xbox_key_dpad_down("DPadDown");
static const std::string g_name_xbox_key_dpad_left("DPadLeft");
static const std::string g_name_xbox_key_dpad_right("DPadRight");
static const std::string g_name_xbox_key_left_thumb("LeftThumb");
static const std::string g_name_xbox_key_right_thumb("RightThumb");
static const std::string g_name_xbox_key_left_shoulder("LeftShoulder");
static const std::string g_name_xbox_key_right_shoulder("Rightshoulder");
static const std::string g_name_xbox_key_a("A");
static const std::string g_name_xbox_key_b("B");
static const std::string g_name_xbox_key_x("X");
static const std::string g_name_xbox_key_y("Y");
static const std::string g_name_xbox_key_start("Start");
static const std::string g_name_xbox_key_back("Back");
static const std::string g_name_xbox_axis_left_x("Axis1");
static const std::string g_name_xbox_axis_left_y("Axis2");
static const std::string g_name_xbox_axis_right_x("Axis3");
@@ -84,20 +70,8 @@ D3d9Input::D3d9Input()
stick->AddAxis(g_name_xbox_axis_left_trigger.c_str());
stick->AddAxis(g_name_xbox_axis_right_trigger.c_str());

stick->AddKey(g_name_xbox_key_dpad_up.c_str());
stick->AddKey(g_name_xbox_key_dpad_down.c_str());
stick->AddKey(g_name_xbox_key_dpad_left.c_str());
stick->AddKey(g_name_xbox_key_dpad_right.c_str());
stick->AddKey(g_name_xbox_key_start.c_str());
stick->AddKey(g_name_xbox_key_back.c_str());
stick->AddKey(g_name_xbox_key_left_thumb.c_str());
stick->AddKey(g_name_xbox_key_right_thumb.c_str());
stick->AddKey(g_name_xbox_key_left_shoulder.c_str());
stick->AddKey(g_name_xbox_key_right_shoulder.c_str());
stick->AddKey(g_name_xbox_key_a.c_str());
stick->AddKey(g_name_xbox_key_b.c_str());
stick->AddKey(g_name_xbox_key_x.c_str());
stick->AddKey(g_name_xbox_key_y.c_str());
#define _BTN(id, name) stick->internal_add_button(input::button::BTN_##name, #name);
#include "ui/buttons.inc" // FIXME: ignore mouse buttons here

m_data->m_joysticks.push(i, stick);
}


+ 10
- 19
src/ui/input.cpp View File

@@ -42,16 +42,13 @@ input::input()
// Create default keyboard device
m_keyboard = std::make_shared<InputDevice>(g_name_keyboard.c_str());
/* Register all scancodes known to SDL (from the USB standard) */
# define _SC(id, str, name) m_keyboard->AddKey(id, #name);
# include "ui/keys.inc"
#define _SC(id, str, name) m_keyboard->internal_add_key(input::key::SC_##name, #name);
#include "ui/keys.inc"

// Create default mouse device
m_mouse = std::make_shared<InputDevice>(g_name_mouse.c_str());
m_mouse->AddButton((int)input::button::BTN_Left, g_name_mouse_key_left.c_str());
m_mouse->AddButton((int)input::button::BTN_Middle, g_name_mouse_key_middle.c_str());
m_mouse->AddButton((int)input::button::BTN_Right, g_name_mouse_key_right.c_str());
m_mouse->AddButton((int)input::button::BTN_Focus, g_name_mouse_key_in_screen.c_str());
// Added to manage if mouse is in the screen or not.
#define _BTN(id, name) m_mouse->internal_add_button(input::button::BTN_##name, #name);
#include "ui/buttons.inc" // FIXME: this will also add joystick buttons!
m_mouse->AddAxis(g_name_mouse_axis_x.c_str());
m_mouse->AddAxis(g_name_mouse_axis_y.c_str());
m_mouse->AddAxis(g_name_mouse_axis_xpixel.c_str());
@@ -116,32 +113,26 @@ void InputDevice::capture_text(bool status)
m_input_active = status;
}

void InputDevice::AddKey(int index, const char* name)
void InputDevice::internal_add_key(input::key key, const char* name)
{
if (index == -1)
index = (int)m_key_names.size();

while (index >= (int)m_key_names.size())
while ((int)key >= (int)m_key_names.size())
{
m_key_names.push_back("");
m_keys.push_back(false);
}

m_key_names[index] = name;
m_key_names[(int)key] = name;
}

void InputDevice::AddButton(int index, const char* name)
void InputDevice::internal_add_button(input::button button, const char* name)
{
if (index == -1)
index = (int)m_button_names.size();

while (index >= (int)m_button_names.size())
while ((int)button >= (int)m_button_names.size())
{
m_button_names.push_back("");
m_buttons.push_back(false);
}

m_button_names[index] = name;
m_button_names[(int)button] = name;
}

void InputDevice::AddAxis(int index, const char* name, float sensitivity)


+ 4
- 17
src/ui/input.h View File

@@ -58,10 +58,8 @@ public:

enum class button : uint16_t
{
BTN_Left,
BTN_Right,
BTN_Middle,
BTN_Focus,
#define _BTN(id, name) BTN_##name = id,
#include "ui/buttons.inc"
};

static std::vector<key> const &all_keys();
@@ -245,19 +243,8 @@ public:
/** Internal functions that allow to construct an InputDevice
* dynamically, when the keys, axis and cursors are not known at
* compile time. */
void AddKey(int id, char const * name);

inline void AddKey(char const * name)
{
AddKey(-1, name);
}

void AddButton(int id, char const * name);

inline void AddButton(char const * name)
{
AddButton(-1, name);
}
void internal_add_key(input::key, char const * name);
void internal_add_button(input::button, char const * name);

void AddAxis(int id, char const * name, float sensitivity = 1.0f);



+ 3
- 2
src/ui/sdl-input.cpp View File

@@ -87,7 +87,7 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h)
for (int j = 0; j < SDL_JoystickNumAxes(sdlstick); ++j)
stick->AddAxis(format("Axis%d", j + 1).c_str());
for (int j = 0; j < SDL_JoystickNumButtons(sdlstick); ++j)
stick->AddKey(format("Button%d", j + 1).c_str());
stick->internal_add_button((input::button)(j + 1), format("Button%d", j + 1).c_str());

m_joysticks.push(sdlstick, stick);
}
@@ -200,7 +200,8 @@ void SdlInput::tick(float seconds)
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
//event.button.which
mouse->internal_set_button((input::button)(event.button.button - 1), event.type == SDL_MOUSEBUTTONDOWN);
mouse->internal_set_button((input::button)((int)input::button::BTN_Left + event.button.button - 1),
event.type == SDL_MOUSEBUTTONDOWN);
break;
case SDL_MOUSEWHEEL:
mouse->internal_set_axis(4, (float)event.button.y);


Loading…
Cancel
Save