From c92c423e3fc29bfbb9c2b24c54d931e5a195c18a Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Mon, 11 Jan 2021 18:49:57 -0800 Subject: [PATCH] Added option to color grid origin lines. Fixes #372. --- common/lc_application.cpp | 2 ++ common/lc_application.h | 1 + common/lc_profile.cpp | 1 + common/lc_profile.h | 1 + common/lc_view.cpp | 26 +++++++++++++++++++++++++- qt/lc_qpreferencesdialog.cpp | 2 ++ qt/lc_qpreferencesdialog.ui | 30 +++++++++++++++++++----------- 7 files changed, 51 insertions(+), 12 deletions(-) diff --git a/common/lc_application.cpp b/common/lc_application.cpp index 320d35a7..b67d6011 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -44,6 +44,7 @@ void lcPreferences::LoadDefaults() mDrawGridLines = lcGetProfileInt(LC_PROFILE_GRID_LINES); mGridLineSpacing = lcGetProfileInt(LC_PROFILE_GRID_LINE_SPACING); mGridLineColor = lcGetProfileInt(LC_PROFILE_GRID_LINE_COLOR); + mDrawGridOrigin = lcGetProfileInt(LC_PROFILE_GRID_ORIGIN); mViewSphereEnabled = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_ENABLED); mViewSphereLocation = static_cast(lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_LOCATION)); mViewSphereSize = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_SIZE); @@ -89,6 +90,7 @@ void lcPreferences::SaveDefaults() lcSetProfileInt(LC_PROFILE_GRID_LINES, mDrawGridLines); lcSetProfileInt(LC_PROFILE_GRID_LINE_SPACING, mGridLineSpacing); lcSetProfileInt(LC_PROFILE_GRID_LINE_COLOR, mGridLineColor); + lcSetProfileInt(LC_PROFILE_GRID_LINE_COLOR, mDrawGridOrigin); lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_ENABLED, mViewSphereSize ? 1 : 0); lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_LOCATION, static_cast(mViewSphereLocation)); lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_SIZE, mViewSphereSize); diff --git a/common/lc_application.h b/common/lc_application.h index 0be3b6e5..e4b7f845 100644 --- a/common/lc_application.h +++ b/common/lc_application.h @@ -56,6 +56,7 @@ public: bool mDrawGridLines; int mGridLineSpacing; quint32 mGridLineColor; + bool mDrawGridOrigin; bool mFixedAxes; bool mViewSphereEnabled; lcViewSphereLocation mViewSphereLocation; diff --git a/common/lc_profile.cpp b/common/lc_profile.cpp index 5052d072..fa72f175 100644 --- a/common/lc_profile.cpp +++ b/common/lc_profile.cpp @@ -83,6 +83,7 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] = lcProfileEntry("Settings", "GridLines", 1), // LC_PROFILE_GRID_LINES lcProfileEntry("Settings", "GridLineSpacing", 5), // LC_PROFILE_GRID_LINE_SPACING lcProfileEntry("Settings", "GridLineColor", LC_RGBA(24, 24, 24, 255)), // LC_PROFILE_GRID_LINE_COLOR + lcProfileEntry("Settings", "GridOrigin", 0), // LC_PROFILE_GRID_ORIGIN lcProfileEntry("Settings", "AASamples", 1), // LC_PROFILE_ANTIALIASING_SAMPLES lcProfileEntry("Settings", "ViewSphereEnabled", 1), // LC_PROFILE_VIEW_SPHERE_ENABLED lcProfileEntry("Settings", "ViewSphereLocation", (int)lcViewSphereLocation::TopRight), // LC_PROFILE_VIEW_SPHERE_LOCATION diff --git a/common/lc_profile.h b/common/lc_profile.h index 0af102f0..1273d5c5 100644 --- a/common/lc_profile.h +++ b/common/lc_profile.h @@ -30,6 +30,7 @@ enum LC_PROFILE_KEY LC_PROFILE_GRID_LINES, LC_PROFILE_GRID_LINE_SPACING, LC_PROFILE_GRID_LINE_COLOR, + LC_PROFILE_GRID_ORIGIN, LC_PROFILE_ANTIALIASING_SAMPLES, LC_PROFILE_VIEW_SPHERE_ENABLED, LC_PROFILE_VIEW_SPHERE_LOCATION, diff --git a/common/lc_view.cpp b/common/lc_view.cpp index 258978b9..f09416af 100644 --- a/common/lc_view.cpp +++ b/common/lc_view.cpp @@ -1820,7 +1820,7 @@ void lcView::DrawGrid() { const lcPreferences& Preferences = lcGetPreferences(); - if (!Preferences.mDrawGridStuds && !Preferences.mDrawGridLines) + if (!Preferences.mDrawGridStuds && !Preferences.mDrawGridLines && !Preferences.mDrawGridOrigin) return; if (!Preferences.mGridEnabled) @@ -1997,6 +1997,30 @@ void lcView::DrawGrid() mContext->SetVertexFormat(BufferOffset, 3, 0, 0, 0, false); mContext->DrawPrimitives(GL_LINES, 0, NumVerts); } + + if (Preferences.mDrawGridOrigin) + { + struct lcGridVertex + { + float x, y; + quint32 Color; + }; + + const quint32 Red = LC_RGBA(204, 0, 0, 255); + const quint32 Green = LC_RGBA(0, 204, 0, 255); + const float Scale = 20.0f * Spacing; + + const lcGridVertex Verts[4] = + { + { 0.0f, MinY * Scale, Green }, { 0.0f, MaxY * Scale, Green }, { MinX * Scale, 0.0f, Red }, { MaxX * Scale, 0.0f, Red } + }; + + mContext->SetMaterial(lcMaterialType::UnlitVertexColor); + mContext->SetVertexBufferPointer(Verts); + mContext->SetVertexFormat(0, 2, 0, 0, 4, false); + + mContext->DrawPrimitives(GL_LINES, 0, 4); + } } lcTrackTool lcView::GetOverrideTrackTool(Qt::MouseButton Button) const diff --git a/qt/lc_qpreferencesdialog.cpp b/qt/lc_qpreferencesdialog.cpp index 7f2a01de..c6052ec4 100644 --- a/qt/lc_qpreferencesdialog.cpp +++ b/qt/lc_qpreferencesdialog.cpp @@ -103,6 +103,7 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO ui->gridStuds->setChecked(mOptions->Preferences.mDrawGridStuds); ui->gridLines->setChecked(mOptions->Preferences.mDrawGridLines); ui->gridLineSpacing->setText(QString::number(mOptions->Preferences.mGridLineSpacing)); + ui->GridOriginCheckBox->setChecked(mOptions->Preferences.mDrawGridOrigin); ui->AxisIconCheckBox->setChecked(mOptions->Preferences.mDrawAxes); if (!mOptions->Preferences.mBackgroundGradient) @@ -278,6 +279,7 @@ void lcQPreferencesDialog::accept() mOptions->Preferences.mDrawGridStuds = ui->gridStuds->isChecked(); mOptions->Preferences.mDrawGridLines = ui->gridLines->isChecked(); mOptions->Preferences.mGridLineSpacing = gridLineSpacing; + mOptions->Preferences.mDrawGridOrigin = ui->GridOriginCheckBox->isChecked(); mOptions->Preferences.mBackgroundGradient = ui->BackgroundGradientRadio->isChecked(); mOptions->Preferences.mDrawAxes = ui->AxisIconCheckBox->isChecked(); diff --git a/qt/lc_qpreferencesdialog.ui b/qt/lc_qpreferencesdialog.ui index de2432bb..5a92909b 100644 --- a/qt/lc_qpreferencesdialog.ui +++ b/qt/lc_qpreferencesdialog.ui @@ -554,7 +554,7 @@ - Axis icon + Axis Icon @@ -642,13 +642,6 @@ Base Grid - - - - Draw studs - - - @@ -669,6 +662,13 @@ + + + + Draw lines every + + + @@ -679,10 +679,17 @@ - - + + - Draw lines every + Draw origin lines + + + + + + + Draw studs @@ -1703,6 +1710,7 @@ gridStuds gridLines gridLineSpacing + GridOriginCheckBox PreviewViewSphereSizeCombo PreviewViewSphereLocationCombo PreviewAxisIconCheckBox