llpreviewanim.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /**
  2. * @file llpreviewanim.cpp
  3. * @brief LLPreviewAnim class implementation
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewergpl$
  6. *
  7. * Copyright (c) 2004-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llpreviewanim.h"
  34. #include "llbutton.h"
  35. #include "llkeyframemotion.h"
  36. #include "lllineeditor.h"
  37. #include "lluictrlfactory.h"
  38. #include "llagent.h"
  39. #include "llvoavatarself.h"
  40. LLPreviewAnim::LLPreviewAnim(const std::string& name, const LLRect& rect,
  41. const std::string& title, const LLUUID& item_uuid,
  42. S32 activate, const LLUUID& object_uuid)
  43. : LLPreview(name, rect, title, item_uuid, object_uuid)
  44. {
  45. LLUICtrlFactory::getInstance()->buildFloater(this,
  46. "floater_preview_animation.xml");
  47. childSetAction("Anim play btn", playAnim, this);
  48. childSetAction("Anim audition btn", auditionAnim, this);
  49. const LLInventoryItem* item = getItem();
  50. childSetCommitCallback("desc", LLPreview::onText, this);
  51. childSetText("desc", item->getDescription());
  52. childSetPrevalidate("desc", &LLLineEditor::prevalidatePrintableNotPipe);
  53. setTitle(title);
  54. if (!getHost())
  55. {
  56. LLRect curRect = getRect();
  57. translate(rect.mLeft - curRect.mLeft, rect.mTop - curRect.mTop);
  58. }
  59. switch (activate)
  60. {
  61. case 1:
  62. refreshFromItem(); // Pre-load the animation immediately
  63. playAnim((void*)this);
  64. break;
  65. case 2:
  66. refreshFromItem(); // Pre-load the animation immediately
  67. auditionAnim((void*)this);
  68. break;
  69. default:
  70. break;
  71. }
  72. }
  73. //virtual
  74. void LLPreviewAnim::refreshFromItem()
  75. {
  76. const LLInventoryItem* item = getItem();
  77. if (!item || !isAgentAvatarValid())
  78. {
  79. return;
  80. }
  81. // Preload the animation
  82. LLMotion* motionp = gAgentAvatarp->createMotion(item->getAssetUUID());
  83. if (motionp)
  84. {
  85. motionp->setName(item->getName());
  86. }
  87. LLPreview::refreshFromItem();
  88. }
  89. //static
  90. void LLPreviewAnim::endAnimCallback(void* userdata)
  91. {
  92. LLHandle<LLFloater>* handlep = ((LLHandle<LLFloater>*)userdata);
  93. LLFloater* self = handlep->get();
  94. delete handlep; // Done with the handle
  95. if (self)
  96. {
  97. self->childSetValue("Anim play btn", false);
  98. self->childSetValue("Anim audition btn", false);
  99. }
  100. }
  101. //static
  102. void LLPreviewAnim::playAnim(void* userdata)
  103. {
  104. LLPreviewAnim* self = (LLPreviewAnim*)userdata;
  105. if (!self || !isAgentAvatarValid())
  106. {
  107. return;
  108. }
  109. const LLInventoryItem* item = self->getItem();
  110. if (!item)
  111. {
  112. return;
  113. }
  114. LLButton* btn = self->getChild<LLButton>("Anim play btn");
  115. if (btn)
  116. {
  117. btn->toggleState();
  118. }
  119. const LLUUID& id = item->getAssetUUID();
  120. if (!self->childGetValue("Anim play btn").asBoolean())
  121. {
  122. gAgentAvatarp->stopMotion(id);
  123. gAgent.sendAnimationRequest(id, ANIM_REQUEST_STOP);
  124. return;
  125. }
  126. self->mPauseRequest = NULL;
  127. gAgent.sendAnimationRequest(id, ANIM_REQUEST_START);
  128. LLMotion* motion = gAgentAvatarp->findMotion(id);
  129. if (!motion)
  130. {
  131. return;
  132. }
  133. motion->setDeactivateCallback(&endAnimCallback,
  134. (void*)(new LLHandle<LLFloater>(self->getHandle())));
  135. }
  136. //static
  137. void LLPreviewAnim::auditionAnim(void* userdata)
  138. {
  139. LLPreviewAnim* self = (LLPreviewAnim*)userdata;
  140. if (!self || !isAgentAvatarValid())
  141. {
  142. return;
  143. }
  144. const LLInventoryItem* item = self->getItem();
  145. if (!item)
  146. {
  147. return;
  148. }
  149. LLButton* btn = self->getChild<LLButton>("Anim audition btn");
  150. if (btn)
  151. {
  152. btn->toggleState();
  153. }
  154. const LLUUID& id = item->getAssetUUID();
  155. if (!self->childGetValue("Anim audition btn").asBoolean())
  156. {
  157. gAgentAvatarp->stopMotion(id);
  158. gAgent.sendAnimationRequest(id, ANIM_REQUEST_STOP);
  159. return;
  160. }
  161. self->mPauseRequest = NULL;
  162. gAgentAvatarp->startMotion(id);
  163. LLMotion* motion = gAgentAvatarp->findMotion(id);
  164. if (!motion)
  165. {
  166. return;
  167. }
  168. motion->setDeactivateCallback(&endAnimCallback,
  169. (void*)(new LLHandle<LLFloater>(self->getHandle())));
  170. }
  171. void LLPreviewAnim::onClose(bool app_quitting)
  172. {
  173. const LLInventoryItem* item = getItem();
  174. if (item && isAgentAvatarValid())
  175. {
  176. const LLUUID& id = item->getAssetUUID();
  177. gAgentAvatarp->stopMotion(id);
  178. gAgent.sendAnimationRequest(id, ANIM_REQUEST_STOP);
  179. }
  180. LLFloater::onClose(app_quitting);
  181. }