void ScrollArea::drawVBar(gcn::Graphics *graphics) { const gcn::Rectangle dim = getVerticalBarDimension(); graphics->setColor(gcn::Color(0, 0, 0, 32)); graphics->fillRectangle(dim); graphics->setColor(gcn::Color(255, 255, 255)); }
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); } } }
Rectangle ScrollArea::getVerticalMarkerDimension() { if (!mVBarVisible) { return Rectangle(0, 0, 0, 0); } int length, pos; Rectangle barDim = getVerticalBarDimension(); if (getContent() && getContent()->getHeight() != 0) { length = (barDim.height * getChildrenArea().height) / getContent()->getHeight(); } else { length = barDim.height; } if (length < mScrollbarWidth) { length = mScrollbarWidth; } if (length > barDim.height) { length = barDim.height; } if (getVerticalMaxScroll() != 0) { pos = ((barDim.height - length) * getVerticalScrollAmount()) / getVerticalMaxScroll(); } else { pos = 0; } return Rectangle(barDim.x, barDim.y + pos, mScrollbarWidth, length); }
void ScrollArea::drawVBar(Graphics* graphics) { Rectangle dim = getVerticalBarDimension(); graphics->pushClipArea(dim); int alpha = getBaseColor().a; Color trackColor = getBaseColor() - 0x101010; trackColor.a = alpha; Color shadowColor = getBaseColor() - 0x303030; shadowColor.a = alpha; graphics->setColor(trackColor); graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); graphics->setColor(shadowColor); graphics->drawLine(0, 0, 0, dim.height); graphics->popClipArea(); }
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(); }