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-2015, 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/event.h"
28 #include "common/key.h"
29 #include "common/singleton.h"
30 
31 #include "math/intpoint.h"
32 
33 #include <map>
34 
40 {
43  unsigned int primary, secondary;
44 
45  InputBinding(unsigned int p = KEY_INVALID, unsigned int s = KEY_INVALID)
46  : primary(p), secondary(s) {}
47 };
48 
54 {
56  int axis = 0;
58  bool invert = false;
59 };
60 
62 const int AXIS_INVALID = -1;
63 
68 class CInput : public CSingleton<CInput>
69 {
70 public:
72  CInput();
73 
75  void EventProcess(Event &event);
76 
78  void MouseMove(Math::IntPoint pos);
79 
80 
82  int GetKmods() const;
83 
85  bool GetKmodState(int kmod) const;
86 
88  bool GetKeyState(InputSlot key) const;
89 
91  bool GetMouseButtonState(int index) const;
92 
94  void ResetKeyStates();
95 
97  Math::Point GetMousePos() const;
98 
99 
101  void SetDefaultInputBindings();
102 
104 
105  void SetInputBinding(InputSlot slot, InputBinding binding);
106  const InputBinding& GetInputBinding(InputSlot slot);
108 
110 
111  void SetJoyAxisBinding(JoyAxisSlot slot, JoyAxisBinding binding);
112  const JoyAxisBinding& GetJoyAxisBinding(JoyAxisSlot slot);
114 
116 
117  void SetJoystickDeadzone(float zone);
118  float GetJoystickDeadzone();
120 
122  InputSlot FindBinding(unsigned int key);
123 
125 
126  void SaveKeyBindings();
127  void LoadKeyBindings();
129 
131  InputSlot SearchKeyById(std::string name);
132 
134 
135  std::string GetKeysString(InputBinding binding);
136  std::string GetKeysString(InputSlot slot);
138 
139 private:
141  unsigned int m_kmodState;
143  bool m_keyPresses[INPUT_SLOT_MAX];
144 
145 
147  Math::Point m_mousePos;
149  unsigned int m_mouseButtonsState;
150 
151 
153  Math::Vector m_keyMotion;
155  Math::Vector m_joyMotion;
156 
158  Math::Vector m_cameraKeyMotion;
159 
161  InputBinding m_inputBindings[INPUT_SLOT_MAX];
162  JoyAxisBinding m_joyAxisBindings[JOY_AXIS_SLOT_MAX];
163  float m_joystickDeadzone;
164 
165  std::map<InputSlot, std::string> m_keyTable;
166 };
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:76
const unsigned int KEY_INVALID
Special value for invalid key bindings.
Definition: key.h:69
Definition: singleton.h:30
2D point
Definition: point.h:50
Binding for joystick axis.
Definition: input.h:53
Key-related macros and enums.
Event types, structs and event queue.
3D (3x1) vector
Definition: vector.h:53
2D Point with integer coords
Definition: intpoint.h:39
unsigned int primary
Definition: input.h:43
Binding for input slot.
Definition: input.h:39
Event sent by system, interface or game.
Definition: event.h:709
IntPoint struct.
const int AXIS_INVALID
Invalid value for axis binding (no axis assigned)
Definition: input.h:62
JoyAxisSlot
Slots for joystick axes inputs.
Definition: key.h:113
Management of mouse, keyboard and joystick.
Definition: input.h:68