1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-28 23:48:30 +02:00
VVVVVV/desktop_version/src/KeyPoll.h
Misa 2608db9151 Directly toggle fullscreen if keybind pressed in key.Poll()
This moves the responsibility of toggling fullscreen when any of the
three toggle fullscreen keybinds are pressed (F11, Alt+Enter, Alt+F)
directly into key.Poll() itself, and not its caller (which is main() -
more specifically, fixedloop()). Furthermore, the fullscreen toggle
itself has been moved to a separate function that key.Poll() just calls,
to prevent cluttering key.Poll() with more business logic (the function
is already quite big enough as it is).

As part of my work in re-removing the 1-frame input delay in #535, I'm
moving the callsite of key.Poll() around, and I don't want to have to
lug this block of code around with it. I'd rather refactor it upfront
than touch any more lines than necessary in that PR.
2021-03-17 03:01:19 -04:00

87 lines
1.5 KiB
C++

#ifndef KEYPOLL_H
#define KEYPOLL_H
#include <map> // FIXME: I should feel very bad for using C++ -flibit
#include <SDL.h>
#include <string>
#include <vector>
enum Kybrd
{
KEYBOARD_UP = SDLK_UP,
KEYBOARD_DOWN = SDLK_DOWN,
KEYBOARD_LEFT = SDLK_LEFT,
KEYBOARD_RIGHT = SDLK_RIGHT,
KEYBOARD_ENTER = SDLK_RETURN,
KEYBOARD_SPACE = SDLK_SPACE,
KEYBOARD_w = SDLK_w,
KEYBOARD_s = SDLK_s,
KEYBOARD_a = SDLK_a,
KEYBOARD_d = SDLK_d,
KEYBOARD_m = SDLK_m,
KEYBOARD_n = SDLK_n,
KEYBOARD_v = SDLK_v,
KEYBOARD_z = SDLK_z,
KEYBOARD_BACKSPACE = SDLK_BACKSPACE
};
class KeyPoll
{
public:
std::map<SDL_Keycode, bool> keymap;
bool isActive;
bool resetWindow;
bool quitProgram;
void toggleFullscreen(void);
int sensitivity;
int inline getThreshold(void);
KeyPoll(void);
void enabletextentry(void);
void disabletextentry(void);
void Poll(void);
bool isDown(SDL_Keycode key);
bool isDown(std::vector<SDL_GameControllerButton> buttons);
bool isDown(SDL_GameControllerButton button);
bool controllerButtonDown(void);
bool controllerWantsLeft(bool includeVert);
bool controllerWantsRight(bool includeVert);
int leftbutton, rightbutton, middlebutton;
int mx, my;
bool textentry(void);
bool pressedbackspace;
std::string keybuffer;
bool linealreadyemptykludge;
Uint64 pauseStart;
private:
std::map<SDL_JoystickID, SDL_GameController*> controllers;
std::map<SDL_GameControllerButton, bool> buttonmap;
int xVel, yVel;
bool useFullscreenSpaces;
Uint32 wasFullscreen;
};
#ifndef KEY_DEFINITION
extern KeyPoll key;
#endif
#endif /* KEYPOLL_H */