Skip to content
Open
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
1 change: 1 addition & 0 deletions src/configuration/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ 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<bool> showBackgroundImage{"SHOW_BACKGROUND_IMAGE", true};
bool drawUpperLayersTextured = false;
bool drawDoorNames = false;
int antialiasingSamples = 0;
Expand Down
26 changes: 26 additions & 0 deletions src/display/Textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../global/utils.h"
#include "../opengl/Font.h"
#include "../opengl/OpenGLTypes.h"
#include "../opengl/OpenGL.h"
#include "Filenames.h"
#include "RoadIndex.h"
#include "mapcanvas.h"
Expand Down Expand Up @@ -254,6 +255,16 @@ void MapCanvas::initTextures()
textures.room_needs_update = loadTexture(getPixmapFilenameRaw("room-needs-update.png"));
textures.room_modified = loadTexture(getPixmapFilenameRaw("room-modified.png"));

textures.backgroundImage = loadTexture(getPixmapFilenameRaw("background-image.png"));

if (textures.backgroundImage) {
auto &tex = deref(textures.backgroundImage);
const auto id = allocateTextureId();
tex.setId(id);
m_opengl.setTextureLookup(id, textures.backgroundImage);
}


{
textures.for_each([this](SharedMMTexture &pTex) -> void {
auto &tex = deref(pTex);
Expand Down Expand Up @@ -337,3 +348,18 @@ void MapCanvas::updateTextures()
// called to trigger an early error
std::ignore = mctp::getProxy(m_textures);
}

void MapCanvasTextures::loadCustomTexture(SharedMMTexture &dest,
const QString &name,
QOpenGLTexture::Target target,
const QImage &img)
{
auto tex = MMTexture::alloc(
target,
[=](QOpenGLTexture &qtex) {
qtex.setData(img);
},
/*forbidUpdates=*/true);

dest = tex;
}
8 changes: 8 additions & 0 deletions src/display/Textures.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ struct NODISCARD MapCanvasTextures final
XFOREACH_MAPCANVAS_TEXTURES(X_DECL)
#undef X_DECL

SharedMMTexture backgroundImage;
SharedMMTexture uploadImageToTexture(const QImage &img);

private:
template<typename Callback>
static void apply_callback(SharedMMTexture &tex, Callback &&callback)
Expand All @@ -159,6 +162,11 @@ struct NODISCARD MapCanvasTextures final
#undef X_EACH
}

void loadCustomTexture(SharedMMTexture &dest,
const QString &name,
QOpenGLTexture::Target target,
const QImage &img);

void destroyAll();
};

Expand Down
36 changes: 34 additions & 2 deletions src/display/mapcanvas_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "../opengl/FontFormatFlags.h"
#include "../opengl/OpenGL.h"
#include "../opengl/OpenGLTypes.h"
#include <QOpenGLFunctions>
#include "Connections.h"
#include "MapCanvasConfig.h"
#include "MapCanvasData.h"
Expand Down Expand Up @@ -242,6 +243,7 @@ void MapCanvas::initializeGL()

// REVISIT: should the font texture have the lowest ID?
initTextures();

auto &font = getGLFont();
font.setTextureId(allocateTextureId());
font.init();
Expand Down Expand Up @@ -581,12 +583,38 @@ void MapCanvas::finishPendingMapBatches()

