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) {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <QMatrix4x4>
|
||||
#include <QOpenGLVertexArrayObject>
|
||||
#include <QOpenGLBuffer>
|
||||
#include <QPoint>
|
||||
|
||||
class QOpenGLShaderProgram;
|
||||
class QOpenGLTexture;
|
||||
@@ -16,13 +17,13 @@ public:
|
||||
~ViewCube();
|
||||
|
||||
void initializeGL();
|
||||
void paintGL(QOpenGLShaderProgram* simpleShader, int simpleShaderColorLoc, const QMatrix4x4& viewMatrix, int width, int height);
|
||||
void paintGL(QOpenGLShaderProgram* simpleShader, int simpleShaderColorLoc, const QMatrix4x4& viewMatrix, int width, int height, const QPoint& mousePos);
|
||||
|
||||
private:
|
||||
void createFaceTextures();
|
||||
void initShaders();
|
||||
void setupBuffers();
|
||||
void drawViewCube(const QMatrix4x4& projection, const QMatrix4x4& view);
|
||||
void drawViewCube(const QMatrix4x4& projection, const QMatrix4x4& view, float opacity);
|
||||
void drawAxes(QOpenGLShaderProgram* simpleShader, int colorLoc, const QMatrix4x4& projection, const QMatrix4x4& view);
|
||||
|
||||
QOpenGLTexture* m_faceTextures[6];
|
||||
|
||||
@@ -191,7 +191,7 @@ void ViewportWidget::paintGL()
|
||||
QMatrix4x4 viewCubeModel;
|
||||
viewCubeModel.rotate(m_camera->xRotation() / 16.0f, 1, 0, 0);
|
||||
viewCubeModel.rotate(m_camera->yRotation() / 16.0f, 0, 1, 0);
|
||||
m_viewCube->paintGL(m_shaderProgram, m_colorLoc, viewCubeModel, width() * retinaScale, height() * retinaScale);
|
||||
m_viewCube->paintGL(m_shaderProgram, m_colorLoc, viewCubeModel, width() * retinaScale, height() * retinaScale, m_currentMousePos);
|
||||
|
||||
glViewport(0, 0, width() * retinaScale, height() * retinaScale);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
@@ -5,8 +5,10 @@ out vec4 FragColor;
|
||||
in vec2 TexCoord;
|
||||
|
||||
uniform sampler2D texture_diffuse1;
|
||||
uniform float opacity;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(texture_diffuse1, TexCoord);
|
||||
vec4 texColor = texture(texture_diffuse1, TexCoord);
|
||||
FragColor = vec4(texColor.rgb, texColor.a * opacity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user