Ver código fonte

RIP lol::Controller and lol::InputProfile ⚰️ LOL

legacy
Sam Hocevar 5 anos atrás
pai
commit
b0a8596001
15 arquivos alterados com 128 adições e 1039 exclusões
  1. +19
    -32
      doc/tutorial/07_input.cpp
  2. +8
    -7
      doc/tutorial/11_fractal.cpp
  3. +0
    -1
      src/Makefile.am
  4. +0
    -2
      src/lol-core.vcxproj
  5. +0
    -6
      src/lol-core.vcxproj.filters
  6. +0
    -1
      src/lol/extras.h
  7. +0
    -444
      src/ui/controller.cpp
  8. +0
    -352
      src/ui/controller.h
  9. +6
    -13
      src/ui/d3d9-input.cpp
  10. +3
    -21
      src/ui/gui.cpp
  11. +0
    -2
      src/ui/gui.h
  12. +13
    -29
      src/ui/input.cpp
  13. +53
    -113
      src/ui/input.h
  14. +25
    -15
      src/ui/sdl-input.cpp
  15. +1
    -1
      src/ui/sdl-input.h

+ 19
- 32
doc/tutorial/07_input.cpp Ver arquivo

@@ -26,16 +26,6 @@ class InputTutorial : public WorldEntity
public:
InputTutorial()
{
m_controller = new Controller("Default");

m_profile
<< InputProfile::JoystickAxis(1, AXIS_PITCH, "Axis2")
<< InputProfile::JoystickAxis(1, AXIS_YAW, "Axis1")
<< InputProfile::MouseAxis(AXIS_DRAG_PITCH, "Y")
<< InputProfile::MouseAxis(AXIS_DRAG_YAW, "X");

m_controller->Init(m_profile);

m_pitch_angle = 0;
m_yaw_angle = 0;
m_autorot = true;
@@ -63,7 +53,7 @@ public:
m_lines_indices << 0 << 4 << 1 << 5 << 2 << 6 << 3 << 7;

m_text = new Text("", "data/font/ascii.png");
m_text->SetPos(vec3(5, 5, 1));
m_text->SetPos(vec3(5, 30, 1));
Ticker::Ref(m_text);

m_ready = false;
@@ -86,10 +76,14 @@ public:
m_autorot = !m_autorot;

/* Handle joystick */
if (lol::abs(m_controller->GetAxisValue(AXIS_PITCH)) > 0.2f)
m_pitch_angle += m_controller->GetAxisValue(AXIS_PITCH) * seconds;
if (lol::abs(m_controller->GetAxisValue(AXIS_YAW)) > 0.2f)
m_yaw_angle += m_controller->GetAxisValue(AXIS_YAW) * seconds;
auto joystick = InputDevice::Get(g_name_joystick(1).c_str());
if ((bool)joystick)
{
if (lol::abs(joystick->axis(input::axis::LeftY)) > 0.2f)
m_pitch_angle += joystick->axis(input::axis::LeftY) * seconds;
if (lol::abs(joystick->axis(input::axis::LeftX)) > 0.2f)
m_yaw_angle += joystick->axis(input::axis::LeftX) * seconds;
}

/* Handle mouse */
if (true)
@@ -97,8 +91,8 @@ public:
if (mouse->button(input::button::BTN_Left))
{
mouse->capture(true);
m_pitch_angle -= m_controller->GetAxisValue(AXIS_DRAG_PITCH) * seconds * 0.1f;
m_yaw_angle += m_controller->GetAxisValue(AXIS_DRAG_YAW) * seconds * 0.1f;
m_pitch_angle -= mouse->axis(input::axis::MoveX) * seconds * 0.1f;
m_yaw_angle += mouse->axis(input::axis::MoveY) * seconds * 0.1f;
}
else
{
@@ -108,9 +102,14 @@ public:
}

m_text->SetText(lol::format(
"cursor: (%0.3f, %0.3f) - pixel (%d, %d)",
mouse->get_cursor_uv(0).x, mouse->get_cursor_uv(0).y,
mouse->get_cursor_pixel(0).x, mouse->get_cursor_pixel(0).y));
"cursor: (%0.3f,%0.3f) - pixel (%d,%d)\n"
" move: (%0.3f,%0.3f) - pixel (%d,%d)",
mouse->axis(input::axis::X), mouse->axis(input::axis::Y),
(int)mouse->axis(input::axis::ScreenX),
(int)mouse->axis(input::axis::ScreenY),
mouse->axis(input::axis::MoveX), mouse->axis(input::axis::MoveY),
(int)mouse->axis(input::axis::ScreenMoveX),
(int)mouse->axis(input::axis::ScreenMoveY)));
}
else
{
@@ -180,18 +179,6 @@ public:
}

private:
enum
{
AXIS_DRAG_PITCH,
AXIS_DRAG_YAW,
AXIS_PITCH,
AXIS_YAW,
AXIS_MAX
};

Controller *m_controller;
InputProfile m_profile;

bool m_autorot;
float m_pitch_angle;
float m_yaw_angle;


+ 8
- 7
doc/tutorial/11_fractal.cpp Ver arquivo

@@ -153,7 +153,8 @@ public:
auto mouse = input::mouse();
auto keyboard = input::keyboard();

ivec2 mousepos = mouse->get_cursor_pixel(0);
vec2 mousepos(mouse->axis(input::axis::ScreenX),
mouse->axis(input::axis::ScreenY));

int prev_frame = (m_frame + 4) % 4;
m_frame = (m_frame + 1) % 4;
@@ -164,7 +165,7 @@ public:
if (m_julia)
{
m_saved_view = m_view;
m_view.r0 = m_view.center + rcmplx(ScreenToWorldOffset((vec2)mousepos));
m_view.r0 = m_view.center + rcmplx(ScreenToWorldOffset(mousepos));
}
else
{
@@ -174,24 +175,24 @@ public:
flag = 2;
}

rcmplx worldmouse = m_view.center + rcmplx(ScreenToWorldOffset((vec2)mousepos));
rcmplx worldmouse = m_view.center + rcmplx(ScreenToWorldOffset(mousepos));

