ninputserver.h
Go to the documentation of this file.00001 #ifndef N_INPUTSERVER_H
00002 #define N_INPUTSERVER_H
00003
00014 #include "kernel/ntypes.h"
00015 #include "kernel/nroot.h"
00016 #include "kernel/nautoref.h"
00017 #include "input/ninputevent.h"
00018 #include "input/ninputstate.h"
00019 #include "util/nhashlist.h"
00020
00021
00022 class nScriptServer;
00023 class nConServer;
00024 class nInputServer : public nRoot
00025 {
00026 public:
00028 nInputServer();
00030 virtual ~nInputServer();
00032 static nInputServer* Instance();
00034 virtual void Open();
00036 virtual void Trigger(double time);
00038 nInputEvent* NewEvent();
00040 void ReleaseEvent(nInputEvent* event);
00042 void LinkEvent(nInputEvent* event);
00044 void UnlinkEvent(nInputEvent* event);
00046 void FlushEvents();
00048 nInputEvent* FirstEvent();
00050 nInputEvent* NextEvent(nInputEvent*);
00052 void BeginMap();
00054 bool Map(const char* event, const char* state);
00056 void EndMap();
00058 float GetSlider(const char* state);
00060 bool GetButton(const char* state);
00062 const vector2& GetMousePos() const;
00064 void StartLogging();
00066 void StopLogging();
00068 bool IsLogging();
00070 void SetLongPressedTime(float);
00072 float GetLongPressedTime();
00074 void SetDoubleClickTime(float);
00076 float GetDoubleClickTime();
00078 void SetMouseFactor(float s);
00080 float GetMouseFactor() const;
00082 void SetMouseInvert(bool b);
00084 bool GetMouseInvert() const;
00086 void ObtainFocus();
00088 void LoseFocus();
00090 void FlushInput();
00092 void SetMute(bool b);
00094 bool GetMute() const;
00095
00096 protected:
00098 bool MapStrToEvent(const char* str, nInputEvent* event);
00100 nInputEvent* FirstIdenticalEvent(nInputEvent* pattern);
00102 nInputEvent* NextIdenticalEvent(nInputEvent* pattern, nInputEvent* cur);
00104 void DoInputMapping();
00106 void BeginScripts();
00108 void AddScript(const char* script);
00110 void EndScripts();
00112 bool IsIdenticalEvent(nInputEvent* event0, nInputEvent* event1);
00114 void LogSingleEvent(nInputEvent* event);
00116 void LogEvents();
00118 nInputState* GetInputState(const char* state);
00120 nInputState* AddInputState(const char* state);
00121
00122 #ifndef __XBxX__
00123
00124 void ExportDefaultKeyboard();
00126 void ExportDefaultMouse();
00127 #endif
00128
00130 const char* BuildInputMappingName(const char* ieStr, const char* isStr, char* buf, int bufSize);
00131
00132 private:
00133 static nInputServer* Singleton;
00134
00135 protected:
00136 enum
00137 {
00138 N_MAXNUM_SCRIPTS = 16,
00139 };
00140
00141 double timeStamp;
00142
00143 nAutoRef<nScriptServer> ref_ss;
00144 nAutoRef<nConServer> ref_con;
00145 nRef<nRoot> ref_statedir;
00146 nRef<nRoot> ref_inpdir;
00147
00148 nList events;
00149
00150 bool log_events;
00151 bool in_begin_map;
00152 bool mute;
00153
00154 nHashList im_list;
00155 nHashList is_list;
00156
00157 int act_script;
00158 const char* script_array[N_MAXNUM_SCRIPTS];
00159
00160 double long_pressed_time;
00161 double double_click_time;
00162 float mouseFactor;
00163 bool mouseInvert;
00164 vector2 mousePos;
00165 };
00166
00167
00170 inline
00171 nInputServer*
00172 nInputServer::Instance()
00173 {
00174 n_assert(Singleton);
00175 return Singleton;
00176 }
00177
00178
00183 inline
00184 void
00185 nInputServer::SetMute(bool b)
00186 {
00187 this->mute = b;
00188 }
00189
00190
00193 inline
00194 bool
00195 nInputServer::GetMute() const
00196 {
00197 return this->mute;
00198 }
00199
00200
00203 inline
00204 const vector2&
00205 nInputServer::GetMousePos() const
00206 {
00207 return this->mousePos;
00208 }
00209
00210
00213 inline
00214 void
00215 nInputServer::SetMouseFactor(float f)
00216 {
00217 this->mouseFactor = f;
00218 n_printf("nInputServer::SetMouseFactor(%f)\n", f);
00219 }
00220
00221
00224 inline
00225 float
00226 nInputServer::GetMouseFactor() const
00227 {
00228 return this->mouseFactor;
00229 }
00230
00231
00234 inline
00235 void
00236 nInputServer::SetMouseInvert(bool b)
00237 {
00238 this->mouseInvert = b;
00239 n_printf("nInputServer::SetInvertMouse(%s)\n", b ? "true" : "false");
00240 }
00241
00242
00245 inline
00246 bool
00247 nInputServer::GetMouseInvert() const
00248 {
00249 return this->mouseInvert;
00250 }
00251
00252
00253 #endif