diff --git a/src/button.cpp b/src/button.cpp index e0c7e3d..d53f2a8 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -23,16 +23,40 @@ Button::~Button() void Button::Draw() { - DrawTextureV(texture, position, WHITE); + DrawTextureV(texture, position, (wasHoveredBefore ? darkenColor : normalColor)); +} + +void Button::SetPosition(Vector2 newPosition) +{ + position = newPosition; } bool Button::isPressed(Vector2 mousePos, bool mousePressed) { Rectangle rect = {position.x, position.y, static_cast(texture.width), static_cast(texture.height)}; + + bool isHovered = CheckCollisionPointRec(mousePos, rect); - if(CheckCollisionPointRec(mousePos,rect) && mousePressed) + if (!isHovered && wasHoveredBefore) { - return true; + UnHovered(); + wasHoveredBefore = false; } - return false; + else if (isHovered && !wasHoveredBefore) + { + Hovered(); + wasHoveredBefore = true; + } + + return isHovered && mousePressed; +} + +void Button::Hovered() +{ + SetMouseCursor(MOUSE_CURSOR_POINTING_HAND); +} + +void Button::UnHovered() +{ + SetMouseCursor(MOUSE_CURSOR_DEFAULT); } diff --git a/src/button.hpp b/src/button.hpp index 2f0aa23..7e071f7 100644 --- a/src/button.hpp +++ b/src/button.hpp @@ -8,7 +8,16 @@ class Button ~Button(); void Draw(); bool isPressed(Vector2 mousePos, bool mousePressed); + void SetPosition(Vector2 newPosition); + private: Texture2D texture; Vector2 position; + bool wasHoveredBefore = false; + + Color normalColor = WHITE; + Color darkenColor = { 50, 50, 50, 255 }; + + void Hovered(); + void UnHovered(); }; \ No newline at end of file