/indra/newview/llpreviewanim.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 187 lines · 133 code · 22 blank · 32 comment · 13 complexity · b6351e626b4707f5915b1d9e0a4dd7f5 MD5 · raw file

  1. /**
  2. * @file llpreviewanim.cpp
  3. * @brief LLPreviewAnim class implementation
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llpreviewanim.h"
  28. #include "llbutton.h"
  29. #include "llresmgr.h"
  30. #include "llinventory.h"
  31. #include "llvoavatarself.h"
  32. #include "llagent.h" // gAgent
  33. #include "llkeyframemotion.h"
  34. #include "llfilepicker.h"
  35. #include "lllineeditor.h"
  36. #include "lluictrlfactory.h"
  37. #include "lluictrlfactory.h"
  38. extern LLAgent gAgent;
  39. LLPreviewAnim::LLPreviewAnim(const LLSD& key)
  40. : LLPreview( key )
  41. {
  42. }
  43. // static
  44. void LLPreviewAnim::endAnimCallback( void *userdata )
  45. {
  46. LLHandle<LLFloater>* handlep = ((LLHandle<LLFloater>*)userdata);
  47. LLFloater* self = handlep->get();
  48. delete handlep; // done with the handle
  49. if (self)
  50. {
  51. self->getChild<LLUICtrl>("Anim play btn")->setValue(FALSE);
  52. self->getChild<LLUICtrl>("Anim audition btn")->setValue(FALSE);
  53. }
  54. }
  55. // virtual
  56. BOOL LLPreviewAnim::postBuild()
  57. {
  58. const LLInventoryItem* item = getItem();
  59. if(item)
  60. {
  61. gAgentAvatarp->createMotion(item->getAssetUUID()); // preload the animation
  62. getChild<LLUICtrl>("desc")->setValue(item->getDescription());
  63. }
  64. childSetAction("Anim play btn",playAnim, this);
  65. childSetAction("Anim audition btn",auditionAnim, this);
  66. childSetCommitCallback("desc", LLPreview::onText, this);
  67. getChild<LLLineEditor>("desc")->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
  68. return LLPreview::postBuild();
  69. }
  70. void LLPreviewAnim::activate(e_activation_type type)
  71. {
  72. switch ( type )
  73. {
  74. case PLAY:
  75. {
  76. playAnim( (void *) this );
  77. break;
  78. }
  79. case AUDITION:
  80. {
  81. auditionAnim( (void *) this );
  82. break;
  83. }
  84. default:
  85. {
  86. //do nothing
  87. }
  88. }
  89. }
  90. // static
  91. void LLPreviewAnim::playAnim( void *userdata )
  92. {
  93. LLPreviewAnim* self = (LLPreviewAnim*) userdata;
  94. const LLInventoryItem *item = self->getItem();
  95. if(item)
  96. {
  97. LLUUID itemID=item->getAssetUUID();
  98. LLButton* btn = self->getChild<LLButton>("Anim play btn");
  99. if (btn)
  100. {
  101. btn->toggleState();
  102. }
  103. if (self->getChild<LLUICtrl>("Anim play btn")->getValue().asBoolean() )
  104. {
  105. self->mPauseRequest = NULL;
  106. gAgent.sendAnimationRequest(itemID, ANIM_REQUEST_START);
  107. LLMotion* motion = gAgentAvatarp->findMotion(itemID);
  108. if (motion)
  109. {
  110. motion->setDeactivateCallback(&endAnimCallback, (void *)(new LLHandle<LLFloater>(self->getHandle())));
  111. }
  112. }
  113. else
  114. {
  115. gAgentAvatarp->stopMotion(itemID);
  116. gAgent.sendAnimationRequest(itemID, ANIM_REQUEST_STOP);
  117. }
  118. }
  119. }
  120. // static
  121. void LLPreviewAnim::auditionAnim( void *userdata )
  122. {
  123. LLPreviewAnim* self = (LLPreviewAnim*) userdata;
  124. const LLInventoryItem *item = self->getItem();
  125. if(item)
  126. {
  127. LLUUID itemID=item->getAssetUUID();
  128. LLButton* btn = self->getChild<LLButton>("Anim audition btn");
  129. if (btn)
  130. {
  131. btn->toggleState();
  132. }
  133. if (self->getChild<LLUICtrl>("Anim audition btn")->getValue().asBoolean() )
  134. {
  135. self->mPauseRequest = NULL;
  136. gAgentAvatarp->startMotion(item->getAssetUUID());
  137. LLMotion* motion = gAgentAvatarp->findMotion(itemID);
  138. if (motion)
  139. {
  140. motion->setDeactivateCallback(&endAnimCallback, (void *)(new LLHandle<LLFloater>(self->getHandle())));
  141. }
  142. }
  143. else
  144. {
  145. gAgentAvatarp->stopMotion(itemID);
  146. gAgent.sendAnimationRequest(itemID, ANIM_REQUEST_STOP);
  147. }
  148. }
  149. }
  150. // virtual
  151. void LLPreviewAnim::onClose(bool app_quitting)
  152. {
  153. const LLInventoryItem *item = getItem();
  154. if(item)
  155. {
  156. gAgentAvatarp->stopMotion(item->getAssetUUID());
  157. gAgent.sendAnimationRequest(item->getAssetUUID(), ANIM_REQUEST_STOP);
  158. LLMotion* motion = gAgentAvatarp->findMotion(item->getAssetUUID());
  159. if (motion)
  160. {
  161. // *TODO: minor memory leak here, user data is never deleted (Use real callbacks)
  162. motion->setDeactivateCallback(NULL, (void *)NULL);
  163. }
  164. }
  165. }