feat: Add translucent view cube with hover opacity effect

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-02-17 16:49:49 -07:00
parent 34ecee0fa2
commit 5e20822df4
4 changed files with 25 additions and 7 deletions

View File

@@ -34,17 +34,31 @@ void ViewCube::initializeGL()
setupBuffers();
}
void ViewCube::paintGL(QOpenGLShaderProgram* simpleShader, int simpleShaderColorLoc, const QMatrix4x4& viewMatrix, int width, int height)
void ViewCube::paintGL(QOpenGLShaderProgram* simpleShader, int simpleShaderColorLoc, const QMatrix4x4& viewMatrix, int width, int height, const QPoint& mousePos)
{
int viewCubeSize = 150 * QGuiApplication::primaryScreen()->devicePixelRatio();
glViewport(width - viewCubeSize, height - viewCubeSize, viewCubeSize, viewCubeSize);
QRect viewCubeRect(width - viewCubeSize, 0, viewCubeSize, viewCubeSize);
QPoint physicalMousePos = mousePos * QGuiApplication::primaryScreen()->devicePixelRatio();
float opacity = 0.25f;
if (viewCubeRect.contains(physicalMousePos)) {
opacity = 1.0f;
}
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClear(GL_DEPTH_BUFFER_BIT);
QMatrix4x4 viewCubeProjection;
viewCubeProjection.ortho(-2, 2, -2, 2, -10, 10);
drawViewCube(viewCubeProjection, viewMatrix);
drawViewCube(viewCubeProjection, viewMatrix, opacity);
drawAxes(simpleShader, simpleShaderColorLoc, viewCubeProjection, viewMatrix);
glDisable(GL_BLEND);
}
void ViewCube::createFaceTextures()
@@ -146,7 +160,7 @@ void ViewCube::setupBuffers()
m_axesVbo.release();
}
void ViewCube::drawViewCube(const QMatrix4x4& projection, const QMatrix4x4& view)
void ViewCube::drawViewCube(const QMatrix4x4& projection, const QMatrix4x4& view, float opacity)
{
if (!m_textureShaderProgram || !m_textureShaderProgram->isLinked()) return;
@@ -155,6 +169,7 @@ void ViewCube::drawViewCube(const QMatrix4x4& projection, const QMatrix4x4& view
m_textureShaderProgram->setUniformValue("projectionMatrix", projection);
m_textureShaderProgram->setUniformValue("modelViewMatrix", view);
m_textureShaderProgram->setUniformValue("texture_diffuse1", 0);
m_textureShaderProgram->setUniformValue("opacity", opacity);
QOpenGLVertexArrayObject::Binder vaoBinder(&m_cubeVao);
for (int i = 0; i < 6; ++i) {