-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d5383c
commit 3d8650d
Showing
8 changed files
with
200 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include "Exports.h" | ||
|
||
namespace Iridescent { | ||
|
||
class IRID_EXPORT Input | ||
{ | ||
public: | ||
inline static bool IsKeyPressed(int keycode) { return s_Instance->IsKeyPressedImpl(keycode); } | ||
|
||
inline static bool IsMouseButtonPressed(int button) { return s_Instance->IsMouseButtonPressedImpl(button); } | ||
inline static std::pair<float, float> GetMousePosition() { return s_Instance->GetMousePositionImpl(); } | ||
inline static float GetMouseX() { return s_Instance->GetMouseXImpl(); } | ||
inline static float GetMouseY() { return s_Instance->GetMouseYImpl(); } | ||
protected: | ||
virtual bool IsKeyPressedImpl(int keycode) = 0; | ||
|
||
virtual bool IsMouseButtonPressedImpl(int button) = 0; | ||
virtual std::pair<float, float> GetMousePositionImpl() = 0; | ||
virtual float GetMouseXImpl() = 0; | ||
virtual float GetMouseYImpl() = 0; | ||
private: | ||
static Input* s_Instance; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "Iridpch.h" | ||
#include "WindowsInput.h" | ||
|
||
#include "Application/Application.h" | ||
#include <GLFW/glfw3.h> | ||
|
||
namespace Iridescent { | ||
|
||
Input* Input::s_Instance = new WindowsInput(); | ||
|
||
bool WindowsInput::IsKeyPressedImpl(int keycode) | ||
{ | ||
auto window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); | ||
auto state = glfwGetKey(window, keycode); | ||
return state == GLFW_PRESS || state == GLFW_REPEAT; | ||
} | ||
|
||
bool WindowsInput::IsMouseButtonPressedImpl(int button) | ||
{ | ||
auto window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); | ||
auto state = glfwGetMouseButton(window, button); | ||
return state == GLFW_PRESS; | ||
} | ||
|
||
std::pair<float, float> WindowsInput::GetMousePositionImpl() | ||
{ | ||
auto window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); | ||
double xpos, ypos; | ||
glfwGetCursorPos(window, &xpos, &ypos); | ||
|
||
return { (float)xpos, (float)ypos }; | ||
} | ||
|
||
float WindowsInput::GetMouseXImpl() | ||
{ | ||
auto[x, y] = GetMousePositionImpl(); | ||
return x; | ||
} | ||
|
||
float WindowsInput::GetMouseYImpl() | ||
{ | ||
auto[x, y] = GetMousePositionImpl(); | ||
return y; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include "Input.h" | ||
|
||
namespace Iridescent { | ||
|
||
class WindowsInput : public Input | ||
{ | ||
protected: | ||
virtual bool IsKeyPressedImpl(int keycode) override; | ||
|
||
virtual bool IsMouseButtonPressedImpl(int button) override; | ||
virtual std::pair<float, float> GetMousePositionImpl() override; | ||
virtual float GetMouseXImpl() override; | ||
virtual float GetMouseYImpl() override; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters