Configurable fade color.

This commit is contained in:
Leonardo Zide 2020-04-25 12:16:37 -07:00
parent acd7dd3f9a
commit a5fde91ee9
13 changed files with 138 additions and 135 deletions

View file

@ -22,6 +22,7 @@ void lcPreferences::LoadDefaults()
mLineWidth = lcGetProfileFloat(LC_PROFILE_LINE_WIDTH);
mAllowLOD = lcGetProfileInt(LC_PROFILE_ALLOW_LOD);
mFadeSteps = lcGetProfileInt(LC_PROFILE_FADE_STEPS);
mFadeStepsColor = lcGetProfileInt(LC_PROFILE_FADE_STEPS_COLOR);
mHighlightNewParts = lcGetProfileInt(LC_PROFILE_HIGHLIGHT_NEW_PARTS);
mHighlightNewPartsColor = lcGetProfileInt(LC_PROFILE_HIGHLIGHT_NEW_PARTS_COLOR);
mDrawGridStuds = lcGetProfileInt(LC_PROFILE_GRID_STUDS);
@ -49,6 +50,7 @@ void lcPreferences::SaveDefaults()
lcSetProfileFloat(LC_PROFILE_LINE_WIDTH, mLineWidth);
lcSetProfileInt(LC_PROFILE_ALLOW_LOD, mAllowLOD);
lcSetProfileInt(LC_PROFILE_FADE_STEPS, mFadeSteps);
lcSetProfileInt(LC_PROFILE_FADE_STEPS_COLOR, mFadeStepsColor);
lcSetProfileInt(LC_PROFILE_HIGHLIGHT_NEW_PARTS, mHighlightNewParts);
lcSetProfileInt(LC_PROFILE_HIGHLIGHT_NEW_PARTS_COLOR, mHighlightNewPartsColor);
lcSetProfileInt(LC_PROFILE_GRID_STUDS, mDrawGridStuds);

View file

@ -34,6 +34,7 @@ public:
float mLineWidth;
bool mAllowLOD;
bool mFadeSteps;
quint32 mFadeStepsColor;
bool mHighlightNewParts;
quint32 mHighlightNewPartsColor;
bool mDrawGridStuds;

View file

@ -13,13 +13,10 @@ lcVector4 gInterfaceColors[LC_NUM_INTERFACECOLORS] = // todo: make the colors co
{
lcVector4(0.898f, 0.298f, 0.400f, 1.000f), // LC_COLOR_SELECTED
lcVector4(0.400f, 0.298f, 0.898f, 1.000f), // LC_COLOR_FOCUSED
lcVector4(0.800f, 0.800f, 0.800f, 1.000f), // LC_COLOR_DISABLED
lcVector4(0.500f, 0.500f, 0.500f, 0.500f), // LC_COLOR_DISABLED_TRANSLUCENT
lcVector4(0.500f, 0.800f, 0.500f, 1.000f), // LC_COLOR_CAMERA
lcVector4(0.500f, 0.800f, 0.500f, 1.000f), // LC_COLOR_LIGHT
lcVector4(0.500f, 0.800f, 0.500f, 0.500f), // LC_COLOR_CONTROL_POINT
lcVector4(0.400f, 0.298f, 0.898f, 0.500f), // LC_COLOR_CONTROL_POINT_FOCUSED
lcVector4(0.098f, 0.898f, 0.500f, 1.000f) // LC_COLOR_HIGHLIGHT
};
static void GetToken(char*& Ptr, char* Token)

View file

@ -34,13 +34,10 @@ enum lcInterfaceColor
{
LC_COLOR_SELECTED,
LC_COLOR_FOCUSED,
LC_COLOR_DISABLED,
LC_COLOR_DISABLED_TRANSLUCENT,
LC_COLOR_CAMERA,
LC_COLOR_LIGHT,
LC_COLOR_CONTROL_POINT,
LC_COLOR_CONTROL_POINT_FOCUSED,
LC_COLOR_HIGHLIGHT,
LC_NUM_INTERFACECOLORS
};

