void ScrollArea::mousePress(int x, int y, int button) { if (getUpButtonDimension().isPointInRect(x, y)) { setVerticalScrollAmount(getVerticalScrollAmount() - 10); mUpButtonPressed = true; } else if (getDownButtonDimension().isPointInRect(x, y)) { setVerticalScrollAmount(getVerticalScrollAmount() + 10); mDownButtonPressed = true; } else if (getLeftButtonDimension().isPointInRect(x, y)) { setHorizontalScrollAmount(getHorizontalScrollAmount() - 10); mLeftButtonPressed = true; } else if (getRightButtonDimension().isPointInRect(x, y)) { setHorizontalScrollAmount(getHorizontalScrollAmount() + 10); mRightButtonPressed = true; } else if (getVerticalMarkerDimension().isPointInRect(x, y)) { mVerticalMarkerPressed = true; mVerticalMarkerMousePosition = y - getVerticalMarkerDimension().y; } else if (getHorizontalMarkerDimension().isPointInRect(x, y)) { mHorizontalMarkerPressed = true; mHorizontalMarkerMousePosition = x - getHorizontalMarkerDimension().x; } }
void ScrollArea::scrollToRectangle(const Rectangle& rectangle) { Rectangle contentDim = getContentDimension(); if (rectangle.x + rectangle.width > getHorizontalScrollAmount() + contentDim.width) { setHorizontalScrollAmount(rectangle.x + rectangle.width - contentDim.width); } if (rectangle.y + rectangle.height > getVerticalScrollAmount() + contentDim.height) { setVerticalScrollAmount(rectangle.y + rectangle.height - contentDim.height); } if (rectangle.x < getHorizontalScrollAmount()) { setHorizontalScrollAmount(rectangle.x); } if (rectangle.y < getVerticalScrollAmount()) { setVerticalScrollAmount(rectangle.y); } }
void ScrollArea::logic() { if (!isVisible()) return; gcn::ScrollArea::logic(); gcn::Widget *content = getContent(); // When no scrollbar in a certain direction, adapt content size to match // the content dimension exactly. if (content) { if (getHorizontalScrollPolicy() == gcn::ScrollArea::SHOW_NEVER) { content->setWidth(getChildrenArea().width - 2 * content->getFrameSize()); } if (getVerticalScrollPolicy() == gcn::ScrollArea::SHOW_NEVER) { content->setHeight(getChildrenArea().height - 2 * content->getFrameSize()); } } if (mUpButtonPressed) { setVerticalScrollAmount(getVerticalScrollAmount() - mUpButtonScrollAmount); } else if (mDownButtonPressed) { setVerticalScrollAmount(getVerticalScrollAmount() + mDownButtonScrollAmount); } else if (mLeftButtonPressed) { setHorizontalScrollAmount(getHorizontalScrollAmount() - mLeftButtonScrollAmount); } else if (mRightButtonPressed) { setHorizontalScrollAmount(getHorizontalScrollAmount() + mRightButtonScrollAmount); } }
void ScrollArea::logic() { checkPolicies(); setVerticalScrollAmount(getVerticalScrollAmount()); setHorizontalScrollAmount(getHorizontalScrollAmount()); if (getContent() != NULL) { getContent()->setPosition(-mHScroll + getContent()->getFrameSize(), -mVScroll + getContent()->getFrameSize()); getContent()->logic(); } }
void ScrollArea::logic() { checkPolicies(); setVerticalScrollAmount(getVerticalScrollAmount()); setHorizontalScrollAmount(getHorizontalScrollAmount()); if (mContent != NULL) { mContent->setPosition(-mHScroll + getContentDimension().x + mContent->getBorderSize(), -mVScroll + getContentDimension().y + mContent->getBorderSize()); mContent->logic(); } }
Rectangle ScrollArea::getHorizontalMarkerDimension() { if (!mHBarVisible) { return Rectangle(0, 0, 0, 0); } int length, pos; Rectangle barDim = getHorizontalBarDimension(); if (getContent() && getContent()->getWidth() != 0) { length = (barDim.width * getChildrenArea().width) / getContent()->getWidth(); } else { length = barDim.width; } if (length < mScrollbarWidth) { length = mScrollbarWidth; } if (length > barDim.width) { length = barDim.width; } if (getHorizontalMaxScroll() != 0) { pos = ((barDim.width - length) * getHorizontalScrollAmount()) / getHorizontalMaxScroll(); } else { pos = 0; } return Rectangle(barDim.x + pos, barDim.y, length, mScrollbarWidth); }
void ScrollArea::mousePressed(MouseEvent& mouseEvent) { int x = mouseEvent.getX(); int y = mouseEvent.getY(); if (getUpButtonDimension().isPointInRect(x, y)) { setVerticalScrollAmount(getVerticalScrollAmount() - mUpButtonScrollAmount); mUpButtonPressed = true; } else if (getDownButtonDimension().isPointInRect(x, y)) { setVerticalScrollAmount(getVerticalScrollAmount() + mDownButtonScrollAmount); mDownButtonPressed = true; } else if (getLeftButtonDimension().isPointInRect(x, y)) { setHorizontalScrollAmount(getHorizontalScrollAmount() - mLeftButtonScrollAmount); mLeftButtonPressed = true; } else if (getRightButtonDimension().isPointInRect(x, y)) { setHorizontalScrollAmount(getHorizontalScrollAmount() + mRightButtonScrollAmount); mRightButtonPressed = true; } else if (getVerticalMarkerDimension().isPointInRect(x, y)) { mIsHorizontalMarkerDragged = false; mIsVerticalMarkerDragged = true; mVerticalMarkerDragOffset = y - getVerticalMarkerDimension().y; } else if (getVerticalBarDimension().isPointInRect(x,y)) { if (y < getVerticalMarkerDimension().y) { setVerticalScrollAmount(getVerticalScrollAmount() - (int)(getChildrenArea().height * 0.95)); } else { setVerticalScrollAmount(getVerticalScrollAmount() + (int)(getChildrenArea().height * 0.95)); } } else if (getHorizontalMarkerDimension().isPointInRect(x, y)) { mIsHorizontalMarkerDragged = true; mIsVerticalMarkerDragged = false; mHorizontalMarkerDragOffset = x - getHorizontalMarkerDimension().x; } else if (getHorizontalBarDimension().isPointInRect(x,y)) { if (x < getHorizontalMarkerDimension().x) { setHorizontalScrollAmount(getHorizontalScrollAmount() - (int)(getChildrenArea().width * 0.95)); } else { setHorizontalScrollAmount(getHorizontalScrollAmount() + (int)(getChildrenArea().width * 0.95)); } } // Eat the mouse mouseEvent.consume(); }