Merge branch 'New-inputsystem' of https://github.com/dean11/Danbias into Input

This commit is contained in:
Dennis Andersen 2014-02-25 00:08:11 +01:00
commit 56258e48c7
8 changed files with 347 additions and 19 deletions

View File

@ -697,7 +697,8 @@ Global
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Mixed Platforms.Build.0 = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Mixed Platforms.Build.0 = Release|Win32
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Win32.ActiveCfg = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Win32.ActiveCfg = Release|Win32
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Win32.Build.0 = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Win32.Build.0 = Release|Win32
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x64.ActiveCfg = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x64.ActiveCfg = Release|x64
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x64.Build.0 = Release|x64
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x86.ActiveCfg = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x86.ActiveCfg = Release|Win32
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x86.Build.0 = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x86.Build.0 = Release|Win32
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|Any CPU.ActiveCfg = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|Any CPU.ActiveCfg = Release|Win32
@ -714,7 +715,8 @@ Global
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Mixed Platforms.Build.0 = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Mixed Platforms.Build.0 = Release|Win32
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Win32.ActiveCfg = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Win32.ActiveCfg = Release|Win32
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Win32.Build.0 = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Win32.Build.0 = Release|Win32
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x64.ActiveCfg = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x64.Build.0 = Release|x64
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x86.Build.0 = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x86.Build.0 = Release|Win32
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.Debug|Any CPU.ActiveCfg = Debug|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.Debug|Any CPU.ActiveCfg = Debug|Win32
@ -731,7 +733,8 @@ Global
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|Mixed Platforms.Build.0 = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|Mixed Platforms.Build.0 = Release|Win32
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|Win32.ActiveCfg = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|Win32.ActiveCfg = Release|Win32
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|Win32.Build.0 = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|Win32.Build.0 = Release|Win32
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|x64.ActiveCfg = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|x64.ActiveCfg = Release|x64
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|x64.Build.0 = Release|x64
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|x86.ActiveCfg = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|x86.ActiveCfg = Release|Win32
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|x86.Build.0 = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|x86.Build.0 = Release|Win32
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.Release|Any CPU.ActiveCfg = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.Release|Any CPU.ActiveCfg = Release|Win32
@ -748,7 +751,8 @@ Global
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|Mixed Platforms.Build.0 = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|Mixed Platforms.Build.0 = Release|Win32
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|Win32.ActiveCfg = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|Win32.ActiveCfg = Release|Win32
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|Win32.Build.0 = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|Win32.Build.0 = Release|Win32
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|x64.ActiveCfg = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|x64.Build.0 = Release|x64
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|x86.Build.0 = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|x86.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection
@ -764,7 +768,6 @@ Global
{C83A6FAD-E71F-4B1E-9D63-E93E61DDC012} = {20720CA7-795C-45AD-A302-9383A6DD503A} {C83A6FAD-E71F-4B1E-9D63-E93E61DDC012} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{8690FDDF-C5B7-4C42-A337-BD5243F29B85} = {20720CA7-795C-45AD-A302-9383A6DD503A} {8690FDDF-C5B7-4C42-A337-BD5243F29B85} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{2A1BC987-AF42-4500-802D-89CD32FC1309} = {20720CA7-795C-45AD-A302-9383A6DD503A} {2A1BC987-AF42-4500-802D-89CD32FC1309} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{C4C76A8D-44C5-4452-9F61-39C7E01CBDB4} = {F156EEBC-0195-4020-8700-4433208DE12B} {C4C76A8D-44C5-4452-9F61-39C7E01CBDB4} = {F156EEBC-0195-4020-8700-4433208DE12B}
{3EA5F14D-2A71-4588-A69D-87C4571C580F} = {F156EEBC-0195-4020-8700-4433208DE12B} {3EA5F14D-2A71-4588-A69D-87C4571C580F} = {F156EEBC-0195-4020-8700-4433208DE12B}
{7E3990D2-3D94-465C-B58D-64A74B3ECF9B} = {1322B12B-5E37-448A-AAAF-F637460DCB23} {7E3990D2-3D94-465C-B58D-64A74B3ECF9B} = {1322B12B-5E37-448A-AAAF-F637460DCB23}

View File

