source: trunk/src/input/input.h @ 1751

Last change on this file since 1751 was 1751, checked in by touky, 8 years ago

Added a skeleton for Input Tracking & base idea for Touch/untouch mechanics.

  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11//
12// The Input static class
13// ----------------------
14//
15
16#if !defined __LOL_INPUT_INPUT_H__
17#define __LOL_INPUT_INPUT_H__
18
19#include "lol/math/vector.h"
20#include "input/stick.h"
21
22namespace lol
23{
24
25class WorldEntity;
26
27//Partial Key reap-off of the SDLK enum
28#define LOLK_UNKNOWN = 0;
29
30#define LOLK_RETURN = '\r';
31#define LOLK_ESCAPE = '\033';
32#define LOLK_BACKSPACE = '\b';
33#define LOLK_TAB = '\t';
34#define LOLK_SPACE = ' ';
35#define LOLK_EXCLAIM = '!';
36#define LOLK_QUOTEDBL = '"';
37#define LOLK_HASH = '#';
38#define LOLK_PERCENT = '%';
39#define LOLK_DOLLAR = '$';
40#define LOLK_AMPERSAND = '&';
41#define LOLK_QUOTE = '\'';
42#define LOLK_LEFTPAREN = '(';
43#define LOLK_RIGHTPAREN = ')';
44#define LOLK_ASTERISK = '*';
45#define LOLK_PLUS = '+';
46#define LOLK_COMMA = ';';
47#define LOLK_MINUS = '-';
48#define LOLK_PERIOD = '.';
49#define LOLK_SLASH = '/';
50#define LOLK_0 = '0';
51#define LOLK_1 = '1';
52#define LOLK_2 = '2';
53#define LOLK_3 = '3';
54#define LOLK_4 = '4';
55#define LOLK_5 = '5';
56#define LOLK_6 = '6';
57#define LOLK_7 = '7';
58#define LOLK_8 = '8';
59#define LOLK_9 = '9';
60#define LOLK_COLON = ':';
61#define LOLK_SEMICOLON = ';';
62#define LOLK_LESS = '<';
63#define LOLK_EQUALS = '=';
64#define LOLK_GREATER = '>';
65#define LOLK_QUESTION = '?';
66#define LOLK_AT = '@';
67/*
68    Skip uppercase letters
69    */
70#define LOLK_LEFTBRACKET = '[';
71#define LOLK_BACKSLASH = '\\';
72#define LOLK_RIGHTBRACKET = ']';
73#define LOLK_CARET = '^';
74#define LOLK_UNDERSCORE = '_';
75#define LOLK_BACKQUOTE = '`';
76#define LOLK_a = 'a';
77#define LOLK_b = 'b';
78#define LOLK_c = 'c';
79#define LOLK_d = 'd';
80#define LOLK_e = 'e';
81#define LOLK_f = 'f';
82#define LOLK_g = 'g';
83#define LOLK_h = 'h';
84#define LOLK_i = 'i';
85#define LOLK_j = 'j';
86#define LOLK_k = 'k';
87#define LOLK_l = 'l';
88#define LOLK_m = 'm';
89#define LOLK_n = 'n';
90#define LOLK_o = 'o';
91#define LOLK_p = 'p';
92#define LOLK_q = 'q';
93#define LOLK_r = 'r';
94#define LOLK_s = 's';
95#define LOLK_t = 't';
96#define LOLK_u = 'u';
97#define LOLK_v = 'v';
98#define LOLK_w = 'w';
99#define LOLK_x = 'x';
100#define LOLK_y = 'y';
101#define LOLK_z = 'z';
102
103struct ActionSetting
104{
105        int                                             ActionId;
106        float                                   BufferingTime;
107        float                                   BufferedSince;
108
109        ActionSetting(int NewActionId)
110        {
111                memset(this, 0, sizeof(ActionSetting));
112                ActionId = NewActionId;
113        }
114};
115
116struct ButtonSetting
117{
118        int                                             RawButtonId;
119        int                                             CurStatus;
120        int                                             PrevStatus;
121        Array<ActionSetting>    AssociatedActionList;
122
123        ButtonSetting(int NewRawButtonId)
124        {
125                memset(this, 0, sizeof(ButtonSetting));
126                RawButtonId = NewRawButtonId;
127        }
128        int GetActionSettingIdx(int ActionId)
129        {
130                for (int i = 0; i < AssociatedActionList.Count(); i++)
131                        if (AssociatedActionList[i].ActionId == ActionId)
132                                return i;
133                return -1;
134        }
135};
136
137class Input
138{
139private:
140        static Array<ButtonSetting>     InputAssocationList;
141
142        static int GetButtonSettingIdx(int ButtonId)
143        {
144                for (int i = 0; i < InputAssocationList.Count(); i++)
145                        if (InputAssocationList[i].RawButtonId == ButtonId)
146                                return i;
147                return -1;
148        }
149
150        static void UpdateActionStatus(float seconds);
151
152public:
153
154    /* These methods are general queries */
155    static ivec2 GetMousePos();
156    static ivec3 GetMouseButtons();
157
158        //BH : Shouldn't use this
159    static int GetButtonState(int button);
160
161        //Action management
162        static void LinkActionIdToButtonId(int ActionId, int ButtonId);
163        static void UnlinkActionId(int ActionId);
164        static int GetActionStatus(int ActionId);
165        static bool WasActionJustReleased(int ActionId);
166
167    /* Entities can subscribe to events */
168    static void TrackMouse(WorldEntity *e);
169    static void UntrackMouse(WorldEntity *e);
170
171    /* These methods are called by the underlying input listeners */
172    static void SetMousePos(ivec2 coord);
173    static void SetMouseButton(int index);
174    static void UnsetMouseButton(int index);
175
176    /*
177     * Joystick handling
178     */
179
180    static Stick *CreateStick();
181    static void DestroyStick(Stick *stick);
182
183    static Stick *TrackStick(int desired);
184    static void UntrackStick(Stick *stick);
185};
186
187} /* namespace lol */
188
189#endif // __LOL_INPUT_INPUT_H__
190
Note: See TracBrowser for help on using the repository browser.