if (mouse->button(input::button::BTN_Middle))
{
if (!m_drag)
{
m_oldmouse = mousepos;
m_oldmouse = (ivec2)mousepos;
m_drag = true;
}
m_view.translate = rcmplx(ScreenToWorldOffset((vec2)m_oldmouse)
- ScreenToWorldOffset((vec2)mousepos));
- ScreenToWorldOffset(mousepos));
/* XXX: the purpose of this hack is to avoid translating by
* an exact number of pixels. If this were to happen, the step()
* optimisation for i915 cards in our shader would behave
* incorrectly because a quarter of the pixels in the image
* would have tied rankings in the distance calculation. */
m_view.translate *= real(1023.0 / 1024.0);
m_oldmouse = mousepos;
m_oldmouse = (ivec2)mousepos;
}
else
{
@@ -239,7 +240,7 @@ public:
m_view.center += m_view.translate;
m_view.center = (m_view.center - worldmouse) * real(zoom) + worldmouse;
worldmouse = m_view.center
+ rcmplx(ScreenToWorldOffset((vec2)mousepos));
+ rcmplx(ScreenToWorldOffset(mousepos));

/* Store the transformation properties to go from m_frame - 1
* to m_frame. */


+ 0
- 1
src/Makefile.am Ver arquivo

@@ -102,7 +102,6 @@ liblol_core_sources = \
audio/audio.cpp audio/sample.cpp \
\
ui/input.cpp ui/input.h ui/keys.inc ui/buttons.inc \
ui/controller.cpp ui/controller.h \
ui/gui.cpp ui/gui.h \
\
gpu/default-material.lolfx \


+ 0
- 2
src/lol-core.vcxproj Ver arquivo

@@ -172,7 +172,6 @@
<ClCompile Include="text.cpp" />
<ClCompile Include="textureimage.cpp" />
<ClCompile Include="tileset.cpp" />
<ClCompile Include="ui\controller.cpp" />
<ClCompile Include="ui\d3d9-input.cpp" />
<ClCompile Include="ui\gui.cpp" />
<ClCompile Include="ui\input.cpp" />
@@ -288,7 +287,6 @@
<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" />
<ClInclude Include="ui\input.h" />


+ 0
- 6
src/lol-core.vcxproj.filters Ver arquivo

@@ -239,9 +239,6 @@
<ClCompile Include="text.cpp" />
<ClCompile Include="textureimage.cpp" />
<ClCompile Include="tileset.cpp" />
<ClCompile Include="ui\controller.cpp">
<Filter>ui</Filter>
</ClCompile>
<ClCompile Include="ui\d3d9-input.cpp">
<Filter>ui</Filter>
</ClCompile>
@@ -524,9 +521,6 @@
<ClInclude Include="ui\buttons.inc">
<Filter>ui</Filter>
</ClInclude>
<ClInclude Include="ui\controller.h">
<Filter>ui</Filter>
</ClInclude>
<ClInclude Include="ui\d3d9-input.h">
<Filter>ui</Filter>
</ClInclude>


+ 0
- 1
src/lol/extras.h Ver arquivo

@@ -46,7 +46,6 @@

// UI
#include <lol/../ui/input.h>
#include <lol/../ui/controller.h>
#include <lol/../ui/gui.h>

// Other objects


+ 0
- 444
src/ui/controller.cpp Ver arquivo

@@ -1,444 +0,0 @@
//
// Lol Engine
//
// Copyright © 2017—2019 Sam Hocevar <sam@hocevar.net>
// © 2010—2015 Benjamin Litzelmann
//
// 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.
//

#include <lol/engine-internal.h>

#include <string>

namespace lol
{

///////////////////////////////////////////////////////////////////////////////
// KeyBinding

void KeyBinding::Bind(const std::string& device_name, const std::string& key_name)
{
const InputDevice* device = InputDevice::Get(device_name);

if (!device)
{
msg::warn("trying to bind key to nonexistent input device %s\n",
device_name.c_str());
return;
}

int keyindex = (int)device->GetKeyIndex(key_name);
if (keyindex < 0)
{
msg::warn("trying to bind nonexistent key %s.%s\n",
device_name.c_str(), key_name.c_str());
return;
}

m_keybindings.push(device, keyindex);
}

bool KeyBinding::Unbind(const std::string& device_name, const std::string& key_name)
{
for (int i = 0; i < m_keybindings.count(); ++i)
{
if (m_keybindings[i].m1->GetName() == device_name)
{
if (m_keybindings[i].m2 == m_keybindings[i].m1->GetKeyIndex(key_name))
{
m_keybindings.remove(i);
return true;
}
}
}
return false;
}

///////////////////////////////////////////////////////////////////////////////
// AxisBinding

void AxisBinding::Bind(const std::string& device_name, const std::string& axis_name)
{
const InputDevice* device = InputDevice::Get(device_name);
if (!device)
{
msg::warn("trying to bind axis to nonexistent input device %s\n",
device_name.c_str());
return;
}

int axisindex = (int)device->GetAxisIndex(axis_name);
if (axisindex < 0)
{
msg::warn("trying to bind nonexistent axis %s.%s\n",
device_name.c_str(), axis_name.c_str());
return;
}

m_axisbindings.push(device, axisindex);
}

void AxisBinding::BindKey(const std::string& device_name, const std::string& key_name)
{
const InputDevice* device = InputDevice::Get(device_name);
if (!device)
{
msg::warn("trying to bind axis key to nonexistent input device %s\n",
device_name.c_str());
return;
}

int keyindex = (int)device->GetKeyIndex(key_name);
if (keyindex < 0)
{
msg::warn("trying to bind nonexistent axis key %s.%s\n",
device_name.c_str(), key_name.c_str());
return;
}

m_keybindings.push(device, -1, keyindex);
}

void AxisBinding::BindKeys(const std::string& device_name, const std::string& min_key_name, const std::string& max_key_name)
{
const InputDevice* device = InputDevice::Get(device_name);
if (!device)
{
msg::warn("trying to bind axis keys to nonexistent input device %s\n",
device_name.c_str());
return;
}

int minkeyindex = (int)device->GetKeyIndex(min_key_name);
if (minkeyindex < 0)
{
msg::warn("trying to bind nonexistent axis key %s.%s\n",
device_name.c_str(), min_key_name.c_str());
return;
}

int maxkeyindex = (int)device->GetKeyIndex(max_key_name);
if (maxkeyindex < 0)
{
msg::warn("trying to bind nonexistent axis key %s.%s\n",
device_name.c_str(), max_key_name.c_str());
return;
}

m_keybindings.push(device, minkeyindex, maxkeyindex);
}

bool AxisBinding::Unbind(const std::string& device_name, const std::string& axis_name)
{
for (int i = 0; i < m_keybindings.count(); ++i)
{
if (m_axisbindings[i].m1->GetName() == device_name)
{
if (m_axisbindings[i].m2 == m_axisbindings[i].m1->GetAxisIndex(axis_name))
{
m_axisbindings.remove(i);
return true;
}
}
}
return false;
}

bool AxisBinding::UnbindKey(const std::string& device_name, const std::string& key_name)
{
for (int i = 0; i < m_keybindings.count(); ++i)
{
if (m_keybindings[i].m1->GetName() == device_name)
{
if (m_keybindings[i].m2 == -1 && m_keybindings[i].m3 == m_keybindings[i].m1->GetKeyIndex(key_name))
{
m_keybindings.remove(i);
return true;
}
}
}
return false;
}

bool AxisBinding::UnbindKeys(const std::string& device_name, const std::string& min_key_name, const std::string& max_key_name)
{
for (int i = 0; i < m_keybindings.count(); ++i)
{
if (m_keybindings[i].m1->GetName() == device_name)
{
if (m_keybindings[i].m2 == m_keybindings[i].m1->GetKeyIndex(min_key_name)
&& m_keybindings[i].m3 == m_keybindings[i].m1->GetKeyIndex(max_key_name))
{
m_keybindings.remove(i);
return true;
}
}
}
return false;

}

float AxisBinding::RetrieveCurrentValue()
{
float max_positive = 0.0f;
float max_negative = 0.0f;

for (int i = 0; i < m_axisbindings.count(); ++i)
{
float value = m_axisbindings[i].m1->GetAxis(m_axisbindings[i].m2);
if (value > max_positive)
max_positive = value;
if (value < max_negative)
max_negative = value;
}

for (int i = 0; i < m_keybindings.count(); ++i)
{
float value = 0.0f;
m_keybindings[i].m1->key((input::key)m_keybindings[i].m2);
value += m_keybindings[i].m1->key((input::key)m_keybindings[i].m3) ? 1.0f : 0.0f;
if (m_keybindings[i].m2 != -1)
value += m_keybindings[i].m1->key((input::key)m_keybindings[i].m2) ? -1.0f : 0.0f;

if (value > max_positive)
max_positive = value;
if (value < max_negative)
max_negative = value;
}

return max_negative + max_positive;
}

///////////////////////////////////////////////////////////////////////////////
// Controller

static std::map<std::string, Controller*> g_controllers;
static uint32_t g_active_layer = ~((uint32_t)0);

//-----------------------------------------------------------------------------
Controller::Controller(std::string const &name)
{
m_gamegroup = tickable::group::game::input;
m_name = name;
m_activate_nextframe = true;
m_deactivate_nextframe = false;
m_active = false;
if (g_controllers[name])
msg::warn("controller “%s” has already been registered\n", name.c_str());
g_controllers[name] = this;
}

Controller::Controller(std::string const &name, InputProfile const& profile)
: Controller(name)
{
Init(profile);
}

Controller::~Controller()
{
ClearProfile();
if (g_controllers[m_name] == this)
g_controllers.erase(m_name);
}

//Init mode 1: Input profile system -------------------------------------------
void Controller::Init(InputProfile const& profile)
{
UnbindProfile();
BindProfile(profile);
}
void Controller::ClearProfile()
{
UnbindProfile();
}

//Layer mask stuff ------------------------------------------------------------
void Controller::SetLayerMask(uint32_t layer_mask)
{
m_layer_mask = layer_mask;
}
uint32_t Controller::GetLayerMask()
{
return m_layer_mask;
}
bool Controller::IsLayerActive()
{
return !!(m_layer_mask & g_active_layer);
}

//GetKeys/Axis stuff ----------------------------------------------------------
KeyBinding& Controller::GetKey(int index)
{
return m_key_bindings[index];
}

AxisBinding& Controller::GetAxis(int index)
{
return m_axis_bindings[index];
}

//Axis methods: should not go directly to binding -----------------------------
float Controller::GetAxisValue(int index) const
{
auto axis = m_axis_bindings.find(index);
return axis != m_axis_bindings.end() ? axis->second.GetValue() : 0.f;
}

float Controller::GetAxisDelta(int index) const
{
auto axis = m_axis_bindings.find(index);
return axis != m_axis_bindings.end() ? axis->second.GetDelta() : 0.f;
}

//Input profile system --------------------------------------------------------
void Controller::UnbindProfile()
{
if (m_profile.IsEmpty())
return;

m_mutex.lock();

//Keyboard
if (m_keyboard)
{
for (InputProfile::KeyboardKey& key : m_profile.m_keys)
GetKey(key.m_idx).UnbindKeyboard(key.m_name);
m_keyboard = nullptr;
}

//Mouse
if (m_mouse)
{
for (InputProfile::MouseKey& key : m_profile.m_mouse_keys)
GetKey(key.m_idx).UnbindMouse(key.m_name);
for (InputProfile::MouseAxis& axis : m_profile.m_mouse_axis)
GetAxis(axis.m_idx).UnbindMouse(axis.m_name);
m_mouse = nullptr;
}

//Joystick
for (InputProfile::JoystickKey& key : m_profile.m_joystick_keys)
{
if (m_joystick_idx.find(key.m_joy) != INDEX_NONE)
GetKey(key.m_idx).UnbindJoystick(key.m_joy, key.m_name);
}
for (InputProfile::JoystickAxis& axis : m_profile.m_joystick_axis)
{
if (m_joystick_idx.find(axis.m_joy) != INDEX_NONE)
GetAxis(axis.m_idx).UnbindJoystick(axis.m_joy, axis.m_name);
}
m_joysticks.clear();
m_joystick_idx.clear();

m_mutex.unlock();
}
//Input profile system --------------------------------------------------------
void Controller::BindProfile(InputProfile const& setup)
{
ASSERT(!setup.IsEmpty());

m_mutex.lock();
m_profile = setup;

// Keyboard
m_keyboard = input::keyboard();
if (m_keyboard)
{
for (InputProfile::KeyboardKey& key : m_profile.m_keys)
GetKey(key.m_idx).BindKeyboard(key.m_name);
}

// Mouse
m_mouse = input::mouse();
if (m_mouse)
{
for (InputProfile::MouseKey& key : m_profile.m_mouse_keys)
GetKey(key.m_idx).BindMouse(key.m_name);
for (InputProfile::MouseAxis& axis : m_profile.m_mouse_axis)
GetAxis(axis.m_idx).BindMouse(axis.m_name);
}

// Joystick
for (uint64_t joy_idx : m_profile.m_joystick)
{
class InputDevice* joystick = InputDevice::GetJoystick(joy_idx);
if (joystick)
{
m_joysticks << joystick;
m_joystick_idx << joy_idx;
}
}
for (InputProfile::JoystickKey& key : m_profile.m_joystick_keys)
{
if (m_joystick_idx.find(key.m_joy) != INDEX_NONE)
GetKey(key.m_idx).BindJoystick(key.m_joy, key.m_name);
}
for (InputProfile::JoystickAxis& axis : m_profile.m_joystick_axis)
{
if (m_joystick_idx.find(axis.m_joy) != INDEX_NONE)
GetAxis(axis.m_idx).BindJoystick(axis.m_joy, axis.m_name);
}

m_mutex.unlock();
}

//-----------------------------------------------------------------------------
void Controller::tick_game(float seconds)
{
Entity::tick_game(seconds);

if (m_active)
{
for (auto &kv : m_key_bindings)
kv.second.Update();

for (auto &kv : m_axis_bindings)
kv.second.Update();
}

if (m_activate_nextframe)
m_active = true;

if (m_deactivate_nextframe)
m_active = false;

m_activate_nextframe = false;
m_deactivate_nextframe = false;
}

//-----------------------------------------------------------------------------
void Controller::Activate()
{
m_activate_nextframe = true;
m_deactivate_nextframe = false;
}

void Controller::Deactivate()
{
m_deactivate_nextframe = true;
m_activate_nextframe = false;
}

//-----------------------------------------------------------------------------
array<Controller*> Controller::DeactivateAll()
{
array<Controller*> result;

for (auto it : g_controllers)
{
if (it.second->m_active || it.second->m_activate_nextframe)
{
result.push(it.second);
it.second->Deactivate();
}
}

return result;
}

} /* namespace lol */

+ 0
- 352
src/ui/controller.h Ver arquivo

@@ -1,352 +0,0 @@
//
// Lol Engine
//
// Copyright © 2017—2019 Sam Hocevar <sam@hocevar.net>
// © 2010—2015 Benjamin Litzelmann
//
// 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.
//

#pragma once

#include <string>
#include <map>

namespace lol
{

//-----------------------------------------------------------------------------
class KeyBinding
{
friend class Controller;

protected:
//Status methods ----------------------------------------------------------
/** Indicates wheither the key is currently down */
bool IsPressed() const { return m_current; }
/** Indicates wheither the key is currently up */
bool IsReleased() const { return !m_current; }

public:
//Binding methods ---------------------------------------------------------
/** Bind a physical device and key */
void Bind(const std::string& device_name, const std::string& key_name);
/** Unbind a previously bound physical device and key. Returns true if the binding was existing. */
bool Unbind(const std::string& device_name, const std::string& key_name);
/* Small helpers */
void BindMouse(const std::string& key_name) { Bind(g_name_mouse, key_name); }
void BindKeyboard(const std::string& key_name) { Bind(g_name_keyboard, key_name); }
void BindJoystick(const uint64_t num, const std::string& key_name) { Bind(g_name_joystick(num), key_name); }
bool UnbindMouse(const std::string& key_name) { return Unbind(g_name_mouse, key_name); }
bool UnbindKeyboard(const std::string& key_name) { return Unbind(g_name_keyboard, key_name); }
bool UnbindJoystick(const uint64_t num, const std::string& key_name) { return Unbind(g_name_joystick(num), key_name); }

protected:
/** Update the binding value. Called internally by the controller, once per frame */
void Update()
{
m_previous = m_current;
m_current = false;
for (int i = 0; i < m_keybindings.count(); ++i)
m_current = m_current || m_keybindings[i].m1->key((input::key)m_keybindings[i].m2);
}

/** m1 is the InputDevice, m2 is the key index on the InputDevice */
array<const InputDevice*, int> m_keybindings;
/** Value at the previous frame */
bool m_current = false;
/** Value at the current frame */
bool m_previous = false;
};

//-----------------------------------------------------------------------------
class AxisBinding
{
friend class Controller;

protected:
//Status methods ----------------------------------------------------------
/** Gets the current absolute value of this axis */
float GetValue() const { return m_current; }
/** Gets the current delta value of this axis */
float GetDelta() const { return m_current - m_previous; }

public:
//Binding methods ---------------------------------------------------------
/** Bind a physical device and axis */
void Bind(const std::string& device_name, const std::string& axis_name);
/** Bind a physical device and key over this axis. The axis value will be 0 if the key is up and 1 if it's down */
void BindKey(const std::string& device_name, const std::string& key_name);
/** Bind physical device and keys over this axis. The axis value will be 0 if both the key are up, -1 if minkey is down, and 1 if maxkey is down */
void BindKeys(const std::string& device_name, const std::string& min_key_name, const std::string& max_key_name);
/** Unbind a previously bound physical device and axis. Returns true if the binding was existing. */
bool Unbind(const std::string& device_name, const std::string& axis_name);
/** Unbind a previously bound physical device and axis. Returns true if the binding was existing. */
bool UnbindKey(const std::string& device_name, const std::string& key_name);
/** Unbind a previously bound physical device and axis. Returns true if the binding was existing. */
bool UnbindKeys(const std::string& device_name, const std::string& min_key_name, const std::string& max_key_name);
/* Small helpers */
void BindMouse(const std::string& axis_name) { Bind(g_name_mouse, axis_name); }
bool UnbindMouse(const std::string& axis_name) { return Unbind(g_name_mouse, axis_name); }
/* */
void BindJoystick(const uint64_t num, const std::string& axis_name) { Bind(g_name_joystick(num), axis_name); }
bool UnbindJoystick(const uint64_t num, const std::string& axis_name) { return Unbind(g_name_joystick(num), axis_name); }

protected:
void Update()
{
m_previous = m_current;
m_current = RetrieveCurrentValue();
}
float RetrieveCurrentValue();

/** m1 is the InputDevice, m2 is the axis index on the InputDevice */
array<const InputDevice*, int> m_axisbindings;
/** m1 is the InputDevice, m2 is the key index on the InputDevice for the negative value, m3 is the key index on the InputDevice for the positive value. Only one key is required to bind key over axis. */
array<const InputDevice*, int, int> m_keybindings;
float m_current = 0.0f;
float m_previous = 0.0f;
};

//-------------------------------------------------------------------------
class InputProfile
{
friend class Controller;

private:
class Key
{
friend class Controller;
friend class InputProfile;
public:
Key() { }
Key(int idx, std::string const& name) : m_idx(idx), m_name(name) { }
Key(const Key& other) : m_idx(other.m_idx), m_name(other.m_name) { }
~Key() { }
bool operator==(const Key& other) { return m_name == other.m_name; }
private:
int m_idx = 0;
std::string m_name;
};

class Joystick
{
friend class Controller;
friend class InputProfile;
public:
Joystick() { }
Joystick(uint64_t joy, int idx, std::string const& name) : m_joy(joy), m_idx(idx), m_name(name) { }
Joystick(const Joystick& other) : m_joy(other.m_joy), m_idx(other.m_idx), m_name(other.m_name) { }
~Joystick() { }
bool operator==(const Joystick& other) { return m_name == other.m_name; }
private:
uint64_t m_joy = 0;
int m_idx = 0;
std::string m_name;
};

public:
class KeyboardKey : public Key
{
friend class Controller;
friend class InputProfile;
public:
KeyboardKey(int idx, std::string const& name) : Key(idx, name) { }
};

class MouseKey : public Key
{
friend class Controller;
friend class InputProfile;
public:
MouseKey(int idx, std::string const& name) : Key(idx, name) { }
};

class MouseAxis : public Key
{
friend class Controller;
friend class InputProfile;
public:
MouseAxis(int idx, std::string const& name) : Key(idx, name) { }
};

class JoystickKey : public Joystick
{
friend class Controller;
friend class InputProfile;
public:
JoystickKey(uint64_t joy, int idx, std::string const& name) : Joystick(joy, idx, name) { }
};

class JoystickAxis : public Joystick
{
friend class Controller;
friend class InputProfile;
public:
JoystickAxis(uint64_t joy, int idx, std::string const& name) : Joystick(joy, idx, name) { }
};

public:
InputProfile() = default;
virtual ~InputProfile() = default;

bool IsEmpty() const
{
return !GetKeyCount() && !GetAxisCount();
}
int GetKeyCount() const
{
return m_keys.count() + m_mouse_keys.count() + m_joystick_keys.count();
}
int GetAxisCount() const
{
return m_mouse_axis.count() + m_joystick_axis.count();
}
//Keys --------------------------------------------------------------------
InputProfile& operator<<(InputProfile::KeyboardKey const& binding)
{
m_keys.push_unique(binding);
return *this;
}
InputProfile& operator<<(array<InputProfile::KeyboardKey> const& bindings)
{
m_keys += bindings;
return *this;
}
//------
InputProfile& operator<<(InputProfile::MouseKey const& binding)
{
m_mouse_keys.push_unique(binding);
return *this;
}
InputProfile& operator<<(array<InputProfile::MouseKey> const& bindings)
{
m_mouse_keys += bindings;
return *this;
}
//------
InputProfile& operator<<(InputProfile::JoystickKey const& binding)
{
m_joystick.push_unique(binding.m_joy);
m_joystick_keys.push_unique(binding);
return *this;
}
InputProfile& operator<<(array<InputProfile::JoystickKey> const& bindings)
{
for (InputProfile::JoystickKey const& binding : bindings)
m_joystick.push_unique(binding.m_joy);
m_joystick_keys += bindings;
return *this;
}
//Axis --------------------------------------------------------------------
InputProfile& operator<<(InputProfile::MouseAxis const& binding)
{
m_mouse_axis.push_unique(binding);
return *this;
}
InputProfile& operator<<(array<InputProfile::MouseAxis> const& bindings)
{
m_mouse_axis += bindings;
return *this;
}
//------
InputProfile& operator<<(InputProfile::JoystickAxis const& binding)
{
m_joystick.push_unique(binding.m_joy);
m_joystick_axis.push_unique(binding);
return *this;
}
InputProfile& operator<<(array<InputProfile::JoystickAxis> const& bindings)
{
for (InputProfile::JoystickAxis const& binding : bindings)
m_joystick.push_unique(binding.m_joy);
m_joystick_axis += bindings;
return *this;
}

void register_default_keys()
{
#define _SC(id, str, name) *this << InputProfile::KeyboardKey(id, #name);
#include "ui/keys.inc"
}

private:
array<KeyboardKey> m_keys;
array<MouseKey> m_mouse_keys;
array<MouseAxis> m_mouse_axis;
array<uint64_t> m_joystick;
array<JoystickKey> m_joystick_keys;
array<JoystickAxis> m_joystick_axis;
};

//-----------------------------------------------------------------------------
//TODO: Add mask|layer system to prevent several controllers from interfering with another. (input overlay in menus)
class Controller : public Entity
{
public:
Controller(std::string const &name);
Controller(std::string const &name, InputProfile const& setup);
virtual ~Controller();

virtual void tick_game(float seconds);

/** Activate the controller on next frame */
void Activate();
/** Deactivate the controller on next frame */
void Deactivate();
/** Deactivate every active controller on next frame and return an array of deactivated (previously active) controllers */
static array<Controller*> DeactivateAll();

/** Init mode 1: Input profile system */
void Init(InputProfile const& profile);
void ClearProfile();

/** layer mask stuff */
void SetLayerMask(uint32_t layer_mask);
uint32_t GetLayerMask();
protected:
bool IsLayerActive();
public:

/** GetKeys/Axis stuff */
KeyBinding& GetKey(int index);
KeyBinding const& GetKey(int index) const;
AxisBinding& GetAxis(int index);
AxisBinding const& GetAxis(int index) const;

/** Axis methods: should not go directly to binding */
/** Gets the current absolute value of this axis */
float GetAxisValue(int index) const;
/** Gets the current delta value of this axis */
float GetAxisDelta(int index) const;

protected:
/** Input profile system */
void UnbindProfile();
void BindProfile(InputProfile const& setup);

private:
uint32_t m_layer_mask = 1; // plugged on the first by default
std::map<int, KeyBinding> m_key_bindings;
std::map<int, AxisBinding> m_axis_bindings;

std::string m_name;
bool m_activate_nextframe;
bool m_deactivate_nextframe;
bool m_active;

//Input profile stuff
mutex m_mutex;
class InputProfile m_profile;
std::shared_ptr<InputDevice> m_keyboard;
std::shared_ptr<InputDevice> m_mouse;
array<class InputDevice*> m_joysticks;
array<uint64_t> m_joystick_idx;
};

} /* namespace lol */


+ 6
- 13
src/ui/d3d9-input.cpp Ver arquivo

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

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");
static const std::string g_name_xbox_axis_right_y("Axis4");
static const std::string g_name_xbox_axis_left_trigger("Axis5");
static const std::string g_name_xbox_axis_right_trigger("Axis6");

/*
* D3d9 Input implementation class
*/
@@ -63,12 +56,12 @@ D3d9Input::D3d9Input()
// TODO: we can put more friendly name here, such as LeftAxisX, ButtonX...
InputDevice* stick = new InputDevice(g_name_joystick(i + 1));

stick->AddAxis(g_name_xbox_axis_left_x.c_str());
stick->AddAxis(g_name_xbox_axis_left_y.c_str());
stick->AddAxis(g_name_xbox_axis_right_x.c_str());
stick->AddAxis(g_name_xbox_axis_right_y.c_str());
stick->AddAxis(g_name_xbox_axis_left_trigger.c_str());
stick->AddAxis(g_name_xbox_axis_right_trigger.c_str());
stick->internal_add_axis(input::axis::LeftX, "LeftX");
stick->internal_add_axis(input::axis::LeftY, "LeftY");
stick->internal_add_axis(input::axis::RightX, "RightX");
stick->internal_add_axis(input::axis::RightY, "RightY");
stick->internal_add_axis(input::axis::LeftShoulder, "LeftShoulder");
stick->internal_add_axis(input::axis::RightShoulder, "RightShoulder");

#define _BTN(id, name) stick->internal_add_button(input::button::BTN_##name, #name);
#include "ui/buttons.inc" // FIXME: ignore mouse buttons here


+ 3
- 21
src/ui/gui.cpp Ver arquivo

@@ -31,11 +31,6 @@ namespace
MiddleClick,
Focus,
};

