New input - added new input and more menu stuff

This commit is contained in:
dean11 2014-02-25 14:25:54 +01:00
commit b4ad883472
18 changed files with 344 additions and 278 deletions

View File

@ -254,8 +254,8 @@ namespace DanBias
data.networkClient.Disconnect();
data.state = nullptr;
SafeDeleteInstance( data.sharedStateContent.network );
Input::InputManager::DestroyInputManager();
EventHandler::Instance().Clean();
Graphics::API::Clean();

View File

@ -78,7 +78,7 @@ namespace DanBias { namespace Client
{
::Oyster::Math::Float lineStep = this->fontHeight + this->lineSpacing;
::Oyster::Math::Float2 rowSize = ::Oyster::Math::Float2( this->size.x, this->fontHeight );
::Oyster::Math::Float3 fieldTopLeft = this->pos - Float3( this->size * 0.25f, 0.0f );
::Oyster::Math::Float3 fieldTopLeft = this->pos - Float3( this->size * 0.25f, 0.001f );
::Oyster::Math::Float3 topLeft = fieldTopLeft;
if( this->isBottomAligned )

View File

@ -87,6 +87,8 @@ bool GameState::Init( SharedStateContent &shared )
this->renderWhireframe = false;
// !DEGUG KEYS
shared.keyboardDevice->ReleaseTextTarget();
auto light = this->privData->lights->begin();
for( ; light != this->privData->lights->end(); ++light )
{

View File

@ -62,21 +62,21 @@ bool LanMenuState::Init( SharedStateContent &shared )
this->privData->mouseCursor = Graphics::API::CreateTexture( L"cursor_md.png" );
// 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"noedge-btn-ipfield.png", Float4(1.0f), Float4(1.0f), this, Float3(0.5f, 0.2f, 0.9f), Float2(0.5f, 0.05f), ResizeAspectRatio_Height );
this->privData->connectIP->ReserveLines( 1 );
this->privData->connectIP->AppendText( L"127.0.0.1" );
//this->privData->connectIP->AppendText( L"194.47.150.206" ); // HACK: connecting to Dennis's server
this->privData->connectIP->SetFontHeight( 0.08f );
this->privData->connectIP->SetFontHeight( 0.035f );
this->privData->connectIP->SetLineSpacing( 0.005f );
this->privData->connectIP->SetTopAligned();
this->privData->connectIP->SetBottomAligned();
this->privData->guiElements.AddButton( this->privData->connectIP );
ButtonRectangle<LanMenuState*> *guiElements;
guiElements = new ButtonRectangle<LanMenuState*>( L"color_white.png", L"Connect", Float4(1.0f),Float4(0.0f),Float4(0.0f),Float4(0.0f), OnButtonInteract_Connect, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None );
guiElements = new ButtonRectangle<LanMenuState*>( L"noedge-btn-join.png", L"", Float4(1.0f),Float4(1.0f),Float4(1.2f),Float4(1.5f), OnButtonInteract_Connect, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.5f, 0.18f), ResizeAspectRatio_None );
this->privData->guiElements.AddButton( guiElements );
guiElements = new ButtonRectangle<LanMenuState*>( L"color_white.png", L"Exit", Float4(1.0f),Float4(0.0f),Float4(0.0f),Float4(0.0f), OnButtonInteract_Exit, this, Float3(0.5f, 0.5f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None );
guiElements = new ButtonRectangle<LanMenuState*>( L"noedge-btn-back.png", L"", Float4(1.0f),Float4(1.0f),Float4(1.2f),Float4(1.5f), OnButtonInteract_Exit, this, Float3(0.5f, 0.8f, 0.5f), Float2(0.5f, 0.18f), ResizeAspectRatio_None );
this->privData->guiElements.AddButton( guiElements );
// bind guiElements collection to the singleton eventhandler

View File

@ -9,6 +9,7 @@
#include "EventHandler\EventHandler.h"
#include "Buttons\ButtonRectangle.h"
#include "Buttons\ButtonEllipse.h"
using namespace ::DanBias::Client;
using namespace ::Oyster;
@ -31,6 +32,7 @@ struct MainState::MyData
};
void OnButtonInteract_Create( Oyster::Event::ButtonEvent<MainState*>& e );
void OnButtonInteract_Settings( Oyster::Event::ButtonEvent<MainState*>& e );
void OnButtonInteract_Join( Oyster::Event::ButtonEvent<MainState*>& e );
void OnButtonInteract_Quit( Oyster::Event::ButtonEvent<MainState*>& e );
@ -57,18 +59,21 @@ bool MainState::Init( SharedStateContent &shared )
// create buttons
ButtonRectangle<MainState*> *button;
Float4 TextCol = Float4(1.0f,0.0f,1.0f,1.0f);
Float4 BackCol = Float4(1.0f,1.0f,1.0f,0.5f);
Float4 HoverCol = Float4(0.0f,1.0f,0.0f,1.0f);
Float4 PressCol = Float4(0.0f,0.0f,1.0f,1.0f);
Float4 TextCol = Float4(0.1f,0.1f,0.1f,1.0f);
Float4 BackCol = Float4(1.0f);
Float4 HoverCol = Float4(1.2f);
Float4 PressCol = Float4(1.5f);
button = new ButtonRectangle<MainState*>( L"color_white.png", L"Create",TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Create, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f));
//button = new ButtonRectangle<MainState*>( L"color_white.png", L"Create",TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Create, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f));
//this->privData->guiElements.AddButton( button );
button = new ButtonRectangle<MainState*>( L"noedge-btn-lan.png", L"", TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Join, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.5f, 0.18f));
this->privData->guiElements.AddButton( button );
button = new ButtonRectangle<MainState*>( L"color_white.png", L"Join", TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Join, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.1f));
button = new ButtonRectangle<MainState*>( L"noedge-btn-settings.png", L"", TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Settings, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.5f, 0.18f));
this->privData->guiElements.AddButton( button );
button = new ButtonRectangle<MainState*>( L"color_white.png", L"Quit", TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Quit, this, Float3(0.5f, 0.8f, 0.5f), Float2(0.3f, 0.1f));
button = new ButtonRectangle<MainState*>( L"noedge-btn-quit.png", L"", TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Quit, this, Float3(0.5f, 0.8f, 0.5f), Float2(0.5f, 0.18f));
this->privData->guiElements.AddButton( button );
// bind button collection to the singleton eventhandler
@ -99,7 +104,7 @@ bool MainState::Render()
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, 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(0.0f, 0.0f, 0.0f, 1.0f) );
this->privData->guiElements.RenderTexture();
Graphics::API::StartTextRender();
@ -139,6 +144,17 @@ void OnButtonInteract_Create( Oyster::Event::ButtonEvent<MainState*>& e )
}
}
void OnButtonInteract_Settings( Oyster::Event::ButtonEvent<MainState*>& e )
{
switch( e.state )
{
case ButtonState_Released:
//e.owner->ChangeState( GameClientState::ClientState_LobbyCreate );
break;
default: break;
}
}
void OnButtonInteract_Join( Oyster::Event::ButtonEvent<MainState*>& e )
{
switch( e.state )

View File

@ -1,36 +0,0 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dan Andersson] [2014]
/////////////////////////////////////////////////////////////////////
#ifndef INPUT_APPLICATION_KEBOARD_H
#define INPUT_APPLICATION_KEBOARD_H
#include "InputObject.h"
#include <string>
namespace Input
{
class ApplicationKeyboard : public InputObject
{
public:
virtual ~ApplicationKeyboard();
bool IsActive() const;
void Activate();
void Deactivate();
void BindTextTarget( ::std::wstring *field );
void ReleaseTextTarget();
protected:
::std::wstring *textTarget;
::std::wstring::size_type writePos;
ApplicationKeyboard();
private:
bool active;
};
}
#endif // !INPUT_KEBOARD_H

