1 //Copyright Paul Reiche, Fred Ford. 1992-2002
2 
3 /*
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 
19 #ifndef UQM_CONTROLS_H_
20 #define UQM_CONTROLS_H_
21 
22 #include "libs/compiler.h"
23 #include "libs/strlib.h"
24 #include "libs/timelib.h"
25 
26 #if defined(__cplusplus)
27 extern "C" {
28 #endif
29 
30 // Enumerated type for controls
31 enum {
32 	KEY_UP,
33 	KEY_DOWN,
34 	KEY_LEFT,
35 	KEY_RIGHT,
36 	KEY_WEAPON,
37 	KEY_SPECIAL,
38 	KEY_ESCAPE,
39 	NUM_KEYS
40 };
41 enum {
42 	KEY_PAUSE,
43 	KEY_EXIT,
44 	KEY_ABORT,
45 	KEY_DEBUG,
46 	KEY_FULLSCREEN,
47 	KEY_MENU_UP,
48 	KEY_MENU_DOWN,
49 	KEY_MENU_LEFT,
50 	KEY_MENU_RIGHT,
51 	KEY_MENU_SELECT,
52 	KEY_MENU_CANCEL,
53 	KEY_MENU_SPECIAL,
54 	KEY_MENU_PAGE_UP,
55 	KEY_MENU_PAGE_DOWN,
56 	KEY_MENU_HOME,
57 	KEY_MENU_END,
58 	KEY_MENU_ZOOM_IN,
59 	KEY_MENU_ZOOM_OUT,
60 	KEY_MENU_DELETE,
61 	KEY_MENU_BACKSPACE,
62 	KEY_MENU_EDIT_CANCEL,
63 	KEY_MENU_SEARCH,
64 	KEY_MENU_NEXT,
65 	KEY_MENU_ANY, /* abstract char key */
66 	NUM_MENU_KEYS
67 };
68 
69 typedef enum {
70 	CONTROL_TEMPLATE_KB_1,
71 	CONTROL_TEMPLATE_KB_2,
72 	CONTROL_TEMPLATE_KB_3,
73 	CONTROL_TEMPLATE_JOY_1,
74 	CONTROL_TEMPLATE_JOY_2,
75 	CONTROL_TEMPLATE_JOY_3,
76 	NUM_TEMPLATES
77 } CONTROL_TEMPLATE;
78 
79 typedef struct _controller_input_state {
80 	int key[NUM_TEMPLATES][NUM_KEYS];
81 	int menu[NUM_MENU_KEYS];
82 } CONTROLLER_INPUT_STATE;
83 
84 typedef UBYTE BATTLE_INPUT_STATE;
85 #define BATTLE_LEFT       ((BATTLE_INPUT_STATE)(1 << 0))
86 #define BATTLE_RIGHT      ((BATTLE_INPUT_STATE)(1 << 1))
87 #define BATTLE_THRUST     ((BATTLE_INPUT_STATE)(1 << 2))
88 #define BATTLE_WEAPON     ((BATTLE_INPUT_STATE)(1 << 3))
89 #define BATTLE_SPECIAL    ((BATTLE_INPUT_STATE)(1 << 4))
90 #define BATTLE_ESCAPE     ((BATTLE_INPUT_STATE)(1 << 5))
91 #define BATTLE_DOWN       ((BATTLE_INPUT_STATE)(1 << 6))
92 
93 BATTLE_INPUT_STATE CurrentInputToBattleInput (COUNT player);
94 BATTLE_INPUT_STATE PulsedInputToBattleInput (COUNT player);
95 
96 extern CONTROLLER_INPUT_STATE CurrentInputState;
97 extern CONTROLLER_INPUT_STATE PulsedInputState;
98 extern volatile CONTROLLER_INPUT_STATE ImmediateInputState;
99 extern CONTROL_TEMPLATE PlayerControls[];
100 
101 void UpdateInputState (void);
102 extern void FlushInput (void);
103 void SetMenuRepeatDelay (DWORD min, DWORD max, DWORD step, BOOLEAN gestalt);
104 void SetDefaultMenuRepeatDelay (void);
105 void ResetKeyRepeat (void);
106 BOOLEAN PauseGame (void);
107 void SleepGame (void);
108 BOOLEAN DoConfirmExit (void);
109 BOOLEAN ConfirmExit (void);
110 
111 #define WAIT_INFINITE ((TimePeriod)-1)
112 BOOLEAN WaitForAnyButton (BOOLEAN newButton, TimePeriod duration,
113 		BOOLEAN resetInput);
114 BOOLEAN WaitForAnyButtonUntil (BOOLEAN newButton, TimeCount timeOut,
115 		BOOLEAN resetInput);
116 BOOLEAN WaitForNoInput (TimePeriod duration, BOOLEAN resetInput);
117 BOOLEAN WaitForNoInputUntil (TimeCount timeOut, BOOLEAN resetInput);
118 
119 void DoPopupWindow(const char *msg);
120 
121 typedef void (InputFrameCallback) (void);
122 InputFrameCallback* SetInputCallback (InputFrameCallback *);
123 // pInputState must point to a struct derived from INPUT_STATE_DESC
124 void DoInput (void *pInputState, BOOLEAN resetInput);
125 
126 extern volatile BOOLEAN GamePaused;
127 extern volatile BOOLEAN ExitRequested;
128 
129 typedef struct joy_char joy_char_t;
130 
131 typedef struct textentry_state
132 {
133 	// standard state required by DoInput
134 	BOOLEAN (*InputFunc) (struct textentry_state *pTES);
135 
136 	// these are semi-private read-only
137 	BOOLEAN Initialized;
138 	DWORD NextTime;    // use this for input frame timing
139 	BOOLEAN Success;   // edit confirmed or canceled
140 	UNICODE *CacheStr; // cached copy to revert immediate changes
141 	STRING JoyAlphaString; // joystick alphabet definition
142 	BOOLEAN JoystickMode;  // TRUE when doing joystick input
143 	BOOLEAN UpperRegister; // TRUE when entering Caps
144 	joy_char_t *JoyAlpha;  // joystick alphabet
145 	int JoyAlphaLength;
146 	joy_char_t *JoyUpper;  // joystick upper register
147 	joy_char_t *JoyLower;  // joystick lower register
148 	int JoyRegLength;
149 	UNICODE *InsPt;        // set to current pos of insertion point
150 	// these are public and must be set before calling DoTextEntry
151 	UNICODE *BaseStr;  // set to string to edit
152 	int CursorPos;     // set to current cursor pos in chars
153 	int MaxSize;       // set to max size of edited string
154 
155 	BOOLEAN (*ChangeCallback) (struct textentry_state *pTES);
156 			// returns TRUE if last change is OK
157 	BOOLEAN (*FrameCallback) (struct textentry_state *pTES);
158 			// called on every input frame; do whatever;
159 			// returns TRUE to continue processing
160 	void *CbParam;     // callback parameter, use as you like
161 
162 } TEXTENTRY_STATE;
163 
164 extern BOOLEAN DoTextEntry (TEXTENTRY_STATE *pTES);
165 
166 #if defined(__cplusplus)
167 }
168 #endif
169 
170 #endif
171 
172 
173