From 7151be0b1a4e8e1434fc33bad341d0a925ed313f Mon Sep 17 00:00:00 2001 From: zulianc Date: Sat, 29 Mar 2025 19:28:04 +0100 Subject: [PATCH] better cursor --- src/GraphicalUI/PlayerCursor.cpp | 42 ++++++++++++++++++++++++++++++++ src/GraphicalUI/PlayerCursor.h | 8 ++++++ 2 files changed, 50 insertions(+) diff --git a/src/GraphicalUI/PlayerCursor.cpp b/src/GraphicalUI/PlayerCursor.cpp index 771f4f0..5d530c1 100644 --- a/src/GraphicalUI/PlayerCursor.cpp +++ b/src/GraphicalUI/PlayerCursor.cpp @@ -66,6 +66,48 @@ void PlayerCursor::goToPosition(const sf::Vector2u& newPosition) { } } +bool PlayerCursor::addPosition(unsigned int x, unsigned int y) { + if (y >= this->rows.size()) return false; + if (x > this->rows.at(y)) return false; + + this->rows.at(y)++; + if (x <= this->position.x) { + this->position.x++; + } + return true; +} + +bool PlayerCursor::removePosition(unsigned int x, unsigned int y) { + if (y >= this->rows.size()) return false; + if (x >= this->rows.at(y)) return false; + + this->rows.at(y)--; + if (x < this->position.x) { + this->position.x--; + } + return true; +} + +bool PlayerCursor::addRow(unsigned int position, unsigned int width) { + if (position > this->rows.size()) return false; + + this->rows.insert(this->rows.begin() + position, width); + if (position <= this->position.y) { + this->position.y++; + } + return true; +} + +bool PlayerCursor::removeRow(unsigned int position) { + if (position >= this->rows.size()) return false; + + this->rows.erase(this->rows.begin() + position); + if (position < this->position.y) { + this->position.y--; + } + return true; +} + const sf::Vector2u& PlayerCursor::getPosition() const { return this->position; } diff --git a/src/GraphicalUI/PlayerCursor.h b/src/GraphicalUI/PlayerCursor.h index 4930c87..860cb04 100644 --- a/src/GraphicalUI/PlayerCursor.h +++ b/src/GraphicalUI/PlayerCursor.h @@ -28,6 +28,14 @@ class PlayerCursor { void goToPosition(const sf::Vector2u& newPosition); + bool addPosition(unsigned int x, unsigned int y); + + bool removePosition(unsigned int x, unsigned int y); + + bool addRow(unsigned int position, unsigned int width); + + bool removeRow(unsigned int position); + const sf::Vector2u& getPosition() const; private: