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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user