Dim the Navigation Cube when not active

Implement the InactiveOpacity option, allowing the user to dim the
navigation cube when not focused by making it transparent.
This commit is contained in:
LemonBoy
2024-01-29 11:49:24 +01:00
committed by Adrián Insaurralde Avalos
parent e40131d4b8
commit fc6d4b6d0f
6 changed files with 77 additions and 12 deletions

View File

@@ -156,7 +156,7 @@ private:
QString str(const char* str);
QMenu* createNaviCubeMenu();
void drawNaviCube(bool picking);
void drawNaviCube(bool picking, float opacity);
SbRotation getNearestOrientation(PickId pickId);
@@ -176,6 +176,7 @@ public:
std::string m_TextFont;
int m_FontWeight = 0;
int m_FontStretch = 0;
float m_InactiveOpacity = 0.5;
SbVec2s m_PosOffset = SbVec2s(0,0);
bool m_Prepared = false;
@@ -187,6 +188,7 @@ private:
bool m_MouseDown = false;
bool m_Dragging = false;
bool m_MightDrag = false;
bool m_Hovering = false;
SbVec2f m_RelPos = SbVec2f(1.0f,1.0f);
SbVec2s m_PosAreaBase = SbVec2s(0,0);
@@ -323,6 +325,11 @@ void NaviCube::setNaviCubeLabels(const std::vector<std::string>& labels)
m_NaviCubeImplementation->setLabels(labels);
}
void NaviCube::setInactiveOpacity(float opacity)
{
m_NaviCubeImplementation->m_InactiveOpacity = opacity;
}
void NaviCubeImplementation::setLabels(const std::vector<std::string>& labels)
{
m_LabelTextures[PickId::Front].label = labels[0];
@@ -701,7 +708,7 @@ void NaviCubeImplementation::drawNaviCube() {
int posX = (int)(m_RelPos[0] * m_PosAreaSize[0]) + m_PosAreaBase[0] - m_CubeWidgetSize / 2;
int posY = (int)(m_RelPos[1] * m_PosAreaSize[1]) + m_PosAreaBase[1] - m_CubeWidgetSize / 2;
glViewport(posX, posY, m_CubeWidgetSize, m_CubeWidgetSize);
drawNaviCube(false);
drawNaviCube(false, m_Hovering ? 1.f : m_InactiveOpacity);
}
void NaviCubeImplementation::createContextMenu(const std::vector<std::string>& cmd) {
@@ -726,7 +733,7 @@ void NaviCubeImplementation::handleResize() {
}
}
void NaviCubeImplementation::drawNaviCube(bool pickMode)
void NaviCubeImplementation::drawNaviCube(bool pickMode, float opacity)
{
if (!m_Prepared) {
if (!m_View3DInventorViewer->viewport())
@@ -821,13 +828,13 @@ void NaviCubeImplementation::drawNaviCube(bool pickMode)
a, a, a // 0
};
glVertexPointer(3, GL_FLOAT, 0, pointData);
glColor3f(1, 0, 0);
glColor4f(1, 0, 0, opacity);
glDrawArrays(GL_LINES, 0, 2);
glDrawArrays(GL_POINTS, 0, 2);
glColor3f(0, 1, 0);
glColor4f(0, 1, 0, opacity);
glDrawArrays(GL_LINES, 2, 2);
glDrawArrays(GL_POINTS, 2, 2);
glColor3f(0, 0, 1);
glColor4f(0, 0, 1, opacity);
glDrawArrays(GL_LINES, 4, 2);
glDrawArrays(GL_POINTS, 4, 2);
}
@@ -843,7 +850,7 @@ void NaviCubeImplementation::drawNaviCube(bool pickMode)
}
else {
QColor& c = m_HiliteId == pickId ? m_HiliteColor : m_BaseColor;
glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF());
glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF() * opacity);
}
glVertexPointer(3, GL_FLOAT, 0, f.vertexArray.data());
glDrawArrays(GL_TRIANGLE_FAN, 0, f.vertexArray.size());
@@ -855,7 +862,7 @@ void NaviCubeImplementation::drawNaviCube(bool pickMode)
auto f = pair.second;
if (f.type == ShapeId::Button)
continue;
glColor4f(cb.redF(), cb.greenF(), cb.blueF(), cb.alphaF());
glColor4f(cb.redF(), cb.greenF(), cb.blueF(), cb.alphaF() * opacity);
glVertexPointer(3, GL_FLOAT, 0, f.vertexArray.data());
glDrawArrays(GL_LINES, 0, f.vertexArray.size());
}
@@ -867,7 +874,7 @@ void NaviCubeImplementation::drawNaviCube(bool pickMode)
float texCoords[] = {0.f,0.f,1.f,0.f,1.f,1.f,0.f,1.f};
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
QColor& c = m_EmphaseColor;
glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF());
glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF() * opacity);
for (const auto& pair : m_LabelTextures) {
auto f = pair.second;
PickId pickId = pair.first;
@@ -898,12 +905,12 @@ void NaviCubeImplementation::drawNaviCube(bool pickMode)
}
else {
QColor& c = m_HiliteId == pickId ? m_HiliteColor : m_BaseColor;
glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF());
glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF() * opacity);
}
glVertexPointer(3, GL_FLOAT, 0, f.vertexArray.data());
glDrawArrays(GL_TRIANGLE_FAN, 0, f.vertexArray.size());
if (!pickMode) {
glColor4f(cb.redF(), cb.greenF(), cb.blueF(), cb.alphaF());
glColor4f(cb.redF(), cb.greenF(), cb.blueF(), cb.alphaF() * opacity);
glDrawArrays(GL_LINE_LOOP, 0, f.vertexArray.size());
}
}
@@ -923,7 +930,7 @@ NaviCubeImplementation::PickId NaviCubeImplementation::pickFace(short x, short y
glViewport(0, 0, m_CubeWidgetSize * 2, m_CubeWidgetSize * 2);
drawNaviCube(true);
drawNaviCube(true, 1.f);
glFinish();
glReadPixels(2 * x + m_CubeWidgetSize, 2 * y + m_CubeWidgetSize, 1, 1,
@@ -1106,6 +1113,14 @@ bool NaviCubeImplementation::inDragZone(short x, short y) {
}
bool NaviCubeImplementation::mouseMoved(short x, short y) {
bool hovering = std::abs(x) <= m_CubeWidgetSize / 2 &&
std::abs(y) <= m_CubeWidgetSize / 2;
if (hovering != m_Hovering) {
m_Hovering = hovering;
m_View3DInventorViewer->getSoRenderManager()->scheduleRedraw();
}
if (!m_Dragging)
setHilite(pickFace(x, y));

View File

@@ -65,6 +65,7 @@ public:
void setHiliteColor(QColor HiliteColor);
void setBorderWidth(double BorderWidth);
void setShowCS(bool showCS);
void setInactiveOpacity(float opacity);
// Label order: front, top, right, rear, bottom, left
void setNaviCubeLabels(const std::vector<std::string>& labels);
static void setNaviCubeCommands(const std::vector<std::string>& cmd);

View File

@@ -10,6 +10,7 @@
<FCInt Name="CornerNaviCube" Value="1"/>
<FCInt Name="CubeSize" Value="132"/>
<FCBool Name="NaviRotateToNearest" Value="1"/>
<FCBool Name="InactiveOpacity" Value="0.5"/>
</FCParamGroup>
<FCParamGroup Name="View">
<FCInt Name="AntiAliasing" Value="0"/>

View File

@@ -96,6 +96,7 @@ void DlgSettingsNavigation::saveSettings()
ui->naviCubeToNearest->onSave();
ui->prefCubeSize->onSave();
ui->naviCubeBaseColor->onSave();
ui->naviCubeInactiveOpacity->onSave();
bool showNaviCube = ui->groupBoxNaviCube->isChecked();
hGrp->SetBool("ShowNaviCube", showNaviCube);
@@ -141,6 +142,7 @@ void DlgSettingsNavigation::loadSettings()
ui->naviCubeToNearest->onRestore();
ui->prefCubeSize->onRestore();
ui->naviCubeBaseColor->onRestore();
ui->naviCubeInactiveOpacity->onRestore();
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/View");

View File

@@ -199,6 +199,47 @@
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLabel" name="inactiveOpacityLabel">
<property name="text">
<string>Opacity when inactive</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="Gui::PrefSpinBox" name="naviCubeInactiveOpacity">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Opacity of the navigation cube when not focused</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="suffix">
<string notr="true">%</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>InactiveOpacity</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>NaviCube</cstring>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="BaseColorLabel">
<property name="text">

View File

@@ -489,6 +489,7 @@ void NaviCubeSettings::applySettings()
parameterChanged("FontWeight");
parameterChanged("FontStretch");
parameterChanged("ShowCS");
parameterChanged("InactiveOpacity");
parameterChanged("TextFront"); // Updates all labels
}
@@ -549,6 +550,10 @@ void NaviCubeSettings::parameterChanged(const char* Name)
else if (strcmp(Name, "ShowCS") == 0) {
nc->setShowCS(hGrp->GetBool("ShowCS", true));
}
else if (strcmp(Name, "InactiveOpacity") == 0) {
float opacity = static_cast<float>(hGrp->GetInt("InactiveOpacity", 50)) / 100;
nc->setInactiveOpacity(opacity);
}
else if (strcmp(Name, "TextTop") == 0 || strcmp(Name, "TextBottom") == 0
|| strcmp(Name, "TextFront") == 0 || strcmp(Name, "TextRear") == 0
|| strcmp(Name, "TextLeft") == 0 || strcmp(Name, "TextRight") == 0) {