View file

@ -509,10 +509,11 @@ void lcContext::SetColorIndexTinted(int ColorIndex, lcInterfaceColor InterfaceCo
SetColor(lcVector4(Color, gColorList[ColorIndex].Value.w));
}
void lcContext::SetColorIndexTintedAlpha(int ColorIndex, lcInterfaceColor InterfaceColor, float Weight)
void lcContext::SetColorIndexTinted(int ColorIndex, const lcVector4& Tint)
{
const lcVector3 Color(gColorList[ColorIndex].Value * Weight + gInterfaceColors[InterfaceColor] * (1.0f - Weight));
SetColor(lcVector4(Color, gColorList[ColorIndex].Value.w * gInterfaceColors[InterfaceColor].w));
const float Weight = Tint.w;
const lcVector3 Color(gColorList[ColorIndex].Value * Weight + Tint * (1.0f - Weight));
SetColor(lcVector4(Color, gColorList[ColorIndex].Value.w * Tint.w));
}
void lcContext::SetEdgeColorIndex(int ColorIndex)
@ -520,16 +521,11 @@ void lcContext::SetEdgeColorIndex(int ColorIndex)
SetColor(gColorList[ColorIndex].Edge);
}
void lcContext::SetEdgeColorIndexTinted(int ColorIndex, lcInterfaceColor InterfaceColor, float Weight)
void lcContext::SetEdgeColorIndexTinted(int ColorIndex, const lcVector4& Tint)
{
const lcVector3 Color(gColorList[ColorIndex].Edge * Weight + gInterfaceColors[InterfaceColor] * (1.0f - Weight));
SetColor(lcVector4(Color, gColorList[ColorIndex].Edge.w));
}
void lcContext::SetEdgeColorIndexTintedAlpha(int ColorIndex, lcInterfaceColor InterfaceColor, float Weight)
{
const lcVector3 Color(gColorList[ColorIndex].Edge * Weight + gInterfaceColors[InterfaceColor] * (1.0f - Weight));
SetColor(lcVector4(Color, gColorList[ColorIndex].Edge.w * gInterfaceColors[InterfaceColor].w));
const float Weight = Tint.w;
const lcVector3 Color(gColorList[ColorIndex].Edge * Weight + Tint * (1.0f - Weight));
SetColor(lcVector4(Color, gColorList[ColorIndex].Edge.w * Tint.w));
}
void lcContext::SetInterfaceColor(lcInterfaceColor InterfaceColor)

View file

@ -174,10 +174,9 @@ public:
void SetColor(float Red, float Green, float Blue, float Alpha);
void SetColorIndex(int ColorIndex);
void SetColorIndexTinted(int ColorIndex, lcInterfaceColor InterfaceColor, float Weight);
void SetColorIndexTintedAlpha(int ColorIndex, lcInterfaceColor InterfaceColor, float Weight);
void SetColorIndexTinted(int ColorIndex, const lcVector4& Tint);
void SetEdgeColorIndex(int ColorIndex);
void SetEdgeColorIndexTinted(int ColorIndex, lcInterfaceColor InterfaceColor, float Weight);
void SetEdgeColorIndexTintedAlpha(int ColorIndex, lcInterfaceColor InterfaceColor, float Weight);
void SetEdgeColorIndexTinted(int ColorIndex, const lcVector4& Tint);
void SetInterfaceColor(lcInterfaceColor InterfaceColor);
void ClearFramebuffer();

View file

