From 1b164a05fc5a2f3eea2a5e2362317d87a3f946c3 Mon Sep 17 00:00:00 2001 From: skyjake Date: Wed, 28 Aug 2013 18:54:25 +0300 Subject: [PATCH] Refactor|UI|Client|ScrollAreaWidget: Use ui::Margins The scroll area widget was using a couple of custom margin methods that are now obsolete. Also internally the widget now uses the full four-sided ui::Margins. --- .../include/ui/widgets/scrollareawidget.h | 8 --- .../client/src/ui/widgets/consolewidget.cpp | 2 +- doomsday/client/src/ui/widgets/logwidget.cpp | 2 +- .../src/ui/widgets/scrollareawidget.cpp | 52 ++++++------------- 4 files changed, 19 insertions(+), 45 deletions(-) diff --git a/doomsday/client/include/ui/widgets/scrollareawidget.h b/doomsday/client/include/ui/widgets/scrollareawidget.h index f460369ffc..ef525f464d 100644 --- a/doomsday/client/include/ui/widgets/scrollareawidget.h +++ b/doomsday/client/include/ui/widgets/scrollareawidget.h @@ -68,14 +68,6 @@ class ScrollAreaWidget : public GuiWidget de::Rectanglei viewport() const; de::Vector2i viewportSize() const; - /** - * Returns the amount of space between the top edge of the widget and the - * top edge of the content. - */ - int topMargin() const; - - int rightMargin() const; - /** * Returns the current scroll XY position, with 0 being the top/left corner * and maximumScroll() being the bottom right position. diff --git a/doomsday/client/src/ui/widgets/consolewidget.cpp b/doomsday/client/src/ui/widgets/consolewidget.cpp index a98d876ddc..40b3963b0f 100644 --- a/doomsday/client/src/ui/widgets/consolewidget.cpp +++ b/doomsday/client/src/ui/widgets/consolewidget.cpp @@ -93,7 +93,7 @@ DENG_GUI_PIMPL(ConsoleWidget) if(height->animation().target() == 0) { // On the first expansion make sure the margins are taken into account. - delta += 2 * log->topMargin(); + delta += log->margins().height().valuei(); } height->set(height->animation().target() + delta, .25f); diff --git a/doomsday/client/src/ui/widgets/logwidget.cpp b/doomsday/client/src/ui/widgets/logwidget.cpp index 06d2e6c992..82e6a9ee3a 100644 --- a/doomsday/client/src/ui/widgets/logwidget.cpp +++ b/doomsday/client/src/ui/widgets/logwidget.cpp @@ -742,7 +742,7 @@ public Font::RichFormat::IStyle { GLState &st = GLState::push(); // Leave room for the indicator in the scissor. - st.setScissor(vp.adjusted(Vector2i(), Vector2i(self.rightMargin(), 0))); + st.setScissor(vp.adjusted(Vector2i(), Vector2i(self.margins().right().valuei(), 0))); // First draw the shadow of the text. uMvpMatrix = projMatrix * Matrix4f::translate( diff --git a/doomsday/client/src/ui/widgets/scrollareawidget.cpp b/doomsday/client/src/ui/widgets/scrollareawidget.cpp index 2dc11c53c2..cbf8e55273 100644 --- a/doomsday/client/src/ui/widgets/scrollareawidget.cpp +++ b/doomsday/client/src/ui/widgets/scrollareawidget.cpp @@ -49,18 +49,13 @@ DENG_GUI_PIMPL(ScrollAreaWidget), public Lockable bool indicatorAnimating; ColorBank::Colorf accent; - Rule const *margin; - Rule const *vertMargin; - Instance(Public *i) : Base(i), origin(Top), pageKeysEnabled(true), scrollOpacity(0), scrollBarWidth(0), - indicatorAnimating(false), - margin(0), - vertMargin(0) + indicatorAnimating(false) { contentRule.setDebugName("ScrollArea-contentRule"); @@ -70,10 +65,10 @@ DENG_GUI_PIMPL(ScrollAreaWidget), public Lockable y = new ScalarRule(0); maxX = new OperatorRule(OperatorRule::Maximum, Const(0), - contentRule.width() - self.rule().width() + *margin * 2); + contentRule.width() - self.rule().width() + self.margins().width()); maxY = new OperatorRule(OperatorRule::Maximum, Const(0), - contentRule.height() - self.rule().height() + *vertMargin * 2); + contentRule.height() - self.rule().height() + self.margins().height()); } ~Instance() @@ -88,8 +83,6 @@ DENG_GUI_PIMPL(ScrollAreaWidget), public Lockable { Style const &st = style(); - margin = &st.rules().rule("gap"); - vertMargin = &st.rules().rule("gap"); scrollBarWidth = st.rules().rule("scrollarea.bar").valuei(); accent = st.colors().colorf("accent"); } @@ -114,7 +107,7 @@ ScrollAreaWidget::ScrollAreaWidget(String const &name) setBehavior(ChildHitClipping); // Link the content rule into the widget's rectangle. - d->contentRule.setInput(Rule::Left, rule().left() + *d->margin - + d->contentRule.setInput(Rule::Left, rule().left() + margins().left() - OperatorRule::minimum(*d->x, *d->maxX)); setOrigin(Top); @@ -131,7 +124,7 @@ void ScrollAreaWidget::setOrigin(Origin origin) if(origin == Top) { // Anchor content to the top of the widget. - d->contentRule.setInput(Rule::Top, rule().top() + *d->vertMargin - + d->contentRule.setInput(Rule::Top, rule().top() + margins().top() - OperatorRule::minimum(*d->y, *d->maxY)); d->contentRule.clearInput(Rule::Bottom); @@ -139,7 +132,7 @@ void ScrollAreaWidget::setOrigin(Origin origin) else { // Anchor content to the bottom of the widget. - d->contentRule.setInput(Rule::Bottom, rule().bottom() - *d->vertMargin + + d->contentRule.setInput(Rule::Bottom, rule().bottom() - margins().bottom() + OperatorRule::minimum(*d->y, *d->maxY)); d->contentRule.clearInput(Rule::Top); @@ -255,46 +248,35 @@ bool ScrollAreaWidget::isScrolling() const Rectanglei ScrollAreaWidget::viewport() const { - duint const margin = d->margin->valuei(); - duint const vertMargin = d->vertMargin->valuei(); + Vector4i const margin = margins().toVector(); - Rectanglei vp = rule().recti().moved(Vector2i(margin, vertMargin)); - if(vp.width() <= 2 * margin) + Rectanglei vp = rule().recti().moved(margin.xy()); + if(int(vp.width()) <= margin.x + margin.z) { vp.setWidth(0); } else { - vp.bottomRight.x -= 2 * margin; + vp.bottomRight.x -= margin.x + margin.z; } - if(vp.height() <= 2 * vertMargin) + if(int(vp.height()) <= margin.y + margin.w) { vp.setHeight(0); } else { - vp.bottomRight.y -= 2 * vertMargin; + vp.bottomRight.y -= margin.y + margin.w; } return vp; } Vector2i ScrollAreaWidget::viewportSize() const { - return Vector2i(rule().width().valuei() - 2 * d->margin->valuei(), - rule().height().valuei() - 2 * d->vertMargin->valuei()) + return Vector2i(rule().width().valuei() - margins().width().valuei(), + rule().height().valuei() - margins().height().valuei()) .max(Vector2i(0, 0)); } -int ScrollAreaWidget::topMargin() const -{ - return d->vertMargin->valuei(); -} - -int ScrollAreaWidget::rightMargin() const -{ - return d->margin->valuei(); -} - Vector2i ScrollAreaWidget::scrollPosition() const { DENG2_GUARD(d); @@ -441,7 +423,7 @@ void ScrollAreaWidget::glMakeScrollIndicatorGeometry(DefaultVertexBuf::Builder & if(viewSize == Vector2i(0, 0)) return; int const indHeight = de::clamp( - d->vertMargin->valuei() * 2, + margins().height().valuei(), int(float(viewSize.y * viewSize.y) / float(d->contentRule.height().value())), viewSize.y / 2); @@ -450,9 +432,9 @@ void ScrollAreaWidget::glMakeScrollIndicatorGeometry(DefaultVertexBuf::Builder & float const avail = viewSize.y - indHeight; - verts.makeQuad(Rectanglef(origin + Vector2f(viewSize.x + d->margin->value() - 2 * d->scrollBarWidth, + verts.makeQuad(Rectanglef(origin + Vector2f(viewSize.x + margins().left().value() - 2 * d->scrollBarWidth, avail - indPos * avail + indHeight), - origin + Vector2f(viewSize.x + d->margin->value() - d->scrollBarWidth, + origin + Vector2f(viewSize.x + margins().left().value() - d->scrollBarWidth, avail - indPos * avail)), Vector4f(1, 1, 1, d->scrollOpacity) * d->accent, d->indicatorUv);