@ -81,9 +81,6 @@ bool GameState::Init( SharedStateContent &shared )
gfxOp.GlobalTint = Math::Float3(1,1,1); gfxOp.GlobalTint = Math::Float3(1,1,1);
Graphics::API::SetOptions(gfxOp); Graphics::API::SetOptions(gfxOp);
//tell server ready
this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) );
// DEGUG KEYS // DEGUG KEYS
this->key_Reload_Shaders = false; this->key_Reload_Shaders = false;
this->key_Wireframe_Toggle = false; this->key_Wireframe_Toggle = false;
@ -105,6 +102,9 @@ bool GameState::Init( SharedStateContent &shared )
((RespawnUI*)respawnUI)->Init(); ((RespawnUI*)respawnUI)->Init();
((StatsUI*)statsUI)->Init(); ((StatsUI*)statsUI)->Init();
//tell server ready
this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) );
return true; return true;
} }

View File

@ -38,6 +38,10 @@ bool GamingUI::Init()
this->plane = new Plane_UI(L"box_tex.png", Float3(0.5f, 0.0f, 0.5f), Float2(0.3f, 0.1f)); this->plane = new Plane_UI(L"box_tex.png", Float3(0.5f, 0.0f, 0.5f), Float2(0.3f, 0.1f));
this->text = new Text_UI(L"hej", Float3(0.5f,0.0f,0.1f), Float2(0.1f,0.1f)); this->text = new Text_UI(L"hej", Float3(0.5f,0.0f,0.1f), Float2(0.1f,0.1f));
// setting input mode to all raw
this->keyboardInput->Activate();
this->mouseInput->Activate();
return true; return true;
} }
GameStateUI::UIState GamingUI::Update( float deltaTime ) GameStateUI::UIState GamingUI::Update( float deltaTime )

View File

@ -30,7 +30,8 @@ struct LanMenuState::MyData
NetworkClient *nwClient; NetworkClient *nwClient;
::Input::Mouse *mouseInput; ::Input::Mouse *mouseInput;
::Input::Keyboard *keyboardInput; ::Input::Keyboard *keyboardInput;
Graphics::API::Texture background; Float3 mousePos;
Graphics::API::Texture background, mouseCursor;
EventButtonCollection guiElements; EventButtonCollection guiElements;
TextField<LanMenuState*> *connectIP; TextField<LanMenuState*> *connectIP;
@ -58,6 +59,7 @@ bool LanMenuState::Init( SharedStateContent &shared )
this->privData->keyboardInput = shared.keyboardDevice; this->privData->keyboardInput = shared.keyboardDevice;
this->privData->background = Graphics::API::CreateTexture( L"color_white.png" ); this->privData->background = Graphics::API::CreateTexture( L"color_white.png" );
this->privData->mouseCursor = Graphics::API::CreateTexture( L"cursor_md.png" );
// create guiElements // create guiElements
this->privData->connectIP = new TextField<LanMenuState*>( L"color_white.png", Float4(1.0f), Float4(0.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None ); this->privData->connectIP = new TextField<LanMenuState*>( L"color_white.png", Float4(1.0f), Float4(0.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None );
@ -92,11 +94,11 @@ GameClientState::ClientState LanMenuState::Update( float deltaTime )
{ {
MouseInput mouseState; MouseInput mouseState;
{ {
::Input::Struct::SAIPointInt2D pos; ::Input::Struct::SAIPointFloat2D pos;
this->privData->mouseInput->GetPixelPosition( pos ); this->privData->mouseInput->GetNormalizedPosition( pos );
mouseState.x = pos.x; this->privData->mousePos.x = mouseState.x = pos.x;
mouseState.y = pos.y; this->privData->mousePos.y = mouseState.y = pos.y;
mouseState.mouseButtonPressed = this->privData->mouseInput->IsBtnDown( ::Input::Enum::SAMI_MouseLeftBtn ); mouseState.mouseButtonPressed = this->privData->mouseInput->IsBtnDown( ::Input::Enum::SAMI_MouseLeftBtn );
} }
EventHandler::Instance().Update( mouseState ); EventHandler::Instance().Update( mouseState );
@ -110,6 +112,7 @@ bool LanMenuState::Render( )
Graphics::API::StartGuiRender(); Graphics::API::StartGuiRender();
Graphics::API::RenderGuiElement( this->privData->mouseCursor, this->privData->mousePos, Float2(0.01f), Float4(1.0f) );
Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) ); Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) );
this->privData->guiElements.RenderTexture(); this->privData->guiElements.RenderTexture();

View File

