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; SynButton *buttons;
SynText output; SynText output;
SynInputField input; SynInputField input;
void ButtonCheck(sf::Vector2i);
void MouseButtonPressedHandle(sf::Vector2i);
void KeyHandle(char);
void BinaryButton(); void BinaryButton();
void QuaternaryButton(); void QuaternaryButton();
void OctalButton(); void OctalButton();
@ -20,11 +23,35 @@ class GUIWindow : public Window
public: public:
GUIWindow(unsigned int = 960, unsigned int = 540, std::string = "Window", sf::Uint32 = sf::Style::Titlebar | sf::Style::Close); GUIWindow(unsigned int = 960, unsigned int = 540, std::string = "Window", sf::Uint32 = sf::Style::Titlebar | sf::Style::Close);
void Update(); void Update();
void ButtonCheck(sf::Vector2i);
void KeyHandle(char);
~GUIWindow(); ~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() void GUIWindow::BinaryButton()
{ {
output.SetText(GetBase(input.GetValue(), 2)); output.SetText(GetBase(input.GetValue(), 2));
@ -191,28 +218,6 @@ void GUIWindow::Update()
window.display(); 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() GUIWindow::~GUIWindow()
{ {
if(buttons) delete buttons; if(buttons) delete buttons;

View File

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