Click Fix

This commit is contained in:
Asrın Doğan 2020-03-04 13:16:54 +03:00
parent 9a5ca4c103
commit 861ed9f13d
2 changed files with 39 additions and 28 deletions

View File

@ -6,6 +6,9 @@ class GUIWindow : public Window
SynButton *buttons;
SynText output;
SynInputField input;
void ButtonCheck(sf::Vector2i);
void MouseButtonPressedHandle(sf::Vector2i);
void KeyHandle(char);
void BinaryButton();
void QuaternaryButton();
void OctalButton();
@ -20,11 +23,35 @@ class GUIWindow : public Window
public:
GUIWindow(unsigned int = 960, unsigned int = 540, std::string = "Window", sf::Uint32 = sf::Style::Titlebar | sf::Style::Close);
void Update();
void ButtonCheck(sf::Vector2i);
void KeyHandle(char);
~GUIWindow();
};
void GUIWindow::MouseButtonPressedHandle(sf::Vector2i mousePos)
{
ButtonCheck(mousePos);
}
void GUIWindow::ButtonCheck(sf::Vector2i mousePos)
{
int i;
SynButton *current;
for (i = 0; i < 10; i++)
{
current = buttons + i;
if(current -> IsMouseOver(mousePos.x, mousePos.y))
{
(buttons + i) -> Click();
break;
}
}
input.Click(input.IsMouseOver(mousePos.x, mousePos.y));
}
void GUIWindow::KeyHandle(char character)
{
input.AddToInput(character);
}
void GUIWindow::BinaryButton()
{
output.SetText(GetBase(input.GetValue(), 2));
@ -191,28 +218,6 @@ void GUIWindow::Update()
window.display();
}
void GUIWindow::ButtonCheck(sf::Vector2i mousePos)
{
int i;
SynButton *current;
for (i = 0; i < 10; i++)
{
current = buttons + i;
if(current -> IsMouseOver(mousePos.x, mousePos.y))
{
(buttons + i) -> Click();
break;
}
}
input.Click(input.IsMouseOver(mousePos.x, mousePos.y));
}
void GUIWindow::KeyHandle(char character)
{
input.AddToInput(character);
}
GUIWindow::~GUIWindow()
{
if(buttons) delete buttons;

View File

@ -64,6 +64,7 @@
virtual void Update();
virtual void ButtonCheck(sf::Vector2i);
virtual void KeyHandle(char);
virtual void MouseButtonPressedHandle(sf::Vector2i);
public:
Window(unsigned int = 960, unsigned int = 540, std::string = "Window", sf::Uint32 = sf::Style::Titlebar | sf::Style::Close);
virtual void CreateWindow();
@ -85,11 +86,11 @@
else if (event.type == sf::Event::GainedFocus)
isFocused = true;
else if (event.type == sf::Event::KeyPressed)
{
KeyHandle((int)event.key.code);
}
else if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
ButtonCheck(sf::Mouse::getPosition(window));
else if (event.type == sf::Event::MouseButtonPressed)
MouseButtonPressedHandle(sf::Mouse::getPosition(window));
// else if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
// ButtonCheck(sf::Mouse::getPosition(window));
// if(sf::Keyboard::isKeyPressed(sf::Keyboard::F))
// {
// fullscreen = !fullscreen;
@ -114,6 +115,11 @@
}
void Window::MouseButtonPressedHandle(sf::Vector2i mousePos)
{
}
Window::Window(unsigned int width, unsigned int height, std::string title, sf::Uint32 style)
{
this -> size.x = width;