Misc - Changed to MouseInput struct in EventHandler update.

This commit is contained in:
Pontus Fransson 2014-02-12 15:44:27 +01:00
parent 7a218c61d8
commit 74d28d1f62
9 changed files with 38 additions and 27 deletions

View File

@ -142,8 +142,19 @@ namespace DanBias
HRESULT DanBiasGame::Update(float deltaTime) HRESULT DanBiasGame::Update(float deltaTime)
{ {
//Get mouse pos and window size (Temporary)
POINT p;
RECT r;
GetCursorPos(&p);
ScreenToClient(WindowShell::GetHWND(), &p);
GetClientRect(WindowShell::GetHWND(), &r);
//Update menu buttons //Update menu buttons
EventHandler::Instance().Update(m_data->inputObj); MouseInput mouseInput;
mouseInput.x = (float)p.x / (float)r.right;
mouseInput.y = (float)p.y / (float)r.bottom;
mouseInput.mouseButtonPressed = m_data->inputObj->IsMousePressed();
EventHandler::Instance().Update(mouseInput);
m_data->inputObj->Update(); m_data->inputObj->Update();

View File

@ -37,15 +37,10 @@ namespace DanBias
{} {}
//Circle vs point collision //Circle vs point collision
bool Collision(InputClass* inputObject) bool Collision(Oyster::Event::MouseInput& input)
{ {
POINT p;
RECT r;
GetCursorPos(&p);
ScreenToClient(WindowShell::GetHWND(), &p);
GetClientRect(WindowShell::GetHWND(), &r);
//Should come from the InputClass //Should come from the InputClass
float xMouse = (float)p.x / (float)r.right, yMouse = (float)p.y / (float)r.bottom; float xMouse = input.x, yMouse = input.y;
double normx = (xMouse - xPos) / width; double normx = (xMouse - xPos) / width;
double normy = (yMouse - yPos) / height; double normy = (yMouse - yPos) / height;

View File

@ -37,16 +37,10 @@ namespace DanBias
{} {}
//Circle vs point collision //Circle vs point collision
bool Collision(InputClass* inputObject) bool Collision(Oyster::Event::MouseInput& input)
{ {
POINT p;
RECT r;
GetCursorPos(&p);
ScreenToClient(WindowShell::GetHWND(), &p);
GetClientRect(WindowShell::GetHWND(), &r);
//Should come from the InputClass //Should come from the InputClass
float xMouse = (float)p.x / (float)r.right, yMouse = (float)p.y / (float)r.bottom; float xMouse = input.x, yMouse = input.y;
float widthTemp = xPos - width * 0.5f; float widthTemp = xPos - width * 0.5f;
float widthTemp2 = xPos + width * 0.5f; float widthTemp2 = xPos + width * 0.5f;

View File

@ -46,7 +46,7 @@ namespace Oyster
private: private:
//Implement this in the inherited classes for collision against that shape. //Implement this in the inherited classes for collision against that shape.
virtual bool Collision(InputClass *input) = 0; virtual bool Collision(MouseInput& input) = 0;
public: public:
EventButton(); EventButton();
@ -56,7 +56,7 @@ namespace Oyster
EventButton(EventFunc func, Owner owner, void* userData); EventButton(EventFunc func, Owner owner, void* userData);
virtual ~EventButton(); virtual ~EventButton();
void Update(InputClass *input); void Update(MouseInput& input);
//Send event to callback function //Send event to callback function
void SendEvent(ButtonState state); void SendEvent(ButtonState state);
@ -135,16 +135,18 @@ namespace Oyster
//Checks for collision and //Checks for collision and
template <typename Owner> template <typename Owner>
void EventButton<Owner>::Update(InputClass *input) void EventButton<Owner>::Update(MouseInput& input)
{ {
if(this->privData.enabled) if(this->privData.enabled)
{ {
ButtonState currentState = ButtonState_None; ButtonState currentState = ButtonState_None;
static bool outside = false; static bool outside = false;
static bool clicked = false; static bool clicked = false;
//Check for collision against the button.
if(Collision(input)) if(Collision(input))
{ {
if(input->IsMousePressed()) if(input.mouseButtonPressed)
{ {
//Change state when the mouse button is pressed //Change state when the mouse button is pressed
switch(this->privData.previousState) switch(this->privData.previousState)

View File

@ -32,13 +32,13 @@ EventButtonCollection::~EventButtonCollection()
} }
} }
void EventButtonCollection::Update(InputClass* inputObject) void EventButtonCollection::Update(MouseInput& input)
{ {
if(this->collectionState == EventCollectionState_Enabled) if(this->collectionState == EventCollectionState_Enabled)
{ {
for(int i = 0; i < (int)buttons.size(); i++) for(int i = 0; i < (int)buttons.size(); i++)
{ {
buttons[i]->Update(inputObject); buttons[i]->Update(input);
} }
} }
} }

View File

@ -36,7 +36,7 @@ namespace Oyster
EventButtonCollection(EventCollectionState state = EventCollectionState_Enabled); EventButtonCollection(EventCollectionState state = EventCollectionState_Enabled);
~EventButtonCollection(); ~EventButtonCollection();
void Update(InputClass* inputObject); void Update(MouseInput& input);
void Render(); void Render();
/*Add a button to the collection when a button is added to the collection you are not allowed to delete it. /*Add a button to the collection when a button is added to the collection you are not allowed to delete it.

View File

@ -27,11 +27,11 @@ void EventHandler::Clean()
collections.clear(); collections.clear();
} }
void EventHandler::Update(InputClass* inputObject) void EventHandler::Update(MouseInput& input)
{ {
for(int i = 0; i < (int)collections.size(); i++) for(int i = 0; i < (int)collections.size(); i++)
{ {
collections.at(i)->Update(inputObject); collections.at(i)->Update(input);
} }
} }

View File

@ -26,7 +26,7 @@ namespace Oyster
void Clean(); void Clean();
void Update(InputClass* inputObject); void Update(MouseInput& input);
void Render(); void Render();
/*Add a collection to the EventHandler will only add collections not already present in the list. /*Add a collection to the EventHandler will only add collections not already present in the list.

View File

@ -19,6 +19,14 @@ namespace Oyster
ButtonState_Down, ButtonState_Down,
ButtonState_Released, ButtonState_Released,
}; };
//Takes normalized device coordinates
struct MouseInput
{
//Normalized device coordinates
float x, y;
bool mouseButtonPressed;
};
class IEventButton class IEventButton
{ {
@ -26,7 +34,8 @@ namespace Oyster
virtual ~IEventButton(){} virtual ~IEventButton(){}
virtual void Render() = 0; virtual void Render() = 0;
virtual void Update(InputClass *input) = 0;
virtual void Update(MouseInput& input) = 0;
virtual void SendEvent(ButtonState state) = 0; virtual void SendEvent(ButtonState state) = 0;