From ef2220ffdc5fd9059b570e3f9a0460e094bf3aa5 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Thu, 26 Nov 2020 11:51:50 -0800 Subject: [PATCH] Moved background color to global options. --- common/lc_application.cpp | 15 ++- common/lc_application.h | 4 + common/lc_model.cpp | 173 +++++------------------------------ common/lc_model.h | 23 ----- common/lc_profile.cpp | 10 +- common/lc_profile.h | 10 +- common/project.cpp | 38 ++++---- qt/lc_qpreferencesdialog.cpp | 38 +++++++- qt/lc_qpreferencesdialog.ui | 99 +++++++++++++++++++- qt/lc_qpropertiesdialog.cpp | 89 +----------------- qt/lc_qpropertiesdialog.h | 4 +- qt/lc_qpropertiesdialog.ui | 143 ----------------------------- 12 files changed, 203 insertions(+), 443 deletions(-) diff --git a/common/lc_application.cpp b/common/lc_application.cpp index 3c85c41f..7a4ece1d 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -18,6 +18,10 @@ void lcPreferences::LoadDefaults() mFixedAxes = lcGetProfileInt(LC_PROFILE_FIXED_AXES); mMouseSensitivity = lcGetProfileInt(LC_PROFILE_MOUSE_SENSITIVITY); mShadingMode = static_cast(lcGetProfileInt(LC_PROFILE_SHADING_MODE)); + mBackgroundGradient = lcGetProfileInt(LC_PROFILE_BACKGROUND_GRADIENT); + mBackgroundSolidColor = lcGetProfileInt(LC_PROFILE_BACKGROUND_COLOR); + mBackgroundGradientColorTop = lcGetProfileInt(LC_PROFILE_GRADIENT_COLOR_TOP); + mBackgroundGradientColorBottom = lcGetProfileInt(LC_PROFILE_GRADIENT_COLOR_BOTTOM); mDrawAxes = lcGetProfileInt(LC_PROFILE_DRAW_AXES); mAxesColor = lcGetProfileInt(LC_PROFILE_AXES_COLOR); mOverlayColor = lcGetProfileInt(LC_PROFILE_OVERLAY_COLOR); @@ -64,6 +68,10 @@ void lcPreferences::SaveDefaults() lcSetProfileInt(LC_PROFILE_SHADING_MODE, static_cast(mShadingMode)); lcSetProfileInt(LC_PROFILE_DRAW_AXES, mDrawAxes); lcSetProfileInt(LC_PROFILE_AXES_COLOR, mAxesColor); + lcSetProfileInt(LC_PROFILE_BACKGROUND_GRADIENT, mBackgroundGradient); + lcSetProfileInt(LC_PROFILE_BACKGROUND_COLOR, mBackgroundSolidColor); + lcSetProfileInt(LC_PROFILE_GRADIENT_COLOR_TOP, mBackgroundGradientColorTop); + lcSetProfileInt(LC_PROFILE_GRADIENT_COLOR_BOTTOM, mBackgroundGradientColorBottom); lcSetProfileInt(LC_PROFILE_OVERLAY_COLOR, mOverlayColor); lcSetProfileInt(LC_PROFILE_ACTIVE_VIEW_COLOR, mActiveViewColor); lcSetProfileInt(LC_PROFILE_DRAW_EDGE_LINES, mDrawEdgeLines); @@ -106,6 +114,9 @@ void lcPreferences::SetInterfaceColors(lcColorTheme ColorTheme) if (ColorTheme == lcColorTheme::Dark) { mAxesColor = LC_RGBA(0, 0, 0, 255); + mBackgroundSolidColor = LC_RGB(49, 52, 55); + mBackgroundGradientColorTop = LC_RGB(0, 0, 191); + mBackgroundGradientColorBottom = LC_RGB(255, 255, 255); mOverlayColor = lcGetProfileInt(LC_PROFILE_OVERLAY_COLOR); mActiveViewColor = LC_RGBA(41, 128, 185, 255); mGridStudColor = LC_RGBA(24, 24, 24, 192); @@ -113,11 +124,13 @@ void lcPreferences::SetInterfaceColors(lcColorTheme ColorTheme) mViewSphereColor = LC_RGBA(35, 38, 41, 255); mViewSphereTextColor = LC_RGBA(224, 224, 224, 255); mViewSphereHighlightColor = LC_RGBA(41, 128, 185, 255); - // todo: background color } else { mAxesColor = LC_RGBA(0, 0, 0, 255); + mBackgroundSolidColor = LC_RGB(255, 255, 255); + mBackgroundGradientColorTop = LC_RGB(54, 72, 95); + mBackgroundGradientColorBottom = LC_RGB(49, 52, 55); mOverlayColor = LC_RGBA(0, 0, 0, 255); mActiveViewColor = LC_RGBA(255, 0, 0, 255); mGridStudColor = LC_RGBA(64, 64, 64, 192); diff --git a/common/lc_application.h b/common/lc_application.h index a640a317..3e352ee8 100644 --- a/common/lc_application.h +++ b/common/lc_application.h @@ -51,6 +51,10 @@ public: int mMouseSensitivity; lcShadingMode mShadingMode; + bool mBackgroundGradient; + quint32 mBackgroundSolidColor; + quint32 mBackgroundGradientColorTop; + quint32 mBackgroundGradientColorBottom; bool mDrawAxes; quint32 mAxesColor; quint32 mOverlayColor; diff --git a/common/lc_model.cpp b/common/lc_model.cpp index e852380f..94af6e81 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -31,26 +31,11 @@ void lcModelProperties::LoadDefaults() { mAuthor = lcGetProfileString(LC_PROFILE_DEFAULT_AUTHOR_NAME); - - mBackgroundType = (lcBackgroundType)lcGetProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_TYPE); - mBackgroundSolidColor = lcVector3FromColor(lcGetProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_COLOR)); - mBackgroundGradientColor1 = lcVector3FromColor(lcGetProfileInt(LC_PROFILE_DEFAULT_GRADIENT_COLOR1)); - mBackgroundGradientColor2 = lcVector3FromColor(lcGetProfileInt(LC_PROFILE_DEFAULT_GRADIENT_COLOR2)); - mBackgroundImage = lcGetProfileString(LC_PROFILE_DEFAULT_BACKGROUND_TEXTURE); - mBackgroundImageTile = lcGetProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_TILE); - mAmbientColor = lcVector3FromColor(lcGetProfileInt(LC_PROFILE_DEFAULT_AMBIENT_COLOR)); } void lcModelProperties::SaveDefaults() { - lcSetProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_TYPE, mBackgroundType); - lcSetProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_COLOR, lcColorFromVector3(mBackgroundSolidColor)); - lcSetProfileInt(LC_PROFILE_DEFAULT_GRADIENT_COLOR1, lcColorFromVector3(mBackgroundGradientColor1)); - lcSetProfileInt(LC_PROFILE_DEFAULT_GRADIENT_COLOR2, lcColorFromVector3(mBackgroundGradientColor2)); - lcSetProfileString(LC_PROFILE_DEFAULT_BACKGROUND_TEXTURE, mBackgroundImage); - lcSetProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_TILE, mBackgroundImageTile); - lcSetProfileInt(LC_PROFILE_DEFAULT_AMBIENT_COLOR, lcColorFromVector3(mAmbientColor)); } @@ -69,32 +54,6 @@ void lcModelProperties::SaveLDraw(QTextStream& Stream) const Stream << QLatin1String("0 !LEOCAD MODEL COMMENT ") << Comment << LineEnding; } - bool TypeChanged = (mBackgroundType != lcGetDefaultProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_TYPE)); - - switch (mBackgroundType) - { - case LC_BACKGROUND_SOLID: - if (mBackgroundSolidColor != lcVector3FromColor(lcGetDefaultProfileInt(LC_PROFILE_DEFAULT_BACKGROUND_COLOR)) || TypeChanged) - Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND COLOR ") << mBackgroundSolidColor[0] << ' ' << mBackgroundSolidColor[1] << ' ' << mBackgroundSolidColor[2] << LineEnding; - break; - - case LC_BACKGROUND_GRADIENT: - if (mBackgroundGradientColor1 != lcVector3FromColor(lcGetProfileInt(LC_PROFILE_DEFAULT_GRADIENT_COLOR1)) || - mBackgroundGradientColor2 != lcVector3FromColor(lcGetProfileInt(LC_PROFILE_DEFAULT_GRADIENT_COLOR2)) || TypeChanged) - Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND GRADIENT ") << mBackgroundGradientColor1[0] << ' ' << mBackgroundGradientColor1[1] << ' ' << mBackgroundGradientColor1[2] << ' ' << mBackgroundGradientColor2[0] << ' ' << mBackgroundGradientColor2[1] << ' ' << mBackgroundGradientColor2[2] << LineEnding; - break; - - case LC_BACKGROUND_IMAGE: - if (!mBackgroundImage.isEmpty()) - { - Stream << QLatin1String("0 !LEOCAD MODEL BACKGROUND IMAGE "); - if (mBackgroundImageTile) - Stream << QLatin1String("TILE "); - Stream << QLatin1String("NAME ") << mBackgroundImage << LineEnding; - } - break; - } - // lcVector3 mAmbientColor; } @@ -148,37 +107,6 @@ void lcModelProperties::ParseLDrawLine(QTextStream& Stream) mComments += '\n'; mComments += Comment; } - else if (Token == QLatin1String("BACKGROUND")) - { - Stream >> Token; - - if (Token == QLatin1String("COLOR")) - { - mBackgroundType = LC_BACKGROUND_SOLID; - Stream >> mBackgroundSolidColor[0] >> mBackgroundSolidColor[1] >> mBackgroundSolidColor[2]; - } - else if (Token == QLatin1String("GRADIENT")) - { - mBackgroundType = LC_BACKGROUND_GRADIENT; - Stream >> mBackgroundGradientColor1[0] >> mBackgroundGradientColor1[1] >> mBackgroundGradientColor1[2] >> mBackgroundGradientColor2[0] >> mBackgroundGradientColor2[1] >> mBackgroundGradientColor2[2]; - } - else if (Token == QLatin1String("IMAGE")) - { - Stream >> Token; - - if (Token == QLatin1String("TILE")) - { - mBackgroundImageTile = true; - Stream >> Token; - } - - if (Token == QLatin1String("NAME")) - { - mBackgroundImage = Stream.readLine().trimmed(); - mBackgroundType = LC_BACKGROUND_IMAGE; - } - } - } } lcModel::lcModel(const QString& FileName, bool Preview) @@ -190,7 +118,6 @@ lcModel::lcModel(const QString& FileName, bool Preview) mActive = false; mCurrentStep = 1; - mBackgroundTexture = nullptr; mPieceInfo = nullptr; } @@ -263,9 +190,6 @@ void lcModel::DeleteHistory() void lcModel::DeleteModel() { - lcReleaseTexture(mBackgroundTexture); - mBackgroundTexture = nullptr; - if (gMainWindow) { const lcArray* Views = gMainWindow->GetViewsForModel(this); @@ -757,7 +681,6 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project) mCurrentStep = CurrentStep; CalculateStep(mCurrentStep); - UpdateBackgroundTexture(); Library->WaitForLoadQueue(); Library->mBuffersDirty = true; Library->UnloadUnusedParts(); @@ -794,9 +717,6 @@ bool lcModel::LoadBinary(lcFile* file) file->ReadFloats(&fv, 1); file->ReadU32(&rgb, 1); - mProperties.mBackgroundSolidColor[0] = (float)((unsigned char) (rgb))/255; - mProperties.mBackgroundSolidColor[1] = (float)((unsigned char) (((unsigned short) (rgb)) >> 8))/255; - mProperties.mBackgroundSolidColor[2] = (float)((unsigned char) ((rgb) >> 16))/255; if (fv < 0.6f) // old view { @@ -993,7 +913,6 @@ bool lcModel::LoadBinary(lcFile* file) { char Background[LC_MAXPATH]; file->ReadBuffer(Background, sh); - mProperties.mBackgroundImage = Background; } else file->Seek(sh, SEEK_CUR); @@ -1023,16 +942,9 @@ bool lcModel::LoadBinary(lcFile* file) if (fv > 1.0f) { file->ReadU32(&rgb, 1); - mProperties.mBackgroundGradientColor1[0] = (float)((unsigned char) (rgb))/255; - mProperties.mBackgroundGradientColor1[1] = (float)((unsigned char) (((unsigned short) (rgb)) >> 8))/255; - mProperties.mBackgroundGradientColor1[2] = (float)((unsigned char) ((rgb) >> 16))/255; file->ReadU32(&rgb, 1); - mProperties.mBackgroundGradientColor2[0] = (float)((unsigned char) (rgb))/255; - mProperties.mBackgroundGradientColor2[1] = (float)((unsigned char) (((unsigned short) (rgb)) >> 8))/255; - mProperties.mBackgroundGradientColor2[2] = (float)((unsigned char) ((rgb) >> 16))/255; } - UpdateBackgroundTexture(); CalculateStep(mCurrentStep); lcGetPiecesLibrary()->UnloadUnusedParts(); @@ -1347,9 +1259,12 @@ void lcModel::AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMat void lcModel::DrawBackground(lcGLWidget* Widget) { - if (mProperties.mBackgroundType == LC_BACKGROUND_SOLID) + const lcPreferences& Preferences = lcGetPreferences(); + + if (!Preferences.mBackgroundGradient) { - glClearColor(mProperties.mBackgroundSolidColor[0], mProperties.mBackgroundSolidColor[1], mProperties.mBackgroundSolidColor[2], 0.0f); + lcVector3 BackgroundColor = lcVector3FromColor(Preferences.mBackgroundSolidColor); + glClearColor(BackgroundColor[0], BackgroundColor[1], BackgroundColor[2], 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); return; } @@ -1368,56 +1283,26 @@ void lcModel::DrawBackground(lcGLWidget* Widget) Context->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0))); Context->SetProjectionMatrix(lcMatrix44Ortho(0.0f, ViewWidth, 0.0f, ViewHeight, -1.0f, 1.0f)); - if (mProperties.mBackgroundType == LC_BACKGROUND_GRADIENT) + Context->SetSmoothShading(true); + + const lcVector3 Color1 = lcVector3FromColor(Preferences.mBackgroundGradientColorTop); + const lcVector3 Color2 = lcVector3FromColor(Preferences.mBackgroundGradientColorBottom); + + float Verts[] = { - Context->SetSmoothShading(true); + ViewWidth, ViewHeight, Color1[0], Color1[1], Color1[2], 1.0f, + 0.0f, ViewHeight, Color1[0], Color1[1], Color1[2], 1.0f, + 0.0f, 0.0f, Color2[0], Color2[1], Color2[2], 1.0f, + ViewWidth, 0.0f, Color2[0], Color2[1], Color2[2], 1.0f + }; - const lcVector3& Color1 = mProperties.mBackgroundGradientColor1; - const lcVector3& Color2 = mProperties.mBackgroundGradientColor2; + Context->SetMaterial(lcMaterialType::UnlitVertexColor); + Context->SetVertexBufferPointer(Verts); + Context->SetVertexFormat(0, 2, 0, 0, 4, false); - float Verts[] = - { - ViewWidth, ViewHeight, Color1[0], Color1[1], Color1[2], 1.0f, - 0.0f, ViewHeight, Color1[0], Color1[1], Color1[2], 1.0f, - 0.0f, 0.0f, Color2[0], Color2[1], Color2[2], 1.0f, - ViewWidth, 0.0f, Color2[0], Color2[1], Color2[2], 1.0f - }; + Context->DrawPrimitives(GL_TRIANGLE_FAN, 0, 4); - Context->SetMaterial(lcMaterialType::UnlitVertexColor); - Context->SetVertexBufferPointer(Verts); - Context->SetVertexFormat(0, 2, 0, 0, 4, false); - - Context->DrawPrimitives(GL_TRIANGLE_FAN, 0, 4); - - Context->SetSmoothShading(false); - } - else if (mProperties.mBackgroundType == LC_BACKGROUND_IMAGE) - { - Context->BindTexture2D(mBackgroundTexture->mTexture); - - float TileWidth = 1.0f, TileHeight = 1.0f; - - if (mProperties.mBackgroundImageTile) - { - TileWidth = ViewWidth / mBackgroundTexture->mWidth; - TileHeight = ViewHeight / mBackgroundTexture->mHeight; - } - - float Verts[] = - { - 0.0f, ViewHeight, 0.0f, 0.0f, - ViewWidth, ViewHeight, TileWidth, 0.0f, - ViewWidth, 0.0f, TileWidth, TileHeight, - 0.0f, 0.0f, 0.0f, TileHeight - }; - - Context->SetColor(1.0f, 1.0f, 1.0f, 1.0f); - Context->SetMaterial(lcMaterialType::UnlitTextureDecal); - Context->SetVertexBufferPointer(Verts); - Context->SetVertexFormat(0, 2, 0, 2, 0, false); - - Context->DrawPrimitives(GL_TRIANGLE_FAN, 0, 4); - } + Context->SetSmoothShading(false); glEnable(GL_DEPTH_TEST); Context->SetDepthWrite(true); @@ -1747,20 +1632,6 @@ std::vector lcModel::GetPageLayouts(std::vectorGetPreviewWidget()->UpdatePreview(); diff --git a/common/lc_model.h b/common/lc_model.h index 8d0c8a3f..47e26846 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -44,13 +44,6 @@ enum class lcTransformType Count }; -enum lcBackgroundType -{ - LC_BACKGROUND_SOLID, - LC_BACKGROUND_GRADIENT, - LC_BACKGROUND_IMAGE -}; - class lcModelProperties { public: @@ -63,11 +56,6 @@ public: mDescription != Properties.mDescription || mComments != Properties.mComments) return false; - if (mBackgroundType != Properties.mBackgroundType || mBackgroundSolidColor != Properties.mBackgroundSolidColor || - mBackgroundGradientColor1 != Properties.mBackgroundGradientColor1 || mBackgroundGradientColor2 != Properties.mBackgroundGradientColor2 || - mBackgroundImage != Properties.mBackgroundImage || mBackgroundImageTile != Properties.mBackgroundImageTile) - return false; - if (mAmbientColor != Properties.mAmbientColor) return false; @@ -84,13 +72,6 @@ public: QString mAuthor; QString mComments; - lcBackgroundType mBackgroundType; - lcVector3 mBackgroundSolidColor; - lcVector3 mBackgroundGradientColor1; - lcVector3 mBackgroundGradientColor2; - QString mBackgroundImage; - bool mBackgroundImageTile; - lcVector3 mAmbientColor; }; @@ -380,8 +361,6 @@ protected: void RemoveEmptyGroups(); bool RemoveSelectedObjects(); - void UpdateBackgroundTexture(); - void SelectGroup(lcGroup* TopGroup, bool Select); void AddPiece(lcPiece* Piece); @@ -394,7 +373,6 @@ protected: bool mActive; lcStep mCurrentStep; lcVector3 mMouseToolDistance; - lcTexture* mBackgroundTexture; lcArray mPieces; lcArray mCameras; @@ -408,4 +386,3 @@ protected: Q_DECLARE_TR_FUNCTIONS(lcModel); }; - diff --git a/common/lc_profile.cpp b/common/lc_profile.cpp index 3e5a3eea..42837d99 100644 --- a/common/lc_profile.cpp +++ b/common/lc_profile.cpp @@ -64,6 +64,10 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] = 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(lcShadingMode::DefaultLights)), // LC_PROFILE_SHADING_MODE + lcProfileEntry("Settings", "BackgroundGradient", false), // LC_PROFILE_BACKGROUND_GRADIENT + lcProfileEntry("Settings", "BackgroundColor", LC_RGB(49, 52, 55)), // LC_PROFILE_BACKGROUND_COLOR + lcProfileEntry("Settings", "GradientColorTop", LC_RGB(54, 72, 95)), // LC_PROFILE_GRADIENT_COLOR_TOP + lcProfileEntry("Settings", "GradientColorBottom", LC_RGB(49, 52, 55)), // LC_PROFILE_GRADIENT_COLOR_BOTTOM lcProfileEntry("Settings", "DrawAxes", 0), // LC_PROFILE_DRAW_AXES lcProfileEntry("Settings", "AxesColor", LC_RGBA(0, 0, 0, 255)), // LC_PROFILE_AXES_COLOR lcProfileEntry("Settings", "OverlayColor", LC_RGBA(0, 0, 0, 255)), // LC_PROFILE_OVERLAY_COLOR @@ -114,12 +118,6 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] = lcProfileEntry("Defaults", "Author", ""), // LC_PROFILE_DEFAULT_AUTHOR_NAME lcProfileEntry("Defaults", "AmbientColor", LC_RGB(75, 75, 75)), // LC_PROFILE_DEFAULT_AMBIENT_COLOR - lcProfileEntry("Defaults", "BackgroundType", LC_BACKGROUND_SOLID), // LC_PROFILE_DEFAULT_BACKGROUND_TYPE - lcProfileEntry("Defaults", "BackgroundColor", LC_RGB(255, 255, 255)), // LC_PROFILE_DEFAULT_BACKGROUND_COLOR - lcProfileEntry("Defaults", "GradientColor1", LC_RGB(0, 0, 191)), // LC_PROFILE_DEFAULT_GRADIENT_COLOR1 - lcProfileEntry("Defaults", "GradientColor2", LC_RGB(255, 255, 255)), // LC_PROFILE_DEFAULT_GRADIENT_COLOR2 - lcProfileEntry("Defaults", "BackgroundTexture", ""), // LC_PROFILE_DEFAULT_BACKGROUND_TEXTURE - lcProfileEntry("Defaults", "BackgroundTile", 0), // LC_PROFILE_DEFAULT_BACKGROUND_TILE lcProfileEntry("HTML", "Options", LC_HTML_SINGLEPAGE), // LC_PROFILE_HTML_OPTIONS lcProfileEntry("HTML", "ImageOptions", LC_IMAGE_TRANSPARENT), // LC_PROFILE_HTML_IMAGE_OPTIONS diff --git a/common/lc_profile.h b/common/lc_profile.h index 6f2c1d48..d291dc89 100644 --- a/common/lc_profile.h +++ b/common/lc_profile.h @@ -12,6 +12,10 @@ enum LC_PROFILE_KEY LC_PROFILE_HIGHLIGHT_NEW_PARTS, LC_PROFILE_HIGHLIGHT_NEW_PARTS_COLOR, LC_PROFILE_SHADING_MODE, + LC_PROFILE_BACKGROUND_GRADIENT, + LC_PROFILE_BACKGROUND_COLOR, + LC_PROFILE_GRADIENT_COLOR_TOP, + LC_PROFILE_GRADIENT_COLOR_BOTTOM, LC_PROFILE_DRAW_AXES, LC_PROFILE_AXES_COLOR, LC_PROFILE_OVERLAY_COLOR, @@ -63,12 +67,6 @@ enum LC_PROFILE_KEY // Defaults for new projects. LC_PROFILE_DEFAULT_AUTHOR_NAME, LC_PROFILE_DEFAULT_AMBIENT_COLOR, - LC_PROFILE_DEFAULT_BACKGROUND_TYPE, - LC_PROFILE_DEFAULT_BACKGROUND_COLOR, - LC_PROFILE_DEFAULT_GRADIENT_COLOR1, - LC_PROFILE_DEFAULT_GRADIENT_COLOR2, - LC_PROFILE_DEFAULT_BACKGROUND_TEXTURE, - LC_PROFILE_DEFAULT_BACKGROUND_TILE, // Exporters. LC_PROFILE_HTML_OPTIONS, diff --git a/common/project.cpp b/common/project.cpp index 43ec0b26..af4b1cd6 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -914,17 +914,15 @@ void Project::Export3DStudio(const QString& FileName) File.WriteU16(0x0010); // CHK_COLOR_F File.WriteU32(18); - File.WriteFloats(Properties.mBackgroundSolidColor, 3); + const lcPreferences& Preferences = lcGetPreferences(); + lcVector3 BackgroundSolidColor = lcVector3FromColor(Preferences.mBackgroundSolidColor); + + File.WriteFloats(BackgroundSolidColor, 3); File.WriteU16(0x0013); // CHK_LIN_COLOR_F File.WriteU32(18); - File.WriteFloats(Properties.mBackgroundSolidColor, 3); - - File.WriteU16(0x1100); // CHK_BIT_MAP - QByteArray BackgroundImage = Properties.mBackgroundImage.toLatin1(); - File.WriteU32(6 + 1 + (quint32)strlen(BackgroundImage.constData())); - File.WriteBuffer(BackgroundImage.constData(), strlen(BackgroundImage.constData()) + 1); + File.WriteFloats(BackgroundSolidColor, 3); File.WriteU16(0x1300); // CHK_V_GRADIENT File.WriteU32(118); @@ -934,43 +932,41 @@ void Project::Export3DStudio(const QString& FileName) File.WriteU16(0x0010); // CHK_COLOR_F File.WriteU32(18); - File.WriteFloats(Properties.mBackgroundGradientColor1, 3); + const lcVector3 BackgroundGradientColor1 = lcVector3FromColor(Preferences.mBackgroundGradientColorTop); + const lcVector3 BackgroundGradientColor2 = lcVector3FromColor(Preferences.mBackgroundGradientColorBottom); + + File.WriteFloats(BackgroundGradientColor1, 3); File.WriteU16(0x0013); // CHK_LIN_COLOR_F File.WriteU32(18); - File.WriteFloats(Properties.mBackgroundGradientColor1, 3); + File.WriteFloats(BackgroundGradientColor1, 3); File.WriteU16(0x0010); // CHK_COLOR_F File.WriteU32(18); - File.WriteFloats((Properties.mBackgroundGradientColor1 + Properties.mBackgroundGradientColor2) / 2.0f, 3); + File.WriteFloats((BackgroundGradientColor1 + BackgroundGradientColor2) / 2.0f, 3); File.WriteU16(0x0013); // CHK_LIN_COLOR_F File.WriteU32(18); - File.WriteFloats((Properties.mBackgroundGradientColor1 + Properties.mBackgroundGradientColor2) / 2.0f, 3); + File.WriteFloats((BackgroundGradientColor1 + BackgroundGradientColor2) / 2.0f, 3); File.WriteU16(0x0010); // CHK_COLOR_F File.WriteU32(18); - File.WriteFloats(Properties.mBackgroundGradientColor2, 3); + File.WriteFloats(BackgroundGradientColor2, 3); File.WriteU16(0x0013); // CHK_LIN_COLOR_F File.WriteU32(18); - File.WriteFloats(Properties.mBackgroundGradientColor2, 3); + File.WriteFloats(BackgroundGradientColor2, 3); - if (Properties.mBackgroundType == LC_BACKGROUND_GRADIENT) + if (Preferences.mBackgroundGradient) { File.WriteU16(0x1301); // LIB3DS_USE_V_GRADIENT File.WriteU32(6); } - else if (Properties.mBackgroundType == LC_BACKGROUND_IMAGE) - { - File.WriteU16(0x1101); // LIB3DS_USE_BIT_MAP - File.WriteU32(6); - } else { File.WriteU16(0x1201); // LIB3DS_USE_SOLID_BGND @@ -1969,12 +1965,12 @@ bool Project::ExportPOVRay(const QString& FileName) const lcVector3& Position = Camera->mPosition; const lcVector3& Target = Camera->mTargetPosition; const lcVector3& Up = Camera->mUpVector; - const lcModelProperties& Properties = mModels[0]->GetProperties(); sprintf(Line, "camera {\n perspective\n right x * image_width / image_height\n sky<%1g,%1g,%1g>\n location <%1g, %1g, %1g>\n look_at <%1g, %1g, %1g>\n angle %.0f * image_width / image_height\n}\n\n", Up[1], Up[0], Up[2], Position[1] / 25.0f, Position[0] / 25.0f, Position[2] / 25.0f, Target[1] / 25.0f, Target[0] / 25.0f, Target[2] / 25.0f, Camera->m_fovy); POVFile.WriteLine(Line); - sprintf(Line, "background { color rgb <%1g, %1g, %1g> }\n\n", Properties.mBackgroundSolidColor[0], Properties.mBackgroundSolidColor[1], Properties.mBackgroundSolidColor[2]); + lcVector3 BackgroundColor = lcVector3FromColor(lcGetPreferences().mBackgroundSolidColor); + sprintf(Line, "background { color rgb <%1g, %1g, %1g> }\n\n", BackgroundColor[0], BackgroundColor[1], BackgroundColor[2]); POVFile.WriteLine(Line); lcVector3 Min(FLT_MAX, FLT_MAX, FLT_MAX); diff --git a/qt/lc_qpreferencesdialog.cpp b/qt/lc_qpreferencesdialog.cpp index 0544481e..c0c84b14 100644 --- a/qt/lc_qpreferencesdialog.cpp +++ b/qt/lc_qpreferencesdialog.cpp @@ -28,6 +28,9 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO delete ui->povrayLayout; #endif + connect(ui->BackgroundSolidColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked())); + connect(ui->BackgroundGradient1ColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked())); + connect(ui->BackgroundGradient2ColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked())); connect(ui->AxesColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked())); connect(ui->OverlayColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked())); connect(ui->FadeStepsColor, SIGNAL(clicked()), this, SLOT(ColorButtonClicked())); @@ -102,6 +105,11 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO ui->gridLineSpacing->setText(QString::number(mOptions->Preferences.mGridLineSpacing)); ui->AxisIconCheckBox->setChecked(mOptions->Preferences.mDrawAxes); + if (!mOptions->Preferences.mBackgroundGradient) + ui->BackgroundSolidRadio->setChecked(true); + else + ui->BackgroundGradientRadio->setChecked(true); + ui->ViewSphereLocationCombo->setCurrentIndex((int)mOptions->Preferences.mViewSphereLocation); if (mOptions->Preferences.mViewSphereEnabled) @@ -186,6 +194,15 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO QPixmap pix(12, 12); + pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mBackgroundSolidColor), LC_RGBA_GREEN(mOptions->Preferences.mBackgroundSolidColor), LC_RGBA_BLUE(mOptions->Preferences.mBackgroundSolidColor))); + ui->BackgroundSolidColorButton->setIcon(pix); + + pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mBackgroundGradientColorTop), LC_RGBA_GREEN(mOptions->Preferences.mBackgroundGradientColorTop), LC_RGBA_BLUE(mOptions->Preferences.mBackgroundGradientColorTop))); + ui->BackgroundGradient1ColorButton->setIcon(pix); + + pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mBackgroundGradientColorBottom), LC_RGBA_GREEN(mOptions->Preferences.mBackgroundGradientColorBottom), LC_RGBA_BLUE(mOptions->Preferences.mBackgroundGradientColorBottom))); + ui->BackgroundGradient2ColorButton->setIcon(pix); + pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mAxesColor), LC_RGBA_GREEN(mOptions->Preferences.mAxesColor), LC_RGBA_BLUE(mOptions->Preferences.mAxesColor))); ui->AxesColorButton->setIcon(pix); @@ -307,6 +324,7 @@ void lcQPreferencesDialog::accept() mOptions->Preferences.mDrawGridLines = ui->gridLines->isChecked(); mOptions->Preferences.mGridLineSpacing = gridLineSpacing; + mOptions->Preferences.mBackgroundGradient = ui->BackgroundGradientRadio->isChecked(); mOptions->Preferences.mDrawAxes = ui->AxisIconCheckBox->isChecked(); mOptions->Preferences.mViewSphereLocation = (lcViewSphereLocation)ui->ViewSphereLocationCombo->currentIndex(); @@ -443,7 +461,25 @@ void lcQPreferencesDialog::ColorButtonClicked() quint32* Color = nullptr; QColorDialog::ColorDialogOptions DialogOptions; - if (Button == ui->AxesColorButton) + if (Button == ui->BackgroundSolidColorButton) + { + Color = &mOptions->Preferences.mBackgroundSolidColor; + Title = tr("Select Background Color"); + DialogOptions = 0; + } + else if (Button == ui->BackgroundGradient1ColorButton) + { + Color = &mOptions->Preferences.mBackgroundGradientColorTop; + Title = tr("Select Gradient Top Color"); + DialogOptions = 0; + } + else if (Button == ui->BackgroundGradient2ColorButton) + { + Color = &mOptions->Preferences.mBackgroundGradientColorBottom; + Title = tr("Select Gradient Bottom Color"); + DialogOptions = 0; + } + else if (Button == ui->AxesColorButton) { Color = &mOptions->Preferences.mAxesColor; Title = tr("Select Axes Color"); diff --git a/qt/lc_qpreferencesdialog.ui b/qt/lc_qpreferencesdialog.ui index 67aa905d..031c64e5 100644 --- a/qt/lc_qpreferencesdialog.ui +++ b/qt/lc_qpreferencesdialog.ui @@ -7,7 +7,7 @@ 0 0 598 - 503 + 530 @@ -545,6 +545,98 @@ Interface + + + + Background + + + + + + + + Top Color + + + + + + + + + + + + + + Bottom Color + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + So&lid Color + + + + + + + &Gradient + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + @@ -1549,6 +1641,11 @@ HighlightNewParts HighlightNewPartsColor ShadingMode + BackgroundSolidRadio + BackgroundSolidColorButton + BackgroundGradientRadio + BackgroundGradient1ColorButton + BackgroundGradient2ColorButton AxisIconCheckBox AxesColorButton ActiveViewColorButton diff --git a/qt/lc_qpropertiesdialog.cpp b/qt/lc_qpropertiesdialog.cpp index bead7e40..f5b58647 100644 --- a/qt/lc_qpropertiesdialog.cpp +++ b/qt/lc_qpropertiesdialog.cpp @@ -30,17 +30,13 @@ public: bool mLast; }; -lcQPropertiesDialog::lcQPropertiesDialog(QWidget *parent, void *data) : - QDialog(parent), +lcQPropertiesDialog::lcQPropertiesDialog(QWidget* Parent, void* Data) + : QDialog(Parent), ui(new Ui::lcQPropertiesDialog) { ui->setupUi(this); - connect(ui->solidColorButton, SIGNAL(clicked()), this, SLOT(colorClicked())); - connect(ui->gradient1ColorButton, SIGNAL(clicked()), this, SLOT(colorClicked())); - connect(ui->gradient2ColorButton, SIGNAL(clicked()), this, SLOT(colorClicked())); - - options = (lcPropertiesDialogOptions*)data; + options = (lcPropertiesDialogOptions*)Data; setWindowTitle(tr("%1 Properties").arg(options->Properties.mFileName)); @@ -48,25 +44,6 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget *parent, void *data) : ui->authorEdit->setText(options->Properties.mAuthor); ui->commentsEdit->setText(options->Properties.mComments); - if (options->Properties.mBackgroundType == LC_BACKGROUND_IMAGE) - ui->imageRadio->setChecked(true); - else if (options->Properties.mBackgroundType == LC_BACKGROUND_GRADIENT) - ui->gradientRadio->setChecked(true); - else - ui->solidRadio->setChecked(true); - - ui->imageNameEdit->setText(options->Properties.mBackgroundImage); - ui->imageTileCheckBox->setChecked(options->Properties.mBackgroundImageTile); - - QPixmap pix(12, 12); - - pix.fill(QColor(options->Properties.mBackgroundSolidColor[0] * 255, options->Properties.mBackgroundSolidColor[1] * 255, options->Properties.mBackgroundSolidColor[2] * 255)); - ui->solidColorButton->setIcon(pix); - pix.fill(QColor(options->Properties.mBackgroundGradientColor1[0] * 255, options->Properties.mBackgroundGradientColor1[1] * 255, options->Properties.mBackgroundGradientColor1[2] * 255)); - ui->gradient1ColorButton->setIcon(pix); - pix.fill(QColor(options->Properties.mBackgroundGradientColor2[0] * 255, options->Properties.mBackgroundGradientColor2[1] * 255, options->Properties.mBackgroundGradientColor2[2] * 255)); - ui->gradient2ColorButton->setIcon(pix); - const lcPartsList& PartsList = options->PartsList; QStringList horizontalLabels; @@ -168,65 +145,5 @@ void lcQPropertiesDialog::accept() options->Properties.mAuthor = ui->authorEdit->text(); options->Properties.mComments = ui->commentsEdit->toPlainText(); - if (ui->imageRadio->isChecked()) - options->Properties.mBackgroundType = LC_BACKGROUND_IMAGE; - else if (ui->gradientRadio->isChecked()) - options->Properties.mBackgroundType = LC_BACKGROUND_GRADIENT; - else - options->Properties.mBackgroundType = LC_BACKGROUND_SOLID; - - options->Properties.mBackgroundImage = ui->imageNameEdit->text(); - options->Properties.mBackgroundImageTile = ui->imageTileCheckBox->isChecked(); - options->SetDefault = ui->setDefaultCheckBox->isChecked(); - QDialog::accept(); } - -void lcQPropertiesDialog::colorClicked() -{ - QObject *button = sender(); - QString title; - float *color = nullptr; - - if (button == ui->solidColorButton) - { - color = options->Properties.mBackgroundSolidColor; - title = tr("Select Background Color"); - } - else if (button == ui->gradient1ColorButton) - { - color = options->Properties.mBackgroundGradientColor1; - title = tr("Select Background Top Color"); - } - else if (button == ui->gradient2ColorButton) - { - color = options->Properties.mBackgroundGradientColor2; - title = tr("Select Background Bottom Color"); - } - - if (!color) - return; - - QColor oldColor = QColor(color[0] * 255, color[1] * 255, color[2] * 255); - QColor newColor = QColorDialog::getColor(oldColor, this, title); - - if (newColor == oldColor || !newColor.isValid()) - return; - - color[0] = (float)newColor.red() / 255.0f; - color[1] = (float)newColor.green() / 255.0f; - color[2] = (float)newColor.blue() / 255.0f; - - QPixmap pix(12, 12); - - pix.fill(newColor); - ((QToolButton*)button)->setIcon(pix); -} - -void lcQPropertiesDialog::on_imageNameButton_clicked() -{ - QString result = QFileDialog::getOpenFileName(this, tr("Select Background Image"), ui->imageNameEdit->text(), tr("All Image Files (*.png *.jpg *.gif *.bmp);;PNG Files (*.png);;JPEG Files (*.jpg);;GIF Files (*.gif);;BMP Files (*.bmp);;All Files (*.*)")); - - if (!result.isEmpty()) - ui->imageNameEdit->setText(QDir::toNativeSeparators(result)); -} diff --git a/qt/lc_qpropertiesdialog.h b/qt/lc_qpropertiesdialog.h index 6f89d056..88fe6160 100644 --- a/qt/lc_qpropertiesdialog.h +++ b/qt/lc_qpropertiesdialog.h @@ -12,15 +12,13 @@ class lcQPropertiesDialog : public QDialog Q_OBJECT public: - explicit lcQPropertiesDialog(QWidget *parent, void *data); + lcQPropertiesDialog(QWidget* Parent, void* Data); ~lcQPropertiesDialog(); lcPropertiesDialogOptions *options; public slots: void accept() override; - void colorClicked(); - void on_imageNameButton_clicked(); private: Ui::lcQPropertiesDialog *ui; diff --git a/qt/lc_qpropertiesdialog.ui b/qt/lc_qpropertiesdialog.ui index 06ec23fe..fc09b274 100644 --- a/qt/lc_qpropertiesdialog.ui +++ b/qt/lc_qpropertiesdialog.ui @@ -72,139 +72,6 @@ - - - Scene - - - - - - Background - - - - - - - - - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - So&lid Color - - - - - - - Image - - - - - - - &Gradient - - - - - - - - - - - - ... - - - - - - - - - Tile - - - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - Set default options for new projects - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - Parts Used @@ -251,16 +118,6 @@ authorEdit descriptionEdit commentsEdit - solidRadio - solidColorButton - gradientRadio - gradient1ColorButton - gradient2ColorButton - imageRadio - imageNameEdit - imageNameButton - imageTileCheckBox - setDefaultCheckBox partsTable