Skip to content

Commit

Permalink
libappfw|Refactor: Line wrapping uses CString ranges; cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 1b910a8 commit e4fb24a
Show file tree
Hide file tree
Showing 21 changed files with 249 additions and 176 deletions.
6 changes: 2 additions & 4 deletions doomsday/libs/appfw/include/de/ui/defs.h
Expand Up @@ -24,8 +24,7 @@
#include "../libappfw.h"
#include <de/Vector>

namespace de {
namespace ui {
namespace de { namespace ui {

/**
* Basic directions.
Expand Down Expand Up @@ -130,7 +129,6 @@ enum SizePolicy {
Expand ///< Size depends on content, expands/contracts to fit.
};

} // namespace ui
} // namespace de
}} // namespace de::ui

#endif // LIBAPPFW_UI_DEFS_H
2 changes: 2 additions & 0 deletions doomsday/libs/appfw/include/de/widgets/lineeditwidget.h
Expand Up @@ -78,6 +78,8 @@ class LIBAPPFW_PUBLIC LineEditWidget : public GuiWidget, public shell::AbstractL
bool handleEvent(Event const &event) override;

public:
static shell::Key shellKey(const KeyEvent &keyEvent);

static KeyModifiers modifiersFromKeyEvent(KeyEvent::Modifiers const &keyMods);

#if defined (DE_MOBILE)
Expand Down
4 changes: 4 additions & 0 deletions doomsday/libs/appfw/src/dialogs/directorylistdialog.cpp
Expand Up @@ -80,8 +80,12 @@ DE_PIMPL(DirectoryListDialog)
groups.insert(groupId, group.release());
return groupId;
}

DE_PIMPL_AUDIENCE(Change)
};

DE_AUDIENCE_METHOD(DirectoryListDialog, Change)

DirectoryListDialog::DirectoryListDialog(String const &name)
: MessageDialog(name)
, d(new Impl(this))
Expand Down
25 changes: 9 additions & 16 deletions doomsday/libs/appfw/src/fontlinewrapping.cpp
Expand Up @@ -96,16 +96,11 @@ DE_PIMPL_NOREF(FontLineWrapping)
rasterized.clear();
}

// String rangeText(Rangei const &range) const
// {
// return text.substr(range.start, range.size());
// }

int rangeVisibleWidth(const CString &range) const
{
if (font)
{
return font->measure(range, format.subRange(range)).width();
return font->measure(format.subRange(range)).width();
}
return 0;
}
Expand All @@ -115,7 +110,7 @@ DE_PIMPL_NOREF(FontLineWrapping)
checkCancel();
if (font)
{
return font->advanceWidth(range, format.subRange(range));
return font->advanceWidth(format.subRange(range));
}
return 0;
}
Expand All @@ -131,9 +126,9 @@ DE_PIMPL_NOREF(FontLineWrapping)
if (iter.markIndent())
{
prevIndents.append(indent);
indent = origIndent + rangeAdvanceWidth(Rangei(0, iter.range().start) + range.start);
indent = origIndent + rangeAdvanceWidth({range.ptr(), iter.range().ptr()});
//Rangei(0, iter.range().start) + range.start);
}

if (iter.resetIndent())
{
if (!prevIndents.isEmpty())
Expand Down Expand Up @@ -171,7 +166,7 @@ DE_PIMPL_NOREF(FontLineWrapping)
Line *line = new Line(WrappedLine(range, width), indent);

// Determine segments in the line.
mb_iterator pos = range.begin();
const char *pos = range.begin();

Font::RichFormatRef rich = format.subRange(range);
Font::RichFormat::Iterator iter(rich);
Expand All @@ -180,22 +175,20 @@ DE_PIMPL_NOREF(FontLineWrapping)
while (iter.hasNext())
{
iter.next();

if (iter.tabStop() != tabStop)
{
int const start = range.start + iter.range().start;
const char *start = iter.range().begin();
if (start > pos)
{
line->info.segs << LineInfo::Segment(Rangei(pos, start), tabStop);
line->info.segs << LineInfo::Segment({pos, start}, tabStop);
pos = start;
}

tabStop = iter.tabStop();
}
}

// The final segment.
line->info.segs << LineInfo::Segment(Rangei(pos, range.end), tabStop);
line->info.segs << LineInfo::Segment({pos, range.end()}, tabStop);

// Determine segment widths.
if (line->info.segs.size() == 1)
Expand Down Expand Up @@ -506,7 +499,7 @@ DE_PIMPL_NOREF(FontLineWrapping)

Image rasterizeSegment(LineInfo::Segment const &segment)
{
return font->rasterize(segment.range, format.subRange(segment.range));
return font->rasterize(format.subRange(segment.range));
}
};

Expand Down
45 changes: 24 additions & 21 deletions doomsday/libs/appfw/src/gltextcomposer.cpp
Expand Up @@ -22,25 +22,26 @@ namespace de {

using namespace ui;

static const Rangei MAX_VISIBLE_RANGE(0, 0x7fffffff);

DE_PIMPL(GLTextComposer)
{
Font const *font = nullptr;
Atlas *atlas = nullptr;
String text;
static const Rangei MAX_VISIBLE_RANGE;

const Font * font = nullptr;
Atlas * atlas = nullptr;
String text;
FontLineWrapping const *wraps = nullptr;
Font::RichFormat format;
bool needRedo = false; ///< Release completely and allocate.
Rangei visibleLineRange { MAX_VISIBLE_RANGE }; ///< Only these lines will be updated/drawn.
Font::RichFormat format;
bool needRedo = false; ///< Release completely and allocate.
int maxGeneratedWidth = 0;
Rangei visibleLineRange{MAX_VISIBLE_RANGE}; ///< Only these lines will be updated/drawn.
bool visibleLineRangeChanged = false;
int maxGeneratedWidth = 0;

struct Line {
struct Segment {
Id id;
CString range;
// String text;
// CString range;
String text;
int x;
int width;
bool compressed;
Expand Down Expand Up @@ -122,13 +123,13 @@ DE_PIMPL(GLTextComposer)
}
for (int i = 0; i < info.segs.sizei(); ++i)
{
if (info.segs[i].range != lines[lineIndex].segs[i].range)
if (lines[lineIndex].segs[i].text != info.segs[i].range)
{
// Range has changed.
//qDebug() << "line" << lineIndex << "seg" << i << "range change";
return false;
}
if (segmentText(i, info) != lines[lineIndex].segs[i].text)
if (lines[lineIndex].segs[i].text != segmentText(i, info))
{
// Text has changed.
//qDebug() << "line" << lineIndex << "seg" << i << "text change";
Expand Down Expand Up @@ -184,9 +185,9 @@ DE_PIMPL(GLTextComposer)
for (int k = 0; k < info.segs.sizei(); ++k)
{
Line::Segment seg;
seg.range = info.segs[k].range;
seg.text = info.segs[k].range;
// seg.text = segmentText(k, info);
if (isLineVisible(i) && seg.range.size() > 0)
if (isLineVisible(i) && seg.text)
{
// The color is white unless a style is defined.
Vec4ub fgColor(255, 255, 255, 255);
Expand Down Expand Up @@ -350,13 +351,15 @@ DE_PIMPL(GLTextComposer)
}
};

const Rangei GLTextComposer::Impl::MAX_VISIBLE_RANGE{0, 0x7fffffff};

GLTextComposer::GLTextComposer() : d(new Impl(this))
{}

void GLTextComposer::release()
{
d->releaseLines();
setRange(MAX_VISIBLE_RANGE);
setRange(Impl::MAX_VISIBLE_RANGE);
setState(false);
}

Expand Down Expand Up @@ -452,18 +455,18 @@ void GLTextComposer::forceUpdate()
}

void GLTextComposer::makeVertices(GuiVertexBuilder &triStrip,
Vec2i const &topLeft,
Alignment const &lineAlign,
Vec4f const &color)
Vec2i const & topLeft,
Alignment const & lineAlign,
Vec4f const & color)
{
makeVertices(triStrip, Rectanglei(topLeft, topLeft), AlignTopLeft, lineAlign, color);
}

void GLTextComposer::makeVertices(GuiVertexBuilder &triStrip,
Rectanglei const &rect,
Alignment const &alignInRect,
Alignment const &lineAlign,
Vec4f const &color)
Alignment const & alignInRect,
Alignment const & lineAlign,
Vec4f const & color)
{
if (!isReady()) return;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/appfw/src/gridlayout.cpp
Expand Up @@ -534,7 +534,7 @@ void GridLayout::setModeAndGridSize(GridLayout::Mode mode, int numCols, int numR

void GridLayout::setColumnAlignment(int column, ui::Alignment cellAlign)
{
DE_ASSERT(column >= 0 && column < d->cols.size());
DE_ASSERT(column >= 0 && column < d->cols.sizei());
d->cols[column]->cellAlign = cellAlign;
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/appfw/src/vr/oculusrift.cpp
Expand Up @@ -69,7 +69,7 @@ DE_PIMPL(OculusRift)
float aspect = 1.f;

BaseWindow *window = nullptr;
QRect oldGeometry;
Rectanglei oldGeometry;

bool inited = false;
bool frameOngoing = false;
Expand Down
4 changes: 4 additions & 0 deletions doomsday/libs/appfw/src/widgets/choicewidget.cpp
Expand Up @@ -231,8 +231,12 @@ DE_GUI_PIMPL(ChoiceWidget)
i->selectionChanged(self(), selected);
}
}

DE_PIMPL_AUDIENCES(Selection, UserSelection)
};

DE_AUDIENCE_METHODS(ChoiceWidget, Selection, UserSelection)

ChoiceWidget::ChoiceWidget(String const &name)
: PopupButtonWidget(name), d(new Impl(this))
{
Expand Down
7 changes: 5 additions & 2 deletions doomsday/libs/appfw/src/widgets/directoryarraywidget.cpp
Expand Up @@ -25,7 +25,6 @@
#include <de/NativePath>
#include <de/TextValue>
#include <de/ToggleWidget>
#include <QFileDialog>

namespace de {

Expand All @@ -38,12 +37,15 @@ DirectoryArrayWidget::DirectoryArrayWidget(Variable &variable, String const &nam
: VariableArrayWidget(variable, name)
, d(new Impl)
{
addButton().setText(tr("Add Folder..."));
addButton().setText("Add Folder...");
addButton().setActionFn([this] ()
{
// Use a native dialog to select the IWAD folder.
DE_BASE_GUI_APP->beginNativeUIMode();

DE_ASSERT_FAIL("Need a file picker");

#if 0
QFileDialog dlg(nullptr, tr("Select Folder"),
Config::get().gets(CFG_LAST_FOLDER, "."), "");
dlg.setFileMode(QFileDialog::Directory);
Expand All @@ -57,6 +59,7 @@ DirectoryArrayWidget::DirectoryArrayWidget(Variable &variable, String const &nam
elementsMenu().items() << makeItem(TextValue(dir));
setVariableFromWidget();
}
#endif

DE_BASE_GUI_APP->endNativeUIMode();
});
Expand Down

0 comments on commit e4fb24a

Please sign in to comment.