Merge branch 'Input' of https://github.com/dean11/Danbias into GameServer

This commit is contained in:
Dennis Andersen 2014-02-16 01:28:50 +01:00
commit cce037783d
26 changed files with 2324 additions and 1401 deletions

View File

@ -0,0 +1,60 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef INPUT_COMMON_H
#define INPUT_COMMON_H
#include "PreReq.h"
#include <math.h>
namespace Input
{
class Keyboard;
class Mouse;
class InputManager;
class InputObject;
/*********************************************************************/
namespace Enum
{
enum SAIType
{
SAIType_Keyboard,
SAIType_Mouse,
SAIType_futureExample1,
SAIType_futureExample2,
SAIType_futureExample3,
};
enum ButtonState
{
ButtonState_Press, // When button is pressed (once)
ButtonState_Down, // When the button is held down
ButtonState_Release, // When button is released (once)
ButtonState_Up, // Default state, will not be proccesed as a callback!
};
}
/*********************************************************************/
namespace Struct
{
struct SAIPoint2D
{
int x;
int y;
SAIPoint2D() :x(0), y(0) { }
SAIPoint2D(int _x, int _y) :x(_x), y(_y) { }
int Length() { return (abs(x) + abs(y)); }
};
struct InputData;
}
/*********************************************************************/
namespace Typedefs
{
typedef void(*InputCallback)(const Struct::InputData& data);
typedef void* DEVICE;
typedef void* WindowHandle;
}
/*********************************************************************/
}
#endif // !INPUT_COMMON_H

View File

@ -0,0 +1,58 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef RAW_INPUT_H
#define RAW_INPUT_H
#include "PreReq.h"
#include "Common.h"
#include "InputObject.h"
#include "Mouse.h"
#include "Keyboard.h"
namespace Input
{
class InputManager
{
public:
/**
* @return Returns an instance of the default input manager.
*/
static InputManager* Instance ();
/**
* @return Returns a new input manager. Should be destroyd with DestroyInputManager function.
*/
static InputManager* CreateInputManager ();
/**
* @return Destroys a input manager.
*/
static void DestroyInputManager (InputManager* inputSystem);
/**
* Creates a device
* @param inputType Which type of device to register
* @param targetApplication The target proccess that will proc input.
* @see InputDescription
* @return Returns a handle to a device that can be rethrown to a specific device.
*/
virtual InputObject* CreateDevice (const Enum::SAIType inputType, Typedefs::WindowHandle targetApplication = 0) = 0;
/** Enables or Disables the Input proccessing.
* @param The toggler.
*/
virtual void ToggleInputSystem (bool enable) = 0;
protected:
InputManager();
InputManager(const InputManager&) {}
const InputManager& operator=(const InputManager&) {return *this;}
virtual~InputManager();
virtual void Destroy() = 0;
};
}
#endif

View File

@ -0,0 +1,31 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef INPUT_INPUTOBJECT_H
#define INPUT_INPUTOBJECT_H
#include "Common.h"
namespace Input
{
class InputObject
{
public:
inline Enum::SAIType Type() { return type; }
virtual inline void Enable () { isEnabled = true; };
virtual inline void Disable () { isEnabled = false; };
protected:
InputObject(Enum::SAIType type) { this->type = type; }
virtual~InputObject() { }
private:
Enum::SAIType type;
protected:
bool isEnabled;
};
}
#endif // !INPUT_INPUTOBJECT_H

View File

@ -0,0 +1,213 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef INPUT_KEBOARD_H
#define INPUT_KEBOARD_H
#include "InputObject.h"
#include <vector>
namespace Input
{
//-----------------------------------------------------------------------------------------------------------------------------
namespace Enum
{
//! Contains keycodes (Enum::SAKI -> Super Awsome Key Input)
enum SAKI
{
SAKI_Backspace ,
SAKI_Tab ,
SAKI_Enter ,
SAKI_LeftShift ,
SAKI_RightShift ,
SAKI_LeftAlt ,
SAKI_RightAlt ,
SAKI_LeftCtrl ,
SAKI_RightCtrl ,
SAKI_Pause ,
SAKI_CapsLock ,
SAKI_Escape ,
SAKI_Space ,
SAKI_PgUp ,
SAKI_PgDown ,
SAKI_End ,
SAKI_Home ,
SAKI_Left ,
SAKI_Up ,
SAKI_Right ,
SAKI_Down ,
SAKI_PrintScreen ,
SAKI_Insert ,
SAKI_Delete ,
SAKI_0 ,
SAKI_1 ,
SAKI_2 ,
SAKI_3 ,
SAKI_4 ,
SAKI_5 ,
SAKI_6 ,
SAKI_7 ,
SAKI_8 ,
SAKI_9 ,
SAKI_A ,
SAKI_B ,
SAKI_C ,
SAKI_D ,
SAKI_E ,
SAKI_F ,
SAKI_G ,
SAKI_H ,
SAKI_I ,
SAKI_J ,
SAKI_K ,
SAKI_L ,
SAKI_M ,
SAKI_N ,
SAKI_O ,
SAKI_P ,
SAKI_Q ,
SAKI_R ,
SAKI_S ,
SAKI_T ,
SAKI_U ,
SAKI_V ,
SAKI_W ,
SAKI_X ,
SAKI_Y ,
SAKI_Z ,
SAKI_LeftWindows ,
SAKI_RightWindows ,
SAKI_Numpad0 ,
SAKI_Numpad1 ,
SAKI_Numpad2 ,
SAKI_Numpad3 ,
SAKI_Numpad4 ,
SAKI_Numpad5 ,
SAKI_Numpad6 ,
SAKI_Numpad7 ,
SAKI_Numpad8 ,
SAKI_Numpad9 ,
SAKI_NumpadEnter ,
SAKI_NumpadMultiply ,
SAKI_NumpadPlus ,
SAKI_NumpadSubtract ,
SAKI_NumpadDecimal ,
SAKI_NumpadDivide ,
SAKI_F1 ,
SAKI_F2 ,
SAKI_F3 ,
SAKI_F4 ,
SAKI_F5 ,
SAKI_F6 ,
SAKI_F7 ,
SAKI_F8 ,
SAKI_F9 ,
SAKI_F10 ,
SAKI_F11 ,
SAKI_F12 ,
SAKI_F13 ,
SAKI_F14 ,
SAKI_F15 ,
SAKI_F16 ,
SAKI_F17 ,
SAKI_F18 ,
SAKI_F19 ,
SAKI_F20 ,
SAKI_F21 ,
SAKI_F22 ,
SAKI_F23 ,
SAKI_F24 ,
SAKI_Numlock ,
SAKI_ScrlLock ,
SAKI_VolumeMute,
SAKI_VolumeDown,
SAKI_VolumeUp,
SAKI_MediaNext,
SAKI_MediaPrev,
SAKI_MediaStop,
SAKI_MediaPlayPause,
SAKI_Unknown
};
}
//-----------------------------------------------------------------------------------------------------------------------------
namespace Typedefs
{
typedef void(*OnKeyPressCallback)(Enum::SAKI key, const wchar_t[40], Keyboard* sender);
typedef void(*OnKeyDownCallback)(Enum::SAKI key, const wchar_t[40], Keyboard* sender);
typedef void(*OnKeyReleaseCallback)(Enum::SAKI key, const wchar_t[40], Keyboard* sender);
}
//-----------------------------------------------------------------------------------------------------------------------------
class Keyboard :public InputObject
{
public:
class KeyboardEvent
{
public:
virtual void OnKeyPress(Enum::SAKI key, const wchar_t[40], Keyboard* sender) { }
virtual void OnKeyDown(Enum::SAKI key, const wchar_t[40], Keyboard* sender) { }
virtual void OnKeyRelease(Enum::SAKI key, const wchar_t[40], Keyboard* sender) { }
};
public: /* Manual check functions */
virtual bool IsKeyUp (Enum::SAKI key) = 0;
virtual bool IsKeyDown (Enum::SAKI key) = 0;
virtual const wchar_t* GetAsText(Enum::SAKI key) = 0;
public: /* global subscribe callback functions */
void AddOnKeyPressCallback (Typedefs::OnKeyPressCallback func);
void AddOnKeyDownCallback (Typedefs::OnKeyDownCallback func);
void AddOnKeyReleaseCallback (Typedefs::OnKeyReleaseCallback func);
void RemoveOnKeyPressCallback (Typedefs::OnKeyPressCallback func);
void RemoveOnKeyDownCallback (Typedefs::OnKeyDownCallback func);
void RemoveOnKeyReleaseCallback (Typedefs::OnKeyReleaseCallback func);
public:
void operator+= (KeyboardEvent* object);
void operator-= (KeyboardEvent* object);
protected:
Keyboard();
~Keyboard();
protected:
struct KeyboardCallbackList
{
enum CallbackDataType
{
CallbackDataType_OnPress,
CallbackDataType_OnDown,
CallbackDataType_OnRelease
} type;
union CallbackData
{
Typedefs::OnKeyPressCallback keyPressCallback;
Typedefs::OnKeyDownCallback keyDownCallback;
Typedefs::OnKeyReleaseCallback keyReleaseCallback;
CallbackData (){ memset(this, 0, sizeof(CallbackData)); }
CallbackData (Typedefs::OnKeyPressCallback o){ keyPressCallback = o; }
bool operator ==(CallbackData o){ return o.keyDownCallback == keyDownCallback; }
bool operator ==(Typedefs::OnKeyPressCallback o ){ return o == keyPressCallback; }
operator bool(){ return this->keyDownCallback != 0; }
} function;
KeyboardCallbackList *next;
KeyboardCallbackList(CallbackData func, CallbackDataType t) :function(func), next(0), type(t) { }
};
protected:
void ClearList(KeyboardCallbackList* first);
void AddToList(Keyboard::KeyboardCallbackList* first, KeyboardCallbackList::CallbackData data, KeyboardCallbackList::CallbackDataType type);
void RemoveFromList(KeyboardCallbackList* first, KeyboardCallbackList::CallbackData data);
bool ExistsInList(KeyboardCallbackList* first, KeyboardCallbackList::CallbackData data);
bool ExistsInList(std::vector<KeyboardEvent*>& list, KeyboardEvent* data);
protected:
std::vector<KeyboardEvent*> keyEventSubscrivers;
KeyboardCallbackList* callbackList;
};
}
#endif // !INPUT_KEBOARD_H

145
Code/Input/Include/Mouse.h Normal file
View File

