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.

976 lines
22 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "ControlPanel.h"
  7. #include "ViewerSettings.h"
  8. #include "StudioModel.h"
  9. #include "IStudioRender.h"
  10. #include "MatSysWin.h"
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <mxtk/mx.h>
  15. #include <mxtk/mxBmp.h>
  16. #include "FlexPanel.h"
  17. #include "mxExpressionTray.h"
  18. #include "PhonemeEditor.h"
  19. #include "hlfaceposer.h"
  20. #include "expclass.h"
  21. #include "mxExpressionTab.h"
  22. #include "ExpressionTool.h"
  23. #include "MDLViewer.h"
  24. #include "choreowidgetdrawhelper.h"
  25. #include "faceposer_models.h"
  26. #include "ifaceposerworkspace.h"
  27. #include "choreoview.h"
  28. #include "GestureTool.h"
  29. #include "RampTool.h"
  30. #include "SceneRampTool.h"
  31. #include "phonemeextractor/PhonemeExtractor.h"
  32. #include "tier1/KeyValues.h"
  33. // memdbgon must be the last include file in a .cpp file!!!
  34. #include "tier0/memdbgon.h"
  35. extern char g_appTitle[];
  36. ControlPanel *g_pControlPanel = 0;
  37. //-----------------------------------------------------------------------------
  38. // Purpose: A simple subclass so we can paint the window background
  39. //-----------------------------------------------------------------------------
  40. class CControlPanelTabWindow : public mxWindow
  41. {
  42. public:
  43. CControlPanelTabWindow( mxWindow *parent, int x, int y, int w, int h ) :
  44. mxWindow( parent, x, y, w, h )
  45. {
  46. FacePoser_AddWindowStyle( this, WS_CLIPSIBLINGS | WS_CLIPCHILDREN );
  47. };
  48. virtual bool PaintBackground( void )
  49. {
  50. CChoreoWidgetDrawHelper drawHelper( this );
  51. RECT rc;
  52. drawHelper.GetClientRect( rc );
  53. drawHelper.DrawFilledRect( RGBToColor( GetSysColor( COLOR_BTNFACE ) ), rc );
  54. return false;
  55. }
  56. };
  57. ControlPanel::ControlPanel (mxWindow *parent)
  58. : IFacePoserToolWindow( "ControlPanel", "Control Panel" ), mxWindow( parent, 0, 0, 0, 0 ), tab( 0 )
  59. {
  60. // create tabcontrol with subdialog windows
  61. tab = new mxTab (this, 0, 0, 0, 0, IDC_TAB);
  62. CControlPanelTabWindow *wRender = new CControlPanelTabWindow (this, 0, 0, 0, 0);
  63. tab->add (wRender, "Render");
  64. cRenderMode = new mxChoice (wRender, 5, 5, 100, 22, IDC_RENDERMODE);
  65. cRenderMode->add ("Wireframe");
  66. cRenderMode->add ("Flatshaded");
  67. cRenderMode->add ("Smoothshaded");
  68. cRenderMode->add ("Textured");
  69. cRenderMode->select (3);
  70. mxToolTip::add (cRenderMode, "Select Render Mode");
  71. slModelGap = new mxSlider( wRender, 220, 5, 140, 20, IDC_MODELSPACING );
  72. slModelGap->setRange( 0.0f, 64.0f, 256 );
  73. slModelGap->setValue( 16 );
  74. mxToolTip::add (slModelGap, "Select Model Spacing" );
  75. new mxLabel (wRender, 220, 25, 140, 20, "Model Spacing");
  76. cbAllWindowsDriveSpeech = new mxCheckBox( wRender, 220, 45, 140, 20, "All tools drive mouth", IDC_TOOLSDRIVEMOUTH );
  77. cbAllWindowsDriveSpeech->setChecked( g_viewerSettings.faceposerToolsDriveMouth );
  78. cbGround = new mxCheckBox (wRender, 110, 5, 100, 20, "Ground", IDC_GROUND);
  79. cbGround->setEnabled( true );
  80. cbMovement = new mxCheckBox (wRender, 110, 25, 100, 20, "Movement", IDC_MOVEMENT);
  81. cbMovement->setEnabled( false );
  82. cbBackground = new mxCheckBox (wRender, 110, 45, 100, 20, "Background", IDC_BACKGROUND);
  83. cbBackground->setEnabled( false );
  84. new mxCheckBox (wRender, 110, 65, 100, 20, "Hit Boxes", IDC_HITBOXES);
  85. new mxCheckBox (wRender, 5, 65, 100, 20, "Bones", IDC_BONES);
  86. mxCheckBox *cbAttachments = new mxCheckBox (wRender, 5, 45, 100, 20, "Attachments", IDC_ATTACHMENTS);
  87. cbAttachments->setEnabled( false );
  88. CControlPanelTabWindow *wSequence = new CControlPanelTabWindow (this, 0, 0, 0, 0);
  89. tab->add (wSequence, "Sequence");
  90. cSequence = new mxChoice (wSequence, 5, 5, 200, 22, IDC_SEQUENCE);
  91. mxToolTip::add (cSequence, "Select Sequence");
  92. slSpeedScale = new mxSlider (wSequence, 5, 32, 200, 18, IDC_SPEEDSCALE);
  93. slSpeedScale->setRange (0.0, 5.0 );
  94. slSpeedScale->setValue (0.0);
  95. mxToolTip::add (slSpeedScale, "Speed Scale");
  96. lSpeedScale = new mxLabel( wSequence, 5, 50, 200, 18 );
  97. lSpeedScale->setLabel( "Speed scale" );
  98. CControlPanelTabWindow *wBody = new CControlPanelTabWindow (this, 0, 0, 0, 0);
  99. tab->add (wBody, "Body");
  100. cBodypart = new mxChoice (wBody, 5, 5, 100, 22, IDC_BODYPART);
  101. mxToolTip::add (cBodypart, "Choose a bodypart");
  102. cSubmodel = new mxChoice (wBody, 110, 5, 100, 22, IDC_SUBMODEL);
  103. mxToolTip::add (cSubmodel, "Choose a submodel of current bodypart");
  104. cController = new mxChoice (wBody, 5, 30, 100, 22, IDC_CONTROLLER);
  105. mxToolTip::add (cController, "Choose a bone controller");
  106. slController = new mxSlider (wBody, 105, 32, 100, 18, IDC_CONTROLLERVALUE);
  107. slController->setRange (0, 45);
  108. mxToolTip::add (slController, "Change current bone controller value");
  109. lModelInfo1 = new mxLabel (wBody, 220, 5, 120, 100, "No Model.");
  110. lModelInfo2 = new mxLabel (wBody, 340, 5, 120, 100, "");
  111. cSkin = new mxChoice (wBody, 5, 55, 100, 22, IDC_SKINS);
  112. mxToolTip::add (cSkin, "Choose a skin family");
  113. }
  114. ControlPanel::~ControlPanel()
  115. {
  116. }
  117. bool ControlPanel::CanClose( void )
  118. {
  119. workspacefiles->StartStoringFiles( IWorkspaceFiles::EXPRESSION );
  120. for ( int i = 0 ; i < expressions->GetNumClasses(); i++ )
  121. {
  122. CExpClass *cl = expressions->GetClass( i );
  123. if ( cl )
  124. {
  125. workspacefiles->StoreFile( IWorkspaceFiles::EXPRESSION, cl->GetFileName() );
  126. }
  127. }
  128. workspacefiles->FinishStoringFiles( IWorkspaceFiles::EXPRESSION );
  129. // Now close them all, or abort exit if user doesn't want to close any that have changed
  130. return Closeall();
  131. }
  132. void ControlPanel::OnDelete()
  133. {
  134. }
  135. void ControlPanel::PositionControls( int width, int height )
  136. {
  137. if ( tab )
  138. {
  139. tab->setBounds( 0, GetCaptionHeight(), width, height );
  140. }
  141. }
  142. void ControlPanel::redraw()
  143. {
  144. if ( !ToolCanDraw() )
  145. return;
  146. CChoreoWidgetDrawHelper helper( this, RGBToColor( GetSysColor( COLOR_BTNFACE ) ) );
  147. HandleToolRedraw( helper );
  148. BaseClass::redraw();
  149. }
  150. int
  151. ControlPanel::handleEvent (mxEvent *event)
  152. {
  153. MDLCACHE_CRITICAL_SECTION_( g_pMDLCache );
  154. int iret = 0;
  155. if ( HandleToolEvent( event ) )
  156. {
  157. return iret;
  158. }
  159. switch ( event->event )
  160. {
  161. case mxEvent::Size:
  162. {
  163. PositionControls( event->width, event->height );
  164. iret = 1;
  165. }
  166. break;
  167. case mxEvent::Action:
  168. {
  169. iret = 1;
  170. switch (event->action)
  171. {
  172. case IDC_TOOLSDRIVEMOUTH:
  173. {
  174. g_viewerSettings.faceposerToolsDriveMouth = ((mxCheckBox *)event->widget)->isChecked();
  175. }
  176. break;
  177. case IDC_TAB:
  178. {
  179. g_viewerSettings.showTexture = (tab->getSelectedIndex() == 3);
  180. }
  181. break;
  182. case IDC_RENDERMODE:
  183. {
  184. int index = cRenderMode->getSelectedIndex();
  185. if (index >= 0)
  186. {
  187. setRenderMode (index);
  188. }
  189. }
  190. break;
  191. case IDC_GROUND:
  192. setShowGround (((mxCheckBox *) event->widget)->isChecked());
  193. break;
  194. case IDC_MOVEMENT:
  195. setShowMovement (((mxCheckBox *) event->widget)->isChecked());
  196. break;
  197. case IDC_BACKGROUND:
  198. setShowBackground (((mxCheckBox *) event->widget)->isChecked());
  199. break;
  200. case IDC_HITBOXES:
  201. g_viewerSettings.showHitBoxes = ((mxCheckBox *) event->widget)->isChecked();
  202. break;
  203. case IDC_PHYSICSMODEL:
  204. g_viewerSettings.showPhysicsModel = ((mxCheckBox *) event->widget)->isChecked();
  205. break;
  206. case IDC_BONES:
  207. g_viewerSettings.showBones = ((mxCheckBox *) event->widget)->isChecked();
  208. break;
  209. case IDC_ATTACHMENTS:
  210. g_viewerSettings.showAttachments = ((mxCheckBox *) event->widget)->isChecked();
  211. break;
  212. case IDC_SEQUENCE:
  213. {
  214. int index = cSequence->getSelectedIndex();
  215. if (index >= 0)
  216. {
  217. setSequence ( index );
  218. }
  219. }
  220. break;
  221. case IDC_SPEEDSCALE:
  222. {
  223. g_viewerSettings.speedScale = ((mxSlider *) event->widget)->getValue();
  224. lSpeedScale->setLabel( va( "Speed scale %.2f", g_viewerSettings.speedScale ) );
  225. }
  226. break;
  227. case IDC_PRIMARYBLEND:
  228. {
  229. setBlend( 0, ((mxSlider *) event->widget)->getValue() );
  230. }
  231. break;
  232. case IDC_SECONDARYBLEND:
  233. {
  234. setBlend( 1, ((mxSlider *) event->widget)->getValue() );
  235. }
  236. break;
  237. case IDC_BODYPART:
  238. {
  239. int index = cBodypart->getSelectedIndex();
  240. if (index >= 0)
  241. {
  242. setBodypart (index);
  243. }
  244. }
  245. break;
  246. case IDC_SUBMODEL:
  247. {
  248. int index = cSubmodel->getSelectedIndex();
  249. if (index >= 0)
  250. {
  251. setSubmodel (index);
  252. }
  253. }
  254. break;
  255. case IDC_CONTROLLER:
  256. {
  257. int index = cController->getSelectedIndex();
  258. if (index >= 0)
  259. setBoneController (index);
  260. }
  261. break;
  262. case IDC_CONTROLLERVALUE:
  263. {
  264. int index = cController->getSelectedIndex();
  265. if (index >= 0)
  266. setBoneControllerValue (index, slController->getValue());
  267. }
  268. break;
  269. case IDC_SKINS:
  270. {
  271. int index = cSkin->getSelectedIndex();
  272. if (index >= 0)
  273. {
  274. models->GetActiveStudioModel()->SetSkin (index);
  275. g_viewerSettings.skin = index;
  276. g_pMatSysWindow->redraw();
  277. }
  278. }
  279. break;
  280. default:
  281. iret = 0;
  282. break;
  283. }
  284. }
  285. }
  286. return iret;
  287. }
  288. void ControlPanel::dumpModelInfo() { }
  289. void ControlPanel::ChangeModel( const char *filename )
  290. {
  291. HCURSOR hPrevCursor = SetCursor( LoadCursor( NULL, IDC_WAIT ) );
  292. // init all the selection tabs based on the current model
  293. initSequenceChoices();
  294. initBodypartChoices();
  295. initBoneControllerChoices();
  296. initSkinChoices();
  297. setModelInfo();
  298. SetCloseCaptionLanguageId( g_viewerSettings.cclanguageid, true );
  299. g_viewerSettings.m_iEditAttachment = -1;
  300. g_viewerSettings.enableIK = true;
  301. g_viewerSettings.enableTargetIK = false;
  302. setSequence( models->GetActiveStudioModel()->GetSequence() );
  303. setSpeed( g_viewerSettings.speedScale );
  304. mx_setcwd (mx_getpath (filename));
  305. g_pFlexPanel->initFlexes();
  306. // centerView();
  307. // CenterOnFace();
  308. IFacePoserToolWindow::ModelChanged();
  309. CExpClass *cl = expressions->GetActiveClass();
  310. if ( cl )
  311. {
  312. cl->SelectExpression( cl->GetSelectedExpression() );
  313. }
  314. SetSuffix( va( " - %s.mdl", models->GetActiveModelName() ) );
  315. redraw();
  316. SetCursor( hPrevCursor );
  317. }
  318. void
  319. ControlPanel::setRenderMode (int mode)
  320. {
  321. g_viewerSettings.renderMode = mode;
  322. g_pMatSysWindow->redraw();
  323. }
  324. void
  325. ControlPanel::setHighlightBone( int index )
  326. {
  327. g_viewerSettings.highlightPhysicsBone = index;
  328. }
  329. void
  330. ControlPanel::setShowGround (bool b)
  331. {
  332. g_viewerSettings.showGround = b;
  333. cbGround->setChecked (b);
  334. }
  335. void
  336. ControlPanel::setShowMovement (bool b)
  337. {
  338. g_viewerSettings.showMovement = b;
  339. cbMovement->setChecked (b);
  340. }
  341. void
  342. ControlPanel::setShowBackground (bool b)
  343. {
  344. g_viewerSettings.showBackground = b;
  345. cbBackground->setChecked (b);
  346. }
  347. void
  348. ControlPanel::initSequenceChoices()
  349. {
  350. CStudioHdr *hdr = models->GetActiveStudioModel()->GetStudioHdr();
  351. if (hdr)
  352. {
  353. cSequence->removeAll();
  354. for (int i = 0; i < hdr->GetNumSeq(); i++)
  355. {
  356. cSequence->add (hdr->pSeqdesc(i).pszLabel());
  357. }
  358. cSequence->select (0);
  359. }
  360. }
  361. void
  362. ControlPanel::setSequence (int index)
  363. {
  364. cSequence->select (index);
  365. models->GetActiveStudioModel()->SetSequence(index);
  366. initPoseParameters( );
  367. }
  368. void
  369. ControlPanel::setSpeed( float value )
  370. {
  371. g_viewerSettings.speedScale = value;
  372. slSpeedScale->setValue( value );
  373. }
  374. void ControlPanel::setBlend(int index, float value )
  375. {
  376. models->GetActiveStudioModel()->SetPoseParameter( index, value );
  377. }
  378. void
  379. ControlPanel::initBodypartChoices()
  380. {
  381. CStudioHdr *hdr = models->GetActiveStudioModel()->GetStudioHdr();
  382. if (hdr)
  383. {
  384. int i;
  385. mstudiobodyparts_t *pbodyparts = hdr->pBodypart(0);
  386. cBodypart->removeAll();
  387. if (hdr->numbodyparts() > 0)
  388. {
  389. for (i = 0; i < hdr->numbodyparts(); i++)
  390. cBodypart->add (pbodyparts[i].pszName());
  391. cBodypart->select (0);
  392. cSubmodel->removeAll();
  393. for (i = 0; i < pbodyparts[0].nummodels; i++)
  394. {
  395. char str[64];
  396. sprintf (str, "Submodel %d", i + 1);
  397. cSubmodel->add (str);
  398. }
  399. cSubmodel->select (0);
  400. }
  401. }
  402. }
  403. void
  404. ControlPanel::setBodypart (int index)
  405. {
  406. CStudioHdr *hdr = models->GetActiveStudioModel()->GetStudioHdr();
  407. if (hdr)
  408. {
  409. //cBodypart->setEn
  410. cBodypart->select (index);
  411. if (index < hdr->numbodyparts())
  412. {
  413. mstudiobodyparts_t *pbodyparts = hdr->pBodypart(0);
  414. cSubmodel->removeAll();
  415. for (int i = 0; i < pbodyparts[index].nummodels; i++)
  416. {
  417. char str[64];
  418. sprintf (str, "Submodel %d", i + 1);
  419. cSubmodel->add (str);
  420. }
  421. cSubmodel->select (0);
  422. //models->GetActiveStudioModel()->SetBodygroup (index, 0);
  423. }
  424. }
  425. }
  426. void
  427. ControlPanel::setSubmodel (int index)
  428. {
  429. models->GetActiveStudioModel()->SetBodygroup (cBodypart->getSelectedIndex(), index);
  430. }
  431. void
  432. ControlPanel::initBoneControllerChoices()
  433. {
  434. CStudioHdr *hdr = models->GetActiveStudioModel()->GetStudioHdr();
  435. if (hdr)
  436. {
  437. cController->setEnabled (hdr->numbonecontrollers() > 0);
  438. slController->setEnabled (hdr->numbonecontrollers() > 0);
  439. cController->removeAll();
  440. for (int i = 0; i < hdr->numbonecontrollers(); i++)
  441. {
  442. mstudiobonecontroller_t *pbonecontroller = hdr->pBonecontroller(i);
  443. char str[32];
  444. sprintf (str, "Controller %d", pbonecontroller->inputfield);
  445. cController->add (str);
  446. }
  447. if (hdr->numbonecontrollers() > 0)
  448. {
  449. mstudiobonecontroller_t *pbonecontrollers = hdr->pBonecontroller(0);
  450. cController->select (0);
  451. slController->setRange (pbonecontrollers->start, pbonecontrollers->end);
  452. slController->setValue (0);
  453. }
  454. }
  455. }
  456. void
  457. ControlPanel::setBoneController (int index)
  458. {
  459. CStudioHdr *hdr = models->GetActiveStudioModel()->GetStudioHdr();
  460. if (hdr)
  461. {
  462. mstudiobonecontroller_t *pbonecontroller = hdr->pBonecontroller(index);
  463. slController->setRange ( pbonecontroller->start, pbonecontroller->end);
  464. slController->setValue (0);
  465. }
  466. }
  467. void
  468. ControlPanel::setBoneControllerValue (int index, float value)
  469. {
  470. CStudioHdr *hdr = models->GetActiveStudioModel()->GetStudioHdr();
  471. if (hdr)
  472. {
  473. mstudiobonecontroller_t *pbonecontrollers = hdr->pBonecontroller(index);
  474. models->GetActiveStudioModel()->SetController (pbonecontrollers->inputfield, value);
  475. }
  476. }
  477. void
  478. ControlPanel::initPoseParameters()
  479. {
  480. CStudioHdr *hdr = models->GetActiveStudioModel()->GetStudioHdr();
  481. if (hdr)
  482. {
  483. for (int i = 0; i < hdr->GetNumPoseParameters(); i++)
  484. {
  485. setBlend( i, 0.0 );
  486. }
  487. }
  488. }
  489. void
  490. ControlPanel::initSkinChoices()
  491. {
  492. CStudioHdr *hdr = models->GetActiveStudioModel()->GetStudioHdr();
  493. if (hdr)
  494. {
  495. cSkin->setEnabled (hdr->numskinfamilies() > 0);
  496. cSkin->removeAll();
  497. for (int i = 0; i < hdr->numskinfamilies(); i++)
  498. {
  499. char str[32];
  500. sprintf (str, "Skin %d", i + 1);
  501. cSkin->add (str);
  502. }
  503. cSkin->select (0);
  504. models->GetActiveStudioModel()->SetSkin (0);
  505. g_viewerSettings.skin = 0;
  506. }
  507. }
  508. void
  509. ControlPanel::setModelInfo()
  510. {
  511. static char str[2048];
  512. CStudioHdr *hdr = models->GetActiveStudioModel()->GetStudioHdr();
  513. if (!hdr)
  514. return;
  515. int hbcount = 0;
  516. for ( int s = 0; s < hdr->numhitboxsets(); s++ )
  517. {
  518. hbcount += hdr->iHitboxCount( s );
  519. }
  520. sprintf (str,
  521. "Bones: %d\n"
  522. "Bone Controllers: %d\n"
  523. "Hit Boxes: %d in %d sets\n"
  524. "Sequences: %d\n",
  525. hdr->numbones(),
  526. hdr->numbonecontrollers(),
  527. hbcount,
  528. hdr->numhitboxsets(),
  529. hdr->GetNumSeq()
  530. );
  531. lModelInfo1->setLabel (str);
  532. sprintf (str,
  533. "Textures: %d\n"
  534. "Skin Families: %d\n"
  535. "Bodyparts: %d\n"
  536. "Attachments: %d\n",
  537. hdr->numtextures(),
  538. hdr->numskinfamilies(),
  539. hdr->numbodyparts(),
  540. hdr->GetNumAttachments());
  541. lModelInfo2->setLabel (str);
  542. }
  543. void ControlPanel::CenterOnFace( void )
  544. {
  545. if ( !models->GetActiveStudioModel() )
  546. return;
  547. StudioModel *mdl = models->GetActiveStudioModel();
  548. if ( !mdl )
  549. return;
  550. CStudioHdr *hdr = mdl->GetStudioHdr();
  551. if ( !hdr )
  552. return;
  553. setSpeed( 1.0f );
  554. int oldSeq = models->GetActiveStudioModel()->GetSequence();
  555. int seq = models->GetActiveStudioModel()->LookupSequence( "idle_suble" );
  556. if ( seq == -1 )
  557. seq = 0;
  558. if ( seq != oldSeq )
  559. {
  560. Con_Printf( "Centering changed model sequence # to %d\n", seq );
  561. }
  562. setSequence( seq );
  563. initPoseParameters( );
  564. mdl->m_angles.Init();
  565. mdl->m_origin.Init();
  566. Vector size;
  567. VectorSubtract( hdr->hull_max(), hdr->hull_min(), size );
  568. float eyeheight = hdr->hull_min().z + 0.9 * size.z;
  569. if ( hdr->GetNumAttachments() > 0 )
  570. {
  571. for (int i = 0; i < hdr->GetNumAttachments(); i++)
  572. {
  573. const mstudioattachment_t &attachment = hdr->pAttachment( i );
  574. int iBone = hdr->GetAttachmentBone( i );
  575. if ( Q_stricmp( attachment.pszName(), "eyes" ) )
  576. continue;
  577. const mstudiobone_t *bone = hdr->pBone( iBone );
  578. if ( !bone )
  579. continue;
  580. matrix3x4_t boneToPose;
  581. MatrixInvert( bone->poseToBone, boneToPose );
  582. matrix3x4_t attachmentPoseToLocal;
  583. ConcatTransforms( boneToPose, attachment.local, attachmentPoseToLocal );
  584. Vector localSpaceEyePosition;
  585. VectorITransform( vec3_origin, attachmentPoseToLocal, localSpaceEyePosition );
  586. // Not sure why this must be negative?
  587. eyeheight = -localSpaceEyePosition.z + hdr->hull_min().z;
  588. break;
  589. }
  590. }
  591. KeyValues *seqKeyValues = new KeyValues("");
  592. if ( seqKeyValues->LoadFromBuffer( mdl->GetFileName( ), mdl->GetKeyValueText( seq ) ) )
  593. {
  594. // Do we have a build point section?
  595. KeyValues *pkvAllFaceposer = seqKeyValues->FindKey("faceposer");
  596. if ( pkvAllFaceposer )
  597. {
  598. float flEyeheight = pkvAllFaceposer->GetFloat( "eye_height", -9999.0f );
  599. if ( flEyeheight != -9999.0f )
  600. {
  601. eyeheight = flEyeheight;
  602. }
  603. }
  604. }
  605. seqKeyValues->deleteThis();
  606. mdl->m_origin.x = size.z * .65f;
  607. mdl->m_origin.z += eyeheight;
  608. CUtlVector< StudioModel * > modellist;
  609. modellist.AddToTail( models->GetActiveStudioModel() );
  610. int i;
  611. if ( models->CountVisibleModels() > 0 )
  612. {
  613. modellist.RemoveAll();
  614. for ( i = 0; i < models->Count(); i++ )
  615. {
  616. if ( models->IsModelShownIn3DView( i ) )
  617. {
  618. modellist.AddToTail( models->GetStudioModel( i ) );
  619. }
  620. }
  621. }
  622. int modelcount = modellist.Count();
  623. int countover2 = modelcount / 2;
  624. int ydelta = GetModelGap();
  625. int yoffset = -countover2 * ydelta;
  626. for ( i = 0 ; i < modelcount; i++ )
  627. {
  628. if ( models->GetStudioHeader( i ) == hdr )
  629. {
  630. mdl->m_origin.y = -yoffset;
  631. }
  632. yoffset += ydelta;
  633. }
  634. g_pMatSysWindow->redraw();
  635. }
  636. //-----------------------------------------------------------------------------
  637. // Purpose:
  638. // Output : float
  639. //-----------------------------------------------------------------------------
  640. float ControlPanel::GetModelGap( void )
  641. {
  642. return slModelGap->getValue();
  643. }
  644. void
  645. ControlPanel::centerView()
  646. {
  647. StudioModel *pModel = models->GetActiveStudioModel();
  648. if ( !pModel )
  649. return;
  650. Vector min, max;
  651. models->GetActiveStudioModel()->ExtractBbox (min, max);
  652. float dx = max[0] - min[0];
  653. float dy = max[1] - min[1];
  654. float dz = max[2] - min[2];
  655. float d = dx;
  656. if (dy > d)
  657. d = dy;
  658. if (dz > d)
  659. d = dz;
  660. pModel->m_origin[0] = d * 1.0f;
  661. pModel->m_origin[1] = 0;
  662. pModel->m_origin[2] = min[2] + dz / 2;
  663. pModel->m_angles[0] = 0.0f;
  664. pModel->m_angles[1] = 0.0f;
  665. pModel->m_angles[2] = 0.0f;
  666. g_viewerSettings.lightrot.x = 0.f;
  667. g_viewerSettings.lightrot.y = -180.0f;
  668. g_viewerSettings.lightrot.z = 0.0f;
  669. g_pMatSysWindow->redraw();
  670. }
  671. bool ControlPanel::Close()
  672. {
  673. int index = g_pExpressionClass->getSelectedIndex();
  674. CExpClass *cl = expressions->GetClass( index );
  675. if ( !cl )
  676. return true;
  677. return expressions->CloseClass( cl );
  678. }
  679. bool ControlPanel::Closeall()
  680. {
  681. bool retval = true;
  682. while ( expressions->GetNumClasses() > 0 )
  683. {
  684. CExpClass *cl = expressions->GetClass( 0 );
  685. if ( !cl )
  686. break;
  687. if ( !expressions->CloseClass( cl ) )
  688. {
  689. return false;
  690. }
  691. }
  692. return retval;
  693. }
  694. //-----------------------------------------------------------------------------
  695. // Purpose:
  696. //-----------------------------------------------------------------------------
  697. void ControlPanel::Copy( void )
  698. {
  699. g_pFlexPanel->CopyControllerSettings();
  700. }
  701. //-----------------------------------------------------------------------------
  702. // Purpose:
  703. //-----------------------------------------------------------------------------
  704. void ControlPanel::Paste( void )
  705. {
  706. g_pFlexPanel->PasteControllerSettings();
  707. }
  708. //-----------------------------------------------------------------------------
  709. // Purpose:
  710. //-----------------------------------------------------------------------------
  711. void ControlPanel::Undo( void )
  712. {
  713. CExpClass *active = expressions->GetActiveClass();
  714. if ( !active )
  715. return;
  716. int index = active->GetSelectedExpression();
  717. if ( index != -1 )
  718. {
  719. UndoExpression( index );
  720. }
  721. }
  722. //-----------------------------------------------------------------------------
  723. // Purpose:
  724. //-----------------------------------------------------------------------------
  725. void ControlPanel::Redo( void )
  726. {
  727. CExpClass *active = expressions->GetActiveClass();
  728. if ( !active )
  729. return;
  730. int index = active->GetSelectedExpression();
  731. if ( index != -1 )
  732. {
  733. RedoExpression( index );
  734. }
  735. }
  736. //-----------------------------------------------------------------------------
  737. // Purpose:
  738. //-----------------------------------------------------------------------------
  739. void ControlPanel::UndoExpression( int index )
  740. {
  741. if ( index == -1 )
  742. return;
  743. CExpClass *active = expressions->GetActiveClass();
  744. if ( !active )
  745. return;
  746. CExpression *exp = active->GetExpression( index );
  747. if ( exp )
  748. {
  749. exp->Undo();
  750. // Show the updated data
  751. active->SelectExpression( index );
  752. }
  753. }
  754. //-----------------------------------------------------------------------------
  755. // Purpose:
  756. //-----------------------------------------------------------------------------
  757. void ControlPanel::RedoExpression( int index )
  758. {
  759. if ( index == -1 )
  760. return;
  761. CExpClass *active = expressions->GetActiveClass();
  762. if ( !active )
  763. return;
  764. CExpression *exp = active->GetExpression( index );
  765. if ( exp )
  766. {
  767. exp->Redo();
  768. // Show the updated data
  769. active->SelectExpression( index );
  770. }
  771. }
  772. void ControlPanel::DeleteExpression( int index )
  773. {
  774. CExpClass *active = expressions->GetActiveClass();
  775. if ( !active )
  776. return;
  777. CExpression *exp = active->GetExpression( index );
  778. if ( exp )
  779. {
  780. Con_Printf( "Deleting expression %s : %s\n", exp->name, exp->description );
  781. g_pFlexPanel->DeleteExpression( index );
  782. active->SelectExpression( max( 0, index - 1 ) );
  783. }
  784. }
  785. //-----------------------------------------------------------------------------
  786. // Purpose:
  787. // Input : dt -
  788. //-----------------------------------------------------------------------------
  789. void ControlPanel::Think( float dt )
  790. {
  791. }
  792. //-----------------------------------------------------------------------------
  793. // Purpose:
  794. // Output : Returns true on success, false on failure.
  795. //-----------------------------------------------------------------------------
  796. bool ControlPanel::AllToolsDriveSpeech( void )
  797. {
  798. return cbAllWindowsDriveSpeech->isChecked();
  799. }