ctkeyframe.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. class CTKeyframe extends ScriptedWidgetEventHandler
  2. {
  3. protected int m_Index;
  4. protected float m_InterpTime;
  5. protected float m_TotalTimeBefore;
  6. protected vector m_Position;
  7. protected vector m_Orientation;
  8. protected CameraToolsMenu m_Menu;
  9. protected Widget m_Root;
  10. protected TextWidget m_IndexWidget;
  11. protected EditBoxWidget m_InterpTimeWidget;
  12. protected EditBoxWidget m_FOVWidget;
  13. protected EditBoxWidget m_DOFWidget;
  14. protected EditBoxWidget m_PinWidget;
  15. protected TextWidget m_TotalTimeWidget;
  16. void CTKeyframe( int index, vector pos, vector orient, float int_value, float fov, float dof, int pin, float time_before, Widget root, CameraToolsMenu parent )
  17. {
  18. m_Menu = parent;
  19. m_Root = GetGame().GetWorkspace().CreateWidgets( "gui/layouts/camera_tools/keyframe_entry.layout", root );
  20. m_IndexWidget = TextWidget.Cast( m_Root.FindAnyWidget( "keyframe_id" ) );
  21. m_InterpTimeWidget = EditBoxWidget.Cast( m_Root.FindAnyWidget( "keyframe_time_edit" ) );
  22. m_FOVWidget = EditBoxWidget.Cast( m_Root.FindAnyWidget( "keyframe_fov_edit" ) );
  23. m_DOFWidget = EditBoxWidget.Cast( m_Root.FindAnyWidget( "keyframe_dof_edit" ) );
  24. m_PinWidget = EditBoxWidget.Cast( m_Root.FindAnyWidget( "keyframe_pin_edit" ) );
  25. m_TotalTimeWidget = TextWidget.Cast( m_Root.FindAnyWidget( "keyframe_time" ) );
  26. m_Index = index;
  27. m_TotalTimeBefore = time_before;
  28. m_Position = pos;
  29. m_Orientation = orient;
  30. SetInterpTime( int_value );
  31. SetFOV( fov );
  32. SetDOF( dof );
  33. SetPin( pin );
  34. m_IndexWidget.SetText( m_Index.ToString() );
  35. m_Root.SetHandler( this );
  36. }
  37. void ~CTKeyframe()
  38. {
  39. delete m_Root;
  40. }
  41. float GetInterpTime()
  42. {
  43. string time_text = m_InterpTimeWidget.GetText();
  44. m_InterpTime = time_text.ToFloat();
  45. return m_InterpTime;
  46. }
  47. void SetPin( int pin )
  48. {
  49. m_PinWidget.SetText( pin.ToString() );
  50. }
  51. int GetPin()
  52. {
  53. return m_PinWidget.GetText().ToInt();
  54. }
  55. void SetFOV( float fov )
  56. {
  57. m_FOVWidget.SetText( fov.ToString() );
  58. }
  59. float GetFOV()
  60. {
  61. return m_FOVWidget.GetText().ToFloat();
  62. }
  63. void SetDOF( float dof )
  64. {
  65. m_DOFWidget.SetText( dof.ToString() );
  66. }
  67. float GetDOF()
  68. {
  69. return m_DOFWidget.GetText().ToFloat();
  70. }
  71. void SetPosition( vector pos )
  72. {
  73. m_Position = pos;
  74. }
  75. void SetOrientation( vector orient )
  76. {
  77. m_Orientation = orient;
  78. }
  79. vector GetPosition()
  80. {
  81. return m_Position;
  82. }
  83. vector GetOrientation()
  84. {
  85. return m_Orientation;
  86. }
  87. void SetTimeBefore( float time )
  88. {
  89. m_TotalTimeBefore = time;
  90. m_TotalTimeWidget.SetText( ( m_TotalTimeBefore + m_InterpTime ).ToString() );
  91. }
  92. void SetInterpTime( float time )
  93. {
  94. m_InterpTime = time;
  95. m_InterpTimeWidget.SetText( m_InterpTime.ToString() );
  96. m_TotalTimeWidget.SetText( ( m_TotalTimeBefore + m_InterpTime ).ToString() );
  97. }
  98. void Select()
  99. {
  100. m_Root.FindAnyWidget( "spacer" ).SetAlpha( 1 );
  101. m_IndexWidget.SetColor( ARGBF( 1, 1, 0, 0 ) );
  102. m_InterpTimeWidget.SetColor( ARGBF( 1, 1, 0, 0 ) );
  103. m_TotalTimeWidget.SetColor( ARGBF( 1, 1, 0, 0 ) );
  104. }
  105. void Unselect()
  106. {
  107. m_Root.FindAnyWidget( "spacer" ).SetAlpha( 0.625 );
  108. m_IndexWidget.SetColor( ARGBF( 1, 1, 1, 1 ) );
  109. m_InterpTimeWidget.SetColor( ARGBF( 1, 1, 1, 1 ) );
  110. m_TotalTimeWidget.SetColor( ARGBF( 1, 1, 1, 1 ) );
  111. }
  112. override bool OnClick( Widget w, int x, int y, int button )
  113. {
  114. if( w == m_Root )
  115. {
  116. m_Menu.SelectKeyframe( this );
  117. return true;
  118. }
  119. return false;
  120. }
  121. override bool OnFocus( Widget w, int x, int y )
  122. {
  123. if( IsFocusable( w ) )
  124. {
  125. m_Menu.SelectKeyframe( this );
  126. return true;
  127. }
  128. return false;
  129. }
  130. bool IsFocusable( Widget w )
  131. {
  132. if( w )
  133. {
  134. return ( w == m_InterpTimeWidget || w == m_TotalTimeWidget || w == m_FOVWidget || w == m_DOFWidget );
  135. }
  136. return false;
  137. }
  138. }