@ -23,7 +23,8 @@ struct LobbyState::MyData
GameClientState::ClientState nextState; GameClientState::ClientState nextState;
NetworkClient *nwClient; NetworkClient *nwClient;
::Input::Mouse *mouseInput; ::Input::Mouse *mouseInput;
Graphics::API::Texture background; Float3 mousePos;
Graphics::API::Texture background, mouseCursor;;
EventButtonCollection guiElements; EventButtonCollection guiElements;
} privData; } privData;
@ -46,6 +47,7 @@ bool LobbyState::Init( SharedStateContent &shared )
this->privData->mouseInput = shared.mouseDevice; this->privData->mouseInput = shared.mouseDevice;
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
this->privData->mouseCursor = Graphics::API::CreateTexture( L"cursor_md.png" );
// create buttons // create buttons
ButtonRectangle<LobbyState*> *button; ButtonRectangle<LobbyState*> *button;
@ -63,11 +65,11 @@ GameClientState::ClientState LobbyState::Update( float deltaTime )
{ {
MouseInput mouseState; MouseInput mouseState;
{ {
::Input::Struct::SAIPointInt2D pos; ::Input::Struct::SAIPointFloat2D pos;
this->privData->mouseInput->GetPixelPosition( pos ); this->privData->mouseInput->GetNormalizedPosition( pos );
mouseState.x = pos.x; this->privData->mousePos.x = mouseState.x = pos.x;
mouseState.y = pos.y; this->privData->mousePos.y = mouseState.y = pos.y;
mouseState.mouseButtonPressed = this->privData->mouseInput->IsBtnDown( ::Input::Enum::SAMI_MouseLeftBtn ); mouseState.mouseButtonPressed = this->privData->mouseInput->IsBtnDown( ::Input::Enum::SAMI_MouseLeftBtn );
} }
EventHandler::Instance().Update( mouseState ); EventHandler::Instance().Update( mouseState );
@ -79,6 +81,7 @@ bool LobbyState::Render( )
Graphics::API::NewFrame(); Graphics::API::NewFrame();
Graphics::API::StartGuiRender(); Graphics::API::StartGuiRender();
Graphics::API::RenderGuiElement( this->privData->mouseCursor, this->privData->mousePos, Float2(0.01f), Float4(1.0f) );
Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) ); Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) );
this->privData->guiElements.RenderTexture(); this->privData->guiElements.RenderTexture();

View File