enum axis_enum
{
Scroll,
};
}

static gui* g_gui = nullptr;
@@ -88,19 +83,6 @@ gui::gui(ImFontAtlas *shared_font_atlas)

m_builder << ShaderProgram::Vertex << imgui_vertex
<< ShaderProgram::Pixel << imgui_pixel;

// Input Setup -------------------------------------------------------------
m_profile.register_default_keys();

m_profile << InputProfile::MouseKey(key_enum::LeftClick, g_name_mouse_key_left);
m_profile << InputProfile::MouseKey(key_enum::RightClick, g_name_mouse_key_right);
m_profile << InputProfile::MouseKey(key_enum::MiddleClick, g_name_mouse_key_middle);
m_profile << InputProfile::MouseKey(key_enum::Focus, g_name_mouse_key_in_screen);

m_profile << InputProfile::MouseAxis(axis_enum::Scroll, g_name_mouse_axis_scroll);

Ticker::Ref(m_controller = new Controller("ImGui_Controller"));
m_controller->Init(m_profile);
}

gui::~gui()
@@ -252,12 +234,12 @@ void gui::tick_game(float seconds)
keyboard->capture_text(io.WantTextInput);

// Update mouse
vec2 cursor = mouse->get_cursor_uv(0);
cursor.y = 1.f - cursor.y;
vec2 cursor(mouse->axis(input::axis::X),
1.f - mouse->axis(input::axis::Y));

