2014-02-11 14:13:35 +01:00
|
|
|
//////////////////////////////////////
|
|
|
|
// Created by Pontus Fransson 2014 //
|
|
|
|
//////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef DANBIAS_CLIENT_BUTTON_RECTANGLE_H
|
|
|
|
#define DANBIAS_CLIENT_BUTTON_RECTANGLE_H
|
|
|
|
|
|
|
|
#include "EventButtonGUI.h"
|
2014-02-12 09:08:38 +01:00
|
|
|
#include <iostream>
|
|
|
|
//Only for testing because we don't have any other input
|
|
|
|
#include "../WindowManager/WindowShell.h"
|
2014-02-11 14:13:35 +01:00
|
|
|
|
|
|
|
namespace DanBias
|
|
|
|
{
|
|
|
|
namespace Client
|
|
|
|
{
|
|
|
|
template <typename Owner>
|
|
|
|
class ButtonRectangle : public EventButtonGUI<Owner>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ButtonRectangle()
|
2014-02-12 09:08:38 +01:00
|
|
|
: EventButtonGUI(), width(0), height(0)
|
2014-02-11 14:13:35 +01:00
|
|
|
{}
|
2014-02-12 11:35:48 +01:00
|
|
|
ButtonRectangle(std::wstring textureName, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
|
|
|
: EventButtonGUI(textureName, owner, xPos, yPos, width, height, resizeToScreenAspectRatio)
|
2014-02-11 14:13:35 +01:00
|
|
|
{}
|
2014-02-12 11:35:48 +01:00
|
|
|
ButtonRectangle(std::wstring textureName, EventFunc func, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
|
|
|
: EventButtonGUI(textureName, func, xPos, yPos, width, height, resizeToScreenAspectRatio)
|
2014-02-11 14:13:35 +01:00
|
|
|
{}
|
2014-02-12 11:35:48 +01:00
|
|
|
ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
|
|
|
: EventButtonGUI(textureName, func, owner, xPos, yPos, width, height, resizeToScreenAspectRatio)
|
2014-02-11 14:13:35 +01:00
|
|
|
{}
|
2014-02-12 11:35:48 +01:00
|
|
|
ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
|
|
|
: EventButtonGUI(textureName, func, owner, userData, xPos, yPos, width, height, resizeToScreenAspectRatio)
|
2014-02-11 14:13:35 +01:00
|
|
|
{}
|
2014-02-12 09:08:38 +01:00
|
|
|
virtual ~ButtonRectangle()
|
2014-02-11 14:13:35 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
//Circle vs point collision
|
|
|
|
bool Collision(InputClass* inputObject)
|
|
|
|
{
|
2014-02-12 09:08:38 +01:00
|
|
|
POINT p;
|
|
|
|
RECT r;
|
|
|
|
GetCursorPos(&p);
|
|
|
|
ScreenToClient(WindowShell::GetHWND(), &p);
|
|
|
|
GetClientRect(WindowShell::GetHWND(), &r);
|
|
|
|
|
2014-02-11 14:13:35 +01:00
|
|
|
//Should come from the InputClass
|
2014-02-12 09:08:38 +01:00
|
|
|
float xMouse = (float)p.x / (float)r.right, yMouse = (float)p.y / (float)r.bottom;
|
|
|
|
|
|
|
|
float widthTemp = xPos - width * 0.5f;
|
|
|
|
float widthTemp2 = xPos + width * 0.5f;
|
|
|
|
float heightTemp = yPos - height * 0.5f;
|
|
|
|
float heightTemp2 = yPos + height * 0.5f;
|
|
|
|
//std::cout << p.x << ' ' << p.y << ' ' << widthTemp << ' ' << heightTemp << std::endl;
|
2014-02-11 14:13:35 +01:00
|
|
|
|
2014-02-12 09:08:38 +01:00
|
|
|
if(xMouse >= widthTemp && xMouse <= widthTemp2 &&
|
|
|
|
yMouse >= heightTemp && yMouse <= heightTemp2)
|
2014-02-11 14:13:35 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|