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.

1533 lines
40 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "dme_controls/BaseAnimSetAttributeSliderPanel.h"
  7. #include "movieobjects/dmechannel.h"
  8. #include "movieobjects/dmeanimationset.h"
  9. #include "vgui_controls/TextImage.h"
  10. #include "vgui_controls/Button.h"
  11. #include "vgui_controls/Slider.h"
  12. #include "vgui_controls/PanelListPanel.h"
  13. #include "dme_controls/BaseAnimSetPresetFaderPanel.h"
  14. #include "dme_controls/BaseAnimationSetEditor.h"
  15. #include "dme_controls/attributeslider.h"
  16. #include "vgui/ISurface.h"
  17. #include "vgui/ISystem.h"
  18. #include "vgui/IInput.h"
  19. // memdbgon must be the last include file in a .cpp file!!!
  20. #include "tier0/memdbgon.h"
  21. using namespace vgui;
  22. #define ANIMATION_SET_EDITOR_ATTRIBUTESLIDERS_BUTTONTRAY_HEIGHT 32
  23. #define ANIMATION_SET_EDITOR_ATTRIBUTESLIDERS_BUTTONTRAY_YPOS 0
  24. //-----------------------------------------------------------------------------
  25. // Enums
  26. //-----------------------------------------------------------------------------
  27. #define SLIDER_PIXEL_SPACING 3
  28. #define RECOMPUTE_PREVIEW_INTERVAL ( 0.5f )
  29. #define CIRCULAR_CONTROL_RADIUS 6.0f
  30. #define FRAC_PER_PIXEL 0.0025f
  31. static ConVar ifm_attributesliderbalance_sensitivity( "ifm_attributesliderbalance_sensitivity", "1.0", 0 );
  32. extern float ifm_fader_timescale;
  33. enum
  34. {
  35. // Just some arbitrary number that we're not likely to see in another .lib or the main app's code
  36. UNDO_CHAIN_MOUSEWHEEL_ATTRIBUTE_SLIDER = 9876,
  37. };
  38. bool CBaseAnimSetAttributeSliderPanel::ChannelToSliderLookup_t::Less( const ChannelToSliderLookup_t& lhs, const ChannelToSliderLookup_t& rhs )
  39. {
  40. return lhs.ch.Get() < rhs.ch.Get();
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Blends flex values in left-right space instead of balance/value space
  44. //-----------------------------------------------------------------------------
  45. static void BlendFlexValues( AttributeValue_t *pResult, const AttributeValue_t &src, const AttributeValue_t &dest, float flBlend, float flBalanceFilter = 0.5f )
  46. {
  47. // Apply the left-right balance to the target
  48. float flLeftFilter, flRightFilter;
  49. ValueBalanceToLeftRight( &flLeftFilter, &flRightFilter, flBlend, flBalanceFilter );
  50. // Do the math in 'left-right' space because we filter in that space
  51. float flSrcLeft, flSrcRight;
  52. ValueBalanceToLeftRight( &flSrcLeft, &flSrcRight, src.m_pValue[ANIM_CONTROL_VALUE], src.m_pValue[ANIM_CONTROL_BALANCE] );
  53. float flDestLeft, flDestRight;
  54. ValueBalanceToLeftRight( &flDestLeft, &flDestRight, dest.m_pValue[ANIM_CONTROL_VALUE], dest.m_pValue[ANIM_CONTROL_BALANCE] );
  55. float flTargetLeft = flSrcLeft + flLeftFilter * ( flDestLeft - flSrcLeft );
  56. float flTargetRight = flSrcRight + flRightFilter * ( flDestRight - flSrcRight );
  57. LeftRightToValueBalance( &pResult->m_pValue[ANIM_CONTROL_VALUE], &pResult->m_pValue[ANIM_CONTROL_BALANCE], flTargetLeft, flTargetRight,
  58. ( flBlend <= 0.5f ) ? src.m_pValue[ANIM_CONTROL_BALANCE] : dest.m_pValue[ANIM_CONTROL_BALANCE] );
  59. pResult->m_pValue[ANIM_CONTROL_MULTILEVEL] = src.m_pValue[ANIM_CONTROL_MULTILEVEL] + ( dest.m_pValue[ANIM_CONTROL_MULTILEVEL] - src.m_pValue[ANIM_CONTROL_MULTILEVEL] ) * flBlend;
  60. }
  61. //-----------------------------------------------------------------------------
  62. //
  63. // CPresetSideFilterSlider class begins
  64. //
  65. //-----------------------------------------------------------------------------
  66. class CPresetSideFilterSlider : public Slider
  67. {
  68. DECLARE_CLASS_SIMPLE( CPresetSideFilterSlider, Slider );
  69. public:
  70. CPresetSideFilterSlider( CBaseAnimSetAttributeSliderPanel *pParent, const char *panelName );
  71. virtual ~CPresetSideFilterSlider();
  72. float GetPos();
  73. void SetPos( float frac );
  74. protected:
  75. virtual void Paint();
  76. virtual void PaintBackground();
  77. virtual void ApplySchemeSettings( IScheme *scheme );
  78. virtual void GetTrackRect( int &x, int &y, int &w, int &h );
  79. virtual void OnMousePressed(MouseCode code);
  80. virtual void OnMouseDoublePressed(MouseCode code);
  81. private:
  82. CBaseAnimSetAttributeSliderPanel *m_pParent;
  83. Color m_ZeroColor;
  84. Color m_TextColor;
  85. Color m_TextColorFocus;
  86. TextImage *m_pName;
  87. float m_flCurrent;
  88. };
  89. //-----------------------------------------------------------------------------
  90. // Constructor, destructor
  91. //-----------------------------------------------------------------------------
  92. CPresetSideFilterSlider::CPresetSideFilterSlider( CBaseAnimSetAttributeSliderPanel *parent, const char *panelName ) :
  93. BaseClass( (Panel *)parent, panelName ), m_pParent( parent )
  94. {
  95. SetRange( 0, 1000 );
  96. SetDragOnRepositionNob( true );
  97. SetPos( 0.5f );
  98. SetPaintBackgroundEnabled( true );
  99. m_pName = new TextImage( "Preset Side Filter" );
  100. SetBgColor( Color( 128, 128, 128, 128 ) );
  101. m_ZeroColor = Color( 33, 33, 33, 255 );
  102. m_TextColor = Color( 200, 200, 200, 255 );
  103. m_TextColorFocus = Color( 208, 143, 40, 255 );
  104. }
  105. CPresetSideFilterSlider::~CPresetSideFilterSlider()
  106. {
  107. delete m_pName;
  108. }
  109. void CPresetSideFilterSlider::OnMousePressed(MouseCode code)
  110. {
  111. if ( code == MOUSE_RIGHT )
  112. {
  113. SetPos( 0.5f );
  114. return;
  115. }
  116. BaseClass::OnMousePressed( code );
  117. }
  118. void CPresetSideFilterSlider::OnMouseDoublePressed(MouseCode code)
  119. {
  120. if ( code == MOUSE_LEFT )
  121. {
  122. SetPos( 0.5f );
  123. return;
  124. }
  125. BaseClass::OnMouseDoublePressed( code );
  126. }
  127. float CPresetSideFilterSlider::GetPos()
  128. {
  129. return GetValue() * 0.001f;
  130. }
  131. void CPresetSideFilterSlider::SetPos( float frac )
  132. {
  133. SetValue( (int)( frac * 1000.0f + 0.5f ), false );
  134. }
  135. void CPresetSideFilterSlider::ApplySchemeSettings( IScheme *scheme )
  136. {
  137. BaseClass::ApplySchemeSettings( scheme );
  138. m_pName->SetFont( scheme->GetFont( "DefaultBold" ) );
  139. m_pName->SetColor( m_TextColor );
  140. m_pName->ResizeImageToContent();
  141. SetFgColor( Color( 194, 120, 0, 255 ) );
  142. SetThumbWidth( 3 );
  143. }
  144. void CPresetSideFilterSlider::GetTrackRect( int &x, int &y, int &w, int &h )
  145. {
  146. GetSize( w, h );
  147. x = 0;
  148. y = 2;
  149. h -= 4;
  150. }
  151. void CPresetSideFilterSlider::Paint()
  152. {
  153. // horizontal nob
  154. int x, y;
  155. int wide,tall;
  156. GetTrackRect( x, y, wide, tall );
  157. Color col = GetFgColor();
  158. surface()->DrawSetColor( col );
  159. surface()->DrawFilledRect( _nobPos[0], 1, _nobPos[1], GetTall() - 1 );
  160. surface()->DrawSetColor( m_ZeroColor );
  161. surface()->DrawFilledRect( _nobPos[0] - 1, y + 1, _nobPos[0], y + tall - 1 );
  162. }
  163. void CPresetSideFilterSlider::PaintBackground()
  164. {
  165. int w, h;
  166. GetSize( w, h );
  167. int tx, ty, tw, th;
  168. GetTrackRect( tx, ty, tw, th );
  169. surface()->DrawSetColor( m_ZeroColor );
  170. surface()->DrawFilledRect( tx, ty, tx + tw, ty + th );
  171. int cw, ch;
  172. m_pName->SetColor( _dragging ? m_TextColorFocus : m_TextColor );
  173. m_pName->GetContentSize( cw, ch );
  174. m_pName->SetPos( ( w - cw ) * 0.5f, ( h - ch ) * 0.5f );
  175. m_pName->Paint();
  176. }
  177. //-----------------------------------------------------------------------------
  178. //
  179. // CBaseAnimSetAttributeSliderPanel begins
  180. //
  181. //-----------------------------------------------------------------------------
  182. CBaseAnimSetAttributeSliderPanel::CBaseAnimSetAttributeSliderPanel( vgui::Panel *parent, const char *className, CBaseAnimationSetEditor *editor ) :
  183. BaseClass( parent, className ),
  184. m_flEstimatedValue( 0.0f ),
  185. m_ChannelToSliderLookup( 0, 0, ChannelToSliderLookup_t::Less ),
  186. m_flRecomputePreviewTime( -1.0f ),
  187. m_bRequestedNewPreview( false ),
  188. m_flPrevTime( 0.0f ),
  189. m_nFaderChangeFlags( 0 )
  190. {
  191. m_hEditor = editor;
  192. m_pLeftRightBoth[ 0 ] = new Button( this, "AttributeSliderLeftOnly", "", this, "OnLeftOnly" );
  193. m_pLeftRightBoth[ 1 ] = new Button( this, "AttributeSliderRightOnly", "", this, "OnRightOnly" );
  194. m_pPresetSideFilter = new CPresetSideFilterSlider( this, "PresetSideFilter" );
  195. m_Sliders = new PanelListPanel( this, "AttributeSliders" );
  196. m_Sliders->SetFirstColumnWidth( 0 );
  197. m_Sliders->SetAutoResize
  198. (
  199. Panel::PIN_TOPLEFT,
  200. Panel::AUTORESIZE_DOWNANDRIGHT,
  201. 0, ANIMATION_SET_EDITOR_ATTRIBUTESLIDERS_BUTTONTRAY_HEIGHT,
  202. 0, 0
  203. );
  204. m_Sliders->SetVerticalBufferPixels( 0 );
  205. m_PreviousPreviewFader = "";
  206. m_Previous.isbeingdragged = false;
  207. m_Previous.holdingctrl = false;
  208. m_Previous.amount = 0.0f;
  209. }
  210. void CBaseAnimSetAttributeSliderPanel::OnCommand( const char *pCommand )
  211. {
  212. if ( !Q_stricmp( pCommand, "OnLeftOnly" ) )
  213. {
  214. m_pPresetSideFilter->SetPos( 0.0f );
  215. return;
  216. }
  217. if ( !Q_stricmp( pCommand, "OnRightOnly" ) )
  218. {
  219. m_pPresetSideFilter->SetPos( 1.0f );
  220. return;
  221. }
  222. BaseClass::OnCommand( pCommand );
  223. }
  224. void CBaseAnimSetAttributeSliderPanel::StampValueIntoLogs( CDmElement *control, AnimationControlType_t type, float flValue )
  225. {
  226. }
  227. void CBaseAnimSetAttributeSliderPanel::ApplySchemeSettings( IScheme *scheme )
  228. {
  229. BaseClass::ApplySchemeSettings( scheme );
  230. m_Sliders->SetBgColor( Color( 42, 42, 42, 255 ) );
  231. }
  232. void CBaseAnimSetAttributeSliderPanel::PerformLayout()
  233. {
  234. BaseClass::PerformLayout();
  235. int w, h;
  236. GetSize( w, h );
  237. int availH = ANIMATION_SET_EDITOR_ATTRIBUTESLIDERS_BUTTONTRAY_HEIGHT;
  238. int btnSize = 9;
  239. m_pLeftRightBoth[ 0 ]->SetBounds( 15, ( availH - btnSize ) / 2, btnSize, btnSize );
  240. m_pLeftRightBoth[ 1 ]->SetBounds( w - 15, ( availH - btnSize ) / 2, btnSize, btnSize );
  241. m_pPresetSideFilter->SetBounds( 23 + btnSize, 4, w - 38 - 2 * btnSize, availH - 8 );
  242. }
  243. //-----------------------------------------------------------------------------
  244. // Purpose: Determines:
  245. // a) are we holding the ctrl key still, if so
  246. // figures out the crossfade amount of each preset slider with non-zero influence
  247. // b) not holding control, then just see if we are previewing whichever preset the mouse is over
  248. // Input : -
  249. //-----------------------------------------------------------------------------
  250. void CBaseAnimSetAttributeSliderPanel::OnThink()
  251. {
  252. BaseClass::OnThink();
  253. CBaseAnimSetPresetFaderPanel *presets = m_hEditor->GetPresetFader();
  254. if ( !presets )
  255. return;
  256. FaderPreview_t fader;
  257. presets->GetPreviewFader( fader );
  258. bool nameChanged = ( fader.name && ( m_PreviousPreviewFader.IsEmpty() || Q_stricmp( m_PreviousPreviewFader.Get(), fader.name ) ) ) ? true : false;
  259. bool beingDraggedChanged = fader.isbeingdragged != m_Previous.isbeingdragged ? true : false;
  260. bool ctrlKeyChanged = fader.holdingctrl != m_Previous.holdingctrl ? true : false;
  261. bool bFaderChanged = ( nameChanged || beingDraggedChanged || ctrlKeyChanged );
  262. bool bPresetChanged = fader.preset != m_Previous.preset;
  263. bool faderAmountChanged = fader.amount != m_Previous.amount ? true : false;
  264. m_nFaderChangeFlags = 0;
  265. if ( nameChanged )
  266. {
  267. m_nFaderChangeFlags |= FADER_NAME_CHANGED;
  268. }
  269. if ( beingDraggedChanged )
  270. {
  271. m_nFaderChangeFlags |= FADER_DRAG_CHANGED;
  272. }
  273. if ( ctrlKeyChanged )
  274. {
  275. m_nFaderChangeFlags |= FADER_CTRLKEY_CHANGED;
  276. }
  277. if ( faderAmountChanged )
  278. {
  279. m_nFaderChangeFlags |= FADER_AMOUNT_CHANGED;
  280. }
  281. if ( bPresetChanged )
  282. {
  283. m_nFaderChangeFlags |= FADER_PRESET_CHANGED;
  284. }
  285. m_PreviousPreviewFader = fader.name;
  286. m_Previous = fader;
  287. int c = m_SliderList.Count();
  288. for ( int i = 0; i < c; ++i )
  289. {
  290. CAttributeSlider *slider = m_SliderList[ i ];
  291. slider->EnablePreview( false, false, false );
  292. if ( !slider->IsVisible() )
  293. continue;
  294. if ( !slider->GetControl() )
  295. continue;
  296. const char *name = slider->GetName();
  297. Assert( name );
  298. if ( m_CtrlKeyPreviewSlider.Get() == slider )
  299. {
  300. // The preset stuff shouldn't be active when we're holding ctrl over the raw attribute sliders!!!
  301. Assert( !fader.isbeingdragged );
  302. m_CtrlKeyPreviewSliderElement = NULL;
  303. m_CtrlKeyPreviewSlider = NULL;
  304. AttributeValue_t dest;
  305. if ( !slider->IsTransform() )
  306. {
  307. dest.m_pValue[ ANIM_CONTROL_VALUE ] = m_flEstimatedValue;
  308. dest.m_pValue[ ANIM_CONTROL_BALANCE ] = slider->GetValue( ANIM_CONTROL_BALANCE );
  309. dest.m_pValue[ ANIM_CONTROL_MULTILEVEL ] = slider->GetValue( ANIM_CONTROL_MULTILEVEL );
  310. }
  311. else
  312. {
  313. dest.m_pValue[ ANIM_CONTROL_VALUE ] = 0.0f;
  314. dest.m_pValue[ ANIM_CONTROL_BALANCE ] = 0.5f;
  315. dest.m_pValue[ ANIM_CONTROL_MULTILEVEL ] = 0.5f;
  316. }
  317. // If we aren't over any of the preset sliders, then we need to be able to ramp down to the current value, too
  318. slider->EnablePreview( true, false, false );
  319. slider->SetPreview( dest, dest, true, true );
  320. continue;
  321. }
  322. if ( !fader.values )
  323. continue;
  324. AttributeValue_t preview;
  325. preview.m_pValue[ ANIM_CONTROL_VALUE ] = slider->IsTransform() ? 0.0f : slider->GetControlDefaultValue( ANIM_CONTROL_VALUE );
  326. preview.m_pValue[ ANIM_CONTROL_BALANCE ] = 0.5f;
  327. preview.m_pValue[ ANIM_CONTROL_MULTILEVEL ] = 0.5f;
  328. AttributeValue_t current = slider->GetValue();
  329. int idx = fader.values->Find( name );
  330. if ( idx != fader.values->InvalidIndex() )
  331. {
  332. preview = (*fader.values)[ idx ];
  333. }
  334. BlendFlexValues( &preview, current, preview, 1.0f, slider->IsControlActive( ANIM_CONTROL_BALANCE ) ? m_pPresetSideFilter->GetPos() : 0.5f );
  335. bool simple = fader.isbeingdragged || ( !fader.holdingctrl && !slider->IsRampingTowardPreview() && !ctrlKeyChanged );
  336. slider->EnablePreview( true, simple, fader.isbeingdragged );
  337. if ( bFaderChanged || fader.isbeingdragged )
  338. {
  339. // If being dragged, slam to current value right away
  340. if ( simple )
  341. {
  342. slider->SetPreview( preview, preview, true, true );
  343. }
  344. else
  345. {
  346. // For the "ramp down" case (just released ctrl key), we need the original values instead of the preview valuees
  347. if ( ctrlKeyChanged && !fader.holdingctrl && slider->IsRampingTowardPreview() )
  348. {
  349. Assert( !fader.isbeingdragged );
  350. slider->RampDown();
  351. }
  352. else
  353. {
  354. // Apply the left-right balance to the target
  355. AttributeValue_t dest;
  356. BlendFlexValues( &dest, current, preview, fader.amount );
  357. slider->SetPreview( dest, preview, !fader.holdingctrl, !nameChanged );
  358. }
  359. }
  360. }
  361. if ( faderAmountChanged || fader.isbeingdragged || fader.holdingctrl )
  362. {
  363. slider->UpdateFaderAmount( fader.amount );
  364. }
  365. }
  366. UpdatePreviewSliderTimes();
  367. ApplySliderValues( false );
  368. PerformRecomputePreview();
  369. }
  370. void CBaseAnimSetAttributeSliderPanel::ChangeAnimationSet( CDmeAnimationSet *newAnimSet )
  371. {
  372. int i;
  373. // Force recomputation
  374. m_nActiveControlSetMode = -1;
  375. bool rebuild = true;
  376. if ( m_AnimSet.Get() && newAnimSet == m_AnimSet )
  377. {
  378. // See if every slider is the same as before
  379. const CDmaElementArray< CDmElement > &controls = m_AnimSet->GetControls();
  380. int controlCount = controls.Count();
  381. if ( m_SliderList.Count() == controlCount )
  382. {
  383. rebuild = false;
  384. for ( i = 0 ; i < controlCount; ++i )
  385. {
  386. CDmElement *control = controls[ i ];
  387. if ( !control )
  388. continue;
  389. if ( Q_stricmp( control->GetName(), m_SliderList[ i ]->GetName() ) )
  390. {
  391. rebuild = true;
  392. break;
  393. }
  394. bool bStereo = control->GetValue< bool >( "combo" );
  395. bool bIsMulti = control->GetValue< bool >( "multi" );
  396. if ( m_SliderList[ i ]->IsControlActive( ANIM_CONTROL_BALANCE ) != bStereo ||
  397. m_SliderList[ i ]->IsControlActive( ANIM_CONTROL_MULTILEVEL ) != bIsMulti )
  398. {
  399. rebuild = true;
  400. break;
  401. }
  402. }
  403. }
  404. }
  405. m_AnimSet = newAnimSet;
  406. if ( !m_AnimSet.Get() )
  407. return;
  408. if ( !rebuild )
  409. return;
  410. int c = m_SliderList.Count();
  411. for ( i = 0 ; i < c; ++i )
  412. {
  413. delete m_SliderList[ i ];
  414. }
  415. m_SliderList.RemoveAll();
  416. m_Sliders->RemoveAll();
  417. m_ChannelToSliderLookup.Purge();
  418. const CDmaElementArray< CDmElement > &controls = m_AnimSet->GetControls();
  419. // Now create sliders for all known controls, nothing visible by default
  420. int controlCount = controls.Count();
  421. for ( i = 0 ; i < controlCount; ++i )
  422. {
  423. CDmElement *control = controls[ i ];
  424. if ( !control )
  425. continue;
  426. CAttributeSlider *slider = new CAttributeSlider( this, control->GetName(), control );
  427. slider->SetVisible( false );
  428. slider->SetValue( ANIM_CONTROL_VALUE, control->GetValue< float >( "value" ) );
  429. slider->SetSize( 100, 20 );
  430. bool bStereo = control->GetValue< bool >( "combo" );
  431. slider->ActivateControl( ANIM_CONTROL_BALANCE, bStereo );
  432. if ( bStereo )
  433. {
  434. slider->SetValue( ANIM_CONTROL_BALANCE, control->GetValue< float >( "balance" ) );
  435. }
  436. bool bMulti = control->GetValue< bool >( "multi" );
  437. slider->ActivateControl( ANIM_CONTROL_MULTILEVEL, bMulti );
  438. if ( bMulti )
  439. {
  440. slider->SetValue( ANIM_CONTROL_MULTILEVEL, control->GetValue< float >( "multilevel" ) );
  441. }
  442. m_SliderList.AddToTail( slider );
  443. ChannelToSliderLookup_t lookup;
  444. lookup.slider = control;
  445. CDmeChannel *ctrlChannels[ LOG_PREVIEW_MAX_CHANNEL_COUNT ];
  446. GetChannelsForControl( control, ctrlChannels );
  447. for ( int j = 0 ; j < LOG_PREVIEW_MAX_CHANNEL_COUNT; ++j )
  448. {
  449. lookup.ch = ctrlChannels[ j ];
  450. lookup.type = (AnimationControlType_t)j;
  451. if ( lookup.ch )
  452. {
  453. Assert( m_ChannelToSliderLookup.Find( lookup) == m_ChannelToSliderLookup.InvalidIndex() );
  454. m_ChannelToSliderLookup.Insert( lookup );
  455. }
  456. }
  457. }
  458. RecomputePreview();
  459. }
  460. void CBaseAnimSetAttributeSliderPanel::SetVisibleControlsForSelectionGroup( CUtlSymbolTable& visible )
  461. {
  462. int i, c;
  463. bool changed = false;
  464. // Walk through all sliders and show only those in the symbol table
  465. c = m_SliderList.Count();
  466. for ( i = 0; i < c; ++i )
  467. {
  468. CAttributeSlider *slider = m_SliderList[ i ];
  469. const char *sliderName = slider->GetName();
  470. bool showSlider = visible.Find( sliderName ) != UTL_INVAL_SYMBOL ? true : false;
  471. if ( slider->IsVisible() != showSlider )
  472. {
  473. changed = true;
  474. break;
  475. }
  476. }
  477. if ( !changed )
  478. return;
  479. m_Sliders->RemoveAll();
  480. c = m_SliderList.Count();
  481. for ( i = 0; i < c; ++i )
  482. {
  483. CAttributeSlider *slider = m_SliderList[ i ];
  484. const char *sliderName = slider->GetName();
  485. if ( visible.Find( sliderName ) != UTL_INVAL_SYMBOL )
  486. {
  487. slider->SetVisible( true );
  488. m_Sliders->AddItem( NULL, slider );
  489. }
  490. else
  491. {
  492. slider->SetVisible( false );
  493. }
  494. }
  495. // Force mode to recompute
  496. m_nActiveControlSetMode = -1;
  497. RecomputePreview();
  498. }
  499. void CBaseAnimSetAttributeSliderPanel::ApplyPreset( float flScale, AttributeDict_t& values )
  500. {
  501. int c = m_SliderList.Count();
  502. for ( int i = 0; i < c; ++i )
  503. {
  504. CAttributeSlider *slider = m_SliderList[ i ];
  505. if ( !slider || !slider->IsVisible() )
  506. continue;
  507. if ( slider->IsTransform() )
  508. continue;
  509. AttributeValue_t current, target;
  510. current = slider->GetValue( );
  511. target.m_pValue[ ANIM_CONTROL_VALUE ] = slider->GetControlDefaultValue( ANIM_CONTROL_VALUE );
  512. target.m_pValue[ ANIM_CONTROL_BALANCE ] = 0.5f;
  513. target.m_pValue[ ANIM_CONTROL_MULTILEVEL ] = 0.5f;
  514. const char *name = slider->GetName();
  515. int idx = name ? values.Find( name ) : values.InvalidIndex();
  516. if ( idx != values.InvalidIndex() )
  517. {
  518. target = values[ idx ];
  519. }
  520. // Apply the left-right balance to the target
  521. AttributeValue_t blend;
  522. BlendFlexValues( &blend, current, target, flScale, slider->IsControlActive( ANIM_CONTROL_BALANCE ) ? m_pPresetSideFilter->GetPos() : 0.5f );
  523. slider->SetValue( blend );
  524. }
  525. }
  526. static const char *s_pAnimControlAttribute[ANIM_CONTROL_COUNT] =
  527. {
  528. "value", "balance", "multilevel"
  529. };
  530. bool CBaseAnimSetAttributeSliderPanel::ApplySliderValues( bool bForce )
  531. {
  532. if ( !m_AnimSet.Get() )
  533. return false;
  534. if ( !bForce )
  535. {
  536. bForce = m_Previous.isbeingdragged;
  537. }
  538. const CDmaElementArray< CDmElement > &controls = m_AnimSet->GetControls();
  539. bool valuesChanged = false;
  540. CDisableUndoScopeGuard guard;
  541. int c = m_SliderList.Count();
  542. for ( int i = 0; i < c; ++i )
  543. {
  544. CAttributeSlider *pSlider = m_SliderList[ i ];
  545. if ( !pSlider->IsVisible() )
  546. continue;
  547. CDmElement *pControl = controls[ i ];
  548. if ( !pControl )
  549. continue;
  550. // Skip these types of sliders...
  551. if ( pControl->GetValue< bool >( "transform" ) )
  552. continue;
  553. CDmeChannel *ctrlChannels[ LOG_PREVIEW_MAX_CHANNEL_COUNT ];
  554. GetChannelsForControl( pControl, ctrlChannels );
  555. bool bUsePreviewValue = pSlider->IsPreviewEnabled() && ( !pSlider->IsSimplePreview() || bForce );
  556. for ( int j = 0; j < LOG_PREVIEW_MAX_CHANNEL_COUNT; ++j )
  557. {
  558. AnimationControlType_t type = (AnimationControlType_t)j;
  559. CDmeChannel *pChannel = ctrlChannels[ j ];
  560. // Figure out what to do based on the channel's mode
  561. ChannelMode_t mode = pChannel ? pChannel->GetMode() : CM_PASS;
  562. bool bPushSlidersIntoScene = ( mode == CM_PASS || mode == CM_RECORD );
  563. bool bPullSlidersFromScene = ( mode == CM_PLAY );
  564. if ( bPullSlidersFromScene )
  565. {
  566. Assert( pChannel );
  567. // If it's actively being manipulated, the UI will be up to date
  568. if ( pSlider->GetDragControl() == type )
  569. continue;
  570. // If we're dragging value, we're now going to be changing balance as well
  571. if ( pSlider->GetDragControl() == ANIM_CONTROL_VALUE && type == ANIM_CONTROL_BALANCE )
  572. continue;
  573. // Drive value setting based on the output data
  574. // NOTE: GetCurrentPlaybackValue might not overwrite flValue.
  575. float flValue = pSlider->GetControlDefaultValue( type );
  576. pChannel->GetCurrentPlaybackValue< float >( flValue );
  577. pSlider->SetValue( type, flValue );
  578. pControl->SetValue< float >( s_pAnimControlAttribute[type], flValue );
  579. }
  580. else if ( bPushSlidersIntoScene )
  581. {
  582. float flValue = bUsePreviewValue ? pSlider->GetPreview( type ) : pSlider->GetValue( type );
  583. if ( pControl->GetValue< float >( s_pAnimControlAttribute[type] ) != flValue || bForce )
  584. {
  585. valuesChanged = true;
  586. pControl->SetValue< float >( s_pAnimControlAttribute[type], flValue );
  587. }
  588. }
  589. }
  590. }
  591. guard.Release();
  592. return valuesChanged;
  593. }
  594. void CBaseAnimSetAttributeSliderPanel::UpdatePreviewSliderTimes()
  595. {
  596. if ( !m_AnimSet.Get() )
  597. return;
  598. const CDmaElementArray< CDmElement > &controls = m_AnimSet->GetControls();
  599. float curtime = system()->GetFrameTime();
  600. float dt = clamp( curtime - m_flPrevTime, 0.0f, 0.1f );
  601. m_flPrevTime = curtime;
  602. dt *= ifm_fader_timescale;
  603. bool previewing = false;
  604. bool changingvalues = false;
  605. bool ctrlDown = input()->IsKeyDown( KEY_LCONTROL ) || input()->IsKeyDown( KEY_RCONTROL );
  606. int mx, my;
  607. input()->GetCursorPos( mx, my );
  608. if ( ctrlDown )
  609. {
  610. bool bInside = m_Sliders->IsWithin( mx, my );
  611. if ( !bInside )
  612. {
  613. ctrlDown = false;
  614. }
  615. VPANEL topMost = input()->GetMouseOver();
  616. if ( topMost && !ipanel()->HasParent( topMost, GetVPanel() ) )
  617. {
  618. ctrlDown = false;
  619. }
  620. }
  621. CAttributeSlider *dragSlider = NULL;
  622. CDmElement *dragSliderElement = NULL;
  623. m_CtrlKeyPreviewSliderElement = NULL;
  624. m_CtrlKeyPreviewSlider = NULL;
  625. m_flEstimatedValue = 0.0f;
  626. int c = m_SliderList.Count();
  627. for ( int i = 0; i < c; ++i )
  628. {
  629. CAttributeSlider *slider = m_SliderList[ i ];
  630. slider->UpdateTime( dt );
  631. if ( !slider->IsVisible() )
  632. continue;
  633. bool ctrlDownOnThisSlider = false;
  634. if ( ctrlDown )
  635. {
  636. int x, y;
  637. x = mx;
  638. y = my;
  639. slider->ScreenToLocal( x, y );
  640. int sw, st;
  641. slider->GetSize( sw, st );
  642. if ( x >= 0 && x < sw && y >= 0 && y < st )
  643. {
  644. // Should only hit one slider!!!
  645. Assert( !ctrlDownOnThisSlider );
  646. ctrlDownOnThisSlider = true;
  647. if ( !slider->IsTransform() )
  648. {
  649. m_flEstimatedValue = slider->EstimateValueAtPos( x, y );
  650. }
  651. }
  652. }
  653. if ( slider->IsPreviewEnabled() )
  654. {
  655. if ( !slider->IsSimplePreview() )
  656. {
  657. previewing = true;
  658. }
  659. }
  660. // If a fader is being dragged, or we're directly manipulating the slider, then we are going to put
  661. // this slider into record mode
  662. if ( slider->IsFaderBeingDragged() )
  663. {
  664. changingvalues = true;
  665. Assert( !dragSlider );
  666. dragSlider = NULL;
  667. dragSliderElement = NULL;
  668. }
  669. else if ( slider->IsDragging() )
  670. {
  671. Assert( !dragSlider );
  672. dragSlider = slider;
  673. dragSliderElement = controls[ i ];
  674. changingvalues = true;
  675. }
  676. if ( ctrlDownOnThisSlider )
  677. {
  678. m_CtrlKeyPreviewSliderElement = controls[ i ];
  679. m_CtrlKeyPreviewSlider = slider;
  680. }
  681. }
  682. switch ( m_hEditor->GetRecordingState() )
  683. {
  684. default:
  685. Assert( 0 );
  686. break;
  687. case AS_OFF:
  688. {
  689. ActivateControlSetInMode( CM_OFF, CM_OFF, CM_OFF, NULL );
  690. }
  691. break;
  692. case AS_RECORD:
  693. {
  694. // Put one or all things into record mode (if dragging a single slider, other channels should be in playback mode)
  695. if ( changingvalues || previewing )
  696. {
  697. ActivateControlSetInMode( changingvalues ? CM_RECORD : CM_PASS, CM_PLAY, CM_PLAY, dragSlider );
  698. }
  699. else
  700. {
  701. ActivateControlSetInMode( CM_PLAY, CM_PLAY, CM_PLAY, dragSlider );
  702. }
  703. }
  704. break;
  705. case AS_PLAYBACK:
  706. {
  707. // Put things into playback, except if dragging a slider, to preview
  708. if ( changingvalues || previewing )
  709. {
  710. ActivateControlSetInMode( CM_PASS, CM_PLAY, CM_PLAY, NULL );
  711. }
  712. else
  713. {
  714. ActivateControlSetInMode( CM_PLAY, CM_PLAY, CM_PLAY, NULL );
  715. }
  716. }
  717. break;
  718. case AS_PREVIEW:
  719. {
  720. // Put things into passthru
  721. ActivateControlSetInMode( CM_PASS, CM_PASS, CM_PLAY, NULL );
  722. }
  723. break;
  724. }
  725. if ( dragSliderElement )
  726. {
  727. SetLogPreviewControl( dragSliderElement );
  728. }
  729. else if ( m_CtrlKeyPreviewSliderElement.Get() )
  730. {
  731. SetLogPreviewControl( m_CtrlKeyPreviewSliderElement );
  732. }
  733. }
  734. bool CBaseAnimSetAttributeSliderPanel::GetAttributeSliderValue( AttributeValue_t *pValue, const char *name )
  735. {
  736. int c = m_SliderList.Count();
  737. for ( int i = 0; i < c; ++i )
  738. {
  739. CAttributeSlider *slider = m_SliderList[ i ];
  740. if ( Q_stricmp( slider->GetName(), name ) )
  741. continue;
  742. *pValue = slider->GetValue( );
  743. return true;
  744. }
  745. return false;
  746. }
  747. void CBaseAnimSetAttributeSliderPanel::GetChannelsForControl( CDmElement *control, CDmeChannel *channels[LOG_PREVIEW_MAX_CHANNEL_COUNT] )
  748. {
  749. if ( control->GetValue< bool >( "transform" ) )
  750. {
  751. CDmeChannel *ch1 = control->GetValueElement< CDmeChannel >( "position" );
  752. CDmeChannel *ch2 = control->GetValueElement< CDmeChannel >( "orientation" );
  753. channels[ LOG_PREVIEW_POSITION ] = ch1;
  754. channels[ LOG_PREVIEW_ORIENTATION ] = ch2;
  755. for ( int i = 2; i < LOG_PREVIEW_MAX_CHANNEL_COUNT; ++i )
  756. {
  757. channels[i] = NULL;
  758. }
  759. return;
  760. }
  761. if ( control->GetValue< bool >( "combo" ) )
  762. {
  763. channels[ LOG_PREVIEW_VALUE ] = control->GetValueElement< CDmeChannel >( "valuechannel" );
  764. channels[ LOG_PREVIEW_BALANCE ] = control->GetValueElement< CDmeChannel >( "balancechannel" );
  765. }
  766. else
  767. {
  768. channels[ LOG_PREVIEW_VALUE ] = control->GetValueElement< CDmeChannel >( "channel" );
  769. channels[ LOG_PREVIEW_BALANCE ] = 0;
  770. }
  771. if ( control->GetValue< bool >( "multi" ) )
  772. {
  773. channels[ LOG_PREVIEW_MULTILEVEL ] = control->GetValueElement< CDmeChannel >( "multilevelchannel" );
  774. }
  775. else
  776. {
  777. channels[ LOG_PREVIEW_MULTILEVEL ] = NULL;
  778. }
  779. for ( int i = 3; i < LOG_PREVIEW_MAX_CHANNEL_COUNT; ++i )
  780. {
  781. channels[i] = NULL;
  782. }
  783. }
  784. void CBaseAnimSetAttributeSliderPanel::GetActiveTimeSelectionParams( DmeLog_TimeSelection_t& params )
  785. {
  786. Assert( 0 );
  787. }
  788. void CBaseAnimSetAttributeSliderPanel::ActivateControlSetInMode( int mode, int otherChannelsMode, int hiddenChannelsMode, CAttributeSlider *whichSlider /*= NULL*/ )
  789. {
  790. int i, c;
  791. if ( !m_AnimSet.Get() )
  792. return;
  793. bool updateChannelsModeChanged = m_nActiveControlSetMode != mode ? true : false;
  794. if ( !updateChannelsModeChanged )
  795. return;
  796. int previousMode = m_nActiveControlSetMode;
  797. m_nActiveControlSetMode = mode;
  798. if ( previousMode == CM_RECORD )
  799. {
  800. DmeLog_TimeSelection_t params;
  801. GetActiveTimeSelectionParams( params );
  802. // Finalize any previously recording layers!!!
  803. g_pChannelRecordingMgr->FinishLayerRecording( params.m_flThreshold, true );
  804. }
  805. ChannelMode_t channelMode = ( ChannelMode_t )mode;
  806. const CDmaElementArray< CDmElement > &controls = m_AnimSet->GetControls();
  807. // Build the list of channels to alter
  808. CUtlVector< CDmeChannel * > updateChannels;
  809. CUtlVector< CDmeChannel * > otherChannels;
  810. CUtlVector< CDmeChannel * > hiddenChannels;
  811. CDisableUndoScopeGuard guard;
  812. c = m_SliderList.Count();
  813. int j;
  814. for ( i = 0; i < c; ++i )
  815. {
  816. CAttributeSlider *slider = m_SliderList[ i ];
  817. CDmElement *ctrl = controls[ i ];
  818. if ( !ctrl )
  819. continue;
  820. CDmeChannel *ctrlChannels[ LOG_PREVIEW_MAX_CHANNEL_COUNT ];
  821. GetChannelsForControl( ctrl, ctrlChannels );
  822. for ( j = 0 ; j < LOG_PREVIEW_MAX_CHANNEL_COUNT; ++j )
  823. {
  824. if ( !ctrlChannels[ j ] )
  825. continue;
  826. CUtlVector< CDmeChannel * > *useArray = NULL;;
  827. // now characterize it
  828. bool hidden = !slider->IsVisible();
  829. if ( hidden )
  830. {
  831. useArray = &hiddenChannels;
  832. }
  833. else
  834. {
  835. if ( !whichSlider )
  836. {
  837. useArray = &updateChannels;
  838. }
  839. else if ( slider == whichSlider )
  840. {
  841. // this causes value and balance to get lumped together, since we're now dragging left/right values
  842. if ( slider->GetDragControl() == ANIM_CONTROL_MULTILEVEL )
  843. {
  844. useArray = ( j == LOG_PREVIEW_MULTILEVEL ) ? &updateChannels : &otherChannels;
  845. }
  846. else
  847. {
  848. useArray = ( j != LOG_PREVIEW_MULTILEVEL ) ? &updateChannels : &otherChannels;
  849. }
  850. }
  851. else
  852. {
  853. useArray = &otherChannels;
  854. }
  855. }
  856. useArray->AddToTail( ctrlChannels[ j ] );
  857. }
  858. }
  859. guard.Release();
  860. c = updateChannels.Count();
  861. if ( c > 0 )
  862. {
  863. if ( channelMode == CM_RECORD )
  864. {
  865. DmeLog_TimeSelection_t params;
  866. GetActiveTimeSelectionParams( params );
  867. params.SetRecordingMode( ( NULL == whichSlider ) ? RECORD_PRESET : RECORD_ATTRIBUTESLIDER );
  868. g_pChannelRecordingMgr->StartLayerRecording( "Dragging Sliders", &params );
  869. for ( i = 0; i < c; ++i )
  870. {
  871. // THIS PUTS THEM INTO CM_RECORD
  872. g_pChannelRecordingMgr->AddChannelToRecordingLayer( updateChannels[ i ], GetCurrentMovie(), GetCurrentShot() );
  873. }
  874. SetTimeSelectionParametersForRecordingChannels( ( NULL == whichSlider ) ? m_Previous.amount : 1.0f );
  875. }
  876. else
  877. {
  878. // Don't create undo records for this
  879. CDisableUndoScopeGuard guardSet;
  880. for ( i = 0; i < c; ++i )
  881. {
  882. updateChannels[ i ]->SetMode( channelMode );
  883. }
  884. }
  885. }
  886. c = otherChannels.Count();
  887. if ( c > 0 )
  888. {
  889. // Don't create undo records for this
  890. CDisableUndoScopeGuard guardRecord;
  891. for ( i = 0; i < c; ++i )
  892. {
  893. // These should never go into record!!!
  894. Assert( (ChannelMode_t)otherChannelsMode != CM_RECORD );
  895. otherChannels[ i ]->SetMode( (ChannelMode_t)otherChannelsMode );
  896. }
  897. }
  898. c = hiddenChannels.Count();
  899. if ( c > 0 )
  900. {
  901. // Don't create undo records for this
  902. CDisableUndoScopeGuard guardRecord;
  903. // For now these should only be able to go into Playback
  904. //Assert( (ChannelMode_t)hiddenChannelsMode == CM_PLAY );
  905. for ( i = 0; i < c; ++i )
  906. {
  907. hiddenChannels[ i ]->SetMode( (ChannelMode_t)hiddenChannelsMode );
  908. }
  909. }
  910. }
  911. static const char *s_pDefaultAttributeName[ANIM_CONTROL_COUNT] =
  912. {
  913. "defaultValue", "defaultBalance", "defaultMultilevel"
  914. };
  915. void CBaseAnimSetAttributeSliderPanel::SetupForPreset( FaderPreview_t &fader, int nChangeFlags )
  916. {
  917. // Nothing special here
  918. }
  919. float CBaseAnimSetAttributeSliderPanel::GetBalanceSliderValue()
  920. {
  921. return m_pPresetSideFilter->GetPos();
  922. }
  923. void CBaseAnimSetAttributeSliderPanel::SetTimeSelectionParametersForRecordingChannels( float flIntensity )
  924. {
  925. CBaseAnimSetPresetFaderPanel *pPresets = m_hEditor->GetPresetFader();
  926. if ( !pPresets )
  927. {
  928. Assert( 0 );
  929. return;
  930. }
  931. FaderPreview_t fader;
  932. pPresets->GetPreviewFader( fader );
  933. SetupForPreset( fader, m_nFaderChangeFlags );
  934. int c = g_pChannelRecordingMgr->GetLayerRecordingChannelCount();
  935. for ( int i = 0; i < c; ++i )
  936. {
  937. CDmeChannel *ch = g_pChannelRecordingMgr->GetLayerRecordingChannel( i );
  938. if ( !ch )
  939. continue;
  940. CDmAttribute *pPreset = NULL;
  941. ChannelToSliderLookup_t search;
  942. search.ch = ch;
  943. unsigned int idx = m_ChannelToSliderLookup.Find( search );
  944. if ( idx != m_ChannelToSliderLookup.InvalidIndex() && fader.values )
  945. {
  946. ChannelToSliderLookup_t &item = m_ChannelToSliderLookup[ idx ];
  947. CDmElement *pControl = item.slider;
  948. Assert( pControl );
  949. int faderIndex = fader.values->Find( pControl->GetName() );
  950. if ( faderIndex != fader.values->InvalidIndex() )
  951. {
  952. pPreset = (*fader.values)[ faderIndex ].m_pAttribute[ item.type ];
  953. }
  954. if ( !pPreset )
  955. {
  956. pPreset = pControl->GetAttribute( s_pDefaultAttributeName[item.type] );
  957. }
  958. }
  959. g_pChannelRecordingMgr->SetPresetValue( ch, pPreset );
  960. }
  961. }
  962. static bool CanPreviewType( DmAttributeType_t attType )
  963. {
  964. switch ( attType )
  965. {
  966. default:
  967. return false;
  968. case AT_FLOAT:
  969. case AT_VECTOR3:
  970. case AT_QUATERNION:
  971. break;
  972. }
  973. return true;
  974. }
  975. void CBaseAnimSetAttributeSliderPanel::MaybeAddPreviewLog( CDmeFilmClip *shot, CUtlVector< LogPreview_t >& list, CDmElement *control, bool bDragging, bool isActiveLog, bool bSelected )
  976. {
  977. CDmeChannel *ctrlChannels[ LOG_PREVIEW_MAX_CHANNEL_COUNT ];
  978. GetChannelsForControl( control, ctrlChannels );
  979. LogPreview_t preview;
  980. preview.m_bDragging = bDragging;
  981. preview.m_bActiveLog = isActiveLog;
  982. preview.m_bSelected = bSelected;
  983. for ( int channel = 0; channel < LOG_PREVIEW_MAX_CHANNEL_COUNT; ++channel )
  984. {
  985. CDmeChannel *ch = ctrlChannels[ channel ];
  986. if ( !ch )
  987. continue;
  988. CDmeLog *log = ch->GetLog();
  989. if ( !log )
  990. continue;
  991. DmAttributeType_t attType = log->GetDataType();
  992. if ( !CanPreviewType( attType ) )
  993. continue;
  994. Assert( control );
  995. preview.m_hControl = control;
  996. preview.m_hShot = shot;
  997. preview.m_hChannels[ channel ] = ch;
  998. preview.m_hOwner = ch->FindOwnerClipForChannel( shot );
  999. }
  1000. list.AddToTail( preview );
  1001. }
  1002. void CBaseAnimSetAttributeSliderPanel::RecomputePreview()
  1003. {
  1004. float curtime = system()->GetFrameTime();
  1005. m_flRecomputePreviewTime = curtime + RECOMPUTE_PREVIEW_INTERVAL;
  1006. m_bRequestedNewPreview = true;
  1007. }
  1008. CDmeFilmClip *CBaseAnimSetAttributeSliderPanel::GetCurrentShot()
  1009. {
  1010. return NULL;
  1011. }
  1012. CDmeFilmClip *CBaseAnimSetAttributeSliderPanel::GetCurrentMovie()
  1013. {
  1014. return NULL;
  1015. }
  1016. void CBaseAnimSetAttributeSliderPanel::PerformRecomputePreview()
  1017. {
  1018. m_CurrentPreview.RemoveAll();
  1019. if ( !m_bRequestedNewPreview )
  1020. return;
  1021. #if 0
  1022. // Tracker 54528: While this saves recomputing things all of the time, the delay is annoying so
  1023. // we'll turn it off for now
  1024. float curtime = system()->GetFrameTime();
  1025. if ( curtime < m_flRecomputePreviewTime )
  1026. return;
  1027. #endif
  1028. m_bRequestedNewPreview = false;
  1029. m_flRecomputePreviewTime = -1.0f;
  1030. // list of bones/root transforms which are in the control set
  1031. m_ActiveTransforms.Purge();
  1032. if ( !m_AnimSet.Get() )
  1033. return;
  1034. CDmeFilmClip *shot = GetCurrentShot();
  1035. CDmElement *previewControl = GetLogPreviewControl();
  1036. const CDmaElementArray< CDmElement > &controls = m_AnimSet->GetControls();
  1037. int c = m_SliderList.Count();
  1038. int i;
  1039. for ( i = 0; i < c; ++i )
  1040. {
  1041. CAttributeSlider *slider = m_SliderList[ i ];
  1042. if ( !slider->IsVisible() )
  1043. continue;
  1044. CDmElement *control = controls[ i ];
  1045. MaybeAddPreviewLog( shot, m_ActiveTransforms, control, slider->IsDragging(), false, slider->IsSelected() );
  1046. MaybeAddPreviewLog( shot, m_CurrentPreview, control, slider->IsDragging(), ( control == previewControl ), slider->IsSelected() );
  1047. }
  1048. }
  1049. CUtlVector< LogPreview_t >* CBaseAnimSetAttributeSliderPanel::GetActiveTransforms()
  1050. {
  1051. return &m_ActiveTransforms;
  1052. }
  1053. CDmElement *CBaseAnimSetAttributeSliderPanel::GetElementFromSlider( CAttributeSlider *pSlider )
  1054. {
  1055. const CDmaElementArray< CDmElement > &controls = m_AnimSet->GetControls();
  1056. int c = m_SliderList.Count();
  1057. int i;
  1058. for ( i = 0; i < c; ++i )
  1059. {
  1060. CAttributeSlider *slider = m_SliderList[ i ];
  1061. if ( slider != pSlider )
  1062. continue;
  1063. CDmElement *control = controls[ i ];
  1064. return control;
  1065. }
  1066. return NULL;
  1067. }
  1068. CDmElement *CBaseAnimSetAttributeSliderPanel::GetLogPreviewControl()
  1069. {
  1070. return m_PreviewControl.Get();
  1071. }
  1072. void CBaseAnimSetAttributeSliderPanel::SetLogPreviewControlFromSlider( CAttributeSlider *pSlider )
  1073. {
  1074. CDmElement *control = GetElementFromSlider( pSlider );
  1075. // Note can be NULL
  1076. SetLogPreviewControl( control );
  1077. }
  1078. void CBaseAnimSetAttributeSliderPanel::SetLogPreviewControl( CDmElement *control )
  1079. {
  1080. if ( !m_hEditor.Get() )
  1081. return;
  1082. bool changed = m_PreviewControl != control ? true : false;
  1083. m_PreviewControl = control;
  1084. if ( changed )
  1085. {
  1086. const CDmaElementArray< CDmElement > &controls = m_AnimSet->GetControls();
  1087. int itemNumber = 0;
  1088. int nSliders = m_SliderList.Count();
  1089. for ( int i = 0; i < nSliders; ++i )
  1090. {
  1091. CAttributeSlider *slider = m_SliderList[ i ];
  1092. slider->SetIsLogPreviewControl( false );
  1093. if ( !slider->IsVisible() )
  1094. continue;
  1095. CDmElement *c = controls[ i ];
  1096. if ( c == control )
  1097. {
  1098. slider->SetIsLogPreviewControl( true );
  1099. slider->RequestFocus();
  1100. m_Sliders->ScrollToItem( itemNumber );
  1101. }
  1102. ++itemNumber;
  1103. }
  1104. RecomputePreview();
  1105. }
  1106. }
  1107. void CBaseAnimSetAttributeSliderPanel::GetVisibleControls( CUtlVector< VisItem_t>& list )
  1108. {
  1109. const CDmaElementArray< CDmElement > &controls = m_AnimSet->GetControls();
  1110. int i, c;
  1111. c = m_SliderList.Count();
  1112. for ( i = 0; i < c; ++i )
  1113. {
  1114. CAttributeSlider *slider = m_SliderList[ i ];
  1115. if ( !slider->IsVisible() )
  1116. continue;
  1117. CDmElement *ctrl = controls[ i ];
  1118. if ( !ctrl )
  1119. continue;
  1120. VisItem_t item;
  1121. item.element = ctrl;
  1122. item.selected = slider->IsSelected();
  1123. item.index = i;
  1124. list.AddToTail( item );
  1125. }
  1126. }
  1127. int CBaseAnimSetAttributeSliderPanel::BuildVisibleControlList( CUtlVector< LogPreview_t >& list )
  1128. {
  1129. if ( !m_AnimSet.Get() )
  1130. return 0;
  1131. const CDmaElementArray< CDmElement > &controls = m_AnimSet->GetControls();
  1132. int i, c;
  1133. c = m_SliderList.Count();
  1134. for ( i = 0; i < c; ++i )
  1135. {
  1136. CAttributeSlider *slider = m_SliderList[ i ];
  1137. if ( !slider->IsVisible() )
  1138. continue;
  1139. CDmElement *ctrl = controls[ i ];
  1140. if ( !ctrl )
  1141. continue;
  1142. MaybeAddPreviewLog( NULL, list, ctrl, slider->IsDragging(), false, slider->IsSelected() );
  1143. }
  1144. return list.Count();
  1145. }
  1146. int CBaseAnimSetAttributeSliderPanel::BuildFullControlList( CUtlVector< LogPreview_t >& list )
  1147. {
  1148. if ( !m_AnimSet.Get() )
  1149. return 0;
  1150. const CDmaElementArray< CDmElement > &controls = m_AnimSet->GetControls();
  1151. int i, c;
  1152. c = m_SliderList.Count();
  1153. for ( i = 0; i < c; ++i )
  1154. {
  1155. CAttributeSlider *slider = m_SliderList[ i ];
  1156. CDmElement *ctrl = controls[ i ];
  1157. if ( !ctrl )
  1158. continue;
  1159. MaybeAddPreviewLog( NULL, list, ctrl, slider->IsDragging(), false, slider->IsSelected() );
  1160. }
  1161. return list.Count();
  1162. }
  1163. void SpewLayer( const char *desc, CDmeTypedLogLayer< float > *l )
  1164. {
  1165. Msg( "%s\n", desc );
  1166. int c = l->GetKeyCount();
  1167. for ( int i = 0; i < c; ++i )
  1168. {
  1169. DmeTime_t kt = l->GetKeyTime( i );
  1170. float v = l->GetKeyValue( i );
  1171. Msg( "%d %.3f = %f\n", i, kt.GetSeconds(), v );
  1172. if ( i > 20 )
  1173. break;
  1174. }
  1175. }
  1176. void CBaseAnimSetAttributeSliderPanel::MoveToSlider( CAttributeSlider *pCurrentSlider, int nDirection )
  1177. {
  1178. Assert( pCurrentSlider );
  1179. if ( !pCurrentSlider )
  1180. return;
  1181. // Find current slider index and then move to next / previous one
  1182. CUtlVector< CAttributeSlider * > visible;
  1183. int c = m_SliderList.Count();
  1184. if ( c <= 1 )
  1185. return;
  1186. int i;
  1187. for ( i = 0; i < c; ++i )
  1188. {
  1189. if ( !m_SliderList[ i ]->IsVisible() )
  1190. continue;
  1191. visible.AddToTail( m_SliderList[ i ] );
  1192. }
  1193. c = visible.Count();
  1194. if ( c <= 1 )
  1195. return;
  1196. for ( i = 0; i < c; ++i )
  1197. {
  1198. if ( visible[ i ] != pCurrentSlider )
  1199. continue;
  1200. Msg( "Found slider at %d (old %s)\n", i, pCurrentSlider->GetName() );
  1201. i += nDirection;
  1202. if ( i < 0 )
  1203. {
  1204. i = c - 1;
  1205. }
  1206. else if ( i >= c )
  1207. {
  1208. i = 0;
  1209. }
  1210. Msg( "Change to slider %d %s\n", i, visible[ i ]->GetName() );
  1211. // m_SliderList[ i ]->RequestFocus();
  1212. SetLogPreviewControl( visible[ i ]->GetControl() );
  1213. break;
  1214. }
  1215. }
  1216. void CBaseAnimSetAttributeSliderPanel::OnKBDeselectAll()
  1217. {
  1218. ClearSelectedControls();
  1219. }
  1220. void CBaseAnimSetAttributeSliderPanel::ClearSelectedControls()
  1221. {
  1222. int c = m_SliderList.Count();
  1223. int i;
  1224. for ( i = 0; i < c; ++i )
  1225. {
  1226. m_SliderList[ i ]->SetSelected( false );
  1227. }
  1228. RecomputePreview();
  1229. }
  1230. void CBaseAnimSetAttributeSliderPanel::SetControlSelected( CAttributeSlider *slider, bool state )
  1231. {
  1232. slider->SetSelected( state);
  1233. RecomputePreview();
  1234. }
  1235. void CBaseAnimSetAttributeSliderPanel::SetControlSelected( CDmElement *control, bool state )
  1236. {
  1237. CAttributeSlider *slider = FindSliderForControl( control );
  1238. if ( !slider )
  1239. return;
  1240. SetControlSelected( slider, state );
  1241. }
  1242. CAttributeSlider *CBaseAnimSetAttributeSliderPanel::FindSliderForControl( CDmElement *control )
  1243. {
  1244. int c = m_SliderList.Count();
  1245. int i;
  1246. for ( i = 0; i < c; ++i )
  1247. {
  1248. if ( m_SliderList[ i ]->GetControl() == control )
  1249. return m_SliderList[ i ];
  1250. }
  1251. return NULL;
  1252. }
  1253. bool CBaseAnimSetAttributeSliderPanel::GetSliderValues( AttributeValue_t *pValue, int nIndex )
  1254. {
  1255. Assert( pValue );
  1256. Assert( nIndex >= 0 && nIndex < m_SliderList.Count() );
  1257. CAttributeSlider *pSlider = m_SliderList[ nIndex ];
  1258. bool bForce = m_Previous.isbeingdragged;
  1259. bool bGetPreview = ( pSlider->IsPreviewEnabled() && ( !pSlider->IsSimplePreview() || bForce ) );
  1260. *pValue = bGetPreview ? pSlider->GetPreview() : pSlider->GetValue();
  1261. return pSlider->IsVisible();
  1262. }