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  int GetKmods() const;
86 
88  bool GetKmodState(int kmod) const;
89 
91  bool GetKeyState(InputSlot key) const;
92 
94  bool GetMouseButtonState(int index) const;
95 
97  void ResetKeyStates();
98 
100  Math::Point GetMousePos() const;
101 
102 
104  void SetDefaultInputBindings();
105 
107 
108  void SetInputBinding(InputSlot slot, InputBinding binding);
109  const InputBinding& GetInputBinding(InputSlot slot);
111 
113 
114  void SetJoyAxisBinding(JoyAxisSlot slot, JoyAxisBinding binding);
115  const JoyAxisBinding& GetJoyAxisBinding(JoyAxisSlot slot);
117 
119 
120  void SetJoystickDeadzone(float zone);
121  float GetJoystickDeadzone();
123 
125  InputSlot FindBinding(unsigned int key);
126 
128 
129  void SaveKeyBindings();
130  void LoadKeyBindings();
132 
134  InputSlot SearchKeyById(std::string id);
135 
137 
138  std::string GetKeysString(InputBinding binding);
139  std::string GetKeysString(InputSlot slot);
141 
142 private:
144  unsigned int m_kmodState;
146  bool m_keyPresses[INPUT_SLOT_MAX];
147 
148 
150  Math::Point m_mousePos;
152  unsigned int m_mouseButtonsState;
153 
154 
156  Math::Vector m_keyMotion;
158  Math::Vector m_joyMotion;
159 
161  Math::Vector m_cameraKeyMotion;
162 
164  InputBinding m_inputBindings[INPUT_SLOT_MAX];
165  JoyAxisBinding m_joyAxisBindings[JOY_AXIS_SLOT_MAX];
166  float m_joystickDeadzone;
167 
168  std::map<InputSlot, std::string> m_keyTable;
169 };
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:39
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:699
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:117
Management of mouse, keyboard and joystick.
Definition: input.h:71