Team Fortress 2 Source Code as on 22/4/2020
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.

676 lines
21 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "dme_controls/particlesystempanel.h"
  8. #include "dme_controls/dmepanel.h"
  9. #include "movieobjects/dmeparticlesystemdefinition.h"
  10. #include "materialsystem/imesh.h"
  11. #include "materialsystem/imaterial.h"
  12. #include "VGuiMatSurface/IMatSystemSurface.h"
  13. #include "matsys_controls/matsyscontrols.h"
  14. #include "vgui/IVGui.h"
  15. #include "vgui_controls/propertypage.h"
  16. #include "vgui_controls/propertysheet.h"
  17. #include "vgui_controls/textentry.h"
  18. #include "vgui_controls/splitter.h"
  19. #include "vgui_controls/checkbutton.h"
  20. #include "matsys_controls/colorpickerpanel.h"
  21. #include "particles/particles.h"
  22. #include "tier1/KeyValues.h"
  23. #include "tier1/utlbuffer.h"
  24. #include "tier2/renderutils.h"
  25. using namespace vgui;
  26. //-----------------------------------------------------------------------------
  27. // Enums
  28. //-----------------------------------------------------------------------------
  29. enum
  30. {
  31. SCROLLBAR_SIZE=18, // the width of a scrollbar
  32. WINDOW_BORDER_WIDTH=2 // the width of the window's border
  33. };
  34. #define SPHERE_RADIUS 10.0f
  35. //-----------------------------------------------------------------------------
  36. // Constructor, destructor
  37. //-----------------------------------------------------------------------------
  38. CParticleSystemPanel::CParticleSystemPanel( vgui::Panel *pParent, const char *pName ) : BaseClass( pParent, pName )
  39. {
  40. m_pParticleSystem = NULL;
  41. m_flLastTime = FLT_MAX;
  42. m_bRenderBounds = false;
  43. m_bRenderCullBounds = false;
  44. m_bRenderHelpers = false;
  45. m_bPerformNameBasedLookup = true;
  46. m_ParticleSystemName = NULL;
  47. InvalidateUniqueId( &m_ParticleSystemId );
  48. InvalidateUniqueId( &m_RenderHelperId );
  49. LookAt( SPHERE_RADIUS );
  50. m_pLightmapTexture.Init( "//platform/materials/debug/defaultlightmap", "editor" );
  51. m_DefaultEnvCubemap.Init( "editor/cubemap", "editor", true );
  52. for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
  53. {
  54. SetControlPointValue( i, Vector( 0, 0, 10.0f * i ) );
  55. }
  56. }
  57. CParticleSystemPanel::~CParticleSystemPanel()
  58. {
  59. m_pLightmapTexture.Shutdown();
  60. m_DefaultEnvCubemap.Shutdown();
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Scheme
  64. //-----------------------------------------------------------------------------
  65. void CParticleSystemPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
  66. {
  67. BaseClass::ApplySchemeSettings( pScheme );
  68. SetBorder( pScheme->GetBorder( "MenuBorder") );
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Indicates that bounds should be drawn
  72. //-----------------------------------------------------------------------------
  73. void CParticleSystemPanel::RenderBounds( bool bEnable )
  74. {
  75. m_bRenderBounds = bEnable;
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Indicates that cull sphere should be drawn
  79. //-----------------------------------------------------------------------------
  80. void CParticleSystemPanel::RenderCullBounds( bool bEnable )
  81. {
  82. m_bRenderCullBounds = bEnable;
  83. }
  84. //-----------------------------------------------------------------------------
  85. // Indicates that bounds should be drawn
  86. //-----------------------------------------------------------------------------
  87. void CParticleSystemPanel::RenderHelpers( bool bEnable )
  88. {
  89. m_bRenderHelpers = bEnable;
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Indicates which helper to draw
  93. //-----------------------------------------------------------------------------
  94. void CParticleSystemPanel::SetRenderedHelper( CDmeParticleFunction *pOp )
  95. {
  96. if ( !pOp )
  97. {
  98. InvalidateUniqueId( &m_RenderHelperId );
  99. }
  100. else
  101. {
  102. CopyUniqueId( pOp->GetId(), &m_RenderHelperId );
  103. }
  104. }
  105. static bool IsValidHierarchy( CParticleCollection *pCollection )
  106. {
  107. if ( !pCollection->IsValid() )
  108. return false;
  109. for( CParticleCollection *pChild = pCollection->m_Children.m_pHead; pChild; pChild = pChild->m_pNext )
  110. {
  111. if ( !IsValidHierarchy( pChild ) )
  112. return false;
  113. }
  114. return true;
  115. }
  116. //-----------------------------------------------------------------------------
  117. // Simulate the particle system
  118. //-----------------------------------------------------------------------------
  119. void CParticleSystemPanel::OnTick()
  120. {
  121. BaseClass::OnTick();
  122. if ( !m_pParticleSystem )
  123. return;
  124. float flTime = Plat_FloatTime();
  125. if ( m_flLastTime == FLT_MAX )
  126. {
  127. m_flLastTime = flTime;
  128. }
  129. float flDt = flTime - m_flLastTime;
  130. m_flLastTime = flTime;
  131. for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
  132. {
  133. if ( !m_pParticleSystem->ReadsControlPoint( i ) )
  134. continue;
  135. m_pParticleSystem->SetControlPoint( i, m_pControlPointValue[i] );
  136. m_pParticleSystem->SetControlPointOrientation( i, Vector( 1, 0, 0 ), Vector( 0, -1, 0 ), Vector( 0, 0, 1 ) );
  137. m_pParticleSystem->SetControlPointParent( i, i );
  138. }
  139. // Restart the particle system if it's finished
  140. bool bIsInvalid = !IsValidHierarchy( m_pParticleSystem );
  141. if ( !bIsInvalid )
  142. {
  143. m_pParticleSystem->Simulate( flDt, false );
  144. }
  145. if ( m_pParticleSystem->IsFinished() || bIsInvalid )
  146. {
  147. delete m_pParticleSystem;
  148. m_pParticleSystem = NULL;
  149. if ( m_bPerformNameBasedLookup )
  150. {
  151. if ( m_ParticleSystemName.Length() )
  152. {
  153. CParticleCollection *pNewParticleSystem = g_pParticleSystemMgr->CreateParticleCollection( m_ParticleSystemName );
  154. m_pParticleSystem = pNewParticleSystem;
  155. }
  156. }
  157. else
  158. {
  159. if ( IsUniqueIdValid( m_ParticleSystemId ) )
  160. {
  161. CParticleCollection *pNewParticleSystem = g_pParticleSystemMgr->CreateParticleCollection( m_ParticleSystemId );
  162. m_pParticleSystem = pNewParticleSystem;
  163. }
  164. }
  165. if ( bIsInvalid )
  166. {
  167. PostActionSignal( new KeyValues( "ParticleSystemReconstructed" ) );
  168. }
  169. m_flLastTime = FLT_MAX;
  170. }
  171. }
  172. //-----------------------------------------------------------------------------
  173. // Startup, shutdown particle collection
  174. //-----------------------------------------------------------------------------
  175. void CParticleSystemPanel::StartupParticleCollection()
  176. {
  177. if ( m_pParticleSystem )
  178. {
  179. vgui::ivgui()->AddTickSignal( GetVPanel(), 0 );
  180. }
  181. m_flLastTime = FLT_MAX;
  182. }
  183. void CParticleSystemPanel::ShutdownParticleCollection()
  184. {
  185. if ( m_pParticleSystem )
  186. {
  187. vgui::ivgui()->RemoveTickSignal( GetVPanel() );
  188. delete m_pParticleSystem;
  189. m_pParticleSystem = NULL;
  190. }
  191. }
  192. //-----------------------------------------------------------------------------
  193. // Set the particle system to draw
  194. //-----------------------------------------------------------------------------
  195. void CParticleSystemPanel::SetParticleSystem( CDmeParticleSystemDefinition *pDef )
  196. {
  197. ShutdownParticleCollection();
  198. if ( pDef )
  199. {
  200. m_bPerformNameBasedLookup = pDef->UseNameBasedLookup();
  201. if ( m_bPerformNameBasedLookup )
  202. {
  203. m_ParticleSystemName = pDef->GetName();
  204. Assert( g_pParticleSystemMgr->IsParticleSystemDefined( m_ParticleSystemName ) );
  205. m_pParticleSystem = g_pParticleSystemMgr->CreateParticleCollection( m_ParticleSystemName );
  206. }
  207. else
  208. {
  209. CopyUniqueId( pDef->GetId(), &m_ParticleSystemId );
  210. Assert( g_pParticleSystemMgr->IsParticleSystemDefined( m_ParticleSystemId ) );
  211. m_pParticleSystem = g_pParticleSystemMgr->CreateParticleCollection( m_ParticleSystemId );
  212. }
  213. PostActionSignal( new KeyValues( "ParticleSystemReconstructed" ) );
  214. }
  215. StartupParticleCollection();
  216. }
  217. void CParticleSystemPanel::SetDmeElement( CDmeParticleSystemDefinition *pDef )
  218. {
  219. SetParticleSystem( pDef );
  220. }
  221. CParticleCollection *CParticleSystemPanel::GetParticleSystem()
  222. {
  223. return m_pParticleSystem;
  224. }
  225. //-----------------------------------------------------------------------------
  226. // Draw bounds
  227. //-----------------------------------------------------------------------------
  228. void CParticleSystemPanel::DrawBounds()
  229. {
  230. Vector vecMins, vecMaxs;
  231. m_pParticleSystem->GetBounds( &vecMins, &vecMaxs );
  232. RenderWireframeBox( vec3_origin, vec3_angle, vecMins, vecMaxs, Color( 0, 255, 255, 255 ), true );
  233. }
  234. //-----------------------------------------------------------------------------
  235. // Draw cull bounds
  236. //-----------------------------------------------------------------------------
  237. void CParticleSystemPanel::DrawCullBounds()
  238. {
  239. Vector vecCenter;
  240. m_pParticleSystem->GetControlPointAtTime( m_pParticleSystem->m_pDef->GetCullControlPoint(), m_pParticleSystem->m_flCurTime, &vecCenter );
  241. RenderWireframeSphere( vecCenter, m_pParticleSystem->m_pDef->GetCullRadius(), 32, 16, Color( 0, 255, 255, 255 ), true );
  242. }
  243. //-----------------------------------------------------------------------------
  244. // paint it!
  245. //-----------------------------------------------------------------------------
  246. #define AXIS_SIZE 5.0f
  247. void CParticleSystemPanel::OnPaint3D()
  248. {
  249. if ( !m_pParticleSystem )
  250. return;
  251. // This needs calling to reset various counters.
  252. g_pParticleSystemMgr->SetLastSimulationTime( m_pParticleSystem->m_flCurTime );
  253. CMatRenderContextPtr pRenderContext( MaterialSystem() );
  254. pRenderContext->BindLightmapTexture( m_pLightmapTexture );
  255. pRenderContext->BindLocalCubemap( m_DefaultEnvCubemap );
  256. // Draw axes
  257. pRenderContext->MatrixMode( MATERIAL_MODEL );
  258. pRenderContext->PushMatrix();
  259. pRenderContext->LoadIdentity( );
  260. if ( m_bRenderBounds )
  261. {
  262. DrawBounds();
  263. Vector vP1;
  264. Vector vP2;
  265. m_pParticleSystem->GetControlPointAtTime( 0, m_pParticleSystem->m_flCurTime, &vP1 );
  266. m_pParticleSystem->GetControlPointAtTime( 1, m_pParticleSystem->m_flCurTime, &vP2 );
  267. RenderLine( vP1, vP2, Color( 0, 255, 255, 255 ), true );
  268. }
  269. if ( m_bRenderCullBounds )
  270. {
  271. DrawCullBounds();
  272. }
  273. if ( m_bRenderHelpers && IsUniqueIdValid( m_RenderHelperId ) )
  274. {
  275. m_pParticleSystem->VisualizeOperator( &m_RenderHelperId );
  276. }
  277. m_pParticleSystem->Render( pRenderContext );
  278. m_pParticleSystem->VisualizeOperator( );
  279. RenderAxes( vec3_origin, AXIS_SIZE, true );
  280. pRenderContext->MatrixMode( MATERIAL_MODEL );
  281. pRenderContext->PopMatrix();
  282. }
  283. //-----------------------------------------------------------------------------
  284. //
  285. // Control point page
  286. //
  287. //-----------------------------------------------------------------------------
  288. class CControlPointPage : public vgui::PropertyPage
  289. {
  290. DECLARE_CLASS_SIMPLE( CControlPointPage, vgui::PropertyPage );
  291. public:
  292. // constructor, destructor
  293. CControlPointPage( vgui::Panel *pParent, const char *pName, CParticleSystemPanel *pParticleSystemPanel );
  294. virtual void PerformLayout();
  295. void CreateControlPointControls( );
  296. private:
  297. MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", params );
  298. MESSAGE_FUNC_PARAMS( OnNewLine, "TextNewLine", params );
  299. void LayoutControlPointControls();
  300. void CleanUpControlPointControls();
  301. vgui::Label *m_pControlPointName[MAX_PARTICLE_CONTROL_POINTS];
  302. vgui::TextEntry *m_pControlPointValue[MAX_PARTICLE_CONTROL_POINTS];
  303. CParticleSystemPanel *m_pParticleSystemPanel;
  304. };
  305. //-----------------------------------------------------------------------------
  306. // Contstructor
  307. //-----------------------------------------------------------------------------
  308. CControlPointPage::CControlPointPage( vgui::Panel *pParent, const char *pName, CParticleSystemPanel *pParticleSystemPanel ) :
  309. BaseClass( pParent, pName )
  310. {
  311. for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
  312. {
  313. m_pControlPointName[i] = NULL;
  314. m_pControlPointValue[i] = NULL;
  315. }
  316. m_pParticleSystemPanel = pParticleSystemPanel;
  317. }
  318. //-----------------------------------------------------------------------------
  319. // Called when the text entry for a control point is changed
  320. //-----------------------------------------------------------------------------
  321. void CControlPointPage::OnTextChanged( KeyValues *pParams )
  322. {
  323. vgui::Panel *pPanel = (vgui::Panel *)pParams->GetPtr( "panel" );
  324. for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
  325. {
  326. if ( pPanel != m_pControlPointValue[i] )
  327. continue;
  328. char pBuf[512];
  329. m_pControlPointValue[i]->GetText( pBuf, sizeof(pBuf) );
  330. Vector vecValue( 0, 0, 0 );
  331. sscanf( pBuf, "%f %f %f", &vecValue.x, &vecValue.y, &vecValue.z );
  332. m_pParticleSystemPanel->SetControlPointValue( i, vecValue );
  333. break;
  334. }
  335. }
  336. //-----------------------------------------------------------------------------
  337. // Called when the text entry for a control point is changed
  338. //-----------------------------------------------------------------------------
  339. void CControlPointPage::OnNewLine( KeyValues *pParams )
  340. {
  341. vgui::Panel *pPanel = (vgui::Panel *)pParams->GetPtr( "panel" );
  342. for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
  343. {
  344. if ( pPanel != m_pControlPointValue[i] )
  345. continue;
  346. char pBuf[512];
  347. m_pControlPointValue[i]->GetText( pBuf, sizeof(pBuf) );
  348. Vector vecValue( 0, 0, 0 );
  349. sscanf( pBuf, "%f %f %f", &vecValue.x, &vecValue.y, &vecValue.z );
  350. m_pParticleSystemPanel->SetControlPointValue( i, vecValue );
  351. vecValue = m_pParticleSystemPanel->GetControlPointValue( i );
  352. Q_snprintf( pBuf, sizeof(pBuf), "%.3f %.3f %.3f", vecValue.x, vecValue.y, vecValue.z );
  353. m_pControlPointValue[i]->SetText( pBuf );
  354. break;
  355. }
  356. }
  357. //-----------------------------------------------------------------------------
  358. // Called when the particle system changes
  359. //-----------------------------------------------------------------------------
  360. void CControlPointPage::PerformLayout()
  361. {
  362. BaseClass::PerformLayout();
  363. LayoutControlPointControls();
  364. }
  365. //-----------------------------------------------------------------------------
  366. // Creates controls used to modify control point values
  367. //-----------------------------------------------------------------------------
  368. void CControlPointPage::CreateControlPointControls()
  369. {
  370. CleanUpControlPointControls();
  371. CParticleCollection* pParticleSystem = m_pParticleSystemPanel->GetParticleSystem();
  372. if ( !pParticleSystem )
  373. return;
  374. for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
  375. {
  376. if ( !pParticleSystem->ReadsControlPoint( i ) )
  377. continue;
  378. char pName[512];
  379. Q_snprintf( pName, sizeof(pName), "Pt #%d:", i );
  380. m_pControlPointName[i] = new Label( this, pName, pName );
  381. Q_snprintf( pName, sizeof(pName), "Entry #%d:", i );
  382. m_pControlPointValue[i] = new TextEntry( this, pName );
  383. m_pControlPointValue[i]->AddActionSignalTarget( this );
  384. m_pControlPointValue[i]->SendNewLine( true );
  385. m_pControlPointValue[i]->SetMultiline( false );
  386. const Vector &vecValue = m_pParticleSystemPanel->GetControlPointValue( i );
  387. Q_snprintf( pName, sizeof(pName), "%.3f %.3f %.3f", vecValue.x, vecValue.y, vecValue.z );
  388. m_pControlPointValue[i]->SetText( pName );
  389. }
  390. LayoutControlPointControls();
  391. }
  392. //-----------------------------------------------------------------------------
  393. // Lays out the controls
  394. //-----------------------------------------------------------------------------
  395. void CControlPointPage::LayoutControlPointControls()
  396. {
  397. int nFoundControlCount = 0;
  398. for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
  399. {
  400. if ( !m_pControlPointName[i] )
  401. continue;
  402. int yVal = 8 + nFoundControlCount * 28;
  403. m_pControlPointName[i]->SetBounds( 8, yVal, 48, 24 );
  404. m_pControlPointValue[i]->SetBounds( 64, yVal, 160, 24 );
  405. ++nFoundControlCount;
  406. }
  407. }
  408. //-----------------------------------------------------------------------------
  409. // Cleans up controls used to modify control point values
  410. //-----------------------------------------------------------------------------
  411. void CControlPointPage::CleanUpControlPointControls( )
  412. {
  413. for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
  414. {
  415. if ( m_pControlPointName[i] )
  416. {
  417. delete m_pControlPointName[i];
  418. m_pControlPointName[i] = NULL;
  419. }
  420. if ( m_pControlPointValue[i] )
  421. {
  422. delete m_pControlPointValue[i];
  423. m_pControlPointValue[i] = NULL;
  424. }
  425. }
  426. }
  427. //-----------------------------------------------------------------------------
  428. //
  429. // CParticleSystemPreviewPanel
  430. //
  431. //-----------------------------------------------------------------------------
  432. //-----------------------------------------------------------------------------
  433. // Dme panel connection
  434. //-----------------------------------------------------------------------------
  435. IMPLEMENT_DMEPANEL_FACTORY( CParticleSystemPreviewPanel, DmeParticleSystemDefinition, "DmeParticleSystemDefinitionViewer", "Particle System Viewer", false );
  436. //-----------------------------------------------------------------------------
  437. // constructor, destructor
  438. //-----------------------------------------------------------------------------
  439. CParticleSystemPreviewPanel::CParticleSystemPreviewPanel( vgui::Panel *pParent, const char *pName ) :
  440. BaseClass( pParent, pName )
  441. {
  442. m_Splitter = new vgui::Splitter( this, "Splitter", SPLITTER_MODE_VERTICAL, 1 );
  443. vgui::Panel *pSplitterLeftSide = m_Splitter->GetChild( 0 );
  444. vgui::Panel *pSplitterRightSide = m_Splitter->GetChild( 1 );
  445. m_pParticleSystemPanel = new CParticleSystemPanel( pSplitterRightSide, "ParticlePreview" );
  446. m_pParticleSystemPanel->AddActionSignalTarget( this );
  447. m_pParticleSystemPanel->SetBackgroundColor( 0, 0, 0 );
  448. m_pParticleCount = new vgui::Label( pSplitterRightSide, "ParticleCountLabel", "" );
  449. m_pParticleCount->SetZPos( 1 );
  450. m_pControlSheet = new vgui::PropertySheet( pSplitterLeftSide, "ControlSheet" );
  451. m_pRenderPage = new vgui::PropertyPage( m_pControlSheet, "RenderPage" );
  452. m_pRenderBounds = new vgui::CheckButton( m_pRenderPage, "RenderBounds", "Render Bounding Box" );
  453. m_pRenderBounds->AddActionSignalTarget( this );
  454. m_pRenderCullBounds = new vgui::CheckButton( m_pRenderPage, "RenderCullBounds", "Render Culling Bounds" );
  455. m_pRenderCullBounds->AddActionSignalTarget( this );
  456. m_pRenderHelpers = new vgui::CheckButton( m_pRenderPage, "RenderHelpers", "Render Helpers" );
  457. m_pRenderHelpers->AddActionSignalTarget( this );
  458. m_pBackgroundColor = new CColorPickerButton( m_pRenderPage, "BackgroundColor", this );
  459. m_pBackgroundColor->SetColor( m_pParticleSystemPanel->GetBackgroundColor() );
  460. m_pRenderPage->LoadControlSettingsAndUserConfig( "resource/particlesystempreviewpanel_renderpage.res" );
  461. m_pControlPointPage = new CControlPointPage( m_pControlSheet, "ControlPointPage", m_pParticleSystemPanel );
  462. // Load layout settings; has to happen before pinning occurs in code
  463. LoadControlSettingsAndUserConfig( "resource/particlesystempreviewpanel.res" );
  464. // NOTE: Page adding happens *after* LoadControlSettingsAndUserConfig
  465. // because the layout of the sheet is correct at this point.
  466. m_pControlSheet->AddPage( m_pRenderPage, "Render" );
  467. m_pControlSheet->AddPage( m_pControlPointPage, "Ctrl Pts" );
  468. }
  469. CParticleSystemPreviewPanel::~CParticleSystemPreviewPanel()
  470. {
  471. }
  472. //-----------------------------------------------------------------------------
  473. // Set the particle system to draw
  474. //-----------------------------------------------------------------------------
  475. void CParticleSystemPreviewPanel::OnThink()
  476. {
  477. BaseClass::OnThink();
  478. CParticleCollection* pParticleSystem = m_pParticleSystemPanel->GetParticleSystem();
  479. if ( !pParticleSystem )
  480. {
  481. m_pParticleCount->SetText( "" );
  482. }
  483. else
  484. {
  485. char buf[256];
  486. Q_snprintf( buf, sizeof(buf), "Particle Count: %5d/%5d",
  487. pParticleSystem->m_nActiveParticles, pParticleSystem->m_nAllocatedParticles );
  488. m_pParticleCount->SetText( buf );
  489. }
  490. }
  491. //-----------------------------------------------------------------------------
  492. // Called when the particle system changes
  493. //-----------------------------------------------------------------------------
  494. void CParticleSystemPreviewPanel::OnParticleSystemReconstructed()
  495. {
  496. m_pControlPointPage->CreateControlPointControls();
  497. }
  498. //-----------------------------------------------------------------------------
  499. // Set the particle system to draw
  500. //-----------------------------------------------------------------------------
  501. void CParticleSystemPreviewPanel::SetParticleSystem( CDmeParticleSystemDefinition *pDef )
  502. {
  503. m_pParticleSystemPanel->SetParticleSystem( pDef );
  504. }
  505. void CParticleSystemPreviewPanel::SetDmeElement( CDmeParticleSystemDefinition *pDef )
  506. {
  507. m_pParticleSystemPanel->SetDmeElement( pDef );
  508. }
  509. //-----------------------------------------------------------------------------
  510. // Indicates which helper to draw
  511. //-----------------------------------------------------------------------------
  512. void CParticleSystemPreviewPanel::SetParticleFunction( CDmeParticleFunction *pFunction )
  513. {
  514. m_pParticleSystemPanel->SetRenderedHelper( pFunction );
  515. }
  516. //-----------------------------------------------------------------------------
  517. // Called when the check button is checked
  518. //-----------------------------------------------------------------------------
  519. void CParticleSystemPreviewPanel::OnCheckButtonChecked( KeyValues *pParams )
  520. {
  521. int state = pParams->GetInt( "state", 0 );
  522. vgui::Panel *pPanel = (vgui::Panel*)pParams->GetPtr( "panel" );
  523. if ( pPanel == m_pRenderBounds )
  524. {
  525. m_pParticleSystemPanel->RenderBounds( state );
  526. return;
  527. }
  528. if ( pPanel == m_pRenderCullBounds )
  529. {
  530. m_pParticleSystemPanel->RenderCullBounds( state );
  531. return;
  532. }
  533. if ( pPanel == m_pRenderHelpers )
  534. {
  535. m_pParticleSystemPanel->RenderHelpers( state );
  536. return;
  537. }
  538. }
  539. //-----------------------------------------------------------------------------
  540. // Called when a new background color is picked
  541. //-----------------------------------------------------------------------------
  542. void CParticleSystemPreviewPanel::OnBackgroundColorChanged( KeyValues *pParams )
  543. {
  544. m_pParticleSystemPanel->SetBackgroundColor( pParams->GetColor( "color" ) );
  545. }
  546. void CParticleSystemPreviewPanel::OnBackgroundColorPreview( KeyValues *pParams )
  547. {
  548. m_pParticleSystemPanel->SetBackgroundColor( pParams->GetColor( "color" ) );
  549. }
  550. void CParticleSystemPreviewPanel::OnBackgroundColorCancel( KeyValues *pParams )
  551. {
  552. m_pParticleSystemPanel->SetBackgroundColor( pParams->GetColor( "startingColor" ) );
  553. }