bool MGMap::mouseScrollingUpdate(int x, int y) { if(m_MouseScrollingOngoing) { int setY = getScrollY() + m_MouseScrollingYClick - y; int setX = getScrollX() + m_MouseScrollingXClick - x; if(setY > getTopEdge()) { setY = getTopEdge(); } else if(setY < getWindowHeight() - getHeight() * getTileHeight() - getBottomEdge()) { setY = getWindowHeight() - getHeight() * getTileHeight() - getBottomEdge(); } if(setX > getLeftEdge()) { setX = getLeftEdge(); } else if(setX < getWindowWidth() - getWidth() * getTileWidth() - getRightEdge()) { setX = getWindowWidth() - getWidth() * getTileWidth() - getRightEdge(); } setScrollOffset(setX, setY); } return m_MouseScrollingOngoing; }
int MGMap::getTileIndex(int clickX, int clickY) { MGFLOG_INFO("MGMap::getTileIndex(" << clickX << ", " << clickY << ")"); if( clickX > getLeftEdge() && clickX < (getWindowWidth() - getRightEdge()) && clickY > getTopEdge() && clickY < (getWindowHeight() - getBottomEdge())) { int x = (clickX - getScrollX()) / getTileWidth(); int y = (clickY - getScrollY()) / getTileHeight(); if(x < getWidth() && y < getHeight()) { return y * getWidth() + x; } } return -1; // Click outside of map }
void AdvScrollArea::ensureVisibleX(int x) { int cw = getScrollAreaWidth(); int cx = getScrollX(); if (x < cx) {setScrollX(x - cw);} if (x > cx + cw) {setScrollX(x);} }