qtk/src/input.h

77 lines
2.2 KiB
C
Raw Normal View History

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>
#include <qtkapi.h>
#include <qtkwidget.h>
2021-09-03 16:56:57 +00:00
namespace Qtk {
class QTKAPI Input {
2022-11-24 22:26:53 +00:00
friend class Qtk::QtkWidget;
2022-11-24 22:26:53 +00:00
public:
// Possible key states
enum InputState {
InputInvalid,
InputRegistered,
InputUnregistered,
InputTriggered,
InputPressed,
InputReleased
};
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-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:
// 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-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