refactor: Move axis label drawing logic from ViewportWidget to SketchGrid
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
#include "SketchGrid.h"
|
||||
#include "ViewportWidget.h"
|
||||
#include <QOpenGLContext>
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <QOpenGLShaderProgram>
|
||||
#include <QPainter>
|
||||
#include <QVector>
|
||||
|
||||
SketchGrid::SketchGrid()
|
||||
SketchGrid::SketchGrid(ViewportWidget* viewport) : m_viewport(viewport)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -123,3 +125,36 @@ void SketchGrid::drawAxes(SketchPlane plane, QOpenGLShaderProgram* shaderProgram
|
||||
m_vbo.allocate(vertices.constData(), vertices.size() * sizeof(GLfloat));
|
||||
glDrawArrays(GL_POINTS, 0, 1);
|
||||
}
|
||||
|
||||
void SketchGrid::paintAxisLabels(QPainter& painter, SketchGrid::SketchPlane plane, const QMatrix4x4& modelView, const QMatrix4x4& projection)
|
||||
{
|
||||
painter.setPen(Qt::white);
|
||||
painter.setFont(QFont("Arial", 10));
|
||||
|
||||
const int range = 50;
|
||||
const int step = 5;
|
||||
|
||||
auto drawLabelsForAxis = [&](int axis_idx) {
|
||||
for (int i = -range; i <= range; i += step) {
|
||||
if (i == 0) continue;
|
||||
QVector3D worldCoord;
|
||||
worldCoord[axis_idx] = i;
|
||||
|
||||
QVector3D screenPos = m_viewport->project(worldCoord, modelView, projection, m_viewport->rect());
|
||||
if (screenPos.z() < 1.0f) { // Not clipped
|
||||
painter.drawText(screenPos.toPoint(), QString::number(i));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (plane == SketchGrid::XY) {
|
||||
drawLabelsForAxis(0); // X
|
||||
drawLabelsForAxis(2); // Y
|
||||
} else if (plane == SketchGrid::XZ) {
|
||||
drawLabelsForAxis(0); // X
|
||||
drawLabelsForAxis(1); // Z
|
||||
} else if (plane == SketchGrid::YZ) {
|
||||
drawLabelsForAxis(1); // Y
|
||||
drawLabelsForAxis(2); // Z
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user