~groovestomp/gsnes

gsnes/input.h -rwxr-xr-x 2.4 KiB
9de07668 — GrooveStomp Foreground rendering works 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/******************************************************************************
  GrooveStomp's NES Emulator
  Copyright (c) 2019 Aaron Oman (GrooveStomp)

  File: input.h
  Created: 2019-07-21
  Updated: 2019-12-01
  Author: Aaron Oman
  Notice: GNU GPLv3 License

  This program comes with ABSOLUTELY NO WARRANTY.
  This is free software, and you are welcome to redistribute it under certain
  conditions; See LICENSE for details.
 ******************************************************************************/
//! \file input.h
//! A small interface to manage handling input separately from main().

#ifndef INPUT_VERSION
#define INPUT_VERSION "0.2-gsnes" //!< include guard and version info

#include <stdbool.h>

struct button_state {
        bool pressed;
        bool released;
        bool held;
};

struct input;

//! \brief Creates and initializes new input state
//! \return The initialized input state
struct input *
InputInit();

//! \brief De-initializes and frees memory for the input state
//! \param[in,out] input
void
InputDeinit(struct input *input);

//! \brief Handle program inputs
//!
//! Processes all program inputs and stores relevant data internally in input.
//!
//! \param[in,out] input
void
InputProcess(struct input *input);

//! \brief Check if the user has tried to quit the program
//!
//! \param[in,out] input
//! \return 1 if quit has been pressed, otherwise 0
int
InputIsQuitRequested(struct input *input);

enum input_key_enum {
        KEY_A = 0,
        KEY_B,
        KEY_C,
        KEY_D,
        KEY_E,
        KEY_F,
        KEY_G,
        KEY_H,
        KEY_I,
        KEY_J,
        KEY_K,
        KEY_L,
        KEY_M,
        KEY_N,
        KEY_O,
        KEY_P,
        KEY_Q,
        KEY_R,
        KEY_S,
        KEY_T,
        KEY_U,
        KEY_V,
        KEY_W,
        KEY_X,
        KEY_Y,
        KEY_Z,
        KEY_LEFT,
        KEY_RIGHT,
        KEY_UP,
        KEY_DOWN,
        KEY_ENTER,
        KEY_ESC,
        KEY_LSHIFT,
        KEY_RSHIFT,
        KEY_LCTRL,
        KEY_RCTRL,
        KEY_SPACE,
        KEY_1,
        KEY_2,
        KEY_3,
        KEY_4,
        KEY_5,
        KEY_6,
        KEY_7,
        KEY_8,
        KEY_9,
        KEY_0,
        KEY_COUNT
};

unsigned int
InputIsKeyPressed(struct input *input, enum input_key_enum e);

struct button_state
InputGetKey(struct input *input, enum input_key_enum e);

#endif // INPUT_VERSION