diff --git a/common/lc_application.cpp b/common/lc_application.cpp index bb070cc0..ee9a95e6 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -340,7 +340,7 @@ lcCommandLineOptions lcApplication::ParseCommandLineOptions() Options.ImageWidth = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH); Options.ImageHeight = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT); Options.AASamples = lcGetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES); - Options.StudStyle = lcGetProfileInt(LC_PROFILE_STUD_STYLE); + Options.StudStyle = static_cast(lcGetProfileInt(LC_PROFILE_STUD_STYLE)); Options.ImageStart = 0; Options.ImageEnd = 0; Options.CameraPosition[0] = lcVector3(0.0f, 0.0f, 0.0f); @@ -655,7 +655,12 @@ lcCommandLineOptions lcApplication::ParseCommandLineOptions() } } else if (Option == QLatin1String("-ss") || Option == QLatin1String("--stud-style")) - ParseInteger(Options.StudStyle, 0, 7); + { + int StudStyle; + + if (ParseInteger(StudStyle, 0, static_cast(lcStudStyle::Count) - 1)) + Options.StudStyle = static_cast(StudStyle); + } else if (Option == QLatin1String("-obj") || Option == QLatin1String("--export-wavefront")) { Options.SaveWavefront = true; @@ -1105,7 +1110,7 @@ void lcApplication::ShowPreferencesDialog() { lcPreferencesDialogOptions Options; int CurrentAASamples = lcGetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES); - int CurrentStudStyle = lcGetProfileInt(LC_PROFILE_STUD_STYLE); + lcStudStyle CurrentStudStyle = lcGetPiecesLibrary()->GetStudStyle(); Options.Preferences = mPreferences; @@ -1156,7 +1161,7 @@ void lcApplication::ShowPreferencesDialog() lcSetProfileString(LC_PROFILE_LANGUAGE, Options.Language); lcSetProfileInt(LC_PROFILE_CHECK_UPDATES, Options.CheckForUpdates); lcSetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES, Options.AASamples); - lcSetProfileInt(LC_PROFILE_STUD_STYLE, Options.StudStyle); + lcSetProfileInt(LC_PROFILE_STUD_STYLE, static_cast(Options.StudStyle)); if (LanguageChanged || LibraryChanged || ColorsChanged || AAChanged) QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Some changes will only take effect the next time you start LeoCAD.")); @@ -1200,16 +1205,10 @@ void lcApplication::ShowPreferencesDialog() if (StudStyleChanged) { - lcSetProfileInt(LC_PROFILE_STUD_STYLE, Options.StudStyle); + lcSetProfileInt(LC_PROFILE_STUD_STYLE, static_cast(Options.StudStyle)); lcGetPiecesLibrary()->SetStudStyle(Options.StudStyle, true); } - // TODO: printing preferences - /* - strcpy(opts.strFooter, m_strFooter); - strcpy(opts.strHeader, m_strHeader); - */ - gMainWindow->SetShadingMode(Options.Preferences.mShadingMode); lcView::UpdateAllViews(); } diff --git a/common/lc_application.h b/common/lc_application.h index a7152975..c4763771 100644 --- a/common/lc_application.h +++ b/common/lc_application.h @@ -95,7 +95,7 @@ struct lcCommandLineOptions int ImageWidth; int ImageHeight; int AASamples; - int StudStyle; + lcStudStyle StudStyle; lcStep ImageStart; lcStep ImageEnd; lcVector3 CameraPosition[3]; diff --git a/common/lc_colors.cpp b/common/lc_colors.cpp index 5984db17..fba1d4ee 100644 --- a/common/lc_colors.cpp +++ b/common/lc_colors.cpp @@ -1,6 +1,7 @@ #include "lc_global.h" #include "lc_colors.h" #include "lc_file.h" +#include "lc_library.h" #include std::vector gColorList; @@ -209,9 +210,9 @@ int lcGetBrickLinkColor(int ColorIndex) return 0; } -static void lcAdjustStudStyleColors(int StudStyle) +static void lcAdjustStudStyleColors(lcStudStyle StudStyle) { - if (StudStyle < 6) + if (StudStyle != lcStudStyle::HighContrast && StudStyle != lcStudStyle::HighContrastLogo) return; for (lcColor& Color : gColorList) @@ -228,7 +229,7 @@ static void lcAdjustStudStyleColors(int StudStyle) } } -bool lcLoadColorFile(lcFile& File, int StudStyle) +bool lcLoadColorFile(lcFile& File, lcStudStyle StudStyle) { char Line[1024], Token[1024]; std::vector& Colors = gColorList; @@ -452,7 +453,7 @@ bool lcLoadColorFile(lcFile& File, int StudStyle) return Colors.size() > 3; } -void lcLoadDefaultColors(int StudStyle) +void lcLoadDefaultColors(lcStudStyle StudStyle) { lcDiskFile ConfigFile(":/resources/ldconfig.ldr"); diff --git a/common/lc_colors.h b/common/lc_colors.h index 9b5efaf7..b60b4b2e 100644 --- a/common/lc_colors.h +++ b/common/lc_colors.h @@ -48,8 +48,8 @@ extern int gNumUserColors; extern int gEdgeColor; extern int gDefaultColor; -void lcLoadDefaultColors(int StudStyle); -bool lcLoadColorFile(lcFile& File, int StudStyle); +void lcLoadDefaultColors(lcStudStyle StudStyle); +bool lcLoadColorFile(lcFile& File, lcStudStyle StudStyle); int lcGetColorIndex(quint32 ColorCode); int lcGetBrickLinkColor(int ColorIndex); diff --git a/common/lc_global.h b/common/lc_global.h index 56429013..ab338cdc 100644 --- a/common/lc_global.h +++ b/common/lc_global.h @@ -71,6 +71,7 @@ struct lcModelPartsEntry; struct lcMinifig; enum class lcViewpoint; enum class lcShadingMode; +enum class lcStudStyle; class lcInstructions; struct lcInstructionsPageSetup; struct lcObjectRayTest; diff --git a/common/lc_library.cpp b/common/lc_library.cpp index 22753edf..6e473d39 100644 --- a/common/lc_library.cpp +++ b/common/lc_library.cpp @@ -41,7 +41,7 @@ lcPiecesLibrary::lcPiecesLibrary() mBuffersDirty = false; mHasUnofficial = false; mCancelLoading = false; - mStudStyle = lcGetProfileInt(LC_PROFILE_STUD_STYLE); + mStudStyle = static_cast(lcGetProfileInt(LC_PROFILE_STUD_STYLE)); } lcPiecesLibrary::~lcPiecesLibrary() @@ -312,16 +312,24 @@ void lcPiecesLibrary::UpdateStudStyleSource() mZipFiles[static_cast(lcZipFileType::StudStyle)].reset(); - if (!mStudStyle) + if (mStudStyle == lcStudStyle::Plain) return; - std::unique_ptr StudStyleFile; - if (mStudStyle < 6) - StudStyleFile = std::unique_ptr(new lcDiskFile(QString(":/resources/studlogo%1.zip").arg(QString::number(mStudStyle)))); - else if (mStudStyle == 6) - StudStyleFile = std::unique_ptr(new lcDiskFile(QString(":/resources/studslegostyle1.zip"))); - else - StudStyleFile = std::unique_ptr(new lcDiskFile(QString(":/resources/studslegostyle2.zip"))); + const QLatin1String FileNames[] = + { + QLatin1String(), // Plain + QLatin1String(":/resources/studlogo1.zip"), // ThinLinesLogo + QLatin1String(":/resources/studlogo2.zip"), // OutlineLogo + QLatin1String(":/resources/studlogo3.zip"), // SharpTopLogo + QLatin1String(":/resources/studlogo4.zip"), // RoundedTopLogo + QLatin1String(":/resources/studlogo5.zip"), // FlattenedLogo + QLatin1String(":/resources/studslegostyle1.zip"), // HighContrast + QLatin1String(":/resources/studslegostyle2.zip") // HighContrastLogo + }; + + LC_ARRAY_SIZE_CHECK(FileNames, lcStudStyle::Count); + + std::unique_ptr StudStyleFile(new lcDiskFile(FileNames[static_cast(mStudStyle)])); if (StudStyleFile->Open(QIODevice::ReadOnly)) OpenArchive(std::move(StudStyleFile), lcZipFileType::StudStyle); @@ -1082,7 +1090,7 @@ bool lcPiecesLibrary::LoadCachePiece(PieceInfo* Info) if (MeshData.ReadBuffer((char*)&Flags, sizeof(Flags)) == 0) return false; - if (Flags != mStudStyle) + if (Flags != static_cast(mStudStyle)) return false; lcMesh* Mesh = new lcMesh; @@ -1102,7 +1110,7 @@ bool lcPiecesLibrary::SaveCachePiece(PieceInfo* Info) { lcMemFile MeshData; - const qint32 Flags = mStudStyle; + const qint32 Flags = static_cast(mStudStyle); if (MeshData.WriteBuffer((char*)&Flags, sizeof(Flags)) == 0) return false; @@ -1534,7 +1542,7 @@ bool lcPiecesLibrary::SupportsStudStyle() const return true; } -void lcPiecesLibrary::SetStudStyle(int StudStyle, bool Reload) +void lcPiecesLibrary::SetStudStyle(lcStudStyle StudStyle, bool Reload) { if (mStudStyle == StudStyle) return; @@ -1897,7 +1905,7 @@ bool lcPiecesLibrary::LoadBuiltinPieces() } } - lcLoadDefaultColors(0); + lcLoadDefaultColors(lcStudStyle::Plain); lcLoadDefaultCategories(true); lcSynthInit(); diff --git a/common/lc_library.h b/common/lc_library.h index d2a7830c..d091128a 100644 --- a/common/lc_library.h +++ b/common/lc_library.h @@ -10,6 +10,19 @@ class PieceInfo; class lcZipFile; class lcLibraryMeshData; +enum class lcStudStyle +{ + Plain, + ThinLinesLogo, + OutlineLogo, + SharpTopLogo, + RoundedTopLogo, + FlattenedLogo, + HighContrast, + HighContrastLogo, + Count +}; + enum class lcZipFileType { Official, @@ -139,9 +152,9 @@ public: bool LoadPrimitive(lcLibraryPrimitive* Primitive); bool SupportsStudStyle() const; - void SetStudStyle(int StudStyle, bool Reload); + void SetStudStyle(lcStudStyle StudStyle, bool Reload); - int GetStudStyle() const + lcStudStyle GetStudStyle() const { return mStudStyle; } @@ -203,7 +216,7 @@ protected: QMutex mTextureMutex; std::vector mTextureUploads; - int mStudStyle; + lcStudStyle mStudStyle; QString mCachePath; qint64 mArchiveCheckSum[4]; diff --git a/common/lc_mesh.cpp b/common/lc_mesh.cpp index f2f8165e..b1b8169d 100644 --- a/common/lc_mesh.cpp +++ b/common/lc_mesh.cpp @@ -492,7 +492,7 @@ bool lcMesh::FileSave(lcMemFile& File) int lcMesh::GetLodIndex(float Distance) const { - if (lcGetPiecesLibrary()->GetStudStyle()) + if (lcGetPiecesLibrary()->GetStudStyle() != lcStudStyle::Plain) // todo: support low lod studs return LC_MESH_LOD_HIGH; if (mLods[LC_MESH_LOD_LOW].NumSections && (Distance > mRadius)) diff --git a/qt/lc_qpreferencesdialog.cpp b/qt/lc_qpreferencesdialog.cpp index c49a00d2..e122032c 100644 --- a/qt/lc_qpreferencesdialog.cpp +++ b/qt/lc_qpreferencesdialog.cpp @@ -164,7 +164,7 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO if (!lcGetPiecesLibrary()->SupportsStudStyle()) ui->studStyleCombo->setEnabled(false); - ui->studStyleCombo->setCurrentIndex(mOptions->StudStyle); + ui->studStyleCombo->setCurrentIndex(static_cast(mOptions->StudStyle)); if (!gSupportsShaderObjects) ui->ShadingMode->removeItem(static_cast(lcShadingMode::DefaultLights)); @@ -295,7 +295,7 @@ void lcQPreferencesDialog::accept() mOptions->Preferences.mShadingMode = (lcShadingMode)ui->ShadingMode->currentIndex(); - mOptions->StudStyle = ui->studStyleCombo->currentIndex(); + mOptions->StudStyle = static_cast(ui->studStyleCombo->currentIndex()); mOptions->Preferences.mDrawPreviewAxis = ui->PreviewAxisIconCheckBox->isChecked(); mOptions->Preferences.mPreviewViewSphereEnabled = ui->PreviewViewSphereSizeCombo->currentIndex() > 0; diff --git a/qt/lc_qpreferencesdialog.h b/qt/lc_qpreferencesdialog.h index 6929cadb..3ba77f56 100644 --- a/qt/lc_qpreferencesdialog.h +++ b/qt/lc_qpreferencesdialog.h @@ -18,7 +18,7 @@ struct lcPreferencesDialogOptions int CheckForUpdates; int AASamples; - int StudStyle; + lcStudStyle StudStyle; std::vector Categories; bool CategoriesModified;