Skip to content

Commit

Permalink
libdeng2|Shell|Refactor: Renamed RectangleRule to RuleRectangle
Browse files Browse the repository at this point in the history
RuleRectangle is a better name because the class is no longer derived
from Rule, and conceptually defines a rectangle made up from rules.
  • Loading branch information
skyjake committed Jan 30, 2013
1 parent fd106c1 commit 8511f61
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 51 deletions.
1 change: 0 additions & 1 deletion doomsday/libdeng2/include/de/RectangleRule

This file was deleted.

1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/RuleRectangle
@@ -0,0 +1 @@
#include "widgets/rulerectangle.h"
Expand Up @@ -29,17 +29,17 @@ namespace de {
/**
* A set of rules defining a rectangle.
*
* RectangleRule is not derived from Rule, but instead manages a complex
* mapping between a set of input and output rules. Note that RectangleRule is
* Instead of being derived from Rule, RuleRectangle acts as a complex mapping
* between a set of input and output Rule instances. Note that RuleRectangle is
* not reference-counted like Rule instances.
*
* RectangleRule::rect() returns the rectangle's currently valid bounds. The
* RuleRectangle::rect() returns the rectangle's currently valid bounds. The
* output rules for the sides can be used normally in other rules. Horizontal
* and vertical axes are handled independently.
*
* @ingroup widgets
*/
class DENG2_PUBLIC RectangleRule : DENG2_OBSERVES(Clock, TimeChange)
class DENG2_PUBLIC RuleRectangle : DENG2_OBSERVES(Clock, TimeChange)
{
public:
enum InputRule {
Expand All @@ -55,7 +55,7 @@ class DENG2_PUBLIC RectangleRule : DENG2_OBSERVES(Clock, TimeChange)
};

public:
RectangleRule();
RuleRectangle();

/**
* Constructs a rectangle rule with individual rules defining the placement
Expand All @@ -66,11 +66,11 @@ class DENG2_PUBLIC RectangleRule : DENG2_OBSERVES(Clock, TimeChange)
* @param right Rule for the right coordinate.
* @param bottom Rule for the bottom coordinate.
*/
RectangleRule(Rule const *left, Rule const *top, Rule const *right, Rule const *bottom);
RuleRectangle(Rule const *left, Rule const *top, Rule const *right, Rule const *bottom);

RectangleRule(RectangleRule const *rect);
RuleRectangle(RuleRectangle const *rect);

~RectangleRule();
~RuleRectangle();

// Output rules.
Rule const *left() const;
Expand All @@ -86,7 +86,7 @@ class DENG2_PUBLIC RectangleRule : DENG2_OBSERVES(Clock, TimeChange)
* @param inputRule InputRule to set.
* @param rule Rule to use as input. A reference is held.
*/
RectangleRule &setInput(InputRule inputRule, Rule const *rule);
RuleRectangle &setInput(InputRule inputRule, Rule const *rule);

/**
* Returns an input rule.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/include/de/widgets/rules.h
Expand Up @@ -22,4 +22,4 @@
#include "../DelegateRule"
#include "../ScalarRule"
#include "../OperatorRule"
#include "../RectangleRule"
#include "../RuleRectangle"
10 changes: 5 additions & 5 deletions doomsday/libdeng2/src/widgets/rootwidget.cpp
Expand Up @@ -19,19 +19,19 @@

#include "de/RootWidget"
#include "de/ConstantRule"
#include "de/RectangleRule"
#include "de/RuleRectangle"
#include "de/math.h"

namespace de {

struct RootWidget::Instance
{
RectangleRule *viewRect;
RuleRectangle *viewRect;
Widget *focus;

Instance() : focus(0)
{
viewRect = new RectangleRule(
viewRect = new RuleRectangle(
refless(new ConstantRule(0)),
refless(new ConstantRule(0)),
refless(new ConstantRule(0)),
Expand Down Expand Up @@ -85,8 +85,8 @@ Rule const *RootWidget::viewBottom() const

void RootWidget::setViewSize(Vector2i const &size)
{
d->viewRect->setInput(RectangleRule::Right, refless(new ConstantRule(size.x)));
d->viewRect->setInput(RectangleRule::Bottom, refless(new ConstantRule(size.y)));
d->viewRect->setInput(RuleRectangle::Right, refless(new ConstantRule(size.x)));
d->viewRect->setInput(RuleRectangle::Bottom, refless(new ConstantRule(size.y)));

notifyTree(&Widget::viewResized);
}
Expand Down
Expand Up @@ -17,14 +17,14 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/

#include "de/RectangleRule"
#include "de/RuleRectangle"
#include "de/DelegateRule"
#include "de/App"
#include "de/math.h"

namespace de {

struct RectangleRule::Instance : public DelegateRule::ISource
struct RuleRectangle::Instance : public DelegateRule::ISource
{
// Internal identifiers for the output rules.
enum OutputIds
Expand Down Expand Up @@ -263,64 +263,64 @@ struct RectangleRule::Instance : public DelegateRule::ISource
}
};

RectangleRule::RectangleRule() : d(new Instance)
RuleRectangle::RuleRectangle() : d(new Instance)
{}

RectangleRule::RectangleRule(Rule const *left, Rule const *top, Rule const *right, Rule const *bottom)
RuleRectangle::RuleRectangle(Rule const *left, Rule const *top, Rule const *right, Rule const *bottom)
: d(new Instance(left, top, right, bottom))
{}

RectangleRule::RectangleRule(RectangleRule const *rect)
RuleRectangle::RuleRectangle(RuleRectangle const *rect)
: d(new Instance(rect->left(), rect->top(), rect->right(), rect->bottom()))
{}

RectangleRule::~RectangleRule()
RuleRectangle::~RuleRectangle()
{
delete d;
}

Rule const *RectangleRule::left() const
Rule const *RuleRectangle::left() const
{
return d->outputRules[Instance::OutLeft];
}

Rule const *RectangleRule::top() const
Rule const *RuleRectangle::top() const
{
return d->outputRules[Instance::OutTop];
}

Rule const *RectangleRule::right() const
Rule const *RuleRectangle::right() const
{
return d->outputRules[Instance::OutRight];
}

Rule const *RectangleRule::bottom() const
Rule const *RuleRectangle::bottom() const
{
return d->outputRules[Instance::OutBottom];
}

Rule const *RectangleRule::width() const
Rule const *RuleRectangle::width() const
{
return d->outputRules[Instance::OutWidth];
}

Rule const *RectangleRule::height() const
Rule const *RuleRectangle::height() const
{
return d->outputRules[Instance::OutHeight];
}

RectangleRule &RectangleRule::setInput(InputRule inputRule, Rule const *rule)
RuleRectangle &RuleRectangle::setInput(InputRule inputRule, Rule const *rule)
{
d->setInputRule(inputRule, rule);
return *this;
}

Rule const *RectangleRule::inputRule(InputRule inputRule)
Rule const *RuleRectangle::inputRule(InputRule inputRule)
{
return d->ruleRef(inputRule);
}

void RectangleRule::setAnchorPoint(Vector2f const &normalizedPoint, TimeDelta const &transition)
void RuleRectangle::setAnchorPoint(Vector2f const &normalizedPoint, TimeDelta const &transition)
{
d->normalizedAnchorPoint.setValue(normalizedPoint, transition);
d->invalidateOutputs();
Expand All @@ -332,7 +332,7 @@ void RectangleRule::setAnchorPoint(Vector2f const &normalizedPoint, TimeDelta co
}
}

void RectangleRule::timeChanged(Clock const &clock)
void RuleRectangle::timeChanged(Clock const &clock)
{
d->invalidateOutputs();

Expand All @@ -342,13 +342,13 @@ void RectangleRule::timeChanged(Clock const &clock)
}
}

Rectanglef RectangleRule::rect() const
Rectanglef RuleRectangle::rect() const
{
return Rectanglef(Vector2f(left()->value(), top()->value()),
Vector2f(right()->value(), bottom()->value()));
}

Rectanglei RectangleRule::recti() const
Rectanglei RuleRectangle::recti() const
{
Rectanglef const r = rect();
return Rectanglei(Vector2i(de::floor(r.topLeft.x), de::floor(r.topLeft.y)),
Expand Down
6 changes: 3 additions & 3 deletions doomsday/libdeng2/widgets.pri
Expand Up @@ -5,7 +5,7 @@ HEADERS += \
include/de/ConstantRule \
include/de/Event \
include/de/OperatorRule \
include/de/RectangleRule \
include/de/RuleRectangle \
include/de/RootWidget \
include/de/ScalarRule \
include/de/Widget
Expand All @@ -17,7 +17,7 @@ HEADERS += \
include/de/widgets/delegaterule.h \
include/de/widgets/event.h \
include/de/widgets/operatorrule.h \
include/de/widgets/rectanglerule.h \
include/de/widgets/rulerectangle.h \
include/de/widgets/rootwidget.h \
include/de/widgets/rule.h \
include/de/widgets/rules.h \
Expand All @@ -29,7 +29,7 @@ SOURCES += \
src/widgets/constantrule.cpp \
src/widgets/delegaterule.cpp \
src/widgets/operatorrule.cpp \
src/widgets/rectanglerule.cpp \
src/widgets/rulerectangle.cpp \
src/widgets/rootwidget.cpp \
src/widgets/rule.cpp \
src/widgets/scalarrule.cpp \
Expand Down
8 changes: 4 additions & 4 deletions doomsday/libshell/include/de/shell/textwidget.h
Expand Up @@ -21,7 +21,7 @@

#include "libshell.h"
#include <de/Widget>
#include <de/RectangleRule>
#include <de/RuleRectangle>
#include <QObject>
#include <QFlags>
#include "TextCanvas"
Expand Down Expand Up @@ -102,11 +102,11 @@ class LIBSHELL_PUBLIC TextWidget : public QObject, public Widget
* @param rule Rectangle that the widget occupied.
* Widget takes ownership.
*/
void setRule(RectangleRule *rule);
void setRule(RuleRectangle *rule);

RectangleRule &rule();
RuleRectangle &rule();

RectangleRule const &rule() const;
RuleRectangle const &rule() const;

/**
* Returns the position of the cursor for the widget. If the widget
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libshell/src/lineeditwidget.cpp
Expand Up @@ -17,7 +17,7 @@
*/

#include <de/String>
#include <de/RectangleRule>
#include <de/RuleRectangle>
#include "de/shell/LineEditWidget"
#include "de/shell/TextRootWidget"
#include "de/shell/KeyEvent"
Expand Down Expand Up @@ -209,7 +209,7 @@ struct LineEditWidget::Instance
LineEditWidget::LineEditWidget(de::String const &name)
: TextWidget(name), d(new Instance(*this))
{
rule().setInput(RectangleRule::Height, d->height);
rule().setInput(RuleRectangle::Height, d->height);
}

LineEditWidget::~LineEditWidget()
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libshell/src/menuwidget.cpp
Expand Up @@ -107,8 +107,8 @@ struct MenuWidget::Instance
MenuWidget::MenuWidget(const String &name)
: TextWidget(name), d(new Instance(*this))
{
rule().setInput(RectangleRule::Width, d->width)
.setInput(RectangleRule::Height, d->height);
rule().setInput(RuleRectangle::Width, d->width)
.setInput(RuleRectangle::Height, d->height);
}

MenuWidget::~MenuWidget()
Expand Down
10 changes: 5 additions & 5 deletions doomsday/libshell/src/textwidget.cpp
Expand Up @@ -27,10 +27,10 @@ namespace shell {
struct TextWidget::Instance
{
TextCanvas *canvas;
RectangleRule *rule;
RuleRectangle *rule;
QList<Action *> actions;

Instance() : canvas(0), rule(new RectangleRule)
Instance() : canvas(0), rule(new RuleRectangle)
{}

~Instance()
Expand Down Expand Up @@ -85,20 +85,20 @@ void TextWidget::drawAndShow()
}
}

void TextWidget::setRule(RectangleRule *rule)
void TextWidget::setRule(RuleRectangle *rule)
{
DENG2_ASSERT(rule != 0);
delete d->rule;
d->rule = rule;
}

RectangleRule &TextWidget::rule()
RuleRectangle &TextWidget::rule()
{
DENG2_ASSERT(d->rule != 0);
return *d->rule;
}

RectangleRule const &TextWidget::rule() const
RuleRectangle const &TextWidget::rule() const
{
DENG2_ASSERT(d->rule != 0);
return *d->rule;
Expand Down
1 change: 0 additions & 1 deletion doomsday/tools/shell/shell-text/src/commandlinewidget.cpp
Expand Up @@ -18,7 +18,6 @@

#include "commandlinewidget.h"
#include <de/String>
#include <de/RectangleRule>
#include <de/shell/TextRootWidget>
#include <de/shell/KeyEvent>

Expand Down

0 comments on commit 8511f61

Please sign in to comment.