GL - FIxed Button state flickering, added flag resizeToScreenAspectRatio.
This commit is contained in:
parent
3a80a71143
commit
f2a444507c
|
@ -21,17 +21,17 @@ namespace DanBias
|
|||
ButtonEllipse()
|
||||
: EventButtonGUI(), radius(0)
|
||||
{}
|
||||
ButtonEllipse(std::wstring textureName, Owner owner, float xPos, float yPos, float textureWidth, float textureHeight)
|
||||
: EventButtonGUI(textureName, owner, xPos, yPos, textureWidth, textureHeight)
|
||||
ButtonEllipse(std::wstring textureName, Owner owner, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true)
|
||||
: EventButtonGUI(textureName, owner, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio)
|
||||
{}
|
||||
ButtonEllipse(std::wstring textureName, EventFunc func, float xPos, float yPos, float textureWidth, float textureHeight)
|
||||
: EventButtonGUI(textureName, func, xPos, yPos, textureWidth, textureHeight)
|
||||
ButtonEllipse(std::wstring textureName, EventFunc func, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true)
|
||||
: EventButtonGUI(textureName, func, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio)
|
||||
{}
|
||||
ButtonEllipse(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float textureWidth, float textureHeight)
|
||||
: EventButtonGUI(textureName, func, owner, xPos, yPos, textureWidth, textureHeight)
|
||||
ButtonEllipse(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true)
|
||||
: EventButtonGUI(textureName, func, owner, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio)
|
||||
{}
|
||||
ButtonEllipse(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float textureWidth, float textureHeight)
|
||||
: EventButtonGUI(textureName, func, owner, userData, xPos, yPos, textureWidth, textureHeight)
|
||||
ButtonEllipse(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true)
|
||||
: EventButtonGUI(textureName, func, owner, userData, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio)
|
||||
{}
|
||||
virtual ~ButtonEllipse()
|
||||
{}
|
||||
|
@ -40,9 +40,9 @@ namespace DanBias
|
|||
bool Collision(InputClass* inputObject)
|
||||
{
|
||||
POINT p;
|
||||
RECT r;
|
||||
GetCursorPos(&p);
|
||||
ScreenToClient(WindowShell::GetHWND(), &p);
|
||||
RECT r;
|
||||
GetClientRect(WindowShell::GetHWND(), &r);
|
||||
|
||||
//Should come from the InputClass
|
||||
|
|
|
@ -21,17 +21,17 @@ namespace DanBias
|
|||
ButtonRectangle()
|
||||
: EventButtonGUI(), width(0), height(0)
|
||||
{}
|
||||
ButtonRectangle(std::wstring textureName, Owner owner, float xPos, float yPos, float width, float height)
|
||||
: EventButtonGUI(textureName, owner, xPos, yPos, width, height)
|
||||
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)
|
||||
{}
|
||||
ButtonRectangle(std::wstring textureName, EventFunc func, float xPos, float yPos, float width, float height)
|
||||
: EventButtonGUI(textureName, func, xPos, yPos, width, height)
|
||||
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)
|
||||
{}
|
||||
ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float width, float height)
|
||||
: EventButtonGUI(textureName, func, owner, xPos, yPos, width, height)
|
||||
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)
|
||||
{}
|
||||
ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float width, float height)
|
||||
: EventButtonGUI(textureName, func, owner, userData, xPos, yPos, width, height)
|
||||
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)
|
||||
{}
|
||||
virtual ~ButtonRectangle()
|
||||
{}
|
||||
|
|
|
@ -19,25 +19,29 @@ namespace DanBias
|
|||
EventButtonGUI()
|
||||
: EventButton(), xPos(0), yPos(0), width(0), height(0), texture(NULL)
|
||||
{}
|
||||
EventButtonGUI(std::wstring textureName, Owner owner, float xPos, float yPos, float width, float height)
|
||||
EventButtonGUI(std::wstring textureName, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
||||
: EventButton(owner), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL)
|
||||
{
|
||||
CreateTexture(textureName);
|
||||
if(resizeToScreenAspectRatio) ResizeWithAspectRatio();
|
||||
}
|
||||
EventButtonGUI(std::wstring textureName, EventFunc func, float xPos, float yPos, float width, float height)
|
||||
EventButtonGUI(std::wstring textureName, EventFunc func, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
||||
: EventButton(func), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL)
|
||||
{
|
||||
CreateTexture(textureName);
|
||||
if(resizeToScreenAspectRatio) ResizeWithAspectRatio();
|
||||
}
|
||||
EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float width, float height)
|
||||
EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
||||
: EventButton(func, owner), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL)
|
||||
{
|
||||
CreateTexture(textureName);
|
||||
if(resizeToScreenAspectRatio) ResizeWithAspectRatio();
|
||||
}
|
||||
EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float width, float height)
|
||||
EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true)
|
||||
: EventButton(func, owner, userData), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL)
|
||||
{
|
||||
CreateTexture(textureName);
|
||||
if(resizeToScreenAspectRatio) ResizeWithAspectRatio();
|
||||
}
|
||||
virtual ~EventButtonGUI()
|
||||
{
|
||||
|
@ -60,26 +64,32 @@ namespace DanBias
|
|||
|
||||
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, 1, 1));
|
||||
Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
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, 1, 0));
|
||||
Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(0.0f, 1.0f, 0.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(1, 0, 0));
|
||||
Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(1.0f, 0.0f, 0.0f));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ResizeWithAspectRatio()
|
||||
{
|
||||
RECT r;
|
||||
GetClientRect(WindowShell::GetHWND(), &r);
|
||||
height *= (float)r.right/(float)r.bottom;
|
||||
}
|
||||
|
||||
protected:
|
||||
float xPos, yPos;
|
||||
float width, height;
|
||||
Oyster::Graphics::API::Texture texture;
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ struct LoginState::myData
|
|||
|
||||
//Menu button collection
|
||||
EventButtonCollection* collection;
|
||||
|
||||
bool createGame;
|
||||
int testNumber;
|
||||
}privData;
|
||||
|
||||
|
@ -51,7 +51,7 @@ void LoginState::ButtonCallback(Oyster::Event::ButtonEvent<LoginState*>& e)
|
|||
switch(type)
|
||||
{
|
||||
case Create:
|
||||
/*if(e.state == ButtonState_None)
|
||||
if(e.state == ButtonState_None)
|
||||
{
|
||||
int a = 0;
|
||||
std::cout << "None" << std::endl;
|
||||
|
@ -76,7 +76,8 @@ void LoginState::ButtonCallback(Oyster::Event::ButtonEvent<LoginState*>& e)
|
|||
//Change to create state or something similar
|
||||
int a = 0;
|
||||
std::cout << "Released" << std::endl;
|
||||
}*/
|
||||
e.owner->privData->createGame = true;
|
||||
}
|
||||
break;
|
||||
case Options:
|
||||
break;
|
||||
|
@ -110,15 +111,15 @@ bool LoginState::Init(Oyster::Network::NetworkClient* nwClient)
|
|||
//Create menu buttons
|
||||
privData->collection = new EventButtonCollection;
|
||||
EventHandler::Instance().AddCollection(privData->collection);
|
||||
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.2f, 0.1f, 0.2f));
|
||||
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.3f, 0.1f, 0.2f));
|
||||
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.4f, 0.1f, 0.2f));
|
||||
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.5f, 0.1f, 0.2f));
|
||||
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.2f, 0.1f, 0.1f));
|
||||
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.3f, 0.1f, 0.1f));
|
||||
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.4f, 0.1f, 0.1f));
|
||||
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.5f, 0.1f, 0.1f));
|
||||
|
||||
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.15f, 0.05f, 0.1f, 0.1f));
|
||||
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.25f, 0.05f, 0.1f, 0.1f));
|
||||
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.35f, 0.05f, 0.1f, 0.1f));
|
||||
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.45f, 0.05f, 0.1f, 0.1f));
|
||||
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.15f, 0.05f, 0.1f, 0.1f));
|
||||
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.25f, 0.05f, 0.1f, 0.1f));
|
||||
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.35f, 0.05f, 0.1f, 0.1f));
|
||||
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.45f, 0.05f, 0.1f, 0.1f));
|
||||
|
||||
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.5f, 0.5f, 0.3f, 0.3f));
|
||||
|
||||
|
@ -126,6 +127,7 @@ bool LoginState::Init(Oyster::Network::NetworkClient* nwClient)
|
|||
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Incr, 0.85f, 0.2f, 0.1f, 0.1f));
|
||||
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Decr, 0.55f, 0.2f, 0.1f, 0.1f));
|
||||
|
||||
privData->createGame = false;
|
||||
privData->testNumber = 0;
|
||||
|
||||
return true;
|
||||
|
@ -182,7 +184,7 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key
|
|||
// check data from server
|
||||
|
||||
// create game
|
||||
if( KeyInput->IsKeyPressed(DIK_C))
|
||||
if( KeyInput->IsKeyPressed(DIK_C) || privData->createGame)
|
||||
{
|
||||
DanBias::GameServerAPI::ServerInitDesc desc;
|
||||
|
||||
|
@ -239,8 +241,9 @@ bool LoginState::Render(float dt)
|
|||
wchar_t temp[10];
|
||||
_itow_s(privData->testNumber, temp, 10);
|
||||
number = temp;
|
||||
|
||||
Oyster::Graphics::API::StartTextRender();
|
||||
Oyster::Graphics::API::RenderText(number, Oyster::Math::Float2(0.7, 0.2), Oyster::Math::Float2(0.1, 0.1), Oyster::Math::Float3(1, 0, 0));
|
||||
Oyster::Graphics::API::RenderText(number, Oyster::Math::Float2(0.7f, 0.2f), Oyster::Math::Float2(0.1f, 0.1f*(1008.0f/730.0f)), Oyster::Math::Float3(1.0f, 0.0f, 0.0f));
|
||||
|
||||
Oyster::Graphics::API::EndFrame();
|
||||
return true;
|
||||
|
|
|
@ -160,6 +160,10 @@ namespace Oyster
|
|||
clicked = true;
|
||||
currentState = ButtonState_Pressed;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentState = ButtonState_Hover;
|
||||
}
|
||||
break;
|
||||
case ButtonState_Released:
|
||||
currentState = ButtonState_Hover;
|
||||
|
|
Loading…
Reference in New Issue