DlgEditTerrainBrush.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. // DlgEditTerrainBrush.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "WorldEditor.h"
  16. #include "DlgEditTerrainBrush.h"
  17. #ifdef _DEBUG
  18. #undef new
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CDlgEditTerrainBrush dialog
  25. CDlgEditTerrainBrush::CDlgEditTerrainBrush(CWnd* pParent /*=NULL*/)
  26. : CDialog(CDlgEditTerrainBrush::IDD, pParent)
  27. {
  28. //{{AFX_DATA_INIT(CDlgEditTerrainBrush)
  29. m_fFallOff = 0.0f;
  30. m_fHotSpot = 0.0f;
  31. //}}AFX_DATA_INIT
  32. }
  33. void CDlgEditTerrainBrush::DoDataExchange(CDataExchange* pDX)
  34. {
  35. CDialog::DoDataExchange(pDX);
  36. // if dialog is reciving data
  37. if( pDX->m_bSaveAndValidate == FALSE)
  38. {
  39. m_fHotSpot=atebCustomEditBrushes[m_iBrush].teb_fHotSpot;
  40. m_fFallOff=atebCustomEditBrushes[m_iBrush].teb_fFallOff;
  41. }
  42. //{{AFX_DATA_MAP(CDlgEditTerrainBrush)
  43. DDX_Text(pDX, IDC_FALLOFF, m_fFallOff);
  44. DDV_MinMaxFloat(pDX, m_fFallOff, 0.f, 1.e+008f);
  45. DDX_Text(pDX, IDC_HOTSPOT, m_fHotSpot);
  46. DDV_MinMaxFloat(pDX, m_fHotSpot, 0.f, 1.e+007f);
  47. //}}AFX_DATA_MAP
  48. // if dialog is giving data
  49. if( pDX->m_bSaveAndValidate != FALSE)
  50. {
  51. atebCustomEditBrushes[m_iBrush].teb_fHotSpot=m_fHotSpot;
  52. atebCustomEditBrushes[m_iBrush].teb_fFallOff=m_fFallOff;
  53. }
  54. }
  55. BEGIN_MESSAGE_MAP(CDlgEditTerrainBrush, CDialog)
  56. //{{AFX_MSG_MAP(CDlgEditTerrainBrush)
  57. ON_BN_CLICKED(ID_GENERATE_TERRAIN_BRUSH, OnGenerateTerrainBrush)
  58. ON_BN_CLICKED(IDC_IMPORT_TERRAIN_BRUSH, OnImportTerrainBrush)
  59. //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CDlgEditTerrainBrush message handlers
  63. void CDlgEditTerrainBrush::OnGenerateTerrainBrush()
  64. {
  65. UpdateData(TRUE);
  66. GenerateTerrainBrushTexture( m_iBrush, m_fHotSpot, m_fFallOff);
  67. }
  68. void CDlgEditTerrainBrush::OnImportTerrainBrush()
  69. {
  70. CTFileName fnBrush = _EngineGUI.FileRequester(
  71. "Choose picture for brush", FILTER_TGA FILTER_PCX FILTER_ALL FILTER_END,
  72. "Terrain brush directory", "Textures\\");
  73. SetFocus();
  74. SetActiveWindow();
  75. if( fnBrush== "") return;
  76. CImageInfo ii;
  77. ii.LoadAnyGfxFormat_t( fnBrush);
  78. // both dimension must be potentions of 2
  79. if( (ii.ii_Width == 1<<((int)Log2( (FLOAT)ii.ii_Width))) &&
  80. (ii.ii_Height == 1<<((int)Log2( (FLOAT)ii.ii_Height))) )
  81. {
  82. CTFileName fnTexture = GetBrushTextureName(m_iBrush);
  83. // creates new texture with one frame
  84. CTextureData tdPicture;
  85. tdPicture.Create_t( &ii, ii.ii_Width, 16, TRUE);
  86. tdPicture.Save_t( fnTexture);
  87. }
  88. }