Merge pull request #609 from trevorsandy/AUTOMATE_EDGE_COLOURS

Automate edge colours
This commit is contained in:
Leonardo Zide 2021-01-25 16:27:01 -08:00 committed by GitHub
commit 0b50555f00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 621 additions and 151 deletions

View file

@ -58,6 +58,13 @@ void lcPreferences::LoadDefaults()
mPreviewViewSphereSize = lcGetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_SIZE);
mPreviewViewSphereLocation = static_cast<lcViewSphereLocation>(lcGetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION));
mDrawPreviewAxis = lcGetProfileInt(LC_PROFILE_PREVIEW_DRAW_AXES);
mStudColor = lcGetProfileInt(LC_PROFILE_STUD_COLOR);
mStudEdgeColor = lcGetProfileInt(LC_PROFILE_STUD_EDGE_COLOR);
mBlackEdgeColor = lcGetProfileInt(LC_PROFILE_BLACK_EDGE_COLOR);
mDarkEdgeColor = lcGetProfileInt(LC_PROFILE_DARK_EDGE_COLOR);
mPartEdgeContrast = lcGetProfileFloat(LC_PROFILE_PART_EDGE_CONTRAST);
mPartColorValueLDIndex = lcGetProfileFloat(LC_PROFILE_PART_COLOR_VALUE_LD_INDEX);
mAutomateEdgeColor = lcGetProfileInt(LC_PROFILE_AUTOMATE_EDGE_COLOR);
}
void lcPreferences::SaveDefaults()
@ -103,6 +110,13 @@ void lcPreferences::SaveDefaults()
lcSetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_SIZE, mPreviewViewSphereSize);
lcSetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION, static_cast<int>(mPreviewViewSphereLocation));
lcSetProfileInt(LC_PROFILE_PREVIEW_DRAW_AXES, mDrawPreviewAxis);
lcSetProfileInt(LC_PROFILE_STUD_COLOR, mStudColor);
lcSetProfileInt(LC_PROFILE_STUD_EDGE_COLOR, mStudEdgeColor);
lcSetProfileInt(LC_PROFILE_BLACK_EDGE_COLOR, mBlackEdgeColor);
lcSetProfileInt(LC_PROFILE_DARK_EDGE_COLOR, mDarkEdgeColor);
lcSetProfileFloat(LC_PROFILE_PART_EDGE_CONTRAST, mPartEdgeContrast);
lcSetProfileFloat(LC_PROFILE_PART_COLOR_VALUE_LD_INDEX, mPartColorValueLDIndex);
lcSetProfileInt(LC_PROFILE_AUTOMATE_EDGE_COLOR, mAutomateEdgeColor);
}
void lcPreferences::SetInterfaceColors(lcColorTheme ColorTheme)
@ -1146,6 +1160,16 @@ void lcApplication::ShowPreferencesDialog()
bool ColorsChanged = Options.ColorConfigPath != lcGetProfileString(LC_PROFILE_COLOR_CONFIG);
bool AAChanged = CurrentAASamples != Options.AASamples;
bool StudStyleChanged = CurrentStudStyle != Options.StudStyle;
bool AutomateEdgeColorChanged = Options.Preferences.mAutomateEdgeColor != bool(lcGetProfileInt(LC_PROFILE_AUTOMATE_EDGE_COLOR));
bool StudColorChanged = Options.Preferences.mStudColor != quint32(lcGetProfileInt(LC_PROFILE_STUD_COLOR));
bool StudEdgeColorChanged = Options.Preferences.mStudEdgeColor != quint32(lcGetProfileInt(LC_PROFILE_STUD_EDGE_COLOR));
bool BlackEdgeColorChanged = Options.Preferences.mBlackEdgeColor != quint32(lcGetProfileInt(LC_PROFILE_BLACK_EDGE_COLOR));
bool DarkEdgeColorChanged = Options.Preferences.mDarkEdgeColor != quint32(lcGetProfileInt(LC_PROFILE_DARK_EDGE_COLOR));
bool PartEdgeContrastChanged = Options.Preferences.mPartEdgeContrast != lcGetProfileFloat(LC_PROFILE_PART_EDGE_CONTRAST);
bool PartColorValueLDIndexChanged = Options.Preferences.mPartColorValueLDIndex != lcGetProfileFloat(LC_PROFILE_PART_COLOR_VALUE_LD_INDEX);
if (!AutomateEdgeColorChanged)
AutomateEdgeColorChanged = (StudColorChanged || StudEdgeColorChanged || BlackEdgeColorChanged || DarkEdgeColorChanged || PartEdgeContrastChanged || PartColorValueLDIndexChanged);
mPreferences = Options.Preferences;
@ -1207,9 +1231,10 @@ void lcApplication::ShowPreferencesDialog()
lcSetProfileInt(LC_PROFILE_STUD_STYLE, static_cast<int>(Options.StudStyle));
lcGetPiecesLibrary()->SetStudStyle(Options.StudStyle, true);
}
else if (ColorsChanged)
else if (ColorsChanged || AutomateEdgeColorChanged)
{
lcSetProfileString(LC_PROFILE_COLOR_CONFIG, Options.ColorConfigPath);
if (ColorsChanged)
lcSetProfileString(LC_PROFILE_COLOR_CONFIG, Options.ColorConfigPath);
lcGetPiecesLibrary()->LoadColors();
}

