FormCommandView.cpp
上传用户:zbjingming
上传日期:2010-01-02
资源大小:2436k
文件大小:4k
- // FormCommandView.cpp : implementation file
- #include "stdafx.h"
- #include "Tool.h"
- #include "MainFrm.h"
- #include "FormCommandView.h"
- #include "ToolDoc.h"
- #include "RenderView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- // CFormCommandView
- IMPLEMENT_DYNCREATE(CFormCommandView, CFormView)
- CFormCommandView::CFormCommandView()
- : CFormView(CFormCommandView::IDD)
- {
- //{{AFX_DATA_INIT(CFormCommandView)
- m_Smooth = FALSE;
- m_Antialias = FALSE;
- //}}AFX_DATA_INIT
- }
- CFormCommandView::~CFormCommandView()
- {
- }
- void CFormCommandView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CFormCommandView)
- DDX_Control(pDX, IDC_FRAME_COLOR_BACK, m_ControlBackColor);
- DDX_Check(pDX, IDC_CHECK_SMOOTH, m_Smooth);
- DDX_Check(pDX, IDC_CHECK_ANTIALIAS, m_Antialias);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CFormCommandView, CFormView)
- //{{AFX_MSG_MAP(CFormCommandView)
- ON_WM_PAINT()
- ON_WM_LBUTTONUP()
- ON_BN_CLICKED(IDC_RADIO_MODEL_1, OnRadioModel1)
- ON_BN_CLICKED(IDC_RADIO_MODEL_2, OnRadioModel2)
- ON_BN_CLICKED(IDC_CHECK_SMOOTH, OnCheckSmooth)
- ON_BN_CLICKED(IDC_CHECK_ANTIALIAS, OnCheckAntialias)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFormCommandView diagnostics
- #ifdef _DEBUG
- void CFormCommandView::AssertValid() const
- {
- CFormView::AssertValid();
- }
- void CFormCommandView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- CToolDoc* CFormCommandView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CToolDoc)));
- return (CToolDoc*)m_pDocument;
- }
- #endif //_DEBUG
- // OnPaint
- void CFormCommandView::OnPaint()
- {
- // Device context for painting
- CPaintDC dc(this);
-
- // Options are stored in Application
- CToolApp *pApp = (CToolApp *)AfxGetApp();
- CRect rect;
-
- // Color back
- m_ControlBackColor.GetWindowRect(&rect);
- ScreenToClient(&rect);
- CBrush BrushBack(pApp->m_OptionColorGlBack);
- dc.FillRect(&rect,&BrushBack);
- }
- // OnLButtonUp
- void CFormCommandView::OnLButtonUp(UINT nFlags,
- CPoint point)
- {
- CRect rect;
- CToolApp *pApp = (CToolApp *)AfxGetApp();
-
- // Option back color
- m_ControlBackColor.GetWindowRect(&rect);
- ScreenToClient(&rect);
- if(rect.PtInRect(point))
- {
- CColorDialog dlg(pApp->m_OptionColorGlBack);
- if(dlg.DoModal()==IDOK)
- {
- pApp->m_OptionColorGlBack = dlg.GetColor();
- CRenderView *pView = (CRenderView *)GetRenderView();
- pView->m_ClearColorRed = (float)GetRValue(pApp->m_OptionColorGlBack) / 255.0f;
- pView->m_ClearColorGreen = (float)GetGValue(pApp->m_OptionColorGlBack) / 255.0f;
- pView->m_ClearColorBlue = (float)GetBValue(pApp->m_OptionColorGlBack) / 255.0f;
- this->InvalidateRect(&rect,FALSE);
- pView->InvalidateRect(NULL,FALSE);
- }
- }
- CFormView::OnLButtonUp(nFlags, point);
- }
- // GetRenderView
- CView *CFormCommandView::GetRenderView()
- {
- CToolApp *pApp = (CToolApp *)AfxGetApp();
- CMainFrame *pFrame = (CMainFrame *)pApp->m_pMainWnd;
- CView *pView = (CView *)pFrame->m_wndSplitter.GetPane(0,1);
- return pView;
- }
- // Model
- void CFormCommandView::OnRadioModel1()
- {
- glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
- this->GetRenderView()->InvalidateRect(NULL,FALSE);
- }
- void CFormCommandView::OnRadioModel2()
- {
- glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
- this->GetRenderView()->InvalidateRect(NULL,FALSE);
- }
- // OnCheckSmooth
- void CFormCommandView::OnCheckSmooth()
- {
- m_Smooth = !m_Smooth;
- if(m_Smooth)
- glShadeModel(GL_SMOOTH);
- else
- glShadeModel(GL_FLAT);
- this->GetRenderView()->InvalidateRect(NULL,FALSE);
-
- }
- // OnCheckAntialias
- // Toggle antialiased lines
- void CFormCommandView::OnCheckAntialias()
- {
- m_Antialias = !m_Antialias;
- if(m_Antialias)
- {
- glEnable(GL_LINE_SMOOTH);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
- glLineWidth(1.5f);
- }
- else
- {
- glDisable(GL_LINE_SMOOTH);
- glDisable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
- glLineWidth(1.0f);
- }
- GetRenderView()->InvalidateRect(NULL,FALSE);
- }