@ -0,0 +1,145 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef INPUT_MOUSE_H
#define INPUT_MOUSE_H
#include "InputObject.h"
#include <vector>
namespace Input
{
//-----------------------------------------------------------------------------------------------------------------------------
namespace Enum
{
//! Contains keycodes (SAMI -> Sam Awsome Mouse Input)
enum SAMI
{
SAMI_MouseLeftBtn,
SAMI_MouseMiddleBtn,
SAMI_MouseRightBtn,
SAMI_MouseBtnX01,
SAMI_MouseBtnX02,
SAMI_MouseBtnX03,
SAMI_MouseBtnX04,
SAMI_MouseBtnX05,
SAMI_MouseBtnX06,
SAMI_MouseBtnX07,
SAMI_MouseBtnX08,
SAMI_MouseBtnX09,
SAMI_MouseBtnX10,
SAMI_MouseBtnX11,
SAMI_MouseBtnX12,
SAMI_MouseBtnX13,
SAMI_MouseBtnX14,
SAMI_MouseBtnX15,
SAMI_MouseBtnX16,
SAMI_MouseBtnX17,
SAMI_MouseBtnX18,
SAMI_MouseBtnX19,
SAMI_MouseBtnX20,
SAMI_Unknown,
};
}
//-----------------------------------------------------------------------------------------------------------------------------
namespace Typedefs
{
typedef void(*OnMousePressCallback)(Enum::SAMI btn, Mouse* sender);
typedef void(*OnMouseDownCallback)(Enum::SAMI btn, Mouse* sender);
typedef void(*OnMouseReleaseCallback)(Enum::SAMI btn, Mouse* sender);
typedef void(*OnMouseMoveCallback)(Struct::SAIPoint2D, Mouse* sender);
typedef void(*OnMouseScrollCallback)(int delta, Mouse* sender);
}
//-----------------------------------------------------------------------------------------------------------------------------
class Mouse :public InputObject
{
public:
class MouseEvent
{
public:
virtual void OnMousePress ( Enum::SAMI key, Mouse* sender ) { }
virtual void OnMouseDown ( Enum::SAMI key, Mouse* sender ) { }
virtual void OnMouseRelease ( Enum::SAMI key, Mouse* sender ) { }
virtual void OnMouseMove ( Struct::SAIPoint2D coordinate, Mouse* sender ) { }
virtual void OnMouseScroll ( int delta, Mouse* sender ) { }
};
public:
virtual bool IsBtnUp(Enum::SAMI key) = 0;
virtual bool IsBtnDown(Enum::SAMI key) = 0;
virtual int GetWheelDelta() = 0;
virtual Struct::SAIPoint2D GetPixelPosition(Struct::SAIPoint2D targetMem = Struct::SAIPoint2D()) = 0;
public:
void AddOnMousePressCallback( Typedefs::OnMousePressCallback func);
void AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func );
void AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func );
void AddOnMouseMoveCallback( Typedefs::OnMouseMoveCallback func );
void AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func );
void RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func);
void RemoveOnMouseDownCallback( Typedefs::OnMouseDownCallback func );
void RemoveOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func );
void RemoveOnMouseMoveCallback( Typedefs::OnMouseMoveCallback func );
void RemoveOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func );
void SetPixelPos(int x, int y);
void ToggleCursor(bool toggler);
private:
void operator+= (MouseEvent* object);
void operator-= (MouseEvent* object);
protected:
Mouse();
~Mouse();
protected:
struct MouseCallbackList
{
enum CallbackDataType
{
CallbackDataType_OnPress,
CallbackDataType_OnDown,
CallbackDataType_OnRelease,
CallbackDataType_OnMove,
CallbackDataType_OnScroll,
} type;
union CallbackData
{
Typedefs::OnMousePressCallback mousePressCallback;
Typedefs::OnMouseDownCallback mouseDownCallback;
Typedefs::OnMouseReleaseCallback mouseReleaseCallback;
Typedefs::OnMouseMoveCallback mouseMoveCallback;
Typedefs::OnMouseScrollCallback mouseScrollCallback;
void* dummy;
CallbackData (){ memset(this, 0, sizeof(CallbackData)); }
CallbackData (void* d){ dummy = d; }
bool operator ==(CallbackData o){ return o.dummy == dummy; }
bool operator ==(void* o ){ return o == dummy; }
operator bool(){ return this->dummy != 0; }
} function;
MouseCallbackList *next;
MouseCallbackList(CallbackData func, CallbackDataType t) :function(func), next(0), type(t) { }
};
protected:
void ClearList(MouseCallbackList* first);
void AddToList(MouseCallbackList* first, MouseCallbackList::CallbackData data, MouseCallbackList::CallbackDataType type);
void RemoveFromList(MouseCallbackList* first, MouseCallbackList::CallbackData data);
bool ExistsInList(MouseCallbackList* first, MouseCallbackList::CallbackData data);
bool ExistsInList(std::vector<MouseEvent*>& list, MouseEvent* data);
protected:
std::vector<MouseEvent*> mouseSubscribers;
MouseCallbackList* callbackList;
Struct::SAIPoint2D pixelPos;
bool isCurorLocked;
int wheelDelta;
};
}
#endif // !INPUT_MOUSE_H

View File

@ -0,0 +1,53 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef INPUT_PREREQ_H
#define INPUT_PREREQ_H
//-------------- Determine Compiler ---------------------------------
#if defined( _MSC_VER )
# define COMPILER_MSVC
#elif defined( __GNUC__ )
# if defined( __WIN32__ ) || defined( _WIN32 )
# define COMPILER_MINGW
# else
# define COMPILER_GCC
# endif
#elif defined( __BORLANDC__ )
# define COMPILER_BORLAND
#else
# error No Recognized Compiler!
#endif
// --------------- Determine Operating System Platform ---------------
#if defined( __WIN32__ ) || defined( _WIN32 )
# if defined ( _XBOX )
# define PLATFORM_XBOX
# else
# define PLATFORM_WIN32
# endif
#elif defined( __APPLE_CC__ ) // Apple OS X
// Device Simulator
# if __IPHONE_OS_VERSION_MIN_REQUIRED >= 20201 || __IPHONE_OS_VERSION_MIN_REQUIRED >= 20000
//# if __IPHONE_OS_VERSION_MIN_REQUIRED >= 30000 || __IPHONE_OS_VERSION_MIN_REQUIRED >= 30000
# define PLATFORM_IPHONE
# else
# define PLATFORM_APPLE
# endif
# define _INPUTExport __attribute__((visibility("default")))
#elif defined( __linux__ )
# define PLATFORM_LINUX
#else
# error Platform not supported!
#endif
//Is Processor 32 or 64 bits...
#if defined(__x86_64__)
# define PLATFORM_64
#else
# define PLATFORM_32
#endif
#endif // !INPUT_PREREQ_H

View File

@ -0,0 +1,109 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_GUARD_RAW_INPUT_H
#define INCLUDE_GUARD_RAW_INPUT_H
#include "..\InputManager.h"
#include "Win32Keyboard.h"
#include "Win32Mouse.h"
#include <vector>
#include <Windows.h>
#include <map>
/**
* TODO:
* 1. Cordinate system
* 1.1. Pixel cordinates
* 1.2. 0 - 1 cordinate
* 1.3. Origo in middle of the screen ( -1 to 1 )
*/
//RIDEV_INPUTSINK to receive all keyboard input regardless of focus
//dx = +2*(x/w) -1
//dx = -2*(y/h) +1
namespace Input
{
enum RawInput_Usage
{
RawInput_Usage_pointer = 1,
RawInput_Usage_mouse = 2,
RawInput_Usage_joystick = 4,
RawInput_Usage_gamepad = 5,
RawInput_Usage_keyboard = 6,
RawInput_Usage_keypad = 7,
RawInput_Usage_multiAxisController = 8,
RawInput_Usage_TabletPCcontrols = 9,
};
class Win32Input :public InputManager
{
// private:
// SubscribeList<INPUT_CALLBACK, const InputData*>* _procInput;
//
// bool _enabled;
// bool _mouseEnabled;
// bool _KeyboardEnabled;
// bool _exclusive;
// List<RawInputDeviceInstance> _deviceList;
//
// List<InputData> _mouseInput;
// List<InputData> _keyboardInput;
//
// HHOOK _msgHook;
//
// private:
// Win32Input ();
// ~Win32Input ();
//
// bool _addDevice (const RAWINPUTDEVICE* k, const int& count);
// RAWINPUT*_TranslateRawInput (LPARAM l);
// void _proccessRawMouseData (RAWMOUSE&);
// void _proccessRawKeyboardData (RAWKEYBOARD&);
//
// static LRESULT CALLBACK WM_INPUT_TRANSLATE (int nCode, WPARAM wParam, LPARAM lParam);
//
// public:
//
// static Win32Input* Self ();
// static void Destroy ();
//
// const wchar_t* Input_GetError () const;
//
// bool Input_AddDevice (IN const HWND& targetApplication);
// bool Input_AddDevice (IN const RAWINPUTDEVICE*, IN const int&);
//
// void Input_Subscribe (IN INPUT_CALLBACK fnc);
// void Input_Unsubscribe (IN INPUT_CALLBACK fnc);
//
// void Input_Disable ();
// void Input_Enable ();
public:
Win32Input();
virtual~Win32Input();
InputObject* CreateDevice(const Enum::SAIType inputType, Typedefs::WindowHandle targetApplication) override;
void ToggleInputSystem(bool enable) override;
void Destroy() override;
private:
std::vector<Win32Keyboard*> keyboard;
std::vector<Win32Mouse*> mouse;
bool enabled;
bool exclusive;
HWND targetHwin;
private:
static Win32Input* instance;
static void RawInputParser(HWND h, LPARAM l);
static LRESULT CALLBACK RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM l);
static void WindowActivate(bool activate);
};
}
#endif

View File

@ -0,0 +1,36 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef INPUT_KEYBOARD_H
#define INPUT_KEYBOARD_H
#include "..\Keyboard.h"
#include <Windows.h>
namespace Input
{
class Win32Keyboard :public Keyboard
{
public:
Win32Keyboard();
~Win32Keyboard();
bool IsKeyUp (Enum::SAKI key) override;
bool IsKeyDown (Enum::SAKI key) override;
const wchar_t* GetAsText(Enum::SAKI key) override;
void ProccessKeyboardData (bool isUp, Enum::SAKI key, unsigned int makeCode, bool isE0);
private:
struct Keys
{
bool isE0;
bool isDown;
unsigned int makecode;
};
static const int MAXKEYS = 256;
Keys keys[MAXKEYS];
};
}
#endif // !INPUT_KEYBOARD_H

View File

@ -0,0 +1,36 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef INPUT_WIN32MOUSE_H
#define INPUT_WIN32MOUSE_H
#include "..\Mouse.h"
#include <Windows.h>
namespace Input
{
class Win32Mouse :public Mouse
{
public:
Win32Mouse();
~Win32Mouse();
bool IsBtnUp(Enum::SAMI key) override;
bool IsBtnDown(Enum::SAMI key) override;
int GetWheelDelta() override;
Struct::SAIPoint2D GetPixelPosition(Struct::SAIPoint2D targetMem = Struct::SAIPoint2D()) override;
void ProccessMouseData (bool isDown, Enum::SAMI btn, int delta, Struct::SAIPoint2D velocity, unsigned int makeCode);
private:
struct Buttons
{
unsigned int makeCode;
bool isDown;
};
static const int MAXBUTTONS = 25;
Buttons buttons[25];
};
}
#endif // !INPUT_WIN32MOUSE_H

View File

@ -20,8 +20,23 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="L_inputClass.cpp" />
<ClCompile Include="Source\InputManager.cpp" />
<ClCompile Include="Source\Keyboard.cpp" />
<ClCompile Include="Source\Mouse.cpp" />
<ClCompile Include="Source\Win32\Win32Input.cpp" />
<ClCompile Include="Source\Win32\Win32Keyboard.cpp" />
<ClCompile Include="Source\Win32\Win32Mouse.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Include\Common.h" />
<ClInclude Include="Include\InputManager.h" />
<ClInclude Include="Include\InputObject.h" />
<ClInclude Include="Include\Keyboard.h" />
<ClInclude Include="Include\Mouse.h" />
<ClInclude Include="Include\PreReq.h" />
<ClInclude Include="Include\Win32\Win32Input.h" />
<ClInclude Include="Include\Win32\Win32Keyboard.h" />
<ClInclude Include="Include\Win32\Win32Mouse.h" />
<ClInclude Include="L_inputClass.h" />
</ItemGroup>
<PropertyGroup Label="Globals">

View File