View file

@ -72,6 +72,14 @@ public:
int mPreviewViewSphereSize;
lcViewSphereLocation mPreviewViewSphereLocation;
int mDrawPreviewAxis;
quint32 mStudColor;
quint32 mStudEdgeColor;
quint32 mBlackEdgeColor;
quint32 mDarkEdgeColor;
float mPartEdgeContrast;
float mPartColorValueLDIndex;
bool mAutomateEdgeColor;
};
struct lcCommandLineOptions

View file

@ -2,6 +2,7 @@
#include "lc_colors.h"
#include "lc_file.h"
#include "lc_library.h"
#include "lc_application.h"
#include <float.h>
std::vector<lcColor> gColorList;
@ -211,20 +212,56 @@ int lcGetBrickLinkColor(int ColorIndex)
static void lcAdjustStudStyleColors(std::vector<lcColor>& Colors, lcStudStyle StudStyle)
{
if (StudStyle != lcStudStyle::HighContrast && StudStyle != lcStudStyle::HighContrastLogo)
if (lcGetPreferences().mAutomateEdgeColor)
{
for (lcColor& Color : Colors)
{
if (Color.Code == 4242)
continue;
float EdgeLuminescence = 0.0f;
float r = LC_GAMMA_ADJUST(Color.Value[0]);
float g = LC_GAMMA_ADJUST(Color.Value[1]);
float b = LC_GAMMA_ADJUST(Color.Value[2]);
float ValueLuminescence = 0.2126f * r + 0.7152f * g + 0.0722f * b;
if (LC_GAMMA_APPLY(ValueLuminescence) > (lcGetPreferences().mPartColorValueLDIndex))
EdgeLuminescence = ValueLuminescence - (ValueLuminescence * lcGetPreferences().mPartEdgeContrast);
else
EdgeLuminescence = (1.0f - ValueLuminescence) * lcGetPreferences().mPartEdgeContrast + ValueLuminescence;
EdgeLuminescence = LC_GAMMA_APPLY(EdgeLuminescence);
Color.Edge = lcVector4(EdgeLuminescence, EdgeLuminescence, EdgeLuminescence, 1.0f);
}
return;
}
else if (StudStyle != lcStudStyle::HighContrast && StudStyle != lcStudStyle::HighContrastLogo)
return;
const lcVector4 Edge(LC_RGBA_RED(lcGetPreferences().mStudEdgeColor),
LC_RGBA_GREEN(lcGetPreferences().mStudEdgeColor),
LC_RGBA_BLUE(lcGetPreferences().mStudEdgeColor),
LC_RGBA_ALPHA(lcGetPreferences().mStudEdgeColor));
const lcVector4 DarkEdge(LC_RGBA_RED(lcGetPreferences().mDarkEdgeColor),
LC_RGBA_GREEN(lcGetPreferences().mDarkEdgeColor),
LC_RGBA_BLUE(lcGetPreferences().mDarkEdgeColor),
LC_RGBA_ALPHA(lcGetPreferences().mDarkEdgeColor));
const lcVector4 BlackEdge(LC_RGBA_RED(lcGetPreferences().mBlackEdgeColor),
LC_RGBA_GREEN(lcGetPreferences().mBlackEdgeColor),
LC_RGBA_BLUE(lcGetPreferences().mBlackEdgeColor),
LC_RGBA_ALPHA(lcGetPreferences().mBlackEdgeColor));
for (lcColor& Color : Colors)
{
const lcVector4 FillColor = Color.Value * 255.0f;
lcVector4 EdgeColor(0.0f, 0.0f, 0.0f, 255.0f);
if (30.0f * FillColor[0] + 59.0f * FillColor[1] + 11.0f * FillColor[2] <= 3600.0f)
EdgeColor = lcVector4(27.0f, 42.0f, 52.0f, 255.0f);
Color.Edge = DarkEdge / 255.0f;
else if (Color.Code == 0)
EdgeColor = lcVector4(255.0f, 255.0f, 255.0f, 255.0f);
Color.Edge = EdgeColor / 255.0f;
Color.Edge = BlackEdge / 255.0f;
else
Color.Edge = Edge / 255.0f;
}
}
@ -435,18 +472,25 @@ bool lcLoadColorFile(lcFile& File, lcStudStyle StudStyle)
if (!FoundStud)
{
lcColor StudColor;
lcVector4 Value = lcVector4(LC_RGBA_RED(lcGetPreferences().mStudColor),
LC_RGBA_GREEN(lcGetPreferences().mStudColor),
LC_RGBA_BLUE(lcGetPreferences().mStudColor),
LC_RGBA_ALPHA(lcGetPreferences().mStudColor)) / 255.0f;
lcVector4 Edge = lcVector4(LC_RGBA_RED(lcGetPreferences().mStudEdgeColor),
LC_RGBA_GREEN(lcGetPreferences().mStudEdgeColor),
LC_RGBA_BLUE(lcGetPreferences().mStudEdgeColor),
LC_RGBA_ALPHA(lcGetPreferences().mStudEdgeColor)) / 255.0f;
StudColor.Code = 4242;
StudColor.Translucent = false;
StudColor.Group = LC_NUM_COLORGROUPS;
StudColor.Value[0] = 27.0f / 255.0f;
StudColor.Value[1] = 42.0f / 255.0f;
StudColor.Value[2] = 52.0f / 255.0f;
StudColor.Value[3] = 1.0f;
StudColor.Edge[0] = 0.0f;
StudColor.Edge[1] = 0.0f;
StudColor.Edge[2] = 0.0f;
StudColor.Edge[3] = 1.0f;
StudColor.Value[0] = Value[0];
StudColor.Value[1] = Value[1];
StudColor.Value[2] = Value[2];
StudColor.Value[3] = Value[3];
StudColor.Edge[0] = Edge[0];
StudColor.Edge[1] = Edge[1];
StudColor.Edge[2] = Edge[2];
StudColor.Edge[3] = Edge[3];
strcpy(StudColor.Name, "Stud Style Black");
strcpy(StudColor.SafeName, "Stud_Style_Black");

View file

@ -0,0 +1,272 @@
#include "lc_edgecolordialog.h"
#include "lc_application.h"
lcAutomateEdgeColorDialog::lcAutomateEdgeColorDialog(QWidget* Parent, bool ShowHighContrastDialog)
:QDialog(Parent)
{
mStudColor = lcGetPreferences().mStudColor;
mStudEdgeColor = lcGetPreferences().mStudEdgeColor;
mBlackEdgeColor = lcGetPreferences().mBlackEdgeColor;
mDarkEdgeColor = lcGetPreferences().mDarkEdgeColor;
mPartEdgeContrast = lcGetPreferences().mPartEdgeContrast;
mPartColorValueLDIndex = lcGetPreferences().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());
ResetPartEdgeContrastButton = new QToolButton(this);
ResetPartEdgeContrastButton->setText(tr("..."));
ResetPartEdgeContrastButton->setToolTip(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);
QLabel* PartColorValueLDIndexLabel = new QLabel(tr("Light/Dark Value:"), this);
PartColorValueLDIndex = new QLabel(this);
PartColorValueLDIndexSlider = new QSlider(Qt::Horizontal, this);
PartColorValueLDIndexSlider->setRange(0, 100);
PartColorValueLDIndexSlider->setValue(mPartColorValueLDIndex * 100);
PartColorValueLDIndexSlider->setToolTip(tr("Set to classify where color values are light or dark - e.g. Dark Bluish Gray (72) is light at 0.39."));
connect(PartColorValueLDIndexSlider, SIGNAL(valueChanged(int)), this, SLOT(SliderValueChanged(int)));
emit PartColorValueLDIndexSlider->valueChanged(PartColorValueLDIndexSlider->value());
ResetPartColorValueLDIndexButton = new QToolButton(this);
ResetPartColorValueLDIndexButton->setText(tr("..."));
ResetPartColorValueLDIndexButton->setToolTip(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);
QGroupBox* StudColorBox = new QGroupBox(tr("High Contrast Studs"), this);
StudColorBox->setVisible(ShowHighContrastDialog);
MainLayout->addWidget(StudColorBox);
QGridLayout* StudColorLayout = new QGridLayout(StudColorBox);
StudColorBox->setLayout(StudColorLayout);
auto SetButtonPixmap = [](quint32 Color, QToolButton* Button)
{
QPixmap Pixmap(12, 12);
QColor ButtonColor(QColor(LC_RGBA_RED(Color), LC_RGBA_GREEN(Color), LC_RGBA_BLUE(Color)));
Pixmap.fill(ButtonColor);
Button->setIcon(Pixmap);
Button->setToolTip(ButtonColor.name().toUpper());
};
QLabel* StudColorLabel = new QLabel(tr("Stud Color:"), this);
StudColorButton = new QToolButton(this);
SetButtonPixmap(mStudColor, StudColorButton);
connect(StudColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
ResetStudColorButton = new QToolButton(this);
ResetStudColorButton->setText(tr("..."));
ResetStudColorButton->setToolTip(tr("Reset"));
connect(ResetStudColorButton, SIGNAL(clicked()), this, SLOT(ResetColorButtonClicked()));
StudColorLayout->addWidget(StudColorLabel,0,0);
StudColorLayout->addWidget(StudColorButton,0,1);
StudColorLayout->addWidget(ResetStudColorButton,0,2);
QLabel* StudEdgeColorLabel = new QLabel(tr("Stud Edge Color:"), this);
StudEdgeColorButton = new QToolButton(this);
SetButtonPixmap(mStudEdgeColor, StudEdgeColorButton);
connect(StudEdgeColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
ResetStudEdgeColorButton = new QToolButton(this);
ResetStudEdgeColorButton->setText(tr("..."));
ResetStudEdgeColorButton->setToolTip(tr("Reset"));
connect(ResetStudEdgeColorButton, SIGNAL(clicked()), this, SLOT(ResetColorButtonClicked()));
StudColorLayout->addWidget(StudEdgeColorLabel,1,0);
StudColorLayout->addWidget(StudEdgeColorButton,1,1);
StudColorLayout->addWidget(ResetStudEdgeColorButton,1,2);
QLabel* BlackEdgeColorLabel = new QLabel(tr("Black Parts Edge Color:"), this);
BlackEdgeColorButton = new QToolButton(this);
SetButtonPixmap(mBlackEdgeColor, BlackEdgeColorButton);
connect(BlackEdgeColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
ResetBlackEdgeColorButton = new QToolButton(this);
ResetBlackEdgeColorButton->setText(tr("..."));
ResetBlackEdgeColorButton->setToolTip(tr("Reset"));
connect(ResetBlackEdgeColorButton, SIGNAL(clicked()), this, SLOT(ResetColorButtonClicked()));
StudColorLayout->addWidget(BlackEdgeColorLabel,2,0);
StudColorLayout->addWidget(BlackEdgeColorButton,2,1);
StudColorLayout->addWidget(ResetBlackEdgeColorButton,2,2);
QLabel* DarkEdgeColorLabel = new QLabel(tr("Dark Parts Edge Color:"), this);
DarkEdgeColorButton = new QToolButton(this);
SetButtonPixmap(mDarkEdgeColor, DarkEdgeColorButton);
connect(DarkEdgeColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
ResetDarkEdgeColorButton = new QToolButton(this);
ResetDarkEdgeColorButton->setText(tr("..."));
ResetDarkEdgeColorButton->setToolTip(tr("Reset"));
connect(ResetDarkEdgeColorButton, SIGNAL(clicked()), this, SLOT(ResetColorButtonClicked()));
StudColorLayout->addWidget(DarkEdgeColorLabel,3,0);
StudColorLayout->addWidget(DarkEdgeColorButton,3,1);
StudColorLayout->addWidget(ResetDarkEdgeColorButton,3,2);
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
MainLayout->addWidget(buttonBox);
QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
setMinimumSize(220,100);
}
void lcAutomateEdgeColorDialog::SliderValueChanged(int Value)
{
if (sender() == PartEdgeContrastSlider)
{
mPartEdgeContrast = Value * 0.01f;
PartEdgeContrast->setText(QString::number(mPartEdgeContrast, 'f', 2));
}
else if (sender() == PartColorValueLDIndexSlider)
{
mPartColorValueLDIndex = Value * 0.01f;
PartColorValueLDIndex->setText(QString::number(mPartColorValueLDIndex, 'f', 2));
}
}
void lcAutomateEdgeColorDialog::ColorButtonClicked()
{
QObject* Button = sender();
QString Title;
quint32* Color = nullptr;
QColorDialog::ColorDialogOptions DialogOptions;
if (Button == StudColorButton)
{
Title = tr("Select Stud Color");
Color = &mStudColor;
}
else if (Button == StudEdgeColorButton)
{
Title = tr("Select Stud Edge Color");
Color = &mStudEdgeColor;
}
else if (Button == BlackEdgeColorButton)
{
if (lcGetPreferences().mAutomateEdgeColor)
{
QMessageBox msgBox;
msgBox.setText("Automate edge colour appears to be enabled.<br>"
"Black parts edge color setting will not be accessible.");
if (msgBox.exec() != QMessageBox::Accepted)
return;
}
Title = tr("Select Black Edge Color");
Color = &mBlackEdgeColor;
}
else if (Button == DarkEdgeColorButton)
{
if (lcGetPreferences().mAutomateEdgeColor)
{
QMessageBox msgBox;
msgBox.setText("Automate edge colour appears to be enabled.<br>"
"Dark parts edge color setting will not be accessible.");
if (msgBox.exec() != QMessageBox::Accepted)
return;
}
Title = tr("Select Dark Edge Color");
Color = &mDarkEdgeColor;
}
else
return;
QColor OldColor = QColor(LC_RGBA_RED(*Color), LC_RGBA_GREEN(*Color), LC_RGBA_BLUE(*Color), LC_RGBA_ALPHA(*Color));
QColor NewColor = QColorDialog::getColor(OldColor, this, Title, DialogOptions);
if (NewColor == OldColor || !NewColor.isValid())
return;
*Color = LC_RGBA(NewColor.red(), NewColor.green(), NewColor.blue(), NewColor.alpha());
QPixmap Pix(12, 12);
NewColor.setAlpha(255);
Pix.fill(NewColor);
((QToolButton*)Button)->setIcon(Pix);
((QToolButton*)Button)->setToolTip(NewColor.name().toUpper());
}
void lcAutomateEdgeColorDialog::ResetSliderButtonClicked()
{
if (sender() == ResetPartEdgeContrastButton)
{
PartEdgeContrastSlider->setValue(0.5f * 100);
emit PartEdgeContrastSlider->valueChanged(PartEdgeContrastSlider->value());
}
else if (sender() == ResetPartColorValueLDIndexButton)
{
PartColorValueLDIndexSlider->setValue(0.5f * 100);
emit PartColorValueLDIndexSlider->valueChanged(PartColorValueLDIndexSlider->value());
}
}
void lcAutomateEdgeColorDialog::ResetColorButtonClicked()
{
quint32* Color = nullptr;
QPixmap Pix(12, 12);
QColor ResetColor;
if (sender() == ResetStudColorButton)
{
Color = &mStudColor;
*Color = LC_RGBA(27, 42, 52, 255);
ResetColor = QColor(LC_RGBA_RED(*Color), LC_RGBA_GREEN(*Color), LC_RGBA_BLUE(*Color), LC_RGBA_ALPHA(*Color));
Pix.fill(ResetColor);
StudColorButton->setIcon(Pix);
StudColorButton->setToolTip(ResetColor.name().toUpper());
}
else if (sender() == ResetStudEdgeColorButton)
{
Color = &mStudEdgeColor;
*Color = LC_RGBA(0, 0, 0, 255);
ResetColor = QColor(LC_RGBA_RED(*Color), LC_RGBA_GREEN(*Color), LC_RGBA_BLUE(*Color), LC_RGBA_ALPHA(*Color));
Pix.fill(ResetColor);
StudEdgeColorButton->setIcon(Pix);
StudEdgeColorButton->setToolTip(ResetColor.name().toUpper());
}
else if (sender() == ResetBlackEdgeColorButton)
{
Color = &mBlackEdgeColor;
*Color = LC_RGBA(255, 255, 255, 255);
ResetColor = QColor(LC_RGBA_RED(*Color), LC_RGBA_GREEN(*Color), LC_RGBA_BLUE(*Color), LC_RGBA_ALPHA(*Color));
Pix.fill(ResetColor);
BlackEdgeColorButton->setIcon(Pix);
BlackEdgeColorButton->setToolTip(ResetColor.name().toUpper());
}
else if (sender() == ResetDarkEdgeColorButton)
{
Color = &mDarkEdgeColor;
*Color = LC_RGBA(27, 42, 52, 255);
ResetColor = QColor(LC_RGBA_RED(*Color), LC_RGBA_GREEN(*Color), LC_RGBA_BLUE(*Color), LC_RGBA_ALPHA(*Color));
Pix.fill(ResetColor);
DarkEdgeColorButton->setIcon(Pix);
DarkEdgeColorButton->setToolTip(ResetColor.name().toUpper());
}
}

View file

@ -0,0 +1,43 @@
#pragma once
#include <QtWidgets>
class lcAutomateEdgeColorDialog : public QDialog
{
Q_OBJECT
public:
lcAutomateEdgeColorDialog(QWidget *Parent, bool ShowHighContrastDialog);
quint32 mStudColor;
quint32 mStudEdgeColor;
quint32 mDarkEdgeColor;
quint32 mBlackEdgeColor;
float mPartEdgeContrast;
float mPartColorValueLDIndex;
protected slots:
void SliderValueChanged(int);
void ResetSliderButtonClicked();
void ColorButtonClicked();
void ResetColorButtonClicked();
protected:
QSlider* PartColorValueLDIndexSlider;
QSlider* PartEdgeContrastSlider;
QLabel* PartEdgeContrast;
QLabel* PartColorValueLDIndex;
QToolButton* ResetPartEdgeContrastButton;
QToolButton* ResetPartColorValueLDIndexButton;
QToolButton* StudColorButton;
QToolButton* StudEdgeColorButton;
QToolButton* BlackEdgeColorButton;
QToolButton* DarkEdgeColorButton;
QToolButton* ResetStudColorButton;
QToolButton* ResetStudEdgeColorButton;
QToolButton* ResetBlackEdgeColorButton;
QToolButton* ResetDarkEdgeColorButton;
};

View file

@ -9,11 +9,14 @@
#define LC_2PI (static_cast<float>(2 * M_PI))
#define LC_RGB(r,g,b) LC_RGBA(r,g,b,255)
#define LC_RGBA(r,g,b,a) ((quint32)(((quint8) (r) | ((quint16) (g) << 8)) | (((quint32) (quint8) (b)) << 16) | (((quint32) (quint8) (a)) << 24)))
#define LC_RGBA(r,g,b,a) ((quint32)(((quint8) (r) | ((quint16) (g) << 8)) | (((quint32) (quint8) (b)) << 16) | (((quint32) (quint8) (a)) << 24)))
#define LC_RGBA_RED(rgba) ((quint8)(((rgba) >> 0) & 0xff))
#define LC_RGBA_GREEN(rgba) ((quint8)(((rgba) >> 8) & 0xff))
#define LC_RGBA_BLUE(rgba) ((quint8)(((rgba) >> 16) & 0xff))
#define LC_RGBA_ALPHA(rgba) ((quint8)(((rgba) >> 24) & 0xff))
#define LC_GAMMA (2.20f)
#define LC_GAMMA_ADJUST(v) (powf(v, LC_GAMMA))
#define LC_GAMMA_APPLY(v) (powf(v, 1.0f/LC_GAMMA))
inline quint32 lcRGBAFromQColor(const QColor& Color)
{
@ -64,12 +67,12 @@ public:
{
return (const float*)this;
}
operator float*()
{
return (float*)this;
}
const float& operator[](int i) const
{
return ((float*)this)[i];
@ -106,12 +109,12 @@ public:
{
return (const float*)this;
}
operator float*()
{
return (float*)this;
}
const float& operator[](int i) const
{
return ((float*)this)[i];
@ -155,12 +158,12 @@ public:
{
return (const float*)this;
}
operator float*()
{
return (float*)this;
}
const float& operator[](int i) const
{
return ((float*)this)[i];
@ -199,12 +202,12 @@ public:
{
return (const float*)this;
}
operator float*()
{
return (float*)this;
}
const lcVector3& operator[](int i) const
{
return r[i];
@ -257,12 +260,12 @@ public:
{
return (const float*)this;
}
operator float*()
{
return (float*)this;
}
const lcVector4& operator[](int i) const
{
return r[i];
@ -1221,7 +1224,7 @@ inline lcVector3 lcMatrix44ToEulerAngles(const lcMatrix44& RotMat)
CosRoll = RotMat.r[2][2] / CosPitch;
SinYaw = RotMat.r[0][1] / CosPitch;
CosYaw = RotMat.r[0][0] / CosPitch;
}
}
else
{
SinRoll = -RotMat.r[2][1];
@ -1371,9 +1374,9 @@ inline lcMatrix44 lcMatrix44Inverse(const lcMatrix44& m)
const lcVector4 Row1(r0[5], r1[5], r2[5], r3[5]);
const lcVector4 Row2(r0[6], r1[6], r2[6], r3[6]);
const lcVector4 Row3(r0[7], r1[7], r2[7], r3[7]);
lcMatrix44 out(Row0, Row1, Row2, Row3);
return out;
#undef MAT
@ -1996,7 +1999,7 @@ inline bool lcBoundingBoxIntersectsVolume(const lcVector3& Min, const lcVector3&
if (OutcodesOR == 0)
return true;
int Indices[36] =
int Indices[36] =
{
0, 1, 2,
0, 2, 3,

View file

@ -139,6 +139,14 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] =
lcProfileEntry("Settings", "PreviewViewSphereSize", 75), // LC_PROFILE_PREVIEW_VIEW_SPHERE_SIZE
lcProfileEntry("Settings", "PreviewViewSphereLocation", (int)lcViewSphereLocation::TopRight), // LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION
lcProfileEntry("Settings", "DrawPreviewAxis", 0), // LC_PROFILE_PREVIEW_DRAW_AXES
lcProfileEntry("Settings", "StudColor", LC_RGBA(27, 42, 52, 255)), // LC_PROFILE_STUD_COLOR
lcProfileEntry("Settings", "StudEdgeColor", LC_RGBA(0, 0, 0, 255)), // LC_PROFILE_STUD_EDGE_COLOR
lcProfileEntry("Settings", "BlackEdgeColor", LC_RGBA(255, 255, 255, 255)), // LC_PROFILE_BLACK_EDGE_COLOR
lcProfileEntry("Settings", "DarkEdgeColor", LC_RGBA(27, 42, 52, 255)), // LC_PROFILE_DARK_EDGE_COLOR
lcProfileEntry("Settings", "PartEdgeContrast", 0.5f), // LC_PROFILE_PART_EDGE_CONTRAST
lcProfileEntry("Settings", "mPartColorValueLDIndex", 0.5f), // LC_PROFILE_PART_COLOR_VALUE_LD_INDEX
lcProfileEntry("Settings", "AutomateEdgeColor", 0) // LC_PROFILE_AUTOMATE_EDGE_COLOR
};
void lcRemoveProfileKey(LC_PROFILE_KEY Key)

View file

@ -88,6 +88,14 @@ enum LC_PROFILE_KEY
LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION,
LC_PROFILE_PREVIEW_DRAW_AXES,
LC_PROFILE_STUD_COLOR,
LC_PROFILE_STUD_EDGE_COLOR,
LC_PROFILE_BLACK_EDGE_COLOR,
LC_PROFILE_DARK_EDGE_COLOR,
LC_PROFILE_PART_EDGE_CONTRAST,
LC_PROFILE_PART_COLOR_VALUE_LD_INDEX,
LC_PROFILE_AUTOMATE_EDGE_COLOR,
LC_NUM_PROFILE_KEYS
};

View file

@ -130,7 +130,7 @@ unix:!macx {
mime.files = qt/leocad.xml
appdata.path = $$APPDATA_DIR
appdata.files = tools/setup/leocad.appdata.xml
INSTALLS += target docs man desktop icons mime appdata
!isEmpty(DISABLE_UPDATE_CHECK) {
@ -171,6 +171,7 @@ SOURCES += \
common/lc_colors.cpp \
common/lc_commands.cpp \
common/lc_context.cpp \
common/lc_edgecolordialog.cpp \
common/lc_file.cpp \
common/lc_glextensions.cpp \
common/lc_http.cpp \
@ -238,6 +239,7 @@ HEADERS += \
common/lc_colors.h \
common/lc_commands.h \
common/lc_context.h \
common/lc_edgecolordialog.h \
common/lc_file.h \
common/lc_glextensions.h \
common/lc_global.h \
@ -309,7 +311,7 @@ FORMS += \
common/lc_minifigdialog.ui \
common/lc_pagesetupdialog.ui \
common/lc_partpalettedialog.ui
OTHER_FILES +=
OTHER_FILES +=
RESOURCES += leocad.qrc resources/stylesheet/stylesheet.qrc
!win32 {

View file

@ -8,6 +8,7 @@
#include "lc_qutils.h"
#include "lc_glextensions.h"
#include "pieceinf.h"
#include "lc_edgecolordialog.h"
static const char* gLanguageLocales[] =
{
@ -46,6 +47,8 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO
ui->shortcutEdit->installEventFilter(this);
connect(ui->commandList, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(commandChanged(QTreeWidgetItem*)));
connect(ui->mouseTree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(MouseTreeItemChanged(QTreeWidgetItem*)));
connect(ui->HighContrastButton, SIGNAL(clicked()), this, SLOT(AutomateEdgeColor()));
connect(ui->AutomateEdgeColorButton, SIGNAL(clicked()), this, SLOT(AutomateEdgeColor()));
ui->partsLibrary->setText(mOptions->LibraryPath);
ui->ColorConfigEdit->setText(mOptions->ColorConfigPath);
@ -69,6 +72,7 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO
ui->fixedDirectionKeys->setChecked(mOptions->Preferences.mFixedAxes);
ui->autoLoadMostRecent->setChecked(mOptions->Preferences.mAutoLoadMostRecent);
ui->RestoreTabLayout->setChecked(mOptions->Preferences.mRestoreTabLayout);
ui->AutomateEdgeColor->setChecked(mOptions->Preferences.mAutomateEdgeColor);
ui->antiAliasing->setChecked(mOptions->AASamples != 1);
if (mOptions->AASamples == 8)
@ -197,6 +201,7 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO
SetButtonPixmap(mOptions->Preferences.mViewSphereHighlightColor, ui->ViewSphereHighlightColorButton);
on_antiAliasing_toggled();
on_AutomateEdgeColor_toggled();
on_edgeLines_toggled();
on_LineWidthSlider_valueChanged();
on_MeshLODSlider_valueChanged();
@ -243,6 +248,7 @@ void lcQPreferencesDialog::accept()
mOptions->DefaultAuthor = ui->authorName->text();
mOptions->Preferences.mMouseSensitivity = ui->mouseSensitivity->value();
mOptions->Preferences.mColorTheme = static_cast<lcColorTheme>(ui->ColorTheme->currentIndex());
mOptions->Preferences.mAutomateEdgeColor = ui->AutomateEdgeColor->isChecked();
int Language = ui->Language->currentIndex();
if (Language < 0 || Language > static_cast<int>(LC_ARRAY_COUNT(gLanguageLocales)))
@ -547,6 +553,30 @@ void lcQPreferencesDialog::on_ViewSphereSizeCombo_currentIndexChanged(int Index)
ui->ViewSphereLocationCombo->setEnabled(Index != 0);
}
void lcQPreferencesDialog::on_AutomateEdgeColor_toggled()
{
ui->AutomateEdgeColorButton->setEnabled(ui->AutomateEdgeColor->isChecked());
}
void lcQPreferencesDialog::on_studStyleCombo_currentIndexChanged(int index)
{
ui->HighContrastButton->setEnabled(index > static_cast<int>(lcStudStyle::FlattenedLogo));
}
void lcQPreferencesDialog::AutomateEdgeColor()
{
lcAutomateEdgeColorDialog Dialog(this, sender() == ui->HighContrastButton);
if (Dialog.exec() == QDialog::Accepted)
{
mOptions->Preferences.mStudColor = Dialog.mStudColor;
mOptions->Preferences.mStudEdgeColor = Dialog.mStudEdgeColor;
mOptions->Preferences.mBlackEdgeColor = Dialog.mBlackEdgeColor;
mOptions->Preferences.mDarkEdgeColor = Dialog.mDarkEdgeColor;
mOptions->Preferences.mPartEdgeContrast = Dialog.mPartEdgeContrast;
mOptions->Preferences.mPartColorValueLDIndex = Dialog.mPartColorValueLDIndex;
}
}
void lcQPreferencesDialog::updateCategories()
{
QTreeWidgetItem* CategoryItem;

View file

@ -65,6 +65,9 @@ public slots:
void on_lgeoPathBrowse_clicked();
void on_ColorTheme_currentIndexChanged(int Index);
void ColorButtonClicked();
void AutomateEdgeColor();
void on_AutomateEdgeColor_toggled();
void on_studStyleCombo_currentIndexChanged(int index);
void on_antiAliasing_toggled();
void on_edgeLines_toggled();
void on_LineWidthSlider_valueChanged();

View file

@ -333,6 +333,13 @@
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QGridLayout" name="gridLayout">
<item row="11" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Shading Mode:</string>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
@ -346,7 +353,79 @@
</property>
</spacer>
</item>
<item row="5" column="0">
<item row="2" column="0">
<widget class="QCheckBox" name="edgeLines">
<property name="text">
<string>Edge lines</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLabel" name="LineWidthLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="label_24">
<property name="text">
<string>Stud Style</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QToolButton" name="FadeStepsColor">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="antiAliasing">
<property name="text">
<string>Anti-aliasing</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QCheckBox" name="FadeSteps">
<property name="text">
<string>Fade previous steps</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="MeshLOD">
<property name="text">
<string>Mesh LOD</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSlider" name="MeshLODSlider">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QToolButton" name="HighlightNewPartsColor">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QCheckBox" name="HighlightNewParts">
<property name="text">
<string>Highlight new parts</string>
@ -372,113 +451,6 @@
</item>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="MeshLOD">
<property name="text">
<string>Mesh LOD</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="edgeLines">
<property name="text">
<string>Edge lines</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="antiAliasing">
<property name="text">
<string>Anti-aliasing</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="FadeSteps">
<property name="text">
<string>Fade previous steps</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Shading Mode:</string>
</property>
</widget>
</item>
<item row="7" 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="4" column="1">
<widget class="QToolButton" name="FadeStepsColor">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QToolButton" name="HighlightNewPartsColor">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSlider" name="LineWidthSlider">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLabel" name="LineWidthLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSlider" name="MeshLODSlider">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QLabel" name="MeshLODLabel">
<property name="text">
@ -486,7 +458,7 @@
</property>
</widget>
</item>
<item row="6" column="1">
<item row="10" column="1">
<widget class="QComboBox" name="studStyleCombo">
<item>
<property name="text">
@ -530,11 +502,60 @@
</item>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_24">
<property name="text">
<string>Stud Style</string>
<item row="2" column="1">
<widget class="QSlider" name="LineWidthSlider">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QToolButton" name="AutomateEdgeColorButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="AutomateEdgeColor">
<property name="text">
<string>Automate edge color</string>
</property>
</widget>
</item>
<item row="10" column="2">
<widget class="QToolButton" name="HighContrastButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="11" column="1">
<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>
</layout>
@ -1712,11 +1733,14 @@
<tabstop>LineWidthSlider</tabstop>
<tabstop>MeshLOD</tabstop>
<tabstop>MeshLODSlider</tabstop>
<tabstop>AutomateEdgeColor</tabstop>
<tabstop>AutomateEdgeColorButton</tabstop>
<tabstop>FadeSteps</tabstop>
<tabstop>FadeStepsColor</tabstop>
<tabstop>HighlightNewParts</tabstop>
<tabstop>HighlightNewPartsColor</tabstop>
<tabstop>studStyleCombo</tabstop>
<tabstop>HighContrastButton</tabstop>
<tabstop>ShadingMode</tabstop>
<tabstop>ViewSphereSizeCombo</tabstop>
<tabstop>ViewSphereLocationCombo</tabstop>
@ -1734,12 +1758,12 @@
<tabstop>BackgroundGradient1ColorButton</tabstop>
<tabstop>BackgroundGradient2ColorButton</tabstop>
<tabstop>ActiveViewColorButton</tabstop>
<tabstop>InactiveViewColorButton</tabstop>
<tabstop>TextColorButton</tabstop>
<tabstop>AxesColorButton</tabstop>
<tabstop>MarqueeBorderColorButton</tabstop>
<tabstop>MarqueeFillColorButton</tabstop>
<tabstop>OverlayColorButton</tabstop>
<tabstop>InactiveViewColorButton</tabstop>
<tabstop>AxesColorButton</tabstop>
<tabstop>MarqueeFillColorButton</tabstop>
<tabstop>gridLineColor</tabstop>
<tabstop>gridStudColor</tabstop>
<tabstop>ViewSphereColorButton</tabstop>