From 03efca45b87665fdaeb17d61097ea59d7766da89 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 19 Feb 2014 15:40:09 +0100 Subject: [PATCH] Fixed ButonEllipse it was not up to date. And only resizing the buttons now. --- .../GameClientState/Buttons/ButtonEllipse.h | 35 +++++++------- .../GameClientState/Buttons/ButtonRectangle.h | 46 +++++++------------ .../GameClientState/Buttons/EventButtonGUI.h | 24 ++++++---- 3 files changed, 48 insertions(+), 57 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/Buttons/ButtonEllipse.h b/Code/Game/GameClient/GameClientState/Buttons/ButtonEllipse.h index 7d9a9a5d..57c6008d 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/ButtonEllipse.h +++ b/Code/Game/GameClient/GameClientState/Buttons/ButtonEllipse.h @@ -7,9 +7,6 @@ #include "EventButtonGUI.h" -//Only for testing because we don't have any other input -#include "../WindowManager/WindowShell.h" - namespace DanBias { namespace Client @@ -18,24 +15,25 @@ namespace DanBias class ButtonEllipse : public EventButtonGUI { public: - ButtonEllipse() - : EventButtonGUI(), radius(0) + ButtonEllipse(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_Height) + : EventButtonGUI(textureName, buttonText, textColor, backColor, hoverColor, pressedColor, owner, pos, size, resize) {} - ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, Owner owner, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButtonGUI(textureName, buttonText, textColor, owner, pos, size, resize) + ButtonEllipse(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, backColor, hoverColor, pressedColor, func, pos, size, resize) {} - ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButtonGUI(textureName, buttonText, textColor, func, pos, size, resize) + ButtonEllipse(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, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, backColor, hoverColor, pressedColor, func, owner, pos, size, resize) {} - ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButtonGUI(textureName, buttonText, textColor, func, owner, pos, size, resize) - {} - ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButtonGUI(textureName, buttonText, textColor, func, owner, userData, pos, size, resize) + ButtonEllipse(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_Height) + : EventButtonGUI(textureName, buttonText, textColor, backColor, hoverColor, pressedColor, func, owner, userData, pos, size, resize) {} virtual ~ButtonEllipse() {} @@ -43,7 +41,6 @@ namespace DanBias //Circle vs point collision bool Collision(Oyster::Event::MouseInput& input) { - //Should come from the InputClass float xMouse = input.x, yMouse = input.y; double normx = (xMouse - pos.x) / size.x; diff --git a/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h b/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h index 7f3db825..33098568 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h +++ b/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h @@ -6,9 +6,6 @@ #define DANBIAS_CLIENT_BUTTON_RECTANGLE_H #include "EventButtonGUI.h" -#include -//Only for testing because we don't have any other input -#include "../WindowManager/WindowShell.h" namespace DanBias { @@ -18,55 +15,46 @@ namespace DanBias class ButtonRectangle : public EventButtonGUI { public: - ButtonRectangle() - : EventButtonGUI(), width(0), height(0) - {} ButtonRectangle(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) - : EventButtonGUI(textureName, buttonText, - textColor, backColor, hoverColor, pressedColor, - owner, pos, size, resize) + Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButtonGUI(textureName, buttonText + , textColor, backColor, hoverColor, pressedColor + , owner, pos, size, resize) {} ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, - EventFunc func, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) - : EventButtonGUI(textureName, buttonText, - textColor, backColor, hoverColor, pressedColor, - func, pos, size, resize) + EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButtonGUI(textureName, buttonText + , textColor, backColor, hoverColor, pressedColor + , func, pos, size, resize) {} ButtonRectangle(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, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) - : EventButtonGUI(textureName, buttonText, - textColor, backColor, hoverColor, pressedColor, - func, owner, pos, size, resize) + EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButtonGUI(textureName, buttonText + , textColor, backColor, hoverColor, pressedColor + , func, owner, pos, size, resize) {} ButtonRectangle(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) - : EventButtonGUI(textureName, buttonText, - textColor, backColor, hoverColor, pressedColor, - func, owner, userData, pos, size, resize) + EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButtonGUI(textureName, buttonText + , textColor, backColor, hoverColor, pressedColor + , func, owner, userData, pos, size, resize) {} virtual ~ButtonRectangle() {} - //Circle vs point collision + //Rectangle vs point collision bool Collision(Oyster::Event::MouseInput& input) { - //Should come from the InputClass float xMouse = input.x, yMouse = input.y; float widthTemp = pos.x - size.x * 0.5f; float widthTemp2 = pos.x + size.x * 0.5f; float heightTemp = pos.y - size.y * 0.5f; float heightTemp2 = pos.y + size.y * 0.5f; - //std::cout << p.x << ' ' << p.y << ' ' << widthTemp << ' ' << heightTemp << std::endl; if(xMouse >= widthTemp && xMouse <= widthTemp2 && yMouse >= heightTemp && yMouse <= heightTemp2) diff --git a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h index 3ae09043..c14d24f2 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h +++ b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h @@ -7,6 +7,7 @@ #include "EventHandler/EventButton.h" #include "DllInterfaces/GFXAPI.h" +#include "../WindowManager/WindowShell.h" namespace DanBias { @@ -37,26 +38,27 @@ namespace DanBias textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor) { CreateTexture(textureName); + this->resizedSize = size; if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } 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, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) : EventButton(func), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor) { CreateTexture(textureName); + this->resizedSize = size; if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } 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, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) : EventButton(func, owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor) { CreateTexture(textureName); + this->resizedSize = size; if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } EventButtonGUI(std::wstring textureName, std::wstring buttonText, @@ -66,6 +68,7 @@ namespace DanBias textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor) { CreateTexture(textureName); + this->resizedSize = size; if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } virtual ~EventButtonGUI() @@ -92,15 +95,15 @@ namespace DanBias if(EventButton::GetState() == ButtonState_None) { - Oyster::Graphics::API::RenderGuiElement(texture, pos, size, backColor); + Oyster::Graphics::API::RenderGuiElement(texture, pos, resizedSize, backColor); } else if(EventButton::GetState() == ButtonState_Hover) { - Oyster::Graphics::API::RenderGuiElement(texture, pos, size, hoverColor); + Oyster::Graphics::API::RenderGuiElement(texture, pos, resizedSize, hoverColor); } else { - Oyster::Graphics::API::RenderGuiElement(texture, pos, size, pressedColor); + Oyster::Graphics::API::RenderGuiElement(texture, pos, resizedSize, pressedColor); } } @@ -121,15 +124,18 @@ namespace DanBias GetClientRect(WindowShell::GetHWND(), &r); if(resize == ResizeAspectRatio_Height) - size.y *= (float)r.right/(float)r.bottom; + resizedSize.y = size.y * ((float)r.right/(float)r.bottom); else if(resize == ResizeAspectRatio_Width) - size.x *= (float)r.bottom/(float)r.right; + resizedSize.x = size.x * ((float)r.bottom/(float)r.right); } protected: Oyster::Math::Float3 pos; Oyster::Math::Float2 size; + //The new calculated resize, it's only used for the button not the text right now. + Oyster::Math::Float2 resizedSize; + Oyster::Graphics::API::Texture texture; std::wstring buttonText;