Przeglądaj źródła

input: remove dead code and more cleanup.

legacy
Sam Hocevar 5 lat temu
rodzic
commit
1388625308
8 zmienionych plików z 46 dodań i 79 usunięć
  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 Wyświetl plik

@@ -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)


+ 1
- 1
src/lol/base/features.h Wyświetl plik

@@ -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


+ 1
- 1
src/math/real.cpp Wyświetl plik

@@ -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':


+ 9
- 7
src/ui/gui.cpp Wyświetl plik

@@ -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);


+ 11
- 11
src/ui/input.cpp Wyświetl plik

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

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;
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;
}


+ 13
- 13
src/ui/input.h Wyświetl plik

@@ -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<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]; }

/** 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<std::string> GetAvailableDevices();

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


+ 4
- 39
src/ui/sdl-input.cpp Wyświetl plik

@@ -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);


+ 1
- 1
src/ui/sdl-input.h Wyświetl plik

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

array<SDL_Joystick *, class InputDevice *> m_joysticks;

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



Ładowanie…
Anuluj
Zapisz