View File

@ -21,22 +21,17 @@ namespace Input
{
SAIType_Keyboard,
SAIType_Mouse,
//SAIType_ApplicationKeyboard,
SAIType_futureExample1,
SAIType_futureExample2,
SAIType_futureExample3,
};
enum InputOptionType
{
InputOptionType_RawInput,
InputOptionType_PlatformDefault,
};
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!
ButtonState_Unknown,
};
}
/*********************************************************************/

View File

@ -26,7 +26,7 @@ namespace Input
static InputManager* CreateInputManager ();
/**
* @return Destroy default input manager.
* @return Destroys the default input manager.
*/
static void DestroyInputManager ();

View File

@ -135,11 +135,23 @@ namespace Input
};
}
//-----------------------------------------------------------------------------------------------------------------------------
namespace Struct
{
struct KeyboardEventData
{
Enum::SAKI key;
Enum::ButtonState state;
Keyboard* sender;
void* tag;
};
}
//-----------------------------------------------------------------------------------------------------------------------------
namespace Typedefs
{
typedef void(*OnKeyPressCallback)(Enum::SAKI key, Keyboard* sender);
typedef void(*OnKeyDownCallback)(Enum::SAKI key, Keyboard* sender);
typedef void(*OnKeyReleaseCallback)(Enum::SAKI key, Keyboard* sender);
typedef void(*OnKeyEventCallback) (const Struct::KeyboardEventData& eventData);
typedef void(*OnKeyPressCallback) (Enum::SAKI key, Keyboard* sender, void* tag);
typedef void(*OnKeyDownCallback) (Enum::SAKI key, Keyboard* sender, void* tag);
typedef void(*OnKeyReleaseCallback) (Enum::SAKI key, Keyboard* sender, void* tag);
}
//-----------------------------------------------------------------------------------------------------------------------------
@ -149,9 +161,10 @@ namespace Input
class KeyboardEvent
{
public:
virtual void OnKeyPress(Enum::SAKI key, Keyboard* sender) { }
virtual void OnKeyDown(Enum::SAKI key, Keyboard* sender) { }
virtual void OnKeyRelease(Enum::SAKI key, Keyboard* sender) { }
virtual void OnKeyEvent (const Struct::KeyboardEventData& eventData) { }
virtual void OnKeyPress (Enum::SAKI key, Keyboard* sender) { }
virtual void OnKeyDown (Enum::SAKI key, Keyboard* sender) { }
virtual void OnKeyRelease (Enum::SAKI key, Keyboard* sender) { }
};
public: /* Manual check functions */
@ -166,18 +179,25 @@ namespace Input
virtual void Deactivate () override = 0;
virtual bool IsActive() override = 0;
public: /* global subscribe callback functions */
void AddOnKeyPressCallback (Typedefs::OnKeyPressCallback func);
void AddOnKeyDownCallback (Typedefs::OnKeyDownCallback func);
void AddOnKeyReleaseCallback (Typedefs::OnKeyReleaseCallback func);
public: /* object subscribe functions */
void AddKeyboardEvent (KeyboardEvent* object);
void RemoveKeyboardEvent (KeyboardEvent* object);
void operator+= (KeyboardEvent* object);
void operator-= (KeyboardEvent* object);
public: /* global subscribe callback functions */
void AddOnKeyEventCallback (Typedefs::OnKeyEventCallback func, void* tag);
void AddOnKeyPressCallback (Typedefs::OnKeyPressCallback func, void* tag);
void AddOnKeyDownCallback (Typedefs::OnKeyDownCallback func, void* tag);
void AddOnKeyReleaseCallback (Typedefs::OnKeyReleaseCallback func, void* tag);
void RemoveOnKeyEventCallback (Typedefs::OnKeyEventCallback 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);
void BindTextTarget( ::std::wstring *field );
void ReleaseTextTarget();
@ -189,6 +209,7 @@ namespace Input
Keyboard();
protected: /* Internal event proc */
void InternalOnEvent(Struct::KeyboardEventData& data);
void InternalOnKeyPress(Enum::SAKI key);
void InternalOnKeyDown(Enum::SAKI key);
void InternalOnKeyRelease(Enum::SAKI key);
@ -199,7 +220,6 @@ namespace Input
::std::wstring* textTarget;
::std::wstring::size_type writePos;
bool active;
Enum::InputOptionType inputMode;
};
}

