diff --git a/common/lc_application.cpp b/common/lc_application.cpp index 7a4ece1d..37d11fb6 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -26,6 +26,7 @@ void lcPreferences::LoadDefaults() mAxesColor = lcGetProfileInt(LC_PROFILE_AXES_COLOR); mOverlayColor = lcGetProfileInt(LC_PROFILE_OVERLAY_COLOR); mActiveViewColor = lcGetProfileInt(LC_PROFILE_ACTIVE_VIEW_COLOR); + mInactiveViewColor = lcGetProfileInt(LC_PROFILE_INACTIVE_VIEW_COLOR); mDrawEdgeLines = lcGetProfileInt(LC_PROFILE_DRAW_EDGE_LINES); mLineWidth = lcGetProfileFloat(LC_PROFILE_LINE_WIDTH); mAllowLOD = lcGetProfileInt(LC_PROFILE_ALLOW_LOD); @@ -49,7 +50,6 @@ void lcPreferences::LoadDefaults() mRestoreTabLayout = lcGetProfileInt(LC_PROFILE_RESTORE_TAB_LAYOUT); mColorTheme = static_cast(lcGetProfileInt(LC_PROFILE_COLOR_THEME)); - mPreviewActiveColor = lcGetProfileInt(LC_PROFILE_PREVIEW_ACTIVE_COLOR); mPreviewViewSphereEnabled = lcGetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_ENABLED); mPreviewViewSphereSize = lcGetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_SIZE); mPreviewViewSphereLocation = static_cast(lcGetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION)); @@ -74,6 +74,7 @@ void lcPreferences::SaveDefaults() lcSetProfileInt(LC_PROFILE_GRADIENT_COLOR_BOTTOM, mBackgroundGradientColorBottom); lcSetProfileInt(LC_PROFILE_OVERLAY_COLOR, mOverlayColor); lcSetProfileInt(LC_PROFILE_ACTIVE_VIEW_COLOR, mActiveViewColor); + lcSetProfileInt(LC_PROFILE_INACTIVE_VIEW_COLOR, mInactiveViewColor); lcSetProfileInt(LC_PROFILE_DRAW_EDGE_LINES, mDrawEdgeLines); lcSetProfileFloat(LC_PROFILE_LINE_WIDTH, mLineWidth); lcSetProfileInt(LC_PROFILE_ALLOW_LOD, mAllowLOD); @@ -97,7 +98,6 @@ void lcPreferences::SaveDefaults() lcSetProfileInt(LC_PROFILE_RESTORE_TAB_LAYOUT, mRestoreTabLayout); lcSetProfileInt(LC_PROFILE_COLOR_THEME, static_cast(mColorTheme)); - lcSetProfileInt(LC_PROFILE_PREVIEW_ACTIVE_COLOR, mPreviewActiveColor); lcSetProfileInt(LC_PROFILE_PREVIEW_ENABLED, mPreviewViewSphereEnabled); lcSetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_SIZE, mPreviewViewSphereSize); lcSetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION, static_cast(mPreviewViewSphereLocation)); diff --git a/common/lc_application.h b/common/lc_application.h index 151d4053..744043f6 100644 --- a/common/lc_application.h +++ b/common/lc_application.h @@ -52,6 +52,7 @@ public: quint32 mAxesColor; quint32 mOverlayColor; quint32 mActiveViewColor; + quint32 mInactiveViewColor; bool mDrawEdgeLines; float mLineWidth; bool mAllowLOD; @@ -77,7 +78,6 @@ public: lcColorTheme mColorTheme; int mPreviewEnabled; - quint32 mPreviewActiveColor; int mPreviewViewSphereEnabled; int mPreviewViewSphereSize; lcViewSphereLocation mPreviewViewSphereLocation; diff --git a/common/lc_glwidget.cpp b/common/lc_glwidget.cpp index 701b0b97..3589ad4b 100644 --- a/common/lc_glwidget.cpp +++ b/common/lc_glwidget.cpp @@ -9,6 +9,8 @@ #include "lc_model.h" #include "lc_scene.h" +lcGLWidget* lcGLWidget::mLastFocusView; + lcGLWidget::lcGLWidget(lcModel* Model) : mModel(Model), mScene(new lcScene()) { @@ -17,6 +19,9 @@ lcGLWidget::lcGLWidget(lcModel* Model) lcGLWidget::~lcGLWidget() { + if (mLastFocusView == this) + mLastFocusView = nullptr; + if (mDeleteContext) delete mContext; } @@ -26,6 +31,12 @@ lcModel* lcGLWidget::GetActiveModel() const return !mActiveSubmodelInstance ? mModel : mActiveSubmodelInstance->mPieceInfo->GetModel(); } +void lcGLWidget::SetFocus(bool Focus) +{ + if (Focus) + mLastFocusView = this; +} + void lcGLWidget::SetMousePosition(int MouseX, int MouseY) { mMouseX = MouseX; @@ -388,6 +399,47 @@ void lcGLWidget::DrawBackground() const Context->SetDepthWrite(true); } +void lcGLWidget::DrawViewport() const +{ + mContext->SetWorldMatrix(lcMatrix44Identity()); + mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0))); + mContext->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f)); + + mContext->SetDepthWrite(false); + glDisable(GL_DEPTH_TEST); + + mContext->SetMaterial(lcMaterialType::UnlitColor); + + if (mLastFocusView == this) + mContext->SetColor(lcVector4FromColor(lcGetPreferences().mActiveViewColor)); + else + mContext->SetColor(lcVector4FromColor(lcGetPreferences().mInactiveViewColor)); + + float Verts[8] = { 0.0f, 0.0f, mWidth - 1.0f, 0.0f, mWidth - 1.0f, mHeight - 1.0f, 0.0f, mHeight - 1.0f }; + + mContext->SetVertexBufferPointer(Verts); + mContext->SetVertexFormatPosition(2); + mContext->DrawPrimitives(GL_LINE_LOOP, 0, 4); + + const char* CameraName = mCamera->GetName(); + + if (CameraName[0]) + { + mContext->SetMaterial(lcMaterialType::UnlitTextureModulate); + mContext->SetColor(0.0f, 0.0f, 0.0f, 1.0f); + mContext->BindTexture2D(gTexFont.GetTexture()); + + glEnable(GL_BLEND); + + gTexFont.PrintText(mContext, 3.0f, (float)mHeight - 1.0f - 6.0f, 0.0f, CameraName); + + glDisable(GL_BLEND); + } + + mContext->SetDepthWrite(true); + glEnable(GL_DEPTH_TEST); +} + void lcGLWidget::DrawAxes() const { // glClear(GL_DEPTH_BUFFER_BIT); diff --git a/common/lc_glwidget.h b/common/lc_glwidget.h index 0a7175c0..13916255 100644 --- a/common/lc_glwidget.h +++ b/common/lc_glwidget.h @@ -111,6 +111,7 @@ public: return mMouseY; } + void SetFocus(bool Focus); void SetMousePosition(int MouseX, int MouseY); void SetMouseModifiers(Qt::KeyboardModifiers MouseModifiers); void SetContext(lcContext* Context); @@ -124,6 +125,7 @@ public: lcMatrix44 GetProjectionMatrix() const; void DrawBackground() const; + void DrawViewport() const; void DrawAxes() const; virtual void OnDraw() { } @@ -162,7 +164,7 @@ protected: int mMouseDownY = 0; Qt::KeyboardModifiers mMouseModifiers = Qt::NoModifier; - bool mTrackUpdated; + bool mTrackUpdated = false; lcTrackTool mTrackTool = lcTrackTool::None; lcTrackButton mTrackButton = lcTrackButton::None; lcCursor mCursor = lcCursor::Default; @@ -175,4 +177,6 @@ protected: lcCamera* mCamera = nullptr; bool mDeleteContext = true; + + static lcGLWidget* mLastFocusView; }; diff --git a/common/lc_previewwidget.cpp b/common/lc_previewwidget.cpp index e541e4ba..4120df75 100644 --- a/common/lc_previewwidget.cpp +++ b/common/lc_previewwidget.cpp @@ -239,30 +239,6 @@ void lcPreviewWidget::SetViewpoint(const lcVector3& Position) Redraw(); } -void lcPreviewWidget::DrawViewport() -{ - mContext->SetWorldMatrix(lcMatrix44Identity()); - mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0))); - mContext->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f)); - - mContext->SetDepthWrite(false); - glDisable(GL_DEPTH_TEST); - - if (true/*we have an active view*/) - { - mContext->SetMaterial(lcMaterialType::UnlitColor); - mContext->SetColor(lcVector4FromColor(lcGetPreferences().mPreviewActiveColor)); - float Verts[8] = { 0.0f, 0.0f, mWidth - 1.0f, 0.0f, mWidth - 1.0f, mHeight - 1.0f, 0.0f, mHeight - 1.0f }; - - mContext->SetVertexBufferPointer(Verts); - mContext->SetVertexFormatPosition(2); - mContext->DrawPrimitives(GL_LINE_LOOP, 0, 4); - } - - mContext->SetDepthWrite(true); - glEnable(GL_DEPTH_TEST); -} - void lcPreviewWidget::StopTracking(bool Accept) { if (mTrackButton == lcTrackButton::None) diff --git a/common/lc_previewwidget.h b/common/lc_previewwidget.h index 60644d54..aca01fd3 100644 --- a/common/lc_previewwidget.h +++ b/common/lc_previewwidget.h @@ -68,8 +68,6 @@ public: void OnMouseWheel(float Direction) override; protected: - void DrawViewport(); - void StopTracking(bool Accept); void OnButtonDown(lcTrackButton TrackButton); diff --git a/common/lc_profile.cpp b/common/lc_profile.cpp index dbb6e25d..b2ec120a 100644 --- a/common/lc_profile.cpp +++ b/common/lc_profile.cpp @@ -73,6 +73,7 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] = 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 lcProfileEntry("Settings", "ActiveViewColor", LC_RGBA(41, 128, 185, 255)), // LC_PROFILE_ACTIVE_VIEW_COLOR + lcProfileEntry("Settings", "InactiveViewColor", LC_RGBA(69, 69, 69, 255)), // LC_PROFILE_INACTIVE_VIEW_COLOR lcProfileEntry("Settings", "DrawEdgeLines", 1), // LC_PROFILE_DRAW_EDGE_LINES lcProfileEntry("Settings", "GridStuds", 1), // LC_PROFILE_GRID_STUDS lcProfileEntry("Settings", "GridStudColor", LC_RGBA(24, 24, 24, 192)), // LC_PROFILE_GRID_STUD_COLOR @@ -128,18 +129,17 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] = lcProfileEntry("POVRay", "Path", "/usr/bin/povray"), // LC_PROFILE_POVRAY_PATH lcProfileEntry("POVRay", "LGEOPath", ""), // LC_PROFILE_POVRAY_LGEO_PATH lcProfileEntry("POVRay", "Width", 1280), // LC_PROFILE_POVRAY_WIDTH - lcProfileEntry("POVRay", "Height", 720), // LC_PROFILE_POVRAY_HEIGHT + lcProfileEntry("POVRay", "Height", 720), // LC_PROFILE_POVRAY_HEIGHT - lcProfileEntry("Settings", "PreviewActiveColor", LC_RGBA(69, 69, 69, 255)), // LC_PROFILE_PREVIEW_ACTIVE_COLOR - lcProfileEntry("Settgins", "PreviewViewSphereEnabled", 1), // LC_PROFILE_PREVIEW_VIEW_SPHERE_ENABLED - lcProfileEntry("Settings", "PreviewViewSphereSize", 75), // LC_PROFILE_PREVIEW_VIEW_SPHERE_SIZE + lcProfileEntry("Settgins", "PreviewViewSphereEnabled", 1), // LC_PROFILE_PREVIEW_VIEW_SPHERE_ENABLED + lcProfileEntry("Settings", "PreviewViewSphereSize", 75), // LC_PROFILE_PREVIEW_VIEW_SPHERE_SIZE lcProfileEntry("Settings", "PreviewViewSphereLocation", (int)lcViewSphereLocation::TopRight), // LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION - lcProfileEntry("Settings", "PreviewEnabled", 1), // LC_PROFILE_PREVIEW_ENABLED - lcProfileEntry("Settings", "PreviewSize", 300), // LC_PROFILE_PREVIEW_SIZE - lcProfileEntry("Settings", "PreviewLocation", (int)lcPreviewLocation::BottomRight), // LC_PROFILE_PREVIEW_LOCATION - lcProfileEntry("Settings", "PreviewPosition", (int)lcPreviewPosition::Dockable), // LC_PROFILE_PREVIEW_POSITION - lcProfileEntry("Settings", "DrawPreviewAxis", 0), // LC_PROFILE_PREVIEW_DRAW_AXES - lcProfileEntry("Settings", "DrawPreviewViewSphere",1) // LC_PROFILE_PREVIEW_DRAW_VIEW_SPHERE + lcProfileEntry("Settings", "PreviewEnabled", 1), // LC_PROFILE_PREVIEW_ENABLED + lcProfileEntry("Settings", "PreviewSize", 300), // LC_PROFILE_PREVIEW_SIZE + lcProfileEntry("Settings", "PreviewLocation", (int)lcPreviewLocation::BottomRight), // LC_PROFILE_PREVIEW_LOCATION + lcProfileEntry("Settings", "PreviewPosition", (int)lcPreviewPosition::Dockable), // LC_PROFILE_PREVIEW_POSITION + lcProfileEntry("Settings", "DrawPreviewAxis", 0), // LC_PROFILE_PREVIEW_DRAW_AXES + lcProfileEntry("Settings", "DrawPreviewViewSphere",1) // LC_PROFILE_PREVIEW_DRAW_VIEW_SPHERE }; void lcRemoveProfileKey(LC_PROFILE_KEY Key) diff --git a/common/lc_profile.h b/common/lc_profile.h index d291dc89..e7297976 100644 --- a/common/lc_profile.h +++ b/common/lc_profile.h @@ -20,6 +20,7 @@ enum LC_PROFILE_KEY LC_PROFILE_AXES_COLOR, LC_PROFILE_OVERLAY_COLOR, LC_PROFILE_ACTIVE_VIEW_COLOR, + LC_PROFILE_INACTIVE_VIEW_COLOR, LC_PROFILE_DRAW_EDGE_LINES, LC_PROFILE_GRID_STUDS, LC_PROFILE_GRID_STUD_COLOR, @@ -78,7 +79,6 @@ enum LC_PROFILE_KEY LC_PROFILE_POVRAY_WIDTH, LC_PROFILE_POVRAY_HEIGHT, - LC_PROFILE_PREVIEW_ACTIVE_COLOR, LC_PROFILE_PREVIEW_VIEW_SPHERE_ENABLED, LC_PROFILE_PREVIEW_VIEW_SPHERE_SIZE, LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION, diff --git a/common/minifig.cpp b/common/minifig.cpp index aec7a97f..023b5318 100644 --- a/common/minifig.cpp +++ b/common/minifig.cpp @@ -323,29 +323,7 @@ void MinifigWizard::OnDraw() DrawBackground(); - // todo: temp viewport drawing code until this is merged with View - { - mContext->SetWorldMatrix(lcMatrix44Identity()); - mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0))); - mContext->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f)); - - mContext->SetDepthWrite(false); - glDisable(GL_DEPTH_TEST); - -// if (gMainWindow->GetActiveView() == this) - { - mContext->SetMaterial(lcMaterialType::UnlitColor); - mContext->SetColor(lcVector4FromColor(lcGetPreferences().mActiveViewColor)); - float Verts[8] = { 0.0f, 0.0f, mWidth - 1.0f, 0.0f, mWidth - 1.0f, mHeight - 1.0f, 0.0f, mHeight - 1.0f }; - - mContext->SetVertexBufferPointer(Verts); - mContext->SetVertexFormatPosition(2); - mContext->DrawPrimitives(GL_LINE_LOOP, 0, 4); - } - - mContext->SetDepthWrite(true); - glEnable(GL_DEPTH_TEST); - } + DrawViewport(); lcVector3 Min(FLT_MAX, FLT_MAX, FLT_MAX), Max(-FLT_MAX, -FLT_MAX, -FLT_MAX); diff --git a/common/view.cpp b/common/view.cpp index 1202016e..4b98942b 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -1660,45 +1660,6 @@ void View::DrawGrid() } } -void View::DrawViewport() -{ - mContext->SetWorldMatrix(lcMatrix44Identity()); - mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0))); - mContext->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f)); - - mContext->SetDepthWrite(false); - glDisable(GL_DEPTH_TEST); - - if (gMainWindow->GetActiveView() == this) - { - mContext->SetMaterial(lcMaterialType::UnlitColor); - mContext->SetColor(lcVector4FromColor(lcGetPreferences().mActiveViewColor)); - float Verts[8] = { 0.0f, 0.0f, mWidth - 1.0f, 0.0f, mWidth - 1.0f, mHeight - 1.0f, 0.0f, mHeight - 1.0f }; - - mContext->SetVertexBufferPointer(Verts); - mContext->SetVertexFormatPosition(2); - mContext->DrawPrimitives(GL_LINE_LOOP, 0, 4); - } - - const char* CameraName = mCamera->GetName(); - - if (CameraName[0]) - { - mContext->SetMaterial(lcMaterialType::UnlitTextureModulate); - mContext->SetColor(0.0f, 0.0f, 0.0f, 1.0f); - mContext->BindTexture2D(gTexFont.GetTexture()); - - glEnable(GL_BLEND); - - gTexFont.PrintText(mContext, 3.0f, (float)mHeight - 1.0f - 6.0f, 0.0f, CameraName); - - glDisable(GL_BLEND); - } - - mContext->SetDepthWrite(true); - glEnable(GL_DEPTH_TEST); -} - void View::OnInitialUpdate() { gMainWindow->AddView(this); diff --git a/common/view.h b/common/view.h index a2a74d24..de6843d6 100644 --- a/common/view.h +++ b/common/view.h @@ -89,7 +89,6 @@ protected: void DrawSelectZoomRegionOverlay(); void DrawRotateViewOverlay(); void DrawGrid(); - void DrawViewport(); void UpdateTrackTool(); bool IsTrackToolAllowed(lcTrackTool TrackTool, quint32 AllowedTransforms) const; diff --git a/qt/lc_qglwidget.cpp b/qt/lc_qglwidget.cpp index ee137565..e6c0d37b 100644 --- a/qt/lc_qglwidget.cpp +++ b/qt/lc_qglwidget.cpp @@ -137,7 +137,6 @@ void lcQGLWidget::SetPreviewPosition(const QRect& ParentRect) setMinimumSize(100,100); show(); - setFocus(); } void lcQGLWidget::resizeGL(int Width, int Height) @@ -151,6 +150,22 @@ void lcQGLWidget::paintGL() mWidget->OnDraw(); } +void lcQGLWidget::focusInEvent(QFocusEvent* FocusEvent) +{ + if (mWidget) + mWidget->SetFocus(true); + + QGLWidget::focusInEvent(FocusEvent); +} + +void lcQGLWidget::focusOutEvent(QFocusEvent* FocusEvent) +{ + if (mWidget) + mWidget->SetFocus(false); + + QGLWidget::focusOutEvent(FocusEvent); +} + void lcQGLWidget::keyPressEvent(QKeyEvent* KeyEvent) { if (KeyEvent->key() == Qt::Key_Control || KeyEvent->key() == Qt::Key_Shift) diff --git a/qt/lc_qglwidget.h b/qt/lc_qglwidget.h index d6ba55c3..9910b70e 100644 --- a/qt/lc_qglwidget.h +++ b/qt/lc_qglwidget.h @@ -26,6 +26,8 @@ public: protected: void resizeGL(int Width, int Height) override; void paintGL() override; + void focusInEvent(QFocusEvent* FocusEvent) override; + void focusOutEvent(QFocusEvent* FocusEvent) override; void keyPressEvent(QKeyEvent* KeyEvent) override; void keyReleaseEvent(QKeyEvent* KeyEvent) override; void mousePressEvent(QMouseEvent* MouseEvent) override;