Skip to content

Commit

Permalink
Refactor|Rule: Added valuei() for accessing value as integer
Browse files Browse the repository at this point in the history
Rules are floating-point, but in many cases it is more convenient
to query the value as an integer.
  • Loading branch information
skyjake committed May 16, 2013
1 parent 5358be6 commit f2b9481
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions doomsday/libdeng2/include/de/widgets/rule.h
Expand Up @@ -70,6 +70,11 @@ class DENG2_PUBLIC Rule : public Counted, public DENG2_AUDIENCE_INTERFACE(RuleIn
*/
float value() const;

/**
* Determines the rule's current value (as integer). Otherwise same as value().
*/
int valuei() const;

/**
* Marks the rule invalid, causing all dependent rules to be invalid, too.
*/
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libdeng2/src/widgets/rootwidget.cpp
Expand Up @@ -43,8 +43,8 @@ DENG2_PIMPL_NOREF(RootWidget)

Size viewSize() const
{
return Size(de::max(0, de::floor(viewRect->right().value())),
de::max(0, de::floor(viewRect->bottom().value())));
return Size(de::max(0, viewRect->right().valuei()),
de::max(0, viewRect->bottom().valuei()));
}
};

Expand Down
6 changes: 6 additions & 0 deletions doomsday/libdeng2/src/widgets/rule.cpp
Expand Up @@ -18,6 +18,7 @@
*/

#include "de/Rule"
#include "de/math.h"
#include <set>

namespace de {
Expand Down Expand Up @@ -70,6 +71,11 @@ float Rule::value() const
return d->value;
}

int Rule::valuei() const
{
return de::floor(value());
}

void Rule::update()
{
// This is a fixed value, so don't do anything.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libshell/src/labelwidget.cpp
Expand Up @@ -110,7 +110,7 @@ void LabelWidget::update()
{
if(d->wraps.isEmpty())
{
d->updateWraps(de::floor(rule().width().value()));
d->updateWraps(rule().width().valuei());
}
}

Expand Down
3 changes: 2 additions & 1 deletion doomsday/libshell/src/lineeditwidget.cpp
Expand Up @@ -20,6 +20,7 @@
#include "de/shell/TextRootWidget"
#include "de/shell/KeyEvent"
#include "de/shell/Lexicon"
#include "de/shell/MonospaceLineWrapping"
#include <de/Rule>
#include <de/RuleRectangle>
#include <de/String>
Expand All @@ -32,7 +33,7 @@ namespace shell {
DENG2_PIMPL(LineEditWidget)
{
bool signalOnEnter;
ConstantRule *height; ///< In rows.
ConstantRule *height; ///< As rows.

Instance(Public &i)
: Base(i),
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libshell/src/logwidget.cpp
Expand Up @@ -154,7 +154,7 @@ int LogWidget::scrollPosition() const

int LogWidget::scrollPageSize() const
{
return de::max(1, de::floor(rule().height().value()) - 1);
return de::max(1, rule().height().valuei() - 1);
}

int LogWidget::maximumScroll() const
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libshell/src/textwidget.cpp
Expand Up @@ -115,8 +115,8 @@ RuleRectangle const &TextWidget::rule() const

Vector2i TextWidget::cursorPosition() const
{
return Vector2i(floor(rule().left().value()),
floor(rule().top().value()));
return Vector2i(rule().left().valuei(),
rule().top().valuei());
}

void TextWidget::addAction(Action *action)
Expand Down

0 comments on commit f2b9481

Please sign in to comment.