|
@@ -36,10 +36,6 @@
|
|
|
#include "graphics/dgl.h"
|
|
|
#endif
|
|
|
|
|
|
-#ifndef _RENDER_PROXY_H_
|
|
|
-#include "2d/core/RenderProxy.h"
|
|
|
-#endif
|
|
|
-
|
|
|
#include "guiSpriteCtrl_ScriptBindings.h"
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
@@ -50,23 +46,16 @@ IMPLEMENT_CONOBJECT(GuiSpriteCtrl);
|
|
|
|
|
|
GuiSpriteCtrl::GuiSpriteCtrl( void ) :
|
|
|
mImageAssetId( StringTable->EmptyString ),
|
|
|
- mAnimationAssetId( StringTable->EmptyString ),
|
|
|
- mImageFrame( 0 ),
|
|
|
- mAnimationPaused( false ),
|
|
|
- mpAnimationController(NULL)
|
|
|
+ mAnimationAssetId( StringTable->EmptyString )
|
|
|
{
|
|
|
+ // Set to self ticking.
|
|
|
+ mSelfTick = true;
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
GuiSpriteCtrl::~GuiSpriteCtrl()
|
|
|
{
|
|
|
- // Destroy animation controller if required.
|
|
|
- if ( mpAnimationController != NULL )
|
|
|
- {
|
|
|
- delete mpAnimationController;
|
|
|
- mpAnimationController = NULL;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
@@ -90,27 +79,15 @@ bool GuiSpriteCtrl::onWake()
|
|
|
return false;
|
|
|
|
|
|
// Are we in static mode?
|
|
|
- if ( isStaticMode() )
|
|
|
+ if ( mImageAssetId != StringTable->EmptyString )
|
|
|
{
|
|
|
- // Set image asset if it's valid.
|
|
|
- if ( mImageAssetId != StringTable->EmptyString )
|
|
|
- mImageAsset = mImageAssetId;
|
|
|
+ // Set image asset.
|
|
|
+ SpriteProxyBase::setImage( mImageAssetId );
|
|
|
}
|
|
|
- else
|
|
|
+ else if ( mAnimationAssetId != StringTable->EmptyString )
|
|
|
{
|
|
|
- // Set animation asset if it's valid.
|
|
|
- if ( mAnimationAssetId != StringTable->EmptyString )
|
|
|
- {
|
|
|
- // Create animation controller if required.
|
|
|
- if ( mpAnimationController == NULL )
|
|
|
- mpAnimationController = new AnimationController();
|
|
|
-
|
|
|
- // Play animation.
|
|
|
- mpAnimationController->playAnimation( mAnimationAssetId, false );
|
|
|
-
|
|
|
- // Turn-on tick processing.
|
|
|
- setProcessTicks( true );
|
|
|
- }
|
|
|
+ // Play animation asset.
|
|
|
+ SpriteProxyBase::setAnimation( mAnimationAssetId, false );
|
|
|
}
|
|
|
|
|
|
return true;
|
|
@@ -121,106 +98,59 @@ bool GuiSpriteCtrl::onWake()
|
|
|
void GuiSpriteCtrl::onSleep()
|
|
|
{
|
|
|
// Clear assets.
|
|
|
- mImageAsset.clear();
|
|
|
-
|
|
|
- // Destroy animation controller if required.
|
|
|
- if ( mpAnimationController != NULL )
|
|
|
- {
|
|
|
- delete mpAnimationController;
|
|
|
- mpAnimationController = NULL;
|
|
|
- }
|
|
|
-
|
|
|
- // Turn-off tick processing.
|
|
|
- setProcessTicks( false );
|
|
|
+ SpriteProxyBase::clearAsset();
|
|
|
|
|
|
// Call parent.
|
|
|
Parent::onSleep();
|
|
|
}
|
|
|
|
|
|
-//------------------------------------------------------------------------------
|
|
|
-
|
|
|
-void GuiSpriteCtrl::processTick( void )
|
|
|
-{
|
|
|
- // Are we in static mode?
|
|
|
- if ( isStaticMode() )
|
|
|
- {
|
|
|
- // Yes, so turn-off tick processing.
|
|
|
- setProcessTicks( false );
|
|
|
-
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // Finish if no animation controller.
|
|
|
- if ( mpAnimationController == NULL )
|
|
|
- return;
|
|
|
-
|
|
|
- // Finish if the animation has finished.
|
|
|
- if ( mpAnimationController->isAnimationFinished() )
|
|
|
- return;
|
|
|
-
|
|
|
- // Finish if animation is paused.
|
|
|
- if ( mAnimationPaused )
|
|
|
- return;
|
|
|
-
|
|
|
- // Update the animation.
|
|
|
- mpAnimationController->updateAnimation( Tickable::smTickSec );
|
|
|
-
|
|
|
- // Finish if the animation has not finished.
|
|
|
- if ( !mpAnimationController->isAnimationFinished() )
|
|
|
- return;
|
|
|
-
|
|
|
- // Turn-off tick processing.
|
|
|
- setProcessTicks( false );
|
|
|
-}
|
|
|
-
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
-void GuiSpriteCtrl::setImage( const char* pImageAssetId )
|
|
|
+bool GuiSpriteCtrl::setImage( const char* pImageAssetId )
|
|
|
{
|
|
|
// Sanity!
|
|
|
AssertFatal( pImageAssetId != NULL, "Cannot use a NULL asset Id." );
|
|
|
|
|
|
+ // Reset animation.
|
|
|
+ mAnimationAssetId = StringTable->EmptyString;
|
|
|
+
|
|
|
// Fetch the asset Id.
|
|
|
mImageAssetId = StringTable->insert(pImageAssetId);
|
|
|
|
|
|
// Reset image frame.
|
|
|
- mImageFrame = 0;
|
|
|
+ mImageFrame = 0;
|
|
|
|
|
|
- // Assign asset if awake.
|
|
|
- if ( isAwake() )
|
|
|
- mImageAsset = mImageAssetId;
|
|
|
-
|
|
|
- // Set static mode.
|
|
|
- mStaticMode = true;
|
|
|
+ // Finish if not awake.
|
|
|
+ if ( !isAwake() )
|
|
|
+ return true;
|
|
|
|
|
|
- // Reset animation.
|
|
|
- mAnimationAssetId = StringTable->EmptyString;
|
|
|
-
|
|
|
- // Destroy animation controller if required.
|
|
|
- if ( mpAnimationController != NULL )
|
|
|
- {
|
|
|
- delete mpAnimationController;
|
|
|
- mpAnimationController = NULL;
|
|
|
- }
|
|
|
+ // Call parent.
|
|
|
+ if ( !SpriteProxyBase::setImage( pImageAssetId, 0 ) )
|
|
|
+ return false;
|
|
|
|
|
|
// Update control.
|
|
|
setUpdate();
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
-void GuiSpriteCtrl::setImageFrame( const U32 imageFrame )
|
|
|
+bool GuiSpriteCtrl::setImageFrame( const U32 frame )
|
|
|
{
|
|
|
- // Set image frame.
|
|
|
- mImageFrame = imageFrame;
|
|
|
+ // Call parent.
|
|
|
+ if ( !SpriteProxyBase::setImageFrame( frame ) )
|
|
|
+ return false;
|
|
|
|
|
|
// Update control.
|
|
|
setUpdate();
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
-void GuiSpriteCtrl::setAnimation( const char* pAnimationAssetId )
|
|
|
+bool GuiSpriteCtrl::setAnimation( const char* pAnimationAssetId )
|
|
|
{
|
|
|
// Sanity!
|
|
|
AssertFatal( pAnimationAssetId != NULL, "Cannot use a NULL asset Id." );
|
|
@@ -231,165 +161,29 @@ void GuiSpriteCtrl::setAnimation( const char* pAnimationAssetId )
|
|
|
// Reset the image asset Id.
|
|
|
mImageAssetId = StringTable->EmptyString;
|
|
|
|
|
|
- // Reset image frame.
|
|
|
- mImageFrame = 0;
|
|
|
-
|
|
|
- // Reset static mode.
|
|
|
- mStaticMode = false;
|
|
|
-
|
|
|
- // Assign asset if awake.
|
|
|
- if ( isAwake() )
|
|
|
- {
|
|
|
- // Set animation asset if it's valid.
|
|
|
- if ( mAnimationAssetId != StringTable->EmptyString )
|
|
|
- {
|
|
|
- // Create animation controller if required.
|
|
|
- if ( mpAnimationController == NULL )
|
|
|
- mpAnimationController = new AnimationController();
|
|
|
-
|
|
|
- // Play animation.
|
|
|
- mpAnimationController->playAnimation( mAnimationAssetId, false );
|
|
|
-
|
|
|
- // Turn-on tick processing.
|
|
|
- setProcessTicks( true );
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-//-----------------------------------------------------------------------------
|
|
|
-
|
|
|
-void GuiSpriteCtrl::play(void)
|
|
|
-{
|
|
|
- // Sanity!
|
|
|
- if (mStaticMode)
|
|
|
- return;
|
|
|
-
|
|
|
- // Reset animation pause.
|
|
|
- mAnimationPaused = false;
|
|
|
-
|
|
|
- // Assign asset if awake.
|
|
|
- if ( isAwake() )
|
|
|
- {
|
|
|
- // Set animation asset if it's valid.
|
|
|
- if ( mAnimationAssetId != StringTable->EmptyString )
|
|
|
- {
|
|
|
- // Play animation.
|
|
|
- mpAnimationController->playAnimation( mAnimationAssetId, false );
|
|
|
-
|
|
|
- // Turn-on tick processing.
|
|
|
- setProcessTicks( true );
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-//-----------------------------------------------------------------------------
|
|
|
-
|
|
|
-void GuiSpriteCtrl::pause(bool flag)
|
|
|
-{
|
|
|
- // Finish if not awake.
|
|
|
- if ( !isAwake() )
|
|
|
- return;
|
|
|
-
|
|
|
- // Finish if no animation.
|
|
|
- if ( mpAnimationController == NULL )
|
|
|
- return;
|
|
|
-
|
|
|
- // Pause the animation.
|
|
|
- mAnimationPaused = flag;
|
|
|
-}
|
|
|
-
|
|
|
-//-----------------------------------------------------------------------------
|
|
|
-
|
|
|
-void GuiSpriteCtrl::stop(void)
|
|
|
-{
|
|
|
// Finish if not awake.
|
|
|
if ( !isAwake() )
|
|
|
- return;
|
|
|
+ return true;
|
|
|
|
|
|
- // Finish if no animation.
|
|
|
- if ( mpAnimationController == NULL )
|
|
|
- return;
|
|
|
+ // Play animation asset if it's valid.
|
|
|
+ if ( mAnimationAssetId != StringTable->EmptyString )
|
|
|
+ SpriteProxyBase::setAnimation( mAnimationAssetId, false );
|
|
|
|
|
|
- // Stop the animation.
|
|
|
- mAnimationPaused = false;
|
|
|
- mpAnimationController->stopAnimation();
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
void GuiSpriteCtrl::onRender( Point2I offset, const RectI &updateRect)
|
|
|
{
|
|
|
- // Are we in static mode?
|
|
|
- if ( isStaticMode() )
|
|
|
- {
|
|
|
- // Do we have a valid image to render?
|
|
|
- if ( mImageAsset.notNull() && mImageAsset->isAssetValid() && mImageFrame < mImageAsset->getFrameCount() )
|
|
|
- {
|
|
|
- // Yes, so calculate source region.
|
|
|
- const ImageAsset::FrameArea::PixelArea& pixelArea = mImageAsset->getImageFrameArea( mImageFrame ).mPixelArea;
|
|
|
- RectI sourceRegion( pixelArea.mPixelOffset, Point2I(pixelArea.mPixelWidth, pixelArea.mPixelHeight) );
|
|
|
-
|
|
|
- // Calculate destination region.
|
|
|
- RectI destinationRegion(offset, mBounds.extent);
|
|
|
-
|
|
|
- // Render image.
|
|
|
- dglSetBitmapModulation( mProfile->mFillColor );
|
|
|
- dglDrawBitmapStretchSR( mImageAsset->getImageTexture(), destinationRegion, sourceRegion );
|
|
|
- dglClearBitmapModulation();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // No, so render no-image render-proxy.
|
|
|
- renderNoImage( offset, updateRect );
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // Do we have a valid animation to render?
|
|
|
- if ( mpAnimationController != NULL && mpAnimationController->isAnimationValid() )
|
|
|
- {
|
|
|
- // Yes, so calculate source region.
|
|
|
- const ImageAsset::FrameArea::PixelArea& pixelArea = mpAnimationController->getCurrentImageFrameArea().mPixelArea;
|
|
|
- RectI sourceRegion( pixelArea.mPixelOffset, Point2I(pixelArea.mPixelWidth, pixelArea.mPixelHeight) );
|
|
|
-
|
|
|
- // Calculate destination region.
|
|
|
- RectI destinationRegion(offset, mBounds.extent);
|
|
|
-
|
|
|
- // Render animation image.
|
|
|
- dglSetBitmapModulation( mProfile->mFillColor );
|
|
|
- dglDrawBitmapStretchSR( mpAnimationController->getImageTexture(), destinationRegion, sourceRegion );
|
|
|
- dglClearBitmapModulation();
|
|
|
-
|
|
|
- // Update control.
|
|
|
- setUpdate();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // No, so render no-image render-proxy.
|
|
|
- renderNoImage( offset, updateRect );
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Render child controls.
|
|
|
- renderChildControls(offset, updateRect);
|
|
|
+ // Call parent.
|
|
|
+ SpriteProxyBase::renderGui( *this, offset, updateRect );
|
|
|
}
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
-void GuiSpriteCtrl::renderNoImage( Point2I &offset, const RectI& updateRect )
|
|
|
+void GuiSpriteCtrl::onAnimationEnd( void )
|
|
|
{
|
|
|
- // Fetch the 'cannot render' proxy.
|
|
|
- RenderProxy* pNoImageRenderProxy = Sim::findObject<RenderProxy>( CANNOT_RENDER_PROXY_NAME );
|
|
|
-
|
|
|
- // Finish if no render proxy available or it can't render.
|
|
|
- if ( pNoImageRenderProxy == NULL || !pNoImageRenderProxy->validRender() )
|
|
|
- return;
|
|
|
-
|
|
|
- // Render using render-proxy.
|
|
|
- pNoImageRenderProxy->renderGui( *this, offset, updateRect );
|
|
|
-
|
|
|
- // Update control.
|
|
|
- setUpdate();
|
|
|
+ // Clear assets.
|
|
|
+ SpriteProxyBase::clearAsset();
|
|
|
}
|
|
|
-
|
|
|
-
|