Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

510 lines
16 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef SCULPTOPTIONS_H
  7. #define SCULPTOPTIONS_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "disppaint.h"
  12. #include "afxwin.h"
  13. #include "afxcmn.h"
  14. class CMapView3D;
  15. class CPaintSculptDlg;
  16. class CSculptTool
  17. {
  18. public:
  19. CSculptTool();
  20. ~CSculptTool();
  21. void SetPaintOwner( CPaintSculptDlg *pOwner ) { m_PaintOwner = pOwner; }
  22. virtual bool BeginPaint( CMapView3D *pView, const Vector2D &vPoint );
  23. virtual bool Paint( CMapView3D *pView, const Vector2D &vPoint, SpatialPaintData_t &SpatialData );
  24. virtual void RenderTool3D(CRender3D *pRender) = 0;
  25. virtual bool OnLMouseUp3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  26. virtual bool OnLMouseDown3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  27. virtual bool OnRMouseUp3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  28. virtual bool OnRMouseDown3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  29. virtual bool OnMouseMove3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  30. virtual bool OnLButtonUpDialog(UINT nFlags, CPoint point) { return false; }
  31. virtual bool OnLButtonDownDialog(UINT nFlags, CPoint point) { return false; }
  32. virtual bool OnMouseMoveDialog(UINT nFlags, CPoint point) { return false; }
  33. protected:
  34. // Painting.
  35. virtual bool PrePaint( CMapView3D *pView, const Vector2D &vPoint );
  36. virtual bool PostPaint( bool bAutoSew );
  37. virtual bool DoPaint( CMapView3D *pView, const Vector2D &vPoint );
  38. virtual void DoPaintOperation( CMapView3D *pView, const Vector2D &vPoint, CMapDisp *pDisp, CMapDisp *pOrigDisp ) = 0;
  39. bool GetStartingSpot( CMapView3D *pView, const Vector2D &vPoint );
  40. bool IsPointInScreenCircle( CMapView3D *pView, CMapDisp *pDisp, CMapDisp *pOrigDisp, int nVertIndex, bool bUseOrigDisplacement = true, bool bUseCurrentPosition = false, float *pflLengthPercent = NULL );
  41. void DoPaintSmooth( CMapView3D *pView, const Vector2D &vPoint, CMapDisp *pDisp, CMapDisp *pOrigDisp );
  42. bool PaintSphereDispBBoxOverlap( const Vector &vCenter, float flRadius, const Vector &vBBoxMin, const Vector &vBBoxMax );
  43. bool IsInSphereRadius( const Vector &vCenter, float flRadius2, const Vector &vPos, float &flDistance2 );
  44. float CalcSmoothRadius2( const Vector &vPoint );
  45. bool DoPaintSmoothOneOverExp( const Vector &vNewCenter, Vector &vPaintPos );
  46. void AddToUndo( CMapDisp **pDisp );
  47. void DrawDirection( CRender3D *pRender, Vector vDirection, Color Towards, Color Away );
  48. void DuplicateSelectedDisp( );
  49. void PrepareDispForPainting( );
  50. bool FindCollisionIntercept( CCamera *pCamera, const Vector2D &vPoint, bool bUseOrigPosition, Vector &vCollisionPoint, Vector &vCollisionNormal, float &vCollisionIntercept,
  51. int *pnCollideDisplacement = NULL, int *pnCollideTri = NULL );
  52. private:
  53. void DetermineKeysDown();
  54. protected:
  55. static bool MapDispLessFunc( EditDispHandle_t const &a, EditDispHandle_t const &b )
  56. {
  57. return a < b;
  58. }
  59. static CUtlMap<EditDispHandle_t, CMapDisp *> m_OrigMapDisp;
  60. Vector m_StartingCollisionPoint, m_StartingCollisionNormal, m_OriginalCollisionPoint, m_OriginalCollisionNormal, m_CurrentCollisionPoint, m_CurrentCollisionNormal;
  61. float m_StartingCollisionIntercept, m_OriginalCollisionIntercept, m_CurrentCollisionIntercept;
  62. float m_StartingProjectedRadius, m_OriginalProjectedRadius, m_CurrentProjectedRadius;
  63. bool m_OriginalCollisionValid, m_CurrentCollisionValid;
  64. Vector2D m_MousePoint;
  65. bool m_bLMBDown; // left mouse button state
  66. bool m_bRMBDown; // right mouse button state
  67. bool m_bAltDown, m_bCtrlDown, m_bShiftDown;
  68. bool m_ValidPaintingSpot;
  69. float m_BrushSize;
  70. CPaintSculptDlg *m_PaintOwner;
  71. SpatialPaintData_t m_SpatialData;
  72. };
  73. class CSculptPainter : public CSculptTool
  74. {
  75. public:
  76. CSculptPainter();
  77. ~CSculptPainter();
  78. virtual bool BeginPaint( CMapView3D *pView, const Vector2D &vPoint );
  79. virtual bool Paint( CMapView3D *pView, const Vector2D &vPoint, SpatialPaintData_t &spatialData );
  80. virtual bool OnLMouseUp3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  81. virtual bool OnLMouseDown3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  82. virtual bool OnRMouseUp3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  83. virtual bool OnRMouseDown3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  84. virtual bool OnMouseMove3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  85. protected:
  86. virtual bool DoSizing( const Vector2D &vPoint );
  87. bool m_InPaintingMode;
  88. bool m_InSizingMode;
  89. Vector2D m_StartSizingPoint;
  90. float m_OrigBrushSize;
  91. };
  92. class CSculptPushOptions : public CDialog, public CSculptPainter
  93. {
  94. DECLARE_DYNAMIC(CSculptPushOptions)
  95. public:
  96. CSculptPushOptions(CWnd* pParent = NULL); // standard constructor
  97. virtual ~CSculptPushOptions();
  98. virtual BOOL OnInitDialog( void );
  99. virtual void OnOK();
  100. virtual void OnCancel();
  101. // Dialog Data
  102. enum { IDD = IDD_DISP_SCULPT_PUSH_OPTIONS };
  103. typedef enum
  104. {
  105. OFFSET_MODE_ADAPTIVE,
  106. OFFSET_MODE_ABSOLUTE
  107. } OffsetMode;
  108. typedef enum
  109. {
  110. NORMAL_MODE_BRUSH_CENTER,
  111. NORMAL_MODE_SCREEN,
  112. NORMAL_MODE_X,
  113. NORMAL_MODE_Y,
  114. NORMAL_MODE_Z,
  115. NORMAL_MODE_SELECTED
  116. } NormalMode;
  117. typedef enum
  118. {
  119. DENSITY_MODE_ADDITIVE,
  120. DENSITY_MODE_ATTENUATED,
  121. } DensityMode;
  122. protected:
  123. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  124. DECLARE_MESSAGE_MAP()
  125. public:
  126. afx_msg void OnCbnSelchangeIdcSculptPushOptionNormalMode();
  127. CComboBox m_OffsetModeControl;
  128. CEdit m_OffsetDistanceControl;
  129. CEdit m_OffsetAmountControl;
  130. CEdit m_SmoothAmountControl;
  131. CEdit m_FalloffPositionControl;
  132. CEdit m_FalloffFinalControl;
  133. CComboBox m_DensityModeControl;
  134. CComboBox m_NormalModeControl;
  135. afx_msg void OnCbnSelchangeSculptPushOptionOffsetMode();
  136. private:
  137. OffsetMode m_OffsetMode;
  138. float m_OffsetDistance, m_OffsetAmount;
  139. NormalMode m_NormalMode;
  140. DensityMode m_DensityMode;
  141. float m_Direction;
  142. float m_SmoothAmount;
  143. Vector m_SelectedNormal;
  144. float m_flFalloffSpot;
  145. float m_flFalloffEndingValue;
  146. void GetPaintAxis( CCamera *pCamera, const Vector2D &vPoint, Vector &vPaintAxis );
  147. public:
  148. virtual bool BeginPaint( CMapView3D *pView, const Vector2D &vPoint );
  149. virtual void RenderTool3D(CRender3D *pRender);
  150. virtual bool OnRMouseDown3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  151. protected:
  152. virtual void DoPaintOperation( CMapView3D *pView, const Vector2D &vPoint, CMapDisp *pDisp, CMapDisp *pOrigDisp );
  153. void DoSmoothOperation( CMapView3D *pView, const Vector2D &vPoint, CMapDisp *pDisp, CMapDisp *pOrigDisp );
  154. public:
  155. afx_msg void OnEnChangeSculptPushOptionOffsetDistance();
  156. afx_msg void OnCbnSelchangeSculptPushOptionDensityMode();
  157. afx_msg void OnEnKillfocusSculptPushOptionSmoothAmount();
  158. afx_msg void OnEnKillfocusSculptPushOptionOffsetAmount();
  159. afx_msg void OnEnKillfocusSculptPushOptionFalloffPosition();
  160. afx_msg void OnEnKillfocusSculptPushOptionFalloffFinal();
  161. };
  162. class CSculptCarveOptions : public CDialog, public CSculptPainter
  163. {
  164. DECLARE_DYNAMIC(CSculptCarveOptions)
  165. public:
  166. CSculptCarveOptions(CWnd* pParent = NULL); // standard constructor
  167. virtual ~CSculptCarveOptions();
  168. virtual BOOL OnInitDialog( void );
  169. virtual void OnOK();
  170. virtual void OnCancel();
  171. // Dialog Data
  172. enum { IDD = IDD_DISP_SCULPT_CARVE_OPTIONS };
  173. typedef enum
  174. {
  175. OFFSET_MODE_ADAPTIVE,
  176. OFFSET_MODE_ABSOLUTE
  177. } OffsetMode;
  178. typedef enum
  179. {
  180. NORMAL_MODE_BRUSH_CENTER,
  181. NORMAL_MODE_SCREEN,
  182. NORMAL_MODE_X,
  183. NORMAL_MODE_Y,
  184. NORMAL_MODE_Z,
  185. NORMAL_MODE_SELECTED
  186. } NormalMode;
  187. typedef enum
  188. {
  189. DENSITY_MODE_ADDITIVE,
  190. DENSITY_MODE_ATTENUATED,
  191. } DensityMode;
  192. protected:
  193. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  194. DECLARE_MESSAGE_MAP()
  195. public:
  196. CComboBox m_OffsetModeControl;
  197. CEdit m_OffsetDistanceControl;
  198. CEdit m_OffsetAmountControl;
  199. CEdit m_SmoothAmountControl;
  200. CComboBox m_DensityModeControl;
  201. CComboBox m_NormalModeControl;
  202. CStatic m_CarveBrushControl;
  203. private:
  204. const static int MAX_SCULPT_SIZE = 100;
  205. const static int MAX_QUEUE_SIZE = 20;
  206. OffsetMode m_OffsetMode;
  207. float m_OffsetDistance, m_OffsetAmount;
  208. NormalMode m_NormalMode;
  209. DensityMode m_DensityMode;
  210. float m_Direction;
  211. float m_SmoothAmount;
  212. Vector m_SelectedNormal;
  213. float m_BrushPoints[ MAX_SCULPT_SIZE ];
  214. int m_BrushLocation;
  215. Vector2D m_StartLine, m_EndLine;
  216. CUtlVector< Vector2D > m_DrawPoints;
  217. CUtlVector< Vector2D > m_DrawNormal;
  218. CUtlVector< Vector2D > m_PointQueue;
  219. void GetPaintAxis( CCamera *pCamera, const Vector2D &vPoint, Vector &vPaintAxis );
  220. void AdjustBrush( int x, int y );
  221. void AdjustBrushCursor( int x, int y );
  222. bool CalculatePointNormal( int PointIndex, Vector2D &vNormal );
  223. bool CalculateQueuePoint( Vector2D &vPoint, Vector2D &vNormal );
  224. void AddQueuePoint( const Vector2D &vPoint, bool bDrawIt );
  225. public:
  226. virtual bool BeginPaint( CMapView3D *pView, const Vector2D &vPoint );
  227. // virtual bool Paint( CMapView3D *pView, const Vector2D &vPoint, SpatialPaintData_t &spatialData );
  228. virtual void RenderTool3D(CRender3D *pRender);
  229. virtual bool OnLMouseUp3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  230. virtual bool OnLMouseDown3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  231. virtual bool OnRMouseDown3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  232. virtual bool OnMouseMove3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  233. protected:
  234. bool IsPointAffected( CMapView3D *pView, CMapDisp *pDisp, CMapDisp *pOrigDisp, int nVertIndex, int nBrushPoint, Vector2D &vViewVert, bool bUseOrigDisplacement = true, bool bUseCurrentPosition = false );
  235. virtual void DoPaintOperation( CMapView3D *pView, const Vector2D &vPoint, CMapDisp *pDisp, CMapDisp *pOrigDisp );
  236. public:
  237. afx_msg void OnPaint();
  238. afx_msg void OnEnChangeSculptPushOptionOffsetDistance();
  239. afx_msg void OnCbnSelchangeSculptPushOptionDensityMode();
  240. afx_msg void OnEnKillfocusSculptPushOptionSmoothAmount();
  241. afx_msg void OnEnKillfocusSculptPushOptionOffsetAmount();
  242. afx_msg void OnCbnSelchangeIdcSculptPushOptionNormalMode();
  243. afx_msg void OnCbnSelchangeSculptPushOptionOffsetMode();
  244. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  245. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  246. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  247. virtual BOOL PreTranslateMessage( MSG* pMsg );
  248. };
  249. #if 0
  250. class ITextureInternal;
  251. // CSculptProjectOptions dialog
  252. class CSculptProjectOptions : public CDialog, public CSculptTool
  253. {
  254. DECLARE_DYNAMIC(CSculptProjectOptions)
  255. public:
  256. CSculptProjectOptions(CWnd* pParent = NULL); // standard constructor
  257. virtual ~CSculptProjectOptions();
  258. // Dialog Data
  259. enum { IDD = IDD_DISP_SCULPT_PROJECT_OPTIONS };
  260. public:
  261. virtual bool Paint( CMapView3D *pView, const Vector2D &vPoint, SpatialPaintData_t &spatialData );
  262. virtual void RenderTool3D(CRender3D *pRender);
  263. virtual bool OnLMouseUp3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  264. virtual bool OnLMouseDown3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  265. virtual bool OnRMouseUp3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  266. virtual bool OnRMouseDown3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  267. virtual bool OnMouseMove3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  268. protected:
  269. typedef enum
  270. {
  271. PROJECT_MODE_NONE,
  272. PROJECT_MODE_SIZE,
  273. PROJECT_MODE_POSITION,
  274. PROJECT_MODE_TILE,
  275. } ToolMode;
  276. CFileDialog *m_FileDialog;
  277. unsigned char *m_ImagePixels;
  278. int m_Width, m_Height;
  279. ITextureInternal *m_pTexture;
  280. IMaterial *m_pMaterial;
  281. Vector m_ProjectLocation, m_ProjectSize;
  282. Vector m_OriginalProjectLocation, m_OriginalProjectSize;
  283. int m_ProjectX, m_ProjectY, m_ProjectWidth, m_ProjectHeight;
  284. float m_TileWidth, m_TileHeight;
  285. float m_OriginalTileWidth, m_OriginalTileHeight;
  286. ToolMode m_ToolMode;
  287. Vector2D m_StartSizingPoint;
  288. protected:
  289. virtual void DoPaintOperation( CMapView3D *pView, const Vector2D &vPoint, CMapDisp *pDisp, CMapDisp *pOrigDisp );
  290. virtual bool DoSizing( const Vector2D &vPoint );
  291. virtual bool DoPosition( const Vector2D &vPoint );
  292. virtual bool DoTiling( const Vector2D &vPoint );
  293. bool ReadImage( CString &FileName );
  294. protected:
  295. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  296. DECLARE_MESSAGE_MAP()
  297. public:
  298. afx_msg void OnBnClickedLoadImage();
  299. public:
  300. CSliderCtrl m_ProjectSizeControl;
  301. public:
  302. afx_msg void OnNMCustomdrawProjectSize(NMHDR *pNMHDR, LRESULT *pResult);
  303. public:
  304. virtual BOOL OnInitDialog();
  305. public:
  306. CStatic m_ProjectSizeNumControl;
  307. };
  308. #endif
  309. class CTextureButton : public CButton
  310. {
  311. public:
  312. CTextureButton( );
  313. void SetTexture( IEditorTexture *pTexture );
  314. void SetSelected( bool bSelected );
  315. virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  316. virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
  317. private:
  318. IEditorTexture *m_pTexure;
  319. bool m_bSelected;
  320. };
  321. class CColorButton : public CButton
  322. {
  323. public:
  324. CColorButton( );
  325. void SetColor( float flRed, float flGreen, float flBlue );
  326. virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  327. virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
  328. private:
  329. float m_flRed, m_flGreen, m_flBlue;
  330. protected:
  331. DECLARE_MESSAGE_MAP()
  332. };
  333. class CSculptBlendOptions : public CDialog, public CSculptPainter
  334. {
  335. DECLARE_DYNAMIC(CSculptBlendOptions)
  336. public:
  337. CSculptBlendOptions(CWnd* pParent = NULL); // standard constructor
  338. virtual ~CSculptBlendOptions();
  339. virtual BOOL OnInitDialog( void );
  340. virtual void OnOK();
  341. virtual void OnCancel();
  342. // Dialog Data
  343. enum { IDD = IDD_DISP_SCULPT_BLEND_OPTIONS };
  344. typedef enum
  345. {
  346. COLOR_MODE_SINGLE,
  347. COLOR_MODE_RANGE,
  348. COLOR_MODE_OR,
  349. COLOR_MODE_MAX
  350. } ColorMode;
  351. protected:
  352. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  353. DECLARE_MESSAGE_MAP()
  354. public:
  355. private:
  356. float m_Direction;
  357. float m_flFalloffSpot;
  358. float m_flFalloffEndingValue;
  359. int m_nLastCollideDisplacement;
  360. int m_nLastCollideTri;
  361. ColorMode m_ColorMode[ MAX_MULTIBLEND_CHANNELS ];
  362. int m_nSelectedTexture;
  363. Vector m_vStartDrawColor[ MAX_MULTIBLEND_CHANNELS ];
  364. Vector m_vEndDrawColor[ MAX_MULTIBLEND_CHANNELS ];
  365. int m_nDefaultFalloffPosition;
  366. int m_nDefaultFalloffFinal;
  367. int m_nDefaultBlendAmount;
  368. int m_nDefaultColorBlendAmount;
  369. int m_nDefaultAlphaBlendAmount;
  370. bool m_b4WayBlendMode;
  371. public:
  372. virtual bool BeginPaint( CMapView3D *pView, const Vector2D &vPoint );
  373. virtual void RenderTool3D(CRender3D *pRender);
  374. virtual bool OnRMouseDown3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  375. protected:
  376. virtual bool DoPaint( CMapView3D *pView, const Vector2D &vPoint );
  377. virtual void DoPaintOperation( CMapView3D *pView, const Vector2D &vPoint, CMapDisp *pDisp, CMapDisp *pOrigDisp );
  378. void SelectTexture( int nTexture );
  379. void SetColorMode( ColorMode NewMode, bool bSetDialog );
  380. public:
  381. CSliderCtrl m_BlendAmountControl;
  382. afx_msg void OnNMCustomdrawBlendAmount(NMHDR *pNMHDR, LRESULT *pResult);
  383. CStatic m_BlendAmountTextControl;
  384. afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
  385. CTextureButton m_TextureControl[ MAX_MULTIBLEND_CHANNELS ];
  386. CButton m_TextureMaskControl[ MAX_MULTIBLEND_CHANNELS ];
  387. CButton m_ColorMaskControl[ MAX_MULTIBLEND_CHANNELS ];
  388. afx_msg void OnBnClickedTextureButton1();
  389. afx_msg void OnBnClickedTextureButton2();
  390. afx_msg void OnBnClickedTextureButton3();
  391. afx_msg void OnBnClickedTextureButton4();
  392. afx_msg void ShrinkBrush();
  393. afx_msg void EnlargeBrush();
  394. afx_msg void OnBnClickedSetColor();
  395. afx_msg void OnBnClickedSetColor2();
  396. afx_msg void OnBnClickedBlendColorOperation();
  397. CSliderCtrl m_ColorBlendAmountControl;
  398. CStatic m_ColorBlendAmountTextControl;
  399. CColorButton m_ColorStartControl;
  400. CColorButton m_ColorEndControl;
  401. afx_msg void OnNMCustomdrawColorBlendAmount(NMHDR *pNMHDR, LRESULT *pResult);
  402. CComboBox m_BlendColorOperationControl;
  403. afx_msg void OnCbnSelchangeBlendColorOperation();
  404. CSliderCtrl m_FalloffPositionControl;
  405. CSliderCtrl m_FalloffFinalControl;
  406. CSliderCtrl m_AlphaBlendAmountControl;
  407. CStatic m_AlphaBlendAmountTextControl;
  408. afx_msg void OnNMCustomdrawAlphaBlendAmount(NMHDR *pNMHDR, LRESULT *pResult);
  409. afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);
  410. };
  411. #endif // SCULPTOPTIONS_H