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 FFScrollArea::keyPressed(gcn::KeyEvent &keyEvent) { if (keyEvent.isConsumed()) { return; } if (keyEvent.getKey().getValue() == gcn::Key::Down) { setVerticalScrollAmount(getVerticalScrollAmount() + 16); } else if (keyEvent.getKey().getValue() == gcn::Key::Up) { setVerticalScrollAmount(getVerticalScrollAmount() - 16); } }
void ScrollArea::mouseWheelDown(int x, int y) { if (hasMouse()) { setVerticalScrollAmount(getVerticalScrollAmount() + getContentDimension().height / 8); } }
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::mouseWheelMovedDown(MouseEvent& mouseEvent) { if (mouseEvent.isConsumed()) { return; } setVerticalScrollAmount(getVerticalScrollAmount() + getChildrenArea().height / 8); mouseEvent.consume(); }
void ScrollArea::showWidgetPart(Widget* widget, Rectangle area) { if (widget != getContent()) { throw GCN_EXCEPTION("Widget not content widget"); } BasicContainer::showWidgetPart(widget, area); setHorizontalScrollAmount(getContent()->getFrameSize() - getContent()->getX()); setVerticalScrollAmount(getContent()->getFrameSize() - getContent()->getY()); }
void ScrollArea::mouseDragged(MouseEvent& mouseEvent) { if (mIsVerticalMarkerDragged) { int pos = mouseEvent.getY() - getVerticalBarDimension().y - mVerticalMarkerDragOffset; int length = getVerticalMarkerDimension().height; Rectangle barDim = getVerticalBarDimension(); if ((barDim.height - length) > 0) { setVerticalScrollAmount((getVerticalMaxScroll() * pos) / (barDim.height - length)); } else { setVerticalScrollAmount(0); } } if (mIsHorizontalMarkerDragged) { int pos = mouseEvent.getX() - getHorizontalBarDimension().x - mHorizontalMarkerDragOffset; int length = getHorizontalMarkerDimension().width; Rectangle barDim = getHorizontalBarDimension(); if ((barDim.width - length) > 0) { setHorizontalScrollAmount((getHorizontalMaxScroll() * pos) / (barDim.width - length)); } else { setHorizontalScrollAmount(0); } } mouseEvent.consume(); }
void ScrollArea::logic() { checkPolicies(); setVerticalScrollAmount(getVerticalScrollAmount()); setHorizontalScrollAmount(getHorizontalScrollAmount()); if (getContent() != NULL) { getContent()->setPosition(-mHScroll + getContent()->getFrameSize(), -mVScroll + getContent()->getFrameSize()); getContent()->logic(); } }
void ScrollArea::mouseMotion(int x, int y) { if (mVerticalMarkerPressed) { int pos = y - getVerticalBarDimension().y - mVerticalMarkerMousePosition; int length = getVerticalMarkerDimension().height; Rectangle barDim = getVerticalBarDimension(); if ((barDim.height - length) > 0) { setVerticalScrollAmount((getVerticalMaxScroll() * pos) / (barDim.height - length)); } else { setVerticalScrollAmount(0); } } if (mHorizontalMarkerPressed) { int pos = x - getHorizontalBarDimension().x - mHorizontalMarkerMousePosition; int length = getHorizontalMarkerDimension().width; Rectangle barDim = getHorizontalBarDimension(); if ((barDim.width - length) > 0) { setHorizontalScrollAmount((getHorizontalMaxScroll() * pos) / (barDim.width - length)); } else { setHorizontalScrollAmount(0); } } }
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(); } }
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(); }
void ScrollArea::setScrollAmount(int hScroll, int vScroll) { setHorizontalScrollAmount(hScroll); setVerticalScrollAmount(vScroll); }