@ -18,10 +18,55 @@
<ClCompile Include="L_inputClass.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\Win32\Win32Input.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\Win32\Win32Keyboard.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\Win32\Win32Mouse.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\InputManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\Keyboard.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\Mouse.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="L_inputClass.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Include\Win32\Win32Input.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Include\Win32\Win32Keyboard.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Include\Win32\Win32Mouse.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Include\Common.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Include\InputManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Include\InputObject.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Include\Keyboard.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Include\Mouse.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Include\PreReq.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -1,193 +0,0 @@
#include"RawInput.h"
//DefRawInputProc
//GetRawInputDeviceList
//GetRegisteredRawInputDevices
LRESULT CALLBACK RawInput::WM_INPUT_TRANSLATE (int nCode, WPARAM wParam, LPARAM lparam)
{
if (nCode < 0) return CallNextHookEx(RawInput::Self()->_msgHook, nCode, wParam, lparam);
MSG *m = (MSG*)lparam;
if(m->message == WM_INPUT)
{
RAWINPUT* raw = RawInput::Self()->_TranslateRawInput(m->lParam);
if(!raw) goto nextHook;
if(!RawInput::Self()->Self()->_enabled)
{
if(FAILED ( DefRawInputProc(&raw, 1, sizeof(RAWINPUTHEADER)) ) )
RawInput::Self()->_errorMsg = L"Failed to proccess default raw input";
goto _final;
}
// if(raw->header.dwType == RIM_TYPEMOUSE) RawInput::Self()->_idleMouseData.insert(raw->data.mouse);
//else if(raw->header.dwType == RIM_TYPEKEYBOARD) RawInput::Self()->_proccessRawKeyboardData(raw->data.keyboard);
_final:
//if(FAILED ( DefRawInputProc(&raw, 1, sizeof(RAWINPUTHEADER)) ) )
// RawInput::Self()->_errorMsg = L"Failed to proccess default raw input";
delete raw;
}
else if (m->message == WM_QUIT)
{
if(UnhookWindowsHookEx(RawInput::Self()->_msgHook) == FALSE)
{
RawInput::Self()->_errorMsg = L"Failed to unhook message hook!";
}
}
nextHook:
return CallNextHookEx(RawInput::Self()->_msgHook, nCode, wParam, lparam);
}
RAWINPUT* RawInput::_TranslateRawInput (LPARAM l)
{
//Get The size of the raw data buffer
UINT bufferSize;
GetRawInputData((HRAWINPUT)l, RID_INPUT, NULL, &bufferSize, sizeof(RAWINPUTHEADER));
if (bufferSize < 1)
{
//Something went wrong
RawInput::Self()->_errorMsg = L"Failed to read raw buffer data in input class";
return 0;
}
//Create and read the raw input data
LPBYTE rawBufferIn = new BYTE[bufferSize];
UINT readBytes = GetRawInputData((HRAWINPUT)l, RID_INPUT, rawBufferIn, &bufferSize, sizeof(RAWINPUTHEADER));
if ( readBytes != bufferSize )
{
RawInput::Self()->_errorMsg = L"Could not read raw input data";
delete [] rawBufferIn;
return 0;
}
return (RAWINPUT*)rawBufferIn;
}
void RawInput::_proccessRawKeyboardData (RAWKEYBOARD& k)
{
if(!this->_KeyboardEnabled) return;
//The key is released.
if(k.Flags == RI_KEY_BREAK || k.Flags == (RI_KEY_BREAK | RI_KEY_E0) || k.Flags == (RI_KEY_BREAK | RI_KEY_E1))
{
if(k.Message == WM_SYSKEYUP)
{
// if(k.VKey == VK_CONTROL) this->_procCollection.skd.ctrl = false;
//else if(k.VKey == VK_MENU) this->_procCollection.skd.alt = false;
//else if(k.VKey == VK_SHIFT) this->_procCollection.skd.shift = false;
}
else if(k.Message == WM_KEYUP)
{
//this->_procCollection.kd.key = (RIK)k.VKey;
//this->_procCollection.kd.released = true;
}
}
//The key is pressed.
else if (k.Flags == RI_KEY_MAKE || k.Flags == (RI_KEY_MAKE | RI_KEY_E0) || k.Flags == (RI_KEY_MAKE | RI_KEY_E1))
{
if(k.Message == WM_SYSKEYDOWN)
{
// if(k.VKey == VK_CONTROL) this->_procCollection.skd.ctrl = true;
//else if(k.VKey == VK_MENU) this->_procCollection.skd.alt = true;
//else if(k.VKey == VK_SHIFT) this->_procCollection.skd.shift = true;
}
else if(k.Message == WM_KEYDOWN)
{
//this->_procCollection.kd.key = (RIK)k.VKey;
//this->_procCollection.kd.released = false;
}
}
}
void RawInput::_proccessRawMouseData (RAWMOUSE& m)
{
if(!this->_mouseEnabled) return;
if(m.lLastX != 0 || m.lLastY != 0)
{
//this->_procCollection.mmd.MousePos_X += m.lLastX;
//this->_procCollection.mmd.MousePos_Y += m.lLastY;
}
if( m.usButtonFlags > 0 )
{
switch (m.usButtonFlags)
{
//Mouse button pressed
case RI_MOUSE_LEFT_BUTTON_DOWN:
case RI_MOUSE_RIGHT_BUTTON_DOWN:
case RI_MOUSE_MIDDLE_BUTTON_DOWN:
{
if(m.usButtonFlags == RI_MOUSE_LEFT_BUTTON_DOWN)
{
//MOUSE_INPUT_btnData.key = RIK_LeftBtn;
//LBTNDOWN = true;
}
else if(m.usButtonFlags == RI_MOUSE_MIDDLE_BUTTON_DOWN)
{
//MOUSE_INPUT_btnData.key = RIK_MiddleBtn;
//MBTNDOWN = true;
}
else if(m.usButtonFlags == RI_MOUSE_RIGHT_BUTTON_DOWN)
{
//MOUSE_INPUT_btnData.key = RIK_RightBtn;
//RBTNDOWN = true;
}
}
break;
//Mouse button Released
case RI_MOUSE_LEFT_BUTTON_UP:
case RI_MOUSE_RIGHT_BUTTON_UP:
case RI_MOUSE_MIDDLE_BUTTON_UP:
{
if(m.usButtonFlags == RI_MOUSE_LEFT_BUTTON_UP)
{
//MOUSE_INPUT_btnData.key = RIK_LeftBtn;
//LBTNDOWN = false;
}
else if(m.usButtonFlags == RI_MOUSE_MIDDLE_BUTTON_UP)
{
//MOUSE_INPUT_btnData.key = RIK_MiddleBtn;
//MBTNDOWN = false;
}
else if(m.usButtonFlags == RI_MOUSE_RIGHT_BUTTON_UP)
{
//MOUSE_INPUT_btnData.key = RIK_RightBtn;
//RBTNDOWN = false;
}
}
break;
case RI_MOUSE_WHEEL:
{
int d = ((int)m.usButtonData);
if(d > 120) d = -1;
else d = 1;
//this->_procCollection.wd = d;
}
break;
}
}
}

View File

@ -1,284 +0,0 @@
#include "InputController.h"
using namespace Oyster::Input;
namespace
{
bool keys[256] = {0};
bool prevs[256]= {0};
bool mouse[5] = {0};
bool mPrev[5] = {0};
int XPos,YPos,PrevX,PrevY,DeltaX,DeltaY;
}
void Controller::KeyPressed(const WPARAM &Key)
{
prevs[Key]=false;
keys[Key]=true;
}
void Controller::KeyReleased(const WPARAM &Key)
{
prevs[Key]=true;
keys[Key] = false;
}
bool Controller::isKeyDown(const WPARAM &Key)
{
return keys[Key];
}
bool Controller::isKeyPressed(const WPARAM &Key)
{
if(keys[Key] && !prevs[Key])
{
prevs[Key] = keys[Key];
return true;
}
return false;
}
bool Controller::isKeyReleased(const WPARAM &Key)
{
if(!keys[Key] && prevs[Key])
{
prevs[Key] = keys[Key];
return true;
}
return false;
}
void Controller::MouseBtnPressed(const WPARAM &btn)
{
switch(btn)
{
case MK_LBUTTON:
mouse[0] = true;
mPrev[0] = false;
break;
case MK_RBUTTON:
mouse[1] = true;
mPrev[1] = false;
break;
case MK_MBUTTON:
mouse[2] = true;
mPrev[2] = false;
break;
case MK_XBUTTON1:
mouse[3] = true;
mPrev[3] = false;
break;
case MK_XBUTTON2:
mouse[4] = true;
mPrev[4] = false;
break;
}
}
void Controller::MouseBtnReleased(const WPARAM &btn)
{
switch(btn)
{
case MK_LBUTTON:
mouse[0] = false;
mPrev[0] = true;
break;
case MK_RBUTTON:
mouse[1] = false;
mPrev[1] = true;
break;
case MK_MBUTTON:
mouse[2] = false;
mPrev[2] = true;
break;
case MK_XBUTTON1:
mouse[3] = false;
mPrev[3] = true;
break;
case MK_XBUTTON2:
mouse[4] = false;
mPrev[4] = true;
break;
}
}
bool Controller::isMouseBtnDown(const WPARAM &Btn)
{
switch(Btn)
{
case MK_LBUTTON:
return mouse[0];
case MK_RBUTTON:
return mouse[1];
case MK_MBUTTON:
return mouse[2];
case MK_XBUTTON1:
return mouse[3];
case MK_XBUTTON2:
return mouse[4];
}
return false;
}
bool Controller::isMouseBtnPressed(const WPARAM &Btn)
{
switch(Btn)
{
case MK_LBUTTON:
if(mouse[0] && !mPrev[0])
{
mPrev[0] = mouse[0];
return true;
}
return false;
case MK_RBUTTON:
if(mouse[1] && !mPrev[1])
{
mPrev[1] = mouse[1];
return true;
}
return false;
case MK_MBUTTON:
if(mouse[2] && !mPrev[2])
{
mPrev[2] = mouse[2];
return true;
}
return false;
case MK_XBUTTON1:
if(mouse[3] && !mPrev[3])
{
mPrev[3] = mouse[3];
return true;
}
return false;
case MK_XBUTTON2:
if(mouse[4] && !mPrev[4])
{
mPrev[4] = mouse[4];
return true;
}
return false;
}
return false;
}
bool Controller::isMouseBtnReleased(const WPARAM &Btn)
{
switch(Btn)
{
case MK_LBUTTON:
if(!mouse[0] && mPrev[0])
{
mPrev[0] = mouse[0];
return true;
}
return false;
case MK_RBUTTON:
if(!mouse[1] && mPrev[1])
{
mPrev[1] = mouse[1];
return true;
}
return false;
case MK_MBUTTON:
if(!mouse[2] && mPrev[2])
{
mPrev[2] = mouse[2];
return true;
}
return false;
case MK_XBUTTON1:
if(!mouse[3] && mPrev[3])
{
mPrev[3] = mouse[3];
return true;
}
return false;
case MK_XBUTTON2:
if(!mouse[4] && mPrev[4])
{
mPrev[4] = mouse[4];
return true;
}
return false;
}
return false;
}
void Controller::MouseMove(int x,int y)
{
PrevY = YPos;
PrevX = XPos;
XPos = x;
YPos = y;
DeltaY = YPos - PrevY;
DeltaX = XPos - PrevX;
}
int Controller::GetY()
{
return YPos;
}
int Controller::GetX()
{
return XPos;
}
float Controller::GetAnalogX()
{
float f = (float)XPos;
f /=( Window::Size.left/2);
return f;
}
float Controller::GetAnalogY()
{
float f = (float)YPos;
f /=( Window::Size.top/2);
return f;
}
int Controller::GetDeltaY()
{
return DeltaY;
}
int Controller::GetDeltaX()
{
return DeltaX;
}
void Controller::ResetDeltaX()
{
DeltaX = 0;
}
void Controller::ResetDeltaY()
{
DeltaY = 0;
}
void Controller::RestrictMouse(bool restrict)
{
Oyster::Window::CaptureMouse(restrict);
}
//sets x=0,y=0 to be the center oc the client area
void Controller::OrigoCenter()
{
int x = Window::Size.left/2;
int y = Window::Size.top/2;
Window::SetMouseOffset(-x,-y);
}
//default
void Controller::OrigoTopLeft()
{
Oyster::Window::SetMouseOffset(0,0);
}

View File

@ -1,63 +0,0 @@
#pragma once
#ifndef InputController_H
#define InputController_H
#include "../Window/Window.h"
//READ http://msdn.microsoft.com/en-us/library/windows/desktop/ms648380(v=vs.85).aspx#_win32_Confining_a_Cursor
namespace Oyster
{
class Window;
namespace Input
{
class Controller
{
friend class ::Oyster::Window;
private:
//Keybord events from Oyster::Window
static void KeyPressed(const WPARAM &Key);
//Keybord events from Oyster::Window
static void KeyReleased(const WPARAM &Key);
//Mouse events from Oyster::Window
static void MouseMove(int x,int y);
//Mouse events from Oyster::Window
static void MouseBtnPressed(const WPARAM &Btn);
static void MouseBtnReleased(const WPARAM &Btn);
public:
//Polling Functions
static bool isKeyDown(const WPARAM &Key);
static bool isKeyPressed(const WPARAM &Key);
static bool isKeyReleased(const WPARAM &Key);
static bool isMouseBtnDown(const WPARAM &Btn);
static bool isMouseBtnPressed(const WPARAM &Btn);
static bool isMouseBtnReleased(const WPARAM &Btn);
static int GetX();
static int GetY();
static float GetAnalogX();
static float GetAnalogY();
static int GetDeltaX();
static int GetDeltaY();
//Controll Functions
static void ResetDeltaX();
static void ResetDeltaY();
//off by default
static void RestrictMouse(bool b = true);
//sets x=0,y=0 to be the center oc the client area
static void OrigoCenter();
//default
static void OrigoTopLeft();
};
}
}
#endif