io.MousePos = cursor * video_size;
//msg::debug("%.2f/%.2f\n", io.MousePos.x, io.MousePos.y);
io.MouseWheel = m_controller->GetAxisValue(axis_enum::Scroll);
io.MouseWheel = mouse->axis(input::axis::Wheel);

io.MouseDown[0] = mouse->button(input::button::BTN_Left);
io.MouseDown[1] = mouse->button(input::button::BTN_Right);


+ 0
- 2
src/ui/gui.h Ver arquivo

@@ -85,8 +85,6 @@ protected:
Uniform m_texture;
array<ShaderAttrib> m_attribs;
std::shared_ptr<VertexDeclaration> m_vdecl;
Controller* m_controller = nullptr;
InputProfile m_profile;
std::string m_clipboard;

class primitive : public PrimitiveRenderer


+ 13
- 29
src/ui/input.cpp Ver arquivo

@@ -49,12 +49,15 @@ input::input()
m_mouse = std::make_shared<InputDevice>(g_name_mouse.c_str());
#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());
m_mouse->AddAxis(g_name_mouse_axis_ypixel.c_str());
m_mouse->AddAxis(g_name_mouse_axis_scroll.c_str(), .0000001f);
m_mouse->AddCursor(g_name_mouse_cursor.c_str());
m_mouse->internal_add_axis(input::axis::X, "X");
m_mouse->internal_add_axis(input::axis::Y, "Y");
m_mouse->internal_add_axis(input::axis::ScreenX, "ScreenX");
m_mouse->internal_add_axis(input::axis::ScreenY, "ScreenY");
m_mouse->internal_add_axis(input::axis::MoveX, "MoveX");
m_mouse->internal_add_axis(input::axis::MoveY, "MoveY");
m_mouse->internal_add_axis(input::axis::ScreenMoveX, "ScreenMoveX");
m_mouse->internal_add_axis(input::axis::ScreenMoveY, "ScreenMoveY");
m_mouse->internal_add_axis(input::axis::Wheel, "Wheel");
}

