Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/frontend/StarChatBubbleSeparation.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-27 00:42:07 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-27 00:42:07 +1000
commit63b68b3a55a11b32b07e7b8bdbf3760722d5e7f9 (patch)
treea6e9f0b6005d20fe69a00e1a585502c7b73461cd /source/frontend/StarChatBubbleSeparation.cpp
parent94c84ad01333850b88091f2c188e4f6173fd25e7 (diff)
Nameplate and chat bubble improvements
They should stack much better now. I also hooked up the true mouth position to the name-tag, but it's too shaky on chat bubbles.
Diffstat (limited to 'source/frontend/StarChatBubbleSeparation.cpp')
-rw-r--r--source/frontend/StarChatBubbleSeparation.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/source/frontend/StarChatBubbleSeparation.cpp b/source/frontend/StarChatBubbleSeparation.cpp
index 568ca37..23a34fe 100644
--- a/source/frontend/StarChatBubbleSeparation.cpp
+++ b/source/frontend/StarChatBubbleSeparation.cpp
@@ -1,4 +1,5 @@
#include "StarChatBubbleSeparation.hpp"
+#include "StarLogging.hpp"
namespace Star {
@@ -21,7 +22,7 @@ bool compareOverlapRight(RectF const& newBox, RectF const& fixedBox) {
template <typename Compare>
void appendHorizontalOverlaps(List<RectF>& overlaps,
List<RectF> const& boxes,
- List<RectF>::iterator leftBound,
+ List<RectF>::const_iterator leftBound,
Compare compare,
RectF const& box) {
auto i = leftBound;
@@ -36,7 +37,7 @@ void appendHorizontalOverlaps(List<RectF>& overlaps,
}
}
-RectF separateBubble(List<RectF>& sortedLeftEdges, List<RectF>& sortedRightEdges, RectF box) {
+RectF separateBubble(List<RectF> const& sortedLeftEdges, List<RectF> const& sortedRightEdges, List<RectF>& outLeftEdges, List<RectF>& outRightEdges, RectF box) {
// We have to maintain two lists of boxes: one sorted by the left edges and
// one
// by the right edges. This is because boxes can be different sizes, and
@@ -54,19 +55,33 @@ RectF separateBubble(List<RectF>& sortedLeftEdges, List<RectF>& sortedRightEdges
// overlap with 'box'.
while (true) {
- // While box is overlapping any other boxes, raise its Y value.
- List<RectF> overlappingBoxes =
- horizontalOverlaps.filtered([&box](RectF const& overlapper) { return box.intersects(overlapper, false); });
+ // While box is overlapping any other boxes, move it halfway away.
+ List<RectF> overlappingBoxes = horizontalOverlaps.filtered([&box](RectF const& overlapper) {
+ if (overlapper.intersects(box, false)) {
+ Vec2F oSize = overlapper.size(), bSize = box.size();
+ if (oSize[0] == bSize[0]) {
+ if (oSize[1] == bSize[1])
+ return overlapper.center()[1] <= box.center()[1];
+ else
+ return oSize[1] > bSize[1];
+ }
+ else if (oSize[0] > bSize[0])
+ return true;
+ }
+ return false;
+ });
if (overlappingBoxes.empty())
break;
RectF overlapBoundBox = fold(overlappingBoxes, box, [](RectF const& a, RectF const& b) { return a.combined(b); });
+ SpatialLogger::logPoly("screen", PolyF(box), { 255, 0, 0, 255 });
+ SpatialLogger::logPoly("screen", PolyF(overlapBoundBox), { 0, 0, 255, 255 });
auto height = box.height();
box.setYMin(overlapBoundBox.yMax());
box.setYMax(box.yMin() + height);
}
- sortedLeftEdges.insertSorted(box, compareLeft);
- sortedRightEdges.insertSorted(box, compareRight);
+ outLeftEdges.append(box);
+ outRightEdges.append(box);
return box;
}