summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleo2006-01-20 06:14:06 +0000
committerleo2006-01-20 06:14:06 +0000
commita05319c8417b5bad66458baefa0cbf8dffa66291 (patch)
tree0fa2d53c3604a72b0dc88c886ec0bd828c99903f
parent633c4ee66a14a6d7df81d82e315df64d7f4b10d8 (diff)
Made the Windows piece preview use the common preview code.
git-svn-id: http://svn.leocad.org/trunk@458 c7d43263-9d01-0410-8a33-9dba5d9f93d6
-rw-r--r--common/preview.cpp92
-rw-r--r--common/preview.h16
-rw-r--r--win/Pieceprv.cpp151
-rw-r--r--win/Pieceprv.h13
4 files changed, 85 insertions, 187 deletions
diff --git a/common/preview.cpp b/common/preview.cpp
index 8317104..12a7986 100644
--- a/common/preview.cpp
+++ b/common/preview.cpp
@@ -7,68 +7,68 @@
#include "project.h"
#include "pieceinf.h"
-PiecePreview::PiecePreview (GLWindow *share)
- : GLWindow (share)
+PiecePreview::PiecePreview(GLWindow *share)
+ : GLWindow(share)
{
- m_pPieceInfo = NULL;
+ m_PieceInfo = NULL;
}
-PiecePreview::~PiecePreview ()
+PiecePreview::~PiecePreview()
{
}
-void PiecePreview::OnDraw ()
+void PiecePreview::OnDraw()
{
- if (m_pPieceInfo == NULL)
- return;
+ if (m_PieceInfo == NULL)
+ return;
- if (!MakeCurrent ())
- return;
+ if (!MakeCurrent())
+ return;
- glEnable (GL_LIGHT0);
- glEnable (GL_LIGHTING);
- glEnable (GL_DEPTH_TEST);
- glDepthFunc (GL_LEQUAL);
- glEnable (GL_POLYGON_OFFSET_FILL);
- glPolygonOffset (0.5f, 0.1f);
- glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glColorMaterial (GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
- glEnable (GL_COLOR_MATERIAL);
- glDisable (GL_DITHER);
- glShadeModel (GL_FLAT);
+ glEnable(GL_LIGHT0);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_LEQUAL);
+ glEnable(GL_POLYGON_OFFSET_FILL);
+ glPolygonOffset(0.5f, 0.1f);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
+ glEnable(GL_COLOR_MATERIAL);
+ glDisable(GL_DITHER);
+ glShadeModel(GL_FLAT);
- double aspect = (float)m_nWidth/(float)m_nHeight;
- glViewport (0, 0, m_nWidth, m_nHeight);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
- gluPerspective (30.0f, aspect, 1.0f, 100.0f);
- glMatrixMode (GL_MODELVIEW);
- glLoadIdentity ();
- m_pPieceInfo->ZoomExtents (30.0f, aspect);
+ float aspect = (float)m_nWidth/(float)m_nHeight;
+ glViewport(0, 0, m_nWidth, m_nHeight);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ gluPerspective(30.0f, aspect, 1.0f, 100.0f);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ m_PieceInfo->ZoomExtents(30.0f, aspect);
- float pos[4] = { 0, 0, 10, 0 }, *bg = project->GetBackgroundColor ();
- glLightfv (GL_LIGHT0, GL_POSITION, pos);
- glClearColor (bg[0], bg[1], bg[2], bg[3]);
- glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- m_pPieceInfo->RenderPiece (project->GetCurrentColor ());
+ float pos[4] = { 0, 0, 10, 0 }, *bg = project->GetBackgroundColor ();
+ glLightfv(GL_LIGHT0, GL_POSITION, pos);
+ glClearColor(bg[0], bg[1], bg[2], bg[3]);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ m_PieceInfo->RenderPiece(project->GetCurrentColor ());
- glFinish ();
- SwapBuffers ();
+ glFinish();
+ SwapBuffers();
}
-void PiecePreview::SetCurrentPiece (PieceInfo *pInfo)
+void PiecePreview::SetCurrentPiece(PieceInfo *pInfo)
{
- MakeCurrent ();
+ MakeCurrent();
- if (m_pPieceInfo != NULL)
- m_pPieceInfo->DeRef();
+ if (m_PieceInfo != NULL)
+ m_PieceInfo->DeRef();
- m_pPieceInfo = pInfo;
+ m_PieceInfo = pInfo;
- if (m_pPieceInfo != NULL)
- {
- m_pPieceInfo->AddRef ();
- project->SetCurrentPiece (m_pPieceInfo);
- Redraw ();
- }
+ if (m_PieceInfo != NULL)
+ {
+ m_PieceInfo->AddRef();
+ project->SetCurrentPiece(m_PieceInfo);
+ Redraw();
+ }
}
diff --git a/common/preview.h b/common/preview.h
index 21ff3a8..13d6f27 100644
--- a/common/preview.h
+++ b/common/preview.h
@@ -7,16 +7,18 @@ class PieceInfo;
class PiecePreview : public GLWindow
{
- public:
- PiecePreview (GLWindow *share);
- virtual ~PiecePreview ();
+public:
+ PiecePreview(GLWindow *share);
+ virtual ~PiecePreview();
- void OnDraw ();
+ void OnDraw();
- void SetCurrentPiece (PieceInfo *pInfo);
+ PieceInfo* GetCurrentPiece() const
+ { return m_PieceInfo; }
+ void SetCurrentPiece(PieceInfo* Info);
- private:
- PieceInfo* m_pPieceInfo;
+protected:
+ PieceInfo* m_PieceInfo;
};
#endif // _PREVIEW_H_
diff --git a/win/Pieceprv.cpp b/win/Pieceprv.cpp
index 707edc3..bf1a714 100644
--- a/win/Pieceprv.cpp
+++ b/win/Pieceprv.cpp
@@ -8,6 +8,7 @@
#include "pieceinf.h"
#include "globals.h"
#include "project.h"
+#include "preview.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -20,10 +21,7 @@ static char THIS_FILE[] = __FILE__;
CPiecePreview::CPiecePreview()
{
- m_pPalette = NULL;
- m_hglRC = 0;
- m_pDC = NULL;
- m_pPieceInfo = NULL;
+ m_Preview = NULL;
}
CPiecePreview::~CPiecePreview()
@@ -50,147 +48,50 @@ BOOL CPiecePreview::OnEraseBkgnd(CDC* pDC)
return TRUE;
}
-void CPiecePreview::SetPieceInfo(PieceInfo* pInfo)
-{
- if (m_pPieceInfo != NULL)
- m_pPieceInfo->DeRef();
- m_pPieceInfo = pInfo;
- m_pPieceInfo->AddRef();
-}
-
void CPiecePreview::OnPaint()
{
- CPaintDC dc(this); // device context for painting
- if (!IsWindowEnabled() || (m_pPieceInfo == NULL))
+ if (!IsWindowEnabled() || (m_Preview == NULL))
return;
- HDC oldDC = pfnwglGetCurrentDC();
- HGLRC oldRC = pfnwglGetCurrentContext();
-
- if (m_pPalette)
- {
- m_pDC->SelectPalette(m_pPalette, FALSE);
- m_pDC->RealizePalette();
- }
-
- pfnwglMakeCurrent(m_pDC->m_hDC, m_hglRC);
-
- double aspect = (float)m_szView.cx/(float)m_szView.cy;
- glViewport(0, 0, m_szView.cx, m_szView.cy);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(30.0f, aspect, 1.0f, 100.0f);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- gluLookAt (-5, -5, 4, 0, 0, 0, 0, 0, 1);
- m_pPieceInfo->ZoomExtents(30.0f, (float)aspect);
-
- float pos[4] = { 0, 0, 10, 0 }, *bg = project->GetBackgroundColor();
- glLightfv(GL_LIGHT0, GL_POSITION, pos);
- glClearColor(bg[0], bg[1], bg[2], bg[3]);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- m_pPieceInfo->RenderPiece(project->GetCurrentColor());
-
- glFinish();
- OpenGLSwapBuffers (m_pDC->m_hDC);
- pfnwglMakeCurrent (oldDC, oldRC);
+ m_Preview->OnDraw();
}
void CPiecePreview::OnSize(UINT nType, int cx, int cy)
{
+ m_Preview->OnSize(cx, cy);
CWnd::OnSize(nType, cx, cy);
-
- if (cy < 1) cy = 1;
- m_szView.cx = cx;
- m_szView.cy = cy;
}
int CPiecePreview::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
- if (CWnd::OnCreate(lpCreateStruct) == -1)
+ if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
-
- m_pDC = new CClientDC(this);
- ASSERT(m_pDC != NULL);
-
- // Fill in the Pixel Format Descriptor
- PIXELFORMATDESCRIPTOR pfd;
- memset(&pfd,0, sizeof(PIXELFORMATDESCRIPTOR));
-
- pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
- pfd.nVersion = 1;
- pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
- pfd.iPixelType = PFD_TYPE_RGBA;
- pfd.cColorBits = 24;
- pfd.cDepthBits = 32;
- pfd.iLayerType = PFD_MAIN_PLANE;
-
- int nPixelFormat = OpenGLChoosePixelFormat(m_pDC->m_hDC, &pfd);
- if (nPixelFormat == 0)
- return 0;
-
- if (!OpenGLSetPixelFormat(m_pDC->m_hDC, nPixelFormat, &pfd))
- return 0;
-
- m_pPalette = new CPalette;
-
- if (CreateRGBPalette(m_pDC->m_hDC, &m_pPalette))
- {
- m_pDC->SelectPalette(m_pPalette, FALSE);
- m_pDC->RealizePalette();
- }
- else
- {
- delete m_pPalette;
- m_pPalette = NULL;
- }
-
- // Create a rendering context.
- m_hglRC = pfnwglCreateContext(m_pDC->m_hDC);
- if (!m_hglRC)
- return 0;
-
- HDC oldDC = pfnwglGetCurrentDC();
- HGLRC oldRC = pfnwglGetCurrentContext();
- pfnwglMakeCurrent (m_pDC->m_hDC, m_hglRC);
-
- glEnable(GL_LIGHT0);
- glEnable(GL_LIGHTING);
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LEQUAL);
- glEnable(GL_POLYGON_OFFSET_FILL);
- glPolygonOffset(0.5f, 0.1f);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- // Set the material color to follow the current color
- glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
- glEnable(GL_COLOR_MATERIAL);
- glDisable (GL_DITHER);
- glShadeModel (GL_FLAT);
-
- pfnwglMakeCurrent (oldDC, oldRC);
- pfnwglShareLists (oldRC, m_hglRC);
-
- return 0;
+
+ m_Preview = new PiecePreview(NULL);
+ m_Preview->Create(m_hWnd);
+ m_Preview->MakeCurrent();
+
+ return 0;
}
void CPiecePreview::OnDestroy()
{
- if (m_pPalette)
+ if (m_Preview)
{
- CClientDC dc(this);
- CPalette palDefault;
- palDefault.CreateStockObject(DEFAULT_PALETTE);
- dc.SelectPalette(&palDefault, FALSE);
- delete m_pPalette;
+ m_Preview->DestroyContext();
+ delete m_Preview;
+ m_Preview = NULL;
}
- if (m_hglRC)
- pfnwglDeleteContext(m_hglRC);
- if (m_pDC)
- delete m_pDC;
-
CWnd::OnDestroy();
}
+
+void CPiecePreview::SetPieceInfo(PieceInfo* pInfo)
+{
+ m_Preview->SetCurrentPiece(pInfo);
+}
+
+PieceInfo* CPiecePreview::GetPieceInfo() const
+{
+ return m_Preview->GetCurrentPiece();
+}
diff --git a/win/Pieceprv.h b/win/Pieceprv.h
index de003be..8de9d21 100644
--- a/win/Pieceprv.h
+++ b/win/Pieceprv.h
@@ -8,6 +8,7 @@
//
class PieceInfo;
+class PiecePreview;
/////////////////////////////////////////////////////////////////////////////
// CPiecePreview window
@@ -20,9 +21,8 @@ public:
// Attributes
public:
- void SetPieceInfo (PieceInfo* pInfo);
- PieceInfo* GetPieceInfo () const
- { return m_pPieceInfo; }
+ void SetPieceInfo(PieceInfo* pInfo);
+ PieceInfo* GetPieceInfo () const;
// Operations
public:
@@ -38,12 +38,7 @@ public:
// Generated message map functions
protected:
- SIZE m_szView;
- HGLRC m_hglRC;
- PieceInfo* m_pPieceInfo;
-
- CPalette* m_pPalette;
- CClientDC* m_pDC;
+ PiecePreview* m_Preview;
//{{AFX_MSG(CPiecePreview)
afx_msg BOOL OnEraseBkgnd(CDC* pDC);