first commit
This commit is contained in:
136
include/platform/input/input_device.h
Normal file
136
include/platform/input/input_device.h
Normal file
@ -0,0 +1,136 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __INPUT_DEVICE__
|
||||
#define __INPUT_DEVICE__
|
||||
|
||||
|
||||
#include "ntypes.h"
|
||||
#include "memory/nshared_ptr.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace Input {
|
||||
|
||||
/*
|
||||
@short Input device.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class Device : public SharedObject
|
||||
{
|
||||
public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
Type_Any = 0, Type_Keyboard, Type_Mouse, Type_Pad, Type_Touch
|
||||
};
|
||||
|
||||
// Binary value.
|
||||
enum KeyCode
|
||||
{
|
||||
Key_None = 0,
|
||||
|
||||
// Keyboard.
|
||||
Key_LShift, Key_RShift, Key_LCtrl, Key_RCtrl, Key_LAlt, Key_RAlt, Key_LWin, Key_RWin,
|
||||
Key_Tab, Key_CapsLock, Key_Space, Key_Backspace, Key_Insert, Key_Suppr, Key_Home, Key_End, Key_PageUp, Key_PageDown,
|
||||
Key_Up, Key_Down, Key_Left, Key_Right,
|
||||
Key_Escape,
|
||||
Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, Key_F6, Key_F7, Key_F8, Key_F9, Key_F10, Key_F11, Key_F12,
|
||||
Key_PrintScreen, Key_ScrollLock, Key_Pause, Key_NumLock, Key_Return,
|
||||
Key_Numpad0, Key_Numpad1, Key_Numpad2, Key_Numpad3, Key_Numpad4, Key_Numpad5, Key_Numpad6, Key_Numpad7, Key_Numpad8, Key_Numpad9,
|
||||
Key_Add, Key_Sub, Key_Mul, Key_Div, Key_Enter,
|
||||
Key_A, Key_B, Key_C, Key_D, Key_E, Key_F, Key_G, Key_H, Key_I, Key_J, Key_K, Key_L, Key_M, Key_N, Key_O, Key_P, Key_Q, Key_R, Key_S, Key_T, Key_U, Key_V, Key_W, Key_X, Key_Y, Key_Z,
|
||||
|
||||
// Mouse/pad.
|
||||
Key_Button0, Key_Button1, Key_Button2, Key_Button3, Key_Button4, Key_Button5, Key_Button6, Key_Button7, Key_Button8, Key_Button9,
|
||||
Key_Button10, Key_Button11, Key_Button12, Key_Button13, Key_Button14, Key_Button15, Key_Button16, Key_Button17, Key_Button18, Key_Button19,
|
||||
Key_Button20, Key_Button21, Key_Button22, Key_Button23, Key_Button24, Key_Button25, Key_Button26, Key_Button27, Key_Button28, Key_Button29,
|
||||
Key_Button30, Key_Button31, Key_Button32, Key_Button33, Key_Button34, Key_Button35, Key_Button36, Key_Button37, Key_Button38, Key_Button39,
|
||||
Key_Button40, Key_Button41, Key_Button42, Key_Button43, Key_Button44, Key_Button45, Key_Button46, Key_Button47, Key_Button48, Key_Button49,
|
||||
Key_Button50, Key_Button51, Key_Button52, Key_Button53, Key_Button54, Key_Button55, Key_Button56, Key_Button57, Key_Button58, Key_Button59,
|
||||
Key_Button60, Key_Button61, Key_Button62, Key_Button63, Key_Button64, Key_Button65, Key_Button66, Key_Button67, Key_Button68, Key_Button69,
|
||||
Key_Button70, Key_Button71, Key_Button72, Key_Button73, Key_Button74, Key_Button75, Key_Button76, Key_Button77, Key_Button78, Key_Button79,
|
||||
Key_Button80, Key_Button81, Key_Button82, Key_Button83, Key_Button84, Key_Button85, Key_Button86, Key_Button87, Key_Button88, Key_Button89,
|
||||
Key_Button90, Key_Button91, Key_Button92, Key_Button93, Key_Button94, Key_Button95, Key_Button96, Key_Button97, Key_Button98, Key_Button99,
|
||||
Key_Button100, Key_Button101, Key_Button102, Key_Button103, Key_Button104, Key_Button105, Key_Button106, Key_Button107, Key_Button108, Key_Button109,
|
||||
Key_Button110, Key_Button111, Key_Button112, Key_Button113, Key_Button114, Key_Button115, Key_Button116, Key_Button117, Key_Button118, Key_Button119,
|
||||
Key_Button120, Key_Button121, Key_Button122, Key_Button123, Key_Button124, Key_Button125, Key_Button126, Key_Button127,
|
||||
Key_Back, Key_Start, Key_Select, Key_L1, Key_L2, Key_L3, Key_R1, Key_R2, Key_R3,
|
||||
Key_Cross_Up, Key_Cross_Down, Key_Cross_Left, Key_Cross_Right,
|
||||
|
||||
Key_Last
|
||||
};
|
||||
|
||||
// Ranged-value.
|
||||
enum InputCode
|
||||
{
|
||||
Input_None = 0,
|
||||
Input_AxisX, Input_AxisY, Input_AxisZ, Input_AxisS, Input_AxisT, Input_AxisR,
|
||||
Input_RotX, Input_RotY, Input_RotZ, Input_RotS, Input_RotT, Input_RotR,
|
||||
Input_Button0, Input_Button1, Input_Button2, Input_Button3, Input_Button4, Input_Button5, Input_Button6, Input_Button7, Input_Button8, Input_Button9, Input_Button10, Input_Button11, Input_Button12, Input_Button13, Input_Button14, Input_Button15
|
||||
};
|
||||
|
||||
// Input semantics.
|
||||
enum InputSemantic
|
||||
{
|
||||
// Mouse semantics.
|
||||
Semantic_LeftMouseButton, Semantic_RightMouseButton, Semantic_MiddleMouseButton,
|
||||
Semantic_MouseAxisX, Semantic_MouseAxisY, Semantic_MouseWheel,
|
||||
|
||||
// Touch semantic.
|
||||
Semantic_TouchPressure, Semantic_TouchAxisX, Semantic_TouchAxisY,
|
||||
|
||||
// Pad semantics.
|
||||
Semantic_StartButton, Semantic_SelectButton
|
||||
};
|
||||
|
||||
enum Effect
|
||||
{
|
||||
Vibrate, VibrateLeft, VibrateRight,
|
||||
ConstantForce
|
||||
};
|
||||
|
||||
/// Get device type.
|
||||
virtual Type GetType() const = 0;
|
||||
/// Get device name.
|
||||
virtual const char *GetName() const = 0;
|
||||
|
||||
/// Pool state and refresh values.
|
||||
virtual void Update() = 0;
|
||||
/// Is device valid.
|
||||
virtual bool IsValid() const { return true; }
|
||||
|
||||
/// Get input from semantic.
|
||||
virtual InputCode GetInputFromSemantic(InputSemantic) { return Input_None; }
|
||||
|
||||
/// Test a key state.
|
||||
virtual bool IsDown(KeyCode) const { return false; }
|
||||
/// Test a key state during the previous update.
|
||||
virtual bool WasDown(KeyCode) const { return false; }
|
||||
|
||||
/// Get input range.
|
||||
virtual bool GetInputRange(InputCode, float &min, float &max) const { return false; }
|
||||
|
||||
/// Get input value.
|
||||
virtual float GetValue(InputCode) const { return 0; }
|
||||
/// Get input value during last update.
|
||||
virtual float GetLastValue(InputCode) const { return 0; }
|
||||
|
||||
/// Set input value, return true if the device supports setting this value.
|
||||
virtual bool SetValue(InputCode, float) { return false; }
|
||||
|
||||
/// Set device effect.
|
||||
virtual void SetEffect(Effect effect, float v) {}
|
||||
|
||||
bool WasPressed(KeyCode key) const
|
||||
{ return !WasDown(key) && IsDown(key); }
|
||||
};
|
||||
|
||||
} // Input
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __INPUT_DEVICE__
|
||||
Reference in New Issue
Block a user