Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ set(mmapper_SRCS
main.cpp
adventure/AdventureLogModel.cpp
adventure/AdventureLogModel.h
font/GlyphAtlas.cpp
font/GlyphAtlas.h
adventure/adventuresession.cpp
adventure/adventuresession.h
adventure/adventuretracker.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/configuration/NamedConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NODISCARD NamedConfig final
private:
std::string m_name;
ChangeMonitor m_changeMonitor;
T m_value = 0;
T m_value{};
bool m_notifying = false;

public:
Expand Down
7 changes: 7 additions & 0 deletions src/configuration/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ ConstString KEY_USE_INTERNAL_EDITOR = "Use internal editor";
ConstString KEY_USE_TRILINEAR_FILTERING = "Use trilinear filtering";
ConstString KEY_WEATHER_ATMOSPHERE_INTENSITY = "weather.atmosphereIntensity";
ConstString KEY_WEATHER_PRECIPITATION_INTENSITY = "weather.precipitationIntensity";
ConstString KEY_MAP_FONT_FAMILY = "Map font family";
ConstString KEY_MAP_FONT_SIZE = "Map font point size";
ConstString KEY_WEATHER_TIME_OF_DAY_INTENSITY = "weather.todIntensity";
ConstString KEY_WINDOW_GEOMETRY = "Window Geometry";
ConstString KEY_WINDOW_STATE = "Window State";
Expand Down Expand Up @@ -686,6 +688,9 @@ void Configuration::CanvasSettings::read(const QSettings &conf)
.append(DEFAULT_MMAPPER_SUBDIR)
.append(DEFAULT_RESOURCES_SUBDIR))
.toString();
mapFontFamily.set(conf.value(KEY_MAP_FONT_FAMILY, mapFontFamily.get()).toString());
mapFontPointSize.set(conf.value(KEY_MAP_FONT_SIZE, mapFontPointSize.get()).toInt());
mapFontPointSize.clamp(6, 72);
showMissingMapId.set(conf.value(KEY_SHOW_MISSING_MAP_ID, true).toBool());
showUnsavedChanges.set(conf.value(KEY_SHOW_UNSAVED_CHANGES, true).toBool());
showUnmappedExits.set(conf.value(KEY_DRAW_NOT_MAPPED_EXITS, true).toBool());
Expand Down Expand Up @@ -897,6 +902,8 @@ NODISCARD static auto getQColorName(const XNamedColor &color)
void Configuration::CanvasSettings::write(QSettings &conf) const
{
conf.setValue(KEY_RESOURCES_DIRECTORY, resourcesDirectory);
conf.setValue(KEY_MAP_FONT_FAMILY, mapFontFamily.get());
conf.setValue(KEY_MAP_FONT_SIZE, mapFontPointSize.get());
conf.setValue(KEY_SHOW_MISSING_MAP_ID, showMissingMapId.get());
conf.setValue(KEY_SHOW_UNSAVED_CHANGES, showUnsavedChanges.get());
conf.setValue(KEY_DRAW_NOT_MAPPED_EXITS, showUnmappedExits.get());
Expand Down
2 changes: 2 additions & 0 deletions src/configuration/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ class NODISCARD Configuration final
NamedConfig<bool> showMissingMapId{"SHOW_MISSING_MAPID", false};
NamedConfig<bool> showUnsavedChanges{"SHOW_UNSAVED_CHANGES", false};
NamedConfig<bool> showUnmappedExits{"SHOW_UNMAPPED_EXITS", false};
NamedConfig<QString> mapFontFamily{"MAP_FONT_FAMILY", QStringLiteral("Cantarell")};
NamedConfig<int> mapFontPointSize{"MAP_FONT_POINT_SIZE", platformPointSize(11)};
bool drawUpperLayersTextured = false;
bool drawDoorNames = false;
bool softwareOpenGL = false;
Expand Down
2 changes: 1 addition & 1 deletion src/display/Characters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ void MapCanvas::drawGroupCharacters(CharacterBatch &batch, ServerRoomId yourServ
QString name = character.getLabel().isEmpty() ? character.getName().toQString()
: character.getLabel().toQString();
if (!name.isEmpty()) {
batch.drawName(pos, mmqt::toStdStringLatin1(name), color);
batch.drawName(pos, mmqt::toStdStringUtf8(name), color);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/display/Connections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void ConnectionDrawer::drawRoomDoorName(const RoomHandle &sourceRoom,
static const auto bg = Colors::black.withAlpha(0.4f);
const glm::vec3 pos{xy, static_cast<float>(m_currentLayer)};
m_roomNameBatch.emplace_back(GLText{pos,
mmqt::toStdStringLatin1(name), // GL font is latin1
mmqt::toStdStringUtf8(name),
Colors::white,
bg,
FontFormatFlags{FontFormatFlagEnum::HALIGN_CENTER}});
Expand Down
3 changes: 1 addition & 2 deletions src/display/Infomarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,8 @@ void MapCanvas::drawInfomark(InfomarksBatch &batch,
switch (infoMarkType) {
case InfomarkTypeEnum::TEXT: {
const auto utf8 = marker.getText().getStdStringViewUtf8();
const auto latin1_to_render = charset::conversion::utf8ToLatin1(utf8); // GL font is latin1
batch.renderText(pos,
latin1_to_render,
std::string{utf8},
textColor(bgColor),
bgColor,
fontFormatFlag,
Expand Down
6 changes: 6 additions & 0 deletions src/display/MapCanvasWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <QOpenGLDebugMessage>
#include <QOpenGLWindow>
#include <QScreen>
#include <QtCore>

class ConnectionSelection;
Expand Down Expand Up @@ -63,6 +64,11 @@ class NODISCARD_QOBJECT MapCanvasWindow final : public QOpenGLWindow, private Ma
// MapCanvasHost
void virt_requestCanvasUpdate() final { update(); }
NODISCARD qreal virt_hostDevicePixelRatio() const final { return devicePixelRatioF(); }
NODISCARD qreal virt_hostLogicalDpi() const final
{
const QScreen *const s = screen();
return (s != nullptr) ? s->logicalDotsPerInchY() : 96.0;
}
NODISCARD QSize virt_hostSize() const final
{
return QSize(QOpenGLWindow::width(), QOpenGLWindow::height());
Expand Down
7 changes: 7 additions & 0 deletions src/display/mapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,13 @@ void MapCanvas::screenChanged()
const auto newDpi = static_cast<float>(currentDpr());
const auto oldDpi = gl.getHostDevicePixelRatio();

// same DPR but different logical DPI (e.g. per-monitor font scaling)
if (utils::isSameFloat(newDpi, oldDpi)
&& !utils::isSameFloat(currentLogicalDpi(), getGLFont().getLogicalDpi())) {
m_pendingFontReload = true;
m_frameManager.requestUpdate();
}

if (!utils::isSameFloat(newDpi, oldDpi)) {
log(QString("Display: %1 DPI").arg(static_cast<double>(newDpi)));

Expand Down
10 changes: 10 additions & 0 deletions src/display/mapcanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class NODISCARD MapCanvasHost
// The host's current device pixel ratio.
NODISCARD qreal hostDevicePixelRatio() const { return virt_hostDevicePixelRatio(); }

// The logical DPI of the host's current screen.
NODISCARD qreal hostLogicalDpi() const { return virt_hostLogicalDpi(); }

// The host's current size in logical pixels.
NODISCARD QSize hostSize() const { return virt_hostSize(); }

Expand All @@ -92,6 +95,7 @@ class NODISCARD MapCanvasHost
private:
virtual void virt_requestCanvasUpdate() = 0;
NODISCARD virtual qreal virt_hostDevicePixelRatio() const = 0;
NODISCARD virtual qreal virt_hostLogicalDpi() const = 0;
NODISCARD virtual QSize virt_hostSize() const = 0;
virtual void virt_setHostCursor(Qt::CursorShape shape) = 0;
virtual void virt_applyPresentViewport() {}
Expand Down Expand Up @@ -204,6 +208,8 @@ class NODISCARD_QOBJECT MapCanvas final : public QObject,
bool m_pendingUpdateTextures = false;
std::optional<float> m_pendingDpr;
std::optional<float> m_pendingRenderScale;
// font preference or logical DPI changed; applied like m_pendingRenderScale
bool m_pendingFontReload = false;

// Touch long-press -> context menu. A left press synthesized from touch
// arms the timer; moving past the drag threshold or releasing disarms it
Expand Down Expand Up @@ -236,6 +242,10 @@ class NODISCARD_QOBJECT MapCanvas final : public QObject,

private:
NODISCARD qreal currentDpr() const { return m_host.hostDevicePixelRatio(); }
NODISCARD float currentLogicalDpi() const
{
return static_cast<float>(m_host.hostLogicalDpi());
}
// Configuration::canvas.renderScale (a percentage) as the factor the
// offscreen FBO is rendered at; see Legacy::Functions::setRenderScale().
NODISCARD static float configuredRenderScale();
Expand Down
23 changes: 19 additions & 4 deletions src/display/mapcanvas_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ bool MapCanvas::hostInitializeGL()
initTextures();
auto &font = getGLFont();
font.setTextureId(allocateTextureId());
font.init();
font.init(currentLogicalDpi());
updateTextures();

// compile all shaders
Expand Down Expand Up @@ -386,6 +386,14 @@ bool MapCanvas::hostInitializeGL()
this->requestUpdateTextures();
});

const auto requestFontReload = [this]() {
// Deferred like m_pendingRenderScale: needs the GL context.
m_pendingFontReload = true;
m_frameManager.requestUpdate();
};
setConfig().canvas.mapFontFamily.registerChangeCallback(m_lifetime, requestFontReload);
setConfig().canvas.mapFontPointSize.registerChangeCallback(m_lifetime, requestFontReload);

// NOTE: The host facade is responsible for connecting to
// QOpenGLContext::aboutToBeDestroyed (see MapCanvas::initializeGL()); the
// core has no notion of a QOpenGLContext or its lifetime.
Expand Down Expand Up @@ -610,7 +618,7 @@ void MapCanvas::applyPendingGLWork()
getOpenGL().setDevicePixelRatio(newDpi);
auto &font = getGLFont();
font.cleanup();
font.init();
font.init(currentLogicalDpi());
}
if (m_pendingRenderScale.has_value()) {
const float newScale = *m_pendingRenderScale;
Expand All @@ -622,14 +630,21 @@ void MapCanvas::applyPendingGLWork()
// and the FBO is sized from it.
auto &font = getGLFont();
font.cleanup();
font.init();
font.init(currentLogicalDpi());
m_batches.resetExistingMeshesButKeepPendingRemesh();
markMultisamplingDirty();
}
}
if (std::exchange(m_pendingUpdateTextures, false)) {
updateTextures();
}
if (std::exchange(m_pendingFontReload, false)) {
auto &font = getGLFont();
font.cleanup();
font.init(currentLogicalDpi());
// existing text meshes reference the old atlas
m_pendingForceUpdateMeshes = true;
}
if (std::exchange(m_pendingForceUpdateMeshes, false)) {
forceUpdateMeshes();
}
Expand Down Expand Up @@ -948,7 +963,7 @@ void MapCanvas::hostPaintGL()
auto y = lineHeight;
const auto print = [lineHeight, rightMargin, &text, &y](const QString &msg) {
text.emplace_back(glm::vec3(rightMargin, y, 0),
mmqt::toStdStringLatin1(msg), // GL font is latin1
mmqt::toStdStringUtf8(msg),
Colors::white,
Colors::black.withAlpha(0.4f),
FontFormatFlags{FontFormatFlagEnum::HALIGN_RIGHT});
Expand Down
Loading
Loading