mirror of
https://github.com/edubart/otclient.git
synced 2025-10-16 20:43:26 +02:00
Use push/pop mechanism for cursors
This commit is contained in:
@@ -61,7 +61,7 @@ void Mouse::addCursor(const std::string& name, const std::string& file, const Po
|
||||
g_logger.error(stdext::format("unable to load cursor %s", name));
|
||||
}
|
||||
|
||||
bool Mouse::setCursor(const std::string& name)
|
||||
bool Mouse::pushCursor(const std::string& name)
|
||||
{
|
||||
auto it = m_cursors.find(name);
|
||||
if(it == m_cursors.end())
|
||||
@@ -73,12 +73,26 @@ bool Mouse::setCursor(const std::string& name)
|
||||
return true;
|
||||
}
|
||||
|
||||
void Mouse::restoreCursor()
|
||||
void Mouse::popCursor(const std::string& name)
|
||||
{
|
||||
if(m_cursorStack.size() == 0)
|
||||
return;
|
||||
|
||||
m_cursorStack.pop_back();
|
||||
if(name.empty() || m_cursors.find(name) == m_cursors.end())
|
||||
m_cursorStack.pop_back();
|
||||
else {
|
||||
int cursorId = m_cursors[name];
|
||||
int index = -1;
|
||||
for(uint i=0;i<m_cursorStack.size();++i) {
|
||||
if(m_cursorStack[i] == cursorId)
|
||||
index = i;
|
||||
}
|
||||
if(index >= 0)
|
||||
m_cursorStack.erase(m_cursorStack.begin() + index);
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_cursorStack.size() > 0)
|
||||
g_window.setMouseCursor(m_cursorStack.back());
|
||||
else
|
||||
@@ -99,6 +113,6 @@ void Mouse::checkStackSize()
|
||||
{
|
||||
if(m_cursorStack.size() > 5) {
|
||||
g_logger.error("mouse cursor stack is too long");
|
||||
m_cursorStack.resize(5);
|
||||
m_cursorStack.pop_front();
|
||||
}
|
||||
}
|
||||
|
@@ -30,8 +30,8 @@ public:
|
||||
|
||||
void loadCursors(std::string filename);
|
||||
void addCursor(const std::string& name, const std::string& file, const Point& hotSpot);
|
||||
bool setCursor(const std::string& name);
|
||||
void restoreCursor();
|
||||
bool pushCursor(const std::string& name);
|
||||
void popCursor(const std::string& name);
|
||||
bool isCursorChanged();
|
||||
bool isPressed(Fw::MouseButton mouseButton);
|
||||
|
||||
@@ -39,7 +39,7 @@ private:
|
||||
void checkStackSize();
|
||||
|
||||
std::map<std::string, int> m_cursors;
|
||||
std::vector<int> m_cursorStack;
|
||||
std::deque<int> m_cursorStack;
|
||||
};
|
||||
|
||||
extern Mouse g_mouse;
|
||||
|
Reference in New Issue
Block a user