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.

415 lines
12 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 "choreoactorwidget.h"
  10. #include "choreochannelwidget.h"
  11. #include "choreoactor.h"
  12. #include "choreoview.h"
  13. #include "choreowidgetdrawhelper.h"
  14. #include "mxBitmapButton.h"
  15. #include "choreoviewcolors.h"
  16. #include "choreochannel.h"
  17. #include "filesystem.h"
  18. #include "StudioModel.h"
  19. #define ACTOR_NAME_HEIGHT 26
  20. //-----------------------------------------------------------------------------
  21. // Purpose:
  22. // Input : *actor -
  23. // *parent -
  24. // x -
  25. // y -
  26. // w -
  27. // h -
  28. // 0 -
  29. // 0 -
  30. //-----------------------------------------------------------------------------
  31. CActorBitmapButton::CActorBitmapButton( CChoreoActorWidget *actor, mxWindow *parent, int x, int y, int w, int h, int id /*= 0*/, const char *bitmap /*= 0*/ )
  32. : mxBitmapButton( parent, x, y, w, h, id, bitmap )
  33. {
  34. m_pActor = actor;
  35. }
  36. //-----------------------------------------------------------------------------
  37. // Purpose:
  38. //-----------------------------------------------------------------------------
  39. CChoreoActorWidget *CActorBitmapButton::GetActor( void )
  40. {
  41. return m_pActor;
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose:
  45. //-----------------------------------------------------------------------------
  46. CActorActiveCheckBox::CActorActiveCheckBox( CChoreoActorWidget *actor, mxWindow *parent, int x, int y, int w, int h, const char *label /*= 0*/, int id /*= 0*/ )
  47. : mxCheckBox( parent, x, y, w, h, label, id )
  48. {
  49. m_pActor = actor;
  50. }
  51. CChoreoActorWidget *CActorActiveCheckBox::GetActor( void )
  52. {
  53. return m_pActor;
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Purpose:
  57. // Input : *parent -
  58. //-----------------------------------------------------------------------------
  59. CChoreoActorWidget::CChoreoActorWidget( CChoreoWidget *parent )
  60. : CChoreoWidget( parent )
  61. {
  62. m_pParent = parent;
  63. m_pActor = NULL;
  64. m_bShowChannels = true;
  65. m_btnOpen = new CActorBitmapButton( this, m_pView, 0, 0, 0, 0, IDC_CHANNELOPEN, "gfx/hlfaceposer/channelopen.bmp" );
  66. m_btnClose = new CActorBitmapButton( this, m_pView, 0, 0, 0, 0, IDC_CHANNELCLOSE, "gfx/hlfaceposer/channelclose.bmp" );
  67. ShowChannels( m_bShowChannels );
  68. memset( m_rgCurrentSetting, 0, sizeof( m_rgCurrentSetting ) );
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Purpose:
  72. //-----------------------------------------------------------------------------
  73. CChoreoActorWidget::~CChoreoActorWidget( void )
  74. {
  75. for ( int i = 0 ; i < m_Channels.Count(); i++ )
  76. {
  77. CChoreoChannelWidget *c = m_Channels[ i ];
  78. delete c;
  79. }
  80. m_Channels.RemoveAll();
  81. delete m_btnOpen;
  82. delete m_btnClose;
  83. }
  84. //-----------------------------------------------------------------------------
  85. // Purpose:
  86. // Output : Returns true on success, false on failure.
  87. //-----------------------------------------------------------------------------
  88. bool CChoreoActorWidget::GetShowChannels( void )
  89. {
  90. return m_bShowChannels;
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Purpose: Switch modes
  94. // Input : show -
  95. //-----------------------------------------------------------------------------
  96. void CChoreoActorWidget::ShowChannels( bool show )
  97. {
  98. m_bShowChannels = show;
  99. m_btnOpen->setVisible( !m_bShowChannels );
  100. m_btnClose->setVisible( m_bShowChannels );
  101. m_pView->InvalidateLayout();
  102. }
  103. //-----------------------------------------------------------------------------
  104. // Purpose:
  105. //-----------------------------------------------------------------------------
  106. void CChoreoActorWidget::Create( void )
  107. {
  108. // Create objects for children
  109. Assert( m_pActor );
  110. // Create objects for children
  111. for ( int i = 0; i < m_pActor->GetNumChannels(); i++ )
  112. {
  113. CChoreoChannel *channel = m_pActor->GetChannel( i );
  114. Assert( channel );
  115. if ( !channel )
  116. {
  117. continue;
  118. }
  119. CChoreoChannelWidget *channelWidget = new CChoreoChannelWidget( this );
  120. channelWidget->SetChannel( channel );
  121. channelWidget->Create();
  122. AddChannel( channelWidget );
  123. }
  124. }
  125. //-----------------------------------------------------------------------------
  126. // Purpose:
  127. // Input : rc -
  128. //-----------------------------------------------------------------------------
  129. void CChoreoActorWidget::Layout( RECT& rc )
  130. {
  131. setBounds( rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top );
  132. int buttonSize = 16;
  133. int ypos = rc.top + ( ACTOR_NAME_HEIGHT - buttonSize )/ 2;
  134. m_btnOpen->setBounds( rc.left + 2, ypos, buttonSize, buttonSize );
  135. m_btnClose->setBounds( rc.left + 2, ypos, buttonSize, buttonSize );
  136. bool buttonsVisible = ( ypos > m_pView->GetStartRow() && ( ypos + buttonSize ) < m_pView->GetEndRow() ) ? true : false;
  137. if ( !buttonsVisible )
  138. {
  139. m_btnOpen->setVisible( false );
  140. m_btnClose->setVisible( false );
  141. }
  142. else
  143. {
  144. m_btnOpen->setVisible( !m_bShowChannels );
  145. m_btnClose->setVisible( m_bShowChannels );
  146. }
  147. RECT rcChannels;
  148. rcChannels = rc;
  149. rcChannels.top += ACTOR_NAME_HEIGHT;
  150. // Create objects for children
  151. for ( int i = 0; i < m_Channels.Count(); i++ )
  152. {
  153. CChoreoChannelWidget *channel = m_Channels[ i ];
  154. Assert( channel );
  155. if ( !channel )
  156. {
  157. continue;
  158. }
  159. rcChannels.bottom = rcChannels.top + channel->GetItemHeight();
  160. channel->Layout( rcChannels );
  161. OffsetRect( &rcChannels, 0, channel->GetItemHeight() );
  162. channel->setVisible( m_bShowChannels );
  163. }
  164. }
  165. //-----------------------------------------------------------------------------
  166. // Purpose:
  167. //-----------------------------------------------------------------------------
  168. int CChoreoActorWidget::GetItemHeight( void )
  169. {
  170. int itemHeight = ACTOR_NAME_HEIGHT + 2;
  171. if ( m_bShowChannels )
  172. {
  173. for ( int i = 0; i < m_Channels.Count(); i++ )
  174. {
  175. CChoreoChannelWidget *channel = m_Channels[ i ];
  176. itemHeight += channel->GetItemHeight();
  177. }
  178. }
  179. return itemHeight;
  180. }
  181. //-----------------------------------------------------------------------------
  182. // Purpose:
  183. //-----------------------------------------------------------------------------
  184. void CChoreoActorWidget::redraw( CChoreoWidgetDrawHelper& drawHelper )
  185. {
  186. if ( !getVisible() )
  187. return;
  188. CChoreoActor *actor = GetActor();
  189. if ( !actor )
  190. return;
  191. RECT rcClient = getBounds();
  192. if ( !actor->GetActive() )
  193. {
  194. RECT rcBg = rcClient;
  195. rcBg.right = rcBg.left + m_pView->GetLabelWidth() ;
  196. InflateRect( &rcBg, -3, -5 );
  197. drawHelper.DrawFilledRect( Color( 220, 220, 220 ), rcBg );
  198. }
  199. RECT rcText;
  200. rcText.left = rcClient.left;
  201. rcText.right = rcClient.left + m_pView->GetLabelWidth();
  202. rcText.top = rcClient.top;
  203. rcText.bottom = rcClient.top + ACTOR_NAME_HEIGHT;
  204. drawHelper.DrawColoredLine( COLOR_CHOREO_ACTORLINE, PS_SOLID, 1, 0, rcText.top,
  205. rcClient.right, rcText.top );
  206. drawHelper.DrawColoredLine( COLOR_CHOREO_ACTORLINE, PS_SOLID, 1, 0, rcClient.bottom-2,
  207. rcClient.right, rcClient.bottom-2 );
  208. drawHelper.DrawColoredLine( Color(200,206,255), PS_SOLID, 1, 0, rcClient.bottom-1,
  209. rcClient.right, rcClient.bottom-1 );
  210. drawHelper.DrawColoredLine( COLOR_CHOREO_DIVIDER, PS_SOLID, 1, rcText.right, rcClient.top,
  211. rcText.right, rcClient.bottom-1 );
  212. RECT rcName = rcText;
  213. rcName.left += 18;
  214. char n[ 512 ];
  215. strcpy( n, actor->GetName() );
  216. drawHelper.DrawColoredText( "Arial",
  217. m_pView->GetFontSize() + 5,
  218. 1000,
  219. actor->GetActive() ? COLOR_CHOREO_ACTORNAME : COLOR_CHOREO_ACTORNAME_INACTIVE,
  220. rcName, n );
  221. if ( !actor->GetActive() )
  222. {
  223. strcpy( n, "(inactive)" );
  224. RECT rcInactive = rcName;
  225. int len = drawHelper.CalcTextWidth( "Arial", m_pView->GetFontSize() - 2, 500, n );
  226. rcInactive.left = rcInactive.right - len - 5;
  227. rcInactive.top += 3;
  228. rcInactive.bottom = rcInactive.top + m_pView->GetFontSize() - 2;
  229. drawHelper.DrawColoredText( "Arial", m_pView->GetFontSize() - 2, 500,
  230. COLOR_CHOREO_ACTORNAME_INACTIVE, rcInactive, n );
  231. }
  232. rcName.left -= 18;
  233. if ( actor->GetFacePoserModelName()[0] )
  234. {
  235. int textWidth = drawHelper.CalcTextWidth( "Arial", m_pView->GetFontSize() + 5, 1000, actor->GetName() );
  236. RECT rcModelName = rcName;
  237. rcModelName.left += ( 14 + textWidth + 2 );
  238. int fontsize = m_pView->GetFontSize() - 2;
  239. char shortname[ 512 ];
  240. Q_FileBase (actor->GetFacePoserModelName(), shortname, sizeof( shortname ) );
  241. strcat( shortname, ".mdl" );
  242. int len = drawHelper.CalcTextWidth( "Arial", fontsize, FW_NORMAL, shortname );
  243. rcModelName.left = rcModelName.right - len - 5;
  244. rcModelName.top = rcModelName.bottom - fontsize;
  245. OffsetRect( &rcModelName, 0, -3 );
  246. drawHelper.DrawColoredText( "Arial", fontsize, FW_NORMAL, COLOR_CHOREO_LIGHTTEXT, rcModelName, shortname );
  247. }
  248. if ( m_bShowChannels )
  249. {
  250. for ( int j = 0; j < GetNumChannels(); j++ )
  251. {
  252. CChoreoChannelWidget *channel = GetChannel( j );
  253. if ( channel )
  254. {
  255. channel->redraw( drawHelper );
  256. }
  257. RECT rcChannel = channel->getBounds();
  258. drawHelper.DrawColoredLine( COLOR_CHOREO_ACTORLINE, PS_SOLID, 1, rcText.right+1, rcChannel.top,
  259. rcChannel.right, rcChannel.top );
  260. drawHelper.DrawColoredLine( COLOR_CHOREO_ACTORLINE, PS_SOLID, 1, rcText.right+1, rcChannel.bottom,
  261. rcChannel.right, rcChannel.bottom );
  262. }
  263. return;
  264. }
  265. OffsetRect( &rcName, m_pView->GetLabelWidth() + 10, 0 );
  266. rcName.right = w();
  267. char sz[ 256 ];
  268. // count channels and events
  269. int ev = 0;
  270. for ( int i = 0; i < actor->GetNumChannels(); i++ )
  271. {
  272. CChoreoChannel *ch = actor->GetChannel( i );
  273. if ( ch )
  274. {
  275. ev += ch->GetNumEvents();
  276. }
  277. }
  278. sprintf( sz, "%i channels with %i events hidden", actor->GetNumChannels(), ev );
  279. drawHelper.DrawColoredText( "Arial", m_pView->GetFontSize(), FW_NORMAL, COLOR_CHOREO_ACTORNAME, rcName, sz );
  280. }
  281. //-----------------------------------------------------------------------------
  282. // Purpose:
  283. // Output : CChoreoActor
  284. //-----------------------------------------------------------------------------
  285. CChoreoActor *CChoreoActorWidget::GetActor( void )
  286. {
  287. return m_pActor;
  288. }
  289. //-----------------------------------------------------------------------------
  290. // Purpose:
  291. // Input : *actor -
  292. //-----------------------------------------------------------------------------
  293. void CChoreoActorWidget::SetActor( CChoreoActor *actor )
  294. {
  295. m_pActor = actor;
  296. }
  297. //-----------------------------------------------------------------------------
  298. // Purpose:
  299. // Input : *channel -
  300. //-----------------------------------------------------------------------------
  301. void CChoreoActorWidget::AddChannel( CChoreoChannelWidget *channel )
  302. {
  303. m_Channels.AddToTail( channel );
  304. }
  305. //-----------------------------------------------------------------------------
  306. // Purpose:
  307. // Input : *channel -
  308. //-----------------------------------------------------------------------------
  309. void CChoreoActorWidget::RemoveChannel( CChoreoChannelWidget *channel )
  310. {
  311. m_Channels.FindAndRemove( channel );
  312. }
  313. //-----------------------------------------------------------------------------
  314. // Purpose:
  315. // Input : num -
  316. // Output : CChoreoChannelWidget
  317. //-----------------------------------------------------------------------------
  318. CChoreoChannelWidget *CChoreoActorWidget::GetChannel( int num )
  319. {
  320. return m_Channels[ num ];
  321. }
  322. //-----------------------------------------------------------------------------
  323. // Purpose:
  324. // Output : int
  325. //-----------------------------------------------------------------------------
  326. int CChoreoActorWidget::GetNumChannels( void )
  327. {
  328. return m_Channels.Count();
  329. }
  330. //-----------------------------------------------------------------------------
  331. // Purpose:
  332. // Output : float
  333. //-----------------------------------------------------------------------------
  334. float *CChoreoActorWidget::GetSettings( void )
  335. {
  336. return m_rgCurrentSetting;
  337. }
  338. //-----------------------------------------------------------------------------
  339. // Purpose:
  340. //-----------------------------------------------------------------------------
  341. void CChoreoActorWidget::ResetSettings( void )
  342. {
  343. memset( m_rgCurrentSetting, 0, sizeof( m_rgCurrentSetting ) );
  344. }