diff --git a/doomsday/libs/appfw/CMakeLists.txt b/doomsday/libs/appfw/CMakeLists.txt index 6f40bfab6a..219887e82a 100644 --- a/doomsday/libs/appfw/CMakeLists.txt +++ b/doomsday/libs/appfw/CMakeLists.txt @@ -34,11 +34,16 @@ target_link_libraries (libappfw if (TARGET LibOVR) target_link_libraries (libappfw PRIVATE LibOVR) endif () -if (WIN32) - # Direct2D is used for DPI information. - target_link_libraries (libappfw PRIVATE d2d1.lib) -endif () deng_deploy_library (libappfw DengAppfw) deng_cotire (libappfw src/precompiled.h) + +if (DE_ENABLE_TESTS) + set (appfwTests + test_appfw + ) + foreach (test ${appfwTests}) + add_subdirectory (../../tests/${test} ${CMAKE_CURRENT_BINARY_DIR}/${test}) + endforeach (test) +endif () diff --git a/doomsday/libs/appfw/include/de/framework/fontlinewrapping.h b/doomsday/libs/appfw/include/de/framework/fontlinewrapping.h index de872fa51f..090b739bb0 100644 --- a/doomsday/libs/appfw/include/de/framework/fontlinewrapping.h +++ b/doomsday/libs/appfw/include/de/framework/fontlinewrapping.h @@ -65,8 +65,8 @@ class LIBAPPFW_PUBLIC FontLineWrapping : public Lockable, public shell::ILineWra */ void reset(); - void wrapTextToWidth(String const &text, WrapWidth maxWidth) override; - void wrapTextToWidth(String const &text, Font::RichFormat const &format, WrapWidth maxWidth); + void wrapTextToWidth(const String &text, WrapWidth maxWidth) override; + void wrapTextToWidth(const String &text, const Font::RichFormat &format, WrapWidth maxWidth); void rasterizeLines(Rangei const &lineRange); void clearRasterizedLines() const; diff --git a/doomsday/libs/appfw/include/de/framework/gltextcomposer.h b/doomsday/libs/appfw/include/de/framework/gltextcomposer.h index 878a2f3dc0..b9aeaa9eb1 100644 --- a/doomsday/libs/appfw/include/de/framework/gltextcomposer.h +++ b/doomsday/libs/appfw/include/de/framework/gltextcomposer.h @@ -48,7 +48,7 @@ class LIBAPPFW_PUBLIC GLTextComposer : public Asset void setText(String const &text); void setStyledText(String const &styledText); - void setText(String const &text, Font::RichFormat const &format); + void setText(/*String const &text, */Font::RichFormat const &format); /** * Sets the range of visible lines. diff --git a/doomsday/libs/appfw/src/baseguiapp.cpp b/doomsday/libs/appfw/src/baseguiapp.cpp index f5c00bb229..a5b8d363a9 100644 --- a/doomsday/libs/appfw/src/baseguiapp.cpp +++ b/doomsday/libs/appfw/src/baseguiapp.cpp @@ -31,11 +31,6 @@ #include #include -#ifdef WIN32 -# define CONST const -# include -#endif - namespace de { static Value *Function_App_LoadFont(Context &, Function::ArgumentValues const &args) @@ -101,24 +96,6 @@ DE_PIMPL(BaseGuiApp) float windowPixelRatio = 1.0f; ///< Without user's Config.ui.scaleConfig ConstantRule *pixelRatio = new ConstantRule; - Impl(Public *i) : Base(i) - { -#if defined(WIN32) - // Use the Direct2D API to find out the desktop pixel ratio. - ID2D1Factory *d2dFactory = nullptr; - HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &d2dFactory); - if (SUCCEEDED(hr)) - { - FLOAT dpiX = 96; - FLOAT dpiY = 96; - d2dFactory->GetDesktopDpi(&dpiX, &dpiY); - windowPixelRatio = dpiX / 96.0; - d2dFactory->Release(); - d2dFactory = nullptr; - } -#endif - } - ~Impl() override { releaseRef(pixelRatio); @@ -150,9 +127,8 @@ void BaseGuiApp::initSubsystems(SubsystemInitFlags flags) { GuiApp::initSubsystems(flags); -#if !defined(WIN32) - d->windowPixelRatio = float(devicePixelRatio()); -#endif + // FIXME: (rebasing) This was probably moved elsewhere? + // The "-dpi" option overrides the detected pixel ratio. if (auto dpi = commandLine().check("-dpi", 1)) { diff --git a/doomsday/libs/appfw/src/fontlinewrapping.cpp b/doomsday/libs/appfw/src/fontlinewrapping.cpp index 6d6f88029e..43e67e1e2d 100644 --- a/doomsday/libs/appfw/src/fontlinewrapping.cpp +++ b/doomsday/libs/appfw/src/fontlinewrapping.cpp @@ -565,6 +565,21 @@ void FontLineWrapping::wrapTextToWidth(const String &text, const Font::RichForma d->text = text; d->format = format; +#if defined (DE_DEBUG) + { + // Ensure the format refers to the correct string. + Font::RichFormat::Iterator iter(format); + while (iter.hasNext()) + { + iter.next(); + DE_ASSERT(iter.range().ptr() >= text.data()); + DE_ASSERT(iter.range().ptr() < text.data() + text.size()); + DE_ASSERT(iter.range().endPtr() >= text.data()); + DE_ASSERT(iter.range().endPtr() <= text.data() + text.size()); + } + } +#endif + // When tabs are used, we must first determine the maximum width of each tab stop. if (d->containsTabs(text)) { diff --git a/doomsday/libs/appfw/src/gltextcomposer.cpp b/doomsday/libs/appfw/src/gltextcomposer.cpp index 75e541f2aa..26d7230d2b 100644 --- a/doomsday/libs/appfw/src/gltextcomposer.cpp +++ b/doomsday/libs/appfw/src/gltextcomposer.cpp @@ -28,7 +28,7 @@ DE_PIMPL(GLTextComposer) const Font * font = nullptr; Atlas * atlas = nullptr; - String text; +// String text; FontLineWrapping const *wraps = nullptr; Font::RichFormat format; bool needRedo = false; ///< Release completely and allocate. @@ -385,20 +385,20 @@ void GLTextComposer::setWrapping(FontLineWrapping const &wrappedLines) void GLTextComposer::setText(String const &text) { - setText(text, Font::RichFormat::fromPlainText(text)); + setText(Font::RichFormat::fromPlainText(text)); } void GLTextComposer::setStyledText(String const &styledText) { d->format.clear(); - d->text = d->format.initFromStyledText(styledText); + d->format.initFromStyledText(styledText); d->needRedo = true; setState(false); } -void GLTextComposer::setText(String const &text, Font::RichFormat const &format) +void GLTextComposer::setText(/*String const &text, */Font::RichFormat const &format) { - d->text = text; +// d->text = text; d->format = format; d->needRedo = true; setState(false); diff --git a/doomsday/libs/appfw/src/guirootwidget.cpp b/doomsday/libs/appfw/src/guirootwidget.cpp index 6012058f45..cd16af15f8 100644 --- a/doomsday/libs/appfw/src/guirootwidget.cpp +++ b/doomsday/libs/appfw/src/guirootwidget.cpp @@ -62,7 +62,7 @@ DE_PIMPL(GuiRootWidget) }; struct ThinCornersImage : public TextureBank::ImageSource { Image load() const { -// QImage img(QSize(DPI_SCALED_INT(15), DPI_SCALED_INT(15)), QImage::Format_ARGB32); + Image img(Image::Size(DPI_SCALED_INT(15), DPI_SCALED_INT(15)), Image::RGBA_8888); // img.fill(QColor(255, 255, 255, 0).rgba()); // QPainter painter(&img); // painter.setRenderHint(QPainter::Antialiasing, true); @@ -70,13 +70,13 @@ DE_PIMPL(GuiRootWidget) // painter.setPen(QPen(Qt::white, DPI_SCALED(1))); // painter.drawEllipse(DPI_SCALED(QPointF(8, 8)), DPI_SCALED(6), DPI_SCALED(6)); // return img; - DE_ASSERT_FAIL("Need to load style image") - return {}; +// DE_ASSERT_FAIL("Need to load style image") + return img; } }; struct BoldCornersImage : public TextureBank::ImageSource { Image load() const { -// QImage img(QSize(DPI_SCALED_INT(12), DPI_SCALED_INT(12)), QImage::Format_ARGB32); + Image img(Image::Size(DPI_SCALED_INT(12), DPI_SCALED_INT(12)), Image::RGBA_8888); // img.fill(QColor(255, 255, 255, 0).rgba()); // QPainter painter(&img); // painter.setRenderHint(QPainter::Antialiasing, true); @@ -84,13 +84,13 @@ DE_PIMPL(GuiRootWidget) // painter.setBrush(Qt::NoBrush); // painter.drawEllipse(DPI_SCALED(QPointF(6, 6)), DPI_SCALED(4), DPI_SCALED(4)); // return img; - DE_ASSERT_FAIL("Need to load style image") - return {}; +// DE_ASSERT_FAIL("Need to load style image") + return img; } }; struct SolidRoundedImage : public TextureBank::ImageSource { Image load() const { -// QImage img(QSize(DPI_SCALED_INT(12), DPI_SCALED_INT(12)), QImage::Format_ARGB32); + Image img(Image::Size(DPI_SCALED_INT(12), DPI_SCALED_INT(12)), Image::RGBA_8888); // img.fill(QColor(255, 255, 255, 0).rgba()); // QPainter painter(&img); // painter.setRenderHint(QPainter::Antialiasing, true); @@ -98,13 +98,13 @@ DE_PIMPL(GuiRootWidget) // painter.setBrush(Qt::white); // painter.drawEllipse(DPI_SCALED(QPointF(6, 6)), DPI_SCALED(6), DPI_SCALED(6)); // return img; - DE_ASSERT_FAIL("Need to load style image") - return {}; +// DE_ASSERT_FAIL("Need to load style image") + return img; } }; struct TinyDotImage : public TextureBank::ImageSource { Image load() const { -// QImage img(QSize(DPI_SCALED_INT(5), DPI_SCALED_INT(5)), QImage::Format_ARGB32); + Image img(Image::Size(DPI_SCALED_INT(5), DPI_SCALED_INT(5)), Image::RGBA_8888); // img.fill(QColor(255, 255, 255, 0).rgba()); // QPainter painter(&img); // painter.setRenderHint(QPainter::Antialiasing, true); @@ -112,8 +112,8 @@ DE_PIMPL(GuiRootWidget) // painter.setBrush(Qt::white); // painter.drawEllipse(DPI_SCALED(QPointF(2.5, 2.5)), DPI_SCALED(2), DPI_SCALED(2)); // return img; - DE_ASSERT_FAIL("Need to load style image") - return {}; +// DE_ASSERT_FAIL("Need to load style image") + return img; } }; struct StyleImage : public TextureBank::ImageSource { diff --git a/doomsday/libs/appfw/src/textdrawable.cpp b/doomsday/libs/appfw/src/textdrawable.cpp index 714e71415d..dc4b73df40 100644 --- a/doomsday/libs/appfw/src/textdrawable.cpp +++ b/doomsday/libs/appfw/src/textdrawable.cpp @@ -112,7 +112,7 @@ DE_PIMPL(TextDrawable) struct Wrapper : public FontLineWrapping { - String plainText; +// String text; Font::RichFormat format; }; @@ -170,11 +170,12 @@ DE_PIMPL(TextDrawable) { _wrapper->format.setStyle(*_style); } - _wrapper->plainText = _wrapper->format.initFromStyledText(_text); +// _wrapper->text = _text; + _wrapper->format.initFromStyledText(_text); // This is where most of the time will be spent: //qDebug() << "wrapping" << _wrapper->plainText << "to" << _width; - _wrapper->wrapTextToWidth(_wrapper->plainText, _wrapper->format, _width); + _wrapper->wrapTextToWidth(_text, _wrapper->format, _width); // Pre-rasterize the first lines of the text. The assumption is that // longer text will only be visible after scrolling, so it will be @@ -278,7 +279,7 @@ DE_PIMPL(TextDrawable) DE_ASSERT(visibleWrap != nullptr); self().setWrapping(*visibleWrap); - self().GLTextComposer::setText(visibleWrap->plainText, visibleWrap->format); + self().GLTextComposer::setText(visibleWrap->format); return true; } diff --git a/doomsday/libs/appfw/src/windowsystem.cpp b/doomsday/libs/appfw/src/windowsystem.cpp index e6bc73045c..cbec0f34d3 100644 --- a/doomsday/libs/appfw/src/windowsystem.cpp +++ b/doomsday/libs/appfw/src/windowsystem.cpp @@ -95,13 +95,13 @@ void WindowSystem::addWindow(String const &id, BaseWindow *window) bool WindowSystem::mainExists() // static { - return get().d->windows.contains("main"); + return get().d->windows.contains(DE_STR("main")); } BaseWindow &WindowSystem::main() // static { DE_ASSERT(mainExists()); - return *get().d->windows.find("main")->second; + return *get().d->windows.find(DE_STR("main"))->second; } BaseWindow *WindowSystem::find(String const &id) const