2021-09-03 16:56:57 +00:00
|
|
|
/*##############################################################################
|
|
|
|
## Author: Shaun Reed ##
|
2022-03-06 16:54:05 +00:00
|
|
|
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
2021-09-03 16:56:57 +00:00
|
|
|
## About: Input class from tutorials followed at trentreed.net ##
|
|
|
|
## ##
|
|
|
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
|
|
##############################################################################*/
|
|
|
|
|
|
|
|
#ifndef QTOPENGL_INPUT_H
|
|
|
|
#define QTOPENGL_INPUT_H
|
|
|
|
|
|
|
|
#include <QPoint>
|
|
|
|
#include <Qt>
|
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
#include <qtkapi.h>
|
2022-08-21 19:37:42 +00:00
|
|
|
#include <qtkwidget.h>
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
namespace Qtk {
|
|
|
|
class QTKAPI Input {
|
2022-11-25 19:36:12 +00:00
|
|
|
public:
|
|
|
|
/*************************************************************************
|
|
|
|
* Typedefs
|
|
|
|
************************************************************************/
|
2022-11-24 22:26:53 +00:00
|
|
|
friend class Qtk::QtkWidget;
|
2022-08-07 17:12:12 +00:00
|
|
|
|
2022-11-25 19:36:12 +00:00
|
|
|
/**
|
|
|
|
* Possible key states
|
|
|
|
*/
|
2022-11-24 22:26:53 +00:00
|
|
|
enum InputState {
|
|
|
|
InputInvalid,
|
|
|
|
InputRegistered,
|
|
|
|
InputUnregistered,
|
|
|
|
InputTriggered,
|
|
|
|
InputPressed,
|
|
|
|
InputReleased
|
|
|
|
};
|
2022-08-07 17:12:12 +00:00
|
|
|
|
2022-11-25 19:36:12 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* Public Methods
|
|
|
|
************************************************************************/
|
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
// State checking
|
|
|
|
inline static bool keyTriggered(Qt::Key key) {
|
|
|
|
return keyState(key) == InputTriggered;
|
|
|
|
}
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
inline static bool keyPressed(Qt::Key key) {
|
|
|
|
return keyState(key) == InputPressed;
|
|
|
|
}
|
2022-08-07 17:12:12 +00:00
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
inline static bool keyReleased(Qt::Key key) {
|
|
|
|
return keyState(key) == InputReleased;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static bool buttonTriggered(Qt::MouseButton button) {
|
|
|
|
return buttonState(button) == InputTriggered;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static bool buttonPressed(Qt::MouseButton button) {
|
|
|
|
return buttonState(button) == InputPressed;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static bool buttonReleased(Qt::MouseButton button) {
|
|
|
|
return buttonState(button) == InputReleased;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implementation
|
|
|
|
static InputState keyState(Qt::Key key);
|
|
|
|
static InputState buttonState(Qt::MouseButton button);
|
|
|
|
|
|
|
|
static QPoint mousePosition();
|
|
|
|
static QPoint mouseDelta();
|
|
|
|
|
|
|
|
private:
|
2022-11-25 19:36:12 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* Private Methods
|
|
|
|
************************************************************************/
|
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
// State updating
|
|
|
|
static void update();
|
|
|
|
static void registerKeyPress(int key);
|
|
|
|
static void registerKeyRelease(int key);
|
|
|
|
static void registerMousePress(Qt::MouseButton button);
|
|
|
|
static void registerMouseRelease(Qt::MouseButton button);
|
|
|
|
static void reset();
|
2022-08-07 17:12:12 +00:00
|
|
|
};
|
2022-11-24 22:26:53 +00:00
|
|
|
} // namespace Qtk
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-11-24 22:26:53 +00:00
|
|
|
#endif // QTOPENGL_INPUT_H
|