View File

@ -38,12 +38,30 @@ namespace Input
SAMI_MouseBtnX18,
SAMI_MouseBtnX19,
SAMI_MouseBtnX20,
SAMI_MouseMove,
SAMI_MouseScroll,
SAMI_Unknown,
};
}
//-----------------------------------------------------------------------------------------------------------------------------
namespace Struct
{
struct MouseEventData
{
Enum::SAMI type;
Enum::ButtonState buttonState;
Struct::SAIPointInt2D pixelPos;
Struct::SAIPointFloat2D normalizedPos;
Struct::SAIPointInt2D velocity;
Mouse* sender;
int scrollDelta;
void* tag;
};
}
//-----------------------------------------------------------------------------------------------------------------------------
namespace Typedefs
{
typedef void(*OnMouseCallback)( const Struct::MouseEventData& eventData );
typedef void(*OnMousePressCallback)(Enum::SAMI btn, Mouse* sender);
typedef void(*OnMouseDownCallback)(Enum::SAMI btn, Mouse* sender);
typedef void(*OnMouseReleaseCallback)(Enum::SAMI btn, Mouse* sender);
@ -60,6 +78,7 @@ namespace Input
class MouseEvent
{
public:
virtual void OnMouse ( const Struct::MouseEventData& eventData ) { }
virtual void OnMousePress ( Enum::SAMI key, Mouse* sender ) { }
virtual void OnMouseDown ( Enum::SAMI key, Mouse* sender ) { }
virtual void OnMouseRelease ( Enum::SAMI key, Mouse* sender ) { }
@ -82,13 +101,21 @@ namespace Input
virtual bool IsActive() override = 0;
public: /* global subscribe callback functions */
void AddOnMousePressCallback( Typedefs::OnMousePressCallback func);
void AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func );
void AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func );
void AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func );
void AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func );
void AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func );
void AddMouseEvent(MouseEvent* object);
void RemoveMouseEvent(MouseEvent* object);
void operator+= (MouseEvent* object);
void operator-= (MouseEvent* object);
public: /* global subscribe callback functions */
void AddOnMouseCallback( Typedefs::OnMouseCallback func, void* tag);
void AddOnMousePressCallback( Typedefs::OnMousePressCallback func, void* tag);
void AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func, void* tag );
void AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func, void* tag );
void AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func, void* tag );
void AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func, void* tag );
void AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func, void* tag );
void RemoveOnMouseCallback( Typedefs::OnMouseCallback func);
void RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func);
void RemoveOnMouseDownCallback( Typedefs::OnMouseDownCallback func );
void RemoveOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func );
@ -96,10 +123,6 @@ namespace Input
void RemoveOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func );
void RemoveOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func );
public:
void operator+= (MouseEvent* object);
void operator-= (MouseEvent* object);
void SetPixelPos(int x, int y);
void ToggleCursor(bool toggler);
@ -111,6 +134,7 @@ namespace Input
virtual ~Mouse();
protected:
void InternalOnEvent(Struct::MouseEventData & data);
void InternalOnBtnPress(Enum::SAMI key);
void InternalOnBtnDown(Enum::SAMI key);
void InternalOnBtnRelease(Enum::SAMI key);
@ -127,7 +151,6 @@ namespace Input
bool isCurorLocked;
int wheelDelta;
Enum::InputOptionType inputMode;
};
}

