Reorganized project again.
This commit is contained in:
31
include/io/hid/Button.h
Normal file
31
include/io/hid/Button.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Str.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Button
|
||||
{
|
||||
private:
|
||||
Str_8 name;
|
||||
UInt_32 hash;
|
||||
|
||||
public:
|
||||
Button();
|
||||
|
||||
Button(const Str_8& name);
|
||||
|
||||
Button(const Button& key);
|
||||
|
||||
Button& operator=(const Button& key);
|
||||
|
||||
bool operator==(const Button& key) const;
|
||||
|
||||
bool operator!=(const Button& key) const;
|
||||
|
||||
Str_8 GetName() const;
|
||||
|
||||
UInt_32 GetHash() const;
|
||||
};
|
||||
}
|
55
include/io/hid/ButtonState.h
Normal file
55
include/io/hid/ButtonState.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Button.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class State
|
||||
{
|
||||
JUST_RELEASED,
|
||||
RELEASED,
|
||||
PRESSED,
|
||||
TOUCHED
|
||||
};
|
||||
|
||||
class ButtonState
|
||||
{
|
||||
private:
|
||||
Button button;
|
||||
State state;
|
||||
bool pressed;
|
||||
float threshold;
|
||||
|
||||
public:
|
||||
ButtonState();
|
||||
|
||||
ButtonState(const Button& button, const State state);
|
||||
|
||||
ButtonState(const ButtonState& bs);
|
||||
|
||||
ButtonState& operator=(const ButtonState& bs);
|
||||
|
||||
bool operator==(const Button& other) const;
|
||||
|
||||
bool operator!=(const Button& other) const;
|
||||
|
||||
bool operator==(const State otherState) const;
|
||||
|
||||
bool operator!=(const State otherState) const;
|
||||
|
||||
Button GetButton() const;
|
||||
|
||||
void SetState(State newState);
|
||||
|
||||
State GetState() const;
|
||||
|
||||
void SetPressed(bool value);
|
||||
|
||||
bool IsPressed() const;
|
||||
|
||||
void SetThreshold(const float newThreshold);
|
||||
|
||||
float GetThreshold() const;
|
||||
};
|
||||
}
|
91
include/io/hid/HID.h
Normal file
91
include/io/hid/HID.h
Normal file
@@ -0,0 +1,91 @@
|
||||
#pragma once
|
||||
|
||||
#include "Array.h"
|
||||
#include "ButtonState.h"
|
||||
|
||||
#define EHS_HID_UNKNOWN 0
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class HID
|
||||
{
|
||||
protected:
|
||||
UInt_8 type;
|
||||
UInt_64 hashName;
|
||||
Str_8 name;
|
||||
UInt_64 id;
|
||||
Array<ButtonState> states;
|
||||
|
||||
public:
|
||||
HID();
|
||||
|
||||
HID(const UInt_8 type, Str_8 name, const UInt_64 id);
|
||||
|
||||
HID(HID&& hid) noexcept;
|
||||
|
||||
HID(const HID& hid);
|
||||
|
||||
HID& operator=(HID&& hid) noexcept;
|
||||
|
||||
HID& operator=(const HID& hid);
|
||||
|
||||
bool operator==(const HID& other) const;
|
||||
|
||||
bool operator!=(const HID& other) const;
|
||||
|
||||
bool operator==(const UInt_64 otherId) const;
|
||||
|
||||
bool operator!=(const UInt_64 otherId) const;
|
||||
|
||||
virtual void Poll();
|
||||
|
||||
UInt_8 GetType() const;
|
||||
|
||||
Str_8 GetName() const;
|
||||
|
||||
UInt_64 GetId() const;
|
||||
|
||||
void ReleaseAll();
|
||||
|
||||
Vector<const ButtonState*> GetAllTouched() const;
|
||||
|
||||
const ButtonState* IsTouched(const Button& button) const;
|
||||
|
||||
const ButtonState* IsTouched() const;
|
||||
|
||||
Vector<const ButtonState*> GetAllDown() const;
|
||||
|
||||
const ButtonState* IsDown(const Button& button) const;
|
||||
|
||||
const ButtonState* IsDown() const;
|
||||
|
||||
Vector<const ButtonState*> GetAllJustReleased() const;
|
||||
|
||||
const ButtonState* IsJustReleased(const Button& button) const;
|
||||
|
||||
const ButtonState* IsJustReleased() const;
|
||||
|
||||
Vector<const ButtonState*> GetAllUp() const;
|
||||
|
||||
const ButtonState* IsUp(const Button& button) const;
|
||||
|
||||
const ButtonState* IsUp() const;
|
||||
|
||||
void ButtonDown(const Button& button);
|
||||
|
||||
void ButtonUp(const Button& button);
|
||||
|
||||
const ButtonState* GetState(const Button& button) const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
virtual HID* Clone() const;
|
||||
|
||||
private:
|
||||
bool HasState(const Button& button) const;
|
||||
|
||||
bool AddState(const ButtonState& state);
|
||||
|
||||
ButtonState* GetState(const Button& button);
|
||||
};
|
||||
}
|
46
include/io/hid/Input.h
Normal file
46
include/io/hid/Input.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "Array.h"
|
||||
#include "Serializer.h"
|
||||
#include "InputHandler.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Input
|
||||
{
|
||||
private:
|
||||
Array<InputHandler*> handlers;
|
||||
bool initalized;
|
||||
|
||||
public:
|
||||
~Input();
|
||||
|
||||
Input();
|
||||
|
||||
Input(Input&& input) noexcept;
|
||||
|
||||
Input(const Input& input);
|
||||
|
||||
Input& operator=(Input&& input) noexcept;
|
||||
|
||||
Input& operator=(const Input& input);
|
||||
|
||||
void Initialize();
|
||||
|
||||
void Release();
|
||||
|
||||
void Poll();
|
||||
|
||||
bool HasHandler(const UInt_64 hashId) const;
|
||||
|
||||
bool HasHandler(const Str_8& id) const;
|
||||
|
||||
bool AddHandler(InputHandler* handler);
|
||||
|
||||
const InputHandler* GetHandler(const UInt_64 hashId) const;
|
||||
|
||||
const InputHandler* GetHandler(const Str_8& id) const;
|
||||
|
||||
bool IsInitialized() const;
|
||||
};
|
||||
}
|
58
include/io/hid/InputHandler.h
Normal file
58
include/io/hid/InputHandler.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include "Array.h"
|
||||
#include "HID.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class InputHandler
|
||||
{
|
||||
private:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
|
||||
protected:
|
||||
Array<HID*> devices;
|
||||
|
||||
public:
|
||||
virtual ~InputHandler();
|
||||
|
||||
InputHandler();
|
||||
|
||||
InputHandler(Str_8 id);
|
||||
|
||||
InputHandler(InputHandler&& ih) noexcept;
|
||||
|
||||
InputHandler(const InputHandler& ih);
|
||||
|
||||
InputHandler& operator=(InputHandler&& ih) noexcept;
|
||||
|
||||
InputHandler& operator=(const InputHandler& ih);
|
||||
|
||||
bool operator==(const UInt_64 otherHashId);
|
||||
|
||||
bool operator!=(const UInt_64 otherHashId);
|
||||
|
||||
virtual bool Initialize();
|
||||
|
||||
virtual bool Release();
|
||||
|
||||
virtual void Poll();
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
void ResetAllStates();
|
||||
|
||||
bool HasDevice(const UInt_64 id) const;
|
||||
|
||||
bool AddDevice(HID* device);
|
||||
|
||||
HID* GetDevice(const UInt_64 id) const;
|
||||
|
||||
HID* GetDeviceByType(const UInt_8 type) const;
|
||||
|
||||
virtual bool IsInitialized() const;
|
||||
};
|
||||
}
|
121
include/io/hid/Keyboard.h
Normal file
121
include/io/hid/Keyboard.h
Normal file
@@ -0,0 +1,121 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
#include "Button.h"
|
||||
#include "HID.h"
|
||||
|
||||
#define EHS_HID_KEYBOARD 0x02
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Keyboard : public HID
|
||||
{
|
||||
public:
|
||||
Keyboard();
|
||||
|
||||
Keyboard(Str_8 name, const UInt_64 id);
|
||||
|
||||
Keyboard(Keyboard&& hid) noexcept = default;
|
||||
|
||||
Keyboard(const Keyboard& hid);
|
||||
|
||||
Keyboard& operator=(Keyboard&& hid) noexcept = default;
|
||||
|
||||
Keyboard& operator=(const Keyboard& hid);
|
||||
|
||||
void Poll() override;
|
||||
|
||||
Keyboard* Clone() const override;
|
||||
|
||||
static const Button Unknown;
|
||||
static const Button Escape;
|
||||
static const Button Backspace;
|
||||
static const Button Enter;
|
||||
static const Button LShift;
|
||||
static const Button RShift;
|
||||
static const Button LAlt;
|
||||
static const Button RAlt;
|
||||
static const Button LCtrl;
|
||||
static const Button RCtrl;
|
||||
static const Button Space;
|
||||
static const Button A;
|
||||
static const Button B;
|
||||
static const Button C;
|
||||
static const Button D;
|
||||
static const Button E;
|
||||
static const Button F;
|
||||
static const Button G;
|
||||
static const Button H;
|
||||
static const Button I;
|
||||
static const Button J;
|
||||
static const Button K;
|
||||
static const Button L;
|
||||
static const Button M;
|
||||
static const Button N;
|
||||
static const Button O;
|
||||
static const Button P;
|
||||
static const Button Q;
|
||||
static const Button R;
|
||||
static const Button S;
|
||||
static const Button T;
|
||||
static const Button U;
|
||||
static const Button V;
|
||||
static const Button W;
|
||||
static const Button X;
|
||||
static const Button Y;
|
||||
static const Button Z;
|
||||
static const Button One;
|
||||
static const Button Two;
|
||||
static const Button Three;
|
||||
static const Button Four;
|
||||
static const Button Five;
|
||||
static const Button Six;
|
||||
static const Button Seven;
|
||||
static const Button Eight;
|
||||
static const Button Nine;
|
||||
static const Button Zero;
|
||||
static const Button Minus;
|
||||
static const Button Equals;
|
||||
static const Button Tilde;
|
||||
static const Button BackSlash;
|
||||
static const Button LeftSquareBracket;
|
||||
static const Button RightSquareBracket;
|
||||
static const Button SemiColon;
|
||||
static const Button Apostrophe;
|
||||
static const Button Comma;
|
||||
static const Button Period;
|
||||
static const Button ForwardSlash;
|
||||
static const Button F1;
|
||||
static const Button F2;
|
||||
static const Button F3;
|
||||
static const Button F4;
|
||||
static const Button F5;
|
||||
static const Button F6;
|
||||
static const Button F7;
|
||||
static const Button F8;
|
||||
static const Button F9;
|
||||
static const Button F10;
|
||||
static const Button F11;
|
||||
static const Button F12;
|
||||
static const Button F13;
|
||||
static const Button F14;
|
||||
static const Button F15;
|
||||
static const Button F16;
|
||||
static const Button F17;
|
||||
static const Button F18;
|
||||
static const Button F19;
|
||||
static const Button F20;
|
||||
static const Button F21;
|
||||
static const Button F22;
|
||||
static const Button F23;
|
||||
static const Button F24;
|
||||
static const Button Left;
|
||||
static const Button Right;
|
||||
static const Button Up;
|
||||
static const Button Down;
|
||||
|
||||
static Button TranslateScanCode(const UInt_32 code);
|
||||
|
||||
static Char_8 TranslateToEnglish_8(const bool shifted, const Button& button);
|
||||
};
|
||||
}
|
55
include/io/hid/Mouse.h
Normal file
55
include/io/hid/Mouse.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
#include "Vec2.h"
|
||||
#include "Button.h"
|
||||
#include "HID.h"
|
||||
|
||||
#define EHS_HID_MOUSE 0x01
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Mouse : public HID
|
||||
{
|
||||
private:
|
||||
friend class Input;
|
||||
|
||||
Vec2_s32 delta;
|
||||
|
||||
public:
|
||||
Mouse();
|
||||
|
||||
Mouse(Str_8 name, const UInt_64 id);
|
||||
|
||||
Mouse(Mouse&& hid) noexcept = default;
|
||||
|
||||
Mouse(const Mouse& hid);
|
||||
|
||||
Mouse& operator=(Mouse&& hid) noexcept = default;
|
||||
|
||||
Mouse& operator=(const Mouse& hid);
|
||||
|
||||
void Poll() override;
|
||||
|
||||
void SetDelta(const Vec2_s32& newDelta);
|
||||
|
||||
Vec2_s32 GetDelta() const;
|
||||
|
||||
Mouse* Clone() const override;
|
||||
|
||||
static const Button Unknown;
|
||||
static const Button LMB;
|
||||
static const Button MMB;
|
||||
static const Button RMB;
|
||||
static const Button Four;
|
||||
static const Button Five;
|
||||
static const Button ScrollUp;
|
||||
static const Button ScrollDown;
|
||||
static const Button ScrollLeft;
|
||||
static const Button ScrollRight;
|
||||
static const Button Back;
|
||||
static const Button Forward;
|
||||
|
||||
static Button TranslateXCB(const UInt_32 code);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user