diff --git a/seminar11_events/02_slider/slider.hpp b/seminar11_events/02_slider/slider.hpp index f72c090..dd6944b 100644 --- a/seminar11_events/02_slider/slider.hpp +++ b/seminar11_events/02_slider/slider.hpp @@ -6,10 +6,7 @@ class Slider { private: - inline static const sf::Color defaultColor {sf::Color(190, 210, 190)}; - inline static const sf::Color pressedColor {sf::Color(150, 170, 150)}; - inline static const sf::Color textColor {sf::Color::Black}; - inline static const int kCharacterSize = 14; + const int kCharacterSize = 14; int mMinValue; int mMaxValue; @@ -20,10 +17,9 @@ private: sf::RectangleShape mAxis; sf::Text mText; - /* Is slider pressed at the moment */ bool mIsPressed = false; - int onMousePressed(const sf::Event& event) + void onMousePressed(const sf::Event& event) { if (event.mouseButton.button == sf::Mouse::Left) { sf::Vector2f mousePosition = mRenderWindow.mapPixelToCoords({event.mouseButton.x, event.mouseButton.y}); @@ -42,13 +38,12 @@ private: } } } - return mMinValue + (mMaxValue - mMinValue) * mSliderPosition; } - int onMouseMove(const sf::Event& event) + void onMouseMove(const sf::Event& event) { if (!mIsPressed) { - return mMinValue + (mMaxValue - mMinValue) * mSliderPosition; + return; } sf::Vector2f mousePosition = mRenderWindow.mapPixelToCoords({event.mouseMove.x, event.mouseMove.y}); if ((mousePosition.x >= mAxis.getPosition().x) && (mousePosition.x + mSlider.getSize().x <= mAxis.getPosition().x + mAxis.getSize().x)) { @@ -63,7 +58,6 @@ private: mSliderPosition = (mSlider.getPosition().x - mAxis.getPosition().x) / (mAxis.getSize().x - mSlider.getSize().x); - return mMinValue + (mMaxValue - mMinValue) * mSliderPosition; } public: @@ -76,7 +70,7 @@ public: mSlider.setOutlineColor(sf::Color::Black); mSlider.setOutlineThickness(2); - mAxis.setFillColor(defaultColor); + mAxis.setFillColor(sf::Color::White); mAxis.setSize({500,10}); mAxis.setPosition(position); @@ -106,10 +100,10 @@ public: int handleEvent(const sf::Event& event) { if (event.type == sf::Event::MouseMoved) { - return onMouseMove(event); + onMouseMove(event); } else if (event.type == sf::Event::MouseButtonPressed) { - return onMousePressed(event); + onMousePressed(event); } else if (event.type == sf::Event::MouseButtonReleased) { mIsPressed = false;