// Lookup tables for scancode and key name lookups
@@ -135,34 +138,15 @@ void InputDevice::internal_add_button(input::button button, const char* name)
m_button_names[(int)button] = name;
}

void InputDevice::AddAxis(int index, const char* name, float sensitivity)
void InputDevice::internal_add_axis(input::axis axis, const char* name)
{
if (index == -1)
index = (int)m_axis_names.size();

while (index >= (int)m_axis_names.size())
while ((int)axis >= (int)m_axis_names.size())
{
m_axis_names.push_back("");
m_axis.push(0.0f, 1.0f);
}

m_axis_names[index] = name;
m_axis[index].m1 = 0.0f;
m_axis[index].m2 = sensitivity;
}

void InputDevice::AddCursor(int index, const char* name)
{
if (index == -1)
index = (int)m_cursor_names.size();

while (index >= (int)m_cursor_names.size())
{
m_cursor_names.push_back("");
m_cursors.push_back(cursor_state());
m_axes.push_back(0.0f);
}

m_cursor_names[index] = name;
m_axis_names[(int)axis] = name;
}

} /* namespace lol */

+ 53
- 113
src/ui/input.h Ver arquivo

@@ -25,19 +25,6 @@ extern const std::string g_name_mouse;
extern const std::string g_name_keyboard;
extern std::string g_name_joystick(const uint64_t num);