@ -98,7 +98,7 @@ bool MainState::Render()
Graphics::API::NewFrame(); Graphics::API::NewFrame();
Graphics::API::StartGuiRender(); Graphics::API::StartGuiRender();
Graphics::API::RenderGuiElement( this->privData->mouseCursor, this->privData->mousePos, Float2(0.1f), Float4(1.0f) ); Graphics::API::RenderGuiElement( this->privData->mouseCursor, this->privData->mousePos, Float2(0.01f), Float4(1.0f) );
Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 0.9f), Float2(1.0f), Float4(63.0f/255.0f,73.0f/255.0f,127.0f/255.0f,0.6f) ); Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 0.9f), Float2(1.0f), Float4(63.0f/255.0f,73.0f/255.0f,127.0f/255.0f,0.6f) );
this->privData->guiElements.RenderTexture(); this->privData->guiElements.RenderTexture();

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{32DD438B-8C9C-49EF-9EA5-EB48951D869A}</ProjectGuid>
<RootNamespace>Test</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,243 @@
#include <Windows.h>
const unsigned short raw_input_usage_keyboard = 6;
const unsigned short raw_input_usage_mouse = 2;
HWND winHandle;
bool isPointAndClickMode;
float normalizedMousePosX, normalizedMousePosY;
LRESULT CALLBACK RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM l);
LRESULT RawInputParser(HWND h, LPARAM l);
void Update( );
//int main()
int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow)
{
WNDCLASSEXW wc;
wc.cbSize = sizeof(WNDCLASSEXW);
wc.hIconSm = NULL;
wc.style = NULL;
wc.lpfnWndProc = RawWindowCallback;
wc.cbClsExtra = NULL;
wc.cbWndExtra = NULL;
wc.hInstance = hinst;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = L"RawInputTest";
if( !RegisterClassExW(&wc) )
{
const char *breakpoint = "";
}
winHandle = CreateWindowExW( 0, L"RawInputTest", L"RawInputTest", WS_OVERLAPPEDWINDOW | WS_CAPTION, 0, 0, 600, 400, NULL, NULL, hinst, NULL );
ShowWindow( winHandle, cmdShow );
if( !winHandle )
{
const char *breakpoint = "";
}
isPointAndClickMode = true;
normalizedMousePosX =
normalizedMousePosY = 0.5f;
MSG msg = {0};
while( true )
{
if( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
{
if (msg.message == WM_QUIT) break;
DispatchMessage(&msg);
}
else
{
Update();
}
}
return 0;
}
LRESULT CALLBACK RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM l)
{
LRESULT val = 0;
switch (m)
{
case WM_INPUT:
{
RawInputParser( h, l );
}
break;
case WM_KEYUP:
{
if( w == 16 )
{
const char *breakpoint = "";
RAWINPUTDEVICE rid;
rid.usUsagePage = 0x01;
rid.hwndTarget = winHandle;
rid.usUsage = raw_input_usage_keyboard;
rid.dwFlags = RIDEV_NOLEGACY;
if( RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == FALSE )
{
const char *breakpoint = "";
}
}
}
break;
case WM_RBUTTONUP:
{
const char *breakpoint = "";
RAWINPUTDEVICE rid;
rid.usUsagePage = 0x01;
rid.hwndTarget = winHandle;
rid.usUsage = raw_input_usage_mouse;
rid.dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE;
if( RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE )
{
ShowCursor( false );
isPointAndClickMode = false;
}
else
{
const char *breakpoint = "";
}
}
break;
case WM_ACTIVATE:
{
const char *breakpoint = "";
}
break;
break;
case WM_CREATE:
{
const char *breakpoint = "";
}
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default: break;
}
return DefWindowProc(h, m, w, l);
}
LRESULT 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 0; }
//Create and read the raw input data
LPBYTE rawBuffer = new BYTE[bufferSize];
UINT readBytes = GetRawInputData((HRAWINPUT)l, RID_INPUT, rawBuffer, &bufferSize, sizeof(RAWINPUTHEADER));
if ( readBytes != bufferSize )
{
delete [] rawBuffer;
return 0;
}
HRESULT result = 0;
RAWINPUT* raw = (RAWINPUT*)rawBuffer;
if( raw->header.dwType == RIM_TYPEKEYBOARD )
{
if( (raw->data.keyboard.Flags & RI_KEY_BREAK) && raw->data.keyboard.VKey == 16 )
{
const char *breakpoint = "";
RAWINPUTDEVICE rid;
rid.usUsagePage = 0x01;
rid.hwndTarget = NULL;
rid.usUsage = raw_input_usage_keyboard;
rid.dwFlags = RIDEV_REMOVE;
if( RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == FALSE )
{
const char *breakpoint = "";
}
}
}
else if( raw->header.dwType == RIM_TYPEMOUSE )
{
if( raw->data.mouse.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_UP )
{
const char *breakpoint = "";
RAWINPUTDEVICE rid;
rid.usUsagePage = 0x01;
rid.hwndTarget = NULL;
rid.usUsage = raw_input_usage_mouse;
rid.dwFlags = RIDEV_REMOVE;
if( RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE )
{
RECT winRect;
GetWindowRect( winHandle, &winRect );
SetCursorPos( (winRect.left + winRect.right) >> 1, (winRect.top + winRect.bottom) >> 1 );
isPointAndClickMode = true;
}
else
{
const char *breakpoint = "";
}
}
}
else result = DefRawInputProc(&raw, 1, sizeof(RAWINPUTHEADER));
delete [] rawBuffer;
return result;
}
void Update( )
{
if( isPointAndClickMode )
{
{ // Calculating and storing the normalizedMousePos values
POINT clientReach, clientCenter, mousePos;
RECT winRect, clientRect;
GetClientRect( winHandle, &clientRect );
GetWindowRect( winHandle, &winRect );
LONG borderThickness = (winRect.right - winRect.left - clientRect.right) >> 1;
clientReach.x = clientRect.right >> 1;
clientReach.y = clientRect.bottom >> 1;
clientCenter.x = (winRect.left + winRect.right) >> 1;
clientCenter.y = winRect.bottom - clientReach.y - borderThickness;
GetCursorPos( &mousePos );
normalizedMousePosX = ((float)(mousePos.x - clientCenter.x + clientReach.x)) / (float)clientRect.right;
normalizedMousePosY = ((float)(mousePos.y - clientCenter.y + clientReach.y)) / (float)clientRect.bottom;
}
// Check if normalizedMousePos intersects client surface [(0,0), (1,1)]
bool mouseIsNowWithinBounds = true;
if ( normalizedMousePosX < 0.0f ) mouseIsNowWithinBounds = false;
else if( normalizedMousePosX > 1.0f ) mouseIsNowWithinBounds = false;
else if( normalizedMousePosY < 0.0f ) mouseIsNowWithinBounds = false;
else if( normalizedMousePosY > 1.0f ) mouseIsNowWithinBounds = false;
// Detect onEnter or onExit case
static bool mouseWereWithinBounds = false;
if( mouseIsNowWithinBounds & !mouseWereWithinBounds )
{ // onEnter
ShowCursor( false );
mouseWereWithinBounds = mouseIsNowWithinBounds;
}
else if( !mouseIsNowWithinBounds & mouseWereWithinBounds )
{ // onExit
ShowCursor( true );
mouseWereWithinBounds = mouseIsNowWithinBounds;
}
}
}