Skip to content

Commit

Permalink
libappfw: Pixel ratio moved to libgui; updated text wrapping code
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent ed1d044 commit e4c6bf2
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 56 deletions.
13 changes: 9 additions & 4 deletions doomsday/libs/appfw/CMakeLists.txt
Expand Up @@ -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 ()
4 changes: 2 additions & 2 deletions doomsday/libs/appfw/include/de/framework/fontlinewrapping.h
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/appfw/include/de/framework/gltextcomposer.h
Expand Up @@ -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.
Expand Down
28 changes: 2 additions & 26 deletions doomsday/libs/appfw/src/baseguiapp.cpp
Expand Up @@ -31,11 +31,6 @@
#include <de/ScriptSystem>
#include <de/Font>

#ifdef WIN32
# define CONST const
# include <d2d1.h>
#endif

namespace de {

static Value *Function_App_LoadFont(Context &, Function::ArgumentValues const &args)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
{
Expand Down
15 changes: 15 additions & 0 deletions doomsday/libs/appfw/src/fontlinewrapping.cpp
Expand Up @@ -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))
{
Expand Down
10 changes: 5 additions & 5 deletions doomsday/libs/appfw/src/gltextcomposer.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions doomsday/libs/appfw/src/guirootwidget.cpp
Expand Up @@ -62,58 +62,58 @@ 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);
// painter.setBrush(Qt::NoBrush);
// 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);
// painter.setPen(QPen(Qt::white, DPI_SCALED(2)));
// 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);
// painter.setPen(Qt::NoPen);
// 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);
// painter.setPen(Qt::NoPen);
// 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 {
Expand Down
9 changes: 5 additions & 4 deletions doomsday/libs/appfw/src/textdrawable.cpp
Expand Up @@ -112,7 +112,7 @@ DE_PIMPL(TextDrawable)

struct Wrapper : public FontLineWrapping
{
String plainText;
// String text;
Font::RichFormat format;
};

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libs/appfw/src/windowsystem.cpp
Expand Up @@ -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
Expand Down

0 comments on commit e4c6bf2

Please sign in to comment.