// Mouse default buttons/axis
const std::string g_name_mouse_key_left("Left");
const std::string g_name_mouse_key_middle("Middle");
const std::string g_name_mouse_key_right("Right");
const std::string g_name_mouse_key_in_screen("InScreen");

const std::string g_name_mouse_axis_x("X");
const std::string g_name_mouse_axis_y("Y");
const std::string g_name_mouse_axis_xpixel("XPixel");
const std::string g_name_mouse_axis_ypixel("YPixel");
const std::string g_name_mouse_axis_scroll("Scroll");
const std::string g_name_mouse_cursor("Cursor");

class input
{
public:
@@ -62,6 +49,27 @@ public:
#include "ui/buttons.inc"
};

enum class axis : uint16_t
{
// Mouse
Wheel,
X,
Y,
ScreenX,
ScreenY,
MoveX,
MoveY,
ScreenMoveX,
ScreenMoveY,
// Joystick
LeftX,
LeftY,
RightX,
RightY,
LeftShoulder,
RightShoulder,
};

static std::vector<key> const &all_keys();
static std::string const &key_to_name(key k);
static key name_to_key(std::string const &name);
@@ -125,6 +133,9 @@ public:
void bind(input::button button, uint16_t event);
void unbind(input::button button, uint16_t event);

void bind(input::axis axis, uint16_t event);
void unbind(input::axis axis, uint16_t event);

