28#include <guichan/exception.hpp>
59 if (scrollBarWidth > 0)
60 setScrollbarWidth(scrollBarWidth);
65 if (
auto content = getContent())
66 content->setFrameSize(scrollAreaSkin.padding);
71 setBaseColor(gcn::Color(0, 0, 0, 0));
73 setUpButtonScrollAmount(5);
74 setDownButtonScrollAmount(5);
75 setLeftButtonScrollAmount(5);
76 setRightButtonScrollAmount(5);
84 gcn::ScrollArea::logic();
85 gcn::Widget *content = getContent();
91 if (getHorizontalScrollPolicy() == gcn::ScrollArea::SHOW_NEVER)
93 content->setWidth(getChildrenArea().width -
94 2 * content->getFrameSize());
96 if (getVerticalScrollPolicy() == gcn::ScrollArea::SHOW_NEVER)
98 content->setHeight(getChildrenArea().height -
99 2 * content->getFrameSize());
103 if (mUpButtonPressed)
105 setVerticalScrollAmount(getVerticalScrollAmount() -
106 mUpButtonScrollAmount);
108 else if (mDownButtonPressed)
110 setVerticalScrollAmount(getVerticalScrollAmount() +
111 mDownButtonScrollAmount);
113 else if (mLeftButtonPressed)
115 setHorizontalScrollAmount(getHorizontalScrollAmount() -
116 mLeftButtonScrollAmount);
118 else if (mRightButtonPressed)
120 setHorizontalScrollAmount(getHorizontalScrollAmount() +
121 mRightButtonScrollAmount);
127 if (getFrameSize() == 0)
138 const int bs = getFrameSize();
141 state.
width += bs * 2;
152 gcn::ScrollArea::drawChildren(
graphics);
162 setFrameSize(mOpaque ? skin.frameSize : 0);
170static void drawButton(gcn::Graphics *
graphics,
173 const gcn::Rectangle &dim)
217 if (
mHasMouse && (
mX > (getWidth() - getScrollbarWidth())))
226 if (
mHasMouse && (
mY > (getHeight() - getScrollbarWidth())))
238 if (
mHasMouse && (
mX > (getWidth() - getScrollbarWidth())))
247 if (state.
width == 0)
250 if (
mHasMouse && (
mY > (getHeight() - getScrollbarWidth())))
265 mHBarVisible =
false;
266 mVBarVisible =
false;
270 mHBarVisible = (mHPolicy == SHOW_ALWAYS);
271 mVBarVisible = (mVPolicy == SHOW_ALWAYS);
275 const int contentFrameSize = getContent()->getFrameSize();
276 w -= 2 * contentFrameSize;
277 h -= 2 * contentFrameSize;
279 if (mHPolicy == SHOW_AUTO &&
280 mVPolicy == SHOW_AUTO)
282 if (getContent()->getWidth() <= w
283 && getContent()->getHeight() <= h)
285 mHBarVisible =
false;
286 mVBarVisible =
false;
289 if (getContent()->getWidth() > w)
294 if ((getContent()->getHeight() > h)
295 || (mHBarVisible && getContent()->getHeight() > h - mScrollbarWidth))
300 if (mVBarVisible && getContent()->getWidth() > w - mScrollbarWidth)
311 mHBarVisible =
false;
319 if (mVPolicy == SHOW_NEVER)
321 mHBarVisible = getContent()->getWidth() > w;
325 mHBarVisible = getContent()->getWidth() > w - mScrollbarWidth;
330 throw GCN_EXCEPTION(
"Horizontal scroll policy invalid.");
336 mVBarVisible =
false;
344 if (mHPolicy == SHOW_NEVER)
346 mVBarVisible = getContent()->getHeight() > h;
350 mVBarVisible = getContent()->getHeight() > h - mScrollbarWidth;
354 throw GCN_EXCEPTION(
"Vertical scroll policy invalid.");
380 int x = mouseEvent.getX();
381 int y = mouseEvent.getY();
385 setVerticalScrollAmount(getVerticalScrollAmount()
386 - mUpButtonScrollAmount);
387 mUpButtonPressed =
true;
391 setVerticalScrollAmount(getVerticalScrollAmount()
392 + mDownButtonScrollAmount);
393 mDownButtonPressed =
true;
397 setHorizontalScrollAmount(getHorizontalScrollAmount()
398 - mLeftButtonScrollAmount);
399 mLeftButtonPressed =
true;
403 setHorizontalScrollAmount(getHorizontalScrollAmount()
404 + mRightButtonScrollAmount);
405 mRightButtonPressed =
true;
409 mIsHorizontalMarkerDragged =
false;
410 mIsVerticalMarkerDragged =
true;
418 setVerticalScrollAmount(getVerticalScrollAmount()
419 - (
int)(getChildrenArea().height * 0.95));
423 setVerticalScrollAmount(getVerticalScrollAmount()
424 + (
int)(getChildrenArea().height * 0.95));
429 mIsHorizontalMarkerDragged =
true;
430 mIsVerticalMarkerDragged =
false;
438 setHorizontalScrollAmount(getHorizontalScrollAmount()
439 - (
int)(getChildrenArea().width * 0.95));
443 setHorizontalScrollAmount(getHorizontalScrollAmount()
444 + (
int)(getChildrenArea().width * 0.95));
455 if (mIsVerticalMarkerDragged)
462 if ((barDim.height - length) > 0)
464 setVerticalScrollAmount((getVerticalMaxScroll() * pos)
465 / (barDim.height - length));
469 setVerticalScrollAmount(0);
473 if (mIsHorizontalMarkerDragged)
480 if ((barDim.width - length) > 0)
482 setHorizontalScrollAmount((getHorizontalMaxScroll() * pos)
483 / (barDim.width - length));
487 setHorizontalScrollAmount(0);
491 mouseEvent.consume();
497 return gcn::Rectangle();
499 return gcn::Rectangle(getWidth() - mScrollbarWidth, 0, mScrollbarWidth, mScrollbarWidth);
505 return gcn::Rectangle();
507 gcn::Rectangle dim(getWidth() - mScrollbarWidth,
508 getHeight() - mScrollbarWidth,
513 dim.y -= mScrollbarWidth;
521 return gcn::Rectangle();
523 return gcn::Rectangle(0, getHeight() - mScrollbarWidth, mScrollbarWidth, mScrollbarWidth);
529 return gcn::Rectangle();
531 gcn::Rectangle dim(getWidth() - mScrollbarWidth,
532 getHeight() - mScrollbarWidth,
537 dim.x -= mScrollbarWidth;
545 return gcn::Rectangle();
547 gcn::Rectangle dim(getWidth() - mScrollbarWidth,
555 dim.height -= mScrollbarWidth;
566 return gcn::Rectangle();
569 getHeight() - mScrollbarWidth,
576 dim.width -= mScrollbarWidth;
584static void getMarkerValues(
int barSize,
585 int maxScroll,
int scrollAmount,
586 int contentHeight,
int viewHeight,
587 int fixedMarkerSize,
int minMarkerSize,
588 int &markerSize,
int &markerPos)
590 if (fixedMarkerSize == 0)
592 if (contentHeight != 0 && contentHeight > viewHeight)
593 markerSize = std::max((barSize * viewHeight) / contentHeight, minMarkerSize);
595 markerSize = barSize;
599 if (contentHeight > viewHeight)
600 markerSize = fixedMarkerSize;
606 if (markerSize > barSize)
610 markerPos = ((barSize - markerSize) * scrollAmount + maxScroll / 2) / maxScroll;
618 return gcn::Rectangle();
623 int contentHeight = 0;
624 if (
auto content = getContent())
625 contentHeight = content->getHeight() + content->getFrameSize() * 2;
630 getMarkerValues(barDim.height,
631 getVerticalMaxScroll(),
632 getVerticalScrollAmount(),
634 getChildrenArea().height,
640 return gcn::Rectangle(barDim.x, barDim.y + pos, mScrollbarWidth, length);
646 return gcn::Rectangle();
651 int contentWidth = 0;
652 if (
auto content = getContent())
653 contentWidth = content->getWidth() + content->getFrameSize() * 2;
658 getMarkerValues(barDim.width,
659 getHorizontalMaxScroll(),
660 getHorizontalScrollAmount(),
662 getChildrenArea().width,
668 return gcn::Rectangle(barDim.x + pos, barDim.y, length, mScrollbarWidth);
A central point of control for graphics.
void pushClipRect(const gcn::Rectangle &rect)
Theme * getTheme() const
The global GUI theme.
const Skin & getSkin(SkinType skinType) const
void drawSkin(Graphics *graphics, SkinType type, const WidgetState &state) const