View File

@ -1,23 +0,0 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dan Andersson] [2014]
/////////////////////////////////////////////////////////////////////
#ifndef INPUT_WIN32_APPLICATION_KEBOARD_H
#define INPUT_WIN32_APPLICATION_KEBOARD_H
#define NOMINMAX
#include <Windows.h>
#include "..\ApplicationKeyboard.h"
namespace Input
{
class Win32ApplicationKeyboard : public ApplicationKeyboard
{
public:
Win32ApplicationKeyboard();
~Win32ApplicationKeyboard();
void CaptureText( UINT msg, WPARAM param );
};
}
#endif // !INPUT_WIN32_APPLICATION_KEBOARD_H

View File

@ -1,44 +0,0 @@
#include "../Include/ApplicationKeyboard.h"
using namespace ::Input;
ApplicationKeyboard::ApplicationKeyboard() :
InputObject( Enum::SAIType_ApplicationKeyboard )
{
this->textTarget = nullptr;
this->writePos = 0;
this->isEnabled = true;
}
ApplicationKeyboard::~ApplicationKeyboard()
{ /* DO nothing */ }
bool ApplicationKeyboard::IsActive() const
{
return this->isEnabled;
}
void ApplicationKeyboard::Activate()
{
this->isEnabled = true;
}
void ApplicationKeyboard::Deactivate()
{
this->isEnabled = false;
}
void ApplicationKeyboard::BindTextTarget( ::std::wstring *field )
{
this->textTarget = field;
if( field )
{
this->writePos = field->size();
}
}
void ApplicationKeyboard::ReleaseTextTarget( )
{
this->BindTextTarget( nullptr );
}

View File

@ -59,6 +59,9 @@ InputManager* InputManager::CreateInputManager()
}
void InputManager::DestroyInputManager()
{
if(!defaultInstance) return;
defaultInstance->Destroy();
delete defaultInstance;
defaultInstance = 0;
}

View File

@ -12,12 +12,14 @@ struct Keyboard::KeyboardCallbackList
{
enum CallbackDataType
{
CallbackDataType_OnEvent,
CallbackDataType_OnPress,
CallbackDataType_OnDown,
CallbackDataType_OnRelease
} type;
union CallbackData
{
Typedefs::OnKeyEventCallback keyEventCallback;
Typedefs::OnKeyPressCallback keyPressCallback;
Typedefs::OnKeyDownCallback keyDownCallback;
Typedefs::OnKeyReleaseCallback keyReleaseCallback;
@ -29,7 +31,8 @@ struct Keyboard::KeyboardCallbackList
operator bool(){ return this->keyDownCallback != 0; }
} function;
KeyboardCallbackList *next;
KeyboardCallbackList(CallbackData func, CallbackDataType t) :function(func), next(0), type(t) { }
void* tag;
KeyboardCallbackList(CallbackData func, CallbackDataType t, void* ct) :function(func), next(0), type(t), tag(ct) { }
};
void ClearList(Keyboard::KeyboardCallbackList* first)
@ -44,7 +47,7 @@ void ClearList(Keyboard::KeyboardCallbackList* first)
delete removee;
}
}
void AddToList(Keyboard::KeyboardCallbackList* first, Keyboard::KeyboardCallbackList::CallbackData data, Keyboard::KeyboardCallbackList::CallbackDataType type)
void AddToList(Keyboard::KeyboardCallbackList* first, Keyboard::KeyboardCallbackList::CallbackData data, Keyboard::KeyboardCallbackList::CallbackDataType type, void* tag)
{
Keyboard::KeyboardCallbackList *w = first;
Keyboard::KeyboardCallbackList *prev = first;
@ -54,7 +57,7 @@ void AddToList(Keyboard::KeyboardCallbackList* first, Keyboard::KeyboardCallback
Keyboard::KeyboardCallbackList::CallbackData f;
f = data;
prev->next = new Keyboard::KeyboardCallbackList(f, type);
prev->next = new Keyboard::KeyboardCallbackList(f, type, tag);
}
void RemoveFromList(Keyboard::KeyboardCallbackList* first, Keyboard::KeyboardCallbackList::CallbackData data)
{
@ -112,6 +115,27 @@ Keyboard::~Keyboard()
}
void Keyboard::InternalOnEvent(Struct::KeyboardEventData& data)
{
for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++)
{
if(this->keyEventSubscrivers[i])
{
this->keyEventSubscrivers[i]->OnKeyEvent(data);
}
}
KeyboardCallbackList *w = this->callbackList;
while (w)
{
if(w->function)
if (w->type == KeyboardCallbackList::CallbackDataType_OnEvent)
{
data.tag = w->tag;
w->function.keyEventCallback(data);
}
w = w->next;
}
}
void Keyboard::InternalOnKeyPress(Enum::SAKI key)
{
for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++)
@ -126,7 +150,9 @@ void Keyboard::InternalOnKeyPress(Enum::SAKI key)
{
if(w->function)
if (w->type == KeyboardCallbackList::CallbackDataType_OnPress)
w->function.keyPressCallback(key, this);
{
w->function.keyPressCallback(key, this, w->tag);
}
w = w->next;
}
}
@ -144,7 +170,7 @@ void Keyboard::InternalOnKeyDown(Enum::SAKI key)
{
if(w->function)
if (w->type == KeyboardCallbackList::CallbackDataType_OnDown)
w->function.keyDownCallback(key, this);
w->function.keyDownCallback(key, this, w->tag);
w = w->next;
}
}
@ -162,46 +188,26 @@ void Keyboard::InternalOnKeyRelease(Enum::SAKI key)
{
if(w->function)
if (w->type == KeyboardCallbackList::CallbackDataType_OnRelease)
w->function.keyReleaseCallback(key, this);
w->function.keyReleaseCallback(key, this, w->tag);
w = w->next;
}
}
void Keyboard::AddOnKeyPressCallback (OnKeyPressCallback func)
void Keyboard::AddKeyboardEvent(KeyboardEvent* object)
{
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);
}
if(ExistsInList(this->keyEventSubscrivers, object)) return;
void Keyboard::RemoveOnKeyPressCallback (OnKeyPressCallback func)
{
RemoveFromList(this->callbackList, func);
this->keyEventSubscrivers.push_back(object);
}
void Keyboard::RemoveOnKeyDownCallback (OnKeyDownCallback func)
void Keyboard::RemoveKeyboardEvent(KeyboardEvent* object)
{
RemoveFromList(this->callbackList, func);
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);
}
}
void Keyboard::RemoveOnKeyReleaseCallback (OnKeyReleaseCallback func)
{
RemoveFromList(this->callbackList, func);
}
void Keyboard::operator+= (KeyboardEvent* object)
{
if(ExistsInList(this->keyEventSubscrivers, object)) return;
@ -218,6 +224,56 @@ void Keyboard::operator-= (KeyboardEvent* object)
}
}
void Keyboard::AddOnKeyEventCallback (OnKeyEventCallback func, void* tag)
{
KeyboardCallbackList::CallbackData d;
d.keyEventCallback = func;
if(!this->callbackList) this->callbackList = new KeyboardCallbackList(d, KeyboardCallbackList::CallbackDataType_OnEvent, tag);
else AddToList(this->callbackList, d, KeyboardCallbackList::CallbackDataType_OnEvent, tag);
}
void Keyboard::AddOnKeyPressCallback (OnKeyPressCallback func, void* tag)
{
KeyboardCallbackList::CallbackData d;
d.keyPressCallback = func;
if(!this->callbackList) this->callbackList = new KeyboardCallbackList(d, KeyboardCallbackList::CallbackDataType_OnPress, tag);
else AddToList(this->callbackList, d, KeyboardCallbackList::CallbackDataType_OnPress, tag);
}
void Keyboard::AddOnKeyDownCallback (OnKeyDownCallback func, void* tag)
{
KeyboardCallbackList::CallbackData d;
d.keyDownCallback = func;
if(!this->callbackList) this->callbackList = new KeyboardCallbackList(d, KeyboardCallbackList::CallbackDataType_OnDown, tag);
else AddToList(this->callbackList, d, KeyboardCallbackList::CallbackDataType_OnDown, tag);
}
void Keyboard::AddOnKeyReleaseCallback (OnKeyReleaseCallback func, void* tag)
{
KeyboardCallbackList::CallbackData d;
d.keyReleaseCallback = func;
if(!this->callbackList) this->callbackList = new KeyboardCallbackList(d, KeyboardCallbackList::CallbackDataType_OnRelease, tag);
else AddToList(this->callbackList, d, KeyboardCallbackList::CallbackDataType_OnRelease, tag);
}
void Keyboard::RemoveOnKeyEventCallback (OnKeyEventCallback func)
{
Keyboard::KeyboardCallbackList::CallbackData temp;
temp.keyEventCallback = func;
RemoveFromList(this->callbackList, temp);
}
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::BindTextTarget( ::std::wstring *field )
{
this->textTarget = field;

View File

@ -13,6 +13,7 @@ struct Mouse::MouseCallbackList
{
enum CallbackDataType
{
CallbackDataType_OnEvent,
CallbackDataType_OnPress,
CallbackDataType_OnDown,
CallbackDataType_OnRelease,
@ -22,6 +23,7 @@ struct Mouse::MouseCallbackList
} type;
union CallbackData
{
Typedefs::OnMouseCallback mouseCallback;
Typedefs::OnMousePressCallback mousePressCallback;
Typedefs::OnMouseDownCallback mouseDownCallback;
Typedefs::OnMouseReleaseCallback mouseReleaseCallback;
@ -37,7 +39,8 @@ struct Mouse::MouseCallbackList
operator bool(){ return this->dummy != 0; }
} function;
MouseCallbackList *next;
MouseCallbackList(CallbackData func, CallbackDataType t) :function(func), next(0), type(t) { }
void* tag;
MouseCallbackList(CallbackData func, CallbackDataType t, void* ct) :function(func), next(0), type(t), tag(ct) { }
};
void ClearList(Mouse::MouseCallbackList* first)
@ -52,7 +55,7 @@ void ClearList(Mouse::MouseCallbackList* first)
delete removee;
}
}
void AddToList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::CallbackData data, Mouse::MouseCallbackList::CallbackDataType type)
void AddToList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::CallbackData data, Mouse::MouseCallbackList::CallbackDataType type, void* tag)
{
Mouse::MouseCallbackList *w = first;
Mouse::MouseCallbackList *prev = first;
@ -62,7 +65,7 @@ void AddToList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::Callba
Mouse::MouseCallbackList::CallbackData f;
f = data;
prev->next = new Mouse::MouseCallbackList(f, type);
prev->next = new Mouse::MouseCallbackList(f, type, tag);
}
void RemoveFromList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::CallbackData data)
{
@ -119,6 +122,25 @@ Mouse::~Mouse()
}
void Mouse::InternalOnEvent(MouseEventData & data)
{
for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++)
{
if(this->mouseSubscribers[i])
this->mouseSubscribers[i]->OnMouse(data);
}
MouseCallbackList *w = this->callbackList;
while (w)
{
if(w->function)
if (w->type == MouseCallbackList::CallbackDataType_OnEvent)
{
data.tag = w->tag;
w->function.mouseCallback(data);
}
w = w->next;
}
}
void Mouse::InternalOnBtnPress(Enum::SAMI btn)
{
for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++)
@ -205,49 +227,85 @@ void Mouse::InternalOnScroll(int delta)
}
}
void Mouse::AddMouseEvent(MouseEvent* object)
{
if(ExistsInList(this->mouseSubscribers, object)) return;
this->mouseSubscribers.push_back(object);
}
void Mouse::RemoveMouseEvent(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);
}
}
void Mouse::operator+= (MouseEvent* object)
{
if(ExistsInList(this->mouseSubscribers, object)) return;
void Mouse::AddOnMousePressCallback( Typedefs::OnMousePressCallback func)
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);
}
}
void Mouse::AddOnMouseCallback( Typedefs::OnMouseCallback func, void* tag)
{
MouseCallbackList::CallbackData d;
d.mouseCallback = func;
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnEvent, tag);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnEvent, tag);
}
void Mouse::AddOnMousePressCallback( Typedefs::OnMousePressCallback func, void* tag)
{
MouseCallbackList::CallbackData d;
d.mousePressCallback = func;
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnPress);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnPress);
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnPress, tag);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnPress, tag);
}
void Mouse::AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func )
void Mouse::AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func, void* tag )
{
MouseCallbackList::CallbackData d;
d.mouseDownCallback = func;
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnDown);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnDown);
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnDown, tag);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnDown, tag);
}
void Mouse::AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func )
void Mouse::AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func, void* tag )
{
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);
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease, tag);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease, tag);
}
void Mouse::AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func )
void Mouse::AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func, void* tag )
{
MouseCallbackList::CallbackData d;
d.mouseMovePixelPosCallback = func;
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMovePixelPos);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMovePixelPos);
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMovePixelPos, tag);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMovePixelPos, tag);
}
void Mouse::AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func )
void Mouse::AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func, void* tag )
{
MouseCallbackList::CallbackData d;
d.mouseMoveVelocityCallback = func;
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMoveVelocity);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMoveVelocity);
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMoveVelocity, tag);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMoveVelocity, tag);
}
void Mouse::AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func )
void Mouse::AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func, void* tag )
{
MouseCallbackList::CallbackData d;
d.mouseScrollCallback = func;
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnScroll);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnScroll);
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnScroll, tag);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnScroll, tag);
}
void Mouse::RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func)
@ -285,21 +343,6 @@ 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

