mirror of
https://github.com/leozide/leocad
synced 2024-12-26 21:58:44 +01:00
Moved DrawBackground to lcGLWidget.
This commit is contained in:
parent
ef2220ffdc
commit
9e12b480ce
9 changed files with 122 additions and 122 deletions
116
common/lc_glwidget.cpp
Normal file
116
common/lc_glwidget.cpp
Normal file
|
@ -0,0 +1,116 @@
|
|||
#include "lc_global.h"
|
||||
#include "lc_glwidget.h"
|
||||
#include "lc_application.h"
|
||||
|
||||
void lcGLWidget::MakeCurrent()
|
||||
{
|
||||
mWidget->makeCurrent();
|
||||
}
|
||||
|
||||
void lcGLWidget::Redraw()
|
||||
{
|
||||
mWidget->update();
|
||||
}
|
||||
|
||||
void lcGLWidget::SetCursor(lcCursor CursorType)
|
||||
{
|
||||
if (mCursor == CursorType)
|
||||
return;
|
||||
|
||||
struct lcCursorInfo
|
||||
{
|
||||
int x, y;
|
||||
const char* Name;
|
||||
};
|
||||
|
||||
const lcCursorInfo Cursors[] =
|
||||
{
|
||||
{ 0, 0, "" }, // lcCursor::Default
|
||||
{ 8, 3, ":/resources/cursor_insert" }, // lcCursor::Brick
|
||||
{ 15, 15, ":/resources/cursor_light" }, // lcCursor::Light
|
||||
{ 7, 10, ":/resources/cursor_spotlight" }, // lcCursor::Spotlight
|
||||
{ 15, 9, ":/resources/cursor_camera" }, // lcCursor::Camera
|
||||
{ 0, 2, ":/resources/cursor_select" }, // lcCursor::Select
|
||||
{ 0, 2, ":/resources/cursor_select_add" }, // lcCursor::SelectAdd
|
||||
{ 0, 2, ":/resources/cursor_select_remove" }, // lcCursor::SelectRemove
|
||||
{ 15, 15, ":/resources/cursor_move" }, // lcCursor::Move
|
||||
{ 15, 15, ":/resources/cursor_rotate" }, // lcCursor::Rotate
|
||||
{ 15, 15, ":/resources/cursor_rotatex" }, // lcCursor::RotateX
|
||||
{ 15, 15, ":/resources/cursor_rotatey" }, // lcCursor::RotateY
|
||||
{ 0, 10, ":/resources/cursor_delete" }, // lcCursor::Delete
|
||||
{ 14, 14, ":/resources/cursor_paint" }, // lcCursor::Paint
|
||||
{ 1, 13, ":/resources/cursor_color_picker" }, // lcCursor::ColorPicker
|
||||
{ 15, 15, ":/resources/cursor_zoom" }, // lcCursor::Zoom
|
||||
{ 9, 9, ":/resources/cursor_zoom_region" }, // lcCursor::ZoomRegion
|
||||
{ 15, 15, ":/resources/cursor_pan" }, // lcCursor::Pan
|
||||
{ 15, 15, ":/resources/cursor_roll" }, // lcCursor::Roll
|
||||
{ 15, 15, ":/resources/cursor_rotate_view" }, // lcCursor::RotateView
|
||||
};
|
||||
|
||||
static_assert(LC_ARRAY_COUNT(Cursors) == static_cast<int>(lcCursor::Count), "Array size mismatch");
|
||||
|
||||
QGLWidget* widget = (QGLWidget*)mWidget;
|
||||
|
||||
if (CursorType > lcCursor::Default && CursorType < lcCursor::Count)
|
||||
{
|
||||
const lcCursorInfo& Cursor = Cursors[static_cast<int>(CursorType)];
|
||||
widget->setCursor(QCursor(QPixmap(Cursor.Name), Cursor.x, Cursor.y));
|
||||
mCursor = CursorType;
|
||||
}
|
||||
else
|
||||
{
|
||||
widget->unsetCursor();
|
||||
mCursor = lcCursor::Default;
|
||||
}
|
||||
}
|
||||
|
||||
void lcGLWidget::DrawBackground() const
|
||||
{
|
||||
const lcPreferences& Preferences = lcGetPreferences();
|
||||
|
||||
if (!Preferences.mBackgroundGradient)
|
||||
{
|
||||
lcVector3 BackgroundColor = lcVector3FromColor(Preferences.mBackgroundSolidColor);
|
||||
glClearColor(BackgroundColor[0], BackgroundColor[1], BackgroundColor[2], 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
return;
|
||||
}
|
||||
|
||||
lcContext* Context = mContext;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
Context->SetDepthWrite(false);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
float ViewWidth = (float)mWidth;
|
||||
float ViewHeight = (float)mHeight;
|
||||
|
||||
Context->SetWorldMatrix(lcMatrix44Identity());
|
||||
Context->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0)));
|
||||
Context->SetProjectionMatrix(lcMatrix44Ortho(0.0f, ViewWidth, 0.0f, ViewHeight, -1.0f, 1.0f));
|
||||
|
||||
Context->SetSmoothShading(true);
|
||||
|
||||
const lcVector3 Color1 = lcVector3FromColor(Preferences.mBackgroundGradientColorTop);
|
||||
const lcVector3 Color2 = lcVector3FromColor(Preferences.mBackgroundGradientColorBottom);
|
||||
|
||||
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->SetMaterial(lcMaterialType::UnlitVertexColor);
|
||||
Context->SetVertexBufferPointer(Verts);
|
||||
Context->SetVertexFormat(0, 2, 0, 0, 4, false);
|
||||
|
||||
Context->DrawPrimitives(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
Context->SetSmoothShading(false);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
Context->SetDepthWrite(true);
|
||||
}
|
|
@ -75,6 +75,7 @@ public:
|
|||
void MakeCurrent();
|
||||
void Redraw();
|
||||
void SetCursor(lcCursor Cursor);
|
||||
void DrawBackground() const;
|
||||
|
||||
virtual void OnDraw() { }
|
||||
virtual void OnInitialUpdate() { }
|
||||
|
@ -100,7 +101,7 @@ public:
|
|||
int mWidth;
|
||||
int mHeight;
|
||||
lcCursor mCursor;
|
||||
void* mWidget;
|
||||
QGLWidget* mWidget;
|
||||
lcContext* mContext;
|
||||
bool mDeleteContext;
|
||||
};
|
||||
|
|
|
@ -1257,57 +1257,6 @@ void lcModel::AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMat
|
|||
Piece->AddSubModelRenderMeshes(Scene, WorldMatrix, DefaultColorIndex, RenderMeshState, ParentActive);
|
||||
}
|
||||
|
||||
void lcModel::DrawBackground(lcGLWidget* Widget)
|
||||
{
|
||||
const lcPreferences& Preferences = lcGetPreferences();
|
||||
|
||||
if (!Preferences.mBackgroundGradient)
|
||||
{
|
||||
lcVector3 BackgroundColor = lcVector3FromColor(Preferences.mBackgroundSolidColor);
|
||||
glClearColor(BackgroundColor[0], BackgroundColor[1], BackgroundColor[2], 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
return;
|
||||
}
|
||||
|
||||
lcContext* Context = Widget->mContext;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
Context->SetDepthWrite(false);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
float ViewWidth = (float)Widget->mWidth;
|
||||
float ViewHeight = (float)Widget->mHeight;
|
||||
|
||||
Context->SetWorldMatrix(lcMatrix44Identity());
|
||||
Context->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0)));
|
||||
Context->SetProjectionMatrix(lcMatrix44Ortho(0.0f, ViewWidth, 0.0f, ViewHeight, -1.0f, 1.0f));
|
||||
|
||||
Context->SetSmoothShading(true);
|
||||
|
||||
const lcVector3 Color1 = lcVector3FromColor(Preferences.mBackgroundGradientColorTop);
|
||||
const lcVector3 Color2 = lcVector3FromColor(Preferences.mBackgroundGradientColorBottom);
|
||||
|
||||
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->SetMaterial(lcMaterialType::UnlitVertexColor);
|
||||
Context->SetVertexBufferPointer(Verts);
|
||||
Context->SetVertexFormat(0, 2, 0, 0, 4, false);
|
||||
|
||||
Context->DrawPrimitives(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
Context->SetSmoothShading(false);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
Context->SetDepthWrite(true);
|
||||
}
|
||||
|
||||
QImage lcModel::GetStepImage(bool Zoom, int Width, int Height, lcStep Step)
|
||||
{
|
||||
View* ActiveView = gMainWindow->GetActiveView();
|
||||
|
|
|
@ -236,7 +236,6 @@ public:
|
|||
|
||||
void GetScene(lcScene& Scene, lcCamera* ViewCamera, bool AllowHighlight, bool AllowFade) const;
|
||||
void AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const;
|
||||
void DrawBackground(lcGLWidget* Widget);
|
||||
QImage GetStepImage(bool Zoom, int Width, int Height, lcStep Step);
|
||||
QImage GetPartsListImage(int MaxWidth, lcStep Step) const;
|
||||
void SaveStepImages(const QString& BaseName, bool AddStepSuffix, bool Zoom, int Width, int Height, lcStep Start, lcStep End);
|
||||
|
|
|
@ -495,7 +495,7 @@ void lcPreviewWidget::OnDraw()
|
|||
|
||||
mContext->SetViewport(0, 0, mWidth, mHeight);
|
||||
|
||||
mModel->DrawBackground(this);
|
||||
DrawBackground();
|
||||
|
||||
mContext->SetProjectionMatrix(GetProjectionMatrix());
|
||||
|
||||
|
|
|
@ -326,7 +326,7 @@ void MinifigWizard::OnDraw()
|
|||
const float Aspect = (float)mWidth/(float)mHeight;
|
||||
mContext->SetViewport(0, 0, mWidth, mHeight);
|
||||
|
||||
lcGetActiveModel()->DrawBackground(this);
|
||||
DrawBackground();
|
||||
|
||||
lcVector3 Min(FLT_MAX, FLT_MAX, FLT_MAX), Max(-FLT_MAX, -FLT_MAX, -FLT_MAX);
|
||||
|
||||
|
|
|
@ -864,7 +864,7 @@ void View::OnDraw()
|
|||
mContext->SetDefaultState();
|
||||
mContext->SetViewport(0, 0, mWidth, mHeight);
|
||||
|
||||
mModel->DrawBackground(this);
|
||||
DrawBackground();
|
||||
|
||||
int CurrentTileWidth, CurrentTileHeight;
|
||||
|
||||
|
|
|
@ -187,6 +187,7 @@ SOURCES += common/view.cpp \
|
|||
common/lc_context.cpp \
|
||||
common/lc_file.cpp \
|
||||
common/lc_glextensions.cpp \
|
||||
common/lc_glwidget.cpp \
|
||||
common/lc_http.cpp \
|
||||
common/lc_library.cpp \
|
||||
common/lc_lxf.cpp \
|
||||
|
|
|
@ -19,72 +19,6 @@
|
|||
|
||||
static QList<QGLWidget*> gWidgetList;
|
||||
|
||||
void lcGLWidget::MakeCurrent()
|
||||
{
|
||||
QGLWidget* Widget = (QGLWidget*)mWidget;
|
||||
|
||||
Widget->makeCurrent();
|
||||
}
|
||||
|
||||
void lcGLWidget::Redraw()
|
||||
{
|
||||
lcQGLWidget* Widget = (lcQGLWidget*)mWidget;
|
||||
|
||||
Widget->update();
|
||||
}
|
||||
|
||||
void lcGLWidget::SetCursor(lcCursor CursorType)
|
||||
{
|
||||
if (mCursor == CursorType)
|
||||
return;
|
||||
|
||||
struct lcCursorInfo
|
||||
{
|
||||
int x, y;
|
||||
const char* Name;
|
||||
};
|
||||
|
||||
const lcCursorInfo Cursors[] =
|
||||
{
|
||||
{ 0, 0, "" }, // lcCursor::Default
|
||||
{ 8, 3, ":/resources/cursor_insert" }, // lcCursor::Brick
|
||||
{ 15, 15, ":/resources/cursor_light" }, // lcCursor::Light
|
||||
{ 7, 10, ":/resources/cursor_spotlight" }, // lcCursor::Spotlight
|
||||
{ 15, 9, ":/resources/cursor_camera" }, // lcCursor::Camera
|
||||
{ 0, 2, ":/resources/cursor_select" }, // lcCursor::Select
|
||||
{ 0, 2, ":/resources/cursor_select_add" }, // lcCursor::SelectAdd
|
||||
{ 0, 2, ":/resources/cursor_select_remove" }, // lcCursor::SelectRemove
|
||||
{ 15, 15, ":/resources/cursor_move" }, // lcCursor::Move
|
||||
{ 15, 15, ":/resources/cursor_rotate" }, // lcCursor::Rotate
|
||||
{ 15, 15, ":/resources/cursor_rotatex" }, // lcCursor::RotateX
|
||||
{ 15, 15, ":/resources/cursor_rotatey" }, // lcCursor::RotateY
|
||||
{ 0, 10, ":/resources/cursor_delete" }, // lcCursor::Delete
|
||||
{ 14, 14, ":/resources/cursor_paint" }, // lcCursor::Paint
|
||||
{ 1, 13, ":/resources/cursor_color_picker" }, // lcCursor::ColorPicker
|
||||
{ 15, 15, ":/resources/cursor_zoom" }, // lcCursor::Zoom
|
||||
{ 9, 9, ":/resources/cursor_zoom_region" }, // lcCursor::ZoomRegion
|
||||
{ 15, 15, ":/resources/cursor_pan" }, // lcCursor::Pan
|
||||
{ 15, 15, ":/resources/cursor_roll" }, // lcCursor::Roll
|
||||
{ 15, 15, ":/resources/cursor_rotate_view" }, // lcCursor::RotateView
|
||||
};
|
||||
|
||||
static_assert(LC_ARRAY_COUNT(Cursors) == static_cast<int>(lcCursor::Count), "Array size mismatch");
|
||||
|
||||
QGLWidget* widget = (QGLWidget*)mWidget;
|
||||
|
||||
if (CursorType != lcCursor::Default && CursorType < lcCursor::Count)
|
||||
{
|
||||
const lcCursorInfo& Cursor = Cursors[static_cast<int>(CursorType)];
|
||||
widget->setCursor(QCursor(QPixmap(Cursor.Name), Cursor.x, Cursor.y));
|
||||
mCursor = CursorType;
|
||||
}
|
||||
else
|
||||
{
|
||||
widget->unsetCursor();
|
||||
mCursor = lcCursor::Default;
|
||||
}
|
||||
}
|
||||
|
||||
lcQGLWidget::lcQGLWidget(QWidget* Parent, lcGLWidget* Owner)
|
||||
: QGLWidget(Parent, gWidgetList.isEmpty() ? nullptr : gWidgetList.first())
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue