Reorganized project again.
This commit is contained in:
50
src/io/hid/Button.cpp
Normal file
50
src/io/hid/Button.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "io/hid/Button.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
Button::Button()
|
||||
: hash(0)
|
||||
{
|
||||
}
|
||||
|
||||
Button::Button(const Str_8& name)
|
||||
: name(name), hash(name.Hash_32())
|
||||
{
|
||||
}
|
||||
|
||||
Button::Button(const Button& key)
|
||||
: name(key.name), hash(key.hash)
|
||||
{
|
||||
}
|
||||
|
||||
Button& Button::operator=(const Button& key)
|
||||
{
|
||||
if (this == &key)
|
||||
return *this;
|
||||
|
||||
name = key.name;
|
||||
hash = key.hash;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Button::operator==(const Button& key) const
|
||||
{
|
||||
return key.hash == hash;
|
||||
}
|
||||
|
||||
bool Button::operator!=(const Button& key) const
|
||||
{
|
||||
return key.hash != hash;
|
||||
}
|
||||
|
||||
Str_8 Button::GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
UInt_32 Button::GetHash() const
|
||||
{
|
||||
return hash;
|
||||
}
|
||||
}
|
87
src/io/hid/ButtonState.cpp
Normal file
87
src/io/hid/ButtonState.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include "io/hid/ButtonState.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
ButtonState::ButtonState()
|
||||
: state(State::RELEASED), pressed(false), threshold(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
ButtonState::ButtonState(const Button& button, const State state)
|
||||
: button(button), state(state), pressed(true), threshold(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
ButtonState::ButtonState(const ButtonState& bs)
|
||||
: button(bs.button), state(bs.state), pressed(bs.pressed), threshold(bs.threshold)
|
||||
{
|
||||
}
|
||||
|
||||
ButtonState& ButtonState::operator=(const ButtonState& bs)
|
||||
{
|
||||
if (this == &bs)
|
||||
return *this;
|
||||
|
||||
button = bs.button;
|
||||
state = bs.state;
|
||||
pressed = bs.pressed;
|
||||
threshold = bs.threshold;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool ButtonState::operator==(const Button& other) const
|
||||
{
|
||||
return button == other;
|
||||
}
|
||||
|
||||
bool ButtonState::operator!=(const Button& other) const
|
||||
{
|
||||
return button != other;
|
||||
}
|
||||
|
||||
bool ButtonState::operator==(const State otherState) const
|
||||
{
|
||||
return state == otherState;
|
||||
}
|
||||
|
||||
bool ButtonState::operator!=(const State otherState) const
|
||||
{
|
||||
return state != otherState;
|
||||
}
|
||||
|
||||
Button ButtonState::GetButton() const
|
||||
{
|
||||
return button;
|
||||
}
|
||||
|
||||
void ButtonState::SetState(State newState)
|
||||
{
|
||||
state = newState;
|
||||
}
|
||||
|
||||
State ButtonState::GetState() const
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
void ButtonState::SetPressed(bool value)
|
||||
{
|
||||
pressed = value;
|
||||
}
|
||||
|
||||
bool ButtonState::IsPressed() const
|
||||
{
|
||||
return pressed;
|
||||
}
|
||||
|
||||
void ButtonState::SetThreshold(const float newThreshold)
|
||||
{
|
||||
threshold = newThreshold;
|
||||
}
|
||||
|
||||
float ButtonState::GetThreshold() const
|
||||
{
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
296
src/io/hid/HID.cpp
Normal file
296
src/io/hid/HID.cpp
Normal file
@@ -0,0 +1,296 @@
|
||||
#include "io/hid/HID.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
HID::HID()
|
||||
: type(EHS_HID_UNKNOWN), id(0)
|
||||
{
|
||||
}
|
||||
|
||||
HID::HID(const UInt_8 type, Str_8 name, const UInt_64 id)
|
||||
: type(type), name((Str_8&&)name), id(id)
|
||||
{
|
||||
}
|
||||
|
||||
HID::HID(HID&& hid) noexcept
|
||||
: type(hid.type), name((Str_8&&)hid.name), id(hid.id), states((Array<ButtonState>&&)hid.states)
|
||||
{
|
||||
hid.type = EHS_HID_UNKNOWN;
|
||||
hid.id = 0;
|
||||
}
|
||||
|
||||
HID::HID(const HID& hid)
|
||||
: type(hid.type), name(hid.name), id(hid.id), states(hid.states)
|
||||
{
|
||||
}
|
||||
|
||||
HID& HID::operator=(HID&& hid) noexcept
|
||||
{
|
||||
if (this == &hid)
|
||||
return *this;
|
||||
|
||||
type = hid.type;
|
||||
name = (Str_8&&)hid.name;
|
||||
id = hid.id;
|
||||
states = (Array<ButtonState>&&)hid.states;
|
||||
|
||||
hid.type = EHS_HID_UNKNOWN;
|
||||
hid.id = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
HID& HID::operator=(const HID& hid)
|
||||
{
|
||||
if (this == &hid)
|
||||
return *this;
|
||||
|
||||
type = hid.type;
|
||||
name = hid.name;
|
||||
id = hid.id;
|
||||
states = hid.states;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool HID::operator==(const HID& other) const
|
||||
{
|
||||
return type == other.type && hashName == other.hashName;
|
||||
}
|
||||
|
||||
bool HID::operator!=(const HID& other) const
|
||||
{
|
||||
return type != other.type || hashName != other.hashName;
|
||||
}
|
||||
|
||||
bool HID::operator==(const UInt_64 otherId) const
|
||||
{
|
||||
return id == otherId;
|
||||
}
|
||||
|
||||
bool HID::operator!=(const UInt_64 otherId) const
|
||||
{
|
||||
return id != otherId;
|
||||
}
|
||||
|
||||
void HID::Poll()
|
||||
{
|
||||
for (UInt_64 i = 0; i < states.Size(); ++i)
|
||||
{
|
||||
if (states[i].IsPressed())
|
||||
{
|
||||
if (states[i].GetState() == State::RELEASED)
|
||||
states[i].SetState(State::TOUCHED);
|
||||
else
|
||||
states[i].SetState(State::PRESSED);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (states[i].GetState() == State::PRESSED || states[i].GetState() == State::TOUCHED)
|
||||
states[i].SetState(State::JUST_RELEASED);
|
||||
else
|
||||
states[i].SetState(State::RELEASED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UInt_8 HID::GetType() const
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
Str_8 HID::GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
UInt_64 HID::GetId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
void HID::ReleaseAll()
|
||||
{
|
||||
for (UInt_64 i = 0; i < states.Size(); ++i)
|
||||
states[i].SetPressed(false);
|
||||
}
|
||||
|
||||
Vector<const ButtonState*> HID::GetAllTouched() const
|
||||
{
|
||||
Vector<const ButtonState*> result(0, states.Size() + 1);
|
||||
|
||||
for (UInt_64 i = 0; i < states.Size(); i++)
|
||||
if (states[i] == State::TOUCHED)
|
||||
result.Push(&states[i]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const ButtonState* HID::IsTouched(const Button& button) const
|
||||
{
|
||||
const ButtonState* state = GetState(button);
|
||||
if (!state || *state != State::TOUCHED)
|
||||
return nullptr;
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
const ButtonState* HID::IsTouched() const
|
||||
{
|
||||
for (UInt_64 i = 0; i < states.Size(); i++)
|
||||
if (states[i] == State::TOUCHED)
|
||||
return &states[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Vector<const ButtonState*> HID::GetAllDown() const
|
||||
{
|
||||
Vector<const ButtonState*> result(0, states.Size() + 1);
|
||||
|
||||
for (UInt_64 i = 0; i < states.Size(); i++)
|
||||
if (states[i] == State::PRESSED || states[i] == State::TOUCHED)
|
||||
result.Push(&states[i]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const ButtonState* HID::IsDown(const Button& button) const
|
||||
{
|
||||
const ButtonState* state = GetState(button);
|
||||
if (!state || (*state != State::PRESSED && *state != State::TOUCHED))
|
||||
return nullptr;
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
const ButtonState* HID::IsDown() const
|
||||
{
|
||||
for (UInt_64 i = 0; i < states.Size(); i++)
|
||||
if (states[i] == State::PRESSED || states[i] == State::TOUCHED)
|
||||
return &states[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Vector<const ButtonState*> HID::GetAllJustReleased() const
|
||||
{
|
||||
Vector<const ButtonState*> result(0, states.Size() + 1);
|
||||
|
||||
for (UInt_64 i = 0; i < states.Size(); i++)
|
||||
if (states[i] == State::JUST_RELEASED)
|
||||
result.Push(&states[i]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const ButtonState* HID::IsJustReleased(const Button& button) const
|
||||
{
|
||||
const ButtonState* state = GetState(button);
|
||||
if (!state || *state != State::JUST_RELEASED)
|
||||
return nullptr;
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
const ButtonState* HID::IsJustReleased() const
|
||||
{
|
||||
for (UInt_64 i = 0; i < states.Size(); i++)
|
||||
if (states[i] == State::JUST_RELEASED)
|
||||
return &states[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Vector<const ButtonState*> HID::GetAllUp() const
|
||||
{
|
||||
Vector<const ButtonState*> result(0, states.Size() + 1);
|
||||
|
||||
for (UInt_64 i = 0; i < states.Size(); i++)
|
||||
if (states[i] == State::RELEASED || states[i] == State::JUST_RELEASED)
|
||||
result.Push(&states[i]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const ButtonState* HID::IsUp(const Button& button) const
|
||||
{
|
||||
const ButtonState* state = GetState(button);
|
||||
if (!state || (*state != State::RELEASED && *state != State::JUST_RELEASED))
|
||||
return nullptr;
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
const ButtonState* HID::IsUp() const
|
||||
{
|
||||
for (UInt_64 i = 0; i < states.Size(); i++)
|
||||
if (states[i] == State::RELEASED || states[i] == State::JUST_RELEASED)
|
||||
return &states[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void HID::ButtonDown(const Button& button)
|
||||
{
|
||||
if (ButtonState* state = GetState(button); state)
|
||||
state->SetPressed(true);
|
||||
else
|
||||
states.Push(ButtonState(button, State::RELEASED));
|
||||
}
|
||||
|
||||
void HID::ButtonUp(const Button& button)
|
||||
{
|
||||
if (ButtonState* state = GetState(button); state)
|
||||
state->SetPressed(false);
|
||||
else
|
||||
states.Push(ButtonState(button, State::JUST_RELEASED));
|
||||
}
|
||||
|
||||
const ButtonState* HID::GetState(const Button& button) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < states.Size(); ++i)
|
||||
if (states[i] == button)
|
||||
return &states[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool HID::IsValid() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
HID* HID::Clone() const
|
||||
{
|
||||
return new HID(*this);
|
||||
}
|
||||
|
||||
bool HID::HasState(const Button& button) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < states.Size(); i++)
|
||||
if (states[i].GetButton() == button)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HID::AddState(const ButtonState& state)
|
||||
{
|
||||
if (HasState(state.GetButton()))
|
||||
return false;
|
||||
|
||||
states.Push(state);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ButtonState* HID::GetState(const Button& button)
|
||||
{
|
||||
for (UInt_64 i = 0; i < states.Size(); i++)
|
||||
if (states[i].GetButton() == button)
|
||||
return &states[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
160
src/io/hid/Input.cpp
Normal file
160
src/io/hid/Input.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
#include "io/hid/Input.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
Input::~Input()
|
||||
{
|
||||
for (UInt_64 i = 0; i < handlers.Size(); i++)
|
||||
delete handlers[i];
|
||||
}
|
||||
|
||||
Input::Input()
|
||||
: initalized(false)
|
||||
{
|
||||
}
|
||||
|
||||
Input::Input(Input&& input) noexcept
|
||||
: handlers((Array<InputHandler*>&&)input.handlers), initalized(input.initalized)
|
||||
{
|
||||
input.initalized = false;
|
||||
}
|
||||
|
||||
Input::Input(const Input& input)
|
||||
: initalized(false)
|
||||
{
|
||||
}
|
||||
|
||||
Input& Input::operator=(Input&& input) noexcept
|
||||
{
|
||||
if (this == &input)
|
||||
return *this;
|
||||
|
||||
handlers = (Array<InputHandler*>&&)input.handlers;
|
||||
initalized = input.initalized;
|
||||
|
||||
input.initalized = false;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Input& Input::operator=(const Input& input)
|
||||
{
|
||||
if (this == &input)
|
||||
return *this;
|
||||
|
||||
for (UInt_64 i = 0; i < handlers.Size(); i++)
|
||||
delete handlers;
|
||||
|
||||
handlers = Array<InputHandler*>();
|
||||
initalized = false;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Input::Initialize()
|
||||
{
|
||||
if (initalized)
|
||||
return;
|
||||
|
||||
UInt_64 i = 0;
|
||||
while (i < handlers.Size())
|
||||
{
|
||||
if (!handlers[i]->Initialize())
|
||||
{
|
||||
if (i != handlers.Size() - 1)
|
||||
handlers.Swap(i, handlers.End());
|
||||
|
||||
delete handlers.Pop();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
initalized = true;
|
||||
}
|
||||
|
||||
void Input::Release()
|
||||
{
|
||||
if (!initalized)
|
||||
return;
|
||||
|
||||
UInt_64 i = 0;
|
||||
while (i < handlers.Size())
|
||||
{
|
||||
if (!handlers[i]->Release())
|
||||
{
|
||||
if (i != handlers.Size() - 1)
|
||||
handlers.Swap(i, handlers.End());
|
||||
|
||||
delete handlers.Pop();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
initalized = false;
|
||||
}
|
||||
|
||||
void Input::Poll()
|
||||
{
|
||||
for (UInt_64 i = 0; i < handlers.Size(); i++)
|
||||
handlers[i]->Poll();
|
||||
}
|
||||
|
||||
bool Input::HasHandler(const UInt_64 hashId) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < handlers.Size(); i++)
|
||||
if (*handlers[i] == hashId)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Input::HasHandler(const Str_8& id) const
|
||||
{
|
||||
return HasHandler(id.Hash_64());
|
||||
}
|
||||
|
||||
bool Input::AddHandler(InputHandler* handler)
|
||||
{
|
||||
if (HasHandler(handler->GetHashId()))
|
||||
return false;
|
||||
|
||||
if (initalized)
|
||||
{
|
||||
bool hInitialized = handler->Initialize();
|
||||
if (!hInitialized)
|
||||
{
|
||||
delete handler;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
handlers.Push(handler);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const InputHandler* Input::GetHandler(const UInt_64 hashId) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < handlers.Size(); i++)
|
||||
if (*handlers[i] == hashId)
|
||||
return handlers[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const InputHandler* Input::GetHandler(const Str_8& id) const
|
||||
{
|
||||
return GetHandler(id.Hash_64());
|
||||
}
|
||||
|
||||
bool Input::IsInitialized() const
|
||||
{
|
||||
return initalized;
|
||||
}
|
||||
}
|
160
src/io/hid/InputHandler.cpp
Normal file
160
src/io/hid/InputHandler.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
#include "io/hid/InputHandler.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
InputHandler::~InputHandler()
|
||||
{
|
||||
for (UInt_64 i = 0; i < devices.Size(); i++)
|
||||
delete devices[i];
|
||||
}
|
||||
|
||||
InputHandler::InputHandler()
|
||||
: hashId(0)
|
||||
{
|
||||
}
|
||||
|
||||
InputHandler::InputHandler(Str_8 id)
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id)
|
||||
{
|
||||
}
|
||||
|
||||
InputHandler::InputHandler(InputHandler&& ih) noexcept
|
||||
: hashId(ih.hashId), id((Str_8&&)ih.id), devices((Array<HID*>&&)ih.devices)
|
||||
{
|
||||
ih.hashId = 0;
|
||||
}
|
||||
|
||||
InputHandler::InputHandler(const InputHandler& ih)
|
||||
: hashId(ih.hashId), id(ih.id), devices(ih.devices.Size())
|
||||
{
|
||||
for (UInt_64 i = 0; i < devices.Size(); i++)
|
||||
devices[i] = ih.devices[i]->Clone();
|
||||
}
|
||||
|
||||
InputHandler& InputHandler::operator=(InputHandler&& ih) noexcept
|
||||
{
|
||||
if (this == &ih)
|
||||
return *this;
|
||||
|
||||
hashId = ih.hashId;
|
||||
id = (Str_8&&)ih.id;
|
||||
devices = (Array<HID*>&&)ih.devices;
|
||||
|
||||
ih.hashId = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
InputHandler& InputHandler::operator=(const InputHandler& ih)
|
||||
{
|
||||
if (this == &ih)
|
||||
return *this;
|
||||
|
||||
for (UInt_64 i = 0; i < devices.Size(); i++)
|
||||
delete devices[i];
|
||||
|
||||
hashId = ih.hashId;
|
||||
id = ih.id;
|
||||
devices = Array<HID*>(ih.devices.Size());
|
||||
|
||||
for (UInt_64 i = 0; i < devices.Size(); i++)
|
||||
devices[i] = ih.devices[i]->Clone();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool InputHandler::operator==(const UInt_64 otherHashId)
|
||||
{
|
||||
return hashId == otherHashId;
|
||||
}
|
||||
|
||||
bool InputHandler::operator!=(const UInt_64 otherHashId)
|
||||
{
|
||||
return hashId != otherHashId;
|
||||
}
|
||||
|
||||
bool InputHandler::Initialize()
|
||||
{
|
||||
if (IsInitialized())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InputHandler::Release()
|
||||
{
|
||||
if (!IsInitialized())
|
||||
return false;
|
||||
|
||||
for (UInt_64 i = 0; i < devices.Size(); i++)
|
||||
delete devices[i];
|
||||
|
||||
devices.Clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InputHandler::Poll()
|
||||
{
|
||||
for (UInt_64 i = 0; i < devices.Size(); i++)
|
||||
devices[i]->Poll();
|
||||
}
|
||||
|
||||
UInt_64 InputHandler::GetHashId() const
|
||||
{
|
||||
return hashId;
|
||||
}
|
||||
|
||||
Str_8 InputHandler::GetId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
void InputHandler::ResetAllStates()
|
||||
{
|
||||
for (UInt_64 i = 0; i < devices.Size(); i++)
|
||||
devices[i]->ReleaseAll();
|
||||
}
|
||||
|
||||
bool InputHandler::HasDevice(const UInt_64 id) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < devices.Size(); i++)
|
||||
if (*devices[i] == id)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputHandler::AddDevice(HID* device)
|
||||
{
|
||||
if (HasDevice(device->GetId()))
|
||||
return false;
|
||||
|
||||
devices.Push(device);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
HID* InputHandler::GetDevice(const UInt_64 id) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < devices.Size(); i++)
|
||||
if (*devices[i] == id)
|
||||
return devices[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HID* InputHandler::GetDeviceByType(const UInt_8 type) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < devices.Size(); i++)
|
||||
if (devices[i]->GetType() == type)
|
||||
return devices[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool InputHandler::IsInitialized() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
507
src/io/hid/Keyboard.cpp
Normal file
507
src/io/hid/Keyboard.cpp
Normal file
@@ -0,0 +1,507 @@
|
||||
#include "io/hid/Keyboard.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
Keyboard::Keyboard()
|
||||
{
|
||||
}
|
||||
|
||||
Keyboard::Keyboard(Str_8 name, const UInt_64 id)
|
||||
: HID(EHS_HID_KEYBOARD, (Str_8&&)name, id)
|
||||
{
|
||||
}
|
||||
|
||||
Keyboard::Keyboard(const Keyboard& hid)
|
||||
: HID(hid)
|
||||
{
|
||||
}
|
||||
|
||||
Keyboard& Keyboard::operator=(const Keyboard& hid)
|
||||
{
|
||||
if (this == &hid)
|
||||
return *this;
|
||||
|
||||
HID::operator=(hid);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Keyboard::Poll()
|
||||
{
|
||||
HID::Poll();
|
||||
}
|
||||
|
||||
Keyboard* Keyboard::Clone() const
|
||||
{
|
||||
return new Keyboard(*this);
|
||||
}
|
||||
|
||||
const Button Keyboard::Unknown("Unknown");
|
||||
const Button Keyboard::Escape("Escape Button");
|
||||
const Button Keyboard::Backspace("Backspace Button");
|
||||
const Button Keyboard::Enter("Enter Button");
|
||||
const Button Keyboard::LShift("Left Shift Button");
|
||||
const Button Keyboard::RShift("Right Shift Button");
|
||||
const Button Keyboard::LAlt("Left Alt Button");
|
||||
const Button Keyboard::RAlt("Right Alt Button");
|
||||
const Button Keyboard::LCtrl("Left Control Button");
|
||||
const Button Keyboard::RCtrl("Right Control Button");
|
||||
const Button Keyboard::Space("Space Button");
|
||||
const Button Keyboard::A("A Button");
|
||||
const Button Keyboard::B("B Button");
|
||||
const Button Keyboard::C("C Button");
|
||||
const Button Keyboard::D("D Button");
|
||||
const Button Keyboard::E("E Button");
|
||||
const Button Keyboard::F("F Button");
|
||||
const Button Keyboard::G("G Button");
|
||||
const Button Keyboard::H("H Button");
|
||||
const Button Keyboard::I("I Button");
|
||||
const Button Keyboard::J("J Button");
|
||||
const Button Keyboard::K("K Button");
|
||||
const Button Keyboard::L("L Button");
|
||||
const Button Keyboard::M("M Button");
|
||||
const Button Keyboard::N("N Button");
|
||||
const Button Keyboard::O("O Button");
|
||||
const Button Keyboard::P("P Button");
|
||||
const Button Keyboard::Q("Q Button");
|
||||
const Button Keyboard::R("R Button");
|
||||
const Button Keyboard::S("S Button");
|
||||
const Button Keyboard::T("T Button");
|
||||
const Button Keyboard::U("U Button");
|
||||
const Button Keyboard::V("V Button");
|
||||
const Button Keyboard::W("W Button");
|
||||
const Button Keyboard::X("X Button");
|
||||
const Button Keyboard::Y("Y Button");
|
||||
const Button Keyboard::Z("Z Button");
|
||||
const Button Keyboard::One("One Button");
|
||||
const Button Keyboard::Two("Two Button");
|
||||
const Button Keyboard::Three("Three Button");
|
||||
const Button Keyboard::Four("Four Button");
|
||||
const Button Keyboard::Five("Five Button");
|
||||
const Button Keyboard::Six("Six Button");
|
||||
const Button Keyboard::Seven("Seven Button");
|
||||
const Button Keyboard::Eight("Eight Button");
|
||||
const Button Keyboard::Nine("Nine Button");
|
||||
const Button Keyboard::Zero("Zero Button");
|
||||
const Button Keyboard::Equals("Equals Button");
|
||||
const Button Keyboard::Minus("Minus Button");
|
||||
const Button Keyboard::Tilde("Tilde Button");
|
||||
const Button Keyboard::BackSlash("Back Slash Button");
|
||||
const Button Keyboard::LeftSquareBracket("Left Square Bracket Button");
|
||||
const Button Keyboard::RightSquareBracket("Right Square Bracket Button");
|
||||
const Button Keyboard::SemiColon("Semi-Colon Button");
|
||||
const Button Keyboard::Apostrophe("Apostrophe Button");
|
||||
const Button Keyboard::Comma("Comma Button");
|
||||
const Button Keyboard::Period("Period Button");
|
||||
const Button Keyboard::ForwardSlash("Forward Slash Button");
|
||||
const Button Keyboard::F1("Function 1 Button");
|
||||
const Button Keyboard::F2("Function 2 Button");
|
||||
const Button Keyboard::F3("Function 3 Button");
|
||||
const Button Keyboard::F4("Function 4 Button");
|
||||
const Button Keyboard::F5("Function 5 Button");
|
||||
const Button Keyboard::F6("Function 6 Button");
|
||||
const Button Keyboard::F7("Function 7 Button");
|
||||
const Button Keyboard::F8("Function 8 Button");
|
||||
const Button Keyboard::F9("Function 9 Button");
|
||||
const Button Keyboard::F10("Function 10 Button");
|
||||
const Button Keyboard::F11("Function 11 Button");
|
||||
const Button Keyboard::F12("Function 12 Button");
|
||||
const Button Keyboard::F13("Function 13 Button");
|
||||
const Button Keyboard::F14("Function 14 Button");
|
||||
const Button Keyboard::F15("Function 15 Button");
|
||||
const Button Keyboard::F16("Function 16 Button");
|
||||
const Button Keyboard::F17("Function 17 Button");
|
||||
const Button Keyboard::F18("Function 18 Button");
|
||||
const Button Keyboard::F19("Function 19 Button");
|
||||
const Button Keyboard::F20("Function 20 Button");
|
||||
const Button Keyboard::F21("Function 21 Button");
|
||||
const Button Keyboard::F22("Function 22 Button");
|
||||
const Button Keyboard::F23("Function 23 Button");
|
||||
const Button Keyboard::F24("Function 24 Button");
|
||||
const Button Keyboard::Left("Left Arrow Button");
|
||||
const Button Keyboard::Right("Right Arrow Button");
|
||||
const Button Keyboard::Up("Up Arrow Button");
|
||||
const Button Keyboard::Down("Down Arrow Button");
|
||||
|
||||
Button Keyboard::TranslateScanCode(const UInt_32 code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case 1:
|
||||
return Keyboard::Escape;
|
||||
case 14:
|
||||
return Keyboard::Backspace;
|
||||
case 28:
|
||||
return Keyboard::Enter;
|
||||
case 0x2A:
|
||||
return Keyboard::LShift;
|
||||
case 0x36:
|
||||
return Keyboard::RShift;
|
||||
case 56:
|
||||
return Keyboard::LAlt;
|
||||
case 100:
|
||||
return Keyboard::RAlt;
|
||||
case 29:
|
||||
return Keyboard::LCtrl;
|
||||
case 97:
|
||||
return Keyboard::RCtrl;
|
||||
case 57:
|
||||
return Keyboard::Space;
|
||||
case 30:
|
||||
return Keyboard::A;
|
||||
case 48:
|
||||
return Keyboard::B;
|
||||
case 46:
|
||||
return Keyboard::C;
|
||||
case 32:
|
||||
return Keyboard::D;
|
||||
case 18:
|
||||
return Keyboard::E;
|
||||
case 33:
|
||||
return Keyboard::F;
|
||||
case 34:
|
||||
return Keyboard::G;
|
||||
case 35:
|
||||
return Keyboard::H;
|
||||
case 23:
|
||||
return Keyboard::I;
|
||||
case 36:
|
||||
return Keyboard::J;
|
||||
case 37:
|
||||
return Keyboard::K;
|
||||
case 38:
|
||||
return Keyboard::L;
|
||||
case 50:
|
||||
return Keyboard::M;
|
||||
case 49:
|
||||
return Keyboard::N;
|
||||
case 24:
|
||||
return Keyboard::O;
|
||||
case 25:
|
||||
return Keyboard::P;
|
||||
case 16:
|
||||
return Keyboard::Q;
|
||||
case 19:
|
||||
return Keyboard::R;
|
||||
case 31:
|
||||
return Keyboard::S;
|
||||
case 20:
|
||||
return Keyboard::T;
|
||||
case 22:
|
||||
return Keyboard::U;
|
||||
case 47:
|
||||
return Keyboard::V;
|
||||
case 17:
|
||||
return Keyboard::W;
|
||||
case 45:
|
||||
return Keyboard::X;
|
||||
case 21:
|
||||
return Keyboard::Y;
|
||||
case 44:
|
||||
return Keyboard::Z;
|
||||
case 2:
|
||||
return Keyboard::One;
|
||||
case 3:
|
||||
return Keyboard::Two;
|
||||
case 4:
|
||||
return Keyboard::Three;
|
||||
case 5:
|
||||
return Keyboard::Four;
|
||||
case 6:
|
||||
return Keyboard::Five;
|
||||
case 7:
|
||||
return Keyboard::Six;
|
||||
case 8:
|
||||
return Keyboard::Seven;
|
||||
case 9:
|
||||
return Keyboard::Eight;
|
||||
case 10:
|
||||
return Keyboard::Nine;
|
||||
case 11:
|
||||
return Keyboard::Zero;
|
||||
case 12:
|
||||
return Keyboard::Minus;
|
||||
case 13:
|
||||
return Keyboard::Equals;
|
||||
case 41:
|
||||
return Keyboard::Tilde;
|
||||
case 43:
|
||||
return Keyboard::BackSlash;
|
||||
case 26:
|
||||
return Keyboard::LeftSquareBracket;
|
||||
case 27:
|
||||
return Keyboard::RightSquareBracket;
|
||||
case 39:
|
||||
return Keyboard::SemiColon;
|
||||
case 40:
|
||||
return Keyboard::Apostrophe;
|
||||
case 51:
|
||||
return Keyboard::Comma;
|
||||
case 52:
|
||||
return Keyboard::Period;
|
||||
case 53:
|
||||
return Keyboard::ForwardSlash;
|
||||
case 59:
|
||||
return Keyboard::F1;
|
||||
case 60:
|
||||
return Keyboard::F2;
|
||||
case 61:
|
||||
return Keyboard::F3;
|
||||
case 62:
|
||||
return Keyboard::F4;
|
||||
case 63:
|
||||
return Keyboard::F5;
|
||||
case 64:
|
||||
return Keyboard::F6;
|
||||
case 65:
|
||||
return Keyboard::F7;
|
||||
case 66:
|
||||
return Keyboard::F8;
|
||||
case 67:
|
||||
return Keyboard::F9;
|
||||
case 68:
|
||||
return Keyboard::F10;
|
||||
case 69:
|
||||
return Keyboard::F11;
|
||||
case 70:
|
||||
return Keyboard::F12;
|
||||
case 71:
|
||||
return Keyboard::F13;
|
||||
case 72:
|
||||
return Keyboard::F14;
|
||||
case 73:
|
||||
return Keyboard::F15;
|
||||
case 74:
|
||||
return Keyboard::F16;
|
||||
case 75:
|
||||
return Keyboard::F17;
|
||||
case 76:
|
||||
return Keyboard::F18;
|
||||
case 77:
|
||||
return Keyboard::F19;
|
||||
case 78:
|
||||
return Keyboard::F20;
|
||||
case 79:
|
||||
return Keyboard::F21;
|
||||
case 80:
|
||||
return Keyboard::F22;
|
||||
case 81:
|
||||
return Keyboard::F23;
|
||||
case 82:
|
||||
return Keyboard::F24;
|
||||
case 105:
|
||||
return Keyboard::Left;
|
||||
case 106:
|
||||
return Keyboard::Right;
|
||||
case 103:
|
||||
return Keyboard::Up;
|
||||
case 108:
|
||||
return Keyboard::Down;
|
||||
default:
|
||||
return Keyboard::Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
Char_8 Keyboard::TranslateToEnglish_8(const bool shifted, const Button& button)
|
||||
{
|
||||
if (shifted)
|
||||
{
|
||||
if (button == A)
|
||||
return 'A';
|
||||
else if (button == B)
|
||||
return 'B';
|
||||
else if (button == C)
|
||||
return 'C';
|
||||
else if (button == D)
|
||||
return 'D';
|
||||
else if (button == E)
|
||||
return 'E';
|
||||
else if (button == F)
|
||||
return 'F';
|
||||
else if (button == G)
|
||||
return 'G';
|
||||
else if (button == H)
|
||||
return 'H';
|
||||
else if (button == I)
|
||||
return 'I';
|
||||
else if (button == J)
|
||||
return 'J';
|
||||
else if (button == K)
|
||||
return 'K';
|
||||
else if (button == L)
|
||||
return 'L';
|
||||
else if (button == M)
|
||||
return 'M';
|
||||
else if (button == N)
|
||||
return 'N';
|
||||
else if (button == O)
|
||||
return 'O';
|
||||
else if (button == P)
|
||||
return 'P';
|
||||
else if (button == Q)
|
||||
return 'Q';
|
||||
else if (button == Q)
|
||||
return 'R';
|
||||
else if (button == S)
|
||||
return 'S';
|
||||
else if (button == T)
|
||||
return 'T';
|
||||
else if (button == U)
|
||||
return 'U';
|
||||
else if (button == V)
|
||||
return 'V';
|
||||
else if (button == W)
|
||||
return 'W';
|
||||
else if (button == X)
|
||||
return 'X';
|
||||
else if (button == Y)
|
||||
return 'Y';
|
||||
else if (button == Z)
|
||||
return 'Z';
|
||||
else if (button == Two)
|
||||
return '@';
|
||||
else if (button == Three)
|
||||
return '#';
|
||||
else if (button == Four)
|
||||
return '$';
|
||||
else if (button == Five)
|
||||
return '%';
|
||||
else if (button == Six)
|
||||
return '^';
|
||||
else if (button == Seven)
|
||||
return '&';
|
||||
else if (button == Eight)
|
||||
return '*';
|
||||
else if (button == Nine)
|
||||
return '(';
|
||||
else if (button == Zero)
|
||||
return ')';
|
||||
else if (button == One)
|
||||
return '!';
|
||||
else if (button == Minus)
|
||||
return '_';
|
||||
else if (button == Equals)
|
||||
return '+';
|
||||
else if (button == Tilde)
|
||||
return '~';
|
||||
else if (button == BackSlash)
|
||||
return '|';
|
||||
else if (button == LeftSquareBracket)
|
||||
return '{';
|
||||
else if (button == RightSquareBracket)
|
||||
return '}';
|
||||
else if (button == SemiColon)
|
||||
return ':';
|
||||
else if (button == Apostrophe)
|
||||
return '"';
|
||||
else if (button == Comma)
|
||||
return '<';
|
||||
else if (button == Period)
|
||||
return '>';
|
||||
else if (button == ForwardSlash)
|
||||
return '?';
|
||||
}
|
||||
else
|
||||
{
|
||||
if (button == A)
|
||||
return 'a';
|
||||
else if (button == B)
|
||||
return 'b';
|
||||
else if (button == C)
|
||||
return 'c';
|
||||
else if (button == D)
|
||||
return 'd';
|
||||
else if (button == E)
|
||||
return 'e';
|
||||
else if (button == F)
|
||||
return 'f';
|
||||
else if (button == G)
|
||||
return 'g';
|
||||
else if (button == H)
|
||||
return 'h';
|
||||
else if (button == I)
|
||||
return 'i';
|
||||
else if (button == J)
|
||||
return 'j';
|
||||
else if (button == K)
|
||||
return 'k';
|
||||
else if (button == L)
|
||||
return 'l';
|
||||
else if (button == M)
|
||||
return 'm';
|
||||
else if (button == N)
|
||||
return 'n';
|
||||
else if (button == O)
|
||||
return 'o';
|
||||
else if (button == P)
|
||||
return 'p';
|
||||
else if (button == Q)
|
||||
return 'q';
|
||||
else if (button == R)
|
||||
return 'r';
|
||||
else if (button == S)
|
||||
return 's';
|
||||
else if (button == T)
|
||||
return 't';
|
||||
else if (button == U)
|
||||
return 'u';
|
||||
else if (button == V)
|
||||
return 'v';
|
||||
else if (button == W)
|
||||
return 'w';
|
||||
else if (button == X)
|
||||
return 'x';
|
||||
else if (button == Y)
|
||||
return 'y';
|
||||
else if (button == Z)
|
||||
return 'z';
|
||||
else if (button == One)
|
||||
return '1';
|
||||
else if (button == Two)
|
||||
return '2';
|
||||
else if (button == Three)
|
||||
return '3';
|
||||
else if (button == Four)
|
||||
return '4';
|
||||
else if (button == Five)
|
||||
return '5';
|
||||
else if (button == Six)
|
||||
return '6';
|
||||
else if (button == Seven)
|
||||
return '7';
|
||||
else if (button == Eight)
|
||||
return '8';
|
||||
else if (button == Nine)
|
||||
return '9';
|
||||
else if (button == Zero)
|
||||
return '0';
|
||||
else if (button == Minus)
|
||||
return '-';
|
||||
else if (button == Equals)
|
||||
return '=';
|
||||
else if (button == Tilde)
|
||||
return '`';
|
||||
else if (button == BackSlash)
|
||||
return '\\';
|
||||
else if (button == LeftSquareBracket)
|
||||
return '[';
|
||||
else if (button == RightSquareBracket)
|
||||
return ']';
|
||||
else if (button == SemiColon)
|
||||
return ';';
|
||||
else if (button == Apostrophe)
|
||||
return '\'';
|
||||
else if (button == Comma)
|
||||
return ',';
|
||||
else if (button == Period)
|
||||
return '.';
|
||||
else if (button == ForwardSlash)
|
||||
return '/';
|
||||
}
|
||||
|
||||
if (button == Space)
|
||||
return ' ';
|
||||
else
|
||||
return 0x00;
|
||||
}
|
||||
}
|
88
src/io/hid/Mouse.cpp
Normal file
88
src/io/hid/Mouse.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include "io/hid/Mouse.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
Mouse::Mouse()
|
||||
{
|
||||
}
|
||||
|
||||
Mouse::Mouse(Str_8 name, const UInt_64 id)
|
||||
: HID(EHS_HID_MOUSE, (Str_8&&)name, id)
|
||||
{
|
||||
}
|
||||
|
||||
Mouse::Mouse(const Mouse& hid)
|
||||
: HID(hid), delta(hid.delta)
|
||||
{
|
||||
}
|
||||
|
||||
Mouse& Mouse::operator=(const Mouse& hid)
|
||||
{
|
||||
if (this == &hid)
|
||||
return *this;
|
||||
|
||||
HID::operator=(hid);
|
||||
|
||||
delta = hid.delta;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Mouse::Poll()
|
||||
{
|
||||
delta = {};
|
||||
|
||||
HID::Poll();
|
||||
}
|
||||
|
||||
void Mouse::SetDelta(const Vec2_s32& newDelta)
|
||||
{
|
||||
delta = newDelta;
|
||||
}
|
||||
|
||||
Vec2_s32 Mouse::GetDelta() const
|
||||
{
|
||||
return delta;
|
||||
}
|
||||
|
||||
Mouse* Mouse::Clone() const
|
||||
{
|
||||
return new Mouse(*this);
|
||||
}
|
||||
|
||||
const Button Mouse::Unknown("Unknown");
|
||||
const Button Mouse::LMB("Left Mouse Button");
|
||||
const Button Mouse::MMB("Middle Mouse Button");
|
||||
const Button Mouse::RMB("Right Mouse Button");
|
||||
const Button Mouse::Four("Mouse Button Four");
|
||||
const Button Mouse::Five("Mouse Button Five");
|
||||
const Button Mouse::ScrollUp("Scroll Up");
|
||||
const Button Mouse::ScrollDown("Scroll Down");
|
||||
const Button Mouse::ScrollLeft("Scroll Left");
|
||||
const Button Mouse::ScrollRight("Scroll Right");
|
||||
const Button Mouse::Back("Back Mouse Button");
|
||||
const Button Mouse::Forward("Forward Mouse Button");
|
||||
|
||||
Button Mouse::TranslateXCB(const UInt_32 code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case 1:
|
||||
return Mouse::LMB;
|
||||
case 2:
|
||||
return Mouse::MMB;
|
||||
case 3:
|
||||
return Mouse::RMB;
|
||||
case 4:
|
||||
return Mouse::ScrollUp;
|
||||
case 5:
|
||||
return Mouse::ScrollDown;
|
||||
case 8:
|
||||
return Mouse::Back;
|
||||
case 9:
|
||||
return Mouse::Forward;
|
||||
default:
|
||||
return Mouse::Unknown;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user