diff --git a/doc/tutorial/12_voronoi.cpp b/doc/tutorial/12_voronoi.cpp
index 3e1c710c..58d14d93 100644
--- a/doc/tutorial/12_voronoi.cpp
+++ b/doc/tutorial/12_voronoi.cpp
@@ -67,12 +67,12 @@ public:
m_timer = -1.0f;
mode = 0;
m_controller = new Controller("Default");
- m_controller->GetKey(KEY_ESC).Bind("Keyboard", "Escape");
- m_controller->GetKey(KEY_PUSH).Bind("Keyboard", "p");
- m_controller->GetKey(KEY_POP).Bind("Keyboard", "o");
- m_controller->GetKey(KEY_F1).Bind("Keyboard", "F1");
- m_controller->GetKey(KEY_F2).Bind("Keyboard", "F2");
- m_controller->GetKey(KEY_F3).Bind("Keyboard", "F3");
+ m_controller->GetKey(KEY_ESC).Bind(g_name_keyboard, "Escape");
+ m_controller->GetKey(KEY_PUSH).Bind(g_name_keyboard, "p");
+ m_controller->GetKey(KEY_POP).Bind(g_name_keyboard, "o");
+ m_controller->GetKey(KEY_F1).Bind(g_name_keyboard, "F1");
+ m_controller->GetKey(KEY_F2).Bind(g_name_keyboard, "F2");
+ m_controller->GetKey(KEY_F3).Bind(g_name_keyboard, "F3");
}
virtual void tick_game(float seconds)
diff --git a/src/lol/base/features.h b/src/lol/base/features.h
index 95a4d869..b3561f05 100644
--- a/src/lol/base/features.h
+++ b/src/lol/base/features.h
@@ -113,7 +113,7 @@
#endif
#ifdef LOL_FEATURE_CXX17_ATTRIBUTE_FALLTHROUGH
-# define LOL_ATTR_FALLTHROUGH [[fallthrough]]
+# define LOL_ATTR_FALLTHROUGH [[fallthrough]];
#else
# define LOL_ATTR_FALLTHROUGH /* */
#endif
diff --git a/src/math/real.cpp b/src/math/real.cpp
index 7c7c7417..1c938130 100644
--- a/src/math/real.cpp
+++ b/src/math/real.cpp
@@ -275,7 +275,7 @@ template<> real::Real(char const *str)
finished = true;
break;
}
- LOL_ATTR_FALLTHROUGH;
+ LOL_ATTR_FALLTHROUGH
case 'a': case 'b': case 'c': case 'd': case 'f':
case 'A': case 'B': case 'C': case 'D': case 'F':
case '0': case '1': case '2': case '3': case '4':
diff --git a/src/ui/gui.cpp b/src/ui/gui.cpp
index b475e9d8..69f15777 100644
--- a/src/ui/gui.cpp
+++ b/src/ui/gui.cpp
@@ -241,13 +241,15 @@ void gui::tick_game(float seconds)
for (input::key k : input::all_keys())
io.KeysDown[(int)k] = m_controller->IsKeyPressed((int)k);
- keyboard->SetTextInputActive(io.WantTextInput);
-
- //Update text input
- std::string text = keyboard->GetText();
- //text.case_change(io.KeyShift);
- for (auto ch : text)
- io.AddInputCharacter(ch);
+ // Update text input
+ if (io.WantTextInput)
+ {
+ std::string text = keyboard->text();
+ //text.case_change(io.KeyShift);
+ for (auto ch : text)
+ io.AddInputCharacter(ch);
+ }
+ keyboard->capture_text(io.WantTextInput);
// Update mouse
vec2 cursor = mouse->GetCursor(0);
diff --git a/src/ui/input.cpp b/src/ui/input.cpp
index e3cd7f0e..712da7d0 100644
--- a/src/ui/input.cpp
+++ b/src/ui/input.cpp
@@ -22,6 +22,14 @@
namespace lol
{
+const std::string g_name_mouse("mouse");
+const std::string g_name_keyboard("keyboard");
+
+std::string g_name_joystick(const uint64_t num)
+{
+ return format("joystick%d", (int)num);
+}
+
std::shared_ptr input::get()
{
static auto instance = new input();
@@ -91,27 +99,19 @@ input::key input::name_to_key(std::string const &name)
array InputDevice::devices;
-array InputDevice::GetAvailableDevices()
-{
- array result;
- for (auto const &device : devices)
- result.push(device->m_name);
- return result;
-}
-
-std::string InputDevice::GetText()
+std::string InputDevice::text()
{
std::string ret = m_text;
m_text = "";
return ret;
}
-bool InputDevice::IsTextInputActive()
+bool InputDevice::capture_text()
{
return m_input_active;
}
-void InputDevice::SetTextInputActive(bool status)
+void InputDevice::capture_text(bool status)
{
m_input_active = status;
}
diff --git a/src/ui/input.h b/src/ui/input.h
index 300f9132..d4330415 100644
--- a/src/ui/input.h
+++ b/src/ui/input.h
@@ -20,13 +20,9 @@
namespace lol
{
-const std::string g_name_mouse("Mouse");
-const std::string g_name_keyboard("Keyboard");
-
-static std::string g_name_joystick(const uint64_t num)
-{
- return format("Joystick%d", (int)num);
-}
+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");
@@ -86,6 +82,10 @@ public:
return GetItemIndex(name, m_cursor_names);
}
+ //
+ // Keyboard-specific section
+ //
+
/** Get the names of all available keys on this device */
std::vector const& key_names() const { return m_key_names; }
@@ -97,9 +97,12 @@ public:
bool key(ptrdiff_t index) const { return m_keys[index]; }
/** Gets the latest contents of text input. */
- std::string GetText();
- bool IsTextInputActive();
- void SetTextInputActive(bool status);
+ std::string text();
+
+ bool capture_text();
+ void capture_text(bool status);
+
+
/** Gets the current value of the given axis. Devices should try to
* clamp this value between -1 and 1, though it is not guaranteed. */
@@ -149,9 +152,6 @@ public:
return m_cursor_names;
}
- /** Gets a list of the name of all available input devices */
- static array GetAvailableDevices();
-
/** Gets an input device by its name */
static InputDevice* Get(std::string const &name)
{
diff --git a/src/ui/sdl-input.cpp b/src/ui/sdl-input.cpp
index be45709d..579062aa 100644
--- a/src/ui/sdl-input.cpp
+++ b/src/ui/sdl-input.cpp
@@ -39,37 +39,6 @@
namespace lol
{
-//-------------------------------------------------------------------------
-/* DEBUG STUFF
-static String ScanCodeToText(int sc)
-{
- switch (sc)
- {
-#define _SC(id, str, name) \
- case id: return String(str);
-#include "ui/keys.inc"
- default:
- msg::error("ScanCodeToText unknown scancode %0d\n", sc);
- }
- return String();
-}
-*/
-//-------------------------------------------------------------------------
-/* DEBUG STUFF
-static String ScanCodeToName(int sc)
-{
- switch (sc)
- {
-#define _SC(id, str, name) \
- case id: return String(#name);
-#include "ui/keys.inc"
- default:
- msg::error("ScanCodeToText unknown scancode %0d\n", sc);
- }
- return String();
-}
-*/
-
/*
* Public SdlInput class
*/
@@ -179,7 +148,7 @@ void SdlInput::tick(float seconds)
mouse->internal_set_axis(4, 0);
- if (keyboard->IsTextInputActive())
+ if (keyboard->capture_text())
SDL_StartTextInput();
else
SDL_StopTextInput();
@@ -219,12 +188,8 @@ void SdlInput::tick(float seconds)
break;
}
keyboard->internal_set_key(sc2, !keyboard->key((int)sc2));
- /* DEBUG STUFF
- msg::debug("Repeat: 0x%02x : %s/%s/%s/%i\n",
- (int)keyboard, ScanCodeToText(sc2).C(), ScanCodeToName(sc2).C(),
- keyboard->GetKey(sc2) ? "up" : "down", event.key.repeat);
- */
}
+ LOL_ATTR_FALLTHROUGH
default:
// Set key updates the corresponding key
keyboard->internal_set_key(sc, event.type == SDL_KEYDOWN);
@@ -298,7 +263,7 @@ void SdlInput::tick(float seconds)
//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_prevmouse);
+ vec2 vprevmouse = vec2(m_prev_mouse_pos);
mouse->SetCursor(0, vmouse / m_app, mouse_pos);
// 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);
@@ -315,7 +280,7 @@ void SdlInput::tick(float seconds)
//SDL_WarpMouse((uint16_t)mouse_pos.x, (uint16_t)mouse_pos.y);
}
- m_prevmouse = mouse_pos;
+ m_prev_mouse_pos = mouse_pos;
#else
UNUSED(seconds);
diff --git a/src/ui/sdl-input.h b/src/ui/sdl-input.h
index cba73616..a5455305 100644
--- a/src/ui/sdl-input.h
+++ b/src/ui/sdl-input.h
@@ -48,7 +48,7 @@ private:
array m_joysticks;
- ivec2 m_prevmouse = ivec2::zero;
+ ivec2 m_prev_mouse_pos = ivec2::zero;
vec2 m_app;
vec2 m_screen;