@ -1,51 +0,0 @@
#include "../../Include/Win32/Win32ApplicationKeyboard.h"
#include "Utilities.h"
using namespace ::Input;
using namespace ::Utility::Value;
using ::std::wstring;
Win32ApplicationKeyboard::Win32ApplicationKeyboard() : ApplicationKeyboard() { /* DO nothing */ }
Win32ApplicationKeyboard::~Win32ApplicationKeyboard() { /* DO nothing */ }
void Win32ApplicationKeyboard::CaptureText( UINT msg, WPARAM param )
{
if( !this->textTarget | !this->isEnabled )
return;
switch( msg )
{
case WM_CHAR:
this->textTarget->insert( this->writePos, 1, (wchar_t)param );
++this->writePos;
break;
case WM_KEYDOWN:
{
switch( param )
{
case VK_BACK:
if( this->writePos > 0 )
{
--this->writePos;
this->textTarget->erase( this->writePos, 1 );
}
break;
case VK_DELETE:
if( this->writePos < this->textTarget->size() )
{
this->textTarget->erase( this->writePos, 1 );
}
break;
case VK_LEFT:
this->writePos = Max( this->writePos - 1, (wstring::size_type)0 );
break;
case VK_RIGHT:
this->writePos = Min( this->writePos + 1, this->textTarget->size() );
break;
default: break;
}
}
default: break;
}
}

