From 861607b3fbdace50b2f0b2879c0eff69b915974f Mon Sep 17 00:00:00 2001 From: skyjake Date: Wed, 22 May 2013 19:56:35 +0300 Subject: [PATCH] Refactor|libshell: Use de::Rangei instead of libshell's own Range --- .../include/de/shell/abstractlineeditor.h | 2 +- doomsday/libshell/include/de/shell/libshell.h | 22 +++++-------------- .../include/de/shell/monospacelinewrapping.h | 4 ++-- .../libshell/include/de/shell/textcanvas.h | 2 +- doomsday/libshell/src/abstractlineeditor.cpp | 10 ++++----- .../libshell/src/monospacelinewrapping.cpp | 10 ++++----- doomsday/libshell/src/textcanvas.cpp | 4 ++-- 7 files changed, 21 insertions(+), 33 deletions(-) diff --git a/doomsday/libshell/include/de/shell/abstractlineeditor.h b/doomsday/libshell/include/de/shell/abstractlineeditor.h index 4c8792b099..13e6804433 100644 --- a/doomsday/libshell/include/de/shell/abstractlineeditor.h +++ b/doomsday/libshell/include/de/shell/abstractlineeditor.h @@ -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. diff --git a/doomsday/libshell/include/de/shell/libshell.h b/doomsday/libshell/include/de/shell/libshell.h index e5c3ebef23..517c7cc516 100644 --- a/doomsday/libshell/include/de/shell/libshell.h +++ b/doomsday/libshell/include/de/shell/libshell.h @@ -20,6 +20,7 @@ #define LIBSHELL_MAIN_H #include +#include /* * The LIBSHELL_PUBLIC macro is used for declaring exported symbols. It must be @@ -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) {} }; @@ -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 diff --git a/doomsday/libshell/include/de/shell/monospacelinewrapping.h b/doomsday/libshell/include/de/shell/monospacelinewrapping.h index 94b6c43b3a..6765ed0cc9 100644 --- a/doomsday/libshell/include/de/shell/monospacelinewrapping.h +++ b/doomsday/libshell/include/de/shell/monospacelinewrapping.h @@ -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 _lines; diff --git a/doomsday/libshell/include/de/shell/textcanvas.h b/doomsday/libshell/include/de/shell/textcanvas.h index 3c23967fc2..a0251387de 100644 --- a/doomsday/libshell/include/de/shell/textcanvas.h +++ b/doomsday/libshell/include/de/shell/textcanvas.h @@ -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); diff --git a/doomsday/libshell/src/abstractlineeditor.cpp b/doomsday/libshell/src/abstractlineeditor.cpp index b0facf16a9..0ff7a9d5ea 100644 --- a/doomsday/libshell/src/abstractlineeditor.cpp +++ b/doomsday/libshell/src/abstractlineeditor.cpp @@ -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; @@ -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; @@ -408,7 +408,7 @@ bool AbstractLineEditor::isSuggestingCompletion() const return d->suggestingCompletion(); } -Range AbstractLineEditor::completionRange() const +Rangei AbstractLineEditor::completionRange() const { return d->completion.range(); } diff --git a/doomsday/libshell/src/monospacelinewrapping.cpp b/doomsday/libshell/src/monospacelinewrapping.cpp index 312b012c74..99b6a886da 100644 --- a/doomsday/libshell/src/monospacelinewrapping.cpp +++ b/doomsday/libshell/src/monospacelinewrapping.cpp @@ -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; } @@ -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; } } @@ -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()) { diff --git a/doomsday/libshell/src/textcanvas.cpp b/doomsday/libshell/src/textcanvas.cpp index 8f05a61334..179af2815d 100644 --- a/doomsday/libshell/src/textcanvas.cpp +++ b/doomsday/libshell/src/textcanvas.cpp @@ -31,7 +31,7 @@ DENG2_PIMPL_NOREF(TextCanvas) struct RichFormat { Char::Attribs attrib; - Range range; + Rangei range; }; QList richFormats; @@ -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;