+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/dali.h>
-#include <dali-toolkit/dali-toolkit.h>
-
-using namespace Dali;
-
-namespace
-{
-const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-gradient.jpg" );
-
-}
-
-// This example shows resolution independent rendering and animation of curves using the gpu.
-//
-class AnimatedShapesExample : public ConnectionTracker
-{
-public:
-
- AnimatedShapesExample( Application& application )
-: mApplication( application )
-{
- // Connect to the Application's Init signal
- mApplication.InitSignal().Connect( this, &AnimatedShapesExample::Create );
-}
-
- ~AnimatedShapesExample()
- {
- // Nothing to do here;
- }
-
- // The Init signal is received once (only) during the Application lifetime
- void Create( Application& application )
- {
- // Get a handle to the stage
- Stage stage = Stage::GetCurrent();
-
- //Create a view
- mView = Dali::Toolkit::View::New();
- stage.Add( mView );
-
- //Set background image for the view
- ImageAttributes attributes;
- Image image = ResourceImage::New( BACKGROUND_IMAGE, attributes );
-
-
- Dali::ImageActor backgroundImageActor = Dali::ImageActor::New( image );
- mView.SetBackground( backgroundImageActor );
-
- CreateTriangleMorph(Vector3( stage.GetSize().x*0.5f,stage.GetSize().y*0.15f,0.0f), 100.0f );
- CreateCircleMorph( Vector3( stage.GetSize().x*0.5f,stage.GetSize().y*0.85f,0.0f), 60.0f );
- CreatePathMorph( Vector3( stage.GetSize().x*0.5f,stage.GetSize().y*0.5f,0.0f), 55.0f );
-
-
- stage.KeyEventSignal().Connect(this, &AnimatedShapesExample::OnKeyEvent);
- }
-
- void CreateCircleMorph( Vector3 center, float radius )
- {
- Toolkit::QuadraticBezier shader = Toolkit::QuadraticBezier::New(16, true);
-
- shader.SetPoint(0, Vector3(-radius,-radius,0.0f));
- shader.SetPoint(1, Vector3( 0.0f,-radius,0.0f));
- shader.SetPoint(2, Vector3(radius,-radius,0.0f));
-
- shader.SetPoint(3, Vector3(radius,-radius,0.0f));
- shader.SetPoint(4, Vector3( radius,0.0f,0.0f));
- shader.SetPoint(5, Vector3(radius,radius,0.0f));
-
- shader.SetPoint(6, Vector3(radius,radius,0.0f));
- shader.SetPoint(7, Vector3( 0.0f,radius,0.0f));
- shader.SetPoint(8, Vector3( -radius,radius,0.0f));
-
- shader.SetPoint(9, Vector3( -radius,radius,0.0f));
- shader.SetPoint(10, Vector3( -radius,0.0f,0.0f));
- shader.SetPoint(11, Vector3(-radius,-radius,0.0f));
-
- shader.SetPoint(12, Vector3(-radius,-radius,0.0f));
- shader.SetPoint(13, Vector3(radius,-radius,0.0f));
- shader.SetPoint(14, Vector3(radius,radius,0.0f));
- shader.SetPoint(15, Vector3( -radius,radius,0.0f));
-
- shader.SetColor(Vector4(1.0f,0.0f,0.0f,1.0f) );
- shader.SetLineWidth(2.0f);
-
- ////Generate the mesh
- Dali::MeshData::VertexContainer vertices;
- for( unsigned int i(0); i<12; i+=3 )
- {
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,0.0f,i) ));
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.5f,0.0f,i+1)));
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(1.0f,1.0f,i+2)));
- }
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,1.0f,12) ));
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,1.0f,13)));
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,1.0f,14)));
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,1.0f,15)));
-
- short unsigned int indexArray[] = { 0,2,1, 3,5,4,6,8,7, 9, 11, 10, 12,15,14,12,14,13};
- Dali::MeshData::FaceIndices index( indexArray, indexArray + sizeof(indexArray)/sizeof(short unsigned int) );
-
- //Material
- Dali::Material material = Material::New("Material");
- material.SetDiffuseColor( Vector4(1.0f,1.0f,1.0f,1.0f));
-
- //Create the Mesh object
- Dali::MeshData data;
- data.SetVertices(vertices);
- data.SetFaceIndices( index );
- data.SetMaterial( material );
- data.SetHasNormals( true );
- Mesh mesh = Mesh::New( data );
-
- //Create the mesh actor
- MeshActor meshActor = MeshActor::New(mesh);
- meshActor.SetAnchorPoint( AnchorPoint::CENTER );
- meshActor.SetShaderEffect(shader);
- meshActor.SetPosition( center );
- meshActor.SetBlendMode(BlendingMode::ON );
- mView.Add( meshActor );
-
-
- //Animation
- Animation animation = Animation::New(5.0f);
- KeyFrames k0 = KeyFrames::New();
- k0.Add( 0.0f, Vector3( 0.0f,-radius, 0.0f) );
- k0.Add( 0.5f, Vector3(0.0f, -radius*4.0f, 0.0f));
- k0.Add( 1.0f, Vector3( 0.0f,-radius, 0.0f) );
- animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(1)),k0,AlphaFunctions::EaseInOutSine );
-
- k0 = KeyFrames::New();
- k0.Add( 0.0f, Vector3( radius, 0.0f, 0.0f) );
- k0.Add( 0.5f, Vector3(radius*4.0f,0.0f, 0.0f));
- k0.Add( 1.0f, Vector3( radius,0.0f, 0.0f));
- animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(4)),k0,AlphaFunctions::EaseInOutSine );
-
- k0 = KeyFrames::New();
- k0.Add( 0.0f, Vector3(0.0f,radius, 0.0f) );
- k0.Add( 0.5f, Vector3(0.0f,radius*4.0f, 0.0f));
- k0.Add( 1.0f, Vector3(0.0f,radius, 0.0f) );
- animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(7)),k0,AlphaFunctions::EaseInOutSine );
-
- k0 = KeyFrames::New();
- k0.Add( 0.0f, Vector3( -radius, 0.0f, 0.0f) );
- k0.Add( 0.5f, Vector3(-radius*4.0f,0.0f, 0.0f));
- k0.Add( 1.0f, Vector3( -radius, 0.0f, 0.0f) );
- animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(10)),k0,AlphaFunctions::EaseInOutSine );
-
- animation.RotateBy(meshActor,Degree(90.0f), Vector3::ZAXIS );
- animation.SetLooping( true );
- animation.Play();
- }
-
- void CreateTriangleMorph( Vector3 center, float side )
- {
- float h = (side *0.5f)/0.866f;
-
- Vector3 v0 = Vector3(-h,h,0.0f);
- Vector3 v1 = Vector3(0.0f,-(side*0.366f),0.0f );
- Vector3 v2 = Vector3(h,h,0.0f);
-
- Vector3 v3 = v0 + ((v1-v0) * 0.5f);
- Vector3 v4 = v1 + ((v2-v1) * 0.5f);
- Vector3 v5 = v2 + ((v0-v2) * 0.5f);
-
- Toolkit::QuadraticBezier shader = Toolkit::QuadraticBezier::New(12, true);
-
- shader.SetPoint(0,v0);
- shader.SetPoint(1,v3);
- shader.SetPoint(2,v1);
-
- shader.SetPoint(3,v1);
- shader.SetPoint(4,v4);
- shader.SetPoint(5,v2);
-
- shader.SetPoint(6,v2);
- shader.SetPoint(7,v5);
- shader.SetPoint(8,v0);
-
- shader.SetPoint(9, v0);
- shader.SetPoint(10,v1);
- shader.SetPoint(11,v2);
-
- shader.SetColor(Vector4(0.0f,1.0f,0.0f,1.0f));
- shader.SetLineWidth(2.0f);
-
- ////Generate the mesh
- Dali::MeshData::VertexContainer vertices;
- for( unsigned int i(0);i<9;i+=3 )
- {
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,0.0f,i)) );
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO,Vector3(0.5f,0.0f,i+1) ) );
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(1.0f,1.0f,i+2) ) );
- }
-
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,1.0f,9)) );
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO,Vector3(0.0f,1.0f,10) ) );
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,1.0f,11) ) );
-
- short unsigned int indexArray[] = { 0,2,1,3,5,4,6,8,7,9,11,10 };
- Dali::MeshData::FaceIndices index( indexArray, indexArray + sizeof(indexArray)/sizeof(short unsigned int) );
-
- //Material
- Dali::Material material = Material::New("Material");
- material.SetDiffuseColor( Vector4(1.0f,1.0f,1.0f,1.0f));
-
- //Create the Mesh object
- Dali::MeshData data;
- data.SetVertices(vertices);
- data.SetFaceIndices( index );
- data.SetMaterial( material );
- data.SetHasNormals( true );
- Mesh mesh = Mesh::New( data );
-
-// //Create the mesh actor
- MeshActor meshActor = MeshActor::New(mesh);
- meshActor.SetAnchorPoint( AnchorPoint::CENTER );
- meshActor.SetShaderEffect(shader);
- meshActor.SetPosition( center );
- meshActor.SetBlendMode(BlendingMode::ON );
- mView.Add( meshActor );
-
- //Animation
- Animation animation = Animation::New(5.0f);
-
- KeyFrames k0 = KeyFrames::New();
- k0.Add( 0.0f,v3 );
- k0.Add( 0.5f, v3 + Vector3(-200.0f,-200.0f,0.0f));
- k0.Add( 1.0f, v3 );
- animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(1)),k0,AlphaFunctions::EaseInOutSine );
-
- k0 = KeyFrames::New();
- k0.Add( 0.0f,v4 );
- k0.Add( 0.5f, v4 + Vector3(200.0f,-200.0f,0.0f));
- k0.Add( 1.0f, v4 );
- animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(4)),k0,AlphaFunctions::EaseInOutSine );
-
- k0 = KeyFrames::New();
- k0.Add( 0.0f,v5 );
- k0.Add( 0.5f, v5 + Vector3(0.0,200.0f,0.0f));
- k0.Add( 1.0f, v5 );
- animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(7)),k0,AlphaFunctions::EaseInOutSine );
- animation.SetLooping( true );
- animation.Play();
- }
-
- void CreatePathMorph( Vector3 center, float radius )
- {
- Toolkit::QuadraticBezier shader = Toolkit::QuadraticBezier::New(12, false);
-
- shader.SetPoint(0, Vector3(-radius,-radius,0.0f));
- shader.SetPoint(1, Vector3( 0.0f,-radius,0.0f));
- shader.SetPoint(2, Vector3(radius,-radius,0.0f));
-
- shader.SetPoint(3, Vector3(radius,-radius,0.0f));
- shader.SetPoint(4, Vector3( radius,0.0f,0.0f));
- shader.SetPoint(5, Vector3(radius,radius,0.0f));
-
- shader.SetPoint(6, Vector3(radius,radius,0.0f));
- shader.SetPoint(7, Vector3( 0.0f,radius,0.0f));
- shader.SetPoint(8, Vector3( -radius,radius,0.0f));
-
- shader.SetPoint(9, Vector3( -radius,radius,0.0f));
- shader.SetPoint(10, Vector3( -radius,0.0f,0.0f));
- shader.SetPoint(11, Vector3(-radius,-radius,0.0f));
-
- shader.SetColor(Vector4(1.0f,1.0f,0.0f,1.0f) );
- shader.SetLineWidth(1.5f);
-
- ////Generate the mesh/S
- Dali::MeshData::VertexContainer vertices;
- for( unsigned int i(0); i<12; i+=3 )
- {
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,0.0f,i) ));
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.5f,0.0f,i+1)));
- vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(1.0f,1.0f,i+2)));
- }
-
-
- short unsigned int indexArray[] = { 0,2,1, 3,5,4,6,8,7, 9, 11, 10 };
- Dali::MeshData::FaceIndices index( indexArray, indexArray + sizeof(indexArray)/sizeof(short unsigned int) );
-
- //Material
- Dali::Material material = Material::New("Material");
- material.SetDiffuseColor( Vector4(1.0f,1.0f,1.0f,1.0f));
-
- //Create the Mesh object
- Dali::MeshData data;
- data.SetVertices(vertices);
- data.SetFaceIndices( index );
- data.SetMaterial( material );
- data.SetHasNormals( true );
- Mesh mesh = Mesh::New( data );
-
- //Create the mesh actor
- MeshActor meshActor = MeshActor::New(mesh);
- meshActor.SetAnchorPoint( AnchorPoint::CENTER );
- meshActor.SetShaderEffect(shader);
- meshActor.SetPosition( center );
- meshActor.SetBlendMode(BlendingMode::ON );
- mView.Add( meshActor );
-
-
- //Animation
- Animation animation = Animation::New(5.0f);
- KeyFrames k0 = KeyFrames::New();
- k0.Add( 0.0f, Vector3( 0.0f,-radius*2.0, 0.0f) );
- k0.Add( 0.5f, Vector3(-radius*2.0, -radius*3.0f, 0.0f));
- k0.Add( 1.0f, Vector3( 0.0f,-radius*2.0, 0.0f) );
- animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(1)),k0,AlphaFunctions::EaseInOutSine );
-
- k0 = KeyFrames::New();
- k0.Add( 0.0f, Vector3( radius*2.0, 0.0f, 0.0f) );
- k0.Add( 0.5f, Vector3(radius*3.0f,-radius*2.0, 0.0f));
- k0.Add( 1.0f, Vector3( radius*2.0,0.0f, 0.0f));
- animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(4)),k0,AlphaFunctions::EaseInOutSine );
-
- k0 = KeyFrames::New();
- k0.Add( 0.0f, Vector3(0.0f,radius*2.0, 0.0f) );
- k0.Add( 0.5f, Vector3(radius*2.0,radius*3.0f, 0.0f));
- k0.Add( 1.0f, Vector3(0.0f,radius*2.0, 0.0f) );
- animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(7)),k0,AlphaFunctions::EaseInOutSine );
-
- k0 = KeyFrames::New();
- k0.Add( 0.0f, Vector3( -radius*2.0, 0.0f, 0.0f) );
- k0.Add( 0.5f, Vector3(-radius*3.0f,radius*2.0, 0.0f));
- k0.Add( 1.0f, Vector3( -radius*2.0, 0.0f, 0.0f) );
- animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(10)),k0,AlphaFunctions::EaseInOutSine );
-
- animation.RotateBy(meshActor,Degree(-90.0f), Vector3::ZAXIS );
- animation.SetLooping( true );
- animation.Play();
- }
-
- /**
- * Main key event handler
- */
- void OnKeyEvent(const KeyEvent& event)
- {
- if( event.state == KeyEvent::Down && (IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK )) )
- {
- mApplication.Quit();
- }
- }
-
-private:
- Application& mApplication;
- Toolkit::View mView;
-};
-
-void RunTest( Application& application )
-{
- AnimatedShapesExample test( application );
- application.MainLoop();
-}
-
-int main( int argc, char **argv )
-{
- Application application = Application::New( &argc, &argv );
- RunTest( application );
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/dali.h>
-#include <dali-toolkit/dali-toolkit.h>
-#include "shared/view.h"
-
-using namespace Dali;
-
-namespace
-{
-const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
-const char * const APPLICATION_TITLE( "Bubble Effect" );
-const char * const CHANGE_BACKGROUND_ICON( DALI_IMAGE_DIR "icon-change.png" );
-const char * const CHANGE_BUBBLE_SHAPE_ICON( DALI_IMAGE_DIR "icon-replace.png" );
-
-const char* BACKGROUND_IMAGES[]=
-{
- DALI_IMAGE_DIR "background-1.jpg",
- DALI_IMAGE_DIR "background-2.jpg",
- DALI_IMAGE_DIR "background-3.jpg",
- DALI_IMAGE_DIR "background-4.jpg",
- DALI_IMAGE_DIR "background-5.jpg",
-};
-const unsigned int NUM_BACKGROUND_IMAGES( sizeof( BACKGROUND_IMAGES ) / sizeof( BACKGROUND_IMAGES[0] ) );
-
-const char* BUBBLE_SHAPE_IMAGES[] =
-{
- DALI_IMAGE_DIR "bubble-ball.png",
- DALI_IMAGE_DIR "icon-item-view-layout-spiral.png",
- DALI_IMAGE_DIR "icon-replace.png",
- DALI_IMAGE_DIR "icon-effect-cross.png"
-};
-const unsigned int NUM_BUBBLE_SHAPE_IMAGES( sizeof( BUBBLE_SHAPE_IMAGES ) / sizeof( BUBBLE_SHAPE_IMAGES[0] ) );
-
-const Vector2 DEFAULT_BUBBLE_SIZE( 10.f, 30.f );
-const unsigned int DEFAULT_NUMBER_OF_BUBBLES( 1000 );
-}// end LOCAL_STUFF
-
-// This example shows the usage of BubbleEmitter which displays lots of moving bubbles on the stage.
-class BubbleEffectExample : public ConnectionTracker
-{
-public:
- BubbleEffectExample(Application &app)
- : mApp(app),
- mHSVDelta( Vector3( 0.f, 0.f, 0.5f ) ),
- mNeedNewAnimation( true ),
- mTimerInterval( 16 ),
- mCurrentBackgroundImageId( 0 ),
- mCurrentBubbleShapeImageId( 0 )
- {
- // Connect to the Application's Init signal
- app.InitSignal().Connect(this, &BubbleEffectExample::Create);
- }
-
- ~BubbleEffectExample()
- {
- }
-
-private:
-
- // The Init signal is received once (only) during the Application lifetime
- void Create(Application& app)
- {
- Stage stage = Stage::GetCurrent();
- Vector2 stageSize = stage.GetSize();
-
- stage.KeyEventSignal().Connect(this, &BubbleEffectExample::OnKeyEvent);
-
- // Creates a default view with a default tool bar.
- // The view is added to the stage.
- Toolkit::ToolBar toolBar;
- Toolkit::View view;
- Layer content = DemoHelper::CreateView( app,
- view,
- toolBar,
- "",
- TOOLBAR_IMAGE,
- APPLICATION_TITLE );
-
- // Add a button to change background. (right of toolbar)
- mChangeBackgroundButton = Toolkit::PushButton::New();
- mChangeBackgroundButton.SetBackgroundImage( ResourceImage::New( CHANGE_BACKGROUND_ICON ) );
- mChangeBackgroundButton.ClickedSignal().Connect( this, &BubbleEffectExample::OnChangeIconClicked );
- toolBar.AddControl( mChangeBackgroundButton,
- DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
- Toolkit::Alignment::HorizontalRight,
- DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
- // Add a button to change bubble shape. ( left of bar )
- mChangeBubbleShapeButton = Toolkit::PushButton::New();
- mChangeBubbleShapeButton.SetBackgroundImage( ResourceImage::New( CHANGE_BUBBLE_SHAPE_ICON ) );
- mChangeBubbleShapeButton.ClickedSignal().Connect( this, &BubbleEffectExample::OnChangeIconClicked );
- toolBar.AddControl( mChangeBubbleShapeButton,
- DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
- Toolkit::Alignment::HorizontalLeft,
- DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
-
- // Create and initialize the BubbleEmitter object
- mBubbleEmitter = Toolkit::BubbleEmitter::New( stageSize,
- ResourceImage::New( BUBBLE_SHAPE_IMAGES[mCurrentBubbleShapeImageId] ),
- DEFAULT_NUMBER_OF_BUBBLES,
- DEFAULT_BUBBLE_SIZE);
- mBackgroundImage = ResourceImage::New( BACKGROUND_IMAGES[mCurrentBackgroundImageId] );
- mBubbleEmitter.SetBackground( mBackgroundImage, mHSVDelta );
-
- // Get the root actor of all bubbles, and add it to stage.
- Actor bubbleRoot = mBubbleEmitter.GetRootActor();
- bubbleRoot.SetParentOrigin(ParentOrigin::CENTER);
- bubbleRoot.SetZ(0.1f); // Make sure the bubbles displayed on top og the background.
- content.Add( bubbleRoot );
-
- // Add the background image actor to stage
- mBackgroundActor = ImageActor::New( mBackgroundImage );
- view.SetBackground( mBackgroundActor );
-
- // Set up the timer to emit bubble regularly when the finger is touched down but not moved
- mTimerForBubbleEmission = Timer::New( mTimerInterval );
- mTimerForBubbleEmission.TickSignal().Connect(this, &BubbleEffectExample::OnTimerTick);
-
- // Connect the callback to the touch signal on the background
- mBackgroundActor.TouchedSignal().Connect( this, &BubbleEffectExample::OnTouch );
- }
-
-
-/***********
- * Emit bubbles
- *****************/
-
- // Set up the animation of emitting bubbles, to be efficient, every animation controls multiple bubbles ( 4 here )
- void SetUpAnimation( Vector2 emitPosition, Vector2 direction )
- {
- if( mNeedNewAnimation )
- {
- float duration = Random::Range(1.f, 1.5f);
- mEmitAnimation = Animation::New( duration );
- mNeedNewAnimation = false;
- mAnimateComponentCount = 0;
- }
-
- mBubbleEmitter.EmitBubble( mEmitAnimation, emitPosition, direction + Vector2(0.f, 30.f) /* upwards */, Vector2(300, 600) );
-
- mAnimateComponentCount++;
-
- if( mAnimateComponentCount % 4 ==0 )
- {
- mEmitAnimation.Play();
- mNeedNewAnimation = true;
- }
- }
-
- // Emit bubbles when the finger touches down but keep stationary.
- // And stops emitting new bubble after being stationary for 2 seconds
- bool OnTimerTick()
- {
- if(mEmitPosition == mCurrentTouchPosition) // finger is not moving
- {
- mNonMovementCount++;
- if(mNonMovementCount < (1000 / mTimerInterval)) // 1 seconds
- {
- for(int i = 0; i < 4; i++) // emit 4 bubbles every timer tick
- {
- SetUpAnimation( mCurrentTouchPosition+Vector2(rand()%5, rand()%5), Vector2(rand()%60-30, rand()%100-50) );
- }
- }
- }
- else
- {
- mNonMovementCount = 0;
- mEmitPosition = mCurrentTouchPosition;
- }
-
- return true;
- }
-
- // Callback function of the touch signal on the background
- bool OnTouch(Dali::Actor actor, const Dali::TouchEvent& event)
- {
- const TouchPoint &point = event.GetPoint(0);
- switch(point.state)
- {
- case TouchPoint::Down:
- {
- mCurrentTouchPosition = point.screen;
- mEmitPosition = point.screen;
- mTimerForBubbleEmission.Start();
- mNonMovementCount = 0;
-
- break;
- }
- case TouchPoint::Motion:
- {
- Vector2 displacement = point.screen - mCurrentTouchPosition;
- mCurrentTouchPosition = point.screen;
- //emit multiple bubbles along the moving direction when the finger moves quickly
- float step = std::min(5.f, displacement.Length());
- for( float i=0.25f; i<step; i=i+1.f)
- {
- SetUpAnimation( mCurrentTouchPosition+displacement*(i/step), displacement );
- }
- break;
- }
- case TouchPoint::Up:
- case TouchPoint::Leave:
- case TouchPoint::Interrupted:
- {
- mTimerForBubbleEmission.Stop();
- break;
- }
- case TouchPoint::Stationary:
- case TouchPoint::Last:
- default:
- {
- break;
- }
-
- }
- return true;
- }
-
- bool OnChangeIconClicked( Toolkit::Button button )
- {
- if(button == mChangeBackgroundButton)
- {
- mBackgroundImage = ResourceImage::New( BACKGROUND_IMAGES[ ++mCurrentBackgroundImageId % NUM_BACKGROUND_IMAGES ] );
-
- mBubbleEmitter.SetBackground( mBackgroundImage, mHSVDelta );
-
- mBackgroundActor.SetImage( mBackgroundImage );
- }
- else if( button == mChangeBubbleShapeButton )
- {
- mBubbleEmitter.SetShapeImage( ResourceImage::New( BUBBLE_SHAPE_IMAGES[ ++mCurrentBubbleShapeImageId % NUM_BUBBLE_SHAPE_IMAGES ] ) );
- }
- return true;
- }
-
- /**
- * Main key event handler
- */
- void OnKeyEvent(const KeyEvent& event)
- {
- if(event.state == KeyEvent::Down)
- {
- if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
- {
- mApp.Quit();
- }
- }
- }
-
-private:
-
- Application& mApp;
- Image mBackgroundImage;
- ImageActor mBackgroundActor;
-
- Toolkit::BubbleEmitter mBubbleEmitter;
- Vector3 mHSVDelta;
-
- Animation mEmitAnimation;
- unsigned int mAnimateComponentCount;
- bool mNeedNewAnimation;
-
- Timer mTimerForBubbleEmission;
- unsigned int mNonMovementCount;
- unsigned int mTimerInterval;
-
- Vector2 mCurrentTouchPosition;
- Vector2 mEmitPosition;
-
- Toolkit::PushButton mChangeBackgroundButton;
- Toolkit::PushButton mChangeBubbleShapeButton;
- unsigned int mCurrentBackgroundImageId;
- unsigned int mCurrentBubbleShapeImageId;
-};
-
-/*****************************************************************************/
-
-static void
-RunTest(Application& app)
-{
- BubbleEffectExample theApp(app);
- app.MainLoop();
-}
-
-/*****************************************************************************/
-
-int
-main(int argc, char **argv)
-{
- Application app = Application::New(&argc, &argv);
-
- RunTest(app);
-
- return 0;
-}
-
-
-
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <dali-toolkit/dali-toolkit.h>
-#include "shared/view.h"
-#include <cstdio>
-#include <iostream>
-
-using namespace Dali;
-using namespace Dali::Toolkit;
-
-class NewWindowController;
-
-namespace
-{
-const char * const BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-2.jpg" );
-const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
-const char * const LOSE_CONTEXT_IMAGE( DALI_IMAGE_DIR "icon-cluster-wobble.png" );
-const char * const BASE_IMAGE( DALI_IMAGE_DIR "gallery-large-14.jpg" );
-const char * const EFFECT_IMAGE( DALI_IMAGE_DIR "gallery-large-18.jpg" );
-
-const float EXPLOSION_DURATION(1.2f);
-const unsigned int EMIT_INTERVAL_IN_MS(80);
-const float TRACK_DURATION_IN_MS(970);
-
-Application gApplication;
-NewWindowController* gNewWindowController(NULL);
-
-const char*const FRAG_SHADER=
- "uniform mediump float alpha;\n"
- "\n"
- "void main()\n"
- "{\n"
- " mediump vec4 fragColor = texture2D(sTexture, vTexCoord);\n"
- " mediump vec4 fxColor = texture2D(sEffect, vTexCoord);\n"
- " gl_FragColor = mix(fragColor,fxColor, alpha);\n"
- "}\n";
-
-}; // anonymous namespace
-
-
-class NewWindowController : public ConnectionTracker
-{
-public:
- NewWindowController( Application& app );
- void Create( Application& app );
- void Destroy( Application& app );
- void OnKeyEvent(const KeyEvent& event);
- bool OnLoseContextButtonClicked( Toolkit::Button button );
- static void NewWindow(void);
-
- void OnContextLost();
- void OnContextRegained();
- void CreateMeshActor();
- Mesh CreateMesh(bool, Material);
- void CreateBubbles(Vector2 stageSize);
- void CreateBlending();
- void CreateText();
- bool OnTrackTimerTick();
- bool OnExplodeTimerTick();
- void SetUpAnimation( Vector2 emitPosition, Vector2 direction );
- FrameBufferImage CreateMirrorImage(const char* imageName);
- ImageActor CreateBlurredMirrorImage(const char* imageName);
- FrameBufferImage CreateFrameBufferForImage(const char* imageName, Image image, ShaderEffect shaderEffect);
-
-
-private:
- Application mApplication;
- Actor mCastingLight;
- TextActor mTextActor;
- ImageActor mImageActor;
- ImageActor mBlendActor;
- Image mEffectImage;
- Image mBaseImage;
- MeshActor mMeshActor;
- MeshActor mAnimatedMeshActor;
-
- Toolkit::View mView; ///< The View instance.
- Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
- TextView mTitleActor; ///< The Toolbar's Title.
- Layer mContentLayer; ///< Content layer (scrolling cluster content)
- Toolkit::PushButton mLoseContextButton;
- Vector3 mHSVDelta;
- Toolkit::BubbleEmitter mEmitter;
-
- Timer mEmitTrackTimer;
- Timer mExplodeTimer;
- bool mNeedNewAnimation;
-
- unsigned int mAnimateComponentCount;
- Animation mEmitAnimation;
-};
-
-
-NewWindowController::NewWindowController( Application& application )
-: mApplication(application),
- mHSVDelta(0.5f, 0.0f, 0.5f),
- mNeedNewAnimation(true)
-{
- mApplication.InitSignal().Connect(this, &NewWindowController::Create);
- mApplication.TerminateSignal().Connect(this, &NewWindowController::Destroy);
-}
-
-void NewWindowController::Create( Application& app )
-{
- Stage stage = Stage::GetCurrent();
- stage.SetBackgroundColor(Color::YELLOW);
-
- stage.KeyEventSignal().Connect(this, &NewWindowController::OnKeyEvent);
-
- // The Init signal is received once (only) during the Application lifetime
-
- // Hide the indicator bar
- mApplication.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
-
- mContentLayer = DemoHelper::CreateView( app,
- mView,
- mToolBar,
- BACKGROUND_IMAGE,
- TOOLBAR_IMAGE,
- "Context recovery" );
-
- // Point the default render task at the view
- RenderTaskList taskList = stage.GetRenderTaskList();
- RenderTask defaultTask = taskList.GetTask( 0u );
- if ( defaultTask )
- {
- defaultTask.SetSourceActor( mView );
- }
-
- mLoseContextButton = Toolkit::PushButton::New();
- mLoseContextButton.SetBackgroundImage( ResourceImage::New( LOSE_CONTEXT_IMAGE ) );
- mLoseContextButton.ClickedSignal().Connect( this, &NewWindowController::OnLoseContextButtonClicked );
- mToolBar.AddControl( mLoseContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
-
-
- Actor logoLayoutActor = Actor::New();
- logoLayoutActor.SetParentOrigin(ParentOrigin::CENTER);
- logoLayoutActor.SetPosition(0.0f, -200.0f, 0.0f);
- logoLayoutActor.SetScale(0.5f);
- mContentLayer.Add(logoLayoutActor);
-
- Image image = ResourceImage::New(DALI_IMAGE_DIR "dali-logo.png");
- mImageActor = ImageActor::New(image);
- mImageActor.SetName("dali-logo");
- mImageActor.SetParentOrigin(ParentOrigin::CENTER);
- mImageActor.SetAnchorPoint(AnchorPoint::BOTTOM_CENTER);
- logoLayoutActor.Add(mImageActor);
-
- ImageActor mirrorImageActor = CreateBlurredMirrorImage(DALI_IMAGE_DIR "dali-logo.png");
- mirrorImageActor.SetParentOrigin(ParentOrigin::CENTER);
- mirrorImageActor.SetAnchorPoint(AnchorPoint::TOP_CENTER);
- logoLayoutActor.Add(mirrorImageActor);
-
- CreateBubbles(stage.GetSize());
- CreateMeshActor();
- CreateBlending();
- CreateText();
-
- stage.ContextLostSignal().Connect(this, &NewWindowController::OnContextLost);
- stage.ContextRegainedSignal().Connect(this, &NewWindowController::OnContextRegained);
-}
-
-void NewWindowController::Destroy( Application& app )
-{
- UnparentAndReset(mTextActor);
-}
-
-bool NewWindowController::OnLoseContextButtonClicked( Toolkit::Button button )
-{
- // Add as an idle callback to avoid ProcessEvents being recursively called.
- mApplication.AddIdle( MakeCallback( NewWindowController::NewWindow ) );
- return true;
-}
-
-void NewWindowController::CreateMeshActor()
-{
- mEffectImage = ResourceImage::New(EFFECT_IMAGE);
-
- Material baseMaterial = Material::New( "Material1" );
- Dali::MeshActor meshActor = MeshActor::New( CreateMesh(true, baseMaterial) );
- meshActor.SetScale( 100.0f );
- meshActor.SetParentOrigin( ParentOrigin::CENTER );
- meshActor.SetPosition(Vector3( -150.0f, 200.0f, 0.0f ));
- meshActor.SetName("MeshActor");
- mContentLayer.Add( meshActor );
-
- Material orchidMaterial = Material::New( "Material2" );
- orchidMaterial.SetDiffuseTexture(mEffectImage);
-
- Dali::MeshActor meshActor2 = MeshActor::New( CreateMesh(false, orchidMaterial) );
- meshActor2.SetScale( 100.0f );
- meshActor2.SetParentOrigin( ParentOrigin::CENTER );
- meshActor2.SetPosition(Vector3( -150.0f, 310.0f, 0.0f ));
- meshActor2.SetName("MeshActor");
- mContentLayer.Add( meshActor2 );
-}
-
-FrameBufferImage NewWindowController::CreateMirrorImage(const char* imageName)
-{
- FrameBufferImage fbo;
- Image image = ResourceImage::New(imageName);
- fbo = CreateFrameBufferForImage(imageName, image, ShaderEffect());
- return fbo;
-}
-
-ImageActor NewWindowController::CreateBlurredMirrorImage(const char* imageName)
-{
- FrameBufferImage fbo;
- Image image = ResourceImage::New( imageName );
- Vector2 FBOSize = ResourceImage::GetImageSize(imageName);
- fbo = FrameBufferImage::New( FBOSize.width, FBOSize.height, Pixel::RGBA8888);
- GaussianBlurView gbv = GaussianBlurView::New(5, 2.0f, Pixel::RGBA8888, 0.5f, 0.5f, true);
- gbv.SetBackgroundColor(Color::TRANSPARENT);
- gbv.SetUserImageAndOutputRenderTarget( image, fbo );
- gbv.SetSize(FBOSize);
- Stage::GetCurrent().Add(gbv);
- gbv.ActivateOnce();
-
- ImageActor blurredActor = ImageActor::New(fbo);
- blurredActor.SetSize(FBOSize);
- blurredActor.SetScale(1.0f, -1.0f, 1.0f);
- return blurredActor;
-}
-
-FrameBufferImage NewWindowController::CreateFrameBufferForImage(const char* imageName, Image image, ShaderEffect shaderEffect)
-{
- Stage stage = Stage::GetCurrent();
- Vector2 FBOSize = ResourceImage::GetImageSize(imageName);
-
- FrameBufferImage framebuffer = FrameBufferImage::New(FBOSize.x, FBOSize.y );
-
- RenderTask renderTask = stage.GetRenderTaskList().CreateTask();
-
- ImageActor imageActor = ImageActor::New(image);
- imageActor.SetName("Source image actor");
- if(shaderEffect)
- {
- imageActor.SetShaderEffect(shaderEffect);
- }
- imageActor.SetParentOrigin(ParentOrigin::CENTER);
- imageActor.SetAnchorPoint(AnchorPoint::CENTER);
- imageActor.SetScale(1.0f, -1.0f, 1.0f);
- stage.Add(imageActor); // Not in default image view
-
- CameraActor cameraActor = CameraActor::New(FBOSize);
- cameraActor.SetParentOrigin(ParentOrigin::CENTER);
- cameraActor.SetFieldOfView(Math::PI*0.25f);
- cameraActor.SetNearClippingPlane(1.0f);
- cameraActor.SetAspectRatio(FBOSize.width / FBOSize.height);
- cameraActor.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor
- cameraActor.SetRotation(Quaternion(M_PI, Vector3::YAXIS));
- cameraActor.SetPosition(0.0f, 0.0f, ((FBOSize.height * 0.5f) / tanf(Math::PI * 0.125f)));
- stage.Add(cameraActor);
-
- renderTask.SetSourceActor(imageActor);
- renderTask.SetInputEnabled(false);
- renderTask.SetTargetFrameBuffer(framebuffer);
- renderTask.SetCameraActor( cameraActor );
- renderTask.SetClearColor( Color::TRANSPARENT );
- renderTask.SetClearEnabled( true );
- renderTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
-
- return framebuffer;
-}
-
-void NewWindowController::CreateBubbles(Vector2 stageSize)
-{
- mEmitter = Toolkit::BubbleEmitter::New( stageSize,
- ResourceImage::New( DALI_IMAGE_DIR "bubble-ball.png" ),
- 1000, Vector2( 5.0f, 5.0f ) );
-
- Image background = ResourceImage::New(BACKGROUND_IMAGE);
- mEmitter.SetBackground( background, mHSVDelta );
- Actor bubbleRoot = mEmitter.GetRootActor();
- mContentLayer.Add( bubbleRoot );
- bubbleRoot.SetParentOrigin(ParentOrigin::CENTER);
- bubbleRoot.SetZ(0.1f);
-
- mEmitTrackTimer = Timer::New( EMIT_INTERVAL_IN_MS );
- mEmitTrackTimer.TickSignal().Connect(this, &NewWindowController::OnTrackTimerTick);
- mEmitTrackTimer.Start();
-
- //mExplodeTimer = Timer::New( Random::Range(4000.f, 8000.f) );
- //mExplodeTimer.TickSignal().Connect(this, &NewWindowController::OnExplodeTimerTick);
- //mExplodeTimer.Start();
-}
-
-bool NewWindowController::OnExplodeTimerTick()
-{
- mEmitter.StartExplosion( EXPLOSION_DURATION, 5.0f );
-
- mExplodeTimer = Timer::New( Random::Range(4.f, 8.f) );
- mExplodeTimer.TickSignal().Connect(this, &NewWindowController::OnExplodeTimerTick);
- return false;
-}
-
-void NewWindowController::SetUpAnimation( Vector2 emitPosition, Vector2 direction )
-{
- if( mNeedNewAnimation )
- {
- float duration = Random::Range(1.f, 1.5f);
- mEmitAnimation = Animation::New( duration );
- mNeedNewAnimation = false;
- mAnimateComponentCount = 0;
- }
-
- mEmitter.EmitBubble( mEmitAnimation, emitPosition, direction, Vector2(1, 1) );
-
- mAnimateComponentCount++;
-
- if( mAnimateComponentCount % 20 ==0 )
- {
- mEmitAnimation.Play();
- mNeedNewAnimation = true;
- }
-}
-
-bool NewWindowController::OnTrackTimerTick()
-{
- static int time=0;
- const float radius(250.0f);
-
- time += EMIT_INTERVAL_IN_MS;
- float modTime = time / TRACK_DURATION_IN_MS;
- float angle = 2.0f*Math::PI*modTime;
-
- Vector2 position(radius*cosf(angle), radius*-sinf(angle));
- Vector2 aimPos(radius*2*sinf(angle), radius*2*-cosf(angle));
- Vector2 direction = aimPos-position;
- Vector2 stageSize = Stage::GetCurrent().GetSize();
-
- for(int i=0; i<20; i++)
- {
- SetUpAnimation( stageSize*0.5f+position, direction );
- }
-
- return true;
-}
-
-
-void NewWindowController::CreateBlending()
-{
- Toolkit::ColorAdjuster colorAdjuster = ColorAdjuster::New(mHSVDelta);
- FrameBufferImage fb2 = CreateFrameBufferForImage( EFFECT_IMAGE, mEffectImage, colorAdjuster );
-
- ImageActor tmpActor = ImageActor::New(fb2);
- mContentLayer.Add(tmpActor);
- tmpActor.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
- tmpActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
- tmpActor.SetScale(0.25f);
-
- // create blending shader effect
- ShaderEffect blendShader = ShaderEffect::New( "", FRAG_SHADER );
- blendShader.SetEffectImage( fb2 );
- blendShader.SetUniform("alpha", 0.5f);
-
- mBaseImage = ResourceImage::New(BASE_IMAGE);
- mBlendActor = ImageActor::New( mBaseImage );
- mBlendActor.SetParentOrigin(ParentOrigin::CENTER);
- mBlendActor.SetPosition(Vector3(150.0f, 200.0f, 0.0f));
- mBlendActor.SetSize(140, 140);
- mBlendActor.SetShaderEffect( blendShader );
- mContentLayer.Add(mBlendActor);
-}
-
-void NewWindowController::CreateText()
-{
- mTextActor = TextActor::New("Some text");
- mTextActor.SetParentOrigin(ParentOrigin::CENTER);
- mTextActor.SetColor(Color::RED);
- mTextActor.SetName("PushMe text");
- mContentLayer.Add( mTextActor );
-}
-
-Mesh NewWindowController::CreateMesh(bool hasColor, Material material)
-{
- // Create vertices and specify their color
- MeshData::VertexContainer vertices(4);
- vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2(0.0f, 0.0f), Vector3(1.0f, 0.0f, 0.0f) );
- vertices[ 1 ] = MeshData::Vertex( Vector3( 0.5f, -0.5f, 0.0f ), Vector2(1.0f, 0.0f), Vector3(1.0f, 1.0f, 0.0f) );
- vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f, 0.5f, 0.0f ), Vector2(0.0f, 1.0f), Vector3(0.0f,1.0f,0.0f) );
- vertices[ 3 ] = MeshData::Vertex( Vector3( 0.5f, 0.5f, 0.0f ), Vector2(1.0f, 1.0f), Vector3(0.0f,0.0f,1.0f) );
-
- // Specify all the faces
- MeshData::FaceIndices faces;
- faces.reserve( 6 ); // 2 triangles in Quad
- faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
- faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
-
- // Create the mesh data from the vertices and faces
- MeshData meshData;
- meshData.SetHasColor( hasColor );
- meshData.SetMaterial( material );
- meshData.SetVertices( vertices );
- meshData.SetFaceIndices( faces );
-
- // Create a mesh from the data
- Dali::Mesh mesh = Mesh::New( meshData );
- return mesh;
-}
-
-void NewWindowController::NewWindow(void)
-{
- PositionSize posSize(0, 0, 720, 1280);
- gApplication.ReplaceWindow(posSize, "NewWindow"); // Generates a new window
-}
-
-void NewWindowController::OnKeyEvent(const KeyEvent& event)
-{
- if(event.state == KeyEvent::Down)
- {
- if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
- {
- mApplication.Quit();
- }
- }
-}
-
-void NewWindowController::OnContextLost()
-{
- printf("Stage reporting context loss\n");
-}
-
-void NewWindowController::OnContextRegained()
-{
- printf("Stage reporting context regain\n");
-}
-
-
-
-
-void RunTest(Application& app)
-{
- gNewWindowController = new NewWindowController(app);
- app.MainLoop(Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS);
-}
-
-// Entry point for Linux & SLP applications
-//
-
-int main(int argc, char **argv)
-{
- gApplication = Application::New(&argc, &argv);
- RunTest(gApplication);
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-/**
- * This example shows how to use path animations in DALi
- */
-
-// EXTERNAL INCLUDES
-#include <dali-toolkit/dali-toolkit.h>
-
-// INTERNAL INCLUDES
-#include "shared/view.h"
-
-using namespace Dali;
-using namespace Dali::Toolkit;
-
-
-namespace
-{
-const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-default.png" );
-const char* ACTOR_IMAGE( DALI_IMAGE_DIR "dali-logo.png" );
-const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
-const char* APPLICATION_TITLE( "Path Example" );
-}; //Unnamed namespace
-
-/**
- * @brief The main class of the demo.
- */
-class PathController : public ConnectionTracker
-{
-public:
-
- PathController( Application& application )
- : mApplication( application )
- {
- // Connect to the Application's Init signal
- mApplication.InitSignal().Connect( this, &PathController::Create );
- }
-
- ~PathController()
- {
- // Nothing to do here.
- }
-
- /**
- * One-time setup in response to Application InitSignal.
- */
- void Create( Application& application )
- {
- // Get a handle to the stage:
- Stage stage = Stage::GetCurrent();
-
- // Connect to input event signals:
- stage.KeyEventSignal().Connect(this, &PathController::OnKeyEvent);
-
- // Create a default view with a default tool bar:
- Toolkit::View view; ///< The View instance.
- Toolkit::ToolBar toolBar; ///< The View's Toolbar.
- mContentLayer = DemoHelper::CreateView( mApplication,
- view,
- toolBar,
- BACKGROUND_IMAGE,
- TOOLBAR_IMAGE,
- "" );
-
- mContentLayer.TouchedSignal().Connect(this, &PathController::OnTouchLayer);
-
- //Title
- TextView title = TextView::New();
- toolBar.AddControl( title, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
- Font font = Font::New();
- title.SetText( APPLICATION_TITLE );
- title.SetSize( font.MeasureText( APPLICATION_TITLE ) );
- title.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle());
-
- //Path
- mPath = Dali::Path::New();
- mPath.AddPoint( Vector3( 10.0f, stage.GetSize().y*0.5f, 0.0f ));
- mPath.AddPoint( Vector3( stage.GetSize().x*0.5f, stage.GetSize().y*0.3f, 0.0f ));
- mPath.GenerateControlPoints(0.25f);
- DrawPath( 200u );
-
- //Actor
- ImageAttributes attributes;
- Image img = ResourceImage::New(ACTOR_IMAGE, attributes );
- mActor = ImageActor::New( img );
- mActor.SetPosition( Vector3( 10.0f, stage.GetSize().y*0.5f, 0.0f ) );
- mActor.SetAnchorPoint( AnchorPoint::CENTER );
- mActor.SetSize( 100, 50, 1 );
- stage.Add( mActor );
-
- mForward = Vector3::XAXIS;
- CreateAnimation();
-
- Dali::TextActor forwardLabel = TextActor::New("Forward Vector");
- forwardLabel.SetPosition( 10.0f, stage.GetSize().y - 60.0f, 0.0f );
- forwardLabel.SetColor( Vector4(0.0f,0.0f,0.0f,1.0f));
- forwardLabel.SetAnchorPoint( AnchorPoint::CENTER_LEFT);
- mContentLayer.Add( forwardLabel );
-
- //TextInput
- Dali::Layer textInputLayer = Dali::Layer::New();
- textInputLayer.SetSize( 400.0f, 30.0f, 0.0 );
- textInputLayer.SetPosition( 0.0f, stage.GetSize().y - 30.0f, 0.0f );
- textInputLayer.SetAnchorPoint( AnchorPoint::TOP_LEFT);
- textInputLayer.SetParentOrigin( ParentOrigin::TOP_LEFT);
- stage.Add( textInputLayer );
- Dali::TextActor label = TextActor::New("X:");
- label.SetPosition( 10.0f, 0.0f, 0.0f );
- label.SetColor( Vector4(0.0f,0.0f,0.0f,1.0f));
- label.SetAnchorPoint( AnchorPoint::CENTER_LEFT);
- textInputLayer.Add( label );
- TextStyle style;
- style.SetTextColor( Vector4( 0.0f, 0.0f ,0.0f, 1.0f ));
- mTextInput[0] = TextInput::New();
- mTextInput[0].SetInitialText("1.0");
- mTextInput[0].SetColor( Vector4(0.0f,0.0f,0.0f,1.0f));
- mTextInput[0].SetAnchorPoint( AnchorPoint::CENTER_LEFT);
- mTextInput[0].SetParentOrigin( ParentOrigin::CENTER_RIGHT);
- mTextInput[0].SetPosition( 10.0f, 0.0f, 0.0f );
- mTextInput[0].SetSize( 70.0f, 0.0f, 0.0f );
- mTextInput[0].SetTextAlignment(Alignment::HorizontalCenter );
- mTextInput[0].SetMaxCharacterLength( 5 );
- mTextInput[0].SetNumberOfLinesLimit(1);
- mTextInput[0].ApplyStyleToAll( style );
- mTextInput[0].SetProperty( mTextInput[0].GetPropertyIndex("cursor-color"), Vector4(0.0f,0.0f,0.0f,1.0f) );
- mTextInput[0].SetBackgroundColor( Vector4(0.8f,1.0f,0.8f, 0.4f));
- mTextInput[0].InputFinishedSignal().Connect(this, &PathController::OnTextInputEnd);
- mTextInput[0].SetEditOnTouch();
- label.Add( mTextInput[0]);
- label = TextActor::New("Y:");
- label.SetPosition( 160.0f,0.0f, 0.0f );
- label.SetColor( Vector4(0.0f,0.0f,0.0f,1.0f));
- label.SetAnchorPoint( AnchorPoint::CENTER_LEFT);
- textInputLayer.Add( label );
- mTextInput[1] = TextInput::New();
- mTextInput[1].SetInitialText("0.0");
- mTextInput[1].SetColor( Vector4(0.0f,0.0f,0.0f,1.0f));
- mTextInput[1].SetAnchorPoint( AnchorPoint::CENTER_LEFT);
- mTextInput[1].SetParentOrigin( ParentOrigin::CENTER_RIGHT);
- mTextInput[1].SetPosition( 10.0f, 0.0f, 0.0f );
- mTextInput[1].SetSize( 70.0f, 0.0f, 0.0f );
- mTextInput[1].SetTextAlignment(Alignment::HorizontalCenter );
- mTextInput[1].SetMaxCharacterLength( 5 );
- mTextInput[1].SetNumberOfLinesLimit(1);
- mTextInput[1].ApplyStyleToAll( style );
- mTextInput[1].SetProperty( mTextInput[1].GetPropertyIndex("cursor-color"), Vector4(0.0f,0.0f,0.0f,1.0f) );
- mTextInput[1].SetBackgroundColor( Vector4(0.8f,1.0f,0.8f, 0.4f));
- mTextInput[1].InputFinishedSignal().Connect(this, &PathController::OnTextInputEnd);
- label.Add( mTextInput[1]);
- label = TextActor::New("Z:");
- label.SetPosition( 310.0f, 0.0f, 0.0f );
- label.SetColor( Vector4(0.0f,0.0f,0.0f,1.0f));
- label.SetAnchorPoint( AnchorPoint::CENTER_LEFT);
- textInputLayer.Add( label );
- mTextInput[2] = TextInput::New();
- mTextInput[2].SetInitialText("0.0");
- mTextInput[2].SetColor( Vector4(0.0f,0.0f,0.0f,1.0f));
- mTextInput[2].SetAnchorPoint( AnchorPoint::CENTER_LEFT);
- mTextInput[2].SetParentOrigin( ParentOrigin::CENTER_RIGHT);
- mTextInput[2].SetPosition( 10.0f, 0.0f, 0.0f );
- mTextInput[2].SetSize( 70.0f, 0.0f, 0.0f );
- mTextInput[2].SetTextAlignment(Alignment::HorizontalCenter );
- mTextInput[2].SetMaxCharacterLength( 5 );
- mTextInput[2].SetNumberOfLinesLimit(1);
- mTextInput[2].ApplyStyleToAll( style );
- mTextInput[2].SetProperty( mTextInput[2].GetPropertyIndex("cursor-color"), Vector4(0.0f,0.0f,0.0f,1.0f) );
- mTextInput[2].SetBackgroundColor( Vector4(0.8f,1.0f,0.8f, 0.4f));
- mTextInput[2].InputFinishedSignal().Connect(this, &PathController::OnTextInputEnd);
- label.Add( mTextInput[2]);
- }
-
- /**
- * Create an actor representing a control point of the curve
- * @param[in] name Name of the actor
- * @param[in] size Size of the containing actor
- * @param[in] imageSize Size of the imageActor
- * @param[in] color Color of the imageActor
- */
- Actor CreateControlPoint(const std::string& name, const Vector3& size, const Vector3& imageSize, const Vector4& color )
- {
- Actor actor = Actor::New();
- actor.SetParentOrigin( ParentOrigin::TOP_LEFT);
- actor.SetAnchorPoint( AnchorPoint::CENTER );
- actor.SetSize( size );
- actor.SetName( name );
- actor.TouchedSignal().Connect(this, &PathController::OnTouchPoint);
-
- ImageActor imageActor = Toolkit::CreateSolidColorActor(color);
- imageActor.SetColor(Vector4(1.0f,0.0f,0.0f,1.0f));
- imageActor.SetParentOrigin( ParentOrigin::CENTER);
- imageActor.SetAnchorPoint( AnchorPoint::CENTER );
- imageActor.SetSize( imageSize );
- actor.Add(imageActor );
-
- return actor;
- }
-
- /**
- * Draws the path and the control points for the path
- * @param[in] resolution Number of segments for the path.
- */
- void DrawPath( unsigned int resolution )
- {
- Stage stage = Dali::Stage::GetCurrent();
-
- //Create path mesh actor
- Dali::MeshData meshData = MeshFactory::NewPath( mPath, resolution );
- Dali::Material material = Material::New("LineMaterial");
- material.SetDiffuseColor( Vector4(0.0f,0.0f,0.0f,1.0f));
- meshData.SetMaterial(material);
- Dali::Mesh mesh = Dali::Mesh::New( meshData );
- if( mMeshPath )
- {
- stage.Remove( mMeshPath );
- }
- mMeshPath = Dali::MeshActor::New( mesh );
- mMeshPath.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mMeshPath.SetParentOrigin( ParentOrigin::TOP_LEFT );
- stage.Add( mMeshPath );
-
-
- ////Create mesh connecting interpolation points and control points
- std::vector<Dali::MeshData::Vertex> vVertex;
- std::vector<unsigned short> vIndex;
- size_t pointCount = mPath.GetPointCount();
- size_t controlPointIndex = 0;
- for( size_t i(0); i<pointCount; ++i )
- {
- vVertex.push_back( MeshData::Vertex(mPath.GetPoint(i),Vector2::ZERO, Vector3::ZERO ) );
- if( i<pointCount-1)
- {
- vVertex.push_back( MeshData::Vertex(mPath.GetControlPoint(controlPointIndex),Vector2::ZERO, Vector3::ZERO ));
- vVertex.push_back( MeshData::Vertex(mPath.GetControlPoint(controlPointIndex+1),Vector2::ZERO, Vector3::ZERO ));
- }
- controlPointIndex += 2;
- }
-
- size_t segmentCount = 2*(pointCount-2)+2;
- unsigned short index=0;
- for( size_t i(0); i<segmentCount; ++i, ++index )
- {
- vIndex.push_back(index);
- vIndex.push_back(index+1);
-
- if( ~i & 1 )
- {
- index++;
- }
- }
-
- meshData.SetLineData( vVertex, vIndex, material );
- meshData.SetMaterial(material);
- mesh = Dali::Mesh::New( meshData );
- if( mMeshHandlers )
- {
- stage.Remove( mMeshHandlers );
- }
- mMeshHandlers = Dali::MeshActor::New( mesh );
- mMeshHandlers.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mMeshHandlers.SetParentOrigin( ParentOrigin::TOP_LEFT );
- stage.Add( mMeshHandlers );
-
-
- //Create actors representing interpolation points
- for( size_t i(0); i<pointCount; ++i )
- {
- if( !mKnot[i] )
- {
- std::string name( "Knot");
- name.push_back(i);
- mKnot[i] = CreateControlPoint( name, Vector3(150.0f,150.0f,0.0f), Vector3(20.0f,20.0f,0.0f), Vector4(0.0f,0.0f,0.0f,1.0f) );
- mContentLayer.Add(mKnot[i] );
- }
-
- mKnot[i].SetPosition( mPath.GetPoint(i) );
- }
-
- //Create actors representing control points
- size_t controlPointCount=2*(pointCount-1);
- for( size_t i(0); i<controlPointCount; ++i )
- {
- if( !mControlPoint[i])
- {
- std::string name( "ControlPoint");
- name.push_back(i);
- mControlPoint[i] = CreateControlPoint( name, Vector3(150.0f,150.0f,0.0f), Vector3(20.0f,20.0f,0.0f), Vector4(1.0f,0.0f,0.0f,1.0f) );
- mContentLayer.Add(mControlPoint[i] );
- }
-
- mControlPoint[i].SetPosition( mPath.GetControlPoint(i) );
- }
- }
-
- bool OnTouchPoint(Actor actor, const TouchEvent& event)
- {
- if(event.GetPointCount()>0)
- {
- const TouchPoint& point = event.GetPoint(0);
-
- if(point.state==TouchPoint::Down)
- {
- // Start dragging
- mDragActor = actor;
- }
- }
- return false;
- }
-
- bool OnTouchLayer(Actor actor, const TouchEvent& event)
- {
- if(event.GetPointCount()>0)
- {
- const TouchPoint& point = event.GetPoint(0);
-
- if(point.state==TouchPoint::Up)
- {
- //Stop dragging
- mDragActor.Reset();
- }
- else if(!mDragActor && point.state==TouchPoint::Down && mPath.GetPointCount()<10 )
- {
- // Add new point
- const TouchPoint& point = event.GetPoint(0);
- Vector3 newPoint = Vector3(point.screen.x, point.screen.y, 0.0f);
-
- size_t pointCount = mPath.GetPointCount();
- Vector3 lastPoint = mPath.GetPoint( pointCount-1);
- mPath.AddPoint( newPoint );
-
- Vector3 displacement = (newPoint-lastPoint)/8;
-
- mPath.AddControlPoint( lastPoint + displacement );
- mPath.AddControlPoint( newPoint - displacement);
-
- DrawPath( 200u );
- CreateAnimation();
- }
- else
- {
- if( mDragActor )
- {
- const TouchPoint& point = event.GetPoint(0);
- Vector3 newPosition = Vector3(point.screen.x, point.screen.y, 0.0f);
-
- std::string actorName(mDragActor.GetName());
-
- if( actorName.compare(0, 4, "Knot") == 0)
- {
- int index = actorName[4];
- mPath.GetPoint(index) = newPosition;
- }
- else
- {
- int index = actorName[12];
- mPath.GetControlPoint(index) = newPosition;
- }
-
- DrawPath( 200u );
- CreateAnimation();
- }
- }
- }
- return false;
- }
-
- /**
- * Main key event handler.
- * Quit on escape key.
- */
- void OnKeyEvent(const KeyEvent& event)
- {
- if( event.state == KeyEvent::Down )
- {
- if( IsKey( event, Dali::DALI_KEY_ESCAPE ) ||
- IsKey( event, Dali::DALI_KEY_BACK ) )
- {
- mApplication.Quit();
- }
- }
- }
-
- /**
- * Callback called when user end to input text in any of the TextInput
- * @param[in] textInput The text input that has generated the signal
- */
- void OnTextInputEnd( TextInput textInput)
- {
- mForward.x = (float)atof( mTextInput[0].GetText().c_str() );
- mForward.y = (float)atof( mTextInput[1].GetText().c_str() );
- mForward.z = (float)atof( mTextInput[2].GetText().c_str() );
- CreateAnimation();
- }
-
- /**
- * Create the path animation.
- */
- void CreateAnimation()
- {
- if( !mAnimation )
- {
- mAnimation = Animation::New( 2.0f );
- }
- else
- {
- mAnimation.Pause();
- mAnimation.Clear();
- mActor.SetRotation( Quaternion() );
- }
-
- mAnimation.Animate( mActor, mPath, mForward );
- mAnimation.SetLooping( true );
- mAnimation.Play();
- }
-
-private:
- Application& mApplication;
-
- Layer mContentLayer; ///< The content layer
-
- Path mPath; ///< The path used in the animation
- ImageActor mActor; ///< Actor being animated
- Vector3 mForward; ///< Current forward vector
- Animation mAnimation; ///< Path animation
-
- MeshActor mMeshPath; ///< Mesh actor for the path
- MeshActor mMeshHandlers; ///< Mesh actor for the segments connecting points and control points
- Actor mKnot[10]; ///< ImageActors for the interpolation points
- Actor mControlPoint[18]; ///< ImageActors for the control points
-
- Actor mDragActor; ///< Reference to the actor currently being dragged
- TextInput mTextInput[3]; ///< Text input to specify forward vector of the path animation
-};
-
-void RunTest( Application& application )
-{
- PathController test( application );
-
- application.MainLoop();
-}
-
-/** Entry point for Linux & Tizen applications */
-int main( int argc, char **argv )
-{
- Application application = Application::New( &argc, &argv );
-
- RunTest( application );
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/dali.h>
-#include <dali-toolkit/dali-toolkit.h>
-#include "shared/view.h"
-#include "radial-sweep-view.h"
-#include "radial-sweep-view-impl.h"
-
-using namespace Dali;
-using namespace Dali::Toolkit;
-
-namespace
-{
-const char* TEST_OUTER_RING_FILENAME = DALI_IMAGE_DIR "layer2.png"; // Image to be masked
-const char* TEST_INNER_RING_FILENAME = DALI_IMAGE_DIR "layer1.png"; // Image to be masked
-const char* TEST_MENU_FILENAME = DALI_IMAGE_DIR "layer3.png"; // Image to be masked
-const char* TEST_DIAL_FILENAME = DALI_IMAGE_DIR "layer4.png"; // Image to be masked
-const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); // Background for toolbar
-const char* APPLICATION_TITLE( "Radial Menu" );
-const char * const PLAY_ICON( DALI_IMAGE_DIR "icon-play.png" );
-const char * const STOP_ICON( DALI_IMAGE_DIR "icon-stop.png" );
-}
-
-
-/********************************************************************************
- * Application controller class
- */
-
-// This example shows how to create a mesh actor for use as a stencil buffer
-class RadialMenuExample : public ConnectionTracker
-{
-public:
- /**
- * Constructor
- * @param[in] app The application handle
- */
- RadialMenuExample(Application app);
-
- /**
- * Destructor
- */
- ~RadialMenuExample();
-
-private:
-
- /**
- * Initialization signal handler - all actor initialization should happen here
- * @param[in] app The application handle
- */
- void OnInit(Application& app);
-
- /**
- * Create a sweep view with the given image and parameters
- */
- RadialSweepView CreateSweepView( std::string imageName, Degree initial, Degree final );
-
- void StartAnimation();
-
- bool OnButtonClicked( Toolkit::Button button );
-
- void OnAnimationFinished( Animation& source );
-
- /**
- * Main key event handler
- *
- * @param[in] event The key event to respond to
- */
- void OnKeyEvent(const KeyEvent& event);
-
-private: // Member variables
- enum AnimState
- {
- STOPPED,
- PAUSED,
- PLAYING
- };
-
- Application mApplication; ///< The application handle
- Toolkit::View mView; ///< The toolbar view
- Layer mContents; ///< The toolbar contents pane
- ImageActor mImageActor; ///< Image actor shown by stencil mask
- Animation mAnimation;
- AnimState mAnimationState;
-
- Image mIconPlay;
- Image mIconStop;
- Toolkit::PushButton mPlayStopButton;
- ImageActor mDialActor;
- RadialSweepView mRadialSweepView1;
- RadialSweepView mRadialSweepView2;
- RadialSweepView mRadialSweepView3;
-};
-
-RadialMenuExample::RadialMenuExample(Application app)
-: mApplication( app ),
- mAnimationState(STOPPED)
-{
- // Connect to the Application's Init signal
- app.InitSignal().Connect(this, &RadialMenuExample::OnInit);
-}
-
-RadialMenuExample::~RadialMenuExample()
-{
- // Nothing to do here; actor handles will clean up themselves.
-}
-
-void RadialMenuExample::OnInit(Application& app)
-{
- Stage stage = Dali::Stage::GetCurrent();
-
- // The Init signal is received once (only) during the Application lifetime
- stage.KeyEventSignal().Connect(this, &RadialMenuExample::OnKeyEvent);
-
- // Create toolbar & view
- Toolkit::ToolBar toolBar;
- mContents = DemoHelper::CreateView( mApplication,
- mView,
- toolBar,
- "",
- TOOLBAR_IMAGE,
- APPLICATION_TITLE );
-
- mIconPlay = ResourceImage::New( PLAY_ICON );
- mIconStop = ResourceImage::New( STOP_ICON );
- mPlayStopButton = Toolkit::PushButton::New();
- mPlayStopButton.SetBackgroundImage( mIconStop );
-
- mPlayStopButton.ClickedSignal().Connect( this, &RadialMenuExample::OnButtonClicked );
-
- toolBar.AddControl( mPlayStopButton,
- DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
- Toolkit::Alignment::HorizontalRight,
- DemoHelper::DEFAULT_PLAY_PADDING );
-
- Vector2 imgSize = ResourceImage::GetImageSize(TEST_OUTER_RING_FILENAME);
- Vector2 stageSize = stage.GetSize();
- float minStageDimension = std::min(stageSize.width, stageSize.height);
-
- if(stageSize.height <= stageSize.width)
- {
- minStageDimension -= DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight * 2.0f;
- }
- float scale = minStageDimension / imgSize.width;
-
- mRadialSweepView1 = CreateSweepView( TEST_OUTER_RING_FILENAME, Degree(-90.0f), Degree(-90.0f));
- mRadialSweepView2 = CreateSweepView( TEST_INNER_RING_FILENAME, Degree(90.0f), Degree(0.0f));
- mRadialSweepView3 = CreateSweepView( TEST_MENU_FILENAME, Degree(100.0f), Degree(0.0f));
- mRadialSweepView3.SetInitialActorAngle(Degree(-110));
- mRadialSweepView3.SetFinalActorAngle(Degree(0));
-
- Image dial = ResourceImage::New( TEST_DIAL_FILENAME );
- mDialActor = ImageActor::New( dial );
- mDialActor.SetPositionInheritanceMode(USE_PARENT_POSITION);
- mDialActor.SetScale(scale);
- Layer dialLayer = Layer::New();
-
- dialLayer.Add(mDialActor);
- dialLayer.SetPositionInheritanceMode(USE_PARENT_POSITION);
- dialLayer.SetSize(stage.GetSize());
- mContents.Add(dialLayer);
-
- mRadialSweepView1.SetScale(scale);
- mRadialSweepView2.SetScale(scale);
- mRadialSweepView3.SetScale(scale);
-
- StartAnimation();
-}
-
-void RadialMenuExample::StartAnimation()
-{
- mDialActor.SetOpacity(0.0f);
- mRadialSweepView1.SetOpacity(0.0f);
- mAnimation = Animation::New(6.0f);
- mRadialSweepView1.Activate(mAnimation, 0.0f, 3.0f);
- mRadialSweepView2.Activate(mAnimation, 1.5f, 3.0f);
- mRadialSweepView3.Activate(mAnimation, 3.0f, 3.0f);
- mAnimation.OpacityTo(mDialActor, 1.0f, AlphaFunctions::EaseIn, 0.0f, 0.8f);
- mAnimation.OpacityTo(mRadialSweepView1, 1.0f, AlphaFunctions::EaseIn, 0.0f, 0.5f);
- mAnimation.FinishedSignal().Connect( this, &RadialMenuExample::OnAnimationFinished );
-
- mAnimationState = PLAYING;
- mAnimation.Play();
-}
-
-bool RadialMenuExample::OnButtonClicked( Toolkit::Button button )
-{
- switch( mAnimationState )
- {
- case PLAYING:
- {
- mAnimation.Pause();
- mPlayStopButton.SetBackgroundImage( mIconPlay );
- }
- break;
-
- case PAUSED:
- {
- mAnimation.Play();
- mPlayStopButton.SetBackgroundImage( mIconStop );
- }
- break;
-
- case STOPPED:
- {
- mPlayStopButton.SetBackgroundImage( mIconStop );
- mRadialSweepView1.Deactivate();
- mRadialSweepView2.Deactivate();
- mRadialSweepView3.Deactivate();
- StartAnimation();
- }
- }
- return false;
-}
-
-void RadialMenuExample::OnAnimationFinished( Animation& source )
-{
- mAnimationState = STOPPED;
- mPlayStopButton.SetBackgroundImage( mIconPlay );
-}
-
-RadialSweepView RadialMenuExample::CreateSweepView( std::string imageName,
- Degree initialAngle,
- Degree finalAngle)
-{
- // Create the image
- Image image = ResourceImage::New(imageName);
- mImageActor = ImageActor::New(image);
- mImageActor.SetParentOrigin(ParentOrigin::CENTER);
- mImageActor.SetAnchorPoint(AnchorPoint::CENTER);
-
- // Create the stencil
- Vector2 imageSize = ResourceImage::GetImageSize(imageName);
- float diameter = std::max(imageSize.width, imageSize.height);
- RadialSweepView radialSweepView = RadialSweepView::New();
- radialSweepView.SetDiameter( diameter );
- radialSweepView.SetInitialAngle( initialAngle );
- radialSweepView.SetFinalAngle( finalAngle );
- radialSweepView.SetInitialSector( Degree(0.0f) );
- radialSweepView.SetFinalSector( Degree(359.999f) );
- radialSweepView.SetSize( Stage::GetCurrent().GetSize());
- radialSweepView.SetEasingFunction( Dali::AlphaFunctions::EaseInOut );
- radialSweepView.SetPositionInheritanceMode(USE_PARENT_POSITION);
- mContents.Add(radialSweepView);
- radialSweepView.Add( mImageActor );
- mImageActor.SetPositionInheritanceMode(USE_PARENT_POSITION);
-
- return radialSweepView;
-}
-
-
-void RadialMenuExample::OnKeyEvent(const KeyEvent& event)
-{
- if(event.state == KeyEvent::Down)
- {
- if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
- {
- mApplication.Quit();
- }
- }
-}
-
-void RunTest(Application app)
-{
- RadialMenuExample test(app);
-
- app.MainLoop();
-}
-
-// Entry point for Linux & Tizen applications
-int main(int argc, char **argv)
-{
- Application app = Application::New(&argc, &argv);
-
- RunTest(app);
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "radial-sweep-view-impl.h"
-
-using namespace Dali;
-
-namespace
-{
-
-/**
- * Method to project a point on a circle of radius halfSide at given
- * angle onto a square of side 2 * halfSide
- */
-Vector3 CircleSquareProjection( Degree angle, float halfSide )
-{
- Vector3 position(0.0f, 0.0f, 0.0f);
- Radian angleInRadians(angle);
-
- // 135 90 45
- // +--+--+
- // | \|/ |
- // 180 +--+--+ 0
- // | /|\ |
- // +--+--+
- // 225 270 315
- if( angle >= 45.0f && angle < 135.0f )
- {
- position.x = halfSide * cosf(angleInRadians) / sinf(angleInRadians);
- position.y = -halfSide;
- }
- else if( angle >= 135.0f && angle < 225.0f )
- {
- position.x = -halfSide;
- position.y = halfSide * sinf(angleInRadians) / cosf(angleInRadians);
- }
- else if( angle >= 225.0f && angle < 315.0f )
- {
- position.x = -halfSide * cosf(angleInRadians) / sinf(angleInRadians);
- position.y = halfSide;
- }
- else
- {
- position.x = halfSide;
- position.y = -halfSide * sinf(angleInRadians) / cosf(angleInRadians);
- }
- return position;
-}
-
-float HoldZeroFastEaseInOutHoldOne(float progress)
-{
- if( progress < 0.2f)
- {
- return 0.0f;
- }
- else if(progress < 0.5f)
- {
- return AlphaFunctions::EaseIn((progress-0.2) / 0.3f) * 0.5f;
- }
- else if(progress < 0.8f)
- {
- return AlphaFunctions::EaseOut((progress - 0.5f) / 0.3f) * 0.5f + 0.5f;
- }
- else
- {
- return 1.0f;
- }
-}
-
-struct SquareFanConstraint
-{
- SquareFanConstraint(int sideIndex)
- : mSideIndex(sideIndex)
- {
- }
-
- Vector3 operator()( const Vector3& current, const PropertyInput& start, const PropertyInput& rotation )
- {
- float degree = fmodf((start.GetFloat() + rotation.GetFloat()), 360.0f);
- if(degree < 0.0f)
- {
- degree += 360.0f;
- }
-
- float startAngle = (90.0f*mSideIndex)-45.0f;
- float endAngle = (90.0f*mSideIndex)+45.0f;
- if(degree < startAngle)
- {
- return Vector3::ZERO;
- }
- else if( degree >= endAngle )
- {
- degree = endAngle;
- }
- Vector3 pos = CircleSquareProjection(Degree(degree), 0.5f);
- pos.x = -pos.x; // Inverting X makes the animation go anti clockwise from left center
- return pos;
- }
-
- int mSideIndex;
-};
-
-} // anonymous namespace
-
-
-RadialSweepView RadialSweepViewImpl::New( )
-{
- return New( 2.0f, 100.0f, Degree(0.0f), Degree(0.0f), Degree(0.0f), Degree(359.999f) );
-}
-
-
-RadialSweepView RadialSweepViewImpl::New( float duration, float diameter, Degree initialAngle, Degree finalAngle, Degree initialSector, Degree finalSector )
-{
- RadialSweepViewImpl* impl= new RadialSweepViewImpl(duration, diameter, initialAngle, finalAngle, initialSector, finalSector);
- RadialSweepView handle = RadialSweepView(*impl);
- return handle;
-}
-
-RadialSweepViewImpl::RadialSweepViewImpl( float duration, float diameter, Degree initialAngle, Degree finalAngle, Degree initialSector, Degree finalSector )
-: Control( CONTROL_BEHAVIOUR_NONE ),
- mDuration(duration),
- mDiameter(diameter),
- mInitialAngle(initialAngle),
- mFinalAngle(finalAngle),
- mInitialSector(initialSector),
- mFinalSector(finalSector),
- mInitialActorAngle(0),
- mFinalActorAngle(0),
- mEasingFunction(HoldZeroFastEaseInOutHoldOne),
- mStartAngleIndex(Property::INVALID_INDEX),
- mRotationAngleIndex(Property::INVALID_INDEX),
- mRotateActorsWithStencil(false),
- mRotateActors(false)
-{
-}
-
-void RadialSweepViewImpl::SetDuration(float duration)
-{
- mDuration = duration;
-}
-
-void RadialSweepViewImpl::SetEasingFunction( Dali::AlphaFunction easingFunction )
-{
- mEasingFunction = easingFunction;
-}
-
-void RadialSweepViewImpl::SetDiameter(float diameter)
-{
- mDiameter = diameter;
-}
-
-void RadialSweepViewImpl::SetInitialAngle( Dali::Degree initialAngle)
-{
- mInitialAngle = initialAngle;
-}
-
-void RadialSweepViewImpl::SetFinalAngle( Dali::Degree finalAngle)
-{
- mFinalAngle = finalAngle;
-}
-
-void RadialSweepViewImpl::SetInitialSector( Dali::Degree initialSector)
-{
- mInitialSector = initialSector;
-}
-
-void RadialSweepViewImpl::SetFinalSector( Dali::Degree finalSector)
-{
- mFinalSector = finalSector;
-}
-
-void RadialSweepViewImpl::SetInitialActorAngle( Dali::Degree initialAngle )
-{
- mInitialActorAngle = initialAngle;
- mRotateActors = true;
-}
-
-void RadialSweepViewImpl::SetFinalActorAngle( Dali::Degree finalAngle )
-{
- mFinalActorAngle = finalAngle;
- mRotateActors = true;
-}
-
-float RadialSweepViewImpl::GetDuration( )
-{
- return mDuration;
-}
-
-float RadialSweepViewImpl::GetDiameter( )
-{
- return mDiameter;
-}
-
-Dali::Degree RadialSweepViewImpl::GetInitialAngle( )
-{
- return mInitialAngle;
-}
-
-Dali::Degree RadialSweepViewImpl::GetFinalAngle( )
-{
- return mFinalAngle;
-}
-
-Dali::Degree RadialSweepViewImpl::GetInitialSector( )
-{
- return mInitialSector;
-}
-
-Dali::Degree RadialSweepViewImpl::GetFinalSector( )
-{
- return mFinalSector;
-}
-
-Dali::Degree RadialSweepViewImpl::GetInitialActorAngle( )
-{
- return mInitialActorAngle;
-}
-
-Dali::Degree RadialSweepViewImpl::GetFinalActorAngle( )
-{
- return mFinalActorAngle;
-}
-
-void RadialSweepViewImpl::RotateActorsWithStencil(bool rotate)
-{
- mRotateActorsWithStencil = rotate;
-}
-
-void RadialSweepViewImpl::Add(Actor actor)
-{
- if( ! mLayer )
- {
- mLayer = Layer::New();
- Self().Add(mLayer);
- mLayer.SetSize( Stage::GetCurrent().GetSize() );
- mLayer.SetPositionInheritanceMode(USE_PARENT_POSITION);
- }
-
- mLayer.Add(actor);
-}
-
-void RadialSweepViewImpl::Activate( Animation anim, float offsetTime, float duration )
-{
- bool startAnimation=false;
- if( ! anim )
- {
- mAnim = Animation::New( mDuration );
- anim = mAnim;
- startAnimation = true;
- }
-
- if( ! mStencilActor )
- {
- CreateStencil( mInitialSector );
- mLayer.Add( mStencilActor );
- mStencilActor.SetSize(mDiameter, mDiameter);
- }
-
- mStencilActor.SetRotation( Degree(mInitialAngle), Vector3::ZAXIS );
- mStencilActor.SetProperty( mRotationAngleIndex, static_cast<float>(mInitialSector) );
-
- if( mRotateActors )
- {
- for(unsigned int i=0, count=mLayer.GetChildCount(); i<count; i++)
- {
- Actor actor = mLayer.GetChildAt(i);
- if( actor != mStencilActor )
- {
- anim.RotateTo( actor, mInitialActorAngle, Vector3::ZAXIS );
- }
- }
- }
-
- anim.AnimateTo( Property( mStencilActor, mRotationAngleIndex ), static_cast<float>(mFinalSector), mEasingFunction, TimePeriod( offsetTime, duration) );
- anim.RotateTo( mStencilActor, mFinalAngle, Vector3::ZAXIS, mEasingFunction, offsetTime, duration );
-
- if( mRotateActorsWithStencil )
- {
- for(unsigned int i=0, count=mLayer.GetChildCount(); i<count; i++)
- {
- Actor actor = mLayer.GetChildAt(i);
- if( actor != mStencilActor )
- {
- anim.RotateTo( actor, Degree(mFinalAngle - mInitialAngle), Vector3::ZAXIS, mEasingFunction, offsetTime, duration );
- }
- }
- }
- else if( mRotateActors )
- {
- for(unsigned int i=0, count=mLayer.GetChildCount(); i<count; i++)
- {
- Actor actor = mLayer.GetChildAt(i);
- if( actor != mStencilActor )
- {
- anim.RotateTo( actor, mFinalActorAngle, Vector3::ZAXIS, mEasingFunction, offsetTime, duration );
- }
- }
- }
-
-
- if( startAnimation )
- {
- anim.SetLooping(true);
- anim.Play();
- }
-}
-
-
-void RadialSweepViewImpl::Deactivate()
-{
- if( mAnim )
- {
- mAnim.Stop();
- }
- // mLayer.Remove( mStencilActor );
- // mStencilActor.Reset();
- // mMesh.Reset();
- // mMaterial.Reset();
-}
-
-void RadialSweepViewImpl::CreateStencil( Degree initialSector )
-{
- mMaterial = Material::New("Material");
- mMaterial.SetDiffuseColor(Color::WHITE);
- mMaterial.SetAmbientColor(Vector4(0.0, 0.1, 0.1, 1.0));
-
- // Generate a square mesh with a point at the center:
-
- AnimatableMesh::Faces faces;
- // Create triangles joining up the verts
- faces.push_back(0); faces.push_back(1); faces.push_back(2);
- faces.push_back(0); faces.push_back(2); faces.push_back(3);
- faces.push_back(0); faces.push_back(3); faces.push_back(4);
- faces.push_back(0); faces.push_back(4); faces.push_back(5);
- faces.push_back(0); faces.push_back(5); faces.push_back(6);
-
- mMesh = AnimatableMesh::New(7, faces, mMaterial);
- mMesh[0].SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) ); // Center pt
-
- mStencilActor = MeshActor::New(mMesh);
- mStencilActor.SetCullFace(CullNone); // Allow clockwise & anticlockwise faces
-
- mStartAngleIndex = mStencilActor.RegisterProperty("start-angle", Property::Value(0.0f));
- mRotationAngleIndex = mStencilActor.RegisterProperty("rotation-angle", Property::Value(initialSector));
-
- Source srcStart( mStencilActor, mStartAngleIndex );
- Source srcRot( mStencilActor, mRotationAngleIndex );
-
- // Constrain the vertices of the square mesh to sweep out a sector as the
- // rotation angle is animated.
- mMesh.ApplyConstraint(Constraint::New<Vector3>( mMesh.GetPropertyIndex(1, AnimatableVertex::Property::Position),
- srcStart, srcStart, SquareFanConstraint(0)));
- mMesh.ApplyConstraint(Constraint::New<Vector3>( mMesh.GetPropertyIndex(2, AnimatableVertex::Property::Position),
- srcStart, srcRot, SquareFanConstraint(0)));
- mMesh.ApplyConstraint(Constraint::New<Vector3>( mMesh.GetPropertyIndex(3, AnimatableVertex::Property::Position),
- srcStart, srcRot, SquareFanConstraint(1)));
- mMesh.ApplyConstraint(Constraint::New<Vector3>( mMesh.GetPropertyIndex(4, AnimatableVertex::Property::Position),
- srcStart, srcRot, SquareFanConstraint(2)));
- mMesh.ApplyConstraint(Constraint::New<Vector3>( mMesh.GetPropertyIndex(5, AnimatableVertex::Property::Position),
- srcStart, srcRot, SquareFanConstraint(3)));
- mMesh.ApplyConstraint(Constraint::New<Vector3>( mMesh.GetPropertyIndex(6, AnimatableVertex::Property::Position),
- srcStart, srcRot, SquareFanConstraint(4)));
-
- mStencilActor.SetDrawMode( DrawMode::STENCIL );
- mStencilActor.SetPositionInheritanceMode(USE_PARENT_POSITION);
-}
+++ /dev/null
-#ifndef DALI_DEMO_RADIAL_SWEEP_VIEW_IMPL_H
-#define DALI_DEMO_RADIAL_SWEEP_VIEW_IMPL_H
-
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali-toolkit/dali-toolkit.h>
-#include "radial-sweep-view.h"
-
-
-/********************************************************************************
- * Class to implement a layer with a radial sweep stencil mask and an actor tree
- */
-class RadialSweepViewImpl : public Dali::Toolkit::Internal::Control
-{
-public:
- static RadialSweepView New();
-
- static RadialSweepView New( float duration,
- float diameter,
- Dali::Degree initialAngle,
- Dali::Degree finalAngle,
- Dali::Degree initialSector,
- Dali::Degree finalSector );
-
- RadialSweepViewImpl( float duration,
- float diameter,
- Dali::Degree initialAngle,
- Dali::Degree finalAngle,
- Dali::Degree initialSector,
- Dali::Degree finalSector );
-
- void SetDuration(float duration);
- void SetEasingFunction( Dali::AlphaFunction easingFunction );
-
- void SetDiameter(float diameter);
- void SetInitialAngle( Dali::Degree initialAngle);
- void SetFinalAngle( Dali::Degree finalAngle);
- void SetInitialSector( Dali::Degree initialSector);
- void SetFinalSector( Dali::Degree finalSector);
- void SetInitialActorAngle( Dali::Degree initialAngle );
- void SetFinalActorAngle( Dali::Degree finalAngle );
-
- float GetDuration( );
- float GetDiameter( );
- Dali::Degree GetInitialAngle( );
- Dali::Degree GetFinalAngle( );
- Dali::Degree GetInitialSector( );
- Dali::Degree GetFinalSector( );
- Dali::Degree GetInitialActorAngle( );
- Dali::Degree GetFinalActorAngle( );
-
- void RotateActorsWithStencil(bool rotate);
-
- void Add( Dali::Actor actor );
-
- void Activate( Dali::Animation anim = Dali::Animation(), float offsetTime=0, float duration=2.0f );
-
- void Deactivate();
-
-private:
-
- /**
- * Create the stencil mask
- */
- void CreateStencil(Dali::Degree initialSector );
-
-private:
- Dali::Layer mLayer;
- Dali::Animation mAnim;
- float mDuration;
- float mDiameter;
- Dali::Degree mInitialAngle;
- Dali::Degree mFinalAngle;
- Dali::Degree mInitialSector;
- Dali::Degree mFinalSector;
- Dali::Degree mInitialActorAngle;
- Dali::Degree mFinalActorAngle;
- Dali::AlphaFunction mEasingFunction;
- Dali::MeshActor mStencilActor; ///< Stencil actor which generates mask
- Dali::Material mMaterial; ///< Material for drawing mesh actor
- Dali::AnimatableMesh mMesh; ///< Animatable mesh
- Dali::Property::Index mStartAngleIndex; ///< Index of start-angle property
- Dali::Property::Index mRotationAngleIndex; ///< Index of rotation-angle property
- bool mRotateActorsWithStencil:1;
- bool mRotateActors;
-};
-
-
-inline RadialSweepViewImpl& GetImpl( RadialSweepView& obj )
-{
- DALI_ASSERT_ALWAYS(obj);
- Dali::RefObject& handle = obj.GetImplementation();
- return static_cast<RadialSweepViewImpl&>(handle);
-}
-
-inline const RadialSweepViewImpl& GetImpl( const RadialSweepView& obj )
-{
- DALI_ASSERT_ALWAYS(obj);
- const Dali::RefObject& handle = obj.GetImplementation();
- return static_cast<const RadialSweepViewImpl&>(handle);
-}
-
-
-
-#endif // DALI_DEMO_RADIAL_SWEEP_VIEW_IMPL_H
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "radial-sweep-view.h"
-#include "radial-sweep-view-impl.h"
-
-using namespace Dali;
-
-RadialSweepView::RadialSweepView()
-{
-}
-
-RadialSweepView::RadialSweepView(const RadialSweepView& handle)
-: Control(handle)
-{
-}
-
-RadialSweepView& RadialSweepView::operator=(const RadialSweepView& rhs)
-{
- if( &rhs != this )
- {
- Control::operator=(rhs);
- }
- return *this;
-}
-
-RadialSweepView::~RadialSweepView()
-{
-}
-
-RadialSweepView RadialSweepView::DownCast( BaseHandle handle )
-{
- return Control::DownCast<RadialSweepView, RadialSweepViewImpl>(handle);
-}
-
-RadialSweepView RadialSweepView::New( )
-{
- return RadialSweepViewImpl::New();
-}
-
-RadialSweepView RadialSweepView::New( float duration,
- float diameter,
- Degree initialAngle,
- Degree finalAngle,
- Degree initialSector,
- Degree finalSector )
-{
- return RadialSweepViewImpl::New(duration, diameter, initialAngle, finalAngle, initialSector, finalSector );
-}
-
-RadialSweepView::RadialSweepView( RadialSweepViewImpl& impl )
-: Control( impl )
-{
-}
-
-RadialSweepView::RadialSweepView( Dali::Internal::CustomActor* impl )
-: Control( impl )
-{
- VerifyCustomActorPointer<RadialSweepViewImpl>(impl);
-}
-
-void RadialSweepView::SetDuration(float duration)
-{
- GetImpl(*this).SetDuration(duration);
-}
-
-void RadialSweepView::SetEasingFunction( Dali::AlphaFunction easingFunction )
-{
- GetImpl(*this).SetEasingFunction( easingFunction );
-}
-
-void RadialSweepView::SetDiameter(float diameter)
-{
- GetImpl(*this).SetDiameter(diameter);
-}
-
-void RadialSweepView::SetInitialAngle( Dali::Degree initialAngle)
-{
- GetImpl(*this).SetInitialAngle(initialAngle);
-}
-
-void RadialSweepView::SetFinalAngle( Dali::Degree finalAngle)
-{
- GetImpl(*this).SetFinalAngle(finalAngle);
-}
-
-void RadialSweepView::SetInitialSector( Dali::Degree initialSector)
-{
- GetImpl(*this).SetInitialSector(initialSector);
-}
-
-void RadialSweepView::SetFinalSector( Dali::Degree finalSector)
-{
- GetImpl(*this).SetFinalSector(finalSector);
-}
-
-void RadialSweepView::SetInitialActorAngle( Dali::Degree initialAngle )
-{
- GetImpl(*this).SetInitialActorAngle(initialAngle);
-}
-
-void RadialSweepView::SetFinalActorAngle( Dali::Degree finalAngle )
-{
- GetImpl(*this).SetFinalActorAngle(finalAngle);
-}
-
-float RadialSweepView::GetDuration( )
-{
- return GetImpl(*this).GetDuration();
-}
-
-float RadialSweepView::GetDiameter( )
-{
- return GetImpl(*this).GetDiameter();
-}
-
-Dali::Degree RadialSweepView::GetInitialAngle( )
-{
- return GetImpl(*this).GetInitialAngle();
-}
-
-Dali::Degree RadialSweepView::GetFinalAngle( )
-{
- return GetImpl(*this).GetFinalAngle();
-}
-
-Dali::Degree RadialSweepView::GetInitialSector( )
-{
- return GetImpl(*this).GetInitialSector();
-}
-
-Dali::Degree RadialSweepView::GetFinalSector( )
-{
- return GetImpl(*this).GetFinalSector();
-}
-
-Dali::Degree RadialSweepView::GetInitialActorAngle( )
-{
- return GetImpl(*this).GetInitialActorAngle();
-}
-
-Dali::Degree RadialSweepView::GetFinalActorAngle( )
-{
- return GetImpl(*this).GetFinalActorAngle();
-}
-
-void RadialSweepView::RotateActorsWithStencil(bool rotate)
-{
- GetImpl(*this).RotateActorsWithStencil(rotate);
-}
-
-void RadialSweepView::Add(Actor actor)
-{
- GetImpl(*this).Add(actor);
-}
-
-void RadialSweepView::Activate()
-{
- GetImpl(*this).Activate();
-}
-
-void RadialSweepView::Activate( Dali::Animation anim, float offsetTime, float duration )
-{
- GetImpl(*this).Activate(anim, offsetTime, duration);
-}
-
-void RadialSweepView::Deactivate()
-{
- GetImpl(*this).Deactivate();
-}
+++ /dev/null
-#ifndef DALI_DEMO_RADIAL_SWEEP_VIEW_H
-#define DALI_DEMO_RADIAL_SWEEP_VIEW_H
-
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali-toolkit/dali-toolkit.h>
-
-class RadialSweepViewImpl;
-
-
-/********************************************************************************
- * Handle to RadialSweepView implementation
- */
-class RadialSweepView : public Dali::Toolkit::Control
-{
-public:
- /**
- * Create a new RadialSweepView with default parameters (2 second animation,
- * no rotation, sweeping out a full cicle).
- */
- static RadialSweepView New( );
-
- /**
- * Create a new RadialSweepView.
- * @param[in] duration The duration of the sweep animation
- * @param[in] diameter The diameter of the stencil mask
- * @param[in] initialAngle The initial angle of the anticlockwise line of the sweep sector
- * @param[in] finalAngle The final angle of the anticlockwise line of the sweep sector
- * @param[in] initialSector The angle of the starting sector
- * @param[in] finalSector The angle of the sector at the end of the animation.
- * Note, to cover the entire circle, use a value of 359.9999f, not zero or 360.
- *
- * initial sector
- * \ | .
- * \ | .
- * initialAngle \ | . final sector
- * \| _|
- * .________
- */
- static RadialSweepView New( float duration,
- float diameter,
- Dali::Degree initialAngle,
- Dali::Degree finalAngle,
- Dali::Degree initialSector,
- Dali::Degree finalSector );
-
- void SetDuration(float duration);
-
- void SetEasingFunction( Dali::AlphaFunction easingFunction );
-
- void SetDiameter(float diameter);
-
- void SetInitialAngle( Dali::Degree initialAngle);
-
- void SetFinalAngle( Dali::Degree finalAngle);
-
- void SetInitialSector( Dali::Degree initialSector);
-
- void SetFinalSector( Dali::Degree finalSector);
-
- void SetInitialActorAngle( Dali::Degree initialAngle );
-
- void SetFinalActorAngle( Dali::Degree finalAngle );
-
- float GetDuration( );
-
- float GetDiameter( );
-
- Dali::Degree GetInitialAngle( );
-
- Dali::Degree GetFinalAngle( );
-
- Dali::Degree GetInitialSector( );
-
- Dali::Degree GetFinalSector( );
-
- Dali::Degree GetInitialActorAngle( );
-
- Dali::Degree GetFinalActorAngle( );
-
- /**
- * @param[in] rotate True if the actors should rotate with the stencil
- */
- void RotateActorsWithStencil(bool rotate);
-
- /**
- * Add actors to the view
- */
- void Add(Actor actor);
-
- /**
- * Activate the sweep animation
- */
- void Activate( );
-
- void Activate( Dali::Animation anim, float offsetTime, float duration );
-
- /**
- * Deactivate the sweep animation
- */
- void Deactivate();
-
- /**
- * Default constructor. Create an uninitialized handle.
- */
- RadialSweepView();
-
- /**
- * Copy constructor
- */
- RadialSweepView(const RadialSweepView& handle);
-
- /**
- * Assignment operator
- */
- RadialSweepView& operator=(const RadialSweepView& rhs);
-
- /**
- * Destructor
- */
- ~RadialSweepView();
-
- /**
- * Downcast method
- */
- static RadialSweepView DownCast( BaseHandle handle );
-
-public: // Not for use by application developers
-
- RadialSweepView( RadialSweepViewImpl& impl );
-
- RadialSweepView( Dali::Internal::CustomActor* impl );
-};
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/dali.h>
-#include <dali-toolkit/dali-toolkit.h>
-#include "shared/view.h"
-
-#include <fstream>
-#include <sstream>
-
-using namespace Dali;
-
-namespace
-{
-const char * const APPLICATION_TITLE( "Refraction Effect" );
-const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
-const char * const CHANGE_TEXTURE_ICON( DALI_IMAGE_DIR "icon-change.png" );
-const char * const CHANGE_MESH_ICON( DALI_IMAGE_DIR "icon-replace.png" );
-
-const char* MESH_FILES[] =
-{
- DALI_MODEL_DIR "surface_pattern_v01.obj",
- DALI_MODEL_DIR "surface_pattern_v02.obj"
-};
-const unsigned int NUM_MESH_FILES( sizeof( MESH_FILES ) / sizeof( MESH_FILES[0] ) );
-
-const char* TEXTURE_IMAGES[]=
-{
- DALI_IMAGE_DIR "background-1.jpg",
- DALI_IMAGE_DIR "background-2.jpg",
- DALI_IMAGE_DIR "background-3.jpg",
- DALI_IMAGE_DIR "background-4.jpg"
-};
-const unsigned int NUM_TEXTURE_IMAGES( sizeof( TEXTURE_IMAGES ) / sizeof( TEXTURE_IMAGES[0] ) );
-
-#define MAKE_SHADER(A)#A
-
-struct LightOffsetConstraint
-{
- LightOffsetConstraint( float radius )
- : mRadius( radius )
- {
- }
-
- Vector2 operator()( const Vector2& current, const PropertyInput& spinAngleProperty)
- {
- float spinAngle = spinAngleProperty.GetFloat();
- return Vector2( cos(spinAngle ), sin( spinAngle ) ) * mRadius;
- }
-
- float mRadius;
-};
-
-} // namespace
-
-/************************************************************************************************
- *** This shader is used when the MeshActor is not touched***
- ************************************************************************************************/
-class NoEffect : public ShaderEffect
-{
-public:
- /**
- * Create an empty handle.
- */
- NoEffect()
- {
- }
-
- /**
- * Virtual destructor
- */
- virtual ~NoEffect()
- {
- }
-
- /**
- * Create a NoEffect object.
- * @return A handle to a newly allocated NoEffect
- */
- static NoEffect New()
- {
- std::string vertexShader = MAKE_SHADER(
- precision mediump float;\n
- uniform mediump vec4 uTextureRect;\n
- void main()\n
- {\n
- gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 );\n
- vTexCoord = aTexCoord.xy;\n
- }\n
- );
- std::string fragmentShader = MAKE_SHADER(
- precision mediump float;\n
- void main()\n
- {\n
- gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
- }\n
- );
- ShaderEffect shaderEffect = ShaderEffect::New( vertexShader, fragmentShader,
- GeometryType( GEOMETRY_TYPE_TEXTURED_MESH),
- ShaderEffect::GeometryHints( ShaderEffect::HINT_NONE ) );
- NoEffect handle( shaderEffect );
- return handle;
- }
-
-private:
- /**
- * Helper for New()
- */
- NoEffect( ShaderEffect handle )
- : ShaderEffect( handle )
- {
- }
-};
-
-/************************************************************/
-/* Custom refraction effect shader******************************/
-/************************************************************/
-
-class RefractionEffect : public ShaderEffect
-{
-public:
-
- /**
- * Create an empty RefractionEffect handle.
- */
- RefractionEffect()
- {
- }
-
- /**
- * Virtual destructor
- */
- virtual ~RefractionEffect()
- {
- }
-
- /**
- * Create a RefractionEffect object.
- * @return A handle to a newly allocated RefractionEffect
- */
- static RefractionEffect New()
- {
- std::string vertexShader = MAKE_SHADER(
- precision mediump float;\n
- varying mediump vec2 vTextureOffset;\n
- void main()\n
- {\n
- gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 );\n
- vTexCoord = aTexCoord.xy;\n
-
- vNormal = aNormal;\n
- vVertex = vec4( aPosition, 1.0 );\n
- float length = max(0.01, length(aNormal.xy)) * 40.0;\n
- vTextureOffset = aNormal.xy / length;\n
- }\n
- );
-
- std::string fragmentShader = MAKE_SHADER(
- precision mediump float;\n
- uniform mediump float uEffectStrength;\n
- uniform mediump vec3 uLightPosition;\n
- uniform mediump vec2 uLightXYOffset;\n
- uniform mediump vec2 uLightSpinOffset;\n
- uniform mediump float uLightIntensity;\n
- varying mediump vec2 vTextureOffset;\n
-
- vec3 rgb2hsl(vec3 rgb)\n
- {\n
- float epsilon = 1.0e-10;\n
- vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n
- vec4 P = mix(vec4(rgb.bg, K.wz), vec4(rgb.gb, K.xy), step(rgb.b, rgb.g));\n
- vec4 Q = mix(vec4(P.xyw, rgb.r), vec4(rgb.r, P.yzx), step(P.x, rgb.r));\n
- \n
- // RGB -> HCV
- float value = Q.x;\n
- float chroma = Q.x - min(Q.w, Q.y);\n
- float hue = abs(Q.z + (Q.w-Q.y) / (6.0*chroma+epsilon));\n
- // HCV -> HSL
- float lightness = value - chroma*0.5;\n
- return vec3( hue, chroma/max( 1.0-abs(lightness*2.0-1.0), 1.0e-1 ), lightness );\n
- }\n
-
- vec3 hsl2rgb( vec3 hsl )
- {
- // pure hue->RGB
- vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n
- vec3 p = abs(fract(hsl.xxx + K.xyz) * 6.0 - K.www);\n
- vec3 RGB = clamp(p - K.xxx, 0.0, 1.0);\n
- \n
- float chroma = ( 1.0 - abs( hsl.z*2.0-1.0 ) ) * hsl.y;\n
- return ( RGB - 0.5 ) * chroma + hsl.z;
- }
-
- void main()\n
- {\n
- vec3 normal = normalize( vNormal);\n
-
- vec3 lightPosition = uLightPosition + vec3(uLightXYOffset+uLightSpinOffset, 0.0);\n
- mediump vec3 vecToLight = normalize( (lightPosition - vVertex.xyz) * 0.01 );\n
- mediump float spotEffect = pow( max(0.05, vecToLight.z ) - 0.05, 8.0);\n
-
- spotEffect = spotEffect * uEffectStrength;\n
- mediump float lightDiffuse = ( ( dot( vecToLight, normal )-0.75 ) *uLightIntensity ) * spotEffect;\n
-
- lowp vec4 color = texture2D( sTexture, vTexCoord + vTextureOffset * spotEffect );\n
- vec3 lightedColor = hsl2rgb( rgb2hsl(color.rgb) + vec3(0.0,0.0,lightDiffuse) );\n
-
- gl_FragColor = vec4( lightedColor, color.a ) * uColor;\n
- }\n
- );
-
- ShaderEffect shaderEffect = ShaderEffect::New( vertexShader, fragmentShader,
- GeometryType( GEOMETRY_TYPE_TEXTURED_MESH),
- ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ) );
- RefractionEffect handle( shaderEffect );
-
- Vector2 stageSize = Stage::GetCurrent().GetSize();
- handle.SetLightPosition( Vector2(stageSize.x, 0.f) );
- handle.SetUniform( "uLightXYOffset", Vector2::ZERO );
- handle.SetUniform( "uLightSpinOffset", Vector2::ZERO );
- handle.SetUniform( "uEffectStrength", 0.f );
- handle.SetUniform( "uLightIntensity", 2.5f );
-
- Dali::Property::Index index = handle.RegisterProperty( "uSpinAngle", 0.f );
- Constraint constraint = Constraint::New<Vector2>( handle.GetPropertyIndex("uLightSpinOffset"),
- LocalSource(index),
- LightOffsetConstraint(stageSize.x*0.1f));
- handle.ApplyConstraint( constraint );
-
- return handle;
- }
-
- void SetLightPosition( const Vector2& position )
- {
- Vector2 stageHalfSize = Stage::GetCurrent().GetSize() * 0.5f;
- SetUniform( "uLightPosition", Vector3( position.x - stageHalfSize.x, position.y - stageHalfSize.y, stageHalfSize.x ) );
- }
-
- void SetLightXYOffset( const Vector2& offset )
- {
- SetUniform( "uLightXYOffset", offset );
- }
-
- void SetEffectStrength( float strength )
- {
- SetUniform( "uEffectStrength", strength );
- }
-
- void SetLightIntensity( float intensity )
- {
- SetUniform( "uLightIntensity", intensity );
- }
-
-private:
- /**
- * Helper for New()
- */
- RefractionEffect( ShaderEffect handle )
- : ShaderEffect( handle )
- {
- }
-};
-
-/*************************************************/
-/*Demo using RefractionEffect*****************/
-/*************************************************/
-class RefractionEffectExample : public ConnectionTracker
-{
-public:
- RefractionEffectExample( Application &application )
- : mApplication( application ),
- mIsDown( false ),
- mCurrentTextureId( 1 ),
- mCurrentMeshId( 0 )
- {
- // Connect to the Application's Init signal
- application.InitSignal().Connect(this, &RefractionEffectExample::Create);
- }
-
- ~RefractionEffectExample()
- {
- }
-
-private:
-
- // The Init signal is received once (only) during the Application lifetime
- void Create(Application& application)
- {
- Stage stage = Stage::GetCurrent();
- mStageHalfSize = stage.GetSize() * 0.5f;
-
- stage.KeyEventSignal().Connect(this, &RefractionEffectExample::OnKeyEvent);
-
- // Creates a default view with a default tool bar.
- // The view is added to the stage.
- Toolkit::ToolBar toolBar;
- Toolkit::View view;
- mContent = DemoHelper::CreateView( application,
- view,
- toolBar,
- "",
- TOOLBAR_IMAGE,
- APPLICATION_TITLE );
-
- // Add a button to change background. (right of toolbar)
- mChangeTextureButton = Toolkit::PushButton::New();
- mChangeTextureButton.SetBackgroundImage( ResourceImage::New( CHANGE_TEXTURE_ICON ) );
- mChangeTextureButton.ClickedSignal().Connect( this, &RefractionEffectExample::OnChangeTexture );
- toolBar.AddControl( mChangeTextureButton,
- DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
- Toolkit::Alignment::HorizontalRight,
- DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
- // Add a button to change mesh pattern. ( left of bar )
- mChangeMeshButton = Toolkit::PushButton::New();
- mChangeMeshButton.SetBackgroundImage( ResourceImage::New( CHANGE_MESH_ICON ) );
- mChangeMeshButton.ClickedSignal().Connect( this, &RefractionEffectExample::OnChangeMesh );
- toolBar.AddControl( mChangeMeshButton,
- DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
- Toolkit::Alignment::HorizontalLeft,
- DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
-
- // creates the shader effects applied on the mesh actor
- mRefractionEffect = RefractionEffect::New(); // used when the finger is touching the screen
- mNoEffect = NoEffect::New(); // used in the other situations, basic render shader
- // Create the mesh from the obj file and add to stage
- mMaterial = Material::New( "Material" ) ;
- mMaterial.SetDiffuseTexture(ResourceImage::New(TEXTURE_IMAGES[mCurrentTextureId]));
- CreateSurface( MESH_FILES[mCurrentMeshId] );
-
- // Connect the callback to the touch signal on the mesh actor
- mContent.TouchedSignal().Connect( this, &RefractionEffectExample::OnTouch );
-
- // the animation which spin the light around the finger touch position
- mLightPosition = Vector2( mStageHalfSize.x*2.f, 0.f);
- mLightAnimation = Animation::New(2.f);
- mLightAnimation.AnimateTo( Property( mRefractionEffect, "uSpinAngle" ), Math::PI*2.f );
- mLightAnimation.SetLooping( true );
- mLightAnimation.Pause();
- }
-
- /**
- * Create a mesh actor with different geometry to replace the current one
- */
- bool OnChangeMesh( Toolkit::Button button )
- {
- if( mMeshActor )
- {
- UnparentAndReset( mMeshActor );
- }
-
- mCurrentMeshId = ( mCurrentMeshId + 1 ) % NUM_MESH_FILES;
- CreateSurface( MESH_FILES[mCurrentMeshId] );
-
- return true;
- }
-
- bool OnChangeTexture( Toolkit::Button button )
- {
- mCurrentTextureId = ( mCurrentTextureId + 1 ) % NUM_TEXTURE_IMAGES;
- mMaterial.SetDiffuseTexture(ResourceImage::New(TEXTURE_IMAGES[mCurrentTextureId]));
-
- return true;
- }
-
- bool OnTouch( Actor actor , const TouchEvent& event )
- {
- const TouchPoint &point = event.GetPoint(0);
-
- switch(point.state)
- {
- case TouchPoint::Down:
- {
- mIsDown = true;
- mDownPosition = point.screen;
-
- mLightAnimation.Play();
-
- if( mStrenghAnimation )
- {
- mStrenghAnimation.Clear();
- }
-
- mRefractionEffect.SetLightXYOffset( point.screen - mLightPosition );
- mMeshActor.SetShaderEffect( mRefractionEffect );
- mStrenghAnimation= Animation::New(0.5f);
- mStrenghAnimation.AnimateTo( Property( mRefractionEffect, "uEffectStrength" ), 1.f );
- mStrenghAnimation.Play();
-
- break;
- }
- case TouchPoint::Motion:
- {
- if(mIsDown)
- {
- // make the light position following the finger movement
- mRefractionEffect.SetLightXYOffset( point.screen - mLightPosition );
- }
- break;
- }
- case TouchPoint::Up:
- case TouchPoint::Leave:
- case TouchPoint::Interrupted:
- {
- if(mIsDown)
- {
- mLightAnimation.Pause();
-
- if( mStrenghAnimation )
- {
- mStrenghAnimation.Clear();
- }
- mStrenghAnimation = Animation::New(0.5f);
- mStrenghAnimation.AnimateTo( Property( mRefractionEffect, "uEffectStrength" ), 0.f );
- mStrenghAnimation.FinishedSignal().Connect( this, &RefractionEffectExample::OnTouchFinished );
- mStrenghAnimation.Play();
- }
-
- mIsDown = false;
- break;
- }
- case TouchPoint::Stationary:
- case TouchPoint::Last:
- default:
- {
- break;
- }
- }
- return true;
- }
-
- void OnTouchFinished( Animation& source )
- {
- mMeshActor.SetShaderEffect( mNoEffect );
- mRefractionEffect.SetLightXYOffset( Vector2::ZERO );
- }
-
- void CreateSurface( const std::string& objFileName )
- {
- MeshData::VertexContainer vertices;
- MeshData::FaceIndices faces;
- MeshData meshData;
-
- std::vector<float> boundingBox;
- std::vector<Vector3> vertexPositions;
- std::vector<int> faceIndices;
- // read the vertice and faces from the .obj file, and record the bounding box
- ReadObjFile( objFileName, boundingBox, vertexPositions, faceIndices );
-
- std::vector<Vector2> textureCoordinates;
- // align the mesh, scale it to fit the screen size, and calculate the texture coordinate for each vertex
- ShapeResizeAndTexureCoordinateCalculation( boundingBox, vertexPositions, textureCoordinates );
-
- // re-organize the mesh, the vertices are duplicated, each vertex only belongs to one triangle.
- // Without sharing vertex between triangle, so we can manipulate the texture offset on each triangle conveniently.
- for( std::size_t i=0; i<faceIndices.size(); i=i+3 )
- {
- Vector3 edge1 = vertexPositions[ faceIndices[i+2] ] - vertexPositions[ faceIndices[i] ];
- Vector3 edge2 = vertexPositions[ faceIndices[i+1] ] - vertexPositions[ faceIndices[i] ];
- Vector3 normal = edge1.Cross(edge2);
- normal.Normalize();
-
- if( normal.z > 0 )
- {
- faces.push_back( i );
- faces.push_back( i+1 );
- faces.push_back( i+2 );
- }
- else
- {
- normal *= -1.f;
- faces.push_back( i );
- faces.push_back( i+2 );
- faces.push_back( i+1 );
- }
-
- vertices.push_back( MeshData::Vertex( vertexPositions[ faceIndices[i] ], textureCoordinates[ faceIndices[i] ], normal ) );
- vertices.push_back( MeshData::Vertex( vertexPositions[ faceIndices[i+1] ], textureCoordinates[ faceIndices[i+1] ], normal ) );
- vertices.push_back( MeshData::Vertex( vertexPositions[ faceIndices[i+2] ], textureCoordinates[ faceIndices[i+2] ], normal ) );
-
- }
-
- // Now ready to construct the mesh actor
- meshData.SetMaterial( mMaterial );
- meshData.SetVertices( vertices );
- meshData.SetFaceIndices( faces );
- meshData.SetHasTextureCoords(true);
- meshData.SetHasNormals(true);
- mMeshActor = MeshActor::New( Mesh::New( meshData ) );
- mMeshActor.SetParentOrigin(ParentOrigin::CENTER);
- mMeshActor.SetShaderEffect( mNoEffect );
- mContent.Add( mMeshActor );
- }
-
- void ReadObjFile( const std::string& objFileName,
- std::vector<float>& boundingBox,
- std::vector<Vector3>& vertexPositions,
- std::vector<int>& faceIndices)
- {
- std::ifstream ifs( objFileName.c_str(), std::ios::in );
-
- boundingBox.resize( 6 );
- boundingBox[0]=boundingBox[2]=boundingBox[4] = std::numeric_limits<float>::max();
- boundingBox[1]=boundingBox[3]=boundingBox[5] = -std::numeric_limits<float>::max();
-
- std::string line;
- while( std::getline( ifs, line ) )
- {
- if( line[0] == 'v' && std::isspace(line[1])) // vertex
- {
- std::istringstream iss(line.substr(2), std::istringstream::in);
- unsigned int i = 0;
- Vector3 vertex;
- while( iss >> vertex[i++] && i < 3);
- if( vertex.x < boundingBox[0] ) boundingBox[0] = vertex.x;
- if( vertex.x > boundingBox[1] ) boundingBox[1] = vertex.x;
- if( vertex.y < boundingBox[2] ) boundingBox[2] = vertex.y;
- if( vertex.y > boundingBox[3] ) boundingBox[3] = vertex.y;
- if( vertex.z < boundingBox[4] ) boundingBox[4] = vertex.z;
- if( vertex.z > boundingBox[5] ) boundingBox[5] = vertex.z;
- vertexPositions.push_back( vertex );
- }
- else if( line[0] == 'f' ) //face
- {
- unsigned int numOfInt = 3;
- while( true )
- {
- std::size_t found = line.find('/');
- if( found == std::string::npos )
- {
- break;
- }
- line[found] = ' ';
- numOfInt++;
- }
-
- std::istringstream iss(line.substr(2), std::istringstream::in);
- int indices[ numOfInt ];
- unsigned int i=0;
- while( iss >> indices[i++] && i < numOfInt);
- unsigned int step = (i+1) / 3;
- faceIndices.push_back( indices[0]-1 );
- faceIndices.push_back( indices[step]-1 );
- faceIndices.push_back( indices[2*step]-1 );
- }
- }
-
- ifs.close();
- }
-
- void ShapeResizeAndTexureCoordinateCalculation( const std::vector<float>& boundingBox,
- std::vector<Vector3>& vertexPositions,
- std::vector<Vector2>& textureCoordinates)
- {
- Vector3 bBoxSize( boundingBox[1] - boundingBox[0], boundingBox[3] - boundingBox[2], boundingBox[5] - boundingBox[4]);
- Vector3 bBoxMinCorner( boundingBox[0], boundingBox[2], boundingBox[4] );
-
- Vector2 stageSize = Stage::GetCurrent().GetSize();
- Vector3 scale( stageSize.x / bBoxSize.x, stageSize.y / bBoxSize.y, 1.f );
- scale.z = (scale.x + scale.y)/2.f;
-
- for( std::vector<Vector3>::iterator iter = vertexPositions.begin(); iter != vertexPositions.end(); iter++ )
- {
- Vector3 newPosition( (*iter) - bBoxMinCorner ) ;
-
- Vector2 textureCoord( newPosition.x / bBoxSize.x, newPosition.y / bBoxSize.y );
- textureCoordinates.push_back( textureCoord );
-
- newPosition -= bBoxSize * 0.5f;
- (*iter) = newPosition * scale;
- }
- }
-
- /**
- * Main key event handler
- */
- void OnKeyEvent(const KeyEvent& event)
- {
- if(event.state == KeyEvent::Down)
- {
- if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
- {
- mApplication.Quit();
- }
- }
- }
-
-private:
-
- Application& mApplication;
- Layer mContent;
-
- bool mIsDown;
- Vector2 mDownPosition;
- Vector2 mLightPosition;
- Vector2 mStageHalfSize;
-
- Material mMaterial;
- MeshActor mMeshActor;
-
- RefractionEffect mRefractionEffect;
- NoEffect mNoEffect;
- Animation mLightAnimation;
- Animation mStrenghAnimation;
-
- Toolkit::PushButton mChangeTextureButton;
- Toolkit::PushButton mChangeMeshButton;
- unsigned int mCurrentTextureId;
- unsigned int mCurrentMeshId;
-};
-
-/*****************************************************************************/
-
-static void
-RunTest(Application& app)
-{
- RefractionEffectExample theApp(app);
- app.MainLoop();
-}
-
-/*****************************************************************************/
-
-int
-main(int argc, char **argv)
-{
- Application app = Application::New(&argc, &argv);
-
- RunTest(app);
-
- return 0;
-}