2014-02-11 14:13:35 +01:00
|
|
|
//////////////////////////////////////
|
|
|
|
// Created by Pontus Fransson 2014 //
|
|
|
|
//////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef DANBIAS_CLIENT_EVENT_BUTTON_GUI_H
|
|
|
|
#define DANBIAS_CLIENT_EVENT_BUTTON_GUI_H
|
|
|
|
|
2014-02-17 10:38:11 +01:00
|
|
|
#include "EventHandler/EventButton.h"
|
|
|
|
#include "DllInterfaces/GFXAPI.h"
|
2014-02-19 15:40:09 +01:00
|
|
|
#include "../WindowManager/WindowShell.h"
|
2014-02-11 14:13:35 +01:00
|
|
|
|
|
|
|
namespace DanBias
|
|
|
|
{
|
|
|
|
namespace Client
|
|
|
|
{
|
2014-02-13 15:21:05 +01:00
|
|
|
/*Dictates if the texture should be resized based on the screen aspect ratio.
|
|
|
|
|
|
|
|
*/
|
|
|
|
enum ResizeAspectRatio
|
|
|
|
{
|
|
|
|
ResizeAspectRatio_None,
|
|
|
|
ResizeAspectRatio_Width,
|
|
|
|
ResizeAspectRatio_Height,
|
|
|
|
|
|
|
|
ResizeAspectRatio_Count,
|
|
|
|
ResizeAspectRatio_Unknown = -1
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-02-11 14:13:35 +01:00
|
|
|
template <typename Owner>
|
|
|
|
class EventButtonGUI : public Oyster::Event::EventButton<Owner>
|
|
|
|
{
|
|
|
|
public:
|
2014-02-18 09:32:10 +01:00
|
|
|
EventButtonGUI(std::wstring textureName, std::wstring buttonText,
|
|
|
|
Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor,
|
|
|
|
Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None)
|
|
|
|
: EventButton(owner), pos(pos), size(size), texture(NULL), buttonText(buttonText),
|
|
|
|
textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor)
|
2014-02-11 14:13:35 +01:00
|
|
|
{
|
|
|
|
CreateTexture(textureName);
|
2014-02-19 15:40:09 +01:00
|
|
|
this->resizedSize = size;
|
2014-02-13 15:21:05 +01:00
|
|
|
if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize);
|
2014-02-11 14:13:35 +01:00
|
|
|
}
|
2014-02-18 09:32:10 +01:00
|
|
|
EventButtonGUI(std::wstring textureName, std::wstring buttonText,
|
|
|
|
Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor,
|
2014-02-19 15:40:09 +01:00
|
|
|
EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None)
|
2014-02-18 09:32:10 +01:00
|
|
|
: EventButton(func), pos(pos), size(size), texture(NULL), buttonText(buttonText),
|
|
|
|
textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor)
|
2014-02-11 14:13:35 +01:00
|
|
|
{
|
|
|
|
CreateTexture(textureName);
|
2014-02-19 15:40:09 +01:00
|
|
|
this->resizedSize = size;
|
2014-02-13 15:21:05 +01:00
|
|
|
if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize);
|
2014-02-11 14:13:35 +01:00
|
|
|
}
|
2014-02-18 09:32:10 +01:00
|
|
|
EventButtonGUI(std::wstring textureName, std::wstring buttonText,
|
|
|
|
Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor,
|
2014-02-19 15:40:09 +01:00
|
|
|
EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None)
|
2014-02-18 09:32:10 +01:00
|
|
|
: EventButton(func, owner), pos(pos), size(size), texture(NULL), buttonText(buttonText),
|
|
|
|
textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor)
|
2014-02-11 14:13:35 +01:00
|
|
|
{
|
|
|
|
CreateTexture(textureName);
|
2014-02-19 15:40:09 +01:00
|
|
|
this->resizedSize = size;
|
2014-02-13 15:21:05 +01:00
|
|
|
if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize);
|
2014-02-11 14:13:35 +01:00
|
|
|
}
|
2014-02-18 09:32:10 +01:00
|
|
|
EventButtonGUI(std::wstring textureName, std::wstring buttonText,
|
|
|
|
Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor,
|
|
|
|
EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None)
|
|
|
|
: EventButton(func, owner, userData), pos(pos), size(size), texture(NULL), buttonText(buttonText),
|
|
|
|
textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor)
|
2014-02-11 14:13:35 +01:00
|
|
|
{
|
|
|
|
CreateTexture(textureName);
|
2014-02-19 15:40:09 +01:00
|
|
|
this->resizedSize = size;
|
2014-02-13 15:21:05 +01:00
|
|
|
if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize);
|
2014-02-11 14:13:35 +01:00
|
|
|
}
|
2014-02-12 09:08:38 +01:00
|
|
|
virtual ~EventButtonGUI()
|
|
|
|
{
|
|
|
|
Oyster::Graphics::API::DeleteTexture(texture);
|
|
|
|
texture = NULL;
|
|
|
|
}
|
2014-02-11 14:13:35 +01:00
|
|
|
|
|
|
|
void CreateTexture(std::wstring textureName)
|
|
|
|
{
|
|
|
|
//Create texture
|
2014-02-12 10:02:52 +01:00
|
|
|
texture = Oyster::Graphics::API::CreateTexture(textureName);
|
2014-02-11 14:13:35 +01:00
|
|
|
}
|
|
|
|
|
2014-02-13 15:21:05 +01:00
|
|
|
virtual void RenderTexture()
|
2014-02-11 14:13:35 +01:00
|
|
|
{
|
2014-02-11 15:06:46 +01:00
|
|
|
if(EventButton<Owner>::Enabled())
|
|
|
|
{
|
2014-02-14 12:09:59 +01:00
|
|
|
// let the using dev decide what is rendered
|
2014-02-18 09:32:10 +01:00
|
|
|
//Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float4(1.0f, 1.0f, 1.0f, 1.0f));
|
2014-02-14 12:09:59 +01:00
|
|
|
|
2014-02-11 15:06:46 +01:00
|
|
|
//Render att xPos and yPos
|
2014-02-12 09:08:38 +01:00
|
|
|
//With width and height
|
|
|
|
|
2014-02-18 09:32:10 +01:00
|
|
|
if(EventButton<Owner>::GetState() == ButtonState_None)
|
|
|
|
{
|
2014-02-19 15:40:09 +01:00
|
|
|
Oyster::Graphics::API::RenderGuiElement(texture, pos, resizedSize, backColor);
|
2014-02-18 09:32:10 +01:00
|
|
|
}
|
|
|
|
else if(EventButton<Owner>::GetState() == ButtonState_Hover)
|
|
|
|
{
|
2014-02-19 15:40:09 +01:00
|
|
|
Oyster::Graphics::API::RenderGuiElement(texture, pos, resizedSize, hoverColor);
|
2014-02-18 09:32:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-19 15:40:09 +01:00
|
|
|
Oyster::Graphics::API::RenderGuiElement(texture, pos, resizedSize, pressedColor);
|
2014-02-18 09:32:10 +01:00
|
|
|
}
|
2014-02-12 09:08:38 +01:00
|
|
|
|
2014-02-11 15:06:46 +01:00
|
|
|
}
|
2014-02-11 14:13:35 +01:00
|
|
|
}
|
|
|
|
|
2014-02-13 15:21:05 +01:00
|
|
|
virtual void RenderText()
|
|
|
|
{
|
|
|
|
if(buttonText.size() > 0)
|
|
|
|
{
|
2014-02-20 16:35:49 +01:00
|
|
|
Oyster::Graphics::API::RenderText(buttonText, pos - Float3(size.x * 0.5f, size.y * 0.25f, +0.001f), size, size.y * 0.5f, textColor);
|
2014-02-13 15:21:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ResizeWithAspectRatio(ResizeAspectRatio resize)
|
2014-02-12 11:35:48 +01:00
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
GetClientRect(WindowShell::GetHWND(), &r);
|
2014-02-13 15:21:05 +01:00
|
|
|
|
|
|
|
if(resize == ResizeAspectRatio_Height)
|
2014-02-19 15:40:09 +01:00
|
|
|
resizedSize.y = size.y * ((float)r.right/(float)r.bottom);
|
2014-02-13 15:21:05 +01:00
|
|
|
else if(resize == ResizeAspectRatio_Width)
|
2014-02-19 15:40:09 +01:00
|
|
|
resizedSize.x = size.x * ((float)r.bottom/(float)r.right);
|
2014-02-12 11:35:48 +01:00
|
|
|
}
|
|
|
|
|
2014-02-11 14:13:35 +01:00
|
|
|
protected:
|
2014-02-13 15:21:05 +01:00
|
|
|
Oyster::Math::Float3 pos;
|
|
|
|
Oyster::Math::Float2 size;
|
2014-02-12 09:08:38 +01:00
|
|
|
|
2014-02-19 15:40:09 +01:00
|
|
|
//The new calculated resize, it's only used for the button not the text right now.
|
|
|
|
Oyster::Math::Float2 resizedSize;
|
|
|
|
|
2014-02-13 15:21:05 +01:00
|
|
|
Oyster::Graphics::API::Texture texture;
|
|
|
|
|
|
|
|
std::wstring buttonText;
|
2014-02-17 13:05:35 +01:00
|
|
|
Oyster::Math::Float4 textColor;
|
2014-02-18 09:32:10 +01:00
|
|
|
|
|
|
|
Oyster::Math::Float4 backColor;
|
|
|
|
Oyster::Math::Float4 hoverColor;
|
|
|
|
Oyster::Math::Float4 pressedColor;
|
2014-02-11 14:13:35 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|