home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 8090 / ModelEdit.7z / SetFOVDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-03-08  |  3.3 KB  |  141 lines

  1. // SetFOVDlg.cpp : implementation file
  2. //
  3.  
  4. #include "precompile.h"
  5. #include "stdafx.h"
  6. #include "modeledit.h"
  7. #include "SetFOVDlg.h"
  8. #include "RenderWnd.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CSetFOVDlg dialog
  18.  
  19.  
  20. CSetFOVDlg::CSetFOVDlg(CRenderWnd *host, CWnd* pParent /*=NULL*/)
  21.     : CDialog(CSetFOVDlg::IDD, pParent)
  22. {
  23.     m_baseFOV = 45 ;
  24.     m_startVal = MIN_FOV ;
  25.     m_endVal = MAX_FOV ;
  26.  
  27.     //{{AFX_DATA_INIT(CSetFOVDlg)
  28.         // NOTE: the ClassWizard will add member initialization here
  29.     //}}AFX_DATA_INIT
  30.     m_Host = host ;
  31. }
  32.  
  33.  
  34. void CSetFOVDlg::DoDataExchange(CDataExchange* pDX)
  35. {
  36.     CDialog::DoDataExchange(pDX);
  37.     //{{AFX_DATA_MAP(CSetFOVDlg)
  38.         // NOTE: the ClassWizard will add DDX and DDV calls here
  39.     //}}AFX_DATA_MAP
  40. }
  41.  
  42.  
  43. BEGIN_MESSAGE_MAP(CSetFOVDlg, CDialog)
  44.     //{{AFX_MSG_MAP(CSetFOVDlg)
  45.     ON_WM_HSCROLL()
  46.     ON_EN_CHANGE(IDC_FOV_EDIT, OnEditChange)
  47.     //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CSetFOVDlg message handlers
  52.  
  53. void CSetFOVDlg::PostNcDestroy() 
  54. {
  55.     // TODO: Add your specialized code here and/or call the base class
  56.  
  57.     // m_Host-> NotifyOfDiagDeath();
  58.     delete this ;    
  59.     CDialog::PostNcDestroy();
  60. }
  61.  
  62. void CSetFOVDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  63. {
  64.     // TODO: Add your message handler code here and/or call default
  65.     // tell host value has changed.    
  66.  
  67.     int nControl = pScrollBar->GetDlgCtrlID();
  68.  
  69.     if( nControl == IDC_FOV_SLIDER )
  70.     {
  71.         CSliderCtrl* pCtrl = GetSliderFOV();
  72.         ASSERT( pCtrl != NULL );
  73.         int nScPos = pCtrl->GetPos();
  74.         char buf[256];
  75.         sprintf(buf,"%d",nScPos);
  76.         GetEditFOV()->SetWindowText( buf );
  77.         m_Host->SetFOV( nScPos ) ;
  78.     }
  79.  
  80.     CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
  81. }
  82.  
  83.  
  84. BOOL CSetFOVDlg::OnInitDialog() 
  85. {
  86.     CDialog::OnInitDialog();
  87.     // TODO: Add extra initialization here
  88.     CSliderCtrl *pSlider = GetSliderFOV();
  89.     pSlider->SetRange(m_startVal, m_endVal );
  90.     pSlider->SetPos(  m_baseFOV );
  91.  
  92.     //make it so there are 10 tics on the slider (the +9 is to round up)
  93.     pSlider->SetTicFreq((m_endVal - m_startVal + 9) / 10);
  94.  
  95.     CString sVal;
  96.     sVal.Format( "%d", m_baseFOV );
  97.     GetEditFOV()->SetWindowText( sVal );
  98.  
  99.     //setup the min/max/mid strings above the scroll bar
  100.     sVal.Format("%d", m_startVal);
  101.     ((CStatic*)GetDlgItem(IDC_MIN))->SetWindowText(sVal);
  102.  
  103.     sVal.Format("%d", m_endVal);
  104.     ((CStatic*)GetDlgItem(IDC_MAX))->SetWindowText(sVal);
  105.  
  106.     sVal.Format("%d", (m_startVal + m_endVal) / 2);
  107.     ((CStatic*)GetDlgItem(IDC_MID))->SetWindowText(sVal);
  108.  
  109.     
  110.     
  111.     return TRUE;  // return TRUE unless you set the focus to a control
  112.                   // EXCEPTION: OCX Property Pages should return FALSE
  113. }
  114.  
  115. CEdit* CSetFOVDlg::GetEditFOV()
  116. {
  117.     return static_cast<CEdit*>(GetDlgItem(IDC_FOV_EDIT));
  118. }
  119.  
  120. CSliderCtrl* CSetFOVDlg::GetSliderFOV()
  121. {
  122.     return static_cast<CSliderCtrl*>(GetDlgItem(IDC_FOV_SLIDER)); 
  123. }
  124.  
  125.  
  126. void CSetFOVDlg::OnEditChange()
  127. {
  128.     //get the string in the edit box
  129.     CString sFOV;
  130.     GetEditFOV()->GetWindowText(sFOV);
  131.  
  132.     //trim unneeded spaces
  133.     sFOV.TrimLeft();
  134.     sFOV.TrimRight();
  135.  
  136.     //convert to an integer
  137.     int nFOV = atoi(sFOV);
  138.  
  139.     //set the slider to reflect the edit box
  140.     GetSliderFOV()->SetPos(nFOV);
  141. }