View File

@ -66,10 +66,10 @@ void Win32Keyboard::Deactivate ()
void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard)
{
if(!this->active)
{
return;
}
if(!this->active) return;
static Struct::KeyboardEventData keyboardEventData;
memset(&keyboardEventData, 0, sizeof(Struct::KeyboardEventData));
bool isUp = (( keyboard.Flags & RI_KEY_BREAK) != 0);
SAKI key = SAKI_Unknown;
@ -86,6 +86,11 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard)
this->keys[key].isDown = false;
this->keys[key].isE0 = isE0;
this->keys[key].makecode = keyboard.MakeCode;
keyboardEventData.key = key;
keyboardEventData.sender = this;
keyboardEventData.state = Enum::ButtonState_Release;
InternalOnEvent(keyboardEventData);
}
//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))*/
@ -93,6 +98,11 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard)
if(this->keys[key].isDown)
{
this->InternalOnKeyDown(key);
keyboardEventData.key = key;
keyboardEventData.sender = this;
keyboardEventData.state = Enum::ButtonState_Down;
InternalOnEvent(keyboardEventData);
}
else
{
@ -100,6 +110,11 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard)
this->keys[key].isDown = true;
this->keys[key].isE0 = isE0;
this->keys[key].makecode = keyboard.MakeCode;
keyboardEventData.key = key;
keyboardEventData.sender = this;
keyboardEventData.state = Enum::ButtonState_Press;
InternalOnEvent(keyboardEventData);
}
}
}