View File

@ -1,57 +0,0 @@
#include "RawInput_Impl.h"
void RawInput_Impl::Mouse_Show()
{
}
void RawInput_Impl::Mouse_Hide()
{
}
void RawInput_Impl::Mouse_Lock()
{
}
void RawInput_Impl::Mouse_Unlock()
{
}
void RawInput_Impl::Mouse_IsBtnPressed(IN RIK)
{
}
int RawInput_Impl::Mouse_WheelDelta()
{
return 0;
}
POINT RawInput_Impl::Mouse_Position()
{
POINT p = {0, 0};
//POINT p = { this->_activeInputData.data.MOUSE_DATA.MousePos_X, this->_activeInputData.data.MOUSE_DATA.MousePos_Y };
return p;
}
void RawInput::Mouse_Enable()
{
this->_mouseEnabled = true;
}
void RawInput::Mouse_Disable()
{
this->_mouseEnabled = false;
}
bool RawInput::Keyboard_KeyUp(IN RIK key)
{
return false
}
bool RawInput::Keyboard_KeyDown(IN RIK key)
{
return false;
}
void RawInput::Keyboard_Enable()
{
this->_KeyboardEnabled = true;
}
void RawInput::Keyboard_Disable()
{
this->_KeyboardEnabled = false;
}

View File

@ -1,142 +0,0 @@
#include "RawInput.h"
template<typename FNC, typename PARAM, typename OBJECT_PARAM>
void SUBSCRIBE(SubscribeList<FNC, PARAM>* l, FNC _fnc, OBJECT_PARAM p)
{
SubscribeList<FNC, PARAM>* t = new SubscribeList<FNC, PARAM>();
t->param = p;
t->fnc = _fnc;
t->next = l;
l = t;
}
template<typename FNC, typename PARAM>
void UNSUBSCRIBE(SubscribeList<FNC, PARAM>* l, FNC fnc)
{
SubscribeList<FNC, PARAM>* w = l;
SubscribeList<FNC, PARAM>* p = 0;
while (w)
{
if(w->fnc == fnc)
{
if(p)
p->next = w->next;
delete w;
w = 0;
}
else
{
p = w;
w = w->next;
}
}
}
void RawInput_Impl::Input_Subscribe (IN INPUT_CALLBACK fnc)
{
//SUBSCRIBE(this->_procInput, fnc, &this->_procCollection.id);
}
void RawInput_Impl::Input_Unsubscribe (IN INPUT_CALLBACK fnc)
{
//UNSUBSCRIBE(this->_procSystemKey, fnc);
}
/*
void RawInput::Subscribe (RAW_KEY_PROC fnc)
{
KeyboardProcList* t = new KeyboardProcList();
t->fnc = fnc;
t->next = 0;
KeyboardProcList* w = this->_keyProcList;
KeyboardProcList* prev = this->_keyProcList;
while (w)
{
prev = w;
w = w->next;
}
prev->next = t;
}
void RawInput::Subscribe (RAW_MOUSE_PROC fnc)
{
MouseProcList* t = new MouseProcList();
t->fnc = fnc;
t->next = 0;
MouseProcList* w = this->_mouseProcList;
MouseProcList* prev = this->_mouseProcList;
while (w)
{
prev = w;
w = w->next;
}
prev->next = t;
}
void RawInput::Unsubscribe (RAW_KEY_PROC fnc)
{
KeyboardProcList* w = this->_keyProcList;
KeyboardProcList* prev = 0;
while (w)
{
if(w->fnc == fnc)
{
if(prev)
prev->next = w->next;
delete w;
w = 0;
}
else
{
prev = w;
w = w->next;
}
}
}
void RawInput::Unsubscribe (RAW_MOUSE_PROC fnc)
{
MouseProcList* w = this->_mouseProcList;
MouseProcList* prev = 0;
while (w)
{
if(w->fnc == fnc)
{
if(prev)
prev->next = w->next;
delete w;
w = 0;
}
else
{
prev = w;
w = w->next;
}
}
}
*/

View File

@ -1,182 +0,0 @@
#include "RawInput_Impl.h"
#include <WindowsX.h>
#include <algorithm>
#include <ctime>
#include <fstream>
#include <iostream>
static RawInput_Impl* gInstance = 0;
template<typename FNC, typename PARAM> void DESTROY_LIST(SubscribeList<FNC, PARAM>* l)
{
SubscribeList<FNC, PARAM>* w = l;
SubscribeList<FNC, PARAM>* p = 0;
while (w)
{
p = w;
w = w->next;
delete p;
}
}
template<typename FNC, typename PARAM> void PROCESS_SUBSCRIBERS(SubscribeList<FNC, PARAM>* l)
{
while (l)
{
l->fnc(l->param);
l = l->next;
}
}
RawInput* RawInput::Self()
{
return (RawInput*)RawInput_Impl::Self();
}
void RawInput::Destroy()
{
RawInput::Destroy();
}
RawInput_Impl* RawInput_Impl::Self()
{
if(!gInstance)
gInstance = new RawInput_Impl();
return gInstance;
}
void RawInput_Impl::Destroy ()
{
/************************ Delete subscribers ****************************/
DESTROY_LIST(RawInput_Impl::Self()->_procInput);
/************************ Delete Other stuff ****************************/
ShowCursor(true);
RECT r;
GetWindowRect(GetDesktopWindow(), &r);
ClipCursor(&r);
/************************ Delete instance ****************************/
delete gInstance;
gInstance = NULL;
}
RawInput_Impl::RawInput_Impl ()
: _procInput(0)
, _enabled(1)
, _mouseEnabled(1)
, _KeyboardEnabled(1)
, _exclusive(0)
, _errorMsg(0)
, _msgHook(SetWindowsHookEx(WH_GETMESSAGE, WM_INPUT_TRANSLATE, (HINSTANCE)0, GetCurrentThreadId()))
{
if(!_msgHook) this->_errorMsg = L"Failed to initiate window message hook";
}
RawInput_Impl::~RawInput_Impl ()
{}
const wchar_t* RawInput_Impl::Input_GetError() const
{
return this->_errorMsg;
}
bool RawInput_Impl::Input_AddDevice(IN const HWND& targetApplication)
{
assert(targetApplication != 0);
static const UINT c = 2;
RAWINPUTDEVICE devices[c] =
{
{ 0x01, RawInput_Usage_keyboard, RIDEV_NOLEGACY, targetApplication },
{ 0x01, RawInput_Usage_mouse, RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE, targetApplication }
};
if(! _addDevice( devices , c ) ) return false;
ShowCursor(FALSE);
//RECT r;
//GetWindow
//GetWindowRect(
return true;
}
bool RawInput_Impl::Input_AddDevice(IN const RAWINPUTDEVICE* d, const int& count)
{
for (int i = 0; i < count; i++)
if(!d[i].hwndTarget)
{
this->_errorMsg = L"Must specify target application";
return false;
}
if(! _addDevice( d, count ) ) return false;
return true;
}
//RAWINPUTDEVICE d = { 0x01, type, RIDEV_REMOVE, NULL };
//this->_errorMsg = L"Failed to unregister device";
void RawInput_Impl::Input_Disable()
{
this->_enabled = false;
}
void RawInput_Impl::Input_Enable()
{
this->_enabled = true;
}
void RawInput_Impl::Input_Read()
{
//for (int i = 0; i < this->_idleKeyData.size(); i++)
// this->_proccessRawKeyboardData(this->_idleKeyData.pop());
//for (int i = 0; i < this->_idleMouseData.size(); i++)
// this->_proccessRawMouseData(this->_idleMouseData.pop());
//
//this->_idleKeyData.clear();
//this->_idleMouseData.clear();
}
bool RawInput_Impl::_addDevice (const RAWINPUTDEVICE* k, const int& count)
{
if(RegisterRawInputDevices(k, count, sizeof(RAWINPUTDEVICE)) == FALSE)
{
DWORD h = GetLastError();
this->_errorMsg = L"Failed to register device";
return false;
}
for (int q = 0; q < count; q++)
{
RawInputDeviceInstance i;
memcpy(&i.description, &k[q], sizeof(RAWINPUTDEVICE));
this->_deviceList.push(i);
}
return true;
}

View File

@ -1,256 +0,0 @@
#ifndef RAW_INPUT_H
#define RAW_INPUT_H
#include <Windows.h>
/*********************************************************************/
/***************************** Enumerations ******************************/
/*********************************************************************/
//! Contains keycodes
enum RIK
{
RIK_Backspace = 0x08,
RIK_Tab = 0x09,
RIK_Enter = 0x0D,
RIK_Shift = 0x10,
RIK_Ctrl = 0x11,
RIK_Alt = 0x12,
RIK_Pause = 0x13,
RIK_CapsLock = 0x14,
RIK_Escape = 0x1B,
RIK_Space = 0x20,
RIK_PgUp = 0x21,
RIK_PgDown = 0x22,
RIK_End = 0x23,
RIK_Home = 0x24,
RIK_Left = 0x25,
RIK_Up = 0x26,
RIK_Right = 0x27,
RIK_Down = 0x28,
RIK_PrintScreen = 0x2C,
RIK_Insert = 0x2D,
RIK_Delete = 0x2E,
RIK_0 = 0x30,
RIK_1 = 0x31,
RIK_2 = 0x32,
RIK_3 = 0x33,
RIK_4 = 0x34,
RIK_5 = 0x35,
RIK_6 = 0x36,
RIK_7 = 0x37,
RIK_8 = 0x38,
RIK_9 = 0x39,
RIK_A = 0x41,
RIK_B = 0x42,
RIK_C = 0x43,
RIK_D = 0x44,
RIK_E = 0x45,
RIK_F = 0x46,
RIK_G = 0x47,
RIK_H = 0x48,
RIK_I = 0x49,
RIK_J = 0x4A,
RIK_K = 0x4B,
RIK_L = 0x4C,
RIK_M = 0x4D,
RIK_N = 0x4E,
RIK_O = 0x4F,
RIK_P = 0x50,
RIK_Q = 0x51,
RIK_R = 0x52,
RIK_S = 0x53,
RIK_T = 0x54,
RIK_U = 0x55,
RIK_V = 0x56,
RIK_W = 0x57,
RIK_X = 0x58,
RIK_Y = 0x59,
RIK_Z = 0x5A,
RIK_LeftWindows = 0x5B,
RIK_RightWindows = 0x5C,
RIK_Numpad0 = 0x60,
RIK_Numpad1 = 0x61,
RIK_Numpad2 = 0x62,
RIK_Numpad3 = 0x63,
RIK_Numpad4 = 0x64,
RIK_Numpad5 = 0x65,
RIK_Numpad6 = 0x66,
RIK_Numpad7 = 0x67,
RIK_Numpad8 = 0x68,
RIK_Numpad9 = 0x69,
RIK_Multiply = 0x6A,
RIK_Plus = 0x6B,
RIK_Subtract = 0x6D,
RIK_Decimal = 0x6E,
RIK_Divide = 0x6F,
RIK_F1 = 0x70,
RIK_F2 = 0x71,
RIK_F3 = 0x72,
RIK_F4 = 0x73,
RIK_F5 = 0x74,
RIK_F6 = 0x75,
RIK_F7 = 0x76,
RIK_F8 = 0x77,
RIK_F9 = 0x78,
RIK_F10 = 0x79,
RIK_F11 = 0x7A,
RIK_F12 = 0x7B,
RIK_F13 = 0x7C,
RIK_F14 = 0x7D,
RIK_F15 = 0x7E,
RIK_F16 = 0x7F,
RIK_F17 = 0x80,
RIK_F18 = 0x81,
RIK_F19 = 0x82,
RIK_F20 = 0x83,
RIK_F21 = 0x84,
RIK_F22 = 0x85,
RIK_F23 = 0x86,
RIK_F24 = 0x87,
RIK_Numlock = 0x90,
RIK_ScrlLock = 0x91,
RIK_LeftShift = 0xA0,
RIK_RightShift = 0xA1,
RIK_LeftCtrl = 0xA2,
RIK_RightCtrl = 0xA3,
COUNT
};
enum RIM
{
RIM_LeftBtn = 0x02,
RIM_MiddleBtn = 0x10,
RIM_RightBtn = 0x04,
RIM_Scroll = 0x0400,
};
enum INPUT_ERROR_CODE
{
INPUT_ERROR_CODE_FAILED,
INPUT_ERROR_CODE_SUCCESS,
};
enum InputType
{
InputType_Keyboard,
InputType_Mouse,
InputType_HID,
};
enum MousePosition
{
MousePosition_GetClientMousePosition,
MousePosition_GetRelativeMousePosition,
MousePosition_GetRelativeMouseVelocity,
MousePosition_GetDesktopMousePosition,
};
/*********************************************************************/
/**************************************************************************/
/***************************** Typedefs ******************************/
/**************************************************************************/
struct RawMouseData
{
bool shift;
bool alt;
bool ctrl;
RIM key;
bool pressed;
int MousePos_X;
int MousePos_Y;
int delta;
};
struct RawKeyData
{
bool shift;
bool alt;
bool ctrl;
RIK key;
bool released;
};
struct RawInputData
{
InputType type;
union
{
RawMouseData MOUSE_DATA;
RawKeyData KEYBOARD_DATA;
RAWHID HID_DATA;
} data;
};
struct INPUT_DESC
{
HWND targetApplication; //!< The target proccess that will proc input.
bool manual; //!< Set this to true if you want to lock callback frequency by calling //!< @see Input_Frame()
};
typedef void(*INPUT_CALLBACK)(const RawInputData*);
/*********************************************************************/
class RawInput
{
public:
/**
* @return Returns a pointer to an instance of RawInput.
*/
static RawInput* Self ();
/**
* Destroys the RawInput singleton object.
*/
static void Destroy ();
/**
* Adds a standard device to start sending input
* @param desc Settings for the device to add
* @see INPUT_DESC
*/
virtual INPUT_ERROR_CODE AddDevice (const INPUT_DESC& desc) = 0;
virtual INPUT_ERROR_CODE AddDevice (const RAWINPUTDEVICE d[], IN const int count) = 0;
/**
* Registers a function to get callback events.
* @param fnc a function pointer to callback function.
* @param subscribe If this is set to false, the function will be removed from callback list.
*/
virtual void Subscribe (IN INPUT_CALLBACK fnc, bool subscribe = true) = 0;
/**
* Enables or Disables the input proccessing.
*/
virtual void Enable (bool enable) = 0;
//Proccess input
/**
* Notifies the subscribers if new input has arrived. If manual variable in structure
* @see INPUT_DESC is set to false this function call will be pointless.
*/
virtual void Frame () = 0;
virtual void Mouse_Show () = 0;
virtual void Mouse_Hide () = 0;
virtual void Mouse_Lock () = 0;
virtual void Mouse_Unlock () = 0;
virtual void Mouse_IsBtnPressed (IN RIK key) = 0;
virtual int Mouse_WheelDelta () = 0;
virtual POINT Mouse_Position () = 0;
virtual void Mouse_Enable () = 0;
virtual void Mouse_Disable () = 0;
virtual bool Keyboard_KeyUp (IN RIK key) = 0;
virtual bool Keyboard_KeyDown (IN RIK key) = 0;
virtual void Keyboard_Enable () = 0;
virtual void Keyboard_Disable () = 0;
virtual bool Query (RIM) = 0;
virtual bool Query (RIK) = 0;
};
#endif

