Skip to content

Commit 6f0ea10

Browse files
committed
make highlight colors configurable
1 parent 91f51ac commit 6f0ea10

File tree

11 files changed

+68
-67
lines changed

11 files changed

+68
-67
lines changed

src/configuration/configuration.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,13 +934,16 @@ void Configuration::NamedColorOptions::resetToDefaults()
934934
static const Color water{76, 216, 255}; // closest well-known color is "Malibu"
935935

936936
BACKGROUND = background;
937+
CONNECTION_NORMAL = Colors::white;
938+
HIGHLIGHT_UNSAVED = Colors::cyan;
939+
HIGHLIGHT_TEMPORARY = Colors::red;
940+
HIGHLIGHT_NEEDS_SERVER_ID = Colors::yellow;
937941
INFOMARK_COMMENT = Colors::gray75;
938942
INFOMARK_HERB = Colors::green;
939943
INFOMARK_MOB = Colors::red;
940944
INFOMARK_OBJECT = Colors::yellow;
941945
INFOMARK_RIVER = water;
942946
INFOMARK_ROAD = road;
943-
CONNECTION_NORMAL = Colors::white;
944947
ROOM_DARK = darkRoom;
945948
ROOM_NO_SUNDEATH = noSundeath;
946949
STREAM = water;

src/configuration/configuration.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,16 @@ class NODISCARD Configuration final
181181

182182
#define XFOREACH_NAMED_COLOR_OPTIONS(X) \
183183
X(BACKGROUND, BACKGROUND_NAME) \
184+
X(CONNECTION_NORMAL, CONNECTION_NORMAL_NAME) \
185+
X(HIGHLIGHT_NEEDS_SERVER_ID, "highlight-needs-server-id") \
186+
X(HIGHLIGHT_UNSAVED, "highlight-unsaved") \
187+
X(HIGHLIGHT_TEMPORARY, "highlight-temporary") \
184188
X(INFOMARK_COMMENT, "infomark-comment") \
185189
X(INFOMARK_HERB, "infomark-herb") \
186190
X(INFOMARK_MOB, "infomark-mob") \
187191
X(INFOMARK_OBJECT, "infomark-object") \
188192
X(INFOMARK_RIVER, "infomark-river") \
189193
X(INFOMARK_ROAD, "infomark-road") \
190-
X(CONNECTION_NORMAL, CONNECTION_NORMAL_NAME) \
191194
X(ROOM_DARK, ROOM_DARK_NAME) \
192195
X(ROOM_NO_SUNDEATH, ROOM_NO_SUNDEATH_NAME) \
193196
X(STREAM, "stream") \

src/display/Textures.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@ void MapCanvas::initTextures()
251251
textures.room_sel_move_bad = loadTexture(getPixmapFilenameRaw("room-sel-move-bad.png"));
252252
textures.room_sel_move_good = loadTexture(getPixmapFilenameRaw("room-sel-move-good.png"));
253253
// 256
254-
textures.room_needs_update = loadTexture(getPixmapFilenameRaw("room-needs-update.png"));
255-
textures.room_modified = loadTexture(getPixmapFilenameRaw("room-modified.png"));
254+
textures.room_highlight = loadTexture(getPixmapFilenameRaw("room-highlight.png"));
256255

