Optimized Button class. Added IsPressed and GetPressed methods.

This commit is contained in:
2024-08-04 00:47:38 -07:00
parent 3970b8d402
commit 8d4420528a
14 changed files with 240 additions and 52 deletions

View File

@@ -8,24 +8,30 @@ namespace ehs
class EHS_LIB_IO Button
{
private:
Str_8 name;
UInt_32 hash;
Str_8 name;
public:
Button();
Button(const Str_8& name);
Button(Str_8 name);
Button(const Button& key);
Button(Button &&key) noexcept;
Button& operator=(const Button& key);
Button(const Button &key);
bool operator==(const Button& key) const;
Button &operator=(Button &&key) noexcept;
bool operator!=(const Button& key) const;
Button &operator=(const Button &key);
bool operator==(const Button &key) const;
bool operator!=(const Button &key) const;
UInt_32 GetHash() const;
Str_8 GetName() const;
UInt_32 GetHash() const;
bool IsValid() const;
};
}

View File

@@ -15,11 +15,15 @@ namespace ehs
Str_8 name;
UInt_64 id;
Array<ButtonState> states;
Button lastState;
float heldTime;
float activateTime;
bool active;
public:
HID();
HID(const UInt_8 type, Str_8 name, const UInt_64 id);
HID(UInt_8 type, Str_8 name, UInt_64 id);
HID(HID&& hid) noexcept;
@@ -33,11 +37,11 @@ namespace ehs
bool operator!=(const HID& other) const;
bool operator==(const UInt_64 otherId) const;
bool operator==(UInt_64 otherId) const;
bool operator!=(const UInt_64 otherId) const;
bool operator!=(UInt_64 otherId) const;
virtual void Poll();
virtual void Poll(float delta);
UInt_8 GetType() const;
@@ -71,6 +75,10 @@ namespace ehs
const ButtonState* IsUp() const;
const ButtonState *IsPressed(const Button &button);
const ButtonState *GetPressed();
void ButtonDown(const Button& button);
void ButtonUp(const Button& button);
@@ -87,5 +95,11 @@ namespace ehs
bool AddState(const ButtonState& state);
ButtonState* GetState(const Button& button);
bool TickHoldTime(float delta);
void ResetTime();
void TickActivateTime(float delta);
};
}

View File

@@ -10,6 +10,8 @@ namespace ehs
private:
UInt_64 hashId;
Str_8 id;
UInt_64 start;
UInt_64 delta;
protected:
Array<HID*> devices;
@@ -29,9 +31,9 @@ namespace ehs
InputHandler& operator=(const InputHandler& ih);
bool operator==(const UInt_64 otherHashId);
bool operator==(const UInt_64 otherHashId) const;
bool operator!=(const UInt_64 otherHashId);
bool operator!=(const UInt_64 otherHashId) const;
virtual bool Initialize();

View File

@@ -23,7 +23,7 @@ namespace ehs
Keyboard& operator=(const Keyboard& hid);
void Poll() override;
void Poll(float delta) override;
Keyboard* Clone() const override;

View File

@@ -19,7 +19,7 @@ namespace ehs
public:
Mouse();
Mouse(Str_8 name, const UInt_64 id);
Mouse(Str_8 name, UInt_64 id);
Mouse(Mouse&& hid) noexcept = default;
@@ -29,7 +29,7 @@ namespace ehs
Mouse& operator=(const Mouse& hid);
void Poll() override;
void Poll(float delta) override;
void SetDelta(const Vec2_s32& newDelta);

View File

@@ -9,5 +9,7 @@ namespace ehs
{
public:
static void OpenURI(const Str_8& uri);
static Str_8 OpenFileDialog(const Str_8 &dir, const Str_8 &filters);
};
}

View File

@@ -9,5 +9,7 @@ namespace ehs
{
public:
static void OpenURI(const Str_8& uri);
static Str_8 OpenFileDialog(const Str_8 &dir, const Str_8 &filters);
};
}