Skip to content

Commit

Permalink
Refactor|libshell: Use de::Rangei instead of libshell's own Range
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed May 22, 2013
1 parent eec0efc commit 861607b
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 33 deletions.
2 changes: 1 addition & 1 deletion doomsday/libshell/include/de/shell/abstractlineeditor.h
Expand Up @@ -71,7 +71,7 @@ class LIBSHELL_PUBLIC AbstractLineEditor : public ITextEditor
Vector2i lineCursorPos() const { return linePos(cursor()); }

bool isSuggestingCompletion() const;
Range completionRange() const;
Rangei completionRange() const;

/**
* Defines the terms and rules for auto-completion.
Expand Down
22 changes: 5 additions & 17 deletions doomsday/libshell/include/de/shell/libshell.h
Expand Up @@ -20,6 +20,7 @@
#define LIBSHELL_MAIN_H

#include <de/String>
#include <de/Range>

/*
* The LIBSHELL_PUBLIC macro is used for declaring exported symbols. It must be
Expand All @@ -41,26 +42,13 @@
namespace de {
namespace shell {

struct LIBSHELL_PUBLIC Range
{
int start;
int end;

Range(int a = 0, int b = 0) : start(a), end(b) {}
inline int size() const { return end - start; }
inline bool contains(int i) const { return i >= start && i < end; }
inline bool operator == (Range const &other) const {
return start == other.start && end == other.end;
}
};

/// Line of word-wrapped text.
struct LIBSHELL_PUBLIC WrappedLine
{
Range range;
Rangei range;
bool isFinal;

WrappedLine(Range const &range_, bool final = false)
WrappedLine(Rangei const &range_, bool final = false)
: range(range_), isFinal(final) {}
};

Expand All @@ -81,11 +69,11 @@ class LIBSHELL_PUBLIC ILineWrapping
virtual int height() const = 0;

/// Returns the advance width of the range.
virtual int rangeWidth(Range const &range) const = 0;
virtual int rangeWidth(Rangei const &range) const = 0;

/// Calculates which index in the provided content range occupies a
/// character at a given width.
virtual int indexAtWidth(Range const &range, int width) const = 0;
virtual int indexAtWidth(Rangei const &range, int width) const = 0;
};

} // namespace shell
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libshell/include/de/shell/monospacelinewrapping.h
Expand Up @@ -52,8 +52,8 @@ class LIBSHELL_PUBLIC MonospaceLineWrapping : public ILineWrapping
WrappedLine line(int index) const { return _lines[index]; }
int width() const;
int height() const;
int rangeWidth(Range const &range) const;
int indexAtWidth(Range const &range, int width) const;
int rangeWidth(Rangei const &range) const;
int indexAtWidth(Rangei const &range, int width) const;

private:
QList<WrappedLine> _lines;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libshell/include/de/shell/textcanvas.h
Expand Up @@ -186,7 +186,7 @@ class LIBSHELL_PUBLIC TextCanvas

void clearRichFormat();

void setRichFormatRange(Char::Attribs const &attribs, Range const &range);
void setRichFormatRange(Char::Attribs const &attribs, Rangei const &range);

void drawLineRect(Rectanglei const &rect, Char::Attribs const &attribs = Char::DefaultAttributes);

Expand Down
10 changes: 5 additions & 5 deletions doomsday/libshell/src/abstractlineeditor.cpp
Expand Up @@ -43,8 +43,8 @@ DENG2_PIMPL(AbstractLineEditor)
void reset() {
pos = size = ordinal = 0;
}
Range range() const {
return Range(pos, pos + size);
Rangei range() const {
return Rangei(pos, pos + size);
}
};
Completion completion;
Expand Down Expand Up @@ -130,8 +130,8 @@ DENG2_PIMPL(AbstractLineEditor)

DENG2_ASSERT(lineOff == 1 || lineOff == -1);

de::Vector2i const linePos = lineCursorPos();
int const destWidth = wraps->rangeWidth(Range(lineSpan(linePos.y).range.start, cursor));
Vector2i const linePos = lineCursorPos();
int const destWidth = wraps->rangeWidth(Rangei(lineSpan(linePos.y).range.start, cursor));

// Check for no room.
if(!linePos.y && lineOff < 0) return false;
Expand Down Expand Up @@ -408,7 +408,7 @@ bool AbstractLineEditor::isSuggestingCompletion() const
return d->suggestingCompletion();
}

Range AbstractLineEditor::completionRange() const
Rangei AbstractLineEditor::completionRange() const
{
return d->completion.range();
}
Expand Down
10 changes: 5 additions & 5 deletions doomsday/libshell/src/monospacelinewrapping.cpp
Expand Up @@ -57,7 +57,7 @@ void MonospaceLineWrapping::wrapTextToWidth(String const &text, int maxWidth)
if(end == text.size())
{
// Time to stop.
_lines.append(WrappedLine(Range(begin, text.size())));
_lines.append(WrappedLine(Rangei(begin, text.size())));
break;
}

Expand All @@ -76,13 +76,13 @@ void MonospaceLineWrapping::wrapTextToWidth(String const &text, int maxWidth)
if(text.at(end) == newline)
{
// The newline will be omitted from the wrapped lines.
_lines.append(WrappedLine(Range(begin, end)));
_lines.append(WrappedLine(Rangei(begin, end)));
begin = end + 1;
}
else
{
if(text.at(end).isSpace()) ++end;
_lines.append(WrappedLine(Range(begin, end)));
_lines.append(WrappedLine(Rangei(begin, end)));
begin = end;
}
}
Expand All @@ -107,12 +107,12 @@ int MonospaceLineWrapping::height() const
return _lines.size();
}

int MonospaceLineWrapping::rangeWidth(Range const &range) const
int MonospaceLineWrapping::rangeWidth(Rangei const &range) const
{
return range.size();
}

int MonospaceLineWrapping::indexAtWidth(Range const &range, int width) const
int MonospaceLineWrapping::indexAtWidth(Rangei const &range, int width) const
{
if(width <= range.size())
{
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libshell/src/textcanvas.cpp
Expand Up @@ -31,7 +31,7 @@ DENG2_PIMPL_NOREF(TextCanvas)
struct RichFormat
{
Char::Attribs attrib;
Range range;
Rangei range;
};
QList<RichFormat> richFormats;

Expand Down Expand Up @@ -206,7 +206,7 @@ void TextCanvas::clearRichFormat()
d->richFormats.clear();
}

void TextCanvas::setRichFormatRange(Char::Attribs const &attribs, Range const &range)
void TextCanvas::setRichFormatRange(Char::Attribs const &attribs, Rangei const &range)
{
Instance::RichFormat rf;
rf.attrib = attribs;
Expand Down

0 comments on commit 861607b

Please sign in to comment.