257256
{
258257
textures.for_each([this](SharedMMTexture &pTex) -> void {

src/display/Textures.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ using TextureArrayNESWUD = EnumIndexedArray<SharedMMTexture, ExitDirEnum, NUM_EX
128128
X(SharedMMTexture, room_sel_distant) \
129129
X(SharedMMTexture, room_sel_move_bad) \
130130
X(SharedMMTexture, room_sel_move_good) \
131-
X(SharedMMTexture, room_needs_update) \
132-
X(SharedMMTexture, room_modified)
131+
X(SharedMMTexture, room_highlight)
133132

134133
struct NODISCARD MapCanvasTextures final
135134
{

src/display/mapcanvas.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,24 @@ class NODISCARD_QOBJECT MapCanvas final : public QOpenGLWidget,
7373
struct NODISCARD Diff final
7474
{
7575
struct NODISCARD MaybeDataOrMesh final
76-
: public std::variant<std::monostate, TexVertVector, UniqueMesh>
76+
: public std::variant<std::monostate, ColoredTexVertVector, UniqueMesh>
7777
{
7878
public:
79-
using base = std::variant<std::monostate, TexVertVector, UniqueMesh>;
79+
using base = std::variant<std::monostate, ColoredTexVertVector, UniqueMesh>;
8080
using base::base;
8181

8282
public:
8383
NODISCARD bool empty() const { return std::holds_alternative<std::monostate>(*this); }
84-
NODISCARD bool hasData() const { return std::holds_alternative<TexVertVector>(*this); }
84+
NODISCARD bool hasData() const
85+
{
86+
return std::holds_alternative<ColoredTexVertVector>(*this);
87+
}
8588
NODISCARD bool hasMesh() const { return std::holds_alternative<UniqueMesh>(*this); }
8689

8790
public:
88-
NODISCARD const TexVertVector &getData() const
91+
NODISCARD const ColoredTexVertVector &getData() const
8992
{
90-
return std::get<TexVertVector>(*this);
93+
return std::get<ColoredTexVertVector>(*this);
9194
}
9295
NODISCARD const UniqueMesh &getMesh() const { return std::get<UniqueMesh>(*this); }
9396

@@ -99,7 +102,7 @@ class NODISCARD_QOBJECT MapCanvas final : public QOpenGLWidget,
99102
}
100103

101104
if (hasData()) {
102-
*this = gl.createTexturedQuadBatch(getData(), texId);
105+
*this = gl.createColoredTexturedQuadBatch(getData(), texId);
103106
assert(hasMesh());
104107
// REVISIT: rendering immediately after uploading the mesh may lag,
105108
// so consider delaying until the data is already on the GPU.
@@ -110,17 +113,15 @@ class NODISCARD_QOBJECT MapCanvas final : public QOpenGLWidget,
110113
return;
111114
}
112115
auto &mesh = getMesh();
113-
mesh.render(
114-
GLRenderState().withColor(Colors::white).withBlend(BlendModeEnum::TRANSPARENCY));
116+
mesh.render(GLRenderState().withBlend(BlendModeEnum::TRANSPARENCY));
115117
}
116118
};
117119

118120
struct NODISCARD HighlightDiff final
119121
{
120122
Map saved;
121123
Map current;
122-
MaybeDataOrMesh needsUpdate;
123-
MaybeDataOrMesh modified;
124+
MaybeDataOrMesh highlights;
124125
};
125126

126127
std::optional<std::future<HighlightDiff>> futureHighlight;

src/display/mapcanvas_gl.cpp

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,14 @@ void MapCanvas::initializeGL()
253253

254254
setConfig().canvas.showUnsavedChanges.registerChangeCallback(m_lifetime, [this]() {
255255
if (getConfig().canvas.showUnsavedChanges.get() && m_diff.highlight.has_value()
256-
&& m_diff.highlight->modified.empty()) {
256+
&& m_diff.highlight->highlights.empty()) {
257257
this->forceUpdateMeshes();
258258
}
259259
});
260260

261261
setConfig().canvas.showMissingMapId.registerChangeCallback(m_lifetime, [this]() {
262262
if (getConfig().canvas.showMissingMapId.get() && m_diff.highlight.has_value()
263-
&& m_diff.highlight->needsUpdate.empty()) {
263+
&& m_diff.highlight->highlights.empty()) {
264264
this->forceUpdateMeshes();
265265
}
266266
});
@@ -465,7 +465,7 @@ void MapCanvas::setViewportAndMvp(int width, int height)
465465

466466
void MapCanvas::resizeGL(int width, int height)
467467
{
468-
if (m_textures.room_modified == nullptr) {
468+
if (m_textures.room_highlight == nullptr) {
469469
// resizeGL called but initializeGL was not called yet
470470
return;
471471
}
@@ -670,13 +670,20 @@ void MapCanvas::Diff::maybeAsyncUpdate(const Map &saved, const Map &current)
670670
return;
671671
}
672672

673-
const bool showNeedsServerId = getConfig().canvas.showMissingMapId.get();
674-
const bool showChanged = getConfig().canvas.showUnsavedChanges.get();
673+
const auto &config = getConfig();
674+
const auto &canvas = config.canvas;
675+
const bool showNeedsServerId = canvas.showMissingMapId.get();
676+
const bool showChanged = canvas.showUnsavedChanges.get();
677+
const auto colorSettings = config.colorSettings.clone();
675678

676679
diff.futureHighlight = std::async(
677680
std::launch::async,
678-
[saved, current, showNeedsServerId, showChanged]() -> Diff::HighlightDiff {
679-
DECL_TIMER(t2, "[async] actuallyPaintGL: highlight differences and needs update");
681+
[saved, current, showNeedsServerId, showChanged, colorSettings]() -> Diff::HighlightDiff {
682+
DECL_TIMER(t2,
683+
"[async] actuallyPaintGL: highlight changes, temporary, and needs update");
684+
685+
const auto &colors = deref(colorSettings);
686+
680687
// 3-2
681688
// |/|
682689
// 0-1
@@ -687,56 +694,49 @@ void MapCanvas::Diff::maybeAsyncUpdate(const Map &saved, const Map &current)
687694
glm::vec3{0, 1, 0},
688695
};
689696

690-
// REVISIT: Just send the position and convert from point to quad in a shader?
691-
auto getChanged = [&saved, &current, showChanged]() -> Diff::MaybeDataOrMesh {
692-
if (!showChanged) {
697+
auto getHighlights = [&saved, &current, showChanged, showNeedsServerId, &colors]()
698+
-> Diff::MaybeDataOrMesh {
699+
if (!showChanged && !showNeedsServerId) {
693700
return Diff::MaybeDataOrMesh{};
694701
}
695-
DECL_TIMER(t3, "[async] actuallyPaintGL: compute differences");
696-
TexVertVector changed;
697-
auto drawQuad = [&changed](const RawRoom &room) {
702+
703+
DECL_TIMER(t3, "[async] actuallyPaintGL: compute highlights");
704+
ColoredTexVertVector highlights;
705+
auto drawQuad = [&highlights](const RawRoom &room, const XNamedColor &color) {
698706
const auto &pos = room.getPosition().to_vec3();
699707
for (auto &corner : corners) {
700-
changed.emplace_back(corner, pos + corner);
708+
highlights.emplace_back(color.getColor(), corner, pos + corner);
701709
}
702710
};
703711

704-
ProgressCounter dummyPc;
705-
Map::foreachChangedRoom(dummyPc, saved, current, drawQuad);
706-
if (changed.empty()) {
707-
return Diff::MaybeDataOrMesh{};
712+
// Handle rooms needing a server ID or that are temporary
713+
if (showNeedsServerId) {
714+
current.getRooms().for_each([&](auto id) {
715+
if (auto h = current.getRoomHandle(id)) {
716+
if (h.isTemporary()) {
717+
drawQuad(h.getRaw(), colors.HIGHLIGHT_TEMPORARY);
718+
} else if (h.getServerId() == INVALID_SERVER_ROOMID) {
719+
drawQuad(h.getRaw(), colors.HIGHLIGHT_NEEDS_SERVER_ID);
720+
}
721+
}
722+
});
708723
}
709724

710-
return Diff::MaybeDataOrMesh{std::move(changed)};
711-
};
712-
713-
auto getNeedsUpdate = [&current, showNeedsServerId]() -> Diff::MaybeDataOrMesh {
714-
if (!showNeedsServerId) {
715-
return MapCanvas::Diff::MaybeDataOrMesh{};
725+
// Handle changed rooms
726+
if (showChanged) {
727+
ProgressCounter dummyPc;
728+
Map::foreachChangedRoom(dummyPc, saved, current, [&](const RawRoom &room) {
729+
drawQuad(room, colors.HIGHLIGHT_UNSAVED);
730+
});
716731
}
717-
DECL_TIMER(t3, "[async] actuallyPaintGL: compute needs update");
718732

719-
TexVertVector needsUpdate;
720-
auto drawQuad = [&needsUpdate](const RoomHandle &h) {
721-
const auto &pos = h.getPosition().to_vec3();
722-
for (auto &corner : corners) {
723-
needsUpdate.emplace_back(corner, pos + corner);
724-
}
725-
};
726-
current.getRooms().for_each([&current, &drawQuad](auto id) {
727-
if (auto h = current.getRoomHandle(id)) {
728-
if (h.getServerId() == INVALID_SERVER_ROOMID) {
729-
drawQuad(h);
730-
}
731-
}
732-
});
733-
if (needsUpdate.empty()) {
733+
if (highlights.empty()) {
734734
return Diff::MaybeDataOrMesh{};
735735
}
736-
return Diff::MaybeDataOrMesh{std::move(needsUpdate)};
736+
return Diff::MaybeDataOrMesh{std::move(highlights)};
737737
};
738738

739-
return Diff::HighlightDiff{saved, current, getNeedsUpdate(), getChanged()};
739+
return Diff::HighlightDiff{saved, current, getHighlights()};
740740
});
741741
}
742742

@@ -754,13 +754,8 @@ void MapCanvas::paintDifferences()
754754
auto &highlight = deref(diff.highlight);
755755
auto &gl = getOpenGL();
756756

757-
if (getConfig().canvas.showMissingMapId.get()) {
758-
if (auto &needsUpdate = highlight.needsUpdate; !needsUpdate.empty()) {
759-
needsUpdate.render(gl, m_textures.room_needs_update->getId());
760-
}
761-
}
762-
if (auto &modified = highlight.modified; !modified.empty()) {
763-
modified.render(gl, m_textures.room_modified->getId());
757+
if (auto &highlights = highlight.highlights; !highlights.empty()) {
758+
highlights.render(gl, m_textures.room_highlight->getId());
764759
}
765760
}
766761

src/opengl/OpenGLTypes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ struct NODISCARD ColoredTexVert final
4848
{}
4949
};
5050

51+
using ColoredTexVertVector = std::vector<ColoredTexVert>;
52+
5153
struct NODISCARD ColorVert final
5254
{
5355
Color color;

src/resources/mmapper2.qrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,11 @@
158158
<file>pixmaps/road-s.png</file>
159159
<file>pixmaps/road-sw.png</file>
160160
<file>pixmaps/road-w.png</file>
161+
<file>pixmaps/room-highlight.png</file>
161162
<file>pixmaps/room-sel-distant.png</file>
162163
<file>pixmaps/room-sel-move-bad.png</file>
163164
<file>pixmaps/room-sel-move-good.png</file>
164165
<file>pixmaps/room-sel.png</file>
165-
<file>pixmaps/room-modified.png</file>
166-
<file>pixmaps/room-needs-update.png</file>
167166
<file>pixmaps/stream-in-down.png</file>
168167
<file>pixmaps/stream-in-east.png</file>
169168
<file>pixmaps/stream-in-north.png</file>
624 Bytes
Loading
-3.36 KB
Binary file not shown.

0 commit comments

Comments
 (0)