View File

@ -1,104 +0,0 @@
#ifndef INCLUDE_GUARD_RAW_INPUT_H
#define INCLUDE_GUARD_RAW_INPUT_H
#include "RawInput.h"
#include "misc.h"
#include <vector>
/**
* TODO:
* 1. Origo in middle of the screen (-1 to 1)
*/
//dx = +2*(x/w) -1
//dx = -2*(y/h) +1
template<class FNC, class PARAM>
struct SubscribeList
{
FNC fnc;
PARAM param;
SubscribeList* next;
};
struct RawInputDeviceInstance
{
RAWINPUTDEVICE description;
};
enum RawInput_Usage
{
RawInput_Usage_pointer = 1,
RawInput_Usage_mouse = 2,
RawInput_Usage_joystick = 4,
RawInput_Usage_gamepad = 5,
RawInput_Usage_keyboard = 6,
RawInput_Usage_keypad = 7,
RawInput_Usage_multiAxisController = 8,
RawInput_Usage_TabletPCcontrols = 9,
};
class RawInput_Impl :public RawInput
{
private:
SubscribeList<INPUT_CALLBACK, const RawInputData*>* _procInput;
bool _enabled;
bool _mouseEnabled;
bool _KeyboardEnabled;
bool _exclusive;
const wchar_t* _errorMsg;
List<RawInputDeviceInstance> _deviceList;
List<RawInputData> _mouseInput;
List<RawInputData> _keyboardInput;
HHOOK _msgHook;
private:
RawInput_Impl ();
~RawInput_Impl ();
bool _addDevice (const RAWINPUTDEVICE* k, const int& count);
RAWINPUT*_TranslateRawInput (LPARAM l);
void _proccessRawMouseData (RAWMOUSE&);
void _proccessRawKeyboardData (RAWKEYBOARD&);
static LRESULT CALLBACK WM_INPUT_TRANSLATE (int nCode, WPARAM wParam, LPARAM lParam);
public:
static RawInput_Impl* Self ();
static void Destroy ();
const wchar_t* Input_GetError () const;
bool Input_AddDevice (IN const HWND& targetApplication);
bool Input_AddDevice (IN const RAWINPUTDEVICE*, IN const int&);
void Input_Subscribe (IN INPUT_CALLBACK fnc);
void Input_Unsubscribe (IN INPUT_CALLBACK fnc);
void Input_Disable ();
void Input_Enable ();
void Input_Read ();
void Mouse_Show ();
void Mouse_Hide ();
void Mouse_Lock ();
void Mouse_Unlock ();
void Mouse_IsBtnPressed (IN RIK);
int Mouse_WheelDelta ();
POINT Mouse_Position ();
void Mouse_Enable ();
void Mouse_Disable ();
bool Keyboard_KeyUp (IN RIK key);
bool Keyboard_KeyDown (IN RIK key);
void Keyboard_Enable ();
void Keyboard_Disable ();
};
#endif

View File

@ -0,0 +1,79 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "..\Include\InputManager.h"
#include "..\Include\PreReq.h"
//-- PLATFORM ----------------------------------------------------------------------------------------------------------------------------------//
//Bring in correct Input for current platform
#if defined PLATFORM_WIN32
# include "..\Include\Win32\Win32Input.h"
#elif defined PLATFORM_LINUX
# include "..\Include\Linux\LinuxInput.h"
#elif defined PLATFORM_APPLE
# include "..\Include\Mac\MacInput.h"
#elif defined PLATFORM_IPHONE
# include "..\Include\IPhone\iPhoneInput.h"
#elif defined PLATFORM_XBOX
# include "..\Include\XBox\XBoxInput.h"
#endif
//----------------------------------------------------------------------------------------------------------------------------------------------//
using namespace Input;
InputManager *defaultInstance = 0;
InputManager* CreateManager()
{
InputManager* obj = 0;
#if defined PLATFORM_WIN32
obj = new Win32Input();
#elif defined PLATFORM_XBOX
obj = new XBoxInput();
#elif defined PLATFORM_LINUX
obj = new LinuxInput();
#elif defined PLATFORM_APPLE
obj = new MacInput();
#elif defined PLATFORM_IPHONE
obj = new iPhoneInput();
#else
OIS_EXCEPT(L"No platform library.. check build platform defines!");
#endif
return obj;
}
//-- STATIC ------------------------------------------------------------------------------------------------------------------------------------//
InputManager* InputManager::Instance()
{
if(!defaultInstance)
{
defaultInstance = CreateManager();
}
return defaultInstance;
}
InputManager* InputManager::CreateInputManager()
{
return CreateManager();
}
void InputManager::DestroyInputManager(InputManager* inputSystem)
{
if(!inputSystem) return;
inputSystem->Destroy();
delete inputSystem;
inputSystem = 0;
}
//----------------------------------------------------------------------------------------------------------------------------------------------//
//-- PRIVATE ------------------------------------------------------------------------------------------------------------------------------------//
InputManager::InputManager()
{}
InputManager::~InputManager()
{}

View File

@ -0,0 +1,136 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "..\Include\Keyboard.h"
using namespace Input;
using namespace Input::Enum;
using namespace Input::Typedefs;
using namespace Input::Struct;
void Keyboard::ClearList(Keyboard::KeyboardCallbackList* first)
{
KeyboardCallbackList* w = first;
KeyboardCallbackList* removee = 0;
while (w)
{
removee = w;
w = w->next;
delete removee;
}
}
void Keyboard::AddToList(Keyboard::KeyboardCallbackList* first, KeyboardCallbackList::CallbackData data, KeyboardCallbackList::CallbackDataType type)
{
KeyboardCallbackList *w = first;
KeyboardCallbackList *prev = first;
while (w)
{ prev = w; w = w->next; }
KeyboardCallbackList::CallbackData f;
f = data;
prev->next = new KeyboardCallbackList(f, type);
}
void Keyboard::RemoveFromList(KeyboardCallbackList* first, KeyboardCallbackList::CallbackData data)
{
KeyboardCallbackList *w = first;
KeyboardCallbackList *prev = first;
while (w)
{
if(data == w->function)
{
KeyboardCallbackList *removee = w;
w = w->next;
prev->next = w;
delete removee;
break;
}
prev = w;
w = w->next;
}
}
bool Keyboard::ExistsInList(KeyboardCallbackList* first, KeyboardCallbackList::CallbackData data)
{
KeyboardCallbackList *w = first;
while (w)
{
if(data == w->function)
{
return true;
}
w = w->next;
}
return true;
}
bool Keyboard::ExistsInList(std::vector<KeyboardEvent*>& list, KeyboardEvent* data)
{
for (unsigned int i = 0; i < list.size(); i++)
{
if(list[i] == data)
return true;
}
return false;
}
Keyboard::Keyboard()
: InputObject(SAIType_Keyboard)
, callbackList(0)
{}
Keyboard::~Keyboard()
{
}
void Keyboard::AddOnKeyPressCallback (OnKeyPressCallback func)
{
KeyboardCallbackList::CallbackData d;
d.keyPressCallback = func;
if(!this->callbackList) this->callbackList = new KeyboardCallbackList(d, KeyboardCallbackList::CallbackDataType_OnPress);
else AddToList(this->callbackList, d, KeyboardCallbackList::CallbackDataType_OnPress);
}
void Keyboard::AddOnKeyDownCallback (OnKeyDownCallback func)
{
KeyboardCallbackList::CallbackData d;
d.keyDownCallback = func;
if(!this->callbackList) this->callbackList = new KeyboardCallbackList(d, KeyboardCallbackList::CallbackDataType_OnDown);
else AddToList(this->callbackList, d, KeyboardCallbackList::CallbackDataType_OnDown);
}
void Keyboard::AddOnKeyReleaseCallback (OnKeyReleaseCallback func)
{
KeyboardCallbackList::CallbackData d;
d.keyReleaseCallback = func;
if(!this->callbackList) this->callbackList = new KeyboardCallbackList(d, KeyboardCallbackList::CallbackDataType_OnRelease);
else AddToList(this->callbackList, d, KeyboardCallbackList::CallbackDataType_OnRelease);
}
void Keyboard::RemoveOnKeyPressCallback (OnKeyPressCallback func)
{
RemoveFromList(this->callbackList, func);
}
void Keyboard::RemoveOnKeyDownCallback (OnKeyDownCallback func)
{
RemoveFromList(this->callbackList, func);
}
void Keyboard::RemoveOnKeyReleaseCallback (OnKeyReleaseCallback func)
{
RemoveFromList(this->callbackList, func);
}
void Keyboard::operator+= (KeyboardEvent* object)
{
if(ExistsInList(this->keyEventSubscrivers, object)) return;
this->keyEventSubscrivers.push_back(object);
}
void Keyboard::operator-= (KeyboardEvent* object)
{
int i = -1;
if((i = ExistsInList(this->keyEventSubscrivers, object)))
{
std::swap(this->keyEventSubscrivers[i], this->keyEventSubscrivers[this->keyEventSubscrivers.size() - 1]);
this->keyEventSubscrivers.resize(this->keyEventSubscrivers.size() - 1);
}
}

