mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Merged DrawViewport().
This commit is contained in:
parent
c758ef2910
commit
489f5e6f7e
13 changed files with 90 additions and 105 deletions
|
@ -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<lcColorTheme>(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<lcViewSphereLocation>(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<int>(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<int>(mPreviewViewSphereLocation));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -68,8 +68,6 @@ public:
|
|||
void OnMouseWheel(float Direction) override;
|
||||
|
||||
protected:
|
||||
void DrawViewport();
|
||||
|
||||
void StopTracking(bool Accept);
|
||||
void OnButtonDown(lcTrackButton TrackButton);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -89,7 +89,6 @@ protected:
|
|||
void DrawSelectZoomRegionOverlay();
|
||||
void DrawRotateViewOverlay();
|
||||
void DrawGrid();
|
||||
void DrawViewport();
|
||||
|
||||
void UpdateTrackTool();
|
||||
bool IsTrackToolAllowed(lcTrackTool TrackTool, quint32 AllowedTransforms) const;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue