FormCommandView.cpp
上传用户:zbjingming
上传日期:2010-01-02
资源大小:2436k
文件大小:4k
源码类别:

OpenGL

开发平台:

Visual C++

  1. // FormCommandView.cpp : implementation file
  2. #include "stdafx.h"
  3. #include "Tool.h"
  4. #include "MainFrm.h"
  5. #include "FormCommandView.h"
  6. #include "ToolDoc.h"
  7. #include "RenderView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. // CFormCommandView
  14. IMPLEMENT_DYNCREATE(CFormCommandView, CFormView)
  15. CFormCommandView::CFormCommandView()
  16. : CFormView(CFormCommandView::IDD)
  17. {
  18. //{{AFX_DATA_INIT(CFormCommandView)
  19. m_Smooth = FALSE;
  20. m_Antialias = FALSE;
  21. //}}AFX_DATA_INIT
  22. }
  23. CFormCommandView::~CFormCommandView()
  24. {
  25. }
  26. void CFormCommandView::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CFormView::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CFormCommandView)
  30. DDX_Control(pDX, IDC_FRAME_COLOR_BACK, m_ControlBackColor);
  31. DDX_Check(pDX, IDC_CHECK_SMOOTH, m_Smooth);
  32. DDX_Check(pDX, IDC_CHECK_ANTIALIAS, m_Antialias);
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(CFormCommandView, CFormView)
  36. //{{AFX_MSG_MAP(CFormCommandView)
  37. ON_WM_PAINT()
  38. ON_WM_LBUTTONUP()
  39. ON_BN_CLICKED(IDC_RADIO_MODEL_1, OnRadioModel1)
  40. ON_BN_CLICKED(IDC_RADIO_MODEL_2, OnRadioModel2)
  41. ON_BN_CLICKED(IDC_CHECK_SMOOTH, OnCheckSmooth)
  42. ON_BN_CLICKED(IDC_CHECK_ANTIALIAS, OnCheckAntialias)
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CFormCommandView diagnostics
  47. #ifdef _DEBUG
  48. void CFormCommandView::AssertValid() const
  49. {
  50. CFormView::AssertValid();
  51. }
  52. void CFormCommandView::Dump(CDumpContext& dc) const
  53. {
  54. CFormView::Dump(dc);
  55. }
  56. CToolDoc* CFormCommandView::GetDocument() // non-debug version is inline
  57. {
  58. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CToolDoc)));
  59. return (CToolDoc*)m_pDocument;
  60. }
  61. #endif //_DEBUG
  62. // OnPaint
  63. void CFormCommandView::OnPaint() 
  64. {
  65. // Device context for painting
  66. CPaintDC dc(this); 
  67. // Options are stored in Application
  68. CToolApp *pApp = (CToolApp *)AfxGetApp();
  69. CRect rect;
  70. // Color back
  71. m_ControlBackColor.GetWindowRect(&rect);
  72. ScreenToClient(&rect);
  73. CBrush BrushBack(pApp->m_OptionColorGlBack);
  74. dc.FillRect(&rect,&BrushBack);
  75. }
  76. // OnLButtonUp
  77. void CFormCommandView::OnLButtonUp(UINT nFlags, 
  78.  CPoint point) 
  79. {
  80. CRect rect;
  81. CToolApp *pApp = (CToolApp *)AfxGetApp();
  82. // Option back color
  83. m_ControlBackColor.GetWindowRect(&rect);
  84. ScreenToClient(&rect);
  85. if(rect.PtInRect(point))
  86. {
  87. CColorDialog dlg(pApp->m_OptionColorGlBack);
  88. if(dlg.DoModal()==IDOK)
  89. {
  90. pApp->m_OptionColorGlBack = dlg.GetColor();
  91. CRenderView *pView = (CRenderView *)GetRenderView();
  92. pView->m_ClearColorRed   = (float)GetRValue(pApp->m_OptionColorGlBack) / 255.0f;
  93. pView->m_ClearColorGreen = (float)GetGValue(pApp->m_OptionColorGlBack) / 255.0f;
  94. pView->m_ClearColorBlue  = (float)GetBValue(pApp->m_OptionColorGlBack) / 255.0f;
  95. this->InvalidateRect(&rect,FALSE);
  96. pView->InvalidateRect(NULL,FALSE);
  97. }
  98. }
  99. CFormView::OnLButtonUp(nFlags, point);
  100. }
  101. // GetRenderView
  102. CView *CFormCommandView::GetRenderView() 
  103. {
  104. CToolApp *pApp = (CToolApp *)AfxGetApp();
  105. CMainFrame *pFrame = (CMainFrame *)pApp->m_pMainWnd;
  106. CView *pView = (CView *)pFrame->m_wndSplitter.GetPane(0,1);
  107. return pView;
  108. }
  109. // Model
  110. void CFormCommandView::OnRadioModel1() 
  111. {
  112. glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
  113. this->GetRenderView()->InvalidateRect(NULL,FALSE); 
  114. }
  115. void CFormCommandView::OnRadioModel2() 
  116. {
  117. glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
  118. this->GetRenderView()->InvalidateRect(NULL,FALSE); 
  119. }
  120. // OnCheckSmooth
  121. void CFormCommandView::OnCheckSmooth() 
  122. {
  123. m_Smooth = !m_Smooth;
  124. if(m_Smooth)
  125. glShadeModel(GL_SMOOTH);
  126. else
  127. glShadeModel(GL_FLAT);
  128. this->GetRenderView()->InvalidateRect(NULL,FALSE); 
  129. }
  130. // OnCheckAntialias
  131. // Toggle antialiased lines
  132. void CFormCommandView::OnCheckAntialias() 
  133. {
  134. m_Antialias = !m_Antialias;
  135. if(m_Antialias)
  136. {
  137. glEnable(GL_LINE_SMOOTH);
  138. glEnable(GL_BLEND);
  139. glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  140. glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
  141. glLineWidth(1.5f);
  142. }
  143. else
  144. {
  145. glDisable(GL_LINE_SMOOTH);
  146. glDisable(GL_BLEND);
  147. glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  148. glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
  149. glLineWidth(1.0f);
  150. }
  151. GetRenderView()->InvalidateRect(NULL,FALSE); 
  152. }