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.

215 lines
5.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include <stdio.h>
  8. #include "hlfaceposer.h"
  9. #include "choreoviewcolors.h"
  10. #include "choreoglobaleventwidget.h"
  11. #include "choreowidgetdrawhelper.h"
  12. #include "ChoreoView.h"
  13. #include "choreoevent.h"
  14. #include "choreoeventwidget.h"
  15. //-----------------------------------------------------------------------------
  16. // Purpose:
  17. // Input : *parent -
  18. //-----------------------------------------------------------------------------
  19. CChoreoGlobalEventWidget::CChoreoGlobalEventWidget( CChoreoWidget *parent )
  20. : CChoreoWidget( parent )
  21. {
  22. m_pEvent = NULL;
  23. m_bDragging = false;
  24. m_xStart = 0;
  25. m_hPrevCursor = 0;
  26. }
  27. //-----------------------------------------------------------------------------
  28. // Purpose:
  29. //-----------------------------------------------------------------------------
  30. CChoreoGlobalEventWidget::~CChoreoGlobalEventWidget( void )
  31. {
  32. }
  33. //-----------------------------------------------------------------------------
  34. // Purpose:
  35. //-----------------------------------------------------------------------------
  36. void CChoreoGlobalEventWidget::Create( void )
  37. {
  38. }
  39. //-----------------------------------------------------------------------------
  40. // Purpose:
  41. // Input : rc -
  42. //-----------------------------------------------------------------------------
  43. void CChoreoGlobalEventWidget::Layout( RECT& rc )
  44. {
  45. setBounds( rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top );
  46. }
  47. //-----------------------------------------------------------------------------
  48. // Redraw to screen
  49. //-----------------------------------------------------------------------------
  50. void CChoreoGlobalEventWidget::redraw( CChoreoWidgetDrawHelper& drawHelper )
  51. {
  52. if ( !getVisible() )
  53. return;
  54. CChoreoEvent *event = GetEvent();
  55. if ( !event )
  56. return;
  57. RECT rcTab;
  58. rcTab = getBounds();
  59. bool isLoop = false;
  60. Color pointColor = COLOR_CHOREO_SEGMENTDIVIDER;
  61. Color clr = COLOR_CHOREO_SEGMENTDIVIDER_BG;
  62. switch ( event->GetType() )
  63. {
  64. default:
  65. break;
  66. case CChoreoEvent::LOOP:
  67. {
  68. clr = COLOR_CHOREO_LOOPPOINT_BG;
  69. pointColor = COLOR_CHOREO_LOOPPOINT;
  70. isLoop = true;
  71. }
  72. break;
  73. case CChoreoEvent::STOPPOINT:
  74. {
  75. clr = COLOR_CHOREO_STOPPOINT_BG;
  76. pointColor = COLOR_CHOREO_STOPPOINT;
  77. }
  78. break;
  79. }
  80. if ( IsSelected() )
  81. {
  82. InflateRect( &rcTab, 2, 2 );
  83. drawHelper.DrawTriangleMarker( rcTab, pointColor );
  84. InflateRect( &rcTab, -2, -2 );
  85. drawHelper.DrawTriangleMarker( rcTab, Color( 240, 240, 220 ) );
  86. }
  87. else
  88. {
  89. drawHelper.DrawTriangleMarker( rcTab, pointColor );
  90. }
  91. RECT rcClient;
  92. drawHelper.GetClientRect( rcClient );
  93. RECT rcLine = rcTab;
  94. rcLine.top = rcTab.bottom + 2;
  95. rcLine.bottom = rcClient.bottom;
  96. rcLine.left = ( rcLine.left + rcLine.right ) / 2;
  97. rcLine.right = rcLine.left;
  98. if ( IsSelected() )
  99. {
  100. drawHelper.DrawColoredLine( clr, PS_DOT, 2, rcLine.left, rcLine.top, rcLine.right, rcLine.bottom );
  101. }
  102. else
  103. {
  104. drawHelper.DrawColoredLine( clr, PS_DOT, 1, rcLine.left, rcLine.top, rcLine.right, rcLine.bottom );
  105. }
  106. if ( event->GetType() == CChoreoEvent::STOPPOINT )
  107. {
  108. OffsetRect( &rcTab, -4, 15 );
  109. mxbitmapdata_t *image = CChoreoEventWidget::GetImage( event->GetType() );
  110. if ( image )
  111. {
  112. drawHelper.OffsetSubRect( rcTab );
  113. DrawBitmapToDC( drawHelper.GrabDC(), rcTab.left, rcTab.top, 16, 16, *image );
  114. }
  115. }
  116. if ( !isLoop )
  117. return;
  118. Color labelText = COLOR_INFO_TEXT;
  119. DrawLabel( drawHelper, labelText, rcLine.left, rcLine.top + 2, false );
  120. // Figure out loop spot
  121. float looptime = (float)atof( event->GetParameters() );
  122. // Find pixel for that
  123. bool clipped = false;
  124. int x = m_pView->GetPixelForTimeValue( looptime, &clipped );
  125. if ( clipped )
  126. return;
  127. rcLine.left = x;
  128. rcLine.right = x;
  129. clr = COLOR_CHOREO_LOOPPOINT_START_BG;
  130. drawHelper.DrawColoredLine( clr, PS_SOLID, 1, rcLine.left, rcLine.top, rcLine.right, rcLine.top + 28);
  131. DrawLabel( drawHelper, labelText, rcLine.left, rcLine.top + 2, true );
  132. }
  133. void CChoreoGlobalEventWidget::DrawLabel( CChoreoWidgetDrawHelper& drawHelper, const Color& clr, int x, int y, bool right )
  134. {
  135. CChoreoEvent *event = GetEvent();
  136. if ( !event )
  137. return;
  138. int len = drawHelper.CalcTextWidth( "Arial", 9, FW_NORMAL, va( "%s", event->GetName() ) );
  139. RECT rcText;
  140. rcText.top = y;
  141. rcText.bottom = y + 10;
  142. rcText.left = x - len / 2;
  143. rcText.right = rcText.left + len;
  144. if ( !right )
  145. {
  146. drawHelper.DrawColoredTextCharset( "Marlett", 9, FW_NORMAL, SYMBOL_CHARSET, clr, rcText, "3" );
  147. OffsetRect( &rcText, 8, 0 );
  148. drawHelper.DrawColoredText( "Arial", 9, FW_NORMAL, clr, rcText, va( "%s", event->GetName() ) );
  149. }
  150. else
  151. {
  152. drawHelper.DrawColoredText( "Arial", 9, FW_NORMAL, clr, rcText, va( "%s", event->GetName() ) );
  153. OffsetRect( &rcText, len, 0 );
  154. drawHelper.DrawColoredTextCharset( "Marlett", 9, FW_NORMAL, SYMBOL_CHARSET, clr, rcText, "4" );
  155. }
  156. }
  157. //-----------------------------------------------------------------------------
  158. // Purpose:
  159. //-----------------------------------------------------------------------------
  160. void CChoreoGlobalEventWidget::DrawFocusRect( void )
  161. {
  162. HDC dc = GetDC( NULL );
  163. ::DrawFocusRect( dc, &m_rcFocus );
  164. ReleaseDC( NULL, dc );
  165. }
  166. //-----------------------------------------------------------------------------
  167. // Purpose:
  168. // Output : CChoreoEvent
  169. //-----------------------------------------------------------------------------
  170. CChoreoEvent *CChoreoGlobalEventWidget::GetEvent( void )
  171. {
  172. return m_pEvent;
  173. }
  174. //-----------------------------------------------------------------------------
  175. // Purpose:
  176. // Input : *event -
  177. //-----------------------------------------------------------------------------
  178. void CChoreoGlobalEventWidget::SetEvent( CChoreoEvent *event )
  179. {
  180. m_pEvent = event;
  181. }