//
// Key, button etc. state
//
@@ -155,6 +166,16 @@ public:
return m_pressed_buttons.find(button) != m_pressed_buttons.end();
}

// Get the current state of the given axis
float axis(input::axis axis) const { return m_axes[(int)axis]; }

bool axis_changed(input::axis axis) const
{
return m_changed_axes.find(axis) != m_changed_axes.end();
}

// TODO: axis sensitivity was removed

//
// Keyboard-specific section
//
@@ -179,86 +200,24 @@ public:
void capture(bool value) { m_capture = value; }
bool capture() const { return m_capture; }

/** Gets the current value of the given axis. Devices should try to
* clamp this value between -1 and 1, though it is not guaranteed. */
float GetAxis(int index) const
{
return m_axis[index].m1 * m_axis[index].m2;
}

/** Gets the current value of the given cursor, 0,0 being the bottom-left
* corner and 1,1 being the top-right corner */
vec2 get_cursor_uv(int index) const
{
return m_cursors[index].uv;
}

/** Gets the coordinate of the pixel the cursor is currently over,
* 0,0 being the bottom-left corner. */
ivec2 get_cursor_pixel(int index) const
{
return m_cursors[index].pixel;
}

/** Sets a per-device-axis sensitivity factor. The value returned by
* the operating system will be multiplied by this value before being
* returned by GetAxis */
void SetAxisSensitivity(int index, float sensitivity)
{
m_axis[index].m2 = sensitivity;
}

/** Gets the per-device-axis sensitivity factor. The value returned by
* the operating system will be multiplied by this value before being
* returned by GetAxis */
float GetAxisSensitivity(int index) const
{
return m_axis[index].m2;
}

/** Gets a list of the name of all available axis in this device */
const std::vector<std::string>& GetAllAxis() const
{
return m_axis_names;
}
/** Gets a list of the name of all available cursors in this device */
const std::vector<std::string>& GetAllCursors() const
{
return m_cursor_names;
}

/** Gets an input device by its name */
static InputDevice* Get(std::string const &name)
{
return GetDevice(name);
}

/** Default helpers */
static InputDevice* GetJoystick(const uint64_t num)
{
return GetDevice(g_name_joystick(num));
for (int i = 0; i < devices.count(); ++i)
{
if (devices[i]->m_name == name)
return devices[i];
}
return nullptr;
}

public:
/** Internal functions that allow to construct an InputDevice
* dynamically, when the keys, axis and cursors are not known at
* compile time. */
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);

inline void AddAxis(char const * name, float sensitivity = 1.0f)
{
AddAxis(-1, name, sensitivity);
}

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

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

/* Internal functions for the platform-specific drivers. */
void internal_begin_frame()
@@ -267,12 +226,7 @@ public:
m_released_keys.clear();
m_pressed_buttons.clear();
m_released_buttons.clear();
}

void internal_set_cursor(int id, vec2 const & position, ivec2 const & pixel)
{
m_cursors[id].uv = position;
m_cursors[id].pixel = pixel;
m_changed_axes.clear();
}

void internal_set_key(input::key key, bool state)
@@ -289,14 +243,16 @@ public:
m_buttons[(int)button] = state;
}

void internal_add_text(std::string const &text)
void internal_set_axis(input::axis axis, float value)
{
m_text += text;
if (m_axes[(int)axis] != value)
m_changed_axes.insert(axis);
m_axes[(int)axis] = value;
}

void internal_set_axis(int id, float value)
void internal_add_text(std::string const &text)
{
m_axis[id].m1 = value;
m_text += text;
}

protected:
@@ -307,25 +263,19 @@ protected:
std::vector<std::string> m_key_names;
std::vector<std::string> m_button_names;
std::vector<std::string> m_axis_names;
std::vector<std::string> m_cursor_names;

/** Key and button states (pressed/released) */
std::vector<bool> m_keys;
std::unordered_set<input::key> m_pressed_keys, m_released_keys;
std::vector<bool> m_buttons;
std::unordered_set<input::button> m_pressed_buttons, m_released_buttons;
std::vector<float> m_axes;
std::unordered_set<input::axis> m_changed_axes;

/** Text input state */
// Text input state
std::string m_text;
bool m_input_active;

/** Axis states (value and sensitivity) */
array<float, float> m_axis;

/** Cursor position */
struct cursor_state { vec2 uv; ivec2 pixel; };
std::vector<cursor_state> m_cursors;

// Capture (for mouse devices)
bool m_capture = false;

@@ -340,16 +290,6 @@ private:
return (int)i;
return -1;
}

static InputDevice* GetDevice(std::string const &name)
{
for (int i = 0; i < devices.count(); ++i)
{
if (devices[i]->m_name == name)
return devices[i];
}
return nullptr;
}
};

} /* namespace lol */


+ 25
- 15
src/ui/sdl-input.cpp Ver arquivo

@@ -85,7 +85,7 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h)

InputDevice* stick = new InputDevice(g_name_joystick(i + 1));
for (int j = 0; j < SDL_JoystickNumAxes(sdlstick); ++j)
stick->AddAxis(format("Axis%d", j + 1).c_str());
stick->internal_add_axis((input::axis)(j + 1), format("Axis%d", j + 1).c_str());
for (int j = 0; j < SDL_JoystickNumButtons(sdlstick); ++j)
stick->internal_add_button((input::button)(j + 1), format("Button%d", j + 1).c_str());

@@ -142,12 +142,12 @@ void SdlInput::tick(float seconds)
for (int i = 0; i < SDL_JoystickNumButtons(m_joysticks[j].m1); i++)
m_joysticks[j].m2->internal_set_button((input::button)i, SDL_JoystickGetButton(m_joysticks[j].m1, i) != 0);
for (int i = 0; i < SDL_JoystickNumAxes(m_joysticks[j].m1); i++)
m_joysticks[j].m2->internal_set_axis(i, (float)SDL_JoystickGetAxis(m_joysticks[j].m1, i) / 32768.f);
m_joysticks[j].m2->internal_set_axis((input::axis)i, (float)SDL_JoystickGetAxis(m_joysticks[j].m1, i) / 32768.f);
}
# endif

keyboard->internal_begin_frame();
mouse->internal_set_axis(4, 0);
float mouse_wheel = 0.f;

if (keyboard->capture_text())
SDL_StartTextInput();
@@ -204,7 +204,7 @@ void SdlInput::tick(float seconds)
event.type == SDL_MOUSEBUTTONDOWN);
break;
case SDL_MOUSEWHEEL:
mouse->internal_set_axis(4, (float)event.button.y);
mouse_wheel += (float)event.button.y;
break;
case SDL_WINDOWEVENT:
{
@@ -239,6 +239,13 @@ void SdlInput::tick(float seconds)
}

/* Handle mouse input */
mouse->internal_set_axis(input::axis::Wheel, mouse_wheel);

ivec2 window_size;
// FIXME: get actual window size
//SDL_GetWindowSize(m_window, &window_size.x, &window_size.y);
window_size = (ivec2)m_app;

ivec2 mouse_pos(-1, -1);
SDL_GetMouseState(&mouse_pos.x, &mouse_pos.y);
mouse_pos.y = Video::GetSize().y - 1 - mouse_pos.y;
@@ -247,32 +254,35 @@ void SdlInput::tick(float seconds)
{
m_mousecapture = mouse->capture();
SDL_SetRelativeMouseMode(m_mousecapture ? SDL_TRUE : SDL_FALSE);
mouse_pos = ivec2(m_app * .5f);

// FIXME: how do I warped mouse?
//SDL_WarpMouse((uint16_t)mouse_pos.x, (uint16_t)mouse_pos.y);
//SDL_ShowCursor(m_mousecapture ? SDL_DISABLE : SDL_ENABLE);
// FIXME: get handle to window
//SDL_WarpMouseInWindow(m_window, window_size.x / 2, window_size.y / 2);
SDL_ShowCursor(m_mousecapture ? SDL_DISABLE : SDL_ENABLE);
}

if (mouse_pos.x >= 0 && mouse_pos.x < m_app.x && mouse_pos.y >= 0 && mouse_pos.y < m_app.y)
if (mouse_pos.x >= 0 && mouse_pos.x < window_size.x && mouse_pos.y >= 0 && mouse_pos.y < window_size.y)
{
//We need the max if we want coherent mouse speed between axis
float max_screen_size = lol::max(m_screen.x, m_screen.y);
vec2 vmouse = vec2(mouse_pos);
vec2 vprevmouse = vec2(m_prev_mouse_pos);
mouse->internal_set_cursor(0, vmouse / m_app, mouse_pos);
mouse->internal_set_axis(input::axis::X, vmouse.x / window_size.x);
mouse->internal_set_axis(input::axis::Y, vmouse.y / window_size.y);
mouse->internal_set_axis(input::axis::ScreenX, mouse_pos.x);
mouse->internal_set_axis(input::axis::ScreenY, mouse_pos.y);

// Note: 100.0f is an arbitrary value that makes it feel about the same than an xbox controller joystick
mouse->internal_set_axis(0, (mouse_pos.x - vprevmouse.x) * MOUSE_SPEED_MOD / max_screen_size);
mouse->internal_set_axis(input::axis::MoveX, (mouse_pos.x - vprevmouse.x) * MOUSE_SPEED_MOD / max_screen_size);
// Y Axis is also negated to match the usual joystick Y axis (negatives values are for the upper direction)
mouse->internal_set_axis(1,-(mouse_pos.y - vprevmouse.y) * MOUSE_SPEED_MOD / max_screen_size);
mouse->internal_set_axis(input::axis::MoveY,-(mouse_pos.y - vprevmouse.y) * MOUSE_SPEED_MOD / max_screen_size);
//Pixel movement
mouse->internal_set_axis(2, (mouse_pos.x - vprevmouse.x));
mouse->internal_set_axis(3,-(mouse_pos.y - vprevmouse.y));
mouse->internal_set_axis(input::axis::ScreenMoveX, (mouse_pos.x - vprevmouse.x));
mouse->internal_set_axis(input::axis::ScreenMoveY,-(mouse_pos.y - vprevmouse.y));
}

if (m_mousecapture)
{
mouse_pos = ivec2(m_app * .5f);
//mouse_pos = ivec2(window_size * .5f);
//SDL_WarpMouse((uint16_t)mouse_pos.x, (uint16_t)mouse_pos.y);
}



+ 1
- 1
src/ui/sdl-input.h Ver arquivo

@@ -48,10 +48,10 @@ private:

array<SDL_Joystick *, class InputDevice *> m_joysticks;

ivec2 m_prev_mouse_pos = ivec2::zero;
vec2 m_app;
vec2 m_screen;

ivec2 m_prev_mouse_pos = ivec2::zero;
bool m_mousecapture = false;
bool m_tick_in_draw_thread = false;
};


Carregando…
Cancelar
Salvar