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::setHorizontalScrollAmount(int hScroll) { int max = getHorizontalMaxScroll(); mHScroll = hScroll; if (hScroll > max) { mHScroll = max; } else if (hScroll < 0) { mHScroll = 0; } }
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::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); } } }