Browse Source

input: remove dead code and more cleanup.

legacy
Sam Hocevar 5 years ago
parent
commit
1388625308
8 changed files with 46 additions and 79 deletions
  1. +6
    -6
      doc/tutorial/12_voronoi.cpp
  2. +1
    -1
      src/lol/base/features.h
  3. +1
    -1
      src/math/real.cpp
  4. +9
    -7
      src/ui/gui.cpp
  5. +11
    -11
      src/ui/input.cpp
  6. +13
    -13
      src/ui/input.h
  7. +4
    -39
      src/ui/sdl-input.cpp
  8. +1
    -1
      src/ui/sdl-input.h

+ 6
- 6
doc/tutorial/12_voronoi.cpp View File

@@ -67,12 +67,12 @@ public:
m_timer = -1.0f; m_timer = -1.0f;
mode = 0; mode = 0;
m_controller = new Controller("Default"); 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) virtual void tick_game(float seconds)


+ 1
- 1
src/lol/base/features.h View File

@@ -113,7 +113,7 @@
#endif #endif


#ifdef LOL_FEATURE_CXX17_ATTRIBUTE_FALLTHROUGH #ifdef LOL_FEATURE_CXX17_ATTRIBUTE_FALLTHROUGH
# define LOL_ATTR_FALLTHROUGH [[fallthrough]]
# define LOL_ATTR_FALLTHROUGH [[fallthrough]];
#else #else
# define LOL_ATTR_FALLTHROUGH /* */ # define LOL_ATTR_FALLTHROUGH /* */
#endif #endif


+ 1
- 1
src/math/real.cpp View File

@@ -275,7 +275,7 @@ template<> real::Real(char const *str)
finished = true; finished = true;
break; 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 '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': case '0': case '1': case '2': case '3': case '4':


+ 9
- 7
src/ui/gui.cpp View File

@@ -241,13 +241,15 @@ void gui::tick_game(float seconds)
for (input::key k : input::all_keys()) for (input::key k : input::all_keys())
io.KeysDown[(int)k] = m_controller->IsKeyPressed((int)k); 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 // Update mouse
vec2 cursor = mouse->GetCursor(0); vec2 cursor = mouse->GetCursor(0);


+ 11
- 11
src/ui/input.cpp View File

@@ -22,6 +22,14 @@
namespace lol 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> input::get() std::shared_ptr<input> input::get()
{ {
static auto instance = new input(); static auto instance = new input();
@@ -91,27 +99,19 @@ input::key input::name_to_key(std::string const &name)


array<InputDevice*> InputDevice::devices; array<InputDevice*> InputDevice::devices;


array<std::string> InputDevice::GetAvailableDevices()
{
array<std::string> 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; std::string ret = m_text;
m_text = ""; m_text = "";
return ret; return ret;
} }


bool InputDevice::IsTextInputActive()
bool InputDevice::capture_text()
{ {
return m_input_active; return m_input_active;
} }


void InputDevice::SetTextInputActive(bool status)
void InputDevice::capture_text(bool status)
{ {
m_input_active = status; m_input_active = status;
} }


+ 13
- 13
src/ui/input.h View File

@@ -20,13 +20,9 @@
namespace lol 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 // Mouse default buttons/axis
const std::string g_name_mouse_key_left("Left"); const std::string g_name_mouse_key_left("Left");
@@ -86,6 +82,10 @@ public:
return GetItemIndex(name, m_cursor_names); return GetItemIndex(name, m_cursor_names);
} }


//
// Keyboard-specific section
//

/** Get the names of all available keys on this device */ /** Get the names of all available keys on this device */
std::vector<std::string> const& key_names() const { return m_key_names; } std::vector<std::string> const& key_names() const { return m_key_names; }


@@ -97,9 +97,12 @@ public:
bool key(ptrdiff_t index) const { return m_keys[index]; } bool key(ptrdiff_t index) const { return m_keys[index]; }


/** Gets the latest contents of text input. */ /** 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 /** Gets the current value of the given axis. Devices should try to
* clamp this value between -1 and 1, though it is not guaranteed. */ * clamp this value between -1 and 1, though it is not guaranteed. */
@@ -149,9 +152,6 @@ public:
return m_cursor_names; return m_cursor_names;
} }


/** Gets a list of the name of all available input devices */
static array<std::string> GetAvailableDevices();

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


+ 4
- 39
src/ui/sdl-input.cpp View File

@@ -39,37 +39,6 @@
namespace lol 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 * Public SdlInput class
*/ */
@@ -179,7 +148,7 @@ void SdlInput::tick(float seconds)


mouse->internal_set_axis(4, 0); mouse->internal_set_axis(4, 0);


if (keyboard->IsTextInputActive())
if (keyboard->capture_text())
SDL_StartTextInput(); SDL_StartTextInput();
else else
SDL_StopTextInput(); SDL_StopTextInput();
@@ -219,12 +188,8 @@ void SdlInput::tick(float seconds)
break; break;
} }
keyboard->internal_set_key(sc2, !keyboard->key((int)sc2)); 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: default:
// Set key updates the corresponding key // Set key updates the corresponding key
keyboard->internal_set_key(sc, event.type == SDL_KEYDOWN); 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 //We need the max if we want coherent mouse speed between axis
float max_screen_size = lol::max(m_screen.x, m_screen.y); float max_screen_size = lol::max(m_screen.x, m_screen.y);
vec2 vmouse = vec2(mouse_pos); 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); 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 // 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(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); //SDL_WarpMouse((uint16_t)mouse_pos.x, (uint16_t)mouse_pos.y);
} }


m_prevmouse = mouse_pos;
m_prev_mouse_pos = mouse_pos;


#else #else
UNUSED(seconds); UNUSED(seconds);


+ 1
- 1
src/ui/sdl-input.h View File

@@ -48,7 +48,7 @@ private:


array<SDL_Joystick *, class InputDevice *> m_joysticks; array<SDL_Joystick *, class InputDevice *> m_joysticks;


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




Loading…
Cancel
Save