2020-03-01 14:13:23 +03:00
|
|
|
#include "SynGame.hpp"
|
2020-03-01 20:03:43 +03:00
|
|
|
#include <iostream>
|
2020-03-01 14:13:23 +03:00
|
|
|
|
|
|
|
class GUIWindow : public Window
|
|
|
|
{
|
|
|
|
private:
|
2020-03-01 20:03:43 +03:00
|
|
|
SynButton *buttons;
|
|
|
|
SynText output;
|
|
|
|
void BinaryButton();
|
|
|
|
void QuaternaryButton();
|
|
|
|
void OctalButton();
|
|
|
|
void HexadecimalButton();
|
2020-03-01 14:13:23 +03:00
|
|
|
public:
|
|
|
|
GUIWindow(unsigned int = 960, unsigned int = 540, std::string = "Window", sf::Uint32 = sf::Style::Titlebar | sf::Style::Close);
|
|
|
|
void Update();
|
2020-03-01 20:03:43 +03:00
|
|
|
void ButtonCheck(sf::Vector2i);
|
2020-03-01 14:13:23 +03:00
|
|
|
~GUIWindow();
|
|
|
|
};
|
|
|
|
|
2020-03-01 20:03:43 +03:00
|
|
|
void GUIWindow::BinaryButton()
|
|
|
|
{
|
|
|
|
output.SetText("Output: Binary");
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIWindow::QuaternaryButton()
|
|
|
|
{
|
|
|
|
output.SetText("Output: Quaternary");
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIWindow::OctalButton()
|
|
|
|
{
|
|
|
|
output.SetText("Output: Octal");
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIWindow::HexadecimalButton()
|
|
|
|
{
|
|
|
|
output.SetText("Output: Hexadecimal");
|
|
|
|
}
|
|
|
|
|
2020-03-01 14:13:23 +03:00
|
|
|
GUIWindow::GUIWindow(unsigned int width, unsigned int height, std::string title, sf::Uint32 style) : Window(width, height, title, style)
|
|
|
|
{
|
2020-03-01 20:03:43 +03:00
|
|
|
output.SetText("Output: ");
|
|
|
|
output.SetCentered(true);
|
|
|
|
output.SetPosition(window.getSize().x / 2, window.getSize().y / 2);
|
|
|
|
output.SetOffset(0, 0);
|
|
|
|
buttons = new SynButton[4];
|
2020-03-01 14:13:23 +03:00
|
|
|
|
2020-03-01 20:03:43 +03:00
|
|
|
(buttons + 0) -> SetText("Binary");
|
|
|
|
(buttons + 1) -> SetText("Quaternary");
|
|
|
|
(buttons + 2) -> SetText("Octal");
|
|
|
|
(buttons + 3) -> SetText("Hexadecimal");
|
|
|
|
|
|
|
|
(buttons + 0) -> SetArea(400, 100); (buttons + 0) -> SetPosition(650, 100);
|
|
|
|
(buttons + 1) -> SetArea(400, 100); (buttons + 1) -> SetPosition(650, 200);
|
|
|
|
(buttons + 2) -> SetArea(400, 100); (buttons + 2) -> SetPosition(650, 300);
|
|
|
|
(buttons + 3) -> SetArea(400, 100); (buttons + 3) -> SetPosition(650, 400);
|
|
|
|
|
|
|
|
(buttons + 0) -> Bind((void (*)(int))&BinaryButton, NULL);
|
|
|
|
(buttons + 1) -> Bind((void (*)(int))&QuaternaryButton, NULL);
|
|
|
|
(buttons + 2) -> Bind((void (*)(int))&OctalButton, NULL);
|
|
|
|
(buttons + 3) -> Bind((void (*)(int))&HexadecimalButton, NULL);
|
2020-03-01 14:13:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GUIWindow::Update()
|
|
|
|
{
|
2020-03-01 20:03:43 +03:00
|
|
|
|
|
|
|
int buttonCounter;
|
|
|
|
|
|
|
|
Window::Update();
|
|
|
|
|
2020-03-01 14:13:23 +03:00
|
|
|
if(!isFocused)
|
|
|
|
return;
|
|
|
|
|
2020-03-01 20:03:43 +03:00
|
|
|
window.clear(sf::Color::Black);
|
|
|
|
|
|
|
|
for (buttonCounter = 0; buttonCounter < 4; buttonCounter++)
|
|
|
|
{
|
|
|
|
window.draw((buttons + buttonCounter) -> GetVertices(), 4, sf::PrimitiveType::Quads);
|
|
|
|
window.draw((buttons + buttonCounter) -> GetText());
|
|
|
|
}
|
|
|
|
|
|
|
|
window.draw(output.GetText());
|
|
|
|
window.display();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GUIWindow::ButtonCheck(sf::Vector2i mousePos)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
SynButton *current;
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
current = buttons + i;
|
|
|
|
if(current -> IsMouseOver(mousePos.x, mousePos.y))
|
|
|
|
{
|
|
|
|
(buttons + i) -> Click();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-01 14:13:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
GUIWindow::~GUIWindow()
|
|
|
|
{
|
2020-03-01 20:03:43 +03:00
|
|
|
if(buttons) delete buttons;
|
2020-03-01 14:13:23 +03:00
|
|
|
}
|