176
Code/Input/Source/Mouse.cpp Normal file
View File

@ -0,0 +1,176 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "..\Include\Mouse.h"
#include <vector>
using namespace Input;
using namespace Input::Enum;
using namespace Input::Struct;
using namespace Input::Typedefs;
void Mouse::ClearList(Mouse::MouseCallbackList* first)
{
MouseCallbackList* w = first;
MouseCallbackList* removee = 0;
while (w)
{
removee = w;
w = w->next;
delete removee;
}
}
void Mouse::AddToList(Mouse::MouseCallbackList* first, MouseCallbackList::CallbackData data, MouseCallbackList::CallbackDataType type)
{
MouseCallbackList *w = first;
MouseCallbackList *prev = first;
while (w)
{ prev = w; w = w->next; }
MouseCallbackList::CallbackData f;
f = data;
prev->next = new MouseCallbackList(f, type);
}
void Mouse::RemoveFromList(MouseCallbackList* first, MouseCallbackList::CallbackData data)
{
MouseCallbackList *w = first;
MouseCallbackList *prev = first;
while (w)
{
if(data == w->function)
{
MouseCallbackList *removee = w;
w = w->next;
prev->next = w;
delete removee;
break;
}
prev = w;
w = w->next;
}
}
bool Mouse::ExistsInList(MouseCallbackList* first, MouseCallbackList::CallbackData data)
{
MouseCallbackList *w = first;
while (w)
{
if(data == w->function)
{
return true;
}
w = w->next;
}
return true;
}
bool Mouse::ExistsInList(std::vector<MouseEvent*>& list, MouseEvent* data)
{
for (unsigned int i = 0; i < list.size(); i++)
{
if(list[i] == data)
return true;
}
return false;
}
Mouse::Mouse()
: InputObject(Input::Enum::SAIType_Mouse)
, callbackList(0)
, wheelDelta(0)
, isCurorLocked(0)
, pixelPos()
{
}
Mouse::~Mouse()
{
}
void Mouse::AddOnMousePressCallback( Typedefs::OnMousePressCallback func)
{
MouseCallbackList::CallbackData d;
d.mousePressCallback = func;
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease);
}
void Mouse::AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func )
{
MouseCallbackList::CallbackData d;
d.mouseDownCallback = func;
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease);
}
void Mouse::AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func )
{
MouseCallbackList::CallbackData d;
d.mouseReleaseCallback = func;
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease);
}
void Mouse::AddOnMouseMoveCallback( Typedefs::OnMouseMoveCallback func )
{
MouseCallbackList::CallbackData d;
d.mouseMoveCallback = func;
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease);
}
void Mouse::AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func )
{
MouseCallbackList::CallbackData d;
d.mouseScrollCallback = func;
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease);
}
void Mouse::RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func)
{
RemoveFromList(this->callbackList, func);
}
void Mouse::RemoveOnMouseDownCallback( Typedefs::OnMouseDownCallback func )
{
RemoveFromList(this->callbackList, func);
}
void Mouse::RemoveOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func )
{
RemoveFromList(this->callbackList, func);
}
void Mouse::RemoveOnMouseMoveCallback( Typedefs::OnMouseMoveCallback func )
{
RemoveFromList(this->callbackList, func);
}
void Mouse::RemoveOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func )
{
RemoveFromList(this->callbackList, func);
}
void Mouse::SetPixelPos(int x, int y)
{
this->pixelPos.x = x;
this->pixelPos.y = y;
}
void Mouse::ToggleCursor(bool toggler)
{
this->isCurorLocked = toggler;
}
void Mouse::operator+= (MouseEvent* object)
{
if(ExistsInList(this->mouseSubscribers, object)) return;
this->mouseSubscribers.push_back(object);
}
void Mouse::operator-= (MouseEvent* object)
{
int i = -1;
if((i = ExistsInList(this->mouseSubscribers, object)))
{
std::swap(this->mouseSubscribers[i], this->mouseSubscribers[this->mouseSubscribers.size() - 1]);
this->mouseSubscribers.resize(this->mouseSubscribers.size() - 1);
}
}

View File

@ -0,0 +1,853 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "..\..\Include\Win32\Win32Input.h"
#include "..\..\Include\Keyboard.h"
#include <WindowsX.h>
#include <Windows.h>
#include <algorithm>
#include <ctime>
#include <fstream>
#include <iostream>
using namespace Input;
using namespace Input::Enum;
using namespace Input::Struct;
using namespace Input::Typedefs;
/*
bool Win32Input::Input_AddDevice(IN const HWND& targetApplication)
{
assert(targetApplication != 0);
static const UINT c = 2;
RAWINPUTDEVICE devices[c] =
{
{ 0x01, RawInput_Usage_keyboard, RIDEV_NOLEGACY, targetApplication },
{ 0x01, RawInput_Usage_mouse, RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE, targetApplication }
};
if(! _addDevice( devices , c ) ) return false;
ShowCursor(FALSE);
//RECT r;
//GetWindow
//GetWindowRect(
return true;
}
bool Win32Input::Input_AddDevice(IN const RAWINPUTDEVICE* d, const int& count)
{
for (int i = 0; i < count; i++)
if(!d[i].hwndTarget)
{
this->_errorMsg = L"Must specify target application";
return false;
}
if(! _addDevice( d, count ) ) return false;
return true;
}
//Win32InputDEVICE d = { 0x01, type, RIDEV_REMOVE, NULL };
//this->_errorMsg = L"Failed to unregister device";
void Win32Input::Input_Disable()
{
this->_enabled = false;
}
void Win32Input::Input_Enable()
{
this->_enabled = true;
}
void Win32Input::Input_Read()
{
//for (int i = 0; i < this->_idleKeyData.size(); i++)
// this->_proccessRawKeyboardData(this->_idleKeyData.pop());
//for (int i = 0; i < this->_idleMouseData.size(); i++)
// this->_proccessRawMouseData(this->_idleMouseData.pop());
//
//this->_idleKeyData.clear();
//this->_idleMouseData.clear();
}
bool Win32Input::_addDevice (const RAWINPUTDEVICE* k, const int& count)
{
if(RegisterRawInputDevices(k, count, sizeof(RAWINPUTDEVICE)) == FALSE)
{
DWORD h = GetLastError();
INPUT_EXCEPT( L"Failed to register device" );
return false;
}
for (int q = 0; q < count; q++)
{
RawInputDeviceInstance i;
memcpy(&i.description, &k[q], sizeof(RAWINPUTDEVICE));
this->_deviceList.push(i);
}
return true;
}
*/
Win32Input *Win32Input::instance = 0;
void MapKey(RAWKEYBOARD& rawKB, bool& out_isUp, SAKI& out_key, unsigned int& sCode, bool& isE0)
{
//------------------------------------------------------------------------------------//
// http://molecularmusings.wordpress.com/2011/09/05/properly-handling-keyboard-input/ //
//------------------------------------------------------------------------------------//
UINT virtualKey = rawKB.VKey;
UINT scanCode = rawKB.MakeCode;
UINT flags = rawKB.Flags;
if (virtualKey == 255)
{
// discard "fake keys" which are part of an escaped sequence
return;
}
else if (virtualKey == VK_SHIFT)
{
// correct left-hand / right-hand SHIFT
virtualKey = MapVirtualKey(scanCode, MAPVK_VSC_TO_VK_EX);
}
else if (virtualKey == VK_NUMLOCK)
{
// correct PAUSE/BREAK and NUM LOCK silliness, and set the extended bit
scanCode = (MapVirtualKey(virtualKey, MAPVK_VK_TO_VSC) | 0x100);
}
// e0 and e1 are escape sequences used for certain special keys, such as PRINT and PAUSE/BREAK.
// see http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
isE0 = ((flags & RI_KEY_E0) != 0);
const bool isE1 = ((flags & RI_KEY_E1) != 0);
if (isE1)
{
// for escaped sequences, turn the virtual key into the correct scan code using MapVirtualKey.
// however, MapVirtualKey is unable to map VK_PAUSE (this is a known bug), hence we map that by hand.
if (virtualKey == VK_PAUSE) scanCode = 0x45;
else scanCode = MapVirtualKey(virtualKey, MAPVK_VK_TO_VSC);
}
switch (virtualKey)
{
// right-hand CONTROL and ALT have their e0 bit set
case VK_CONTROL:
if (isE0) out_key = SAKI_RightCtrl;
else out_key = SAKI_LeftCtrl;
break;
case VK_MENU:
if (isE0) out_key = SAKI_RightAlt;
else out_key = SAKI_LeftAlt;
break;
// NUMPAD ENTER has its e0 bit set
case VK_RETURN:
if (isE0) out_key = SAKI_NumpadEnter;
break;
// the standard INSERT, DELETE, HOME, END, PRIOR and NEXT keys will always have their e0 bit set, but the
// corresponding keys on the NUMPAD will not.
case VK_INSERT:
if (!isE0) out_key = SAKI_Numpad0;
break;
case VK_DELETE:
if (!isE0) out_key = SAKI_NumpadDecimal;
break;
case VK_HOME:
if (!isE0) out_key = SAKI_Numpad7;
break;
case VK_END:
if (!isE0) out_key = SAKI_Numpad1;
break;
case VK_PRIOR:
if (!isE0) out_key = SAKI_Numpad9;
break;
case VK_NEXT:
if (!isE0) out_key = SAKI_Numpad3;
break;
// the standard arrow keys will always have their e0 bit set, but the
// corresponding keys on the NUMPAD will not.
case VK_LEFT:
if (!isE0) out_key = SAKI_Numpad4;
break;
case VK_RIGHT:
if (!isE0) out_key = SAKI_Numpad6;
break;
case VK_UP:
if (!isE0) out_key = SAKI_Numpad8;
break;
case VK_DOWN:
if (!isE0) out_key = SAKI_Numpad2;
break;
// NUMPAD 5 doesn't have its e0 bit set
case VK_CLEAR:
if (!isE0) out_key = SAKI_Numpad5;
break;
case 0x03 : //VK_CANCEL
break;
case 0x08 : //VK_BACK
out_key = SAKI_Backspace;
break;
case 0x09 : //VK_TAB
out_key = SAKI_Tab;
break;
case 0x10 : //VK_SHIFT
out_key = SAKI_LeftShift;
out_key = SAKI_RightShift;
break;
case 0x13 : //VK_PAUSE
out_key = SAKI_Pause;
break;
case 0x14 : //VK_CAPITAL
out_key = SAKI_CapsLock;
break;
case 0x15 : //VK_KANA
break;
case 0x1B : //VK_ESCAPE
out_key = SAKI_Escape;
break;
case 0x1C : //VK_CONVERT
break;
case 0x1D : //VK_NONCONVERT
break;
case 0x1E : //VK_ACCEPT
break;
case 0x1F : //VK_MODECHANGE
break;
case 0x20 : //VK_SPACE
out_key = SAKI_Space;
break;
case 0x29 : //VK_SELECT
break;
case 0x2A : //VK_PRINT
out_key = SAKI_PrintScreen;
break;
case 0x2B : //VK_EXECUTE
break;
case 0x2C : //VK_SNAPSHOT
break;
case 0x2F : //VK_HELP
break;
case 0x30 : //0 key
out_key = SAKI_0;
break;
case 0x31 : //1 key
out_key = SAKI_1;
break;
case 0x32 : //2 key
out_key = SAKI_2;
break;
case 0x33 : //3 key
out_key = SAKI_3;
break;
case 0x34 : //4 key
out_key = SAKI_4;
break;
case 0x35 : //5 key
out_key = SAKI_5;
break;
case 0x36 : //6 key
out_key = SAKI_6;
break;
case 0x37 : //7 key
out_key = SAKI_7;
break;
case 0x38 : //8 key
out_key = SAKI_8;
break;
case 0x39 : //9 key
out_key = SAKI_9;
break;
case 0x41 : //A key
out_key = SAKI_A;
break;
case 0x42 : //B key
out_key = SAKI_B;
break;
case 0x43 : //C key
out_key = SAKI_C;
break;
case 0x44 : //D key
out_key = SAKI_D;
break;
case 0x45 : //E key
out_key = SAKI_E;
break;
case 0x46 : //F key
out_key = SAKI_F;
break;
case 0x47 : //G key
out_key = SAKI_G;
break;
case 0x48 : //H key
out_key = SAKI_H;
break;
case 0x49 : //I key
out_key = SAKI_I;
break;
case 0x4A : //J key
out_key = SAKI_J;
break;
case 0x4B : //K key
out_key = SAKI_K;
break;
case 0x4C : //L key
out_key = SAKI_L;
break;
case 0x4D : //M key
out_key = SAKI_M;
break;
case 0x4E : //N key
out_key = SAKI_N;
break;
case 0x4F : //O key
out_key = SAKI_O;
break;
case 0x50 : //P key
out_key = SAKI_P;
break;
case 0x51 : //Q key
out_key = SAKI_Q;
break;
case 0x52 : //R key
out_key = SAKI_R;
break;
case 0x53 : //S key
out_key = SAKI_S;
break;
case 0x54 : //T key
out_key = SAKI_T;
break;
case 0x55 : //U key
out_key = SAKI_U;
break;
case 0x56 : //V key
out_key = SAKI_V;
break;
case 0x57 : //W key
out_key = SAKI_W;
break;
case 0x58 : //X key
out_key = SAKI_X;
break;
case 0x59 : //Y key
out_key = SAKI_Y;
break;
case 0x5A : //Z key
out_key = SAKI_Z;
break;
case 0x5B : //VK_LWIN
break;
case 0x5C : //VK_RWIN
break;
case 0x5D : //VK_APPS
break;
case 0x5F : //VK_SLEEP
break;
case 0x60 : //VK_NUMPAD0
out_key = SAKI_Numpad0;
break;
case 0x61 : //VK_NUMPAD1
out_key = SAKI_Numpad1;
break;
case 0x62 : //VK_NUMPAD2
out_key = SAKI_Numpad2;
break;
case 0x63 : //VK_NUMPAD3
out_key = SAKI_Numpad3;
break;
case 0x64 : //VK_NUMPAD4
out_key = SAKI_Numpad4;
break;
case 0x65 : //VK_NUMPAD5
out_key = SAKI_Numpad5;
break;
case 0x66 : //VK_NUMPAD6
out_key = SAKI_Numpad6;
break;
case 0x67 : //VK_NUMPAD7
out_key = SAKI_Numpad7;
break;
case 0x68 : //VK_NUMPAD8
out_key = SAKI_Numpad8;
break;
case 0x69 : //VK_NUMPAD9
out_key = SAKI_Numpad9;
break;
case 0x6A : //VK_MULTIPLY
out_key = SAKI_NumpadMultiply;
break;
case 0x6B : //VK_ADD
out_key = SAKI_NumpadPlus;
break;
case 0x6C : //VK_SEPARATOR
break;
case 0x6D : //VK_SUBTRACT
out_key = SAKI_NumpadSubtract;
break;
case 0x6E : //VK_DECIMAL
out_key = SAKI_NumpadDecimal;
break;
case 0x6F : //VK_DIVIDE
out_key = SAKI_NumpadDivide;
break;
case 0x70 : //VK_F1
out_key = SAKI_F1;
break;
case 0x71 : //VK_F2
out_key = SAKI_F2;
break;
case 0x72 : //VK_F3
out_key = SAKI_F3;
break;
case 0x73 : //VK_F4
out_key = SAKI_F4;
break;
case 0x74 : //VK_F5
out_key = SAKI_F5;
break;
case 0x75 : //VK_F6
out_key = SAKI_F6;
break;
case 0x76 : //VK_F7
out_key = SAKI_F7;
break;
case 0x77 : //VK_F8
out_key = SAKI_F8;
break;
case 0x78 : //VK_F9
out_key = SAKI_F9;
break;
case 0x79 : //VK_F10
out_key = SAKI_F10;
break;
case 0x7A : //VK_F11
out_key = SAKI_F11;
break;
case 0x7B : //VK_F12
out_key = SAKI_F12;
break;
case 0x7C : //VK_F13
out_key = SAKI_F13;
break;
case 0x7D : //VK_F14
out_key = SAKI_F14;
break;
case 0x7E : //VK_F15
out_key = SAKI_F15;
break;
case 0x7F : //VK_F16
out_key = SAKI_F16;
break;
case 0x80 : //VK_F17
out_key = SAKI_F17;
break;
case 0x81 : //VK_F18
out_key = SAKI_F18;
break;
case 0x82 : //VK_F19
out_key = SAKI_F19;
break;
case 0x83 : //VK_F20
out_key = SAKI_F20;
break;
case 0x84 : //VK_F21
out_key = SAKI_F21;
break;
case 0x85 : //VK_F22
out_key = SAKI_F22;
break;
case 0x86 : //VK_F23
out_key = SAKI_F23;
break;
case 0x87 : //VK_F24
out_key = SAKI_F24;
break;
case 0x90 : //VK_NUMLOCK
out_key = SAKI_Numlock;
break;
case 0x91 : //VK_SCROLL
out_key = SAKI_ScrlLock;
break;
case 0xA0 : //VK_LSHIFT
out_key = SAKI_LeftShift;
break;
case 0xA1 : //VK_RSHIFT
out_key = SAKI_RightShift;
break;
case 0xA2 : //VK_LCONTROL
out_key = SAKI_LeftCtrl;
break;
case 0xA3 : //VK_RCONTROL
out_key = SAKI_RightCtrl;
break;
case 0xA4 : //VK_LMENU
out_key = SAKI_LeftAlt;
break;
case 0xA5 : //VK_RMENU
out_key = SAKI_RightCtrl;
break;
case 0xAD : //VK_VOLUME_MUTE
out_key = SAKI_VolumeMute;
break;
case 0xAE : //VK_VOLUME_DOWN
out_key = SAKI_VolumeDown;
break;
case 0xAF : //VK_VOLUME_UP
out_key = SAKI_VolumeUp;
break;
case 0xB0 : //VK_MEDIA_NEXT_TRACK
out_key = SAKI_MediaNext;
break;
case 0xB1 : //VK_MEDIA_PREV_TRACK
out_key = SAKI_MediaPrev;
break;
case 0xB2 : //VK_MEDIA_STOP
out_key = SAKI_MediaStop;
break;
case 0xB3 : //VK_MEDIA_PLAY_PAUSE
out_key = SAKI_MediaPlayPause;
break;
case 0xBB://VK_OEM_PLUS
break;
case 0xBC://VK_OEM_COMMA
break;
case 0xBD://VK_OEM_MINUS
break;
case 0xBE://VK_OEM_PERIOD
break;
case 0xBA://VK_OEM_1
break;
case 0xBF://VK_OEM_2
break;
case 0xC0://VK_OEM_3
break;
case 0xDB://VK_OEM_4
break;
case 0xDC://VK_OEM_5
break;
case 0xDD://VK_OEM_6
break;
case 0xDE://VK_OEM_7
break;
case 0xDF://VK_OEM_8
break;
}
out_isUp = ((flags & RI_KEY_BREAK) != 0);
rawKB.MakeCode = scanCode;
sCode = scanCode;
}
void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Struct::SAIPoint2D& vel, unsigned int& mcode)
{
if(rawMouse.lLastX != 0 || rawMouse.lLastY != 0)
{
vel.x = rawMouse.lLastX;
vel.y = rawMouse.lLastY;
}
if( rawMouse.usButtonFlags > 0 )
{
//--------------------------------------------------------------------------------------
//Mouse button pressed
if(rawMouse.usButtonFlags == RI_MOUSE_LEFT_BUTTON_DOWN)
{
btn = SAMI_MouseLeftBtn;
isUp = false;
}
else if(rawMouse.usButtonFlags == RI_MOUSE_MIDDLE_BUTTON_DOWN)
{
btn = SAMI_MouseMiddleBtn;
isUp = false;
}
else if(rawMouse.usButtonFlags == RI_MOUSE_RIGHT_BUTTON_DOWN)
{
btn = SAMI_MouseRightBtn;
isUp = false;
}
//--------------------------------------------------------------------------------------
//Mouse button Released
else if(rawMouse.usButtonFlags == RI_MOUSE_LEFT_BUTTON_UP)
{
btn = SAMI_MouseLeftBtn;
isUp = true;
}
else if(rawMouse.usButtonFlags == RI_MOUSE_MIDDLE_BUTTON_UP)
{
btn = SAMI_MouseMiddleBtn;
isUp = true;
}
else if(rawMouse.usButtonFlags == RI_MOUSE_RIGHT_BUTTON_UP)
{
btn = SAMI_MouseRightBtn;
isUp = true;
}
//--------------------------------------------------------------------------------------
else if (rawMouse.usButtonFlags == RI_MOUSE_WHEEL)
{
delta = ((int)rawMouse.usButtonData);
if(delta > 120) delta = -1;
else delta = 1;
}
}
}
void Win32Input::RawInputParser(HWND h, LPARAM l)
{
//Get The size of the raw data buffer
UINT bufferSize;
GetRawInputData((HRAWINPUT)l, RID_INPUT, NULL, &bufferSize, sizeof(RAWINPUTHEADER));
if (bufferSize < 1)
{
return;
}
//Create and read the raw input data
LPBYTE rawBufferIn = new BYTE[bufferSize];
UINT readBytes = GetRawInputData((HRAWINPUT)l, RID_INPUT, rawBufferIn, &bufferSize, sizeof(RAWINPUTHEADER));
if ( readBytes != bufferSize )
{
delete [] rawBufferIn;
return;
}
RAWINPUT* raw = (RAWINPUT*)rawBufferIn;
if(!Win32Input::instance->enabled)
{
if(FAILED ( DefRawInputProc(&raw, 1, sizeof(RAWINPUTHEADER)) ) )
{
}
}
else
{
if(raw->header.dwType == RIM_TYPEMOUSE)
{
for (unsigned int i = 0; i < Win32Input::instance->mouse.size(); i++)
{
bool isUp = true;
Enum::SAMI btn = Enum::SAMI_Unknown;
int delta = 0;
Struct::SAIPoint2D vel;
unsigned int mcode = 0;
MapButton(raw->data.mouse, isUp, btn, delta, vel, mcode);
Win32Input::instance->mouse[i]->ProccessMouseData(isUp, btn, delta, vel, mcode);
}
}
else if(raw->header.dwType == RIM_TYPEKEYBOARD)
{
for (unsigned int i = 0; i < Win32Input::instance->keyboard.size(); i++)
{
bool isUp;
SAKI key = SAKI_Unknown;
unsigned int makeCode;
bool isE0;
MapKey(raw->data.keyboard, isUp, key, makeCode, isE0);
Win32Input::instance->keyboard[i]->ProccessKeyboardData(isUp, key, makeCode, isE0);
}
}
}
delete raw;
}
LRESULT CALLBACK Win32Input::RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM l)
{
switch (m)
{
case WM_INPUT:
Win32Input::instance->RawInputParser(h, l);
break;
case WM_ACTIVATE:
Win32Input::instance->WindowActivate((w == TRUE));
break;
case WM_CREATE:
Win32Input::instance->WindowActivate(true);
break;
}
return DefWindowProc(h, m, w, l);
}
void Win32Input::WindowActivate(bool activate)
{
if(activate)
{
ShowCursor(0);
}
else
{
ShowCursor(0);
}
}
Win32Input::Win32Input()
{
if(!this->instance)
{
this->instance = this;
}
WNDCLASSEXW wc;
wc.cbSize = sizeof(WNDCLASSEXW);
wc.hIconSm = NULL;
wc.style = NULL;
wc.lpfnWndProc = RawWindowCallback;
wc.cbClsExtra = NULL;
wc.cbWndExtra = NULL;
wc.hInstance = (HINSTANCE)GetModuleHandle(0);
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = L"RawInputCallbackFunc";
if( !RegisterClassExW(&wc) )
{ /*wrong*/ }
}
Win32Input::~Win32Input()
{}
InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowHandle targetApplication)
{
if(!this->instance->targetHwin)
{
this->targetHwin = CreateWindowExW( 0, L"RawInputCallbackFunc" , NULL, NULL, NULL, NULL, NULL,
NULL, (HWND)targetApplication, NULL, (HINSTANCE)GetModuleHandle(0), NULL );
}
InputObject* val = 0;
RAWINPUTDEVICE rid;
rid.usUsagePage = 0x01;
rid.hwndTarget = this->instance->targetHwin;
switch (inputType)
{
case SAIType_Keyboard:
{
rid.usUsage = RawInput_Usage_keyboard;
rid.dwFlags = RIDEV_NOLEGACY;
if(RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE)
{
Win32Keyboard* obj = new Win32Keyboard();
this->keyboard.push_back(obj);
val = obj;
}
else
{
return 0;
}
}
break;
case SAIType_Mouse:
{
rid.usUsage = RawInput_Usage_mouse;
rid.dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE;
if(RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE)
{
int i = 0;
val = (InputObject*)1;
Win32Mouse* obj = new Win32Mouse();
this->mouse.push_back(obj);
val = obj;
}
else
{
return 0;
}
}
break;
}
return val;
}
void Win32Input::ToggleInputSystem(bool enable)
{
this->enabled = enable;
}
void Win32Input::Destroy ()
{
ShowCursor(true);
RECT r;
GetWindowRect(GetDesktopWindow(), &r);
ClipCursor(&r);
for (unsigned int i = 0; i < this->keyboard.size(); i++)
{
delete this->keyboard[i];
}
for (unsigned int i = 0; i < this->mouse.size(); i++)
{
delete this->mouse[i];
}
this->mouse.resize(0);
this->keyboard.resize(0);
}
/* This method is used with hooks!
LRESULT CALLBACK RawInput::WM_INPUT_TRANSLATE (int nCode, WPARAM wParam, LPARAM lparam)
{
if (nCode < 0) return CallNextHookEx(RawInput::Self()->_msgHook, nCode, wParam, lparam);
MSG *m = (MSG*)lparam;
if(m->message == WM_INPUT)
{
RAWINPUT* raw = RawInput::Self()->_TranslateRawInput(m->lParam);
if(!raw) goto nextHook;
if(!RawInput::Self()->Self()->_enabled)
{
if(FAILED ( DefRawInputProc(&raw, 1, sizeof(RAWINPUTHEADER)) ) )
RawInput::Self()->_errorMsg = L"Failed to proccess default raw input";
goto _final;
}
// if(raw->header.dwType == RIM_TYPEMOUSE) RawInput::Self()->_idleMouseData.insert(raw->data.mouse);
//else if(raw->header.dwType == RIM_TYPEKEYBOARD) RawInput::Self()->_proccessRawKeyboardData(raw->data.keyboard);
_final:
//if(FAILED ( DefRawInputProc(&raw, 1, sizeof(RAWINPUTHEADER)) ) )
// RawInput::Self()->_errorMsg = L"Failed to proccess default raw input";
delete raw;
}
else if (m->message == WM_QUIT)
{
if(UnhookWindowsHookEx(RawInput::Self()->_msgHook) == FALSE)
{
RawInput::Self()->_errorMsg = L"Failed to unhook message hook!";
}
}
nextHook:
return CallNextHookEx(RawInput::Self()->_msgHook, nCode, wParam, lparam);
}
*/

