Input - Merged with old input stuff that caused errors

This commit is contained in:
dean11 2014-02-24 16:27:43 +01:00
commit b46b6525cd
11 changed files with 78 additions and 23 deletions

View File

@ -60,8 +60,8 @@ namespace DanBias
~DanBiasGamePrivateData() ~DanBiasGamePrivateData()
{ {
SafeDeleteInstance( this->sharedStateContent.mouseDevice ); //SafeDeleteInstance( this->sharedStateContent.mouseDevice );
SafeDeleteInstance( this->sharedStateContent.keyboardDevice ); //SafeDeleteInstance( this->sharedStateContent.keyboardDevice );
} }
} data; } data;
} }
@ -273,6 +273,9 @@ LRESULT CALLBACK WindowCallBack(HWND handle, UINT message, WPARAM wParam, LPARAM
case WM_DESTROY: case WM_DESTROY:
PostQuitMessage( 0 ); PostQuitMessage( 0 );
break; break;
case WM_INPUT:
message = 0;
break;
default: break; default: break;
} }

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<ShowAllFiles>false</ShowAllFiles> <ShowAllFiles>true</ShowAllFiles>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory> <LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>

View File

@ -161,7 +161,7 @@ void GamingUI::ReadKeyInput()
//send delta mouse movement //send delta mouse movement
{ {
static const float mouseSensitivity = Radian( 1.0f ); static const float mouseSensitivity = Radian( 1.0f );
::Input::Struct::SAIPoint2D deltaPos; ::Input::Struct::SAIPointFloat2D deltaPos;
this->mouseInput->GetDeltaPosition( deltaPos ); this->mouseInput->GetDeltaPosition( deltaPos );
this->camera->PitchDown( deltaPos.y * mouseSensitivity );; this->camera->PitchDown( deltaPos.y * mouseSensitivity );;

View File

@ -92,7 +92,7 @@ GameClientState::ClientState LanMenuState::Update( float deltaTime )
{ {
MouseInput mouseState; MouseInput mouseState;
{ {
::Input::Struct::SAIPoint2D pos; ::Input::Struct::SAIPointInt2D pos;
this->privData->mouseInput->GetPixelPosition( pos ); this->privData->mouseInput->GetPixelPosition( pos );
mouseState.x = pos.x; mouseState.x = pos.x;

View File

@ -63,7 +63,7 @@ GameClientState::ClientState LobbyAdminState::Update( float deltaTime )
{ {
MouseInput mouseState; MouseInput mouseState;
{ {
::Input::Struct::SAIPoint2D pos; ::Input::Struct::SAIPointInt2D pos;
this->privData->mouseInput->GetPixelPosition( pos ); this->privData->mouseInput->GetPixelPosition( pos );
mouseState.x = pos.x; mouseState.x = pos.x;

View File

@ -63,7 +63,7 @@ GameClientState::ClientState LobbyState::Update( float deltaTime )
{ {
MouseInput mouseState; MouseInput mouseState;
{ {
::Input::Struct::SAIPoint2D pos; ::Input::Struct::SAIPointInt2D pos;
this->privData->mouseInput->GetPixelPosition( pos ); this->privData->mouseInput->GetPixelPosition( pos );
mouseState.x = pos.x; mouseState.x = pos.x;

View File

@ -81,8 +81,8 @@ GameClientState::ClientState MainState::Update( float deltaTime )
{ {
MouseInput mouseState; MouseInput mouseState;
{ {
::Input::Struct::SAIPoint2D pos; ::Input::Struct::SAIPointFloat2D pos;
this->privData->mouseInput->GetPixelPosition( pos ); this->privData->mouseInput->GetNormalizedPosition( pos );
this->privData->mousePos.x = mouseState.x = pos.x; this->privData->mousePos.x = mouseState.x = pos.x;
this->privData->mousePos.y = mouseState.y = pos.y; this->privData->mousePos.y = mouseState.y = pos.y;

View File

@ -40,6 +40,7 @@ namespace Input
RAWINPUTDEVICE device; RAWINPUTDEVICE device;
Struct::SAIPointInt2D windowSize; Struct::SAIPointInt2D windowSize;
bool isActive; bool isActive;
Struct::SAIPointInt2D winCursPos;
}; };
} }

View File

@ -12,18 +12,45 @@
#include <Windows.h> #include <Windows.h>
#include "Include\Input.h" #include "Include\Input.h"
#include "..\WindowManager\WindowShell.h" #include "WindowShell.h"
using namespace std; using namespace std;
using namespace Input;
using namespace Input::Enum;
int main(int agrc, char*args) Input::Keyboard* keyboard = 0;
Input::Mouse* mouse = 0;
void KeyPress(Input::Enum::SAKI key, Input::Keyboard* sender)
{ {
WindowShell::CreateWin(WindowShell::WINDOW_INIT_DESC()); if(key == SAKI_A)
{
if(mouse->IsActive()) mouse->Deactivate();
else mouse->Activate();
Input::Keyboard* app = Input::InputManager::Instance()->CreateKeyboardDevice(); }
app->Deactivate(); }
void MouseVelocity(Input::Struct::SAIPointInt2D vel, Input::Mouse* sender)
{
int i = vel.Length();
if(abs(i) > 2)
i = 0;
}
int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow)
{
std::wstring text; std::wstring text;
app->BindTextTarget( &text );
WindowShell::CreateWin(WindowShell::WINDOW_INIT_DESC());
WindowShell::CreateConsoleWindow();
keyboard = Input::InputManager::Instance()->CreateKeyboardDevice(WindowShell::GetHWND());
mouse = Input::InputManager::Instance()->CreateMouseDevice(WindowShell::GetHWND());
mouse->AddOnMouseMoveVelocityCallback(MouseVelocity);
keyboard->BindTextTarget( &text );
keyboard->AddOnKeyPressCallback(KeyPress);
int oldLen = 0; int oldLen = 0;
while (WindowShell::Frame()) while (WindowShell::Frame())
@ -31,8 +58,11 @@ int main(int agrc, char*args)
if(text.length() != oldLen) if(text.length() != oldLen)
{ {
wprintf(text.c_str()); wprintf(text.c_str());
oldLen =text.length();
} }
} }
system("pause"); system("pause");
return cmdShow;
} }

View File

@ -17,6 +17,7 @@ using namespace Input::Struct;
using namespace Input::Typedefs; using namespace Input::Typedefs;
Win32Input *Win32Input::instance = 0; Win32Input *Win32Input::instance = 0;
TRACKMOUSEEVENT tme;
LRESULT Win32Input::RawInputParser(HWND h, LPARAM l) LRESULT Win32Input::RawInputParser(HWND h, LPARAM l)
{ {
@ -93,6 +94,18 @@ LRESULT CALLBACK Win32Input::RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM
break; break;
case WM_CREATE: case WM_CREATE:
Win32Input::instance->WindowActivate(true); Win32Input::instance->WindowActivate(true);
//tme.cbSize=sizeof(tme);
//tme.dwFlags=TME_HOVER;
//tme.hwndTrack=h;//hanlde of window you want the mouse over message for.
//tme.dwHoverTime=HOVER_DEFAULT;
//if(TrackMouseEvent(&tme) == FALSE)
//{ }
break;
case WM_MOUSEHOVER:
//val = 0;
break;
case WM_MOUSELEAVE:
//val = 0;
break; break;
} }
@ -100,14 +113,14 @@ LRESULT CALLBACK Win32Input::RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM
} }
void Win32Input::WindowActivate(bool activate) void Win32Input::WindowActivate(bool activate)
{ {
if(activate) //if(activate)
{ //{
ShowCursor(0); // ShowCursor(0);
} //}
else //else
{ //{
ShowCursor(1); // ShowCursor(1);
} //}
} }

View File

@ -145,6 +145,8 @@ void Win32Mouse::Deactivate ()
if(RegisterRawInputDevices(&d, 1, sizeof(RAWINPUTDEVICE))) if(RegisterRawInputDevices(&d, 1, sizeof(RAWINPUTDEVICE)))
{ {
this->isActive = false; this->isActive = false;
SetCursorPos(this->winCursPos.x, this->winCursPos.y);
ShowCursor(TRUE);
} }
} }
@ -219,6 +221,12 @@ bool Win32Mouse::Create()
if(RegisterRawInputDevices(&this->device, 1, sizeof(RAWINPUTDEVICE)) == TRUE) if(RegisterRawInputDevices(&this->device, 1, sizeof(RAWINPUTDEVICE)) == TRUE)
{ {
this->isActive = true; this->isActive = true;
POINT p;
GetCursorPos(&p);
this->winCursPos.x = p.x;
this->winCursPos.y = p.y;
ShowCursor(FALSE);
return true; return true;
} }