summaryrefslogtreecommitdiff
path: root/src/FLD.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/FLD.hpp')
-rw-r--r--src/FLD.hpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/FLD.hpp b/src/FLD.hpp
index 05677fb..958a724 100644
--- a/src/FLD.hpp
+++ b/src/FLD.hpp
@@ -1,8 +1,10 @@
#pragma once
#include <SDL2/SDL_render.h>
+#include <SDL2/SDL_scancode.h>
+#include <SDL2/SDL_gamecontroller.h>
#include <string>
#include <map>
-#include <optional>
+#include <array>
#include <climits>
#include "soloud.h"
@@ -13,6 +15,15 @@ public:
using Error = int;
using Uint = unsigned int;
using MainLoop = int (*)(FLD& fld, void *udata);
+ enum class InputState {
+ Up,
+ Down,
+ Release,
+ Press
+ };
+ using InputStateArray = std::array<InputState, SDL_NUM_SCANCODES>;
+ using MouseStateArray = std::array<InputState, 256>;
+ using JoyStateArray = std::array<InputState, SDL_CONTROLLER_BUTTON_MAX>;
struct Config {
int width = 640;
int height = 480;
@@ -85,6 +96,9 @@ public:
READONLY(SDL_Texture *, target, nullptr);
READONLY(unsigned long, tick, 0);
READONLY(Color, drawColor, Color({0, 0, 0, 1}));
+ READONLY(InputStateArray, keystates, {});
+ READONLY(MouseStateArray, mousestates, {});
+ READONLY(JoyStateArray, joystates, {});
public:
FLD(const Config& config);
FLD(const Config&& config);
@@ -103,6 +117,24 @@ public:
Error drawRectangle(const Rectangle& rect, Uint flags=NONE) const;
[[nodiscard]] Image& image(const std::string& path);
+
+ [[nodiscard]] InputState keyGet(SDL_Scancode sc) const;
+ [[nodiscard]] bool keyDown(SDL_Scancode sc) const;
+ [[nodiscard]] bool keyUp(SDL_Scancode sc) const;
+ [[nodiscard]] bool keyPressed(SDL_Scancode sc) const;
+ [[nodiscard]] bool keyReleased(SDL_Scancode sc) const;
+
+ [[nodiscard]] InputState mouseGet(SDL_Scancode sc) const;
+ [[nodiscard]] bool mouseDown(SDL_Scancode sc) const;
+ [[nodiscard]] bool mouseUp(SDL_Scancode sc) const;
+ [[nodiscard]] bool mousePressed(SDL_Scancode sc) const;
+ [[nodiscard]] bool mouseReleased(SDL_Scancode sc) const;
+
+ [[nodiscard]] InputState joyGet(SDL_Scancode sc) const;
+ [[nodiscard]] bool joyDown(SDL_Scancode sc) const;
+ [[nodiscard]] bool joyUp(SDL_Scancode sc) const;
+ [[nodiscard]] bool joyPressed(SDL_Scancode sc) const;
+ [[nodiscard]] bool joyReleased(SDL_Scancode sc) const;
private:
bool shouldQuit = false;
struct {