View File

@ -0,0 +1,138 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "..\..\Include\Win32\Win32Keyboard.h"
#pragma warning ( disable : 4172 )
using namespace Input;
using namespace Input::Enum;
Win32Keyboard::Win32Keyboard()
{
memset(&this->keys[0], 0, sizeof(Win32Keyboard::Keys) * MAXKEYS);
}
Win32Keyboard::~Win32Keyboard()
{
}
bool Win32Keyboard::IsKeyUp (SAKI key)
{
return !this->keys[key].isDown;
}
bool Win32Keyboard::IsKeyDown (SAKI key)
{
return this->keys[key].isDown;
}
const wchar_t* Win32Keyboard::GetAsText(Enum::SAKI key)
{
if(Enum::SAKI_Unknown == key) return 0;
// getting a human-readable string
UINT temp = (this->keys[key].makecode << 16) | (this->keys[key].isE0 << 24);
wchar_t buff[56] = {0};
GetKeyNameTextW((LONG)temp, buff, 64);
return buff;
}
void Win32Keyboard::ProccessKeyboardData (bool isUp, SAKI key, unsigned int makeCode, bool isE0)
{
if(key == SAKI_Unknown) return;
//The key is released.
if(isUp)/*(k.Flags == RI_KEY_BREAK || k.Flags == (RI_KEY_BREAK | RI_KEY_E0) || k.Flags == (RI_KEY_BREAK | RI_KEY_E1))*/
{
if(key == SAKI_LeftAlt)
{ }
else if(key == SAKI_LeftCtrl)
{}
else if(key == SAKI_LeftShift)
{}
else if(key == SAKI_RightAlt)
{}
else if(key == SAKI_RightCtrl)
{}
else if(key == SAKI_RightShift)
{}
else
{
this->keys[key].isDown = false;
this->keys[key].isE0 = isE0;
this->keys[key].makecode = makeCode;
for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++)
{
if(this->keyEventSubscrivers[i])
{
this->keyEventSubscrivers[i]->OnKeyRelease(key, GetAsText(key), this);
}
}
KeyboardCallbackList *w = this->callbackList;
while (w)
{
if(w->function)
if (w->type == KeyboardCallbackList::CallbackDataType_OnRelease)
w->function.keyReleaseCallback(key, GetAsText(key), this);
w = w->next;
}
}
//this->_procCollection.kd.key = (RIK)k.VKey;
//this->_procCollection.kd.released = true;
}
//The key is pressed.
else /*if (k.Flags == RI_KEY_MAKE || k.Flags == (RI_KEY_MAKE | RI_KEY_E0) || k.Flags == (RI_KEY_MAKE | RI_KEY_E1))*/
{
if(key == SAKI_LeftAlt)
{}
else if(key == SAKI_LeftCtrl)
{}
else if(key == SAKI_LeftShift)
{}
else if(key == SAKI_RightAlt)
{}
else if(key == SAKI_RightCtrl)
{}
else if(key == SAKI_RightShift)
{}
else
{
if(this->keys[key].isDown)
{
for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++)
{
if(this->keyEventSubscrivers[i])
{
this->keyEventSubscrivers[i]->OnKeyDown(key, GetAsText(key), this);
}
}
KeyboardCallbackList *w = this->callbackList;
while (w)
{
if(w->function)
if (w->type == KeyboardCallbackList::CallbackDataType_OnDown)
w->function.keyDownCallback(key, GetAsText(key), this);
w = w->next;
}
}
else
{
this->keys[key].isDown = true;
this->keys[key].isE0 = isE0;
this->keys[key].makecode = makeCode;
for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++)
{
if(this->keyEventSubscrivers[i])
{
this->keyEventSubscrivers[i]->OnKeyPress(key, GetAsText(key), this);
}
}
KeyboardCallbackList *w = this->callbackList;
while (w)
{
if(w->function)
if (w->type == KeyboardCallbackList::CallbackDataType_OnPress)
w->function.keyPressCallback(key, GetAsText(key), this);
w = w->next;
}
}
}
}
}

View File

@ -0,0 +1,141 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "..\..\Include\Win32\Win32Mouse.h"
using namespace Input;
using namespace Input::Enum;
using namespace Input::Struct;
using namespace Input::Typedefs;
Win32Mouse::Win32Mouse()
{
memset(&this->buttons[0], 0, sizeof(Buttons) * MAXBUTTONS);
}
Win32Mouse::~Win32Mouse()
{
}
bool Win32Mouse::IsBtnUp(Enum::SAMI btn)
{
if(btn == SAMI_Unknown) return false;
return !this->buttons[btn].isDown;
}
bool Win32Mouse::IsBtnDown(Enum::SAMI btn)
{
if(btn == SAMI_Unknown) return false;
return this->buttons[btn].isDown;
}
int Win32Mouse::GetWheelDelta()
{
return this->wheelDelta;
}
Struct::SAIPoint2D Win32Mouse::GetPixelPosition(Struct::SAIPoint2D targetMem)
{
targetMem = this->pixelPos;
return targetMem;
}
void Win32Mouse::ProccessMouseData (bool isUp, Enum::SAMI btn, int delta, Struct::SAIPoint2D velocity, unsigned int makeCode)
{
if(velocity.Length() != 0)
{
this->pixelPos.x += velocity.x;
this->pixelPos.y += velocity.y;
for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++)
{
if(this->mouseSubscribers[i])
this->mouseSubscribers[i]->OnMouseMove(this->pixelPos, this);
}
MouseCallbackList *w = this->callbackList;
while (w)
{
if(w->function)
if (w->type == MouseCallbackList::CallbackDataType_OnMove)
w->function.mouseMoveCallback(this->pixelPos, this);
w = w->next;
}
}
if(delta != 0)
{
for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++)
{
if(this->mouseSubscribers[i])
this->mouseSubscribers[i]->OnMouseScroll(delta, this);
}
MouseCallbackList *w = this->callbackList;
while (w)
{
if(w->function)
if (w->type == MouseCallbackList::CallbackDataType_OnMove)
w->function.mouseScrollCallback(delta, this);
w = w->next;
}
}
if(btn == SAMI_Unknown) return;
this->buttons[btn].isDown = !isUp;
this->buttons[btn].makeCode = makeCode;
//The btn is released.
if(isUp)
{
for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++)
{
if(this->mouseSubscribers[i])
this->mouseSubscribers[i]->OnMouseRelease(btn, this);
}
MouseCallbackList *w = this->callbackList;
while (w)
{
if(w->function)
if (w->type == MouseCallbackList::CallbackDataType_OnRelease)
w->function.mouseReleaseCallback(btn, this);
w = w->next;
}
}
//The btn is pressed.
else
{
if(this->buttons[btn].isDown)
{
for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++)
{
if(this->mouseSubscribers[i])
this->mouseSubscribers[i]->OnMouseDown(btn, this);
}
MouseCallbackList *w = this->callbackList;
while (w)
{
if(w->function)
if (w->type == MouseCallbackList::CallbackDataType_OnDown)
w->function.mouseDownCallback(btn, this);
w = w->next;
}
}
else
{
for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++)
{
if(this->mouseSubscribers[i])
this->mouseSubscribers[i]->OnMousePress(btn, this);
}
MouseCallbackList *w = this->callbackList;
while (w)
{
if(w->function)
if (w->type == MouseCallbackList::CallbackDataType_OnPress)
w->function.mousePressCallback(btn, this);
w = w->next;
}
}
}
}

View File

@ -1,120 +0,0 @@
#ifndef MISC_H
#define MISC_H
#include <assert.h>
template<typename T>
class List
{
private:
class Node
{
public:
T value;
Node *next;
Node(T value){ this->value = value; this->next = NULL; }
~Node() {}
};
Node *first;
int nrOfNodes;
public:
List::List()
{
this->first = NULL;
this->nrOfNodes = 0;
}
List::~List()
{
Node *walker = this->first;
for(int i = 0; i<this->nrOfNodes; i++)
{
walker = walker->next;
delete this->first;
this->first = walker;
}
}
List& List::operator=(const List& origObj)
{
if(this->nrOfNodes > 0)
{
Node *walker = this->first;
for(int i = 0; i<this->nrOfNodes; i++)
{
walker = walker->next;
delete this->first;
this->first = walker;
}
}
this->nrOfNodes = 0;
if(origObj.nrOfNodes > 0)
{
Node *walker = origObj.first;
for(int i = 0; i<origObj.nrOfNodes; i++)
{
insertLast(walker->value);
walker = walker->next;
}
}
return *this;
}
void List::push(T value)
{
Node *e = new Node(value);
e->next = this->first;
this->first = e;
e = NULL;
this->nrOfNodes++;
}
T List::pop()
{
T removed;
memset(&removed, 0, sizeof(T));
if(this->nrOfNodes > 0)
{
Node *temp = first;
this->first = first->next;
memcpy(&removed, &temp->value, sizeof(T));
delete temp;
this->nrOfNodes--;
}
return removed;
}
int List::size() const
{
return this->nrOfNodes;
}
void clear()
{
Node *w = this->first;
Node *p = 0;
while (w)
{
p = w;
w = w->next;
delete p;
}
this->first = 0;
}
};
#endif