From 861ed9f13dd942ee02736b56895bd200494e8ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asr=C4=B1n=20Do=C4=9Fan?= Date: Wed, 4 Mar 2020 13:16:54 +0300 Subject: [PATCH] Click Fix --- GUITest/GUIWindow.hpp | 53 +++++++++++++++++++++++-------------------- GUITest/Window.hpp | 14 ++++++++---- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/GUITest/GUIWindow.hpp b/GUITest/GUIWindow.hpp index ab00ea7..f4ea159 100644 --- a/GUITest/GUIWindow.hpp +++ b/GUITest/GUIWindow.hpp @@ -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; diff --git a/GUITest/Window.hpp b/GUITest/Window.hpp index 5ba4520..d598aed 100644 --- a/GUITest/Window.hpp +++ b/GUITest/Window.hpp @@ -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;