Merge
This commit is contained in:
parent
3139d6d409
commit
3b225ea054
|
@ -21,17 +21,17 @@ namespace DanBias
|
||||||
ButtonEllipse()
|
ButtonEllipse()
|
||||||
: EventButtonGUI(), radius(0)
|
: EventButtonGUI(), radius(0)
|
||||||
{}
|
{}
|
||||||
ButtonEllipse(std::wstring textureName, Owner owner, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true)
|
ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||||
: EventButtonGUI(textureName, owner, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio)
|
: EventButtonGUI(textureName, buttonText, textColor, owner, pos, size, resize)
|
||||||
{}
|
{}
|
||||||
ButtonEllipse(std::wstring textureName, EventFunc func, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true)
|
ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||||
: EventButtonGUI(textureName, func, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio)
|
: EventButtonGUI(textureName, buttonText, textColor, func, pos, size, resize)
|
||||||
{}
|
{}
|
||||||
ButtonEllipse(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true)
|
ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||||
: EventButtonGUI(textureName, func, owner, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio)
|
: EventButtonGUI(textureName, buttonText, textColor, func, owner, pos, size, resize)
|
||||||
{}
|
{}
|
||||||
ButtonEllipse(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true)
|
ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||||
: EventButtonGUI(textureName, func, owner, userData, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio)
|
: EventButtonGUI(textureName, buttonText, textColor, func, owner, userData, pos, size, resize)
|
||||||
{}
|
{}
|
||||||
virtual ~ButtonEllipse()
|
virtual ~ButtonEllipse()
|
||||||
{}
|
{}
|
||||||
|
@ -42,8 +42,8 @@ namespace DanBias
|
||||||
//Should come from the InputClass
|
//Should come from the InputClass
|
||||||
float xMouse = input.x, yMouse = input.y;
|
float xMouse = input.x, yMouse = input.y;
|
||||||
|
|
||||||
double normx = (xMouse - xPos) / width;
|
double normx = (xMouse - pos.x) / size.x;
|
||||||
double normy = (yMouse - yPos) / height;
|
double normy = (yMouse - pos.y) / size.y;
|
||||||
|
|
||||||
return (normx * normx + normy * normy) < 0.25;
|
return (normx * normx + normy * normy) < 0.25;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,17 +21,17 @@ namespace DanBias
|
||||||
ButtonRectangle()
|
ButtonRectangle()
|
||||||
: EventButtonGUI(), width(0), height(0)
|
: EventButtonGUI(), width(0), height(0)
|
||||||
{}
|
{}
|
||||||
ButtonRectangle(std::wstring textureName, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||||
: EventButtonGUI(textureName, owner, xPos, yPos, width, height, resizeToScreenAspectRatio)
|
: EventButtonGUI(textureName, buttonText, textColor, owner, pos, size, resize)
|
||||||
{}
|
{}
|
||||||
ButtonRectangle(std::wstring textureName, EventFunc func, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||||
: EventButtonGUI(textureName, func, xPos, yPos, width, height, resizeToScreenAspectRatio)
|
: EventButtonGUI(textureName, buttonText, textColor, func, pos, size, resize)
|
||||||
{}
|
{}
|
||||||
ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||||
: EventButtonGUI(textureName, func, owner, xPos, yPos, width, height, resizeToScreenAspectRatio)
|
: EventButtonGUI(textureName, buttonText, textColor, func, owner, pos, size, resize)
|
||||||
{}
|
{}
|
||||||
ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||||
: EventButtonGUI(textureName, func, owner, userData, xPos, yPos, width, height, resizeToScreenAspectRatio)
|
: EventButtonGUI(textureName, buttonText, textColor, func, owner, userData, pos, size, resize)
|
||||||
{}
|
{}
|
||||||
virtual ~ButtonRectangle()
|
virtual ~ButtonRectangle()
|
||||||
{}
|
{}
|
||||||
|
@ -42,10 +42,10 @@ namespace DanBias
|
||||||
//Should come from the InputClass
|
//Should come from the InputClass
|
||||||
float xMouse = input.x, yMouse = input.y;
|
float xMouse = input.x, yMouse = input.y;
|
||||||
|
|
||||||
float widthTemp = xPos - width * 0.5f;
|
float widthTemp = pos.x - size.x * 0.5f;
|
||||||
float widthTemp2 = xPos + width * 0.5f;
|
float widthTemp2 = pos.x + size.x * 0.5f;
|
||||||
float heightTemp = yPos - height * 0.5f;
|
float heightTemp = pos.y - size.y * 0.5f;
|
||||||
float heightTemp2 = yPos + height * 0.5f;
|
float heightTemp2 = pos.y + size.y * 0.5f;
|
||||||
//std::cout << p.x << ' ' << p.y << ' ' << widthTemp << ' ' << heightTemp << std::endl;
|
//std::cout << p.x << ' ' << p.y << ' ' << widthTemp << ' ' << heightTemp << std::endl;
|
||||||
|
|
||||||
if(xMouse >= widthTemp && xMouse <= widthTemp2 &&
|
if(xMouse >= widthTemp && xMouse <= widthTemp2 &&
|
||||||
|
|
|
@ -8,40 +8,56 @@
|
||||||
#include "../Misc/EventHandler/EventButton.h"
|
#include "../Misc/EventHandler/EventButton.h"
|
||||||
#include "../OysterGraphics/DllInterfaces/GFXAPI.h"
|
#include "../OysterGraphics/DllInterfaces/GFXAPI.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace DanBias
|
namespace DanBias
|
||||||
{
|
{
|
||||||
namespace Client
|
namespace Client
|
||||||
{
|
{
|
||||||
|
/*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
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename Owner>
|
template <typename Owner>
|
||||||
class EventButtonGUI : public Oyster::Event::EventButton<Owner>
|
class EventButtonGUI : public Oyster::Event::EventButton<Owner>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EventButtonGUI()
|
EventButtonGUI()
|
||||||
: EventButton(), xPos(0), yPos(0), width(0), height(0), texture(NULL)
|
: EventButton(), pos(0, 0), size(0, 0), texture(NULL), buttonText(""), textColor(0, 0, 0)
|
||||||
{}
|
{}
|
||||||
EventButtonGUI(std::wstring textureName, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||||
: EventButton(owner), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL)
|
: EventButton(owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor)
|
||||||
{
|
{
|
||||||
CreateTexture(textureName);
|
CreateTexture(textureName);
|
||||||
if(resizeToScreenAspectRatio) ResizeWithAspectRatio();
|
if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize);
|
||||||
}
|
}
|
||||||
EventButtonGUI(std::wstring textureName, EventFunc func, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||||
: EventButton(func), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL)
|
: EventButton(func), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor)
|
||||||
{
|
{
|
||||||
CreateTexture(textureName);
|
CreateTexture(textureName);
|
||||||
if(resizeToScreenAspectRatio) ResizeWithAspectRatio();
|
if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize);
|
||||||
}
|
}
|
||||||
EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||||
: EventButton(func, owner), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL)
|
: EventButton(func, owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor)
|
||||||
{
|
{
|
||||||
CreateTexture(textureName);
|
CreateTexture(textureName);
|
||||||
if(resizeToScreenAspectRatio) ResizeWithAspectRatio();
|
if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize);
|
||||||
}
|
}
|
||||||
EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height)
|
||||||
: EventButton(func, owner, userData), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL)
|
: EventButton(func, owner, userData), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor)
|
||||||
{
|
{
|
||||||
CreateTexture(textureName);
|
CreateTexture(textureName);
|
||||||
if(resizeToScreenAspectRatio) ResizeWithAspectRatio();
|
if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize);
|
||||||
}
|
}
|
||||||
virtual ~EventButtonGUI()
|
virtual ~EventButtonGUI()
|
||||||
{
|
{
|
||||||
|
@ -55,7 +71,7 @@ namespace DanBias
|
||||||
texture = Oyster::Graphics::API::CreateTexture(textureName);
|
texture = Oyster::Graphics::API::CreateTexture(textureName);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Render()
|
virtual void RenderTexture()
|
||||||
{
|
{
|
||||||
if(EventButton<Owner>::Enabled())
|
if(EventButton<Owner>::Enabled())
|
||||||
{
|
{
|
||||||
|
@ -64,32 +80,48 @@ namespace DanBias
|
||||||
|
|
||||||
if(EventButton<Owner>::GetState() == ButtonState_None)
|
if(EventButton<Owner>::GetState() == ButtonState_None)
|
||||||
{
|
{
|
||||||
Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(1.0f, 1.0f, 1.0f));
|
Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(1.0f, 1.0f, 1.0f));
|
||||||
}
|
}
|
||||||
else if(EventButton<Owner>::GetState() == ButtonState_Hover)
|
else if(EventButton<Owner>::GetState() == ButtonState_Hover)
|
||||||
{
|
{
|
||||||
Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(0.0f, 1.0f, 0.0f));
|
Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(0.0f, 1.0f, 0.0f));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(1.0f, 0.0f, 0.0f));
|
Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(1.0f, 0.0f, 0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResizeWithAspectRatio()
|
virtual void RenderText()
|
||||||
|
{
|
||||||
|
if(buttonText.size() > 0)
|
||||||
|
{
|
||||||
|
Oyster::Graphics::API::RenderText(buttonText, pos.xy, size, textColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void ResizeWithAspectRatio(ResizeAspectRatio resize)
|
||||||
{
|
{
|
||||||
RECT r;
|
RECT r;
|
||||||
GetClientRect(WindowShell::GetHWND(), &r);
|
GetClientRect(WindowShell::GetHWND(), &r);
|
||||||
height *= (float)r.right/(float)r.bottom;
|
|
||||||
|
if(resize == ResizeAspectRatio_Height)
|
||||||
|
size.y *= (float)r.right/(float)r.bottom;
|
||||||
|
else if(resize == ResizeAspectRatio_Width)
|
||||||
|
size.x *= (float)r.bottom/(float)r.right;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float xPos, yPos;
|
Oyster::Math::Float3 pos;
|
||||||
float width, height;
|
Oyster::Math::Float2 size;
|
||||||
Oyster::Graphics::API::Texture texture;
|
|
||||||
|
|
||||||
|
Oyster::Graphics::API::Texture texture;
|
||||||
|
|
||||||
|
std::wstring buttonText;
|
||||||
|
Oyster::Math::Float3 textColor;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,13 +43,24 @@ void EventButtonCollection::Update(MouseInput& input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventButtonCollection::Render()
|
void EventButtonCollection::RenderTexture()
|
||||||
{
|
{
|
||||||
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]->Render();
|
buttons[i]->RenderTexture();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventButtonCollection::RenderText()
|
||||||
|
{
|
||||||
|
if(this->collectionState == EventCollectionState_Enabled)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < (int)buttons.size(); i++)
|
||||||
|
{
|
||||||
|
buttons[i]->RenderText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,8 @@ namespace Oyster
|
||||||
~EventButtonCollection();
|
~EventButtonCollection();
|
||||||
|
|
||||||
void Update(MouseInput& input);
|
void Update(MouseInput& input);
|
||||||
void Render();
|
void RenderTexture();
|
||||||
|
void RenderText();
|
||||||
|
|
||||||
/*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.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -35,11 +35,19 @@ void EventHandler::Update(MouseInput& input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandler::Render()
|
void EventHandler::RenderTexture()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < (int)collections.size(); i++)
|
for(int i = 0; i < (int)collections.size(); i++)
|
||||||
{
|
{
|
||||||
collections.at(i)->Render();
|
collections.at(i)->RenderTexture();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventHandler::RenderText()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < (int)collections.size(); i++)
|
||||||
|
{
|
||||||
|
collections.at(i)->RenderText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,8 @@ namespace Oyster
|
||||||
void Clean();
|
void Clean();
|
||||||
|
|
||||||
void Update(MouseInput& input);
|
void Update(MouseInput& input);
|
||||||
void Render();
|
void RenderTexture();
|
||||||
|
void RenderText();
|
||||||
|
|
||||||
/*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.
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,9 @@
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <WinSock2.h>
|
#include <WinSock2.h>
|
||||||
|
|
||||||
|
//For conversion from wstring to string
|
||||||
|
#include <codecvt>
|
||||||
|
|
||||||
using namespace Oyster::Network;
|
using namespace Oyster::Network;
|
||||||
using namespace Oyster::Thread;
|
using namespace Oyster::Thread;
|
||||||
using namespace Utility::DynamicMemory;
|
using namespace Utility::DynamicMemory;
|
||||||
|
@ -295,6 +298,17 @@ bool NetworkClient::Connect(unsigned short port, const char serverIP[])
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NetworkClient::Connect(unsigned short port, std::wstring serverIP)
|
||||||
|
{
|
||||||
|
//Convert from wstring to string.
|
||||||
|
typedef std::codecvt_utf8<wchar_t> convert_typeX;
|
||||||
|
std::wstring_convert<convert_typeX, wchar_t> converterX;
|
||||||
|
|
||||||
|
std::string ip = converterX.to_bytes(serverIP);
|
||||||
|
|
||||||
|
return this->Connect(port, ip.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
void NetworkClient::Disconnect()
|
void NetworkClient::Disconnect()
|
||||||
{
|
{
|
||||||
if(!privateData) return;
|
if(!privateData) return;
|
||||||
|
|
|
@ -88,6 +88,11 @@ namespace Oyster
|
||||||
*/
|
*/
|
||||||
bool Connect(unsigned short port, const char serverIP[]);
|
bool Connect(unsigned short port, const char serverIP[]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool Connect(unsigned short port, std::wstring serverIP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue