aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llpreviewanim.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llpreviewanim.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llpreviewanim.cpp')
-rw-r--r--linden/indra/newview/llpreviewanim.cpp216
1 files changed, 216 insertions, 0 deletions
diff --git a/linden/indra/newview/llpreviewanim.cpp b/linden/indra/newview/llpreviewanim.cpp
new file mode 100644
index 0000000..bd619b4
--- /dev/null
+++ b/linden/indra/newview/llpreviewanim.cpp
@@ -0,0 +1,216 @@
1/**
2 * @file llpreviewanim.cpp
3 * @brief LLPreviewAnim class implementation
4 *
5 * Copyright (c) 2004-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "llpreviewanim.h"
31#include "llbutton.h"
32#include "llresmgr.h"
33#include "llinventory.h"
34#include "llinventoryview.h"
35#include "llvoavatar.h"
36#include "llagent.h" // gAgent
37#include "llkeyframemotion.h"
38#include "llfilepicker.h"
39#include "lllineeditor.h"
40#include "lluictrlfactory.h"
41#include "llvieweruictrlfactory.h"
42
43extern LLAgent gAgent;
44
45LLPreviewAnim::LLPreviewAnim(const std::string& name, const LLRect& rect, const std::string& title, const LLUUID& item_uuid, const S32& activate, const LLUUID& object_uuid ) :
46 LLPreview( name, rect, title, item_uuid, object_uuid)
47{
48 gUICtrlFactory->buildFloater(this,"floater_preview_animation.xml");
49
50 childSetAction("Anim play btn",playAnim,this);
51 childSetAction("Anim audition btn",auditionAnim,this);
52
53 LLInventoryItem* item = getItem();
54
55 childSetCommitCallback("desc", LLPreview::onText, this);
56 childSetText("desc", item->getDescription());
57 childSetPrevalidate("desc", &LLLineEditor::prevalidatePrintableNotPipe);
58
59 setTitle(title);
60
61 if (!getHost())
62 {
63 LLRect curRect = getRect();
64 translate(rect.mLeft - curRect.mLeft, rect.mTop - curRect.mTop);
65 }
66
67 // preload the animation
68 if(item)
69 {
70 gAgent.getAvatarObject()->createMotion(item->getAssetUUID());
71 }
72
73 switch ( activate )
74 {
75 case 1:
76 {
77 playAnim( (void *) this );
78 break;
79 }
80 case 2:
81 {
82 auditionAnim( (void *) this );
83 break;
84 }
85 default:
86 {
87 //do nothing
88 }
89 }
90}
91
92// static
93void LLPreviewAnim::endAnimCallback( void *userdata )
94{
95 LLPreviewAnim* self = (LLPreviewAnim*) userdata;
96
97 self->childSetValue("Anim play btn", FALSE);
98 self->childSetValue("Anim audition btn", FALSE);
99
100}
101
102// static
103void LLPreviewAnim::playAnim( void *userdata )
104{
105 LLPreviewAnim* self = (LLPreviewAnim*) userdata;
106 LLInventoryItem *item = self->getItem();
107
108 if(item)
109 {
110 LLUUID itemID=item->getAssetUUID();
111
112 LLButton* btn = LLUICtrlFactory::getButtonByName(self, "Anim play btn");
113 if (btn)
114 {
115 btn->toggleState();
116 }
117
118 if (self->childGetValue("Anim play btn").asBoolean() )
119 {
120 self->mPauseRequest = NULL;
121 gAgent.sendAnimationRequest(itemID, ANIM_REQUEST_START);
122
123 LLVOAvatar* avatar = gAgent.getAvatarObject();
124 LLMotion* motion = avatar->findMotion(itemID);
125
126 if (motion)
127 motion->setDeactivateCallback(&endAnimCallback, (void *)self);
128 }
129 else
130 {
131 gAgent.getAvatarObject()->stopMotion(itemID);
132 gAgent.sendAnimationRequest(itemID, ANIM_REQUEST_STOP);
133 }
134 }
135}
136
137// static
138void LLPreviewAnim::auditionAnim( void *userdata )
139{
140 LLPreviewAnim* self = (LLPreviewAnim*) userdata;
141 LLInventoryItem *item = self->getItem();
142
143 if(item)
144 {
145 LLUUID itemID=item->getAssetUUID();
146
147 LLButton* btn = LLUICtrlFactory::getButtonByName(self, "Anim audition btn");
148 if (btn)
149 {
150 btn->toggleState();
151 }
152
153 if (self->childGetValue("Anim audition btn").asBoolean() )
154 {
155 self->mPauseRequest = NULL;
156 gAgent.getAvatarObject()->startMotion(item->getAssetUUID());
157
158 LLVOAvatar* avatar = gAgent.getAvatarObject();
159 LLMotion* motion = avatar->findMotion(itemID);
160
161 if (motion)
162 motion->setDeactivateCallback(&endAnimCallback, (void *)self);
163 }
164 else
165 {
166 gAgent.getAvatarObject()->stopMotion(itemID);
167 gAgent.sendAnimationRequest(itemID, ANIM_REQUEST_STOP);
168 }
169 }
170}
171
172void LLPreviewAnim::saveAnim( void *userdata )
173{
174 LLPreviewAnim* self = (LLPreviewAnim*) userdata;
175 LLInventoryItem *item = self->getItem();
176
177 if(item)
178 {
179 LLKeyframeMotion* motionp = (LLKeyframeMotion*)gAgent.getAvatarObject()->createMotion( item->getAssetUUID() );
180 if (motionp && motionp->isLoaded())
181 {
182 LLFilePicker& picker = LLFilePicker::instance();
183 LLString proposed_name = item->getName() + LLString(".xaf");
184 if (picker.getSaveFile(LLFilePicker::FFSAVE_ANIM, proposed_name.c_str()))
185 {
186 apr_file_t* fp = ll_apr_file_open(picker.getFirstFile(), LL_APR_W);
187 if (!fp)
188 {
189 llwarns << "Unable to open file " << picker.getFirstFile() << llendl;
190 return;
191 }
192 motionp->writeCAL3D(fp);
193 apr_file_close(fp);
194 }
195 }
196 }
197}
198
199void LLPreviewAnim::onClose(bool app_quitting)
200{
201 LLInventoryItem *item = getItem();
202
203 if(item)
204 {
205 gAgent.getAvatarObject()->stopMotion(item->getAssetUUID());
206 gAgent.sendAnimationRequest(item->getAssetUUID(), ANIM_REQUEST_STOP);
207
208 LLVOAvatar* avatar = gAgent.getAvatarObject();
209 LLMotion* motion = avatar->findMotion(item->getAssetUUID());
210
211 if (motion)
212 motion->setDeactivateCallback(NULL, (void *)NULL);
213
214 }
215 destroy();
216}