PageRenderTime 53ms CodeModel.GetById 20ms app.highlight 17ms RepoModel.GetById 13ms app.codeStats 1ms

/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
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llpreviewanim.h"
 30#include "llbutton.h"
 31#include "llresmgr.h"
 32#include "llinventory.h"
 33#include "llvoavatarself.h"
 34#include "llagent.h"          // gAgent
 35#include "llkeyframemotion.h"
 36#include "llfilepicker.h"
 37#include "lllineeditor.h"
 38#include "lluictrlfactory.h"
 39#include "lluictrlfactory.h"
 40
 41extern LLAgent gAgent;
 42
 43LLPreviewAnim::LLPreviewAnim(const LLSD& key)
 44	: LLPreview( key )
 45{
 46}
 47
 48// static
 49void LLPreviewAnim::endAnimCallback( void *userdata )
 50{
 51	LLHandle<LLFloater>* handlep = ((LLHandle<LLFloater>*)userdata);
 52	LLFloater* self = handlep->get();
 53	delete handlep; // done with the handle
 54	if (self)
 55	{
 56		self->getChild<LLUICtrl>("Anim play btn")->setValue(FALSE);
 57		self->getChild<LLUICtrl>("Anim audition btn")->setValue(FALSE);
 58	}
 59}
 60
 61// virtual
 62BOOL LLPreviewAnim::postBuild()
 63{
 64	const LLInventoryItem* item = getItem();
 65	if(item)
 66	{
 67		gAgentAvatarp->createMotion(item->getAssetUUID()); // preload the animation
 68		getChild<LLUICtrl>("desc")->setValue(item->getDescription());
 69	}
 70
 71	childSetAction("Anim play btn",playAnim, this);
 72	childSetAction("Anim audition btn",auditionAnim, this);
 73
 74	childSetCommitCallback("desc", LLPreview::onText, this);
 75	getChild<LLLineEditor>("desc")->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
 76	
 77	return LLPreview::postBuild();
 78}
 79
 80void LLPreviewAnim::activate(e_activation_type type)
 81{
 82	switch ( type ) 
 83	{
 84		case PLAY:
 85		{
 86			playAnim( (void *) this );
 87			break;
 88		}
 89		case AUDITION:
 90		{
 91			auditionAnim( (void *) this );
 92			break;
 93		}
 94		default:
 95		{
 96		//do nothing
 97		}
 98	}
 99}
100
101// static
102void LLPreviewAnim::playAnim( void *userdata )
103{
104	LLPreviewAnim* self = (LLPreviewAnim*) userdata;
105	const LLInventoryItem *item = self->getItem();
106
107	if(item)
108	{
109		LLUUID itemID=item->getAssetUUID();
110
111		LLButton* btn = self->getChild<LLButton>("Anim play btn");
112		if (btn)
113		{
114			btn->toggleState();
115		}
116		
117		if (self->getChild<LLUICtrl>("Anim play btn")->getValue().asBoolean() ) 
118		{
119			self->mPauseRequest = NULL;
120			gAgent.sendAnimationRequest(itemID, ANIM_REQUEST_START);
121			LLMotion* motion = gAgentAvatarp->findMotion(itemID);
122			if (motion)
123			{
124				motion->setDeactivateCallback(&endAnimCallback, (void *)(new LLHandle<LLFloater>(self->getHandle())));
125			}
126		}
127		else
128		{
129			gAgentAvatarp->stopMotion(itemID);
130			gAgent.sendAnimationRequest(itemID, ANIM_REQUEST_STOP);
131		}
132	}
133}
134
135// static
136void LLPreviewAnim::auditionAnim( void *userdata )
137{
138	LLPreviewAnim* self = (LLPreviewAnim*) userdata;
139	const LLInventoryItem *item = self->getItem();
140
141	if(item)
142	{
143		LLUUID itemID=item->getAssetUUID();
144
145		LLButton* btn = self->getChild<LLButton>("Anim audition btn");
146		if (btn)
147		{
148			btn->toggleState();
149		}
150		
151		if (self->getChild<LLUICtrl>("Anim audition btn")->getValue().asBoolean() ) 
152		{
153			self->mPauseRequest = NULL;
154			gAgentAvatarp->startMotion(item->getAssetUUID());
155			LLMotion* motion = gAgentAvatarp->findMotion(itemID);
156			
157			if (motion)
158			{
159				motion->setDeactivateCallback(&endAnimCallback, (void *)(new LLHandle<LLFloater>(self->getHandle())));
160			}
161		}
162		else
163		{
164			gAgentAvatarp->stopMotion(itemID);
165			gAgent.sendAnimationRequest(itemID, ANIM_REQUEST_STOP);
166		}
167	}
168}
169
170// virtual
171void LLPreviewAnim::onClose(bool app_quitting)
172{
173	const LLInventoryItem *item = getItem();
174
175	if(item)
176	{
177		gAgentAvatarp->stopMotion(item->getAssetUUID());
178		gAgent.sendAnimationRequest(item->getAssetUUID(), ANIM_REQUEST_STOP);
179		LLMotion* motion = gAgentAvatarp->findMotion(item->getAssetUUID());
180		
181		if (motion)
182		{
183			// *TODO: minor memory leak here, user data is never deleted (Use real callbacks)
184			motion->setDeactivateCallback(NULL, (void *)NULL);
185		}
186	}
187}