Colobot
input.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 #include "common/key.h"
28 #include "common/singleton.h"
29 
30 #include "math/intpoint.h"
31 #include "math/point.h"
32 #include "math/vector.h"
33 
34 #include <map>
35 
36 struct Event;
37 
43 {
46  unsigned int primary, secondary;
47 
48  InputBinding(unsigned int p = KEY_INVALID, unsigned int s = KEY_INVALID)
49  : primary(p), secondary(s) {}
50 };
51 
57 {
59  int axis = 0;
61  bool invert = false;
62 };
63 
65 const int AXIS_INVALID = -1;
66 
71 class CInput : public CSingleton<CInput>
72 {
73 public:
75  CInput();
76 
78  void EventProcess(Event &event);
79 
81  void MouseMove(Math::IntPoint pos);
82 
83 
85  bool GetKeyState(InputSlot key) const;
86 
88  bool GetMouseButtonState(int index) const;
89 
91  void ResetKeyStates();
92 
94  Math::Point GetMousePos() const;
95 
96 
98  void SetDefaultInputBindings();
99 
101 
102  void SetInputBinding(InputSlot slot, InputBinding binding);
103  const InputBinding& GetInputBinding(InputSlot slot);
105 
107 
108  void SetJoyAxisBinding(JoyAxisSlot slot, JoyAxisBinding binding);
109  const JoyAxisBinding& GetJoyAxisBinding(JoyAxisSlot slot);
111 
113 
114  void SetJoystickDeadzone(float zone);
115  float GetJoystickDeadzone();
117 
119  InputSlot FindBinding(unsigned int key);
120 
122 
123  void SaveKeyBindings();
124  void LoadKeyBindings();
126 
128  InputSlot SearchKeyById(std::string id);
129 
131 
132  std::string GetKeysString(InputBinding binding);
133  std::string GetKeysString(InputSlot slot);
135 
136 private:
138  bool m_keyPresses[INPUT_SLOT_MAX];
139 
140 
142  Math::Point m_mousePos;
144  unsigned int m_mouseButtonsState;
145 
146 
148  Math::Vector m_keyMotion;
150  Math::Vector m_joyMotion;
152  Math::Vector m_joyMotionCam;
153 
155  Math::Vector m_cameraKeyMotion;
156 
158  InputBinding m_inputBindings[INPUT_SLOT_MAX];
159  JoyAxisBinding m_joyAxisBindings[JOY_AXIS_SLOT_MAX];
160  float m_joystickDeadzone;
161 
162  std::map<InputSlot, std::string> m_keyTable;
163 };
CSingleton base class for singletons.
InputSlot
Available slots for input bindings NOTE: When adding new values, remember to also update keyTable in ...
Definition: key.h:79
const unsigned int KEY_INVALID
Special value for invalid key bindings.
Definition: key.h:72
Point struct and related functions.
Definition: singleton.h:30
2D point
Definition: point.h:50
Binding for joystick axis.
Definition: input.h:56
Key-related macros and enums.
Vector struct and related functions.
3D (3x1) vector
Definition: vector.h:53
2D Point with integer coords
Definition: intpoint.h:41
unsigned int primary
Definition: input.h:46
Binding for input slot.
Definition: input.h:42
Event sent by system, interface or game.
Definition: event.h:735
IntPoint struct.
const int AXIS_INVALID
Invalid value for axis binding (no axis assigned)
Definition: input.h:65
JoyAxisSlot
Slots for joystick axes inputs.
Definition: key.h:120
Management of mouse, keyboard and joystick.
Definition: input.h:71