@ -59,6 +59,7 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] =
lcProfileEntry("Settings", "LineWidth", 1.0f), // LC_PROFILE_LINE_WIDTH
lcProfileEntry("Settings", "AllowLOD", true), // LC_PROFILE_ALLOW_LOD
lcProfileEntry("Settings", "FadeSteps", false), // LC_PROFILE_FADE_STEPS
lcProfileEntry("Settings", "FadeStepsColor", LC_RGBA(128, 128, 128, 128)), // LC_PROFILE_FADE_STEPS_COLOR
lcProfileEntry("Settings", "HighlightNewParts", 0), // LC_PROFILE_HIGHLIGHT_NEW_PARTS
lcProfileEntry("Settings", "HighlightNewPartsColor", LC_RGBA(255, 242, 0, 192)), // LC_PROFILE_HIGHLIGHT_NEW_PARTS_COLOR
lcProfileEntry("Settings", "ShadingMode", static_cast<int>(lcShadingMode::DefaultLights)), // LC_PROFILE_SHADING_MODE

View file

@ -7,6 +7,7 @@ enum LC_PROFILE_KEY
LC_PROFILE_LINE_WIDTH,
LC_PROFILE_ALLOW_LOD,
LC_PROFILE_FADE_STEPS,
LC_PROFILE_FADE_STEPS_COLOR,
LC_PROFILE_HIGHLIGHT_NEW_PARTS,
LC_PROFILE_HIGHLIGHT_NEW_PARTS_COLOR,
LC_PROFILE_SHADING_MODE,

View file

@ -7,8 +7,6 @@
#include "lc_application.h"
#include "object.h"
bool gTranslucentFade = true; // todo: move to preferences
lcScene::lcScene()
: mRenderMeshes(0, 1024), mOpaqueMeshes(0, 1024), mTranslucentMeshes(0, 1024), mInterfaceObjects(0, 1024)
{
@ -24,12 +22,17 @@ void lcScene::Begin(const lcMatrix44& ViewMatrix)
{
mViewMatrix = ViewMatrix;
mActiveSubmodelInstance = nullptr;
mHasFadedParts = false;
mPreTranslucentCallback = nullptr;
mRenderMeshes.RemoveAll();
mOpaqueMeshes.RemoveAll();
mTranslucentMeshes.RemoveAll();
mInterfaceObjects.RemoveAll();
const lcPreferences& Preferences = lcGetPreferences();
mHighlightColor = lcVector4FromColor(Preferences.mHighlightNewPartsColor);
mFadeColor = lcVector4FromColor(Preferences.mFadeStepsColor);
mHasFadedParts = false;
mTranslucentFade = mFadeColor.w != 1.0f;
}
void lcScene::End()
@ -69,7 +72,7 @@ void lcScene::AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorInde
const float Distance = fabsf(lcMul31(WorldMatrix[3], mViewMatrix).z);
RenderMesh.LodIndex = mAllowLOD ? RenderMesh.Mesh->GetLodIndex(Distance) : LC_MESH_LOD_HIGH;
const bool ForceTranslucent = (gTranslucentFade && State == lcRenderMeshState::Faded);
const bool ForceTranslucent = (mTranslucentFade && State == lcRenderMeshState::Faded);
const bool Translucent = lcIsColorTranslucent(ColorIndex) || ForceTranslucent;
const lcMeshFlags Flags = Mesh->mFlags;
mHasFadedParts |= State == lcRenderMeshState::Faded;
@ -192,9 +195,9 @@ void lcScene::DrawOpaqueMeshes(lcContext* Context, bool DrawLit, int PrimitiveTy
break;
case lcRenderMeshState::Faded:
if (gTranslucentFade)
if (mTranslucentFade)
continue;
Context->SetColorIndexTinted(ColorIndex, LC_COLOR_DISABLED, 0.25f);
Context->SetColorIndexTinted(ColorIndex, mFadeColor);
break;
}
}
@ -218,14 +221,11 @@ void lcScene::DrawOpaqueMeshes(lcContext* Context, bool DrawLit, int PrimitiveTy
break;
case lcRenderMeshState::Highlighted:
Context->SetColor(lcVector4FromColor(lcGetPreferences().mHighlightNewPartsColor));
Context->SetColor(mHighlightColor);
break;
case lcRenderMeshState::Faded:
if (gTranslucentFade)
Context->SetEdgeColorIndexTintedAlpha(ColorIndex, LC_COLOR_DISABLED_TRANSLUCENT, 0.25f);
else
Context->SetEdgeColorIndexTinted(ColorIndex, LC_COLOR_DISABLED, 0.25f);
Context->SetEdgeColorIndexTinted(ColorIndex, mFadeColor);
break;
}
}
@ -370,10 +370,7 @@ void lcScene::DrawTranslucentMeshes(lcContext* Context, bool DrawLit, bool DrawF
break;
case lcRenderMeshState::Faded:
if (gTranslucentFade)
Context->SetColorIndexTintedAlpha(ColorIndex, LC_COLOR_DISABLED_TRANSLUCENT, 0.25f);
else
Context->SetColorIndexTinted(ColorIndex, LC_COLOR_DISABLED, 0.25f);
Context->SetColorIndexTinted(ColorIndex, mFadeColor);
break;
}
@ -452,7 +449,7 @@ void lcScene::Draw(lcContext* Context) const
const int SolidPrimitiveTypes = LC_MESH_TRIANGLES | LC_MESH_TEXTURED_TRIANGLES;
if (gTranslucentFade && mHasFadedParts)
if (mTranslucentFade && mHasFadedParts)
{
DrawOpaqueMeshes(Context, false, SolidPrimitiveTypes | LinePrimitiveTypes, false, true);
@ -485,7 +482,7 @@ void lcScene::Draw(lcContext* Context) const
if (DrawConditional)
LinePrimitiveTypes |= LC_MESH_CONDITIONAL_LINES;
if (gTranslucentFade && mHasFadedParts)
if (mTranslucentFade && mHasFadedParts)
{
DrawOpaqueMeshes(Context, true, LC_MESH_TRIANGLES | LC_MESH_TEXTURED_TRIANGLES, false, true);

View file

@ -102,7 +102,11 @@ protected:
bool mDrawInterface;
bool mAllowWireframe;
bool mAllowLOD;
lcVector4 mFadeColor;
lcVector4 mHighlightColor;
bool mHasFadedParts;
bool mTranslucentFade;
std::function<void()> mPreTranslucentCallback;
lcArray<lcRenderMesh> mRenderMeshes;

View file

@ -29,6 +29,7 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO
#endif
ui->lineWidth->setValidator(new QDoubleValidator(ui->lineWidth));
connect(ui->FadeStepsColor, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
connect(ui->HighlightNewPartsColor, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
connect(ui->gridStudColor, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
connect(ui->gridLineColor, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
@ -112,6 +113,9 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO
QPixmap pix(12, 12);
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mFadeStepsColor), LC_RGBA_GREEN(mOptions->Preferences.mFadeStepsColor), LC_RGBA_BLUE(mOptions->Preferences.mFadeStepsColor)));
ui->FadeStepsColor->setIcon(pix);
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mHighlightNewPartsColor), LC_RGBA_GREEN(mOptions->Preferences.mHighlightNewPartsColor), LC_RGBA_BLUE(mOptions->Preferences.mHighlightNewPartsColor)));
ui->HighlightNewPartsColor->setIcon(pix);
@ -133,6 +137,7 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO
on_studLogo_toggled();
on_antiAliasing_toggled();
on_edgeLines_toggled();
on_FadeSteps_toggled();
on_HighlightNewParts_toggled();
on_gridStuds_toggled();
on_gridLines_toggled();
@ -299,7 +304,13 @@ void lcQPreferencesDialog::ColorButtonClicked()
quint32* Color = nullptr;
QColorDialog::ColorDialogOptions DialogOptions;
if (Button == ui->HighlightNewPartsColor)
if (Button == ui->FadeStepsColor)
{
Color = &mOptions->Preferences.mFadeStepsColor;
Title = tr("Select Fade Color");
DialogOptions = QColorDialog::ShowAlphaChannel;
}
else if (Button == ui->HighlightNewPartsColor)
{
Color = &mOptions->Preferences.mHighlightNewPartsColor;
Title = tr("Select Highlight Color");
@ -367,6 +378,11 @@ void lcQPreferencesDialog::on_edgeLines_toggled()
ui->lineWidth->setEnabled(ui->edgeLines->isChecked());
}
void lcQPreferencesDialog::on_FadeSteps_toggled()
{
ui->FadeStepsColor->setEnabled(ui->FadeSteps->isChecked());
}
void lcQPreferencesDialog::on_HighlightNewParts_toggled()
{
ui->HighlightNewPartsColor->setEnabled(ui->HighlightNewParts->isChecked());

View file

@ -35,6 +35,7 @@ public slots:
void ColorButtonClicked();
void on_antiAliasing_toggled();
void on_edgeLines_toggled();
void on_FadeSteps_toggled();
void on_HighlightNewParts_toggled();
void on_gridStuds_toggled();
void on_gridLines_toggled();

View file

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>598</width>
<height>489</height>
<height>492</height>
</rect>
</property>
<property name="windowTitle">
@ -304,6 +304,13 @@
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QGridLayout" name="gridLayout">
<item row="6" column="0">
<widget class="QCheckBox" name="HighlightNewParts">
<property name="text">
<string>Highlight new parts</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="antiAliasingSamples">
<item>
@ -323,53 +330,23 @@
</item>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Shading Mode:</string>
<item row="0" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>width</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineWidth">
<property name="maximumSize">
<property name="sizeHint" stdset="0">
<size>
<width>75</width>
<height>16777215</height>
<width>40</width>
<height>20</height>
</size>
</property>
</widget>
</spacer>
</item>
<item row="8" column="1" colspan="2">
<widget class="QComboBox" name="ShadingMode">
<item>
<property name="text">
<string>Wireframe</string>
</property>
</item>
<item>
<property name="text">
<string>Flat Shading</string>
</property>
</item>
<item>
<property name="text">
<string>Default Lights</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="antiAliasing">
<item row="1" column="0">
<widget class="QCheckBox" name="studLogo">
<property name="text">
<string>Anti-aliasing</string>
<string>Stud Logo</string>
</property>
</widget>
</item>
@ -402,33 +379,6 @@
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="studLogo">
<property name="text">
<string>Stud Logo</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="axisIcon">
<property name="text">
<string>Axis icon</string>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="edgeLines">
<property name="text">
@ -436,10 +386,20 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="FadeSteps">
<item row="2" column="1">
<widget class="QLineEdit" name="lineWidth">
<property name="maximumSize">
<size>
<width>75</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="antiAliasing">
<property name="text">
<string>Fade Previous Steps</string>
<string>Anti-aliasing</string>
</property>
</widget>
</item>
@ -450,36 +410,66 @@
</property>
</widget>
</item>
<item row="7" column="0" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item row="8" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Shading Mode:</string>
</property>
</widget>
</item>
<item row="8" column="1" colspan="2">
<widget class="QComboBox" name="ShadingMode">
<item>
<widget class="QCheckBox" name="HighlightNewParts">
<property name="text">
<string>Highlight new parts</string>
</property>
</widget>
<property name="text">
<string>Wireframe</string>
</property>
</item>
<item>
<widget class="QToolButton" name="HighlightNewPartsColor">
<property name="text">
<string/>
</property>
</widget>
<property name="text">
<string>Flat Shading</string>
</property>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
<property name="text">
<string>Default Lights</string>
</property>
</item>
</layout>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>width</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="axisIcon">
<property name="text">
<string>Axis icon</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="FadeSteps">
<property name="text">
<string>Fade previous steps</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QToolButton" name="FadeStepsColor">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QToolButton" name="HighlightNewPartsColor">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
@ -1229,6 +1219,7 @@
<tabstop>MeshLOD</tabstop>
<tabstop>axisIcon</tabstop>
<tabstop>FadeSteps</tabstop>
<tabstop>FadeStepsColor</tabstop>
<tabstop>HighlightNewParts</tabstop>
<tabstop>HighlightNewPartsColor</tabstop>
<tabstop>ShadingMode</tabstop>