diff --git a/common/lc_colors.cpp b/common/lc_colors.cpp index 7b85c86d..175a4ba0 100644 --- a/common/lc_colors.cpp +++ b/common/lc_colors.cpp @@ -213,21 +213,21 @@ int lcGetBrickLinkColor(int ColorIndex) static void lcAdjustStudStyleColors(std::vector& Colors, lcStudStyle StudStyle) { const lcPreferences& Preferences = lcGetPreferences(); + if (!Preferences.mAutomateEdgeColor && StudStyle != lcStudStyle::HighContrast && StudStyle != lcStudStyle::HighContrastLogo) + return; + const float LDIndex = LC_SRGB_TO_LINEAR(Preferences.mPartColorValueLDIndex); + const lcVector4 Edge = lcVector4FromColor(Preferences.mPartEdgeColor); + const lcVector4 DarkEdge = lcVector4FromColor(Preferences.mDarkEdgeColor); + const lcVector4 BlackEdge = lcVector4FromColor(Preferences.mBlackEdgeColor); - if (Preferences.mAutomateEdgeColor) + for (lcColor& Color : Colors) { - for (lcColor& Color : Colors) + float ValueLuminescence = lcLuminescenceFromRGBA(Color.Value); + + if (Preferences.mAutomateEdgeColor) { - if (Color.Code == 4242) - continue; - float EdgeLuminescence = 0.0f; - float r = LC_SRGB_TO_LINEAR(Color.Value[0]); - float g = LC_SRGB_TO_LINEAR(Color.Value[1]); - float b = LC_SRGB_TO_LINEAR(Color.Value[2]); - - float ValueLuminescence = 0.2126f * r + 0.7152f * g + 0.0722f * b; if (ValueLuminescence > LDIndex) EdgeLuminescence = ValueLuminescence - (ValueLuminescence * Preferences.mPartEdgeContrast); @@ -238,26 +238,17 @@ static void lcAdjustStudStyleColors(std::vector& Colors, lcStudStyle St Color.Edge = lcVector4(EdgeLuminescence, EdgeLuminescence, EdgeLuminescence, 1.0f); } - - return; - } - - if (StudStyle != lcStudStyle::HighContrast && StudStyle != lcStudStyle::HighContrastLogo) - return; - - const lcVector4 Edge = lcVector4FromColor(Preferences.mPartEdgeColor); - const lcVector4 DarkEdge = lcVector4FromColor(Preferences.mDarkEdgeColor); - const lcVector4 BlackEdge = lcVector4FromColor(Preferences.mBlackEdgeColor); - - for (lcColor& Color : Colors) - { - const lcVector4 FillColor = Color.Value * 255.0f; - if (30.0f * FillColor[0] + 59.0f * FillColor[1] + 11.0f * FillColor[2] <= 3600.0f) - Color.Edge = DarkEdge; - else if (Color.Code == 0) - Color.Edge = BlackEdge; else - Color.Edge = Edge; + { + if (Color.Code == 4242) + continue; + else if (Color.Code == 0) + Color.Edge = BlackEdge; + else if (ValueLuminescence < LDIndex) + Color.Edge = DarkEdge; + else + Color.Edge = Edge; + } } } @@ -355,7 +346,7 @@ static std::vector lcParseColorFile(lcFile& File) Color.Group = LC_COLORGROUP_SPECIAL; } else if (!strcmp(Token, "CHROME") || !strcmp(Token, "PEARLESCENT") || !strcmp(Token, "RUBBER") || - !strcmp(Token, "MATTE_METALIC") || !strcmp(Token, "METAL") || !strcmp(Token, "LUMINANCE")) + !strcmp(Token, "MATTE_METALIC") || !strcmp(Token, "METAL") || !strcmp(Token, "LUMINANCE")) { Color.Group = LC_COLORGROUP_SPECIAL; } diff --git a/common/lc_edgecolordialog.cpp b/common/lc_edgecolordialog.cpp index 580d4c59..d69bac32 100644 --- a/common/lc_edgecolordialog.cpp +++ b/common/lc_edgecolordialog.cpp @@ -4,40 +4,46 @@ lcAutomateEdgeColorDialog::lcAutomateEdgeColorDialog(QWidget* Parent, bool ShowHighContrastDialog) :QDialog(Parent) { - mStudCylinderColor = lcGetPreferences().mStudCylinderColor; - mPartEdgeColor = lcGetPreferences().mPartEdgeColor; - mBlackEdgeColor = lcGetPreferences().mBlackEdgeColor; - mDarkEdgeColor = lcGetPreferences().mDarkEdgeColor; - - mPartEdgeContrast = lcGetPreferences().mPartEdgeContrast; - mPartColorValueLDIndex = lcGetPreferences().mPartColorValueLDIndex; + const lcPreferences& Preferences = lcGetPreferences(); + mStudCylinderColor = Preferences.mStudCylinderColor; + mPartEdgeColor = Preferences.mPartEdgeColor; + mBlackEdgeColor = Preferences.mBlackEdgeColor; + mDarkEdgeColor = Preferences.mDarkEdgeColor; + mPartEdgeContrast = Preferences.mPartEdgeContrast; + mPartColorValueLDIndex = Preferences.mPartColorValueLDIndex; setWindowTitle(tr("Color Preferences")); QVBoxLayout* MainLayout = new QVBoxLayout(this); QGroupBox* EdgeSettingsBox = new QGroupBox(tr("Edge Colors"), this); - EdgeSettingsBox->setVisible(!ShowHighContrastDialog); MainLayout->addWidget(EdgeSettingsBox); QGridLayout* EdgeSettingsLayout = new QGridLayout(EdgeSettingsBox); EdgeSettingsBox->setLayout(EdgeSettingsLayout); - QLabel* PartEdgeContrastLabel = new QLabel(tr("Contrast:"), this); - PartEdgeContrast = new QLabel(this); - PartEdgeContrastSlider = new QSlider(Qt::Horizontal, this); - PartEdgeContrastSlider->setRange(0, 100); - PartEdgeContrastSlider->setValue(mPartEdgeContrast * 100); - PartEdgeContrastSlider->setToolTip(tr("Set the amount of contrast - 0.50 is midway.")); - connect(PartEdgeContrastSlider, SIGNAL(valueChanged(int)), this, SLOT(SliderValueChanged(int))); - emit PartEdgeContrastSlider->valueChanged(PartEdgeContrastSlider->value()); + int LDIndexRow = 0; + PartEdgeContrast = nullptr; + PartEdgeContrastSlider = nullptr; + if (!ShowHighContrastDialog) + { + LDIndexRow = 1; + QLabel* PartEdgeContrastLabel = new QLabel(tr("Contrast:"), this); + PartEdgeContrast = new QLabel(this); + PartEdgeContrastSlider = new QSlider(Qt::Horizontal, this); + PartEdgeContrastSlider->setRange(0, 100); + PartEdgeContrastSlider->setValue(mPartEdgeContrast * 100); + PartEdgeContrastSlider->setToolTip(tr("Set the amount of contrast - 0.50 is midway.")); + connect(PartEdgeContrastSlider, SIGNAL(valueChanged(int)), this, SLOT(SliderValueChanged(int))); + emit PartEdgeContrastSlider->valueChanged(PartEdgeContrastSlider->value()); - ResetPartEdgeContrastButton = new QToolButton(this); - ResetPartEdgeContrastButton->setText(tr("Reset")); - connect(ResetPartEdgeContrastButton, SIGNAL(clicked()), this, SLOT(ResetSliderButtonClicked())); + ResetPartEdgeContrastButton = new QToolButton(this); + ResetPartEdgeContrastButton->setText(tr("Reset")); + connect(ResetPartEdgeContrastButton, SIGNAL(clicked()), this, SLOT(ResetSliderButtonClicked())); - EdgeSettingsLayout->addWidget(PartEdgeContrastLabel,0,0); - EdgeSettingsLayout->addWidget(PartEdgeContrastSlider,0,1); - EdgeSettingsLayout->addWidget(PartEdgeContrast,0,2); - EdgeSettingsLayout->addWidget(ResetPartEdgeContrastButton,0,3); + EdgeSettingsLayout->addWidget(PartEdgeContrastLabel,0,0); + EdgeSettingsLayout->addWidget(PartEdgeContrastSlider,0,1); + EdgeSettingsLayout->addWidget(PartEdgeContrast,0,2); + EdgeSettingsLayout->addWidget(ResetPartEdgeContrastButton,0,3); + } QLabel* PartColorValueLDIndexLabel = new QLabel(tr("Light/Dark Value:"), this); PartColorValueLDIndex = new QLabel(this); @@ -52,10 +58,10 @@ lcAutomateEdgeColorDialog::lcAutomateEdgeColorDialog(QWidget* Parent, bool ShowH ResetPartColorValueLDIndexButton->setText(tr("Reset")); connect(ResetPartColorValueLDIndexButton, SIGNAL(clicked()), this, SLOT(ResetSliderButtonClicked())); - EdgeSettingsLayout->addWidget(PartColorValueLDIndexLabel,1,0); - EdgeSettingsLayout->addWidget(PartColorValueLDIndexSlider,1,1); - EdgeSettingsLayout->addWidget(PartColorValueLDIndex,1,2); - EdgeSettingsLayout->addWidget(ResetPartColorValueLDIndexButton,1,3); + EdgeSettingsLayout->addWidget(PartColorValueLDIndexLabel,LDIndexRow,0); + EdgeSettingsLayout->addWidget(PartColorValueLDIndexSlider,LDIndexRow,1); + EdgeSettingsLayout->addWidget(PartColorValueLDIndex,LDIndexRow,2); + EdgeSettingsLayout->addWidget(ResetPartColorValueLDIndexButton,LDIndexRow,3); QGroupBox* HighContrastColorBox = new QGroupBox(tr("High Contrast"), this); HighContrastColorBox->setVisible(ShowHighContrastDialog); diff --git a/common/lc_math.h b/common/lc_math.h index 3b8bc575..3fd0f977 100644 --- a/common/lc_math.h +++ b/common/lc_math.h @@ -651,6 +651,15 @@ inline quint32 lcColorFromVector3(const lcVector3& Color) return LC_RGB(Color[0] * 255, Color[1] * 255, Color[2] * 255); } +inline float lcLuminescenceFromRGBA(lcVector4& Value) +{ + float r = LC_SRGB_TO_LINEAR(Value[0]); + float g = LC_SRGB_TO_LINEAR(Value[1]); + float b = LC_SRGB_TO_LINEAR(Value[2]); + + return 0.2126f * r + 0.7152f * g + 0.0722f * b; +} + inline lcVector3 lcMul(const lcVector3& a, const lcMatrix33& b) { return b.r[0] * a[0] + b.r[1] * a[1] + b.r[2] * a[2];