Skip to content

Commit 8d968dd

Browse files
committed
more sprites stuff
1 parent c7c7bc5 commit 8d968dd

File tree

7 files changed

+204
-132
lines changed

7 files changed

+204
-132
lines changed

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
- Frame uses exactly one comparison mask and one dynamic mask assignment.
4646
- Mask editing happens on the original (orange) frame.
4747
- Background mask is independent from mask/dynamic mask toggles.
48+
- Sprite detection area outlines must be drawn from filled masks (not line masks) to avoid double rectangles.
4849

4950
## HD/SD rules
5051
- HD is 256x64 (SD is 128x32).

app/GLCanvasWidget.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ void GLCanvasWidget::setGridScales(int topScale, int bottomScale)
122122
update();
123123
}
124124

125+
void GLCanvasWidget::setGridRegions(const QRect& topRegion, const QRect& bottomRegion)
126+
{
127+
m_gridTopRegion = topRegion;
128+
m_gridBottomRegion = bottomRegion;
129+
m_gridHasTopRegion = topRegion.isValid() && !topRegion.isEmpty();
130+
m_gridHasBottomRegion = bottomRegion.isValid() && !bottomRegion.isEmpty();
131+
update();
132+
}
133+
125134
void GLCanvasWidget::setMaskOutline(const cv::Mat& mask, const QColor& color, const QRect& region)
126135
{
127136
if (mask.empty()) {
@@ -283,14 +292,23 @@ void GLCanvasWidget::paintGL()
283292
painter.scale(m_zoom, m_zoom);
284293
const int w = m_image.cols;
285294
const int h = m_image.rows;
286-
auto drawRegion = [&](int yStart, int yEnd, int scale) {
295+
auto drawRegion = [&](int yStart, int yEnd, int scale, const QRect* regionOverride) {
287296
if (yEnd <= yStart) {
288297
return;
289298
}
299+
int xStart = 0;
300+
int xEnd = w;
301+
if (regionOverride && regionOverride->isValid() && !regionOverride->isEmpty()) {
302+
xStart = std::clamp(regionOverride->x(), 0, w);
303+
xEnd = std::clamp(regionOverride->x() + regionOverride->width(), 0, w);
304+
}
305+
if (xEnd <= xStart) {
306+
return;
307+
}
290308
painter.save();
291-
painter.setClipRect(QRectF(-w / 2.0,
309+
painter.setClipRect(QRectF(xStart - w / 2.0,
292310
yStart - h / 2.0,
293-
w,
311+
xEnd - xStart,
294312
yEnd - yStart));
295313
const double gapRatio = 0.5;
296314
const double cell = std::max(1, scale);
@@ -305,24 +323,26 @@ void GLCanvasWidget::paintGL()
305323
gridPen.setWidthF(lineWidth);
306324
gridPen.setCapStyle(Qt::SquareCap);
307325
painter.setPen(gridPen);
308-
for (int x = 0; x <= w; x += step) {
326+
for (int x = xStart; x <= xEnd; x += step) {
309327
painter.drawLine(QPointF(x - w / 2.0, yStart - h / 2.0),
310328
QPointF(x - w / 2.0, yEnd - h / 2.0));
311329
}
312330
for (int y = yStart; y <= yEnd; y += step) {
313-
painter.drawLine(QPointF(-w / 2.0, y - h / 2.0),
314-
QPointF(w / 2.0, y - h / 2.0));
331+
painter.drawLine(QPointF(xStart - w / 2.0, y - h / 2.0),
332+
QPointF(xEnd - w / 2.0, y - h / 2.0));
315333
}
316334
painter.restore();
317335
};
318336
if (m_gridTopHeight > 0 && m_gridBottomHeight > 0 &&
319337
m_gridTopHeight + m_gridGap + m_gridBottomHeight <= h) {
320-
drawRegion(0, m_gridTopHeight, m_gridTopScale);
338+
drawRegion(0, m_gridTopHeight, m_gridTopScale,
339+
m_gridHasTopRegion ? &m_gridTopRegion : nullptr);
321340
drawRegion(m_gridTopHeight + m_gridGap,
322341
m_gridTopHeight + m_gridGap + m_gridBottomHeight,
323-
m_gridBottomScale);
342+
m_gridBottomScale,
343+
m_gridHasBottomRegion ? &m_gridBottomRegion : nullptr);
324344
} else {
325-
drawRegion(0, h, 1);
345+
drawRegion(0, h, 1, nullptr);
326346
}
327347
painter.restore();
328348
}

app/GLCanvasWidget.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class GLCanvasWidget : public QOpenGLWidget, protected QOpenGLFunctions
2121
void setGridEnabled(bool enabled);
2222
void setGridSegments(int topHeight, int gapHeight, int bottomHeight);
2323
void setGridScales(int topScale, int bottomScale);
24+
void setGridRegions(const QRect& topRegion, const QRect& bottomRegion);
2425
void setMaskOutline(const cv::Mat& mask, const QColor& color, const QRect& region = QRect());
2526
void setSecondaryMaskOutline(const cv::Mat& mask, const QColor& color, const QRect& region = QRect());
2627
void setTertiaryMaskOutline(const cv::Mat& mask, const QColor& color, const QRect& region = QRect());
@@ -65,6 +66,10 @@ class GLCanvasWidget : public QOpenGLWidget, protected QOpenGLFunctions
6566
int m_gridGap = 0;
6667
int m_gridTopScale = 1;
6768
int m_gridBottomScale = 1;
69+
QRect m_gridTopRegion;
70+
QRect m_gridBottomRegion;
71+
bool m_gridHasTopRegion = false;
72+
bool m_gridHasBottomRegion = false;
6873
cv::Mat m_outlineMask;
6974
QColor m_outlineColor = QColor(200, 0, 200);
7075
bool m_outlineEnabled = false;

0 commit comments

Comments
 (0)