diff --git a/demo/dali-demo.cpp b/demo/dali-demo.cpp index c2320eb..ce22a9a 100644 --- a/demo/dali-demo.cpp +++ b/demo/dali-demo.cpp @@ -57,11 +57,13 @@ int main(int argc, char **argv) demo.AddExample(Example("text-label.example", DALI_DEMO_STR_TITLE_TEXT_LABEL)); demo.AddExample(Example("text-label-multi-language.example", DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE)); demo.AddExample(Example("text-label-emojis.example", DALI_DEMO_STR_TITLE_EMOJI_TEXT)); - demo.AddExample(Example("animated-shapes.example", DALI_DEMO_STR_TITLE_ANIMATED_SHAPES)); - demo.AddExample(Example("path-animation.example", DALI_DEMO_STR_TITLE_PATH_ANIMATION)); demo.AddExample(Example("size-negotiation.example", DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE)); demo.AddExample(Example("buttons.example", DALI_DEMO_STR_TITLE_BUTTONS)); demo.AddExample(Example("logging.example", DALI_DEMO_STR_TITLE_LOGGING)); + demo.AddExample(Example("mesh-morph.example", DALI_DEMO_STR_TITLE_MESH_MORPH)); + demo.AddExample(Example("mesh-sorting.example", DALI_DEMO_STR_TITLE_MESH_SORTING)); + demo.AddExample(Example("textured-mesh.example", DALI_DEMO_STR_TITLE_TEXTURED_MESH)); + demo.AddExample(Example("line-mesh.example", DALI_DEMO_STR_TITLE_LINE_MESH)); demo.SortAlphabetically( true ); diff --git a/demo/dali-table-view.cpp b/demo/dali-table-view.cpp index 0ddd2bd..24cdac8 100644 --- a/demo/dali-table-view.cpp +++ b/demo/dali-table-view.cpp @@ -268,9 +268,11 @@ void DaliTableView::Initialize( Application& application ) mScrollView.TouchedSignal().Connect( this, &DaliTableView::OnScrollTouched ); mScrollViewLayer = Layer::New(); + + // Disable the depth test for performance + mScrollViewLayer.SetDepthTestDisabled( true ); mScrollViewLayer.SetAnchorPoint( AnchorPoint::CENTER ); mScrollViewLayer.SetParentOrigin( ParentOrigin::CENTER ); - mScrollViewLayer.SetDrawMode( DrawMode::OVERLAY ); mScrollViewLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); // Create solid background colour. @@ -279,7 +281,9 @@ void DaliTableView::Initialize( Application& application ) backgroundColourActor.SetParentOrigin( ParentOrigin::CENTER ); backgroundColourActor.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); backgroundColourActor.SetSizeModeFactor( Vector3( 1.0f, 1.5f, 1.0f ) ); - backgroundColourActor.SetZ( BACKGROUND_Z ); + + // Force the filled background right to the back + backgroundColourActor.SetSortModifier( DemoHelper::BACKGROUND_DEPTH_INDEX ); mScrollViewLayer.Add( backgroundColourActor ); // Populate background and bubbles - needs to be scrollViewLayer so scroll ends show @@ -526,7 +530,7 @@ ImageActor DaliTableView::NewStencilImage() stencilActor.SetAnchorPoint( AnchorPoint::CENTER ); stencilActor.SetDrawMode( DrawMode::STENCIL ); - Dali::ShaderEffect shaderEffect = AlphaDiscardEffect::New(); + Dali::ShaderEffect shaderEffect = CreateAlphaDiscardEffect(); stencilActor.SetShaderEffect( shaderEffect ); return stencilActor; @@ -764,11 +768,14 @@ void DaliTableView::AddBackgroundActors( Actor layer, int count, BufferImage dis dfActor.SetSize( Vector2( randSize, randSize ) ); dfActor.SetParentOrigin( ParentOrigin::CENTER ); - Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New(); + // Force the bubbles just in front of the solid background + dfActor.SetSortModifier( DemoHelper::BACKGROUND_DEPTH_INDEX + 1 ); + + ShaderEffect effect = Toolkit::CreateDistanceFieldEffect(); dfActor.SetShaderEffect( effect ); dfActor.SetColor( randColour ); - effect.SetOutlineParams( Vector2( 0.55f, 0.00f ) ); - effect.SetSmoothingEdge( 0.5f ); + effect.SetUniform("uOutlineParams", Vector2( 0.55f, 0.00f ) ); + effect.SetUniform("uSmoothing", 0.5f ); layer.Add( dfActor ); } diff --git a/examples/animated-shapes/animated-shapes-example.cpp b/examples/animated-shapes/animated-shapes-example.cpp deleted file mode 100644 index 11de583..0000000 --- a/examples/animated-shapes/animated-shapes-example.cpp +++ /dev/null @@ -1,382 +0,0 @@ -/* - * 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 -#include -#include -#include -#include - -#include "shared/view.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::Control::New(); - mView.SetAnchorPoint( Dali::AnchorPoint::CENTER ); - mView.SetParentOrigin( Dali::ParentOrigin::CENTER ); - mView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mView.SetDrawMode( DrawMode::OVERLAY ); - stage.Add( mView ); - - //Set background image for the view - mView.SetBackgroundImage( ResourceImage::New( BACKGROUND_IMAGE ) ); - - 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,AlphaFunction::EASE_IN_OUT ); - - 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,AlphaFunction::EASE_IN_OUT ); - - 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,AlphaFunction::EASE_IN_OUT ); - - 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,AlphaFunction::EASE_IN_OUT ); - - animation.AnimateBy( Property( meshActor, Actor::Property::ORIENTATION ), Quaternion( Radian( 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,AlphaFunction::EASE_IN_OUT ); - - 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,AlphaFunction::EASE_IN_OUT ); - - 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,AlphaFunction::EASE_IN_OUT ); - 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,AlphaFunction::EASE_IN_OUT ); - - 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,AlphaFunction::EASE_IN_OUT ); - - 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,AlphaFunction::EASE_IN_OUT ); - - 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,AlphaFunction::EASE_IN_OUT ); - - animation.AnimateBy( Property( meshActor, Actor::Property::ORIENTATION ), Quaternion( Radian( 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::Control mView; -}; - -void RunTest( Application& application ) -{ - AnimatedShapesExample test( application ); - application.MainLoop(); -} - -int main( int argc, char **argv ) -{ - Application application = Application::New( &argc, &argv, DALI_DEMO_THEME_PATH ); - RunTest( application ); - - return 0; -} diff --git a/examples/bubble-effect/bubble-effect-example.cpp b/examples/bubble-effect/bubble-effect-example.cpp index 5e4e304..0ac4d76 100644 --- a/examples/bubble-effect/bubble-effect-example.cpp +++ b/examples/bubble-effect/bubble-effect-example.cpp @@ -42,9 +42,9 @@ const unsigned int NUM_BACKGROUND_IMAGES( sizeof( BACKGROUND_IMAGES ) / sizeof( const char* BUBBLE_SHAPE_IMAGES[] = { DALI_IMAGE_DIR "bubble-ball.png", + DALI_IMAGE_DIR "icon-effect-cross.png", DALI_IMAGE_DIR "icon-item-view-layout-spiral.png", - DALI_IMAGE_DIR "icon-replace.png", - DALI_IMAGE_DIR "icon-effect-cross.png" + DALI_IMAGE_DIR "icon-replace.png" }; const unsigned int NUM_BUBBLE_SHAPE_IMAGES( sizeof( BUBBLE_SHAPE_IMAGES ) / sizeof( BUBBLE_SHAPE_IMAGES[0] ) ); @@ -74,10 +74,10 @@ public: BubbleEffectExample(Application &app) : mApp(app), mHSVDelta( Vector3( 0.f, 0.f, 0.5f ) ), - mNeedNewAnimation( true ), mTimerInterval( 16 ), mCurrentBackgroundImageId( 0 ), - mCurrentBubbleShapeImageId( 0 ) + mCurrentBubbleShapeImageId( 0 ), + mNeedNewAnimation( true ) { // Connect to the Application's Init signal app.InitSignal().Connect(this, &BubbleEffectExample::Create); @@ -154,7 +154,7 @@ private: * Emit bubbles *****************/ - // Set up the animation of emitting bubbles, to be efficient, every animation controls multiple bubbles ( 4 here ) + // Set up the animation of emitting bubbles, to be efficient, every animation controls multiple emission ( 4 here ) void SetUpAnimation( Vector2 emitPosition, Vector2 direction ) { if( mNeedNewAnimation ) @@ -232,6 +232,9 @@ private: case TouchPoint::Interrupted: { mTimerForBubbleEmission.Stop(); + mEmitAnimation.Play(); + mNeedNewAnimation = true; + mAnimateComponentCount = 0; break; } case TouchPoint::Stationary: @@ -283,23 +286,22 @@ private: Dali::Toolkit::Control mBackground; Toolkit::BubbleEmitter mBubbleEmitter; - Vector3 mHSVDelta; - Animation mEmitAnimation; - unsigned int mAnimateComponentCount; - bool mNeedNewAnimation; - + Toolkit::PushButton mChangeBackgroundButton; + Toolkit::PushButton mChangeBubbleShapeButton; Timer mTimerForBubbleEmission; - unsigned int mNonMovementCount; - unsigned int mTimerInterval; + Vector3 mHSVDelta; Vector2 mCurrentTouchPosition; Vector2 mEmitPosition; - Toolkit::PushButton mChangeBackgroundButton; - Toolkit::PushButton mChangeBubbleShapeButton; + unsigned int mAnimateComponentCount; + unsigned int mNonMovementCount; + unsigned int mTimerInterval; unsigned int mCurrentBackgroundImageId; unsigned int mCurrentBubbleShapeImageId; + + bool mNeedNewAnimation; }; /*****************************************************************************/ diff --git a/examples/cluster/cluster-example.cpp b/examples/cluster/cluster-example.cpp index f9df49d..2642a2c 100644 --- a/examples/cluster/cluster-example.cpp +++ b/examples/cluster/cluster-example.cpp @@ -376,6 +376,8 @@ public: TOOLBAR_IMAGE, "" ); + mContentLayer.SetProperty(Layer::Property::BEHAVIOR, "Dali::Layer::LAYER_3D"); + // Create a effect toggle button. (right of toolbar) mLayoutButtonImages[ NO_EFFECT ] = ResourceImage::New( LAYOUT_NONE_IMAGE ); mLayoutButtonImages[ MOTION_BLUR_EFFECT ] = ResourceImage::New( LAYOUT_MOTION_BLUR_IMAGE ); @@ -552,21 +554,22 @@ public: */ void SetMotionBlurEffect( Actor actor ) { + // only do something if the actor and effect are valid if( actor ) { // first remove from this actor - RenderableActor renderable = RenderableActor::DownCast( actor ); - if( renderable ) + ImageActor imageActor = ImageActor::DownCast( actor ); + if( imageActor ) { - MotionBlurEffect shaderEffect = MotionBlurEffect::New(); - shaderEffect.SetSpeedScalingFactor(0.1f); + ShaderEffect shaderEffect = Toolkit::CreateMotionBlurEffect(); + shaderEffect.SetUniform("uSpeedScalingFactor",0.1f); Dali::Property::Index uModelProperty = shaderEffect.GetPropertyIndex( "uModelLastFrame" ); Constraint constraint = Constraint::New( shaderEffect, uModelProperty, EqualToConstraint() ); - constraint.AddSource( Source( actor , Actor::Property::WORLD_MATRIX ) ); + constraint.AddSource( Source( imageActor , Actor::Property::WORLD_MATRIX ) ); constraint.Apply(); - renderable.SetShaderEffect( shaderEffect ); + imageActor.SetShaderEffect( shaderEffect ); } // then all children recursively const unsigned int count = actor.GetChildCount(); @@ -650,8 +653,8 @@ public: case CAROUSEL_EFFECT: { // Apply Carousel Shader Effect to scrollView - CarouselEffect shaderEffect = CarouselEffect::New(); - shaderEffect.SetRadius( -CAROUSEL_EFFECT_RADIUS ); + ShaderEffect shaderEffect = Toolkit::CreateCarouselEffect(); + shaderEffect.SetUniform( "uRadius", -CAROUSEL_EFFECT_RADIUS ); // dont apply shader effect to scrollview as it might override internal shaders for bounce effect etc for( std::vector::iterator i = mClusterInfo.begin(); i != mClusterInfo.end(); ++i ) { @@ -663,7 +666,7 @@ public: const Vector2 angleSweep( CAROUSEL_EFFECT_ANGLE_SWEEP / stageSize.width, CAROUSEL_EFFECT_ANGLE_SWEEP / stageSize.width ); - Property::Index anglePerUnit = shaderEffect.GetPropertyIndex( shaderEffect.GetAnglePerUnitPropertyName() ); + Property::Index anglePerUnit = shaderEffect.GetPropertyIndex( "uAnglePerUnit" ); Constraint constraint = Constraint::New( shaderEffect, anglePerUnit, CarouselEffectOrientationConstraint( angleSweep ) ); constraint.AddSource( Source(mView, Actor::Property::ORIENTATION) ); constraint.Apply(); @@ -685,10 +688,10 @@ public: mScrollView.SetRulerY(rulerY); // Apply Carousel Shader Effect to scrollView (Spherical style) - CarouselEffect shaderEffect = CarouselEffect::New(); + ShaderEffect shaderEffect = Toolkit::CreateCarouselEffect(); - shaderEffect.SetRadius( SPHERE_EFFECT_RADIUS ); - shaderEffect.SetAnglePerUnit( Vector2( SPHERE_EFFECT_ANGLE_SWEEP / stageSize.y, SPHERE_EFFECT_ANGLE_SWEEP / stageSize.y ) ); + shaderEffect.SetUniform( "uRadius", SPHERE_EFFECT_RADIUS ); + shaderEffect.SetUniform( "uAnglePerUnit", Vector2( SPHERE_EFFECT_ANGLE_SWEEP / stageSize.y, SPHERE_EFFECT_ANGLE_SWEEP / stageSize.y ) ); // dont apply shader effect to scrollview as it might override internal shaders for bounce effect etc for( std::vector::iterator i = mClusterInfo.begin(); i != mClusterInfo.end(); ++i ) { diff --git a/examples/dissolve-effect/dissolve-effect-example.cpp b/examples/dissolve-effect/dissolve-effect-example.cpp index bb39943..37e8d6b 100644 --- a/examples/dissolve-effect/dissolve-effect-example.cpp +++ b/examples/dissolve-effect/dissolve-effect-example.cpp @@ -163,8 +163,8 @@ private: ImageActor mNextImage; unsigned int mIndex; - Toolkit::DissolveEffect mCurrentImageEffect; - Toolkit::DissolveEffect mNextImageEffect; + ShaderEffect mCurrentImageEffect; + ShaderEffect mNextImageEffect; bool mUseHighPrecision; Animation mAnimation; @@ -234,8 +234,8 @@ void DissolveEffectApp::OnInit( Application& application ) mPanGestureDetector.DetectedSignal().Connect( this, &DissolveEffectApp::OnPanGesture ); // create the dissolve effect object - mCurrentImageEffect = Toolkit::DissolveEffect::New(mUseHighPrecision); - mNextImageEffect = Toolkit::DissolveEffect::New(mUseHighPrecision); + mCurrentImageEffect = Toolkit::CreateDissolveEffect(mUseHighPrecision); + mNextImageEffect = Toolkit::CreateDissolveEffect(mUseHighPrecision); mViewTimer = Timer::New( VIEWINGTIME ); mViewTimer.TickSignal().Connect( this, &DissolveEffectApp::OnTimerTick ); @@ -293,20 +293,20 @@ void DissolveEffectApp::StartTransition(Vector2 position, Vector2 displacement) { mAnimation = Animation::New(TRANSITION_DURATION); - mCurrentImageEffect.SetCentralLine(position,displacement); - mCurrentImageEffect.SetDistortion(0.0f); + Dali::Toolkit::DissolveEffectSetCentralLine( mCurrentImageEffect, position, displacement ); + mCurrentImageEffect.SetUniform("uPercentage", 0.0f); mCurrentImage.SetShaderEffect(mCurrentImageEffect); - mAnimation.AnimateTo( Property(mCurrentImageEffect, mCurrentImageEffect.GetDistortionPropertyName()), 1.0f, AlphaFunction::LINEAR ); + mAnimation.AnimateTo( Property(mCurrentImageEffect, "uPercentage"), 1.0f, AlphaFunction::LINEAR ); mNextImage.SetOpacity(0.0f); mAnimation.AnimateTo( Property( mNextImage, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::LINEAR ); if(mUseHighPrecision) { - mNextImageEffect.SetCentralLine(position,-displacement); - mNextImageEffect.SetDistortion(1.0f); + Dali::Toolkit::DissolveEffectSetCentralLine( mNextImageEffect, position, displacement ); + mNextImageEffect.SetUniform("uPercentage", 1.0f); mNextImage.SetShaderEffect(mNextImageEffect); - mAnimation.AnimateTo( Property(mNextImageEffect, mNextImageEffect.GetDistortionPropertyName()), 0.0f, AlphaFunction::LINEAR ); + mAnimation.AnimateTo( Property(mNextImageEffect, "uPercentage"), 0.0f, AlphaFunction::LINEAR ); } else { @@ -332,7 +332,7 @@ void DissolveEffectApp::OnKeyEvent(const KeyEvent& event) bool DissolveEffectApp::OnEffectButtonClicked( Toolkit::Button button ) { mUseHighPrecision = !mUseHighPrecision; - mCurrentImageEffect = Toolkit::DissolveEffect::New(mUseHighPrecision); + mCurrentImageEffect = Dali::Toolkit::CreateDissolveEffect(mUseHighPrecision); if(mUseHighPrecision) { mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_HIGHP) ); diff --git a/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp b/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp index a49d306..bfab91e 100644 --- a/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp +++ b/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp @@ -211,16 +211,19 @@ public: mDesiredBox.SetParentOrigin( ParentOrigin::CENTER ); mDesiredBox.SetAnchorPoint( AnchorPoint::CENTER ); mDesiredBox.SetPosition( 0, 0, -1 ); + mDesiredBox.SetSortModifier(4.f); mHeightBox.SetSize( stage.GetSize().width, (stage.GetSize() * mImageStageScale).height ); mHeightBox.SetParentOrigin( ParentOrigin::CENTER ); mHeightBox.SetAnchorPoint( AnchorPoint::CENTER ); mHeightBox.SetPosition( 0, 0, -1 ); + mHeightBox.SetSortModifier(3.f); mWidthBox.SetSize( (stage.GetSize() * mImageStageScale).width, stage.GetSize().height ); mWidthBox.SetParentOrigin( ParentOrigin::CENTER ); mWidthBox.SetAnchorPoint( AnchorPoint::CENTER ); mWidthBox.SetPosition( 0, 0, -1 ); + mWidthBox.SetSortModifier(2.f); // Make a grab-handle for resizing the image: mGrabCorner = Toolkit::PushButton::New(); @@ -233,9 +236,14 @@ public: mGrabCorner.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT ); mGrabCorner.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT ); mGrabCorner.SetSize( Vector2( stage.GetSize().width*0.08f, stage.GetSize().width*0.08f ) ); - mGrabCorner.SetZ( 1.0f ); mGrabCorner.SetOpacity( 0.6f ); - mDesiredBox.Add( mGrabCorner ); + + Layer grabCornerLayer = Layer::New(); + grabCornerLayer.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT ); + grabCornerLayer.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT ); + + grabCornerLayer.Add( mGrabCorner ); + mDesiredBox.Add( grabCornerLayer ); mPanGestureDetector = PanGestureDetector::New(); mPanGestureDetector.Attach( mGrabCorner ); mPanGestureDetector.DetectedSignal().Connect( this, &ImageScalingAndFilteringController::OnPan ); @@ -246,6 +254,7 @@ public: // Reposition the actor mImageActor.SetParentOrigin( ParentOrigin::CENTER ); mImageActor.SetAnchorPoint( AnchorPoint::CENTER ); + mImageActor.SetSortModifier(5.f); // Display the actor on the stage stage.Add( mImageActor ); @@ -700,9 +709,9 @@ private: private: Application& mApplication; - Actor mDesiredBox; //< Background rectangle to show requested image size. - Actor mHeightBox; //< Background horizontal stripe to show requested image height. - Actor mWidthBox; //< Background vertical stripe to show requested image width. + ImageActor mDesiredBox; //< Background rectangle to show requested image size. + ImageActor mHeightBox; //< Background horizontal stripe to show requested image height. + ImageActor mWidthBox; //< Background vertical stripe to show requested image width. Toolkit::PushButton mFittingModeButton; Toolkit::PushButton mSamplingModeButton; Toolkit::Popup mPopup; diff --git a/examples/line-mesh/line-mesh-example.cpp b/examples/line-mesh/line-mesh-example.cpp new file mode 100644 index 0000000..642441d --- /dev/null +++ b/examples/line-mesh/line-mesh-example.cpp @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2015 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. + * + */ + +// EXTERNAL INCLUDES +#include +#include + +// INTERNAL INCLUDES +#include "shared/view.h" + +using namespace Dali; + +namespace +{ +const char* MATERIAL_SAMPLE( DALI_IMAGE_DIR "gallery-small-48.jpg" ); +const char* MATERIAL_SAMPLE2( DALI_IMAGE_DIR "gallery-medium-19.jpg" ); + +#define MAKE_SHADER(A)#A + +const char* VERTEX_SHADER = MAKE_SHADER( +attribute mediump vec2 aPosition1; +attribute mediump vec2 aPosition2; +uniform mediump mat4 uMvpMatrix; +uniform mediump vec3 uSize; +uniform mediump float uMorphAmount; + +void main() +{ + mediump vec2 morphPosition = mix(aPosition1, aPosition2, uMorphAmount); + mediump vec4 vertexPosition = vec4(morphPosition, 0.0, 1.0); + vertexPosition.xyz *= uSize; + vertexPosition = uMvpMatrix * vertexPosition; + gl_Position = vertexPosition; +} +); + +const char* FRAGMENT_SHADER = MAKE_SHADER( +uniform lowp vec4 uColor; +uniform sampler2D sTexture; + +void main() +{ + gl_FragColor = uColor; +} +); + +Geometry CreateGeometry() +{ + // Create vertices + struct Vertex { Vector2 position; }; + Vertex pentagonVertexData[5] = + { + { Vector2( 0.0f, 1.00f) }, // 0 + { Vector2( -0.95f, 0.31f) }, // 1 + { Vector2( -0.59f, -0.81f) }, // 2 + { Vector2( 0.59f, -0.81f) }, // 3 + { Vector2( 0.95f, 0.31f) }, // 4 + }; + + Vertex pentacleVertexData[5] = + { + { Vector2( 0.0f, -1.00f) }, // + { Vector2( 0.59f, 0.81f) }, // + { Vector2( -0.95f, -0.31f) }, // + { Vector2( 0.95f, -0.31f) }, // + { Vector2( -0.59f, 0.81f) }, // + }; + + Property::Map pentagonVertexFormat; + pentagonVertexFormat["aPosition1"] = Property::VECTOR2; + PropertyBuffer pentagonVertices = PropertyBuffer::New( pentagonVertexFormat, 5 ); + pentagonVertices.SetData(pentagonVertexData); + + Property::Map pentacleVertexFormat; + pentacleVertexFormat["aPosition2"] = Property::VECTOR2; + PropertyBuffer pentacleVertices = PropertyBuffer::New( pentacleVertexFormat, 5 ); + pentacleVertices.SetData(pentacleVertexData); + + // Create indices + unsigned int indexData[10] = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 0 }; + Property::Map indexFormat; + indexFormat["indices"] = Property::UNSIGNED_INTEGER; + PropertyBuffer indices = PropertyBuffer::New( indexFormat, sizeof(indexData)/sizeof(indexData[0]) ); + indices.SetData(indexData); + + // Create the geometry object + Geometry pentagonGeometry = Geometry::New(); + pentagonGeometry.AddVertexBuffer( pentagonVertices ); + pentagonGeometry.AddVertexBuffer( pentacleVertices ); + pentagonGeometry.SetIndexBuffer( indices ); + + pentagonGeometry.SetGeometryType( Geometry::LINES ); + + return pentagonGeometry; +} + +} // anonymous namespace + +// This example shows how to morph between 2 meshes with the same number of +// vertices. +class ExampleController : public ConnectionTracker +{ +public: + + /** + * The example controller constructor. + * @param[in] application The application instance + */ + ExampleController( Application& application ) + : mApplication( application ) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect( this, &ExampleController::Create ); + } + + /** + * The example controller destructor + */ + ~ExampleController() + { + // Nothing to do here; + } + + /** + * Invoked upon creation of application + * @param[in] application The application instance + */ + void Create( Application& application ) + { + Stage stage = Stage::GetCurrent(); + stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); + + mStageSize = stage.GetSize(); + + // The Init signal is received once (only) during the Application lifetime + + // Hide the indicator bar + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); + + mImage = ResourceImage::New( MATERIAL_SAMPLE ); + mSampler = Sampler::New(mImage, "sTexture"); + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + + mMaterial = Material::New( mShader ); + mMaterial.AddSampler( mSampler ); + + mGeometry = CreateGeometry(); + + mRenderer = Renderer::New( mGeometry, mMaterial ); + + mMeshActor = Actor::New(); + mMeshActor.AddRenderer( mRenderer ); + mMeshActor.SetSize(200, 200); + + Property::Index morphAmountIndex = mMeshActor.RegisterProperty( "uMorphAmount", 0.0f ); + + mRenderer.SetDepthIndex(0); + + mMeshActor.SetParentOrigin( ParentOrigin::CENTER ); + mMeshActor.SetAnchorPoint( AnchorPoint::CENTER ); + stage.Add( mMeshActor ); + + mChangeImageTimer = Timer::New( 5000 ); + mChangeImageTimer.TickSignal().Connect( this, &ExampleController::OnTimer ); + mChangeImageTimer.Start(); + + Animation animation = Animation::New(5); + KeyFrames keyFrames = KeyFrames::New(); + keyFrames.Add(0.0f, 0.0f); + keyFrames.Add(1.0f, 1.0f); + + animation.AnimateBetween( Property( mMeshActor, morphAmountIndex ), keyFrames, AlphaFunction(AlphaFunction::SIN) ); + animation.SetLooping(true); + animation.Play(); + + stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));; + } + + /** + * Invoked whenever the quit button is clicked + * @param[in] button the quit button + */ + bool OnQuitButtonClicked( Toolkit::Button button ) + { + // quit the application + mApplication.Quit(); + return true; + } + + bool OnTimer() + { + Image image = ResourceImage::New( MATERIAL_SAMPLE2 ); + mSampler.SetImage( image ); + return false; + } + + 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; ///< Application instance + Vector3 mStageSize; ///< The size of the stage + + Image mImage; + Sampler mSampler; + Shader mShader; + Material mMaterial; + Geometry mGeometry; + Renderer mRenderer; + Actor mMeshActor; + Renderer mRenderer2; + Actor mMeshActor2; + Timer mChangeImageTimer; +}; + +void RunTest( Application& application ) +{ + ExampleController test( application ); + + application.MainLoop(); +} + +// Entry point for Linux & SLP applications +// +int main( int argc, char **argv ) +{ + Application application = Application::New( &argc, &argv ); + + RunTest( application ); + + return 0; +} diff --git a/examples/mesh-morph/mesh-morph-example.cpp b/examples/mesh-morph/mesh-morph-example.cpp new file mode 100644 index 0000000..baf9ff6 --- /dev/null +++ b/examples/mesh-morph/mesh-morph-example.cpp @@ -0,0 +1,372 @@ +/* + * 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. + * + */ + +// EXTERNAL INCLUDES +#include +#include + +// INTERNAL INCLUDES +#include "shared/view.h" + +using namespace Dali; + +namespace +{ + +#define MAKE_SHADER(A)#A + +const char* VERTEX_SHADER = MAKE_SHADER( +attribute mediump vec2 aInitPos; +attribute mediump vec2 aFinalPos; +attribute mediump vec3 aColor; +uniform mediump mat4 uMvpMatrix; +uniform mediump vec3 uSize; +uniform mediump float uDelta; +uniform lowp vec4 uColor; +varying lowp vec4 vColor; + +void main() +{ + mediump vec4 vertexPosition = vec4(mix(aInitPos, aFinalPos, uDelta), 0.0, 1.0); + vertexPosition.xyz *= uSize; + vertexPosition = uMvpMatrix * vertexPosition; + gl_Position = vertexPosition; + vColor = vec4(aColor, 0.) * uColor; +} +); + +const char* FRAGMENT_SHADER = MAKE_SHADER( +varying lowp vec4 vColor; + +void main() +{ + gl_FragColor = vColor; +} +); + +Geometry CreateGeometry() +{ + // Create vertices + struct VertexPosition { Vector2 position; }; + struct VertexColor { Vector3 color; }; + + VertexPosition quad[] = { + // yellow + { Vector2(-.5, -.5) }, + { Vector2( .0, .0) }, + { Vector2(-.5, .5) }, + + // green + { Vector2(-.5, -.5) }, + { Vector2( .5, -.5) }, + { Vector2( .0, .0) }, + + // blue + { Vector2(.5, -.5) }, + { Vector2(.5, .0) }, + { Vector2(.25, -.25) }, + + // red + { Vector2(.25, -.25) }, + { Vector2(.5, .0) }, + { Vector2(.25, .25) }, + { Vector2(.25, .25) }, + { Vector2(.0, .0) }, + { Vector2(.25, -.25) }, + + // cyan + { Vector2( .0, .0) }, + { Vector2( .25, .25) }, + { Vector2(-.25, .25) }, + + // magenta + { Vector2(-.25, .25) }, + { Vector2( .25, .25) }, + { Vector2( .0, .5) }, + { Vector2( .0, .5) }, + { Vector2(-.5, .5) }, + { Vector2(-.25, .25) }, + + // orange + { Vector2( .5, .0) }, + { Vector2( .5, .5) }, + { Vector2( .0, .5) }, + }; + + float bigSide = 0.707106781; + float side = bigSide * .5f; + // float smallSide = side * .5f; + + Vector2 pA = Vector2( side, .25 ); + Vector2 pB = pA + Vector2( 0., bigSide ); + Vector2 pC = pB + Vector2( -bigSide, 0. ); + Vector2 pD = pA + Vector2(-.5, -.5 ); + Vector2 pE = pD + Vector2( .0, 1. ); + Vector2 pF = pD + Vector2(-side, side ); + Vector2 pF2 = pD + Vector2( 0., bigSide ); + Vector2 pG = pD + Vector2(-.25, .25 ); + Vector2 pH = pD + Vector2( -.5, .0 ); + Vector2 pI = pD + Vector2(-.25, -.25 ); + Vector2 pJ = pD + Vector2( 0., -.5); + Vector2 pK = pD + Vector2(-.5, -.5); + Vector2 pL = pB + Vector2(0, -side); + Vector2 pM = pL + Vector2(side, -side); + Vector2 pN = pB + Vector2(side, -side); + + VertexPosition cat[] = { + // yellow + { pA }, + { pB }, + { pC }, + + // green + { pD }, + { pA }, + { pE }, + + // blue + { pJ }, + { pD }, + { pI }, + + // red + { pI }, + { pD }, + { pG }, + { pG }, + { pH }, + { pI }, + + // cyan + { pI }, + { pH }, + { pK }, + + // magenta + { pL }, + { pM }, + { pN }, + { pN }, + { pB }, + { pL }, + + // orange + { pD }, + { pF2 }, + { pF }, + }; + + VertexColor colors[] = { + // yellow + { Vector3( 1., 1., 0. ) }, + { Vector3( 1., 1., 0. ) }, + { Vector3( 1., 1., 0. ) }, + + // green + { Vector3( 0., 1., 0. ) }, + { Vector3( 0., 1., 0. ) }, + { Vector3( 0., 1., 0. ) }, + + // blue + { Vector3( 0., 0., 1. ) }, + { Vector3( 0., 0., 1. ) }, + { Vector3( 0., 0., 1. ) }, + + // red + { Vector3( 1., 0., 0. ) }, + { Vector3( 1., 0., 0. ) }, + { Vector3( 1., 0., 0. ) }, + { Vector3( 1., 0., 0. ) }, + { Vector3( 1., 0., 0. ) }, + { Vector3( 1., 0., 0. ) }, + + // cyan + { Vector3( 0., 1., 1. ) }, + { Vector3( 0., 1., 1. ) }, + { Vector3( 0., 1., 1. ) }, + + // magenta + { Vector3( 1., 0., 1. ) }, + { Vector3( 1., 0., 1. ) }, + { Vector3( 1., 0., 1. ) }, + { Vector3( 1., 0., 1. ) }, + { Vector3( 1., 0., 1. ) }, + { Vector3( 1., 0., 1. ) }, + + // orange + { Vector3( 1., 0.5, 0. ) }, + { Vector3( 1., 0.5, 0. ) }, + { Vector3( 1., 0.5, 0. ) }, + + }; + + unsigned int numberOfVertices = sizeof(quad)/sizeof(VertexPosition); + + Property::Map initialPositionVertexFormat; + initialPositionVertexFormat["aInitPos"] = Property::VECTOR2; + PropertyBuffer initialPositionVertices = PropertyBuffer::New( initialPositionVertexFormat, numberOfVertices ); + initialPositionVertices.SetData(quad); + + Property::Map finalPositionVertexFormat; + finalPositionVertexFormat["aFinalPos"] = Property::VECTOR2; + PropertyBuffer finalPositionVertices = PropertyBuffer::New( finalPositionVertexFormat, numberOfVertices ); + finalPositionVertices.SetData(cat); + + Property::Map colorVertexFormat; + colorVertexFormat["aColor"] = Property::VECTOR3; + PropertyBuffer colorVertices = PropertyBuffer::New( colorVertexFormat, numberOfVertices ); + colorVertices.SetData(colors); + + // Create the geometry object + Geometry texturedQuadGeometry = Geometry::New(); + texturedQuadGeometry.AddVertexBuffer( initialPositionVertices ); + texturedQuadGeometry.AddVertexBuffer( finalPositionVertices ); + texturedQuadGeometry.AddVertexBuffer( colorVertices ); + + return texturedQuadGeometry; +} + +inline float StationarySin( float progress ) ///< Single revolution +{ + float val = cosf(progress * 2.0f * Math::PI) + .5f; + val = val > 1.f ? 1.f : val; + val = val < 0.f ? 0.f : val; + return val; +} + +} // anonymous namespace + +// This example shows how to use a simple mesh +// +class ExampleController : public ConnectionTracker +{ +public: + + /** + * The example controller constructor. + * @param[in] application The application instance + */ + ExampleController( Application& application ) + : mApplication( application ) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect( this, &ExampleController::Create ); + } + + /** + * The example controller destructor + */ + ~ExampleController() + { + // Nothing to do here; + } + + /** + * Invoked upon creation of application + * @param[in] application The application instance + */ + void Create( Application& application ) + { + Stage stage = Stage::GetCurrent(); + stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); + + mStageSize = stage.GetSize(); + + // The Init signal is received once (only) during the Application lifetime + + // Hide the indicator bar + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); + + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + + mMaterial = Material::New( mShader ); + mGeometry = CreateGeometry(); + + mRenderer = Renderer::New( mGeometry, mMaterial ); + + mMeshActor = Actor::New(); + mMeshActor.AddRenderer( mRenderer ); + mMeshActor.SetSize(400, 400); + + Property::Index morphDeltaIndex = mMeshActor.RegisterProperty( "uDelta", 0.f ); + + mRenderer.SetDepthIndex(0); + + mMeshActor.SetParentOrigin( ParentOrigin::CENTER ); + mMeshActor.SetAnchorPoint( AnchorPoint::CENTER ); + stage.Add( mMeshActor ); + + Animation animation = Animation::New(10); + animation.AnimateTo( Property( mMeshActor, morphDeltaIndex ), 1.f, StationarySin ); + animation.SetLooping( true ); + animation.Play(); + + stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));; + } + + /** + * Invoked whenever the quit button is clicked + * @param[in] button the quit button + */ + bool OnQuitButtonClicked( Toolkit::Button button ) + { + // quit the application + mApplication.Quit(); + return true; + } + + 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; ///< Application instance + Vector3 mStageSize; ///< The size of the stage + + Shader mShader; + Material mMaterial; + Geometry mGeometry; + Renderer mRenderer; + Actor mMeshActor; + Timer mMorphTimer; +}; + +void RunTest( Application& application ) +{ + ExampleController test( application ); + + application.MainLoop(); +} + +// Entry point for Linux & SLP applications +// +int main( int argc, char **argv ) +{ + Application application = Application::New( &argc, &argv ); + + RunTest( application ); + + return 0; +} diff --git a/examples/mesh-sorting/mesh-sorting-example.cpp b/examples/mesh-sorting/mesh-sorting-example.cpp new file mode 100644 index 0000000..248a4c3 --- /dev/null +++ b/examples/mesh-sorting/mesh-sorting-example.cpp @@ -0,0 +1,346 @@ +/* + * Copyright (c) 2015 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. + * + */ + +// EXTERNAL INCLUDES +#include +#include +#include +#include +#include + +// INTERNAL INCLUDES +#include "shared/view.h" + +using namespace Dali; + +namespace +{ + +const char* MATERIAL_SAMPLES[] = +{ + DALI_IMAGE_DIR "people-medium-1.jpg", + DALI_IMAGE_DIR "people-medium-4.jpg", + DALI_IMAGE_DIR "people-medium-11.jpg", + DALI_IMAGE_DIR "people-small-16.jpg", + DALI_IMAGE_DIR "people-medium-15.jpg", + DALI_IMAGE_DIR "people-medium-6.jpg", +}; +const unsigned int NUMBER_OF_SAMPLES(sizeof(MATERIAL_SAMPLES)/sizeof(const char*)); + + +#define MAKE_SHADER(A)#A + +const char* VERTEX_SHADER = MAKE_SHADER( +uniform highp float uHue; +attribute mediump vec2 aPosition; +attribute highp vec2 aTexCoord; +varying mediump vec2 vTexCoord; +uniform mediump mat4 uMvpMatrix; +uniform mediump vec3 uSize; +varying mediump vec3 vGlobColor; + +vec3 hsv2rgb(vec3 c) +{ + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} + +void main() +{ + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); + vertexPosition.xyz *= uSize; + vertexPosition = uMvpMatrix * vertexPosition; + vGlobColor = hsv2rgb( vec3( clamp(uHue, 0.0, 1.0), 1.0, 1.0 ) ); + + vTexCoord = aTexCoord; + gl_Position = vertexPosition; +} +); + +const char* FRAGMENT_SHADER = MAKE_SHADER( +varying mediump vec2 vTexCoord; +varying mediump vec3 vGlobColor; +uniform lowp vec4 uColor; +uniform sampler2D sTexture; + +void main() +{ + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * vec4(vGlobColor, 1.0) ; +} +); + +Geometry CreateGeometry() +{ + // Create vertices + const float halfQuadSize = .5f; + struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; + TexturedQuadVertex texturedQuadVertexData[4] = { + { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) }, + { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) }, + { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) }, + { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } }; + + Property::Map texturedQuadVertexFormat; + texturedQuadVertexFormat["aPosition"] = Property::VECTOR2; + texturedQuadVertexFormat["aTexCoord"] = Property::VECTOR2; + PropertyBuffer texturedQuadVertices = PropertyBuffer::New( texturedQuadVertexFormat, 4 ); + texturedQuadVertices.SetData(texturedQuadVertexData); + + // Create indices + unsigned int indexData[6] = { 0, 3, 1, 0, 2, 3 }; + Property::Map indexFormat; + indexFormat["indices"] = Property::UNSIGNED_INTEGER; + PropertyBuffer indices = PropertyBuffer::New( indexFormat, 6 ); + indices.SetData(indexData); + + // Create the geometry object + Geometry texturedQuadGeometry = Geometry::New(); + texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices ); + texturedQuadGeometry.SetIndexBuffer( indices ); + + return texturedQuadGeometry; +} + +} // anonymous namespace + +// This example shows how to use a simple mesh +// +class ExampleController : public ConnectionTracker +{ +public: + + /** + * The example controller constructor. + * @param[in] application The application instance + */ + ExampleController( Application& application ) + : mApplication( application ), + mZMode(0) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect( this, &ExampleController::Create ); + memset(mDepthIndices, 0, sizeof(mDepthIndices)); + } + + /** + * The example controller destructor + */ + ~ExampleController() + { + // Nothing to do here; + } + + /** + * Invoked upon creation of application + * @param[in] application The application instance + */ + void Create( Application& application ) + { + Stage stage = Stage::GetCurrent(); + stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); + + mStageSize = stage.GetSize(); + + // The Init signal is received once (only) during the Application lifetime + + // Hide the indicator bar + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); + + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mGeometry = CreateGeometry(); + + Material firstMat; + + for( unsigned i=0; i(actor.GetPropertyIndex("index")); + + int newDepthIndex = (mDepthIndices[index] + 10) % 30; + mDepthIndices[index] = newDepthIndex; + + Renderer renderer = actor.GetRendererAt(0); + renderer.SetDepthIndex(newDepthIndex); + + PrintDepths(); + } + return true; + } + + bool OnStageTouched( Actor rootLayer, const TouchEvent& event ) + { + if( event.GetPoint(0).state == TouchPoint::Finished ) + { + switch( mZMode ) + { + case 0: + { + mZMode = 1; + for(unsigned int i=1; i < rootLayer.GetChildCount(); ++i) + { + Actor child = rootLayer.GetChildAt(i); + child.SetZ( 0.0f ); + } + PrintDepths(); + break; + } + case 1: + { + mZMode = 2; + for(unsigned int i=1; i < rootLayer.GetChildCount(); ++i) + { + Actor child = rootLayer.GetChildAt(i); + child.SetZ( 100-i*10 ); + } + PrintDepths(); + break; + } + case 2: + { + mZMode = 0; + for(unsigned int i=1; i < rootLayer.GetChildCount(); ++i) + { + Actor child = rootLayer.GetChildAt(i); + child.SetZ( i*10 ); + } + PrintDepths(); + break; + } + } + } + return true; + } + + /** + * Invoked whenever the quit button is clicked + * @param[in] button the quit button + */ + bool OnQuitButtonClicked( Toolkit::Button button ) + { + // quit the application + mApplication.Quit(); + return true; + } + + 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; ///< Application instance + Vector3 mStageSize; ///< The size of the stage + + Shader mShader; + Geometry mGeometry; + + int mDepthIndices[NUMBER_OF_SAMPLES]; + Actor mActors[NUMBER_OF_SAMPLES]; + int mZMode; +}; + +void RunTest( Application& application ) +{ + ExampleController test( application ); + + application.MainLoop(); +} + +// Entry point for Linux & SLP applications +// +int main( int argc, char **argv ) +{ + Application application = Application::New( &argc, &argv ); + + RunTest( application ); + + return 0; +} diff --git a/examples/motion-blur/motion-blur-example.cpp b/examples/motion-blur/motion-blur-example.cpp index d783a3b..0e9ae80 100644 --- a/examples/motion-blur/motion-blur-example.cpp +++ b/examples/motion-blur/motion-blur-example.cpp @@ -214,7 +214,12 @@ public: mContentLayer.Add( mMotionBlurImageActor ); // Create shader used for doing motion blur - mMotionBlurEffect = MotionBlurEffect::Apply(mMotionBlurImageActor); + mMotionBlurEffect = Toolkit::CreateMotionBlurEffect(); + Dali::Property::Index uModelProperty = mMotionBlurEffect.GetPropertyIndex( "uModelLastFrame" ); + Constraint constraint = Constraint::New( mMotionBlurEffect, uModelProperty, EqualToConstraint() ); + constraint.AddSource( Source( mMotionBlurImageActor , Actor::Property::WORLD_MATRIX ) ); + constraint.Apply(); + mMotionBlurImageActor.SetShaderEffect( mMotionBlurEffect ); #ifdef MULTIPLE_MOTION_BLURRED_ACTORS @@ -231,7 +236,7 @@ public: mMotionBlurImageActor.Add( mMotionBlurImageActor2 ); // Create shader used for doing motion blur - mMotionBlurEffect2 = MotionBlurEffect::New(MOTION_BLUR_NUM_SAMPLES); + mMotionBlurEffect2 = CreateMotionBlurEffect(MOTION_BLUR_NUM_SAMPLES); // set actor shader to the blur one mMotionBlurImageActor2.SetShaderEffect( mMotionBlurEffect2 ); @@ -249,7 +254,7 @@ public: mMotionBlurImageActor.Add( mMotionBlurImageActor3 ); // Create shader used for doing motion blur - mMotionBlurEffect3 = MotionBlurEffect::New(MOTION_BLUR_NUM_SAMPLES); + mMotionBlurEffect3 = CreateMotionBlurEffect(MOTION_BLUR_NUM_SAMPLES); // set actor shader to the blur one mMotionBlurImageActor3.SetShaderEffect( mMotionBlurEffect3 ); @@ -267,7 +272,7 @@ public: mMotionBlurImageActor.Add( mMotionBlurImageActor4 ); // Create shader used for doing motion blur - mMotionBlurEffect4 = MotionBlurEffect::New(MOTION_BLUR_NUM_SAMPLES); + mMotionBlurEffect4 = CreateMotionBlurEffect(MOTION_BLUR_NUM_SAMPLES); // set actor shader to the blur one mMotionBlurImageActor4.SetShaderEffect( mMotionBlurEffect4 ); @@ -285,7 +290,7 @@ public: mMotionBlurImageActor.Add( mMotionBlurImageActor5 ); // Create shader used for doing motion blur - mMotionBlurEffect5 = MotionBlurEffect::New(MOTION_BLUR_NUM_SAMPLES); + mMotionBlurEffect5 = CreateMotionBlurEffect(MOTION_BLUR_NUM_SAMPLES); // set actor shader to the blur one mMotionBlurImageActor5.SetShaderEffect( mMotionBlurEffect5 ); @@ -515,15 +520,15 @@ private: PushButton mActorEffectsButton; ///< The actor effects toggling Button. // Motion blur - MotionBlurEffect mMotionBlurEffect; + ShaderEffect mMotionBlurEffect; ImageActor mMotionBlurImageActor; Size mMotionBlurActorSize; #ifdef MULTIPLE_MOTION_BLURRED_ACTORS - MotionBlurEffect mMotionBlurEffect2; - MotionBlurEffect mMotionBlurEffect3; - MotionBlurEffect mMotionBlurEffect4; - MotionBlurEffect mMotionBlurEffect5; + ShaderEffect mMotionBlurEffect2; + ShaderEffect mMotionBlurEffect3; + ShaderEffect mMotionBlurEffect4; + ShaderEffect mMotionBlurEffect5; ImageActor mMotionBlurImageActor2; ImageActor mMotionBlurImageActor3; diff --git a/examples/motion-stretch/motion-stretch-example.cpp b/examples/motion-stretch/motion-stretch-example.cpp index ebfa809..0084cdd 100644 --- a/examples/motion-stretch/motion-stretch-example.cpp +++ b/examples/motion-stretch/motion-stretch-example.cpp @@ -184,7 +184,12 @@ public: mContentLayer.Add( mMotionStretchImageActor ); // Create shader used for doing motion stretch - mMotionStretchEffect = MotionStretchEffect::Apply(mMotionStretchImageActor); + mMotionStretchEffect = Toolkit::CreateMotionStretchEffect(); + Dali::Property::Index uModelProperty = mMotionStretchEffect.GetPropertyIndex( "uModelLastFrame" ); + Constraint constraint = Constraint::New( mMotionStretchEffect, uModelProperty, EqualToConstraint() ); + constraint.AddSource( Source( mMotionStretchImageActor , Actor::Property::WORLD_MATRIX ) ); + constraint.Apply(); + mMotionStretchImageActor.SetShaderEffect( mMotionStretchEffect ); } ////////////////////////////////////////////////////////////// @@ -408,7 +413,7 @@ private: PushButton mActorEffectsButton; ///< The actor effects toggling Button. // Motion stretch - MotionStretchEffect mMotionStretchEffect; + ShaderEffect mMotionStretchEffect; ImageActor mMotionStretchImageActor; // animate actor to position where user taps screen diff --git a/examples/new-window/new-window-example.cpp b/examples/new-window/new-window-example.cpp index 9282c8c..78978d5 100644 --- a/examples/new-window/new-window-example.cpp +++ b/examples/new-window/new-window-example.cpp @@ -14,18 +14,17 @@ * limitations under the License. */ +// EXTERNAL INCLUDES +#include #include -#include -#include -#include #include -#include - -#include "shared/view.h" #include #include +// INTERNAL INCLUDES +#include "shared/view.h" + using namespace Dali; using namespace Dali::Toolkit; @@ -38,23 +37,76 @@ 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 char * const LOGO_IMAGE(DALI_IMAGE_DIR "dali-logo.png"); const float EXPLOSION_DURATION(1.2f); -const unsigned int EMIT_INTERVAL_IN_MS(80); +const unsigned int EMIT_INTERVAL_IN_MS(40); 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"; +#define MAKE_SHADER(A)#A + +const char* VERTEX_COLOR_MESH = MAKE_SHADER( +attribute mediump vec3 aPosition;\n +attribute lowp vec3 aColor;\n +uniform mediump mat4 uMvpMatrix;\n +uniform mediump vec3 uSize;\n +varying lowp vec3 vColor;\n +\n +void main()\n +{\n + gl_Position = uMvpMatrix * vec4( aPosition*uSize, 1.0 );\n + vColor = aColor;\n +}\n +); + +const char* FRAGMENT_COLOR_MESH = MAKE_SHADER( +uniform lowp vec4 uColor;\n +varying lowp vec3 vColor;\n +\n +void main()\n +{\n + gl_FragColor = vec4(vColor,1.0)*uColor; +}\n +); + +const char* VERTEX_TEXTURE_MESH = MAKE_SHADER( +attribute mediump vec3 aPosition;\n +attribute highp vec2 aTexCoord;\n +uniform mediump mat4 uMvpMatrix;\n +uniform mediump vec3 uSize;\n +varying mediump vec2 vTexCoord;\n +\n +void main()\n +{\n + gl_Position = uMvpMatrix * vec4( aPosition*uSize, 1.0 );\n + vTexCoord = aTexCoord;\n +}\n +); + +const char* FRAGMENT_TEXTURE_MESH = MAKE_SHADER( +varying mediump vec2 vTexCoord;\n +uniform lowp vec4 uColor;\n +uniform sampler2D sTexture;\n +\n +void main()\n +{\n + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor; +}\n +); + +const char* FRAGMENT_BLEND_SHADER = MAKE_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 @@ -65,48 +117,39 @@ 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); + void AddBubbles(const Vector2& stageSize); + void AddMeshActor(); + void AddBlendingImageActor(); + void AddTextLabel(); + ImageActor CreateBlurredMirrorImage(const char* imageName); FrameBufferImage CreateFrameBufferForImage(const char* imageName, Image image, ShaderEffect shaderEffect); + void SetUpBubbleEmission( const Vector2& emitPosition, const Vector2& direction ); + Geometry CreateMeshGeometry(); + ShaderEffect CreateColorModifierer( const Vector3& rgbDelta ); + static void NewWindow(void); + + bool OnTrackTimerTick(); + void OnKeyEvent(const KeyEvent& event); + bool OnLoseContextButtonClicked( Toolkit::Button button ); + void OnContextLost(); + void OnContextRegained(); private: Application mApplication; - Actor mCastingLight; TextLabel mTextActor; - ImageActor mImageActor; - ImageActor mBlendActor; - Image mEffectImage; - Image mBaseImage; - MeshActor mMeshActor; - MeshActor mAnimatedMeshActor; Toolkit::Control mView; ///< The View instance. Toolkit::ToolBar mToolBar; ///< The View's Toolbar. - TextLabel mTitleActor; ///< The Toolbar's Title. + TextLabel mTitleActor; ///< The Toolbar's Title. Layer mContentLayer; ///< Content layer (scrolling cluster content) Toolkit::PushButton mLoseContextButton; - Vector3 mHSVDelta; - Toolkit::BubbleEmitter mEmitter; + Toolkit::BubbleEmitter mEmitter; Timer mEmitTrackTimer; - Timer mExplodeTimer; bool mNeedNewAnimation; - unsigned int mAnimateComponentCount; Animation mEmitAnimation; }; @@ -114,7 +157,6 @@ private: NewWindowController::NewWindowController( Application& application ) : mApplication(application), - mHSVDelta(0.5f, 0.0f, 0.5f), mNeedNewAnimation(true) { mApplication.InitSignal().Connect(this, &NewWindowController::Create); @@ -136,10 +178,17 @@ void NewWindowController::Create( Application& app ) mContentLayer = DemoHelper::CreateView( app, mView, mToolBar, - BACKGROUND_IMAGE, + "", TOOLBAR_IMAGE, "Context recovery" ); + Size stageSize = stage.GetSize(); + Image backgroundImage = ResourceImage::New( BACKGROUND_IMAGE, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); + ImageActor backgroundActor = ImageActor::New( backgroundImage ); + backgroundActor.SetParentOrigin( ParentOrigin::CENTER ); + backgroundActor.SetZ(-2.f); + mContentLayer.Add(backgroundActor); + // Point the default render task at the view RenderTaskList taskList = stage.GetRenderTaskList(); RenderTask defaultTask = taskList.GetTask( 0u ); @@ -153,29 +202,28 @@ void NewWindowController::Create( Application& app ) 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); + Image image = ResourceImage::New(LOGO_IMAGE); + ImageActor imageActor = ImageActor::New(image); + imageActor.SetName("dali-logo"); + imageActor.SetParentOrigin(ParentOrigin::CENTER); + imageActor.SetAnchorPoint(AnchorPoint::BOTTOM_CENTER); + logoLayoutActor.Add(imageActor); - ImageActor mirrorImageActor = CreateBlurredMirrorImage(DALI_IMAGE_DIR "dali-logo.png"); + ImageActor mirrorImageActor = CreateBlurredMirrorImage(LOGO_IMAGE); mirrorImageActor.SetParentOrigin(ParentOrigin::CENTER); mirrorImageActor.SetAnchorPoint(AnchorPoint::TOP_CENTER); logoLayoutActor.Add(mirrorImageActor); - CreateBubbles(stage.GetSize()); - CreateMeshActor(); - CreateBlending(); - CreateText(); + AddBubbles(stage.GetSize()); + AddMeshActor(); + AddBlendingImageActor(); + AddTextLabel(); stage.ContextLostSignal().Connect(this, &NewWindowController::OnContextLost); stage.ContextRegainedSignal().Connect(this, &NewWindowController::OnContextRegained); @@ -186,51 +234,109 @@ void NewWindowController::Destroy( Application& app ) UnparentAndReset(mTextActor); } -bool NewWindowController::OnLoseContextButtonClicked( Toolkit::Button button ) +void NewWindowController::AddBubbles(const Vector2& stageSize) { - // Add as an idle callback to avoid ProcessEvents being recursively called. - mApplication.AddIdle( MakeCallback( NewWindowController::NewWindow ) ); - return true; + mEmitter = Toolkit::BubbleEmitter::New( stageSize, + ResourceImage::New( DALI_IMAGE_DIR "bubble-ball.png" ), + 200, Vector2( 5.0f, 5.0f ) ); + + Image background = ResourceImage::New(BACKGROUND_IMAGE); + mEmitter.SetBackground( background, Vector3(0.5f, 0.f,0.5f) ); + mEmitter.SetBubbleDensity( 9.f ); + 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(); } -void NewWindowController::CreateMeshActor() +void NewWindowController::AddMeshActor() { - 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 ); + Geometry meshGeometry = CreateMeshGeometry(); + + // Create a coloured mesh + Shader shaderColorMesh = Shader::New( VERTEX_COLOR_MESH, FRAGMENT_COLOR_MESH ); + Material colorMeshmaterial = Material::New( shaderColorMesh ); + Renderer colorMeshRenderer = Renderer::New( meshGeometry, colorMeshmaterial ); + + Actor colorMeshActor = Actor::New(); + colorMeshActor.AddRenderer( colorMeshRenderer ); + colorMeshActor.SetSize( 175.f,175.f ); + colorMeshActor.SetParentOrigin( ParentOrigin::CENTER ); + colorMeshActor.SetAnchorPoint(AnchorPoint::TOP_CENTER); + colorMeshActor.SetPosition(Vector3(0.0f, 50.0f, 0.0f)); + colorMeshActor.SetOrientation( Degree(75.f), Vector3::XAXIS ); + colorMeshActor.SetName("ColorMeshActor"); + mContentLayer.Add( colorMeshActor ); + + // Create a textured mesh + Image effectImage = ResourceImage::New(EFFECT_IMAGE); + Sampler sampler = Sampler::New(effectImage, "sTexture"); + + Shader shaderTextureMesh = Shader::New( VERTEX_TEXTURE_MESH, FRAGMENT_TEXTURE_MESH ); + Material textureMeshMaterial = Material::New( shaderTextureMesh ); + textureMeshMaterial.AddSampler( sampler ); + Renderer textureMeshRenderer = Renderer::New( meshGeometry, textureMeshMaterial ); + + Actor textureMeshActor = Actor::New(); + textureMeshActor.AddRenderer( textureMeshRenderer ); + textureMeshActor.SetSize( 175.f,175.f ); + textureMeshActor.SetParentOrigin( ParentOrigin::CENTER ); + textureMeshActor.SetAnchorPoint(AnchorPoint::TOP_CENTER); + textureMeshActor.SetPosition(Vector3(0.0f, 200.0f, 0.0f)); + textureMeshActor.SetOrientation( Degree(75.f), Vector3::XAXIS ); + textureMeshActor.SetName("TextureMeshActor"); + mContentLayer.Add( textureMeshActor ); } -FrameBufferImage NewWindowController::CreateMirrorImage(const char* imageName) +void NewWindowController::AddBlendingImageActor() { - FrameBufferImage fbo; - Image image = ResourceImage::New(imageName); - fbo = CreateFrameBufferForImage(imageName, image, ShaderEffect()); - return fbo; + ShaderEffect colorModifier = CreateColorModifierer(Vector3( 0.5f, 0.5f, 0.5f )); + Image effectImage = ResourceImage::New(EFFECT_IMAGE); + FrameBufferImage fb2 = CreateFrameBufferForImage( EFFECT_IMAGE, effectImage, colorModifier ); + + ImageActor tmpActor = ImageActor::New(fb2); + mContentLayer.Add(tmpActor); + tmpActor.SetParentOrigin(ParentOrigin::CENTER_RIGHT); + tmpActor.SetAnchorPoint(AnchorPoint::TOP_RIGHT); + tmpActor.SetPosition(Vector3(0.0f, 150.0f, 0.0f)); + tmpActor.SetScale(0.25f); + + // create blending shader effect + ShaderEffect blendShader = ShaderEffect::New( "", FRAGMENT_BLEND_SHADER ); + blendShader.SetEffectImage( fb2 ); + blendShader.SetUniform("alpha", 0.5f); + + Image baseImage = ResourceImage::New(BASE_IMAGE); + ImageActor blendActor = ImageActor::New( baseImage ); + blendActor.SetParentOrigin(ParentOrigin::CENTER_RIGHT); + blendActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT); + blendActor.SetPosition(Vector3(0.0f, 100.0f, 0.0f)); + blendActor.SetSize(140, 140); + blendActor.SetShaderEffect( blendShader ); + mContentLayer.Add(blendActor); +} + +void NewWindowController::AddTextLabel() +{ + mTextActor = TextLabel::New("Some text"); + mTextActor.SetParentOrigin(ParentOrigin::CENTER); + mTextActor.SetColor(Color::RED); + mTextActor.SetName("PushMe text"); + mContentLayer.Add( mTextActor ); } ImageActor NewWindowController::CreateBlurredMirrorImage(const char* imageName) { - FrameBufferImage fbo; Image image = ResourceImage::New(imageName); + Uint16Pair intFboSize = ResourceImage::GetImageSize(imageName); Vector2 FBOSize = Vector2( intFboSize.GetWidth(), intFboSize.GetHeight() ); - fbo = FrameBufferImage::New( FBOSize.width, FBOSize.height, Pixel::RGBA8888); + FrameBufferImage 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 ); @@ -285,38 +391,7 @@ FrameBufferImage NewWindowController::CreateFrameBufferForImage(const char* imag 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 ) +void NewWindowController::SetUpBubbleEmission( const Vector2& emitPosition, const Vector2& direction) { if( mNeedNewAnimation ) { @@ -326,17 +401,97 @@ void NewWindowController::SetUpAnimation( Vector2 emitPosition, Vector2 directio mAnimateComponentCount = 0; } - mEmitter.EmitBubble( mEmitAnimation, emitPosition, direction, Vector2(1, 1) ); + mEmitter.EmitBubble( mEmitAnimation, emitPosition, direction, Vector2(10,10) ); mAnimateComponentCount++; - if( mAnimateComponentCount % 20 ==0 ) + if( mAnimateComponentCount % 6 ==0 ) { mEmitAnimation.Play(); mNeedNewAnimation = true; } } +Geometry NewWindowController::CreateMeshGeometry() +{ + // Create vertices and specify their color + struct Vertex + { + Vector3 position; + Vector2 textureCoordinates; + Vector3 color; + }; + + Vertex vertexData[5] = { + { Vector3( 0.0f, 0.0f, 0.5f ), Vector2(0.5f, 0.5f), Vector3(1.0f, 1.0f, 1.0f) }, + { Vector3( -0.5f, -0.5f, 0.0f ), Vector2(0.0f, 0.0f), Vector3(1.0f, 0.0f, 0.0f) }, + { Vector3( 0.5f, -0.5f, 0.0f ), Vector2(1.0f, 0.0f), Vector3(1.0f, 1.0f, 0.0f) }, + { Vector3( -0.5f, 0.5f, 0.0f ), Vector2(0.0f, 1.0f), Vector3(0.0f, 1.0f, 0.0f) }, + { Vector3( 0.5f, 0.5f, 0.0f ), Vector2(1.0f, 1.0f), Vector3(0.0f, 0.0f, 1.0f) } }; + + Property::Map vertexFormat; + vertexFormat["aPosition"] = Property::VECTOR3; + vertexFormat["aTexCoord"] = Property::VECTOR2; + vertexFormat["aColor"] = Property::VECTOR3; + PropertyBuffer vertices = PropertyBuffer::New( vertexFormat, 5 ); + vertices.SetData( vertexData ); + + // Specify all the faces + unsigned int indexData[12] = { 0,1,3,0,2,4,0,3,4,0,2,1 }; + Property::Map indexFormat; + indexFormat["indices"] = Property::UNSIGNED_INTEGER; + PropertyBuffer indices = PropertyBuffer::New( indexFormat, 12 ); + indices.SetData( indexData ); + + // Create the geometry object + Geometry geometry = Geometry::New(); + geometry.AddVertexBuffer( vertices ); + geometry.SetIndexBuffer( indices ); + + return geometry; +} + +ShaderEffect NewWindowController::CreateColorModifierer( const Vector3& rgbDelta ) +{ + std::string fragmentShader = MAKE_SHADER( + precision highp float;\n + uniform vec3 uRGBDelta;\n + uniform float uIgnoreAlpha;\n + float rand(vec2 co) \n + {\n + return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); \n} + \n + void main() {\n + vec4 color = texture2D(sTexture, vTexCoord); \n + // modify the hsv Value + color.rgb += uRGBDelta * rand(vTexCoord); \n + // if the new vale exceeds one, then decrease it + color.rgb -= max(color.rgb*2.0 - vec3(2.0), 0.0);\n + // if the new vale drops below zero, then increase it + color.rgb -= min(color.rgb*2.0, 0.0);\n + gl_FragColor = color; \n + }\n + ); + + ShaderEffect shaderEffect = ShaderEffect::New("", fragmentShader); + shaderEffect.SetUniform( "uRGBDelta", rgbDelta ); + + return shaderEffect; +} + +void NewWindowController::NewWindow(void) +{ + PositionSize posSize(0, 0, 720, 1280); + gApplication.ReplaceWindow(posSize, "NewWindow"); // Generates a new window +} + +bool NewWindowController::OnLoseContextButtonClicked( Toolkit::Button button ) +{ + // Add as an idle callback to avoid ProcessEvents being recursively called. + mApplication.AddIdle( MakeCallback( NewWindowController::NewWindow ) ); + return true; +} + bool NewWindowController::OnTrackTimerTick() { static int time=0; @@ -351,82 +506,13 @@ bool NewWindowController::OnTrackTimerTick() Vector2 direction = aimPos-position; Vector2 stageSize = Stage::GetCurrent().GetSize(); - for(int i=0; i<20; i++) - { - SetUpAnimation( stageSize*0.5f+position, direction ); - } + SetUpBubbleEmission( stageSize*0.5f+position, direction ); + SetUpBubbleEmission( stageSize*0.5f+position*0.75f, direction ); + SetUpBubbleEmission( stageSize*0.5f+position*0.7f, 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 = TextLabel::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) @@ -448,9 +534,6 @@ void NewWindowController::OnContextRegained() printf("Stage reporting context regain\n"); } - - - void RunTest(Application& app) { gNewWindowController = new NewWindowController(app); @@ -459,7 +542,6 @@ void RunTest(Application& app) // Entry point for Linux & Tizen applications // - int main(int argc, char **argv) { gApplication = Application::New(&argc, &argv, DALI_DEMO_THEME_PATH); diff --git a/examples/page-turn-view/page-turn-view-example.cpp b/examples/page-turn-view/page-turn-view-example.cpp index 39e329e..79b6ac2 100644 --- a/examples/page-turn-view/page-turn-view-example.cpp +++ b/examples/page-turn-view/page-turn-view-example.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #include #include diff --git a/examples/path-animation/path-animation.cpp b/examples/path-animation/path-animation.cpp deleted file mode 100644 index 8eaf0fc..0000000 --- a/examples/path-animation/path-animation.cpp +++ /dev/null @@ -1,517 +0,0 @@ -/* - * 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 -#include -#include -#include -#include - - - -// 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 Animation 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. - } - - /* - * Create a control composed of a label and an slider - * @param[in] label The text to be displayed ny the label - * @param[in] size The size of the slider - * @param[in] callback Pointer to the callback function to be called when user moves the slider - */ - Actor CreateVectorComponentControl( const std::string& label, const Vector3& size, bool(PathController::*callback)(Dali::Toolkit::Slider,float) ) - { - TextLabel text = TextLabel::New(label); - text.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH ); - text.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - text.SetColor( Vector4(0.0f,0.0f,0.0f,1.0f)); - - Slider slider = Slider::New(); - slider.SetAnchorPoint( AnchorPoint::CENTER_LEFT); - slider.SetParentOrigin( ParentOrigin::CENTER_RIGHT); - slider.SetProperty(Slider::Property::LOWER_BOUND, -1.0f ); - slider.SetProperty(Slider::Property::UPPER_BOUND, 1.0f ); - - Property::Array marks; - float mark = -1.0f; - for(unsigned short i(0); i<21; ++i ) - { - marks.PushBack( mark ); - mark += 0.1f; - } - - slider.SetProperty(Slider::Property::MARKS, marks); - slider.SetProperty(Slider::Property::SNAP_TO_MARKS, true ); - slider.SetSize(size); - slider.SetScale( 0.5f ); - slider.ValueChangedSignal().Connect(this,callback); - text.Add( slider ); - return text; - } - - /** - * Crate all the GUI controls - */ - void CreateControls() - { - Stage stage = Stage::GetCurrent(); - - //TextInput - Dali::Layer controlsLayer = Dali::Layer::New(); - controlsLayer.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - controlsLayer.SetSizeModeFactor( Vector3( 1.0f, 0.3f, 1.0f ) ); - controlsLayer.SetPosition( 0.0f, stage.GetSize().y*0.8f, 0.0f ); - controlsLayer.SetAnchorPoint( AnchorPoint::TOP_LEFT); - controlsLayer.SetParentOrigin( ParentOrigin::TOP_LEFT); - controlsLayer.TouchedSignal().Connect(this, &PathController::OnTouchGuiLayer); - stage.Add( controlsLayer ); - - Vector3 textInputSize( stage.GetSize().x, stage.GetSize().y*0.04f, 0.0f ); - Actor control0 = CreateVectorComponentControl("x:", textInputSize, &PathController::OnSliderXValueChange ); - control0.SetY( stage.GetSize().y*0.05f ); - control0.SetAnchorPoint(AnchorPoint::TOP_LEFT); - controlsLayer.Add( control0 ); - - Actor control1 = CreateVectorComponentControl("y:", textInputSize, &PathController::OnSliderYValueChange ); - control1.SetAnchorPoint(AnchorPoint::TOP_LEFT); - control1.SetParentOrigin( ParentOrigin::BOTTOM_LEFT ); - control1.SetPosition(0.0f,stage.GetSize().y*0.01,0.0f); - control0.Add( control1 ); - - Actor control2 =CreateVectorComponentControl("z:", textInputSize, &PathController::OnSliderZValueChange ); - control2.SetAnchorPoint(AnchorPoint::TOP_LEFT); - control2.SetParentOrigin( ParentOrigin::BOTTOM_LEFT ); - control2.SetPosition(0.0f,stage.GetSize().y*0.01,0.0f); - control1.Add( control2 ); - } - - /** - * Draws the path and the control points for the path - * @param[in] resolution Number of segments for the path. - */ - void DrawPath( unsigned int resolution ) - { - //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 ) - { - mContentLayer.Remove( mMeshPath ); - } - mMeshPath = Dali::MeshActor::New( mesh ); - mMeshPath.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mMeshPath.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mContentLayer.Add( mMeshPath ); - - - ////Create mesh connecting interpolation points and control points - std::vector vVertex; - std::vector vIndex; - size_t pointCount = mPath.GetPointCount(); - size_t controlPointIndex = 0; - for( size_t i(0); i0) - { - const TouchPoint& point = event.GetPoint(0); - - if(point.state==TouchPoint::Up) - { - //Stop dragging - mDragActor.Reset(); - } - else if(point.state==TouchPoint::Down) - { - Vector3 touchPoint = Vector3(event.GetPoint(0).screen.x, event.GetPoint(0).screen.y, 0.0f); - if(!mDragActor ) - { - mDragActor = GetClosestActor( touchPoint ); - if( !mDragActor && mPath.GetPointCount() < 10 ) - { - // Add new point - Vector3 lastPoint = mPath.GetPoint( mPath.GetPointCount()-1); - mPath.AddPoint( touchPoint ); - Vector3 displacement = (touchPoint-lastPoint)/8; - mPath.AddControlPoint( lastPoint + displacement ); - mPath.AddControlPoint( touchPoint - displacement); - - DrawPath( 200u ); - CreateAnimation(); - } - } - } - else if( mDragActor && point.state==TouchPoint::Motion ) - { - Vector3 touchPoint = Vector3(event.GetPoint(0).screen.x, event.GetPoint(0).screen.y, 0.0f); - std::string actorName(mDragActor.GetName()); - if( actorName.compare(0, 4, "Knot") == 0) - { - int index = actorName[4]; - mPath.GetPoint(index) = touchPoint; - } - else - { - int index = actorName[12]; - mPath.GetControlPoint(index) = touchPoint; - } - - DrawPath( 200u ); - CreateAnimation(); - } - } - - return true; - } - - bool OnTouchGuiLayer(Actor actor, const TouchEvent& event) - { - mDragActor.Reset(); - return false; - } - /** - * Callback called when user changes slider X - * @param[in] slider The slider that has generated the signal - * @param[in] value The new value - */ - bool OnSliderXValueChange( Slider s, float value) - { - if( fabs( value ) - Math::MACHINE_EPSILON_1000 < 0.0f ) - { - mForward.x = 0.0f; - } - else - { - mForward.x = value; - } - - CreateAnimation(); - return true; - } - - /** - * Callback called when user changes slider Y - * @param[in] slider The slider that has generated the signal - * @param[in] value The new value - */ - bool OnSliderYValueChange( Slider s, float value) - { - if( fabs( value ) - Math::MACHINE_EPSILON_1000 < 0.0f ) - { - mForward.y = 0.0f; - } - else - { - mForward.y = value; - } - CreateAnimation(); - return true; - } - - /** - * Callback called when user changes slider Z - * @param[in] slider The slider that has generated the signal - * @param[in] value The new value - */ - bool OnSliderZValueChange( Slider s, float value) - { - if( fabs( value ) - Math::MACHINE_EPSILON_1000 < 0.0f ) - { - mForward.z = 0.0f; - } - else - { - mForward.z = value; - } - - CreateAnimation(); - return true; - } - - /** - * 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(); - } - } - } - - /** - * 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::Control view; ///< The View instance. - Toolkit::ToolBar toolBar; ///< The View's Toolbar. - mContentLayer = DemoHelper::CreateView( mApplication, - view, - toolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - "" ); - mContentLayer.SetDrawMode( DrawMode::OVERLAY ); - - mContentLayer.TouchedSignal().Connect(this, &PathController::OnTouchLayer); - - //Title - TextLabel title = DemoHelper::CreateToolBarLabel( APPLICATION_TITLE ); - toolBar.AddControl( title, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter ); - - //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.5f, 0.0f )); - mPath.GenerateControlPoints(0.25f); - DrawPath( 200u ); - - //Actor - Image img = ResourceImage::New(ACTOR_IMAGE); - mActor = ImageActor::New( img ); - mActor.SetAnchorPoint( AnchorPoint::CENTER ); - mActor.SetSize( 100, 50, 1 ); - mContentLayer.Add( mActor ); - - CreateAnimation(); - CreateControls(); - } - -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 handlers of the path - - Actor mControlPoint[28]; ///< ImageActors represeting control points of the path - - Actor mDragActor; ///< Reference to the actor currently being dragged -}; - - -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, DALI_DEMO_THEME_PATH ); - - RunTest( application ); - - return 0; -} diff --git a/examples/point-mesh/point-mesh-example.cpp b/examples/point-mesh/point-mesh-example.cpp new file mode 100644 index 0000000..ec98259 --- /dev/null +++ b/examples/point-mesh/point-mesh-example.cpp @@ -0,0 +1,253 @@ +/* + * Copyright (c) 2015 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. + * + */ + +// EXTERNAL INCLUDES +#include +#include + +// INTERNAL INCLUDES +#include "shared/view.h" + +using namespace Dali; + +namespace +{ +const char* MATERIAL_SAMPLE( DALI_IMAGE_DIR "gallery-small-48.jpg" ); +const char* MATERIAL_SAMPLE2( DALI_IMAGE_DIR "gallery-medium-19.jpg" ); + +#define MAKE_SHADER(A)#A + +const char* VERTEX_SHADER = MAKE_SHADER( +attribute mediump vec2 aPosition; +attribute highp float aHue; +varying mediump vec2 vTexCoord; +uniform mediump mat4 uMvpMatrix; +uniform mediump vec3 uSize; +uniform mediump float uPointSize; +uniform lowp vec4 uFadeColor; +varying mediump vec3 vVertexColor; +varying mediump float vHue; + +vec3 hsv2rgb(vec3 c) +{ + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} + +void main() +{ + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); + vertexPosition.xyz *= (uSize-uPointSize); + vertexPosition = uMvpMatrix * vertexPosition; + vVertexColor = hsv2rgb( vec3( aHue, 0.7, 1.0 ) ); + vHue = aHue; + gl_PointSize = uPointSize; + gl_Position = vertexPosition; +} +); + +const char* FRAGMENT_SHADER = MAKE_SHADER( +varying mediump vec3 vVertexColor; +varying mediump float vHue; +uniform lowp vec4 uColor; +uniform sampler2D sTexture1; +uniform sampler2D sTexture2; +uniform lowp vec4 uFadeColor; + +void main() +{ + mediump vec4 texCol1 = texture2D(sTexture1, gl_PointCoord); + mediump vec4 texCol2 = texture2D(sTexture2, gl_PointCoord); + gl_FragColor = vec4(vVertexColor, 1.0) * ((texCol1*vHue) + (texCol2*(1.0-vHue))); +} +); + +Geometry CreateGeometry() +{ + // Create vertices + struct Vertex { Vector2 position; float hue; }; + + unsigned int numSides = 20; + Vertex polyhedraVertexData[numSides]; + float angle=0; + float sectorAngle = 2.0f * Math::PI / (float) numSides; + + for(unsigned int i=0; i #include -#include #include "shared/view.h" #include "radial-sweep-view.h" #include "radial-sweep-view-impl.h" @@ -70,10 +69,19 @@ private: */ RadialSweepView CreateSweepView( std::string imageName, Degree initial, Degree final ); + /** + * Start the sweep animation on the menu + */ void StartAnimation(); + /** + * Play or pause the animation when the button is clicked + */ bool OnButtonClicked( Toolkit::Button button ); + /** + * Update the state flag and change the button icon when the animation is finished + */ void OnAnimationFinished( Animation& source ); /** @@ -149,16 +157,15 @@ void RadialMenuExample::OnInit(Application& app) DemoHelper::DEFAULT_PLAY_PADDING ); - const Uint16Pair intImgSize = ResourceImage::GetImageSize(TEST_OUTER_RING_FILENAME); + const ImageDimensions intImgSize = ResourceImage::GetImageSize(TEST_OUTER_RING_FILENAME); Vector2 imgSize = Vector2( intImgSize.GetWidth(), intImgSize.GetHeight() ); Vector2 stageSize = stage.GetSize(); - float minStageDimension = std::min(stageSize.width, stageSize.height); - - if(stageSize.height <= stageSize.width) + float scale = stageSize.width / imgSize.width; + float availableHeight = stageSize.height - DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight * 2.0f; + if(availableHeight <= stageSize.width) { - minStageDimension -= DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight * 2.0f; + scale = availableHeight / imgSize.width; } - 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)); @@ -208,6 +215,7 @@ bool RadialMenuExample::OnButtonClicked( Toolkit::Button button ) case PLAYING: { mAnimation.Pause(); + mAnimationState = PAUSED; mPlayStopButton.SetBackgroundImage( mIconPlay ); } break; @@ -215,6 +223,7 @@ bool RadialMenuExample::OnButtonClicked( Toolkit::Button button ) case PAUSED: { mAnimation.Play(); + mAnimationState = PLAYING; mPlayStopButton.SetBackgroundImage( mIconStop ); } break; @@ -249,7 +258,7 @@ RadialSweepView RadialMenuExample::CreateSweepView( std::string imageName, mImageActor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); // Create the stencil - const Uint16Pair imageSize = ResourceImage::GetImageSize(imageName); + const ImageDimensions imageSize = ResourceImage::GetImageSize(imageName); float diameter = std::max(imageSize.GetWidth(), imageSize.GetHeight()); RadialSweepView radialSweepView = RadialSweepView::New(); radialSweepView.SetDiameter( diameter ); diff --git a/examples/radial-menu/radial-sweep-view-impl.cpp b/examples/radial-menu/radial-sweep-view-impl.cpp index 44ec95d..85dbc47 100644 --- a/examples/radial-menu/radial-sweep-view-impl.cpp +++ b/examples/radial-menu/radial-sweep-view-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 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. @@ -17,47 +17,56 @@ #include "radial-sweep-view-impl.h" +#include +#include + 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 - */ -void CircleSquareProjection( Vector3& position, Radian angle, float halfSide ) -{ - // 135 90 45 - // +--+--+ - // | \|/ | - // 180 +--+--+ 0 - // | /|\ | - // +--+--+ - // 225 270 315 - if( angle >= Dali::ANGLE_45 && angle < Dali::ANGLE_135 ) - { - position.x = halfSide * cosf(angle) / sinf(angle); - position.y = -halfSide; - } - else if( angle >= Dali::ANGLE_135 && angle < Dali::ANGLE_225 ) - { - position.x = -halfSide; - position.y = halfSide * sinf(angle) / cosf(angle); - } - else if( angle >= Dali::ANGLE_225 && angle < Dali::ANGLE_315 ) - { - position.x = -halfSide * cosf(angle) / sinf(angle); - position.y = halfSide; - } - else - { - position.x = halfSide; - position.y = -halfSide * sinf(angle) / cosf(angle); - } - - position.z = 0.0f; +const char* VERTEX_SHADER_PREFIX( "#define MATH_PI_2 1.570796\n#define MATH_PI_4 0.785398\n" ); + +const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( +attribute mediump float aAngleIndex;\n +attribute mediump vec2 aPosition1;\n +attribute mediump vec2 aPosition2;\n +uniform mediump mat4 uMvpMatrix;\n +uniform mediump float uStartAngle;\n +uniform mediump float uRotationAngle;\n +\n +void main()\n +{\n + float currentAngle = uStartAngle + uRotationAngle;\n + float angleInterval1 = MATH_PI_4 * aAngleIndex;\n + vec4 vertexPosition = vec4(0.0, 0.0, 0.0, 1.0);\n + if( currentAngle >= angleInterval1)\n + {\n + float angleInterval2 = angleInterval1 + MATH_PI_2;\n + float angle = currentAngle < angleInterval2 ? currentAngle : angleInterval2;\n + float delta;\n + if( mod( aAngleIndex+4.0, 4.0) < 2.0 )\n + {\n + delta = 0.5 - 0.5*cos(angle) / sin(angle);\n + }\n + else\n + {\n + delta = 0.5 + 0.5*sin(angle) / cos(angle);\n + }\n + vertexPosition.xy = mix( aPosition1, aPosition2, delta );\n + }\n + gl_Position = uMvpMatrix * vertexPosition;\n } +); + +const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( +uniform lowp vec4 uColor;\n +\n +void main()\n +{\n + gl_FragColor = uColor;\n +}\n +); float HoldZeroFastEaseInOutHoldOne(float progress) { @@ -81,58 +90,23 @@ float HoldZeroFastEaseInOutHoldOne(float progress) } } -struct SquareFanConstraint -{ - SquareFanConstraint(int sideIndex) - : mSideIndex(sideIndex) - { - } - - void operator()( Vector3& current, const PropertyInputContainer& inputs ) - { - float degree = fmodf((inputs[0]->GetFloat() + inputs[1]->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) - { - current = Vector3::ZERO; - } - else - { - if( degree >= endAngle ) - { - degree = endAngle; - } - CircleSquareProjection( current, Degree(degree), 0.5f ); - current.x = -current.x; // Inverting X makes the animation go anti clockwise from left center - } - } - - 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) ); + return New( 2.0f, 100.0f, ANGLE_0, ANGLE_0, ANGLE_0, ANGLE_360 ); } -RadialSweepView RadialSweepViewImpl::New( float duration, float diameter, Degree initialAngle, Degree finalAngle, Degree initialSector, Degree finalSector ) +RadialSweepView RadialSweepViewImpl::New( float duration, float diameter, Radian initialAngle, Radian finalAngle, Radian initialSector, Radian 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 ) +RadialSweepViewImpl::RadialSweepViewImpl( float duration, float diameter, Radian initialAngle, Radian finalAngle, Radian initialSector, Radian finalSector ) : Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ), mDuration(duration), mDiameter(diameter), @@ -165,33 +139,33 @@ void RadialSweepViewImpl::SetDiameter(float diameter) mDiameter = diameter; } -void RadialSweepViewImpl::SetInitialAngle( Dali::Degree initialAngle) +void RadialSweepViewImpl::SetInitialAngle( Dali::Radian initialAngle) { mInitialAngle = initialAngle; } -void RadialSweepViewImpl::SetFinalAngle( Dali::Degree finalAngle) +void RadialSweepViewImpl::SetFinalAngle( Dali::Radian finalAngle) { mFinalAngle = finalAngle; } -void RadialSweepViewImpl::SetInitialSector( Dali::Degree initialSector) +void RadialSweepViewImpl::SetInitialSector( Dali::Radian initialSector) { mInitialSector = initialSector; } -void RadialSweepViewImpl::SetFinalSector( Dali::Degree finalSector) +void RadialSweepViewImpl::SetFinalSector( Dali::Radian finalSector) { mFinalSector = finalSector; } -void RadialSweepViewImpl::SetInitialActorAngle( Dali::Degree initialAngle ) +void RadialSweepViewImpl::SetInitialActorAngle( Dali::Radian initialAngle ) { mInitialActorAngle = initialAngle; mRotateActors = true; } -void RadialSweepViewImpl::SetFinalActorAngle( Dali::Degree finalAngle ) +void RadialSweepViewImpl::SetFinalActorAngle( Dali::Radian finalAngle ) { mFinalActorAngle = finalAngle; mRotateActors = true; @@ -207,32 +181,32 @@ float RadialSweepViewImpl::GetDiameter( ) return mDiameter; } -Dali::Degree RadialSweepViewImpl::GetInitialAngle( ) +Dali::Radian RadialSweepViewImpl::GetInitialAngle( ) { return mInitialAngle; } -Dali::Degree RadialSweepViewImpl::GetFinalAngle( ) +Dali::Radian RadialSweepViewImpl::GetFinalAngle( ) { return mFinalAngle; } -Dali::Degree RadialSweepViewImpl::GetInitialSector( ) +Dali::Radian RadialSweepViewImpl::GetInitialSector( ) { return mInitialSector; } -Dali::Degree RadialSweepViewImpl::GetFinalSector( ) +Dali::Radian RadialSweepViewImpl::GetFinalSector( ) { return mFinalSector; } -Dali::Degree RadialSweepViewImpl::GetInitialActorAngle( ) +Dali::Radian RadialSweepViewImpl::GetInitialActorAngle( ) { return mInitialActorAngle; } -Dali::Degree RadialSweepViewImpl::GetFinalActorAngle( ) +Dali::Radian RadialSweepViewImpl::GetFinalActorAngle( ) { return mFinalActorAngle; } @@ -269,11 +243,11 @@ void RadialSweepViewImpl::Activate( Animation anim, float offsetTime, float dura { CreateStencil( mInitialSector ); mLayer.Add( mStencilActor ); - mStencilActor.SetSize(mDiameter, mDiameter); + mStencilActor.SetScale(mDiameter); } - mStencilActor.SetOrientation( Degree(mInitialAngle), Vector3::ZAXIS ); - mStencilActor.SetProperty( mRotationAngleIndex, mInitialSector.degree ); + mStencilActor.SetOrientation( mInitialAngle, Vector3::ZAXIS ); + mStencilActor.SetProperty( mRotationAngleIndex, mInitialSector.radian ); if( mRotateActors ) { @@ -287,7 +261,7 @@ void RadialSweepViewImpl::Activate( Animation anim, float offsetTime, float dura } } - anim.AnimateTo( Property( mStencilActor, mRotationAngleIndex ), mFinalSector.degree, mEasingFunction, TimePeriod( offsetTime, duration ) ); + anim.AnimateTo( Property( mStencilActor, mRotationAngleIndex ), mFinalSector.radian, mEasingFunction, TimePeriod( offsetTime, duration ) ); anim.AnimateTo( Property( mStencilActor, Actor::Property::ORIENTATION ), Quaternion( Radian( mFinalAngle ), Vector3::ZAXIS ), mEasingFunction, TimePeriod( offsetTime, duration ) ); if( mRotateActorsWithStencil ) @@ -297,7 +271,7 @@ void RadialSweepViewImpl::Activate( Animation anim, float offsetTime, float dura Actor actor = mLayer.GetChildAt(i); if( actor != mStencilActor ) { - anim.AnimateTo( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( mFinalAngle.degree - mInitialAngle.degree ) ), Vector3::ZAXIS ), mEasingFunction, TimePeriod( offsetTime, duration ) ); + anim.AnimateTo( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( mFinalAngle.radian - mInitialAngle.radian ) , Vector3::ZAXIS ), mEasingFunction, TimePeriod( offsetTime, duration ) ); } } } @@ -334,65 +308,58 @@ void RadialSweepViewImpl::Deactivate() // mMaterial.Reset(); } -void RadialSweepViewImpl::CreateStencil( Degree initialSector ) +void RadialSweepViewImpl::CreateStencil( Radian 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.degree)); - - Source srcStart( mStencilActor, mStartAngleIndex ); - Source srcRotation( mStencilActor, mRotationAngleIndex ); - - // Constrain the vertices of the square mesh to sweep out a sector as the - // rotation angle is animated. - Constraint constraint = Constraint::New( mMesh, mMesh.GetPropertyIndex(1, AnimatableVertex::Property::POSITION), SquareFanConstraint(0) ); - constraint.AddSource( srcStart ); - constraint.AddSource( srcStart ); - constraint.Apply(); - - constraint = Constraint::New( mMesh, mMesh.GetPropertyIndex(2, AnimatableVertex::Property::POSITION), SquareFanConstraint(0) ); - constraint.AddSource( srcStart ); - constraint.AddSource( srcRotation ); - constraint.Apply(); - - constraint = Constraint::New( mMesh, mMesh.GetPropertyIndex(3, AnimatableVertex::Property::POSITION), SquareFanConstraint(1) ); - constraint.AddSource( srcStart ); - constraint.AddSource( srcRotation ); - constraint.Apply(); - - constraint = Constraint::New( mMesh, mMesh.GetPropertyIndex(4, AnimatableVertex::Property::POSITION), SquareFanConstraint(2) ); - constraint.AddSource( srcStart ); - constraint.AddSource( srcRotation ); - constraint.Apply(); - - constraint = Constraint::New( mMesh, mMesh.GetPropertyIndex(5, AnimatableVertex::Property::POSITION), SquareFanConstraint(3) ); - constraint.AddSource( srcStart ); - constraint.AddSource( srcRotation ); - constraint.Apply(); - - constraint = Constraint::New( mMesh, mMesh.GetPropertyIndex(6, AnimatableVertex::Property::POSITION), SquareFanConstraint(4) ); - constraint.AddSource( srcStart ); - constraint.AddSource( srcRotation ); - constraint.Apply(); + // Create the stencil mesh geometry + // 3-----2 + // | \ / | + // | 0--1 , 6 + // | / \ | + // 4-----5 + + struct VertexPosition { float angleIndex; Vector2 position1; Vector2 position2; }; + VertexPosition vertexData[7] = { // With X coordinate inverted to make the animation go anti clockwise from left center + { 9.f, Vector2( 0.f, 0.f ), Vector2( 0.f, 0.f ) }, // center point, keep static + { 0.f, Vector2( -0.5f, 0.f ), Vector2( -0.5f, 0.f ) }, // vertex 1, 0 degree, keep static + { -1.f, Vector2( -0.5f, 0.5f ), Vector2( -0.5f, -0.5f ) }, // -45 ~ 45 degrees ( 0 ~ 45) + { 1.f, Vector2( -0.5f, -0.5f ), Vector2( 0.5f, -0.5f ) }, // 45 ~ 135 degrees + { 3.f, Vector2( 0.5f, -0.5f ), Vector2( 0.5f, 0.5f ) }, // 135 ~ 225 degrees + { 5.f, Vector2( 0.5f, 0.5f ), Vector2( -0.5f, 0.5f ) }, // 225 ~ 315 degrees + { 7.f, Vector2( -0.5f, 0.5f ), Vector2( -0.5f, -0.5f ) } // 315 ~ 405 degrees ( 315 ~ 359.999 ) + }; + Property::Map vertexFormat; + vertexFormat["aAngleIndex"] = Property::FLOAT; + vertexFormat["aPosition1"] = Property::VECTOR2; + vertexFormat["aPosition2"] = Property::VECTOR2; + PropertyBuffer vertices = PropertyBuffer::New( vertexFormat, 7u ); + vertices.SetData( vertexData ); + + unsigned int indexData[15] = { 0,1,2,0,2,3,0,3,4,0,4,5,0,5,6 }; + Property::Map indexFormat; + indexFormat["indices"] = Property::UNSIGNED_INTEGER; + PropertyBuffer indices = PropertyBuffer::New( indexFormat, 15u ); + indices.SetData( indexData ); + + Geometry meshGeometry = Geometry::New(); + meshGeometry.AddVertexBuffer( vertices ); + meshGeometry.SetIndexBuffer( indices ); + + // Create material + std::ostringstream vertexShaderStringStream; + vertexShaderStringStream< -#include -#include -#include - #include "radial-sweep-view.h" @@ -36,37 +32,37 @@ public: static RadialSweepView New( float duration, float diameter, - Dali::Degree initialAngle, - Dali::Degree finalAngle, - Dali::Degree initialSector, - Dali::Degree finalSector ); + Dali::Radian initialAngle, + Dali::Radian finalAngle, + Dali::Radian initialSector, + Dali::Radian finalSector ); RadialSweepViewImpl( float duration, float diameter, - Dali::Degree initialAngle, - Dali::Degree finalAngle, - Dali::Degree initialSector, - Dali::Degree finalSector ); + Dali::Radian initialAngle, + Dali::Radian finalAngle, + Dali::Radian initialSector, + Dali::Radian 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 ); + void SetInitialAngle( Dali::Radian initialAngle); + void SetFinalAngle( Dali::Radian finalAngle); + void SetInitialSector( Dali::Radian initialSector); + void SetFinalSector( Dali::Radian finalSector); + void SetInitialActorAngle( Dali::Radian initialAngle ); + void SetFinalActorAngle( Dali::Radian finalAngle ); float GetDuration( ); float GetDiameter( ); - Dali::Degree GetInitialAngle( ); - Dali::Degree GetFinalAngle( ); - Dali::Degree GetInitialSector( ); - Dali::Degree GetFinalSector( ); - Dali::Degree GetInitialActorAngle( ); - Dali::Degree GetFinalActorAngle( ); + Dali::Radian GetInitialAngle( ); + Dali::Radian GetFinalAngle( ); + Dali::Radian GetInitialSector( ); + Dali::Radian GetFinalSector( ); + Dali::Radian GetInitialActorAngle( ); + Dali::Radian GetFinalActorAngle( ); void RotateActorsWithStencil(bool rotate); @@ -81,23 +77,21 @@ private: /** * Create the stencil mask */ - void CreateStencil(Dali::Degree initialSector ); + void CreateStencil(Dali::Radian 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::Radian mInitialAngle; + Dali::Radian mFinalAngle; + Dali::Radian mInitialSector; + Dali::Radian mFinalSector; + Dali::Radian mInitialActorAngle; + Dali::Radian 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::Actor mStencilActor; ///< Stencil actor which generates mask Dali::Property::Index mStartAngleIndex; ///< Index of start-angle property Dali::Property::Index mRotationAngleIndex; ///< Index of rotation-angle property bool mRotateActorsWithStencil:1; diff --git a/examples/radial-menu/radial-sweep-view.cpp b/examples/radial-menu/radial-sweep-view.cpp index 6792711..46e2609 100644 --- a/examples/radial-menu/radial-sweep-view.cpp +++ b/examples/radial-menu/radial-sweep-view.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 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. @@ -18,10 +18,6 @@ #include "radial-sweep-view.h" #include "radial-sweep-view-impl.h" -// EXTERNAL INCLUDES -#include - - using namespace Dali; RadialSweepView::RadialSweepView() @@ -58,10 +54,10 @@ RadialSweepView RadialSweepView::New( ) RadialSweepView RadialSweepView::New( float duration, float diameter, - Degree initialAngle, - Degree finalAngle, - Degree initialSector, - Degree finalSector ) + Radian initialAngle, + Radian finalAngle, + Radian initialSector, + Radian finalSector ) { return RadialSweepViewImpl::New(duration, diameter, initialAngle, finalAngle, initialSector, finalSector ); } @@ -92,32 +88,32 @@ void RadialSweepView::SetDiameter(float diameter) GetImpl(*this).SetDiameter(diameter); } -void RadialSweepView::SetInitialAngle( Dali::Degree initialAngle) +void RadialSweepView::SetInitialAngle( Dali::Radian initialAngle) { GetImpl(*this).SetInitialAngle(initialAngle); } -void RadialSweepView::SetFinalAngle( Dali::Degree finalAngle) +void RadialSweepView::SetFinalAngle( Dali::Radian finalAngle) { GetImpl(*this).SetFinalAngle(finalAngle); } -void RadialSweepView::SetInitialSector( Dali::Degree initialSector) +void RadialSweepView::SetInitialSector( Dali::Radian initialSector) { GetImpl(*this).SetInitialSector(initialSector); } -void RadialSweepView::SetFinalSector( Dali::Degree finalSector) +void RadialSweepView::SetFinalSector( Dali::Radian finalSector) { GetImpl(*this).SetFinalSector(finalSector); } -void RadialSweepView::SetInitialActorAngle( Dali::Degree initialAngle ) +void RadialSweepView::SetInitialActorAngle( Dali::Radian initialAngle ) { GetImpl(*this).SetInitialActorAngle(initialAngle); } -void RadialSweepView::SetFinalActorAngle( Dali::Degree finalAngle ) +void RadialSweepView::SetFinalActorAngle( Dali::Radian finalAngle ) { GetImpl(*this).SetFinalActorAngle(finalAngle); } @@ -132,32 +128,32 @@ float RadialSweepView::GetDiameter( ) return GetImpl(*this).GetDiameter(); } -Dali::Degree RadialSweepView::GetInitialAngle( ) +Dali::Radian RadialSweepView::GetInitialAngle( ) { return GetImpl(*this).GetInitialAngle(); } -Dali::Degree RadialSweepView::GetFinalAngle( ) +Dali::Radian RadialSweepView::GetFinalAngle( ) { return GetImpl(*this).GetFinalAngle(); } -Dali::Degree RadialSweepView::GetInitialSector( ) +Dali::Radian RadialSweepView::GetInitialSector( ) { return GetImpl(*this).GetInitialSector(); } -Dali::Degree RadialSweepView::GetFinalSector( ) +Dali::Radian RadialSweepView::GetFinalSector( ) { return GetImpl(*this).GetFinalSector(); } -Dali::Degree RadialSweepView::GetInitialActorAngle( ) +Dali::Radian RadialSweepView::GetInitialActorAngle( ) { return GetImpl(*this).GetInitialActorAngle(); } -Dali::Degree RadialSweepView::GetFinalActorAngle( ) +Dali::Radian RadialSweepView::GetFinalActorAngle( ) { return GetImpl(*this).GetFinalActorAngle(); } diff --git a/examples/radial-menu/radial-sweep-view.h b/examples/radial-menu/radial-sweep-view.h index 1c70078..3abdcb0 100644 --- a/examples/radial-menu/radial-sweep-view.h +++ b/examples/radial-menu/radial-sweep-view.h @@ -2,7 +2,7 @@ #define DALI_DEMO_RADIAL_SWEEP_VIEW_H /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 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. @@ -31,7 +31,7 @@ class RadialSweepView : public Dali::Toolkit::Control public: /** * Create a new RadialSweepView with default parameters (2 second animation, - * no rotation, sweeping out a full cicle). + * no rotation, sweeping out a full circle). */ static RadialSweepView New( ); @@ -43,7 +43,7 @@ public: * @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. + * Note, to cover the entire circle, use a value of 359.9999 degrees, not zero or 360 degrees. * * initial sector * \ | . @@ -54,10 +54,10 @@ public: */ static RadialSweepView New( float duration, float diameter, - Dali::Degree initialAngle, - Dali::Degree finalAngle, - Dali::Degree initialSector, - Dali::Degree finalSector ); + Dali::Radian initialAngle, + Dali::Radian finalAngle, + Dali::Radian initialSector, + Dali::Radian finalSector ); void SetDuration(float duration); @@ -65,33 +65,33 @@ public: void SetDiameter(float diameter); - void SetInitialAngle( Dali::Degree initialAngle); + void SetInitialAngle( Dali::Radian initialAngle); - void SetFinalAngle( Dali::Degree finalAngle); + void SetFinalAngle( Dali::Radian finalAngle); - void SetInitialSector( Dali::Degree initialSector); + void SetInitialSector( Dali::Radian initialSector); - void SetFinalSector( Dali::Degree finalSector); + void SetFinalSector( Dali::Radian finalSector); - void SetInitialActorAngle( Dali::Degree initialAngle ); + void SetInitialActorAngle( Dali::Radian initialAngle ); - void SetFinalActorAngle( Dali::Degree finalAngle ); + void SetFinalActorAngle( Dali::Radian finalAngle ); float GetDuration( ); float GetDiameter( ); - Dali::Degree GetInitialAngle( ); + Dali::Radian GetInitialAngle( ); - Dali::Degree GetFinalAngle( ); + Dali::Radian GetFinalAngle( ); - Dali::Degree GetInitialSector( ); + Dali::Radian GetInitialSector( ); - Dali::Degree GetFinalSector( ); + Dali::Radian GetFinalSector( ); - Dali::Degree GetInitialActorAngle( ); + Dali::Radian GetInitialActorAngle( ); - Dali::Degree GetFinalActorAngle( ); + Dali::Radian GetFinalActorAngle( ); /** * @param[in] rotate True if the actors should rotate with the stencil diff --git a/examples/refraction-effect/refraction-effect-example.cpp b/examples/refraction-effect/refraction-effect-example.cpp index a220490..c192b52 100644 --- a/examples/refraction-effect/refraction-effect-example.cpp +++ b/examples/refraction-effect/refraction-effect-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 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. @@ -15,18 +15,18 @@ * */ +// EXTERNAL INCLUDES #include +#include #include -#include -#include -#include - -#include "shared/view.h" #include #include #include +// INTERNAL INCLUDES +#include "shared/view.h" + using namespace Dali; namespace @@ -52,8 +52,6 @@ const char* TEXTURE_IMAGES[]= }; const unsigned int NUM_TEXTURE_IMAGES( sizeof( TEXTURE_IMAGES ) / sizeof( TEXTURE_IMAGES[0] ) ); -#define MAKE_SHADER(A)#A - struct LightOffsetConstraint { LightOffsetConstraint( float radius ) @@ -86,214 +84,134 @@ ResourceImage LoadStageFillingImage( const char * const imagePath ) return ResourceImage::New( imagePath, ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); } -} // namespace - -/************************************************************************************************ - *** This shader is used when the MeshActor is not touched*** - ************************************************************************************************/ -class NoEffect : public ShaderEffect +/** + * structure of the vertex in the mesh + */ +struct Vertex { -public: - /** - * Create an empty handle. - */ - NoEffect() - { - } + Vector3 position; + Vector3 normal; + Vector2 textureCoord; - /** - * 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; - } + Vertex() + {} -private: - /** - * Helper for New() - */ - NoEffect( ShaderEffect handle ) - : ShaderEffect( handle ) - { - } + Vertex( const Vector3& position, const Vector3& normal, const Vector2& textureCoord ) + : position( position ), normal( normal ), textureCoord( textureCoord ) + {} }; -/************************************************************/ -/* 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( handle, handle.GetPropertyIndex("uLightSpinOffset"), LightOffsetConstraint(stageSize.x*0.1f) ); - constraint.AddSource( LocalSource(index) ); - constraint.Apply(); - - 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 ); - } +/************************************************************************************************ + *** The shader source is used when the MeshActor is not touched*** + ************************************************************************************************/ +const char* VERTEX_SHADER_FLAT = DALI_COMPOSE_SHADER( +attribute mediump vec3 aPosition;\n +attribute mediump vec3 aNormal;\n +attribute highp vec2 aTexCoord;\n +uniform mediump mat4 uMvpMatrix;\n +varying mediump vec2 vTexCoord;\n +void main()\n +{\n + gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 );\n + vTexCoord = aTexCoord.xy;\n +}\n +); + +const char* FRAGMENT_SHADER_FLAT = DALI_COMPOSE_SHADER( +uniform lowp vec4 uColor;\n +uniform sampler2D sTexture;\n +varying mediump vec2 vTexCoord;\n +void main()\n +{\n + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n +}\n +); + +/************************************************************ + ** Custom refraction effect shader*************************** + ************************************************************/ +const char* VERTEX_SHADER_REFRACTION = DALI_COMPOSE_SHADER( +attribute mediump vec3 aPosition;\n +attribute mediump vec3 aNormal;\n +attribute highp vec2 aTexCoord;\n +uniform mediump mat4 uMvpMatrix;\n +varying mediump vec4 vVertex;\n +varying mediump vec3 vNormal;\n +varying mediump vec2 vTexCoord;\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 +); + +const char* FRAGMENT_SHADER_REFRACTION = DALI_COMPOSE_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 +uniform lowp vec4 uColor;\n +uniform sampler2D sTexture;\n +varying mediump vec4 vVertex;\n +varying mediump vec3 vNormal;\n +varying mediump vec2 vTexCoord;\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 )\n +{\n + // 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;\n +}\n + +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 +); - void SetLightIntensity( float intensity ) - { - SetUniform( "uLightIntensity", intensity ); - } +} // namespace -private: - /** - * Helper for New() - */ - RefractionEffect( ShaderEffect handle ) - : ShaderEffect( handle ) - { - } -}; /*************************************************/ /*Demo using RefractionEffect*****************/ @@ -303,7 +221,6 @@ class RefractionEffectExample : public ConnectionTracker public: RefractionEffectExample( Application &application ) : mApplication( application ), - mIsDown( false ), mCurrentTextureId( 1 ), mCurrentMeshId( 0 ) { @@ -321,7 +238,7 @@ private: void Create(Application& application) { Stage stage = Stage::GetCurrent(); - mStageHalfSize = stage.GetSize() * 0.5f; + Vector2 stageSize = stage.GetSize(); stage.KeyEventSignal().Connect(this, &RefractionEffectExample::OnKeyEvent); @@ -353,37 +270,68 @@ private: 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( LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] ) ); - CreateSurface( MESH_FILES[mCurrentMeshId] ); + + + // shader used when the screen is not touched, render a flat surface + mShaderFlat = Shader::New( VERTEX_SHADER_FLAT, FRAGMENT_SHADER_FLAT ); + mGeometry = CreateGeometry( MESH_FILES[mCurrentMeshId] ); + + Image texture = LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] ); + mSampler = Sampler::New( texture, "sTexture" ); + mMaterial = Material::New( mShaderFlat ); + mMaterial.AddSampler( mSampler ); + + mRenderer = Renderer::New( mGeometry, mMaterial ); + + mMeshActor = Actor::New(); + mMeshActor.AddRenderer( mRenderer ); + mMeshActor.SetSize( stageSize ); + mMeshActor.SetParentOrigin(ParentOrigin::CENTER); + mContent.Add( mMeshActor ); // Connect the callback to the touch signal on the mesh actor mContent.TouchedSignal().Connect( this, &RefractionEffectExample::OnTouch ); + // shader used when the finger is touching the screen. render refraction effect + mShaderRefraction = Shader::New( VERTEX_SHADER_REFRACTION, FRAGMENT_SHADER_REFRACTION ); + + // register uniforms + mLightXYOffsetIndex = mMeshActor.RegisterProperty( "uLightXYOffset", Vector2::ZERO ); + + mLightIntensityIndex = mMeshActor.RegisterProperty( "uLightIntensity", 2.5f ); + + mEffectStrengthIndex = mMeshActor.RegisterProperty( "uEffectStrength", 0.f ); + + Vector3 lightPosition( -stageSize.x*0.5f, -stageSize.y*0.5f, stageSize.x*0.5f ); // top_left + mMeshActor.RegisterProperty( "uLightPosition", lightPosition ); + + Property::Index lightSpinOffsetIndex = mMeshActor.RegisterProperty( "uLightSpinOffset", Vector2::ZERO ); + + mSpinAngleIndex = mMeshActor.RegisterProperty("uSpinAngle", 0.f ); + Constraint constraint = Constraint::New( mMeshActor, lightSpinOffsetIndex, LightOffsetConstraint(stageSize.x*0.1f) ); + constraint.AddSource( LocalSource(mSpinAngleIndex) ); + constraint.Apply(); + // 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.AnimateTo( Property( mMeshActor, mSpinAngleIndex ), Math::PI*2.f ); mLightAnimation.SetLooping( true ); mLightAnimation.Pause(); } + void SetLightXYOffset( const Vector2& offset ) + { + mMeshActor.SetProperty( mLightXYOffsetIndex, offset ); + } + /** * 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] ); + mGeometry = CreateGeometry( MESH_FILES[mCurrentMeshId] ); + mRenderer.SetGeometry( mGeometry ); return true; } @@ -391,21 +339,21 @@ private: bool OnChangeTexture( Toolkit::Button button ) { mCurrentTextureId = ( mCurrentTextureId + 1 ) % NUM_TEXTURE_IMAGES; - mMaterial.SetDiffuseTexture( LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] ) ); - + Image texture = LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] ); + mSampler.SetImage( texture ); 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; + mMaterial.SetShader( mShaderRefraction ); + + SetLightXYOffset( point.screen ); mLightAnimation.Play(); @@ -414,42 +362,32 @@ private: mStrenghAnimation.Clear(); } - mRefractionEffect.SetLightXYOffset( point.screen - mLightPosition ); - mMeshActor.SetShaderEffect( mRefractionEffect ); mStrenghAnimation= Animation::New(0.5f); - mStrenghAnimation.AnimateTo( Property( mRefractionEffect, "uEffectStrength" ), 1.f ); + mStrenghAnimation.AnimateTo( Property( mMeshActor, mEffectStrengthIndex ), 1.f ); mStrenghAnimation.Play(); break; } case TouchPoint::Motion: { - if(mIsDown) - { - // make the light position following the finger movement - mRefractionEffect.SetLightXYOffset( point.screen - mLightPosition ); - } + // make the light position following the finger movement + SetLightXYOffset( point.screen ); break; } case TouchPoint::Up: case TouchPoint::Leave: case TouchPoint::Interrupted: { - if(mIsDown) - { - mLightAnimation.Pause(); + 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(); + if( mStrenghAnimation ) + { + mStrenghAnimation.Clear(); } - - mIsDown = false; + mStrenghAnimation = Animation::New(0.5f); + mStrenghAnimation.AnimateTo( Property( mMeshActor, mEffectStrengthIndex ), 0.f ); + mStrenghAnimation.FinishedSignal().Connect( this, &RefractionEffectExample::OnTouchFinished ); + mStrenghAnimation.Play(); break; } case TouchPoint::Stationary: @@ -459,24 +397,21 @@ private: break; } } + return true; } void OnTouchFinished( Animation& source ) { - mMeshActor.SetShaderEffect( mNoEffect ); - mRefractionEffect.SetLightXYOffset( Vector2::ZERO ); + mMaterial.SetShader( mShaderFlat ); + SetLightXYOffset( Vector2::ZERO ); } - void CreateSurface( const std::string& objFileName ) + Geometry CreateGeometry(const std::string& objFileName) { - MeshData::VertexContainer vertices; - MeshData::FaceIndices faces; - MeshData meshData; - - std::vector boundingBox; std::vector vertexPositions; - std::vector faceIndices; + Vector faceIndices; + Vector boundingBox; // read the vertice and faces from the .obj file, and record the bounding box ReadObjFile( objFileName, boundingBox, vertexPositions, faceIndices ); @@ -486,53 +421,55 @@ private: // 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 vertices; + + std::size_t size = faceIndices.Size(); + vertices.reserve( size ); + + for( std::size_t i=0; i 0 ) { - faces.push_back( i ); - faces.push_back( i+1 ); - faces.push_back( i+2 ); + vertices.push_back( Vertex( vertexPositions[ faceIndices[i] ], normal, textureCoordinates[ faceIndices[i] ] ) ); + vertices.push_back( Vertex( vertexPositions[ faceIndices[i+1] ], normal, textureCoordinates[ faceIndices[i+1] ] ) ); + vertices.push_back( Vertex( vertexPositions[ faceIndices[i+2] ], normal, textureCoordinates[ faceIndices[i+2] ] ) ); } else { normal *= -1.f; - faces.push_back( i ); - faces.push_back( i+2 ); - faces.push_back( i+1 ); + vertices.push_back( Vertex( vertexPositions[ faceIndices[i] ], normal, textureCoordinates[ faceIndices[i] ] ) ); + vertices.push_back( Vertex( vertexPositions[ faceIndices[i+2] ], normal, textureCoordinates[ faceIndices[i+2] ] ) ); + vertices.push_back( Vertex( vertexPositions[ faceIndices[i+1] ], normal, textureCoordinates[ faceIndices[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 ) ); + Property::Map vertexFormat; + vertexFormat["aPosition"] = Property::VECTOR3; + vertexFormat["aNormal"] = Property::VECTOR3; + vertexFormat["aTexCoord"] = Property::VECTOR2; + PropertyBuffer surfaceVertices = PropertyBuffer::New( vertexFormat, vertices.size() ); + surfaceVertices.SetData( &vertices[0] ); - } + Geometry surface = Geometry::New(); + surface.AddVertexBuffer( surfaceVertices ); - // 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 ); + return surface; } void ReadObjFile( const std::string& objFileName, - std::vector& boundingBox, + Vector& boundingBox, std::vector& vertexPositions, - std::vector& faceIndices) + Vector& faceIndices) { std::ifstream ifs( objFileName.c_str(), std::ios::in ); - boundingBox.resize( 6 ); + boundingBox.Resize( 6 ); boundingBox[0]=boundingBox[2]=boundingBox[4] = std::numeric_limits::max(); boundingBox[1]=boundingBox[3]=boundingBox[5] = -std::numeric_limits::max(); @@ -568,20 +505,20 @@ private: } std::istringstream iss(line.substr(2), std::istringstream::in); - int indices[ numOfInt ]; + unsigned 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 ); + faceIndices.PushBack( indices[0]-1 ); + faceIndices.PushBack( indices[step]-1 ); + faceIndices.PushBack( indices[2*step]-1 ); } } ifs.close(); } - void ShapeResizeAndTexureCoordinateCalculation( const std::vector& boundingBox, + void ShapeResizeAndTexureCoordinateCalculation( const Vector& boundingBox, std::vector& vertexPositions, std::vector& textureCoordinates) { @@ -592,12 +529,13 @@ private: Vector3 scale( stageSize.x / bBoxSize.x, stageSize.y / bBoxSize.y, 1.f ); scale.z = (scale.x + scale.y)/2.f; + textureCoordinates.reserve(vertexPositions.size()); + for( std::vector::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 ); + textureCoordinates.push_back( Vector2( newPosition.x / bBoxSize.x, newPosition.y / bBoxSize.y ) ); newPosition -= bBoxSize * 0.5f; (*iter) = newPosition * scale; @@ -623,18 +561,22 @@ private: Application& mApplication; Layer mContent; - bool mIsDown; - Vector2 mDownPosition; - Vector2 mLightPosition; - Vector2 mStageHalfSize; - + Sampler mSampler; Material mMaterial; - MeshActor mMeshActor; + Geometry mGeometry; + Renderer mRenderer; + Actor mMeshActor; + + Shader mShaderFlat; + Shader mShaderRefraction; + + Animation mLightAnimation; + Animation mStrenghAnimation; - RefractionEffect mRefractionEffect; - NoEffect mNoEffect; - Animation mLightAnimation; - Animation mStrenghAnimation; + Property::Index mLightXYOffsetIndex; + Property::Index mSpinAngleIndex; + Property::Index mLightIntensityIndex; + Property::Index mEffectStrengthIndex; Toolkit::PushButton mChangeTextureButton; Toolkit::PushButton mChangeMeshButton; diff --git a/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp b/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp index 49e6142..7aad0c3 100644 --- a/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp +++ b/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp @@ -167,6 +167,7 @@ public: // Setup mView.SetPosition(Vector3(0.0f, 0.0f, -50)); + mContents.SetBehavior(Layer::LAYER_3D); mContents.SetPosition(mTranslation); mContents.SetOrientation( CalculateWorldRotation( mSceneXRotation, mSceneYRotation ) ); mContents.SetScale(mPinchScale, mPinchScale, mPinchScale); diff --git a/examples/textured-mesh/textured-mesh-example.cpp b/examples/textured-mesh/textured-mesh-example.cpp new file mode 100644 index 0000000..04b3e7b --- /dev/null +++ b/examples/textured-mesh/textured-mesh-example.cpp @@ -0,0 +1,299 @@ +/* + * 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. + * + */ + +// EXTERNAL INCLUDES +#include +#include + +// INTERNAL INCLUDES +#include "shared/view.h" + +using namespace Dali; + +namespace +{ +const char* MATERIAL_SAMPLE( DALI_IMAGE_DIR "gallery-small-48.jpg" ); +const char* MATERIAL_SAMPLE2( DALI_IMAGE_DIR "gallery-medium-19.jpg" ); + +#define MAKE_SHADER(A)#A + +const char* VERTEX_SHADER = MAKE_SHADER( +attribute mediump vec2 aPosition; +attribute highp vec2 aTexCoord; +varying mediump vec2 vTexCoord; +uniform mediump mat4 uMvpMatrix; +uniform mediump vec3 uSize; +uniform lowp vec4 uFadeColor; + +void main() +{ + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); + vertexPosition.xyz *= uSize; + vertexPosition = uMvpMatrix * vertexPosition; + vTexCoord = aTexCoord; + gl_Position = vertexPosition; +} +); + +const char* FRAGMENT_SHADER = MAKE_SHADER( +varying mediump vec2 vTexCoord; +uniform lowp vec4 uColor; +uniform sampler2D sTexture; +uniform lowp vec4 uFadeColor; + +void main() +{ + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * uFadeColor; +} +); + +Geometry CreateGeometry() +{ + // Create vertices + const float halfQuadSize = .5f; + struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; + TexturedQuadVertex texturedQuadVertexData[4] = { + { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) }, + { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) }, + { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) }, + { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } }; + + Property::Map texturedQuadVertexFormat; + texturedQuadVertexFormat["aPosition"] = Property::VECTOR2; + texturedQuadVertexFormat["aTexCoord"] = Property::VECTOR2; + PropertyBuffer texturedQuadVertices = PropertyBuffer::New( texturedQuadVertexFormat, 4 ); + texturedQuadVertices.SetData(texturedQuadVertexData); + + // Create indices + unsigned int indexData[6] = { 0, 3, 1, 0, 2, 3 }; + Property::Map indexFormat; + indexFormat["indices"] = Property::UNSIGNED_INTEGER; + PropertyBuffer indices = PropertyBuffer::New( indexFormat, sizeof(indexData)/sizeof(indexData[0]) ); + indices.SetData(indexData); + + // Create the geometry object + Geometry texturedQuadGeometry = Geometry::New(); + texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices ); + texturedQuadGeometry.SetIndexBuffer( indices ); + + return texturedQuadGeometry; +} + +/** + * Sinusoidal curve starting at zero with 2 cycles + */ +float AlphaFunctionSineX2(float progress) +{ + return 0.5f - cosf(progress * 4.0f * Math::PI) * 0.5f; +} + +} // anonymous namespace + +// This example shows how to use a simple mesh +// +class ExampleController : public ConnectionTracker +{ +public: + + /** + * The example controller constructor. + * @param[in] application The application instance + */ + ExampleController( Application& application ) + : mApplication( application ) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect( this, &ExampleController::Create ); + } + + /** + * The example controller destructor + */ + ~ExampleController() + { + // Nothing to do here; + } + + /** + * Invoked upon creation of application + * @param[in] application The application instance + */ + void Create( Application& application ) + { + // The Init signal is received once (only) during the Application lifetime + + Stage stage = Stage::GetCurrent(); + stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); + + mStageSize = stage.GetSize(); + + // Hide the indicator bar + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); + + mImage = ResourceImage::New( MATERIAL_SAMPLE, ResourceImage::ON_DEMAND, Image::NEVER ); + mSampler1 = Sampler::New(mImage, "sTexture"); + + Image image = ResourceImage::New( MATERIAL_SAMPLE2 ); + mSampler2 = Sampler::New(image, "sTexture"); + + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mMaterial1 = Material::New( mShader ); + mMaterial1.AddSampler( mSampler1 ); + + mMaterial2 = Material::New( mShader ); + mMaterial2.AddSampler( mSampler2 ); + + mGeometry = CreateGeometry(); + + mRenderer = Renderer::New( mGeometry, mMaterial1 ); + + mMeshActor = Actor::New(); + mMeshActor.AddRenderer( mRenderer ); + mMeshActor.SetSize(400, 400); + + Property::Index fadeColorIndex = mMeshActor.RegisterProperty( "uFadeColor", Color::GREEN ); + + fadeColorIndex = mRenderer.RegisterProperty( "uFadeColor", Color::MAGENTA ); + mRenderer.SetDepthIndex(0); + + mMeshActor.SetParentOrigin( ParentOrigin::TOP_CENTER ); + mMeshActor.SetAnchorPoint( AnchorPoint::TOP_CENTER ); + stage.Add( mMeshActor ); + + mRenderer2 = Renderer::New( mGeometry, mMaterial2 ); + + mMeshActor2 = Actor::New(); + mMeshActor2.AddRenderer( mRenderer2 ); + mMeshActor2.SetSize(400, 400); + + mMeshActor2.RegisterProperty( "a-n-other-property", Color::GREEN ); + Property::Index fadeColorIndex2 = mMeshActor2.RegisterProperty( "uFadeColor", Color::GREEN ); + + mRenderer2.RegisterProperty( "a-n-other-property", Vector3::ZERO ); + mRenderer2.RegisterProperty( "a-coefficient", 0.008f ); + fadeColorIndex2 = mRenderer2.RegisterProperty( "uFadeColor", Color::BLUE ); + mRenderer2.SetDepthIndex(0); + + mMeshActor2.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); + mMeshActor2.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + stage.Add( mMeshActor2 ); + + Animation animation = Animation::New(5); + KeyFrames keyFrames = KeyFrames::New(); + keyFrames.Add(0.0f, Vector4::ZERO); + keyFrames.Add(1.0f, Vector4( Color::GREEN )); + + KeyFrames keyFrames2 = KeyFrames::New(); + keyFrames2.Add(0.0f, Vector4::ZERO); + keyFrames2.Add(1.0f, Color::MAGENTA); + + animation.AnimateBetween( Property( mRenderer, fadeColorIndex ), keyFrames, AlphaFunction(AlphaFunction::SIN) ); + animation.AnimateBetween( Property( mRenderer2, fadeColorIndex2 ), keyFrames2, AlphaFunction(AlphaFunctionSineX2) ); + animation.SetLooping(true); + animation.Play(); + + stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));; + } + + BufferImage CreateBufferImage() + { + BufferImage image = BufferImage::New( 200, 200, Pixel::RGB888 ); + PixelBuffer* pixelBuffer = image.GetBuffer(); + unsigned int stride = image.GetBufferStride(); + for( unsigned int x=0; x<200; x++ ) + { + for( unsigned int y=0; y<200; y++ ) + { + PixelBuffer* pixel = pixelBuffer + y*stride + x*3; + if( ((int)(x/20.0f))%2 + ((int)(y/20.0f)%2) == 1 ) + { + pixel[0]=255; + pixel[1]=0; + pixel[2]=0; + pixel[3]=255; + } + else + { + pixel[0]=0; + pixel[1]=0; + pixel[2]=255; + pixel[3]=255; + } + } + } + image.Update(); + return image; + } + + /** + * Invoked whenever the quit button is clicked + * @param[in] button the quit button + */ + bool OnQuitButtonClicked( Toolkit::Button button ) + { + // quit the application + mApplication.Quit(); + return true; + } + + 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; ///< Application instance + Vector3 mStageSize; ///< The size of the stage + + Image mImage; + Sampler mSampler1; + Sampler mSampler2; + Shader mShader; + Material mMaterial1; + Material mMaterial2; + Geometry mGeometry; + Renderer mRenderer; + Actor mMeshActor; + Renderer mRenderer2; + Actor mMeshActor2; + Timer mChangeImageTimer; +}; + +void RunTest( Application& application ) +{ + ExampleController test( application ); + + application.MainLoop(); +} + +// Entry point for Linux & SLP applications +// +int main( int argc, char **argv ) +{ + Application application = Application::New( &argc, &argv ); + + RunTest( application ); + + return 0; +} diff --git a/shared/dali-demo-strings.h b/shared/dali-demo-strings.h index af8ace8..d6b01a9 100644 --- a/shared/dali-demo-strings.h +++ b/shared/dali-demo-strings.h @@ -53,11 +53,13 @@ extern "C" #define DALI_DEMO_STR_TITLE_TEXT_LABEL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL") #define DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE") #define DALI_DEMO_STR_TITLE_EMOJI_TEXT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_EMOJI_TEXT") -#define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES dgettext(DALI_DEMO_STR_TITLE_ANIMATED_SHAPES) -#define DALI_DEMO_STR_TITLE_PATH_ANIMATION dgettext(DALI_DEMO_STR_TITLE_PATH_ANIMATION) #define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE dgettext(DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE) #define DALI_DEMO_STR_TITLE_BUTTONS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BUTTONS") #define DALI_DEMO_STR_TITLE_LOGGING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_LOGGING") +#define DALI_DEMO_STR_TITLE_MESH_MORPH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_MESH_MORPH") +#define DALI_DEMO_STR_TITLE_MESH_SORTING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_MESH_SORTING") +#define DALI_DEMO_STR_TITLE_TEXTURED_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TEXTURED_MESH") +#define DALI_DEMO_STR_TITLE_LINE_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_LINE_MESH") #else // !INTERNATIONALIZATION_ENABLED @@ -82,11 +84,13 @@ extern "C" #define DALI_DEMO_STR_TITLE_TEXT_LABEL "Text Label" #define DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE "Text Scripts" #define DALI_DEMO_STR_TITLE_EMOJI_TEXT "Emoji Text" -#define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES "Animated Shapes" -#define DALI_DEMO_STR_TITLE_PATH_ANIMATION "Animated Path" #define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE "Negotiate Size" #define DALI_DEMO_STR_TITLE_BUTTONS "Buttons" #define DALI_DEMO_STR_TITLE_LOGGING "Logging" +#define DALI_DEMO_STR_TITLE_MESH_MORPH "Mesh Morph" +#define DALI_DEMO_STR_TITLE_MESH_SORTING "Mesh Sorting" +#define DALI_DEMO_STR_TITLE_TEXTURED_MESH "Mesh Texture" +#define DALI_DEMO_STR_TITLE_LINE_MESH "Mesh Line" #endif diff --git a/shared/view.h b/shared/view.h index dcf8e9a..d417b6f 100644 --- a/shared/view.h +++ b/shared/view.h @@ -26,6 +26,13 @@ namespace DemoHelper { +enum ControlDepthIndexRanges +{ + BACKGROUND_DEPTH_INDEX = -10000000, + CONTENT_DEPTH_INDEX = 0, + DECORATION_DEPTH_INDEX = 10000000 +}; + /** * Provide a style for the view and its tool bar. */ @@ -94,7 +101,6 @@ Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar, { Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New(); label.SetAnchorPoint( Dali::AnchorPoint::TOP_LEFT ); - label.SetDrawMode( Dali::DrawMode::OVERLAY ); label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" ); label.SetProperty( Dali::Toolkit::TextLabel::Property::TEXT, title ); label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); @@ -160,7 +166,6 @@ Dali::Toolkit::TextLabel CreateToolBarLabel( const std::string& text ) { Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New( text ); label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" ); - label.SetDrawMode( Dali::DrawMode::OVERLAY ); label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); label.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT );