diff --git a/src/lol-core.vcxproj b/src/lol-core.vcxproj
index af4e4294..66b7abe1 100644
--- a/src/lol-core.vcxproj
+++ b/src/lol-core.vcxproj
@@ -121,10 +121,14 @@
-
+
+ true
+
-
+
+ true
+
diff --git a/src/ui/input.cpp b/src/ui/input.cpp
index fa31f6a0..12823fca 100644
--- a/src/ui/input.cpp
+++ b/src/ui/input.cpp
@@ -2,7 +2,6 @@
// Lol Engine
//
// Copyright © 2017—2019 Sam Hocevar
-// © 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
@@ -105,24 +104,24 @@ std::shared_ptr input::joystick(int n)
// input::device
//
-std::string input::device::text()
+std::string input::device::keyboard::text()
{
std::string ret = m_text;
m_text = "";
return ret;
}
-bool input::device::capture_text()
+bool input::device::keyboard::capture_text()
{
return m_input_active;
}
-void input::device::capture_text(bool status)
+void input::device::keyboard::capture_text(bool status)
{
m_input_active = status;
}
-void input::device::internal_add_key(input::key key, const char* name)
+void input::device::keyboard::internal_add_key(input::key key, const char* name)
{
while ((int)key >= (int)m_key_names.size())
{
diff --git a/src/ui/input.h b/src/ui/input.h
index 5f5237ee..c934be7e 100644
--- a/src/ui/input.h
+++ b/src/ui/input.h
@@ -2,7 +2,6 @@
// Lol Engine
//
// Copyright © 2017—2019 Sam Hocevar
-// © 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
@@ -21,6 +20,8 @@
namespace lol
{
+// FIXME: maybe m_key_names is no longer required?
+
class input
{
public:
@@ -66,11 +67,8 @@ public:
class keyboard;
class joystick;
- /** Gets the name of this input device */
- const std::string& GetName() const
- {
- return m_name;
- }
+ // Get the name of this input device
+ const std::string& name() const { return m_name; }
//
// Bindings section
@@ -134,35 +132,10 @@ public:
// TODO: axis sensitivity was removed
- //
- // Keyboard-specific section
- //
-
- /** Get the names of all available keys on this device */
- std::vector const& key_names() const { return m_key_names; }
-
- /** Get the current state of all keys */
- std::vector const &keys() const { return m_keys; }
-
- /** Gets the latest contents of text input. */
- std::string text();
-
- bool capture_text();
- void capture_text(bool status);
-
- //
- // Mouse-specific section
- //
-
- // Gets and sets whether the mouse cursor should be captured.
- void capture(bool value) { m_capture = value; }
- bool capture() const { return m_capture; }
-
public:
/** Internal functions that allow to construct an input device
* 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 internal_add_axis(input::axis, char const *name);
@@ -176,13 +149,6 @@ public:
m_changed_axes.clear();
}
- void internal_set_key(input::key key, bool state)
- {
- if (m_keys[(int)key] != state)
- (state ? m_pressed_keys : m_released_keys).insert(key);
- m_keys[(int)key] = state;
- }
-
void internal_set_button(input::button button, bool state)
{
if (m_buttons[(int)button] != state)
@@ -197,11 +163,6 @@ public:
m_axes[(int)axis] = value;
}
- void internal_add_text(std::string const &text)
- {
- m_text += text;
- }
-
protected:
std::string m_name;
@@ -216,13 +177,6 @@ public:
std::unordered_set m_pressed_buttons, m_released_buttons;
std::vector m_axes;
std::unordered_set m_changed_axes;
-
- // Text input state
- std::string m_text;
- bool m_input_active = false;
-
- // Capture (for mouse devices)
- bool m_capture = false;
};
// Default devices
@@ -245,18 +199,68 @@ private:
std::map> m_joysticks;
};
+//
+// The mouse class
+//
+
class input::device::mouse : public input::device
{
public:
mouse(std::string const &name) : input::device(name) {}
+
+ // Gets and sets whether the mouse cursor should be captured.
+ void capture(bool value) { m_capture = value; }
+ bool capture() const { return m_capture; }
+
+private:
+ // Capture mouse pointer
+ bool m_capture = false;
};
+//
+// The keyboard class
+//
+
class input::device::keyboard : public input::device
{
public:
keyboard(std::string const &name) : input::device(name) {}
+
+ // Get the names of all available keys on this device
+ std::vector const& key_names() const { return m_key_names; }
+
+ // Get the current state of all keys
+ std::vector const &keys() const { return m_keys; }
+
+ // Gets the latest contents of text input.
+ std::string text();
+
+ bool capture_text();
+ void capture_text(bool status);
+
+ void internal_add_key(input::key, char const *name);
+ void internal_set_key(input::key key, bool state)
+ {
+ if (m_keys[(int)key] != state)
+ (state ? m_pressed_keys : m_released_keys).insert(key);
+ m_keys[(int)key] = state;
+ }
+
+ void internal_add_text(std::string const &text)
+ {
+ m_text += text;
+ }
+
+private:
+ // Text input state
+ std::string m_text;
+ bool m_input_active = false;
};
+//
+// The joystick class
+//
+
class input::device::joystick : public input::device
{
public:
diff --git a/src/ui/sdl-input.cpp b/src/ui/sdl-input.cpp
index 9f52608f..0f0a318a 100644
--- a/src/ui/sdl-input.cpp
+++ b/src/ui/sdl-input.cpp
@@ -267,8 +267,8 @@ void SdlInput::tick(float seconds)
vec2 vprevmouse = vec2(m_prev_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);
+ mouse->internal_set_axis(input::axis::ScreenX, (float)mouse_pos.x);
+ mouse->internal_set_axis(input::axis::ScreenY, (float)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(input::axis::MoveX, (mouse_pos.x - vprevmouse.x) * MOUSE_SPEED_MOD / max_screen_size);