EditMipSwitchDistance.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. // EditMipSwitchDistance.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "EditMipSwitchDistance.h"
  16. #ifdef _DEBUG
  17. #undef new
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CEditMipSwitchDistance
  24. CEditMipSwitchDistance::CEditMipSwitchDistance()
  25. {
  26. m_pbrmBrushMipSelected = NULL;
  27. m_fLastValue = -1;
  28. }
  29. CEditMipSwitchDistance::~CEditMipSwitchDistance()
  30. {
  31. }
  32. BEGIN_MESSAGE_MAP(CEditMipSwitchDistance, CEdit)
  33. //{{AFX_MSG_MAP(CEditMipSwitchDistance)
  34. //}}AFX_MSG_MAP
  35. END_MESSAGE_MAP()
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CEditMipSwitchDistance message handlers
  38. CBrushMip *GetMipBrush(void)
  39. {
  40. CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  41. CEntity *penSelected = pMainFrame->m_CSGDesitnationCombo.GetSelectedBrushEntity();
  42. CWorldEditorView *pWedView = theApp.GetActiveView();
  43. if( pWedView != NULL)
  44. {
  45. CBrushMip *pbmCurrentMip = pWedView->GetCurrentBrushMip();
  46. return pbmCurrentMip;
  47. }
  48. return NULL;
  49. }
  50. BOOL IsEditingEnabled(void)
  51. {
  52. CWorldEditorView *pWedView = theApp.GetActiveView();
  53. if( pWedView != NULL)
  54. {
  55. CChildFrame *pWedChild = pWedView->GetChildFrame();
  56. if( pWedChild != NULL)
  57. {
  58. CBrushMip *pbrm = GetMipBrush();
  59. CWorldEditorDoc *pDoc = pWedView->GetDocument();
  60. if( (pDoc != NULL) && (pDoc->GetEditingMode() == ENTITY_MODE) && (pbrm != NULL))
  61. {
  62. return !pWedChild->m_bAutoMipBrushingOn;
  63. }
  64. }
  65. }
  66. return FALSE;
  67. }
  68. BOOL CEditMipSwitchDistance::PreTranslateMessage(MSG* pMsg)
  69. {
  70. // if we caught key down message
  71. if( pMsg->message==WM_KEYDOWN)
  72. {
  73. if( ((int)pMsg->wParam==VK_RETURN) && IsEditingEnabled() )
  74. {
  75. // set new mip switch distance
  76. CString strWindowText;
  77. GetWindowText( strWindowText);
  78. CTString strValue = CStringA(strWindowText);
  79. FLOAT fValue = 100.0f;
  80. CBrushMip *pbrm = GetMipBrush();
  81. // if value is valid and brush exists
  82. if( (strValue.ScanF( "%g", &fValue) == 1) && (pbrm != NULL) )
  83. {
  84. pbrm->SetMipDistance( fValue);
  85. m_fLastValue = fValue;
  86. CWorldEditorView *pWedView = theApp.GetActiveView();
  87. CWorldEditorDoc *pDoc = pWedView->GetDocument();
  88. pDoc->SetModifiedFlag( TRUE);
  89. pDoc->m_chSelections.MarkChanged();
  90. pDoc->UpdateAllViews( NULL);
  91. }
  92. }
  93. else
  94. {
  95. TranslateMessage(pMsg);
  96. SendMessage( WM_KEYDOWN, pMsg->wParam, pMsg->lParam);
  97. }
  98. return TRUE;
  99. }
  100. return CEdit::PreTranslateMessage(pMsg);
  101. }
  102. BOOL CEditMipSwitchDistance::OnIdle(LONG lCount)
  103. {
  104. CBrushMip *pbrmip = GetMipBrush();
  105. // if editing is disabled
  106. if( !IsEditingEnabled() )
  107. {
  108. EnableWindow( FALSE);
  109. }
  110. // if we should update value
  111. else
  112. {
  113. EnableWindow( TRUE);
  114. FLOAT fValue = pbrmip->GetMipDistance();
  115. if( (pbrmip != m_pbrmBrushMipSelected) || (fValue != m_fLastValue) )
  116. {
  117. CTString strValue;
  118. m_fLastValue = fValue;
  119. strValue.PrintF( "%g", fValue);
  120. SetWindowText( CString(strValue));
  121. }
  122. }
  123. m_pbrmBrushMipSelected = pbrmip;
  124. return TRUE;
  125. }