View File

@ -152,6 +152,10 @@ void Win32Mouse::Deactivate ()
void Win32Mouse::ProccessMouseData (RAWMOUSE mouse)
{
static MouseEventData mouseEventData;
memset(&mouseEventData, 0, sizeof(MouseEventData));
bool isUp = true;
Enum::SAMI btn = Enum::SAMI_Unknown;
int delta = 0;
@ -167,11 +171,30 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse)
ContainPoint(this->pixelPos, this->windowSize);
InternalOnMove(this->pixelPos, velocity);
GetNormalizedPosition( mouseEventData.normalizedPos );
mouseEventData.pixelPos = this->pixelPos;
mouseEventData.velocity = velocity;
mouseEventData.buttonState = Enum::ButtonState_Unknown;
mouseEventData.scrollDelta = 0;
mouseEventData.sender = this;
mouseEventData.type = SAMI::SAMI_MouseMove;
InternalOnEvent(mouseEventData);
}
if(delta != 0)
{
InternalOnScroll(delta);
GetNormalizedPosition( mouseEventData.normalizedPos );
mouseEventData.pixelPos = this->pixelPos;
mouseEventData.buttonState = Enum::ButtonState_Unknown;
mouseEventData.scrollDelta = delta;
mouseEventData.sender = this;
mouseEventData.type = SAMI::SAMI_MouseScroll;
InternalOnEvent(mouseEventData);
}
@ -184,6 +207,14 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse)
if(isUp)
{
InternalOnBtnRelease(btn);
GetNormalizedPosition( mouseEventData.normalizedPos );
mouseEventData.pixelPos = this->pixelPos;
mouseEventData.buttonState = Enum::ButtonState_Release;
mouseEventData.type = btn;
mouseEventData.sender = this;
InternalOnEvent(mouseEventData);
}
//The btn is pressed.
else
@ -192,10 +223,26 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse)
if(this->buttons[btn].isDown)
{
InternalOnBtnDown(btn);
GetNormalizedPosition( mouseEventData.normalizedPos );
mouseEventData.pixelPos = this->pixelPos;
mouseEventData.buttonState = Enum::ButtonState_Down;
mouseEventData.type = btn;
mouseEventData.sender = this;
InternalOnEvent(mouseEventData);
}
else
{
InternalOnBtnPress(btn);
GetNormalizedPosition( mouseEventData.normalizedPos );
mouseEventData.pixelPos = this->pixelPos;
mouseEventData.buttonState = Enum::ButtonState_Press;
mouseEventData.type = btn;
mouseEventData.sender = this;
InternalOnEvent(mouseEventData);
}
}
}