void MapCanvas::actuallyPaintGL()
{
// DECL_TIMER(t, __FUNCTION__);
setViewportAndMvp(width(), height());

auto &gl = getOpenGL();
gl.clear(Color{getConfig().canvas.backgroundColor});

if (getConfig().canvas.showBackgroundImage.get()
&& m_textures.backgroundImage
&& m_textures.backgroundImage->getId() != INVALID_MM_TEXTURE_ID) {
const auto &tex = m_textures.backgroundImage;

// Z is arbitrary since we don't rely on depth testing here
const glm::vec3 topLeft{-6.f, 21.f, 0.f};
const glm::vec3 topRight{721.f, 21.f, 0.f};
const glm::vec3 bottomRight{721.f, -271.f, 0.f};
const glm::vec3 bottomLeft{-6.f, -271.f, 0.f};

const std::vector<TexVert> quadVerts = {
TexVert{glm::vec3(0.f, 1.f, 0.f), topLeft},
TexVert{glm::vec3(1.f, 1.f, 0.f), topRight},
TexVert{glm::vec3(1.f, 0.f, 0.f), bottomRight},
TexVert{glm::vec3(0.f, 0.f, 0.f), bottomLeft},
};

gl.renderTexturedQuads(
quadVerts,
GLRenderState()
.withBlend(BlendModeEnum::NONE)
.withTexture0(tex->getId())
.withColor(Color{1.0f, 1.0f, 1.0f, 1.0f}) // Fully opaque white
);
}

if (m_data.isEmpty()) {
getGLFont().renderTextCentered("No map loaded");
return;
Expand Down Expand Up @@ -1046,7 +1074,11 @@ void MapCanvas::renderMapBatches()
const int thisLayer = layer.first;
if (thisLayer == m_currentLayer) {
gl.clearDepth();
fadeBackground();

// Prevent overlay dimming if we have a custom background
if (!m_textures.backgroundImage) {
fadeBackground();
}
}
drawLayer(thisLayer, m_currentLayer);
}
Expand Down
6 changes: 6 additions & 0 deletions src/preferences/graphicspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ GraphicsPage::GraphicsPage(QWidget *parent)
&QCheckBox::stateChanged,
this,
&GraphicsPage::slot_drawUpperLayersTexturedStateChanged);
connect(ui->backgroundImageCheckBox, &QCheckBox::toggled,
[](bool checked) {
setConfig().canvas.showBackgroundImage.set(checked);
});

connect(ui->resourceLineEdit, &QLineEdit::textChanged, this, [](const QString &text) {
setConfig().canvas.resourcesDirectory = text;
Expand Down Expand Up @@ -133,6 +137,8 @@ void GraphicsPage::slot_loadConfig()
ui->drawDoorNames->setChecked(settings.drawDoorNames);

ui->resourceLineEdit->setText(settings.resourcesDirectory);

ui->backgroundImageCheckBox->setChecked(getConfig().canvas.showBackgroundImage.get());
}

void GraphicsPage::changeColorClicked(XNamedColor &namedColor, QPushButton *const pushButton)
Expand Down
18 changes: 17 additions & 1 deletion src/preferences/graphicspage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>445</width>
<height>507</height>
<height>568</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -327,6 +327,22 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_Background">
<property name="title">
<string>Map Background</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_Background">
<item>
<widget class="QCheckBox" name="backgroundImageCheckBox">
<property name="text">
<string>Show Background Image</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_Advanced">
<property name="title">
Expand Down
6 changes: 5 additions & 1 deletion src/proxy/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,11 @@ void Proxy::allocParser()

const bool endsInNewline = s.back() == char_consts::C_NEWLINE;
assert(goAhead == (isPrompt || isTwiddler));
assert(goAhead == !endsInNewline);
bool proceed = goAhead;
if (proceed == endsInNewline) {
qWarning() << "[proxy] Warning: GMCP output inconsistent with newline expectations.";
proceed = !endsInNewline; // fallback behavior
}

auto startsWithNewline = [](QStringView sv) {
if (sv.isEmpty()) {
Expand Down
5 changes: 3 additions & 2 deletions src/resources/mmapper2.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<RCC>
<qresource prefix="/">
<file>LICENSE.GLM</file>
<file>LICENSE.GPL2</file>
<file>LICENSE.LGPL</file>
Expand Down Expand Up @@ -84,6 +84,7 @@
<file>icons/viewmag+.png</file>
<file>icons/viewmag-.png</file>
<file>icons/viewmagfit.png</file>
<file>pixmaps/background-image.png</file>
<file>pixmaps/char-arrows.png</file>
<file>pixmaps/char-room-sel.png</file>
<file>pixmaps/door-down.png</file>
Expand Down
Binary file added src/resources/pixmaps/background-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.