Commit 8d10a2d0f9e9adb56a41a258c73a818eca4f0b4e
Merge branch 'devel/new_mesh' into devel/master
Change-Id: I84faa5b88e6cca8f606c5f32d8fb5e18ce0ce27c
Showing
26 changed files
with
2358 additions
and
1700 deletions
demo/dali-demo.cpp
| @@ -57,11 +57,13 @@ int main(int argc, char **argv) | @@ -57,11 +57,13 @@ int main(int argc, char **argv) | ||
| 57 | demo.AddExample(Example("text-label.example", DALI_DEMO_STR_TITLE_TEXT_LABEL)); | 57 | demo.AddExample(Example("text-label.example", DALI_DEMO_STR_TITLE_TEXT_LABEL)); |
| 58 | demo.AddExample(Example("text-label-multi-language.example", DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE)); | 58 | demo.AddExample(Example("text-label-multi-language.example", DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE)); |
| 59 | demo.AddExample(Example("text-label-emojis.example", DALI_DEMO_STR_TITLE_EMOJI_TEXT)); | 59 | demo.AddExample(Example("text-label-emojis.example", DALI_DEMO_STR_TITLE_EMOJI_TEXT)); |
| 60 | - demo.AddExample(Example("animated-shapes.example", DALI_DEMO_STR_TITLE_ANIMATED_SHAPES)); | ||
| 61 | - demo.AddExample(Example("path-animation.example", DALI_DEMO_STR_TITLE_PATH_ANIMATION)); | ||
| 62 | demo.AddExample(Example("size-negotiation.example", DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE)); | 60 | demo.AddExample(Example("size-negotiation.example", DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE)); |
| 63 | demo.AddExample(Example("buttons.example", DALI_DEMO_STR_TITLE_BUTTONS)); | 61 | demo.AddExample(Example("buttons.example", DALI_DEMO_STR_TITLE_BUTTONS)); |
| 64 | demo.AddExample(Example("logging.example", DALI_DEMO_STR_TITLE_LOGGING)); | 62 | demo.AddExample(Example("logging.example", DALI_DEMO_STR_TITLE_LOGGING)); |
| 63 | + demo.AddExample(Example("mesh-morph.example", DALI_DEMO_STR_TITLE_MESH_MORPH)); | ||
| 64 | + demo.AddExample(Example("mesh-sorting.example", DALI_DEMO_STR_TITLE_MESH_SORTING)); | ||
| 65 | + demo.AddExample(Example("textured-mesh.example", DALI_DEMO_STR_TITLE_TEXTURED_MESH)); | ||
| 66 | + demo.AddExample(Example("line-mesh.example", DALI_DEMO_STR_TITLE_LINE_MESH)); | ||
| 65 | 67 | ||
| 66 | demo.SortAlphabetically( true ); | 68 | demo.SortAlphabetically( true ); |
| 67 | 69 |
demo/dali-table-view.cpp
| @@ -268,9 +268,11 @@ void DaliTableView::Initialize( Application& application ) | @@ -268,9 +268,11 @@ void DaliTableView::Initialize( Application& application ) | ||
| 268 | mScrollView.TouchedSignal().Connect( this, &DaliTableView::OnScrollTouched ); | 268 | mScrollView.TouchedSignal().Connect( this, &DaliTableView::OnScrollTouched ); |
| 269 | 269 | ||
| 270 | mScrollViewLayer = Layer::New(); | 270 | mScrollViewLayer = Layer::New(); |
| 271 | + | ||
| 272 | + // Disable the depth test for performance | ||
| 273 | + mScrollViewLayer.SetDepthTestDisabled( true ); | ||
| 271 | mScrollViewLayer.SetAnchorPoint( AnchorPoint::CENTER ); | 274 | mScrollViewLayer.SetAnchorPoint( AnchorPoint::CENTER ); |
| 272 | mScrollViewLayer.SetParentOrigin( ParentOrigin::CENTER ); | 275 | mScrollViewLayer.SetParentOrigin( ParentOrigin::CENTER ); |
| 273 | - mScrollViewLayer.SetDrawMode( DrawMode::OVERLAY ); | ||
| 274 | mScrollViewLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); | 276 | mScrollViewLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); |
| 275 | 277 | ||
| 276 | // Create solid background colour. | 278 | // Create solid background colour. |
| @@ -279,7 +281,9 @@ void DaliTableView::Initialize( Application& application ) | @@ -279,7 +281,9 @@ void DaliTableView::Initialize( Application& application ) | ||
| 279 | backgroundColourActor.SetParentOrigin( ParentOrigin::CENTER ); | 281 | backgroundColourActor.SetParentOrigin( ParentOrigin::CENTER ); |
| 280 | backgroundColourActor.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); | 282 | backgroundColourActor.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); |
| 281 | backgroundColourActor.SetSizeModeFactor( Vector3( 1.0f, 1.5f, 1.0f ) ); | 283 | backgroundColourActor.SetSizeModeFactor( Vector3( 1.0f, 1.5f, 1.0f ) ); |
| 282 | - backgroundColourActor.SetZ( BACKGROUND_Z ); | 284 | + |
| 285 | + // Force the filled background right to the back | ||
| 286 | + backgroundColourActor.SetSortModifier( DemoHelper::BACKGROUND_DEPTH_INDEX ); | ||
| 283 | mScrollViewLayer.Add( backgroundColourActor ); | 287 | mScrollViewLayer.Add( backgroundColourActor ); |
| 284 | 288 | ||
| 285 | // Populate background and bubbles - needs to be scrollViewLayer so scroll ends show | 289 | // Populate background and bubbles - needs to be scrollViewLayer so scroll ends show |
| @@ -526,7 +530,7 @@ ImageActor DaliTableView::NewStencilImage() | @@ -526,7 +530,7 @@ ImageActor DaliTableView::NewStencilImage() | ||
| 526 | stencilActor.SetAnchorPoint( AnchorPoint::CENTER ); | 530 | stencilActor.SetAnchorPoint( AnchorPoint::CENTER ); |
| 527 | stencilActor.SetDrawMode( DrawMode::STENCIL ); | 531 | stencilActor.SetDrawMode( DrawMode::STENCIL ); |
| 528 | 532 | ||
| 529 | - Dali::ShaderEffect shaderEffect = AlphaDiscardEffect::New(); | 533 | + Dali::ShaderEffect shaderEffect = CreateAlphaDiscardEffect(); |
| 530 | stencilActor.SetShaderEffect( shaderEffect ); | 534 | stencilActor.SetShaderEffect( shaderEffect ); |
| 531 | 535 | ||
| 532 | return stencilActor; | 536 | return stencilActor; |
| @@ -764,11 +768,14 @@ void DaliTableView::AddBackgroundActors( Actor layer, int count, BufferImage dis | @@ -764,11 +768,14 @@ void DaliTableView::AddBackgroundActors( Actor layer, int count, BufferImage dis | ||
| 764 | dfActor.SetSize( Vector2( randSize, randSize ) ); | 768 | dfActor.SetSize( Vector2( randSize, randSize ) ); |
| 765 | dfActor.SetParentOrigin( ParentOrigin::CENTER ); | 769 | dfActor.SetParentOrigin( ParentOrigin::CENTER ); |
| 766 | 770 | ||
| 767 | - Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New(); | 771 | + // Force the bubbles just in front of the solid background |
| 772 | + dfActor.SetSortModifier( DemoHelper::BACKGROUND_DEPTH_INDEX + 1 ); | ||
| 773 | + | ||
| 774 | + ShaderEffect effect = Toolkit::CreateDistanceFieldEffect(); | ||
| 768 | dfActor.SetShaderEffect( effect ); | 775 | dfActor.SetShaderEffect( effect ); |
| 769 | dfActor.SetColor( randColour ); | 776 | dfActor.SetColor( randColour ); |
| 770 | - effect.SetOutlineParams( Vector2( 0.55f, 0.00f ) ); | ||
| 771 | - effect.SetSmoothingEdge( 0.5f ); | 777 | + effect.SetUniform("uOutlineParams", Vector2( 0.55f, 0.00f ) ); |
| 778 | + effect.SetUniform("uSmoothing", 0.5f ); | ||
| 772 | layer.Add( dfActor ); | 779 | layer.Add( dfActor ); |
| 773 | } | 780 | } |
| 774 | 781 |
examples/animated-shapes/animated-shapes-example.cpp deleted
| 1 | -/* | ||
| 2 | - * Copyright (c) 2014 Samsung Electronics Co., Ltd. | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - * | ||
| 16 | - */ | ||
| 17 | - | ||
| 18 | -#include <dali/dali.h> | ||
| 19 | -#include <dali-toolkit/dali-toolkit.h> | ||
| 20 | -#include <dali/devel-api/actors/mesh-actor.h> | ||
| 21 | -#include <dali/devel-api/geometry/mesh.h> | ||
| 22 | -#include <dali-toolkit/devel-api/shader-effects/quadratic-bezier.h> | ||
| 23 | - | ||
| 24 | -#include "shared/view.h" | ||
| 25 | - | ||
| 26 | -using namespace Dali; | ||
| 27 | - | ||
| 28 | -namespace | ||
| 29 | -{ | ||
| 30 | -const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-gradient.jpg" ); | ||
| 31 | - | ||
| 32 | -} | ||
| 33 | - | ||
| 34 | -// This example shows resolution independent rendering and animation of curves using the gpu. | ||
| 35 | -// | ||
| 36 | -class AnimatedShapesExample : public ConnectionTracker | ||
| 37 | -{ | ||
| 38 | -public: | ||
| 39 | - | ||
| 40 | - AnimatedShapesExample( Application& application ) | ||
| 41 | -: mApplication( application ) | ||
| 42 | -{ | ||
| 43 | - // Connect to the Application's Init signal | ||
| 44 | - mApplication.InitSignal().Connect( this, &AnimatedShapesExample::Create ); | ||
| 45 | -} | ||
| 46 | - | ||
| 47 | - ~AnimatedShapesExample() | ||
| 48 | - { | ||
| 49 | - // Nothing to do here; | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - // The Init signal is received once (only) during the Application lifetime | ||
| 53 | - void Create( Application& application ) | ||
| 54 | - { | ||
| 55 | - // Get a handle to the stage | ||
| 56 | - Stage stage = Stage::GetCurrent(); | ||
| 57 | - | ||
| 58 | - // Create a view | ||
| 59 | - mView = Dali::Toolkit::Control::New(); | ||
| 60 | - mView.SetAnchorPoint( Dali::AnchorPoint::CENTER ); | ||
| 61 | - mView.SetParentOrigin( Dali::ParentOrigin::CENTER ); | ||
| 62 | - mView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); | ||
| 63 | - mView.SetDrawMode( DrawMode::OVERLAY ); | ||
| 64 | - stage.Add( mView ); | ||
| 65 | - | ||
| 66 | - //Set background image for the view | ||
| 67 | - mView.SetBackgroundImage( ResourceImage::New( BACKGROUND_IMAGE ) ); | ||
| 68 | - | ||
| 69 | - CreateTriangleMorph(Vector3( stage.GetSize().x*0.5f,stage.GetSize().y*0.15f,0.0f), 100.0f ); | ||
| 70 | - CreateCircleMorph( Vector3( stage.GetSize().x*0.5f,stage.GetSize().y*0.85f,0.0f), 60.0f ); | ||
| 71 | - CreatePathMorph( Vector3( stage.GetSize().x*0.5f,stage.GetSize().y*0.5f,0.0f), 55.0f ); | ||
| 72 | - | ||
| 73 | - | ||
| 74 | - stage.KeyEventSignal().Connect(this, &AnimatedShapesExample::OnKeyEvent); | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | - void CreateCircleMorph( Vector3 center, float radius ) | ||
| 78 | - { | ||
| 79 | - Toolkit::QuadraticBezier shader = Toolkit::QuadraticBezier::New(16, true); | ||
| 80 | - | ||
| 81 | - shader.SetPoint(0, Vector3(-radius,-radius,0.0f)); | ||
| 82 | - shader.SetPoint(1, Vector3( 0.0f,-radius,0.0f)); | ||
| 83 | - shader.SetPoint(2, Vector3(radius,-radius,0.0f)); | ||
| 84 | - | ||
| 85 | - shader.SetPoint(3, Vector3(radius,-radius,0.0f)); | ||
| 86 | - shader.SetPoint(4, Vector3( radius,0.0f,0.0f)); | ||
| 87 | - shader.SetPoint(5, Vector3(radius,radius,0.0f)); | ||
| 88 | - | ||
| 89 | - shader.SetPoint(6, Vector3(radius,radius,0.0f)); | ||
| 90 | - shader.SetPoint(7, Vector3( 0.0f,radius,0.0f)); | ||
| 91 | - shader.SetPoint(8, Vector3( -radius,radius,0.0f)); | ||
| 92 | - | ||
| 93 | - shader.SetPoint(9, Vector3( -radius,radius,0.0f)); | ||
| 94 | - shader.SetPoint(10, Vector3( -radius,0.0f,0.0f)); | ||
| 95 | - shader.SetPoint(11, Vector3(-radius,-radius,0.0f)); | ||
| 96 | - | ||
| 97 | - shader.SetPoint(12, Vector3(-radius,-radius,0.0f)); | ||
| 98 | - shader.SetPoint(13, Vector3(radius,-radius,0.0f)); | ||
| 99 | - shader.SetPoint(14, Vector3(radius,radius,0.0f)); | ||
| 100 | - shader.SetPoint(15, Vector3( -radius,radius,0.0f)); | ||
| 101 | - | ||
| 102 | - shader.SetColor(Vector4(1.0f,0.0f,0.0f,1.0f) ); | ||
| 103 | - shader.SetLineWidth(2.0f); | ||
| 104 | - | ||
| 105 | - ////Generate the mesh | ||
| 106 | - Dali::MeshData::VertexContainer vertices; | ||
| 107 | - for( unsigned int i(0); i<12; i+=3 ) | ||
| 108 | - { | ||
| 109 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,0.0f,i) )); | ||
| 110 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.5f,0.0f,i+1))); | ||
| 111 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(1.0f,1.0f,i+2))); | ||
| 112 | - } | ||
| 113 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,1.0f,12) )); | ||
| 114 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,1.0f,13))); | ||
| 115 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,1.0f,14))); | ||
| 116 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,1.0f,15))); | ||
| 117 | - | ||
| 118 | - short unsigned int indexArray[] = { 0,2,1, 3,5,4,6,8,7, 9, 11, 10, 12,15,14,12,14,13}; | ||
| 119 | - Dali::MeshData::FaceIndices index( indexArray, indexArray + sizeof(indexArray)/sizeof(short unsigned int) ); | ||
| 120 | - | ||
| 121 | - //Material | ||
| 122 | - Dali::Material material = Material::New("Material"); | ||
| 123 | - material.SetDiffuseColor( Vector4(1.0f,1.0f,1.0f,1.0f)); | ||
| 124 | - | ||
| 125 | - //Create the Mesh object | ||
| 126 | - Dali::MeshData data; | ||
| 127 | - data.SetVertices(vertices); | ||
| 128 | - data.SetFaceIndices( index ); | ||
| 129 | - data.SetMaterial( material ); | ||
| 130 | - data.SetHasNormals( true ); | ||
| 131 | - Mesh mesh = Mesh::New( data ); | ||
| 132 | - | ||
| 133 | - //Create the mesh actor | ||
| 134 | - MeshActor meshActor = MeshActor::New(mesh); | ||
| 135 | - meshActor.SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 136 | - meshActor.SetShaderEffect(shader); | ||
| 137 | - meshActor.SetPosition( center ); | ||
| 138 | - meshActor.SetBlendMode(BlendingMode::ON ); | ||
| 139 | - mView.Add( meshActor ); | ||
| 140 | - | ||
| 141 | - | ||
| 142 | - //Animation | ||
| 143 | - Animation animation = Animation::New(5.0f); | ||
| 144 | - KeyFrames k0 = KeyFrames::New(); | ||
| 145 | - k0.Add( 0.0f, Vector3( 0.0f,-radius, 0.0f) ); | ||
| 146 | - k0.Add( 0.5f, Vector3(0.0f, -radius*4.0f, 0.0f)); | ||
| 147 | - k0.Add( 1.0f, Vector3( 0.0f,-radius, 0.0f) ); | ||
| 148 | - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(1)),k0,AlphaFunction::EASE_IN_OUT ); | ||
| 149 | - | ||
| 150 | - k0 = KeyFrames::New(); | ||
| 151 | - k0.Add( 0.0f, Vector3( radius, 0.0f, 0.0f) ); | ||
| 152 | - k0.Add( 0.5f, Vector3(radius*4.0f,0.0f, 0.0f)); | ||
| 153 | - k0.Add( 1.0f, Vector3( radius,0.0f, 0.0f)); | ||
| 154 | - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(4)),k0,AlphaFunction::EASE_IN_OUT ); | ||
| 155 | - | ||
| 156 | - k0 = KeyFrames::New(); | ||
| 157 | - k0.Add( 0.0f, Vector3(0.0f,radius, 0.0f) ); | ||
| 158 | - k0.Add( 0.5f, Vector3(0.0f,radius*4.0f, 0.0f)); | ||
| 159 | - k0.Add( 1.0f, Vector3(0.0f,radius, 0.0f) ); | ||
| 160 | - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(7)),k0,AlphaFunction::EASE_IN_OUT ); | ||
| 161 | - | ||
| 162 | - k0 = KeyFrames::New(); | ||
| 163 | - k0.Add( 0.0f, Vector3( -radius, 0.0f, 0.0f) ); | ||
| 164 | - k0.Add( 0.5f, Vector3(-radius*4.0f,0.0f, 0.0f)); | ||
| 165 | - k0.Add( 1.0f, Vector3( -radius, 0.0f, 0.0f) ); | ||
| 166 | - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(10)),k0,AlphaFunction::EASE_IN_OUT ); | ||
| 167 | - | ||
| 168 | - animation.AnimateBy( Property( meshActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(90.0f) ), Vector3::ZAXIS ) ); | ||
| 169 | - animation.SetLooping( true ); | ||
| 170 | - animation.Play(); | ||
| 171 | - } | ||
| 172 | - | ||
| 173 | - void CreateTriangleMorph( Vector3 center, float side ) | ||
| 174 | - { | ||
| 175 | - float h = (side *0.5f)/0.866f; | ||
| 176 | - | ||
| 177 | - Vector3 v0 = Vector3(-h,h,0.0f); | ||
| 178 | - Vector3 v1 = Vector3(0.0f,-(side*0.366f),0.0f ); | ||
| 179 | - Vector3 v2 = Vector3(h,h,0.0f); | ||
| 180 | - | ||
| 181 | - Vector3 v3 = v0 + ((v1-v0) * 0.5f); | ||
| 182 | - Vector3 v4 = v1 + ((v2-v1) * 0.5f); | ||
| 183 | - Vector3 v5 = v2 + ((v0-v2) * 0.5f); | ||
| 184 | - | ||
| 185 | - Toolkit::QuadraticBezier shader = Toolkit::QuadraticBezier::New(12, true); | ||
| 186 | - | ||
| 187 | - shader.SetPoint(0,v0); | ||
| 188 | - shader.SetPoint(1,v3); | ||
| 189 | - shader.SetPoint(2,v1); | ||
| 190 | - | ||
| 191 | - shader.SetPoint(3,v1); | ||
| 192 | - shader.SetPoint(4,v4); | ||
| 193 | - shader.SetPoint(5,v2); | ||
| 194 | - | ||
| 195 | - shader.SetPoint(6,v2); | ||
| 196 | - shader.SetPoint(7,v5); | ||
| 197 | - shader.SetPoint(8,v0); | ||
| 198 | - | ||
| 199 | - shader.SetPoint(9, v0); | ||
| 200 | - shader.SetPoint(10,v1); | ||
| 201 | - shader.SetPoint(11,v2); | ||
| 202 | - | ||
| 203 | - shader.SetColor(Vector4(0.0f,1.0f,0.0f,1.0f)); | ||
| 204 | - shader.SetLineWidth(2.0f); | ||
| 205 | - | ||
| 206 | - ////Generate the mesh | ||
| 207 | - Dali::MeshData::VertexContainer vertices; | ||
| 208 | - for( unsigned int i(0);i<9;i+=3 ) | ||
| 209 | - { | ||
| 210 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,0.0f,i)) ); | ||
| 211 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO,Vector3(0.5f,0.0f,i+1) ) ); | ||
| 212 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(1.0f,1.0f,i+2) ) ); | ||
| 213 | - } | ||
| 214 | - | ||
| 215 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,1.0f,9)) ); | ||
| 216 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO,Vector3(0.0f,1.0f,10) ) ); | ||
| 217 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,1.0f,11) ) ); | ||
| 218 | - | ||
| 219 | - short unsigned int indexArray[] = { 0,2,1,3,5,4,6,8,7,9,11,10 }; | ||
| 220 | - Dali::MeshData::FaceIndices index( indexArray, indexArray + sizeof(indexArray)/sizeof(short unsigned int) ); | ||
| 221 | - | ||
| 222 | - //Material | ||
| 223 | - Dali::Material material = Material::New("Material"); | ||
| 224 | - material.SetDiffuseColor( Vector4(1.0f,1.0f,1.0f,1.0f)); | ||
| 225 | - | ||
| 226 | - //Create the Mesh object | ||
| 227 | - Dali::MeshData data; | ||
| 228 | - data.SetVertices(vertices); | ||
| 229 | - data.SetFaceIndices( index ); | ||
| 230 | - data.SetMaterial( material ); | ||
| 231 | - data.SetHasNormals( true ); | ||
| 232 | - Mesh mesh = Mesh::New( data ); | ||
| 233 | - | ||
| 234 | -// //Create the mesh actor | ||
| 235 | - MeshActor meshActor = MeshActor::New(mesh); | ||
| 236 | - meshActor.SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 237 | - meshActor.SetShaderEffect(shader); | ||
| 238 | - meshActor.SetPosition( center ); | ||
| 239 | - meshActor.SetBlendMode(BlendingMode::ON ); | ||
| 240 | - mView.Add( meshActor ); | ||
| 241 | - | ||
| 242 | - //Animation | ||
| 243 | - Animation animation = Animation::New(5.0f); | ||
| 244 | - | ||
| 245 | - KeyFrames k0 = KeyFrames::New(); | ||
| 246 | - k0.Add( 0.0f,v3 ); | ||
| 247 | - k0.Add( 0.5f, v3 + Vector3(-200.0f,-200.0f,0.0f)); | ||
| 248 | - k0.Add( 1.0f, v3 ); | ||
| 249 | - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(1)),k0,AlphaFunction::EASE_IN_OUT ); | ||
| 250 | - | ||
| 251 | - k0 = KeyFrames::New(); | ||
| 252 | - k0.Add( 0.0f,v4 ); | ||
| 253 | - k0.Add( 0.5f, v4 + Vector3(200.0f,-200.0f,0.0f)); | ||
| 254 | - k0.Add( 1.0f, v4 ); | ||
| 255 | - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(4)),k0,AlphaFunction::EASE_IN_OUT ); | ||
| 256 | - | ||
| 257 | - k0 = KeyFrames::New(); | ||
| 258 | - k0.Add( 0.0f,v5 ); | ||
| 259 | - k0.Add( 0.5f, v5 + Vector3(0.0,200.0f,0.0f)); | ||
| 260 | - k0.Add( 1.0f, v5 ); | ||
| 261 | - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(7)),k0,AlphaFunction::EASE_IN_OUT ); | ||
| 262 | - animation.SetLooping( true ); | ||
| 263 | - animation.Play(); | ||
| 264 | - } | ||
| 265 | - | ||
| 266 | - void CreatePathMorph( Vector3 center, float radius ) | ||
| 267 | - { | ||
| 268 | - Toolkit::QuadraticBezier shader = Toolkit::QuadraticBezier::New(12, false); | ||
| 269 | - | ||
| 270 | - shader.SetPoint(0, Vector3(-radius,-radius,0.0f)); | ||
| 271 | - shader.SetPoint(1, Vector3( 0.0f,-radius,0.0f)); | ||
| 272 | - shader.SetPoint(2, Vector3(radius,-radius,0.0f)); | ||
| 273 | - | ||
| 274 | - shader.SetPoint(3, Vector3(radius,-radius,0.0f)); | ||
| 275 | - shader.SetPoint(4, Vector3( radius,0.0f,0.0f)); | ||
| 276 | - shader.SetPoint(5, Vector3(radius,radius,0.0f)); | ||
| 277 | - | ||
| 278 | - shader.SetPoint(6, Vector3(radius,radius,0.0f)); | ||
| 279 | - shader.SetPoint(7, Vector3( 0.0f,radius,0.0f)); | ||
| 280 | - shader.SetPoint(8, Vector3( -radius,radius,0.0f)); | ||
| 281 | - | ||
| 282 | - shader.SetPoint(9, Vector3( -radius,radius,0.0f)); | ||
| 283 | - shader.SetPoint(10, Vector3( -radius,0.0f,0.0f)); | ||
| 284 | - shader.SetPoint(11, Vector3(-radius,-radius,0.0f)); | ||
| 285 | - | ||
| 286 | - shader.SetColor(Vector4(1.0f,1.0f,0.0f,1.0f) ); | ||
| 287 | - shader.SetLineWidth(1.5f); | ||
| 288 | - | ||
| 289 | - ////Generate the mesh/S | ||
| 290 | - Dali::MeshData::VertexContainer vertices; | ||
| 291 | - for( unsigned int i(0); i<12; i+=3 ) | ||
| 292 | - { | ||
| 293 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.0f,0.0f,i) )); | ||
| 294 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(0.5f,0.0f,i+1))); | ||
| 295 | - vertices.push_back( MeshData::Vertex( Vector3::ZERO, Vector2::ZERO, Vector3(1.0f,1.0f,i+2))); | ||
| 296 | - } | ||
| 297 | - | ||
| 298 | - | ||
| 299 | - short unsigned int indexArray[] = { 0,2,1, 3,5,4,6,8,7, 9, 11, 10 }; | ||
| 300 | - Dali::MeshData::FaceIndices index( indexArray, indexArray + sizeof(indexArray)/sizeof(short unsigned int) ); | ||
| 301 | - | ||
| 302 | - //Material | ||
| 303 | - Dali::Material material = Material::New("Material"); | ||
| 304 | - material.SetDiffuseColor( Vector4(1.0f,1.0f,1.0f,1.0f)); | ||
| 305 | - | ||
| 306 | - //Create the Mesh object | ||
| 307 | - Dali::MeshData data; | ||
| 308 | - data.SetVertices(vertices); | ||
| 309 | - data.SetFaceIndices( index ); | ||
| 310 | - data.SetMaterial( material ); | ||
| 311 | - data.SetHasNormals( true ); | ||
| 312 | - Mesh mesh = Mesh::New( data ); | ||
| 313 | - | ||
| 314 | - //Create the mesh actor | ||
| 315 | - MeshActor meshActor = MeshActor::New(mesh); | ||
| 316 | - meshActor.SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 317 | - meshActor.SetShaderEffect(shader); | ||
| 318 | - meshActor.SetPosition( center ); | ||
| 319 | - meshActor.SetBlendMode(BlendingMode::ON ); | ||
| 320 | - mView.Add( meshActor ); | ||
| 321 | - | ||
| 322 | - | ||
| 323 | - //Animation | ||
| 324 | - Animation animation = Animation::New(5.0f); | ||
| 325 | - KeyFrames k0 = KeyFrames::New(); | ||
| 326 | - k0.Add( 0.0f, Vector3( 0.0f,-radius*2.0, 0.0f) ); | ||
| 327 | - k0.Add( 0.5f, Vector3(-radius*2.0, -radius*3.0f, 0.0f)); | ||
| 328 | - k0.Add( 1.0f, Vector3( 0.0f,-radius*2.0, 0.0f) ); | ||
| 329 | - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(1)),k0,AlphaFunction::EASE_IN_OUT ); | ||
| 330 | - | ||
| 331 | - k0 = KeyFrames::New(); | ||
| 332 | - k0.Add( 0.0f, Vector3( radius*2.0, 0.0f, 0.0f) ); | ||
| 333 | - k0.Add( 0.5f, Vector3(radius*3.0f,-radius*2.0, 0.0f)); | ||
| 334 | - k0.Add( 1.0f, Vector3( radius*2.0,0.0f, 0.0f)); | ||
| 335 | - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(4)),k0,AlphaFunction::EASE_IN_OUT ); | ||
| 336 | - | ||
| 337 | - k0 = KeyFrames::New(); | ||
| 338 | - k0.Add( 0.0f, Vector3(0.0f,radius*2.0, 0.0f) ); | ||
| 339 | - k0.Add( 0.5f, Vector3(radius*2.0,radius*3.0f, 0.0f)); | ||
| 340 | - k0.Add( 1.0f, Vector3(0.0f,radius*2.0, 0.0f) ); | ||
| 341 | - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(7)),k0,AlphaFunction::EASE_IN_OUT ); | ||
| 342 | - | ||
| 343 | - k0 = KeyFrames::New(); | ||
| 344 | - k0.Add( 0.0f, Vector3( -radius*2.0, 0.0f, 0.0f) ); | ||
| 345 | - k0.Add( 0.5f, Vector3(-radius*3.0f,radius*2.0, 0.0f)); | ||
| 346 | - k0.Add( 1.0f, Vector3( -radius*2.0, 0.0f, 0.0f) ); | ||
| 347 | - animation.AnimateBetween( Property(shader, shader.GetPointPropertyName(10)),k0,AlphaFunction::EASE_IN_OUT ); | ||
| 348 | - | ||
| 349 | - animation.AnimateBy( Property( meshActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(-90.0f) ), Vector3::ZAXIS ) ); | ||
| 350 | - animation.SetLooping( true ); | ||
| 351 | - animation.Play(); | ||
| 352 | - } | ||
| 353 | - | ||
| 354 | - /** | ||
| 355 | - * Main key event handler | ||
| 356 | - */ | ||
| 357 | - void OnKeyEvent(const KeyEvent& event) | ||
| 358 | - { | ||
| 359 | - if( event.state == KeyEvent::Down && (IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK )) ) | ||
| 360 | - { | ||
| 361 | - mApplication.Quit(); | ||
| 362 | - } | ||
| 363 | - } | ||
| 364 | - | ||
| 365 | -private: | ||
| 366 | - Application& mApplication; | ||
| 367 | - Toolkit::Control mView; | ||
| 368 | -}; | ||
| 369 | - | ||
| 370 | -void RunTest( Application& application ) | ||
| 371 | -{ | ||
| 372 | - AnimatedShapesExample test( application ); | ||
| 373 | - application.MainLoop(); | ||
| 374 | -} | ||
| 375 | - | ||
| 376 | -int main( int argc, char **argv ) | ||
| 377 | -{ | ||
| 378 | - Application application = Application::New( &argc, &argv, DALI_DEMO_THEME_PATH ); | ||
| 379 | - RunTest( application ); | ||
| 380 | - | ||
| 381 | - return 0; | ||
| 382 | -} |
examples/bubble-effect/bubble-effect-example.cpp
| @@ -42,9 +42,9 @@ const unsigned int NUM_BACKGROUND_IMAGES( sizeof( BACKGROUND_IMAGES ) / sizeof( | @@ -42,9 +42,9 @@ const unsigned int NUM_BACKGROUND_IMAGES( sizeof( BACKGROUND_IMAGES ) / sizeof( | ||
| 42 | const char* BUBBLE_SHAPE_IMAGES[] = | 42 | const char* BUBBLE_SHAPE_IMAGES[] = |
| 43 | { | 43 | { |
| 44 | DALI_IMAGE_DIR "bubble-ball.png", | 44 | DALI_IMAGE_DIR "bubble-ball.png", |
| 45 | + DALI_IMAGE_DIR "icon-effect-cross.png", | ||
| 45 | DALI_IMAGE_DIR "icon-item-view-layout-spiral.png", | 46 | DALI_IMAGE_DIR "icon-item-view-layout-spiral.png", |
| 46 | - DALI_IMAGE_DIR "icon-replace.png", | ||
| 47 | - DALI_IMAGE_DIR "icon-effect-cross.png" | 47 | + DALI_IMAGE_DIR "icon-replace.png" |
| 48 | }; | 48 | }; |
| 49 | const unsigned int NUM_BUBBLE_SHAPE_IMAGES( sizeof( BUBBLE_SHAPE_IMAGES ) / sizeof( BUBBLE_SHAPE_IMAGES[0] ) ); | 49 | const unsigned int NUM_BUBBLE_SHAPE_IMAGES( sizeof( BUBBLE_SHAPE_IMAGES ) / sizeof( BUBBLE_SHAPE_IMAGES[0] ) ); |
| 50 | 50 | ||
| @@ -74,10 +74,10 @@ public: | @@ -74,10 +74,10 @@ public: | ||
| 74 | BubbleEffectExample(Application &app) | 74 | BubbleEffectExample(Application &app) |
| 75 | : mApp(app), | 75 | : mApp(app), |
| 76 | mHSVDelta( Vector3( 0.f, 0.f, 0.5f ) ), | 76 | mHSVDelta( Vector3( 0.f, 0.f, 0.5f ) ), |
| 77 | - mNeedNewAnimation( true ), | ||
| 78 | mTimerInterval( 16 ), | 77 | mTimerInterval( 16 ), |
| 79 | mCurrentBackgroundImageId( 0 ), | 78 | mCurrentBackgroundImageId( 0 ), |
| 80 | - mCurrentBubbleShapeImageId( 0 ) | 79 | + mCurrentBubbleShapeImageId( 0 ), |
| 80 | + mNeedNewAnimation( true ) | ||
| 81 | { | 81 | { |
| 82 | // Connect to the Application's Init signal | 82 | // Connect to the Application's Init signal |
| 83 | app.InitSignal().Connect(this, &BubbleEffectExample::Create); | 83 | app.InitSignal().Connect(this, &BubbleEffectExample::Create); |
| @@ -154,7 +154,7 @@ private: | @@ -154,7 +154,7 @@ private: | ||
| 154 | * Emit bubbles | 154 | * Emit bubbles |
| 155 | *****************/ | 155 | *****************/ |
| 156 | 156 | ||
| 157 | - // Set up the animation of emitting bubbles, to be efficient, every animation controls multiple bubbles ( 4 here ) | 157 | + // Set up the animation of emitting bubbles, to be efficient, every animation controls multiple emission ( 4 here ) |
| 158 | void SetUpAnimation( Vector2 emitPosition, Vector2 direction ) | 158 | void SetUpAnimation( Vector2 emitPosition, Vector2 direction ) |
| 159 | { | 159 | { |
| 160 | if( mNeedNewAnimation ) | 160 | if( mNeedNewAnimation ) |
| @@ -232,6 +232,9 @@ private: | @@ -232,6 +232,9 @@ private: | ||
| 232 | case TouchPoint::Interrupted: | 232 | case TouchPoint::Interrupted: |
| 233 | { | 233 | { |
| 234 | mTimerForBubbleEmission.Stop(); | 234 | mTimerForBubbleEmission.Stop(); |
| 235 | + mEmitAnimation.Play(); | ||
| 236 | + mNeedNewAnimation = true; | ||
| 237 | + mAnimateComponentCount = 0; | ||
| 235 | break; | 238 | break; |
| 236 | } | 239 | } |
| 237 | case TouchPoint::Stationary: | 240 | case TouchPoint::Stationary: |
| @@ -283,23 +286,22 @@ private: | @@ -283,23 +286,22 @@ private: | ||
| 283 | Dali::Toolkit::Control mBackground; | 286 | Dali::Toolkit::Control mBackground; |
| 284 | 287 | ||
| 285 | Toolkit::BubbleEmitter mBubbleEmitter; | 288 | Toolkit::BubbleEmitter mBubbleEmitter; |
| 286 | - Vector3 mHSVDelta; | ||
| 287 | - | ||
| 288 | Animation mEmitAnimation; | 289 | Animation mEmitAnimation; |
| 289 | - unsigned int mAnimateComponentCount; | ||
| 290 | - bool mNeedNewAnimation; | ||
| 291 | - | 290 | + Toolkit::PushButton mChangeBackgroundButton; |
| 291 | + Toolkit::PushButton mChangeBubbleShapeButton; | ||
| 292 | Timer mTimerForBubbleEmission; | 292 | Timer mTimerForBubbleEmission; |
| 293 | - unsigned int mNonMovementCount; | ||
| 294 | - unsigned int mTimerInterval; | ||
| 295 | 293 | ||
| 294 | + Vector3 mHSVDelta; | ||
| 296 | Vector2 mCurrentTouchPosition; | 295 | Vector2 mCurrentTouchPosition; |
| 297 | Vector2 mEmitPosition; | 296 | Vector2 mEmitPosition; |
| 298 | 297 | ||
| 299 | - Toolkit::PushButton mChangeBackgroundButton; | ||
| 300 | - Toolkit::PushButton mChangeBubbleShapeButton; | 298 | + unsigned int mAnimateComponentCount; |
| 299 | + unsigned int mNonMovementCount; | ||
| 300 | + unsigned int mTimerInterval; | ||
| 301 | unsigned int mCurrentBackgroundImageId; | 301 | unsigned int mCurrentBackgroundImageId; |
| 302 | unsigned int mCurrentBubbleShapeImageId; | 302 | unsigned int mCurrentBubbleShapeImageId; |
| 303 | + | ||
| 304 | + bool mNeedNewAnimation; | ||
| 303 | }; | 305 | }; |
| 304 | 306 | ||
| 305 | /*****************************************************************************/ | 307 | /*****************************************************************************/ |
examples/cluster/cluster-example.cpp
| @@ -376,6 +376,8 @@ public: | @@ -376,6 +376,8 @@ public: | ||
| 376 | TOOLBAR_IMAGE, | 376 | TOOLBAR_IMAGE, |
| 377 | "" ); | 377 | "" ); |
| 378 | 378 | ||
| 379 | + mContentLayer.SetProperty(Layer::Property::BEHAVIOR, "Dali::Layer::LAYER_3D"); | ||
| 380 | + | ||
| 379 | // Create a effect toggle button. (right of toolbar) | 381 | // Create a effect toggle button. (right of toolbar) |
| 380 | mLayoutButtonImages[ NO_EFFECT ] = ResourceImage::New( LAYOUT_NONE_IMAGE ); | 382 | mLayoutButtonImages[ NO_EFFECT ] = ResourceImage::New( LAYOUT_NONE_IMAGE ); |
| 381 | mLayoutButtonImages[ MOTION_BLUR_EFFECT ] = ResourceImage::New( LAYOUT_MOTION_BLUR_IMAGE ); | 383 | mLayoutButtonImages[ MOTION_BLUR_EFFECT ] = ResourceImage::New( LAYOUT_MOTION_BLUR_IMAGE ); |
| @@ -552,21 +554,22 @@ public: | @@ -552,21 +554,22 @@ public: | ||
| 552 | */ | 554 | */ |
| 553 | void SetMotionBlurEffect( Actor actor ) | 555 | void SetMotionBlurEffect( Actor actor ) |
| 554 | { | 556 | { |
| 557 | + | ||
| 555 | // only do something if the actor and effect are valid | 558 | // only do something if the actor and effect are valid |
| 556 | if( actor ) | 559 | if( actor ) |
| 557 | { | 560 | { |
| 558 | // first remove from this actor | 561 | // first remove from this actor |
| 559 | - RenderableActor renderable = RenderableActor::DownCast( actor ); | ||
| 560 | - if( renderable ) | 562 | + ImageActor imageActor = ImageActor::DownCast( actor ); |
| 563 | + if( imageActor ) | ||
| 561 | { | 564 | { |
| 562 | - MotionBlurEffect shaderEffect = MotionBlurEffect::New(); | ||
| 563 | - shaderEffect.SetSpeedScalingFactor(0.1f); | 565 | + ShaderEffect shaderEffect = Toolkit::CreateMotionBlurEffect(); |
| 566 | + shaderEffect.SetUniform("uSpeedScalingFactor",0.1f); | ||
| 564 | 567 | ||
| 565 | Dali::Property::Index uModelProperty = shaderEffect.GetPropertyIndex( "uModelLastFrame" ); | 568 | Dali::Property::Index uModelProperty = shaderEffect.GetPropertyIndex( "uModelLastFrame" ); |
| 566 | Constraint constraint = Constraint::New<Matrix>( shaderEffect, uModelProperty, EqualToConstraint() ); | 569 | Constraint constraint = Constraint::New<Matrix>( shaderEffect, uModelProperty, EqualToConstraint() ); |
| 567 | - constraint.AddSource( Source( actor , Actor::Property::WORLD_MATRIX ) ); | 570 | + constraint.AddSource( Source( imageActor , Actor::Property::WORLD_MATRIX ) ); |
| 568 | constraint.Apply(); | 571 | constraint.Apply(); |
| 569 | - renderable.SetShaderEffect( shaderEffect ); | 572 | + imageActor.SetShaderEffect( shaderEffect ); |
| 570 | } | 573 | } |
| 571 | // then all children recursively | 574 | // then all children recursively |
| 572 | const unsigned int count = actor.GetChildCount(); | 575 | const unsigned int count = actor.GetChildCount(); |
| @@ -650,8 +653,8 @@ public: | @@ -650,8 +653,8 @@ public: | ||
| 650 | case CAROUSEL_EFFECT: | 653 | case CAROUSEL_EFFECT: |
| 651 | { | 654 | { |
| 652 | // Apply Carousel Shader Effect to scrollView | 655 | // Apply Carousel Shader Effect to scrollView |
| 653 | - CarouselEffect shaderEffect = CarouselEffect::New(); | ||
| 654 | - shaderEffect.SetRadius( -CAROUSEL_EFFECT_RADIUS ); | 656 | + ShaderEffect shaderEffect = Toolkit::CreateCarouselEffect(); |
| 657 | + shaderEffect.SetUniform( "uRadius", -CAROUSEL_EFFECT_RADIUS ); | ||
| 655 | // dont apply shader effect to scrollview as it might override internal shaders for bounce effect etc | 658 | // dont apply shader effect to scrollview as it might override internal shaders for bounce effect etc |
| 656 | for( std::vector<ClusterInfo>::iterator i = mClusterInfo.begin(); i != mClusterInfo.end(); ++i ) | 659 | for( std::vector<ClusterInfo>::iterator i = mClusterInfo.begin(); i != mClusterInfo.end(); ++i ) |
| 657 | { | 660 | { |
| @@ -663,7 +666,7 @@ public: | @@ -663,7 +666,7 @@ public: | ||
| 663 | const Vector2 angleSweep( CAROUSEL_EFFECT_ANGLE_SWEEP / stageSize.width, | 666 | const Vector2 angleSweep( CAROUSEL_EFFECT_ANGLE_SWEEP / stageSize.width, |
| 664 | CAROUSEL_EFFECT_ANGLE_SWEEP / stageSize.width ); | 667 | CAROUSEL_EFFECT_ANGLE_SWEEP / stageSize.width ); |
| 665 | 668 | ||
| 666 | - Property::Index anglePerUnit = shaderEffect.GetPropertyIndex( shaderEffect.GetAnglePerUnitPropertyName() ); | 669 | + Property::Index anglePerUnit = shaderEffect.GetPropertyIndex( "uAnglePerUnit" ); |
| 667 | Constraint constraint = Constraint::New<Vector2>( shaderEffect, anglePerUnit, CarouselEffectOrientationConstraint( angleSweep ) ); | 670 | Constraint constraint = Constraint::New<Vector2>( shaderEffect, anglePerUnit, CarouselEffectOrientationConstraint( angleSweep ) ); |
| 668 | constraint.AddSource( Source(mView, Actor::Property::ORIENTATION) ); | 671 | constraint.AddSource( Source(mView, Actor::Property::ORIENTATION) ); |
| 669 | constraint.Apply(); | 672 | constraint.Apply(); |
| @@ -685,10 +688,10 @@ public: | @@ -685,10 +688,10 @@ public: | ||
| 685 | mScrollView.SetRulerY(rulerY); | 688 | mScrollView.SetRulerY(rulerY); |
| 686 | 689 | ||
| 687 | // Apply Carousel Shader Effect to scrollView (Spherical style) | 690 | // Apply Carousel Shader Effect to scrollView (Spherical style) |
| 688 | - CarouselEffect shaderEffect = CarouselEffect::New(); | 691 | + ShaderEffect shaderEffect = Toolkit::CreateCarouselEffect(); |
| 689 | 692 | ||
| 690 | - shaderEffect.SetRadius( SPHERE_EFFECT_RADIUS ); | ||
| 691 | - shaderEffect.SetAnglePerUnit( Vector2( SPHERE_EFFECT_ANGLE_SWEEP / stageSize.y, SPHERE_EFFECT_ANGLE_SWEEP / stageSize.y ) ); | 693 | + shaderEffect.SetUniform( "uRadius", SPHERE_EFFECT_RADIUS ); |
| 694 | + shaderEffect.SetUniform( "uAnglePerUnit", Vector2( SPHERE_EFFECT_ANGLE_SWEEP / stageSize.y, SPHERE_EFFECT_ANGLE_SWEEP / stageSize.y ) ); | ||
| 692 | // dont apply shader effect to scrollview as it might override internal shaders for bounce effect etc | 695 | // dont apply shader effect to scrollview as it might override internal shaders for bounce effect etc |
| 693 | for( std::vector<ClusterInfo>::iterator i = mClusterInfo.begin(); i != mClusterInfo.end(); ++i ) | 696 | for( std::vector<ClusterInfo>::iterator i = mClusterInfo.begin(); i != mClusterInfo.end(); ++i ) |
| 694 | { | 697 | { |
examples/dissolve-effect/dissolve-effect-example.cpp
| @@ -163,8 +163,8 @@ private: | @@ -163,8 +163,8 @@ private: | ||
| 163 | ImageActor mNextImage; | 163 | ImageActor mNextImage; |
| 164 | unsigned int mIndex; | 164 | unsigned int mIndex; |
| 165 | 165 | ||
| 166 | - Toolkit::DissolveEffect mCurrentImageEffect; | ||
| 167 | - Toolkit::DissolveEffect mNextImageEffect; | 166 | + ShaderEffect mCurrentImageEffect; |
| 167 | + ShaderEffect mNextImageEffect; | ||
| 168 | bool mUseHighPrecision; | 168 | bool mUseHighPrecision; |
| 169 | Animation mAnimation; | 169 | Animation mAnimation; |
| 170 | 170 | ||
| @@ -234,8 +234,8 @@ void DissolveEffectApp::OnInit( Application& application ) | @@ -234,8 +234,8 @@ void DissolveEffectApp::OnInit( Application& application ) | ||
| 234 | mPanGestureDetector.DetectedSignal().Connect( this, &DissolveEffectApp::OnPanGesture ); | 234 | mPanGestureDetector.DetectedSignal().Connect( this, &DissolveEffectApp::OnPanGesture ); |
| 235 | 235 | ||
| 236 | // create the dissolve effect object | 236 | // create the dissolve effect object |
| 237 | - mCurrentImageEffect = Toolkit::DissolveEffect::New(mUseHighPrecision); | ||
| 238 | - mNextImageEffect = Toolkit::DissolveEffect::New(mUseHighPrecision); | 237 | + mCurrentImageEffect = Toolkit::CreateDissolveEffect(mUseHighPrecision); |
| 238 | + mNextImageEffect = Toolkit::CreateDissolveEffect(mUseHighPrecision); | ||
| 239 | 239 | ||
| 240 | mViewTimer = Timer::New( VIEWINGTIME ); | 240 | mViewTimer = Timer::New( VIEWINGTIME ); |
| 241 | mViewTimer.TickSignal().Connect( this, &DissolveEffectApp::OnTimerTick ); | 241 | mViewTimer.TickSignal().Connect( this, &DissolveEffectApp::OnTimerTick ); |
| @@ -293,20 +293,20 @@ void DissolveEffectApp::StartTransition(Vector2 position, Vector2 displacement) | @@ -293,20 +293,20 @@ void DissolveEffectApp::StartTransition(Vector2 position, Vector2 displacement) | ||
| 293 | { | 293 | { |
| 294 | mAnimation = Animation::New(TRANSITION_DURATION); | 294 | mAnimation = Animation::New(TRANSITION_DURATION); |
| 295 | 295 | ||
| 296 | - mCurrentImageEffect.SetCentralLine(position,displacement); | ||
| 297 | - mCurrentImageEffect.SetDistortion(0.0f); | 296 | + Dali::Toolkit::DissolveEffectSetCentralLine( mCurrentImageEffect, position, displacement ); |
| 297 | + mCurrentImageEffect.SetUniform("uPercentage", 0.0f); | ||
| 298 | mCurrentImage.SetShaderEffect(mCurrentImageEffect); | 298 | mCurrentImage.SetShaderEffect(mCurrentImageEffect); |
| 299 | - mAnimation.AnimateTo( Property(mCurrentImageEffect, mCurrentImageEffect.GetDistortionPropertyName()), 1.0f, AlphaFunction::LINEAR ); | 299 | + mAnimation.AnimateTo( Property(mCurrentImageEffect, "uPercentage"), 1.0f, AlphaFunction::LINEAR ); |
| 300 | 300 | ||
| 301 | mNextImage.SetOpacity(0.0f); | 301 | mNextImage.SetOpacity(0.0f); |
| 302 | mAnimation.AnimateTo( Property( mNextImage, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::LINEAR ); | 302 | mAnimation.AnimateTo( Property( mNextImage, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::LINEAR ); |
| 303 | 303 | ||
| 304 | if(mUseHighPrecision) | 304 | if(mUseHighPrecision) |
| 305 | { | 305 | { |
| 306 | - mNextImageEffect.SetCentralLine(position,-displacement); | ||
| 307 | - mNextImageEffect.SetDistortion(1.0f); | 306 | + Dali::Toolkit::DissolveEffectSetCentralLine( mNextImageEffect, position, displacement ); |
| 307 | + mNextImageEffect.SetUniform("uPercentage", 1.0f); | ||
| 308 | mNextImage.SetShaderEffect(mNextImageEffect); | 308 | mNextImage.SetShaderEffect(mNextImageEffect); |
| 309 | - mAnimation.AnimateTo( Property(mNextImageEffect, mNextImageEffect.GetDistortionPropertyName()), 0.0f, AlphaFunction::LINEAR ); | 309 | + mAnimation.AnimateTo( Property(mNextImageEffect, "uPercentage"), 0.0f, AlphaFunction::LINEAR ); |
| 310 | } | 310 | } |
| 311 | else | 311 | else |
| 312 | { | 312 | { |
| @@ -332,7 +332,7 @@ void DissolveEffectApp::OnKeyEvent(const KeyEvent& event) | @@ -332,7 +332,7 @@ void DissolveEffectApp::OnKeyEvent(const KeyEvent& event) | ||
| 332 | bool DissolveEffectApp::OnEffectButtonClicked( Toolkit::Button button ) | 332 | bool DissolveEffectApp::OnEffectButtonClicked( Toolkit::Button button ) |
| 333 | { | 333 | { |
| 334 | mUseHighPrecision = !mUseHighPrecision; | 334 | mUseHighPrecision = !mUseHighPrecision; |
| 335 | - mCurrentImageEffect = Toolkit::DissolveEffect::New(mUseHighPrecision); | 335 | + mCurrentImageEffect = Dali::Toolkit::CreateDissolveEffect(mUseHighPrecision); |
| 336 | if(mUseHighPrecision) | 336 | if(mUseHighPrecision) |
| 337 | { | 337 | { |
| 338 | mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_HIGHP) ); | 338 | mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_HIGHP) ); |
examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp
| @@ -211,16 +211,19 @@ public: | @@ -211,16 +211,19 @@ public: | ||
| 211 | mDesiredBox.SetParentOrigin( ParentOrigin::CENTER ); | 211 | mDesiredBox.SetParentOrigin( ParentOrigin::CENTER ); |
| 212 | mDesiredBox.SetAnchorPoint( AnchorPoint::CENTER ); | 212 | mDesiredBox.SetAnchorPoint( AnchorPoint::CENTER ); |
| 213 | mDesiredBox.SetPosition( 0, 0, -1 ); | 213 | mDesiredBox.SetPosition( 0, 0, -1 ); |
| 214 | + mDesiredBox.SetSortModifier(4.f); | ||
| 214 | 215 | ||
| 215 | mHeightBox.SetSize( stage.GetSize().width, (stage.GetSize() * mImageStageScale).height ); | 216 | mHeightBox.SetSize( stage.GetSize().width, (stage.GetSize() * mImageStageScale).height ); |
| 216 | mHeightBox.SetParentOrigin( ParentOrigin::CENTER ); | 217 | mHeightBox.SetParentOrigin( ParentOrigin::CENTER ); |
| 217 | mHeightBox.SetAnchorPoint( AnchorPoint::CENTER ); | 218 | mHeightBox.SetAnchorPoint( AnchorPoint::CENTER ); |
| 218 | mHeightBox.SetPosition( 0, 0, -1 ); | 219 | mHeightBox.SetPosition( 0, 0, -1 ); |
| 220 | + mHeightBox.SetSortModifier(3.f); | ||
| 219 | 221 | ||
| 220 | mWidthBox.SetSize( (stage.GetSize() * mImageStageScale).width, stage.GetSize().height ); | 222 | mWidthBox.SetSize( (stage.GetSize() * mImageStageScale).width, stage.GetSize().height ); |
| 221 | mWidthBox.SetParentOrigin( ParentOrigin::CENTER ); | 223 | mWidthBox.SetParentOrigin( ParentOrigin::CENTER ); |
| 222 | mWidthBox.SetAnchorPoint( AnchorPoint::CENTER ); | 224 | mWidthBox.SetAnchorPoint( AnchorPoint::CENTER ); |
| 223 | mWidthBox.SetPosition( 0, 0, -1 ); | 225 | mWidthBox.SetPosition( 0, 0, -1 ); |
| 226 | + mWidthBox.SetSortModifier(2.f); | ||
| 224 | 227 | ||
| 225 | // Make a grab-handle for resizing the image: | 228 | // Make a grab-handle for resizing the image: |
| 226 | mGrabCorner = Toolkit::PushButton::New(); | 229 | mGrabCorner = Toolkit::PushButton::New(); |
| @@ -233,9 +236,14 @@ public: | @@ -233,9 +236,14 @@ public: | ||
| 233 | mGrabCorner.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT ); | 236 | mGrabCorner.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT ); |
| 234 | mGrabCorner.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT ); | 237 | mGrabCorner.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT ); |
| 235 | mGrabCorner.SetSize( Vector2( stage.GetSize().width*0.08f, stage.GetSize().width*0.08f ) ); | 238 | mGrabCorner.SetSize( Vector2( stage.GetSize().width*0.08f, stage.GetSize().width*0.08f ) ); |
| 236 | - mGrabCorner.SetZ( 1.0f ); | ||
| 237 | mGrabCorner.SetOpacity( 0.6f ); | 239 | mGrabCorner.SetOpacity( 0.6f ); |
| 238 | - mDesiredBox.Add( mGrabCorner ); | 240 | + |
| 241 | + Layer grabCornerLayer = Layer::New(); | ||
| 242 | + grabCornerLayer.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT ); | ||
| 243 | + grabCornerLayer.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT ); | ||
| 244 | + | ||
| 245 | + grabCornerLayer.Add( mGrabCorner ); | ||
| 246 | + mDesiredBox.Add( grabCornerLayer ); | ||
| 239 | mPanGestureDetector = PanGestureDetector::New(); | 247 | mPanGestureDetector = PanGestureDetector::New(); |
| 240 | mPanGestureDetector.Attach( mGrabCorner ); | 248 | mPanGestureDetector.Attach( mGrabCorner ); |
| 241 | mPanGestureDetector.DetectedSignal().Connect( this, &ImageScalingAndFilteringController::OnPan ); | 249 | mPanGestureDetector.DetectedSignal().Connect( this, &ImageScalingAndFilteringController::OnPan ); |
| @@ -246,6 +254,7 @@ public: | @@ -246,6 +254,7 @@ public: | ||
| 246 | // Reposition the actor | 254 | // Reposition the actor |
| 247 | mImageActor.SetParentOrigin( ParentOrigin::CENTER ); | 255 | mImageActor.SetParentOrigin( ParentOrigin::CENTER ); |
| 248 | mImageActor.SetAnchorPoint( AnchorPoint::CENTER ); | 256 | mImageActor.SetAnchorPoint( AnchorPoint::CENTER ); |
| 257 | + mImageActor.SetSortModifier(5.f); | ||
| 249 | 258 | ||
| 250 | // Display the actor on the stage | 259 | // Display the actor on the stage |
| 251 | stage.Add( mImageActor ); | 260 | stage.Add( mImageActor ); |
| @@ -700,9 +709,9 @@ private: | @@ -700,9 +709,9 @@ private: | ||
| 700 | 709 | ||
| 701 | private: | 710 | private: |
| 702 | Application& mApplication; | 711 | Application& mApplication; |
| 703 | - Actor mDesiredBox; //< Background rectangle to show requested image size. | ||
| 704 | - Actor mHeightBox; //< Background horizontal stripe to show requested image height. | ||
| 705 | - Actor mWidthBox; //< Background vertical stripe to show requested image width. | 712 | + ImageActor mDesiredBox; //< Background rectangle to show requested image size. |
| 713 | + ImageActor mHeightBox; //< Background horizontal stripe to show requested image height. | ||
| 714 | + ImageActor mWidthBox; //< Background vertical stripe to show requested image width. | ||
| 706 | Toolkit::PushButton mFittingModeButton; | 715 | Toolkit::PushButton mFittingModeButton; |
| 707 | Toolkit::PushButton mSamplingModeButton; | 716 | Toolkit::PushButton mSamplingModeButton; |
| 708 | Toolkit::Popup mPopup; | 717 | Toolkit::Popup mPopup; |
examples/line-mesh/line-mesh-example.cpp
0 โ 100644
| 1 | +/* | ||
| 2 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + | ||
| 18 | +// EXTERNAL INCLUDES | ||
| 19 | +#include <dali/devel-api/rendering/renderer.h> | ||
| 20 | +#include <dali-toolkit/dali-toolkit.h> | ||
| 21 | + | ||
| 22 | +// INTERNAL INCLUDES | ||
| 23 | +#include "shared/view.h" | ||
| 24 | + | ||
| 25 | +using namespace Dali; | ||
| 26 | + | ||
| 27 | +namespace | ||
| 28 | +{ | ||
| 29 | +const char* MATERIAL_SAMPLE( DALI_IMAGE_DIR "gallery-small-48.jpg" ); | ||
| 30 | +const char* MATERIAL_SAMPLE2( DALI_IMAGE_DIR "gallery-medium-19.jpg" ); | ||
| 31 | + | ||
| 32 | +#define MAKE_SHADER(A)#A | ||
| 33 | + | ||
| 34 | +const char* VERTEX_SHADER = MAKE_SHADER( | ||
| 35 | +attribute mediump vec2 aPosition1; | ||
| 36 | +attribute mediump vec2 aPosition2; | ||
| 37 | +uniform mediump mat4 uMvpMatrix; | ||
| 38 | +uniform mediump vec3 uSize; | ||
| 39 | +uniform mediump float uMorphAmount; | ||
| 40 | + | ||
| 41 | +void main() | ||
| 42 | +{ | ||
| 43 | + mediump vec2 morphPosition = mix(aPosition1, aPosition2, uMorphAmount); | ||
| 44 | + mediump vec4 vertexPosition = vec4(morphPosition, 0.0, 1.0); | ||
| 45 | + vertexPosition.xyz *= uSize; | ||
| 46 | + vertexPosition = uMvpMatrix * vertexPosition; | ||
| 47 | + gl_Position = vertexPosition; | ||
| 48 | +} | ||
| 49 | +); | ||
| 50 | + | ||
| 51 | +const char* FRAGMENT_SHADER = MAKE_SHADER( | ||
| 52 | +uniform lowp vec4 uColor; | ||
| 53 | +uniform sampler2D sTexture; | ||
| 54 | + | ||
| 55 | +void main() | ||
| 56 | +{ | ||
| 57 | + gl_FragColor = uColor; | ||
| 58 | +} | ||
| 59 | +); | ||
| 60 | + | ||
| 61 | +Geometry CreateGeometry() | ||
| 62 | +{ | ||
| 63 | + // Create vertices | ||
| 64 | + struct Vertex { Vector2 position; }; | ||
| 65 | + Vertex pentagonVertexData[5] = | ||
| 66 | + { | ||
| 67 | + { Vector2( 0.0f, 1.00f) }, // 0 | ||
| 68 | + { Vector2( -0.95f, 0.31f) }, // 1 | ||
| 69 | + { Vector2( -0.59f, -0.81f) }, // 2 | ||
| 70 | + { Vector2( 0.59f, -0.81f) }, // 3 | ||
| 71 | + { Vector2( 0.95f, 0.31f) }, // 4 | ||
| 72 | + }; | ||
| 73 | + | ||
| 74 | + Vertex pentacleVertexData[5] = | ||
| 75 | + { | ||
| 76 | + { Vector2( 0.0f, -1.00f) }, // | ||
| 77 | + { Vector2( 0.59f, 0.81f) }, // | ||
| 78 | + { Vector2( -0.95f, -0.31f) }, // | ||
| 79 | + { Vector2( 0.95f, -0.31f) }, // | ||
| 80 | + { Vector2( -0.59f, 0.81f) }, // | ||
| 81 | + }; | ||
| 82 | + | ||
| 83 | + Property::Map pentagonVertexFormat; | ||
| 84 | + pentagonVertexFormat["aPosition1"] = Property::VECTOR2; | ||
| 85 | + PropertyBuffer pentagonVertices = PropertyBuffer::New( pentagonVertexFormat, 5 ); | ||
| 86 | + pentagonVertices.SetData(pentagonVertexData); | ||
| 87 | + | ||
| 88 | + Property::Map pentacleVertexFormat; | ||
| 89 | + pentacleVertexFormat["aPosition2"] = Property::VECTOR2; | ||
| 90 | + PropertyBuffer pentacleVertices = PropertyBuffer::New( pentacleVertexFormat, 5 ); | ||
| 91 | + pentacleVertices.SetData(pentacleVertexData); | ||
| 92 | + | ||
| 93 | + // Create indices | ||
| 94 | + unsigned int indexData[10] = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 0 }; | ||
| 95 | + Property::Map indexFormat; | ||
| 96 | + indexFormat["indices"] = Property::UNSIGNED_INTEGER; | ||
| 97 | + PropertyBuffer indices = PropertyBuffer::New( indexFormat, sizeof(indexData)/sizeof(indexData[0]) ); | ||
| 98 | + indices.SetData(indexData); | ||
| 99 | + | ||
| 100 | + // Create the geometry object | ||
| 101 | + Geometry pentagonGeometry = Geometry::New(); | ||
| 102 | + pentagonGeometry.AddVertexBuffer( pentagonVertices ); | ||
| 103 | + pentagonGeometry.AddVertexBuffer( pentacleVertices ); | ||
| 104 | + pentagonGeometry.SetIndexBuffer( indices ); | ||
| 105 | + | ||
| 106 | + pentagonGeometry.SetGeometryType( Geometry::LINES ); | ||
| 107 | + | ||
| 108 | + return pentagonGeometry; | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | +} // anonymous namespace | ||
| 112 | + | ||
| 113 | +// This example shows how to morph between 2 meshes with the same number of | ||
| 114 | +// vertices. | ||
| 115 | +class ExampleController : public ConnectionTracker | ||
| 116 | +{ | ||
| 117 | +public: | ||
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * The example controller constructor. | ||
| 121 | + * @param[in] application The application instance | ||
| 122 | + */ | ||
| 123 | + ExampleController( Application& application ) | ||
| 124 | + : mApplication( application ) | ||
| 125 | + { | ||
| 126 | + // Connect to the Application's Init signal | ||
| 127 | + mApplication.InitSignal().Connect( this, &ExampleController::Create ); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * The example controller destructor | ||
| 132 | + */ | ||
| 133 | + ~ExampleController() | ||
| 134 | + { | ||
| 135 | + // Nothing to do here; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + /** | ||
| 139 | + * Invoked upon creation of application | ||
| 140 | + * @param[in] application The application instance | ||
| 141 | + */ | ||
| 142 | + void Create( Application& application ) | ||
| 143 | + { | ||
| 144 | + Stage stage = Stage::GetCurrent(); | ||
| 145 | + stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); | ||
| 146 | + | ||
| 147 | + mStageSize = stage.GetSize(); | ||
| 148 | + | ||
| 149 | + // The Init signal is received once (only) during the Application lifetime | ||
| 150 | + | ||
| 151 | + // Hide the indicator bar | ||
| 152 | + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); | ||
| 153 | + | ||
| 154 | + mImage = ResourceImage::New( MATERIAL_SAMPLE ); | ||
| 155 | + mSampler = Sampler::New(mImage, "sTexture"); | ||
| 156 | + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); | ||
| 157 | + | ||
| 158 | + mMaterial = Material::New( mShader ); | ||
| 159 | + mMaterial.AddSampler( mSampler ); | ||
| 160 | + | ||
| 161 | + mGeometry = CreateGeometry(); | ||
| 162 | + | ||
| 163 | + mRenderer = Renderer::New( mGeometry, mMaterial ); | ||
| 164 | + | ||
| 165 | + mMeshActor = Actor::New(); | ||
| 166 | + mMeshActor.AddRenderer( mRenderer ); | ||
| 167 | + mMeshActor.SetSize(200, 200); | ||
| 168 | + | ||
| 169 | + Property::Index morphAmountIndex = mMeshActor.RegisterProperty( "uMorphAmount", 0.0f ); | ||
| 170 | + | ||
| 171 | + mRenderer.SetDepthIndex(0); | ||
| 172 | + | ||
| 173 | + mMeshActor.SetParentOrigin( ParentOrigin::CENTER ); | ||
| 174 | + mMeshActor.SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 175 | + stage.Add( mMeshActor ); | ||
| 176 | + | ||
| 177 | + mChangeImageTimer = Timer::New( 5000 ); | ||
| 178 | + mChangeImageTimer.TickSignal().Connect( this, &ExampleController::OnTimer ); | ||
| 179 | + mChangeImageTimer.Start(); | ||
| 180 | + | ||
| 181 | + Animation animation = Animation::New(5); | ||
| 182 | + KeyFrames keyFrames = KeyFrames::New(); | ||
| 183 | + keyFrames.Add(0.0f, 0.0f); | ||
| 184 | + keyFrames.Add(1.0f, 1.0f); | ||
| 185 | + | ||
| 186 | + animation.AnimateBetween( Property( mMeshActor, morphAmountIndex ), keyFrames, AlphaFunction(AlphaFunction::SIN) ); | ||
| 187 | + animation.SetLooping(true); | ||
| 188 | + animation.Play(); | ||
| 189 | + | ||
| 190 | + stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));; | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + /** | ||
| 194 | + * Invoked whenever the quit button is clicked | ||
| 195 | + * @param[in] button the quit button | ||
| 196 | + */ | ||
| 197 | + bool OnQuitButtonClicked( Toolkit::Button button ) | ||
| 198 | + { | ||
| 199 | + // quit the application | ||
| 200 | + mApplication.Quit(); | ||
| 201 | + return true; | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + bool OnTimer() | ||
| 205 | + { | ||
| 206 | + Image image = ResourceImage::New( MATERIAL_SAMPLE2 ); | ||
| 207 | + mSampler.SetImage( image ); | ||
| 208 | + return false; | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + void OnKeyEvent(const KeyEvent& event) | ||
| 212 | + { | ||
| 213 | + if(event.state == KeyEvent::Down) | ||
| 214 | + { | ||
| 215 | + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) | ||
| 216 | + { | ||
| 217 | + mApplication.Quit(); | ||
| 218 | + } | ||
| 219 | + } | ||
| 220 | + } | ||
| 221 | + | ||
| 222 | +private: | ||
| 223 | + | ||
| 224 | + Application& mApplication; ///< Application instance | ||
| 225 | + Vector3 mStageSize; ///< The size of the stage | ||
| 226 | + | ||
| 227 | + Image mImage; | ||
| 228 | + Sampler mSampler; | ||
| 229 | + Shader mShader; | ||
| 230 | + Material mMaterial; | ||
| 231 | + Geometry mGeometry; | ||
| 232 | + Renderer mRenderer; | ||
| 233 | + Actor mMeshActor; | ||
| 234 | + Renderer mRenderer2; | ||
| 235 | + Actor mMeshActor2; | ||
| 236 | + Timer mChangeImageTimer; | ||
| 237 | +}; | ||
| 238 | + | ||
| 239 | +void RunTest( Application& application ) | ||
| 240 | +{ | ||
| 241 | + ExampleController test( application ); | ||
| 242 | + | ||
| 243 | + application.MainLoop(); | ||
| 244 | +} | ||
| 245 | + | ||
| 246 | +// Entry point for Linux & SLP applications | ||
| 247 | +// | ||
| 248 | +int main( int argc, char **argv ) | ||
| 249 | +{ | ||
| 250 | + Application application = Application::New( &argc, &argv ); | ||
| 251 | + | ||
| 252 | + RunTest( application ); | ||
| 253 | + | ||
| 254 | + return 0; | ||
| 255 | +} |
examples/mesh-morph/mesh-morph-example.cpp
0 โ 100644
| 1 | +/* | ||
| 2 | + * Copyright (c) 2014 Samsung Electronics Co., Ltd. | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + | ||
| 18 | +// EXTERNAL INCLUDES | ||
| 19 | +#include <dali/devel-api/rendering/renderer.h> | ||
| 20 | +#include <dali-toolkit/dali-toolkit.h> | ||
| 21 | + | ||
| 22 | +// INTERNAL INCLUDES | ||
| 23 | +#include "shared/view.h" | ||
| 24 | + | ||
| 25 | +using namespace Dali; | ||
| 26 | + | ||
| 27 | +namespace | ||
| 28 | +{ | ||
| 29 | + | ||
| 30 | +#define MAKE_SHADER(A)#A | ||
| 31 | + | ||
| 32 | +const char* VERTEX_SHADER = MAKE_SHADER( | ||
| 33 | +attribute mediump vec2 aInitPos; | ||
| 34 | +attribute mediump vec2 aFinalPos; | ||
| 35 | +attribute mediump vec3 aColor; | ||
| 36 | +uniform mediump mat4 uMvpMatrix; | ||
| 37 | +uniform mediump vec3 uSize; | ||
| 38 | +uniform mediump float uDelta; | ||
| 39 | +uniform lowp vec4 uColor; | ||
| 40 | +varying lowp vec4 vColor; | ||
| 41 | + | ||
| 42 | +void main() | ||
| 43 | +{ | ||
| 44 | + mediump vec4 vertexPosition = vec4(mix(aInitPos, aFinalPos, uDelta), 0.0, 1.0); | ||
| 45 | + vertexPosition.xyz *= uSize; | ||
| 46 | + vertexPosition = uMvpMatrix * vertexPosition; | ||
| 47 | + gl_Position = vertexPosition; | ||
| 48 | + vColor = vec4(aColor, 0.) * uColor; | ||
| 49 | +} | ||
| 50 | +); | ||
| 51 | + | ||
| 52 | +const char* FRAGMENT_SHADER = MAKE_SHADER( | ||
| 53 | +varying lowp vec4 vColor; | ||
| 54 | + | ||
| 55 | +void main() | ||
| 56 | +{ | ||
| 57 | + gl_FragColor = vColor; | ||
| 58 | +} | ||
| 59 | +); | ||
| 60 | + | ||
| 61 | +Geometry CreateGeometry() | ||
| 62 | +{ | ||
| 63 | + // Create vertices | ||
| 64 | + struct VertexPosition { Vector2 position; }; | ||
| 65 | + struct VertexColor { Vector3 color; }; | ||
| 66 | + | ||
| 67 | + VertexPosition quad[] = { | ||
| 68 | + // yellow | ||
| 69 | + { Vector2(-.5, -.5) }, | ||
| 70 | + { Vector2( .0, .0) }, | ||
| 71 | + { Vector2(-.5, .5) }, | ||
| 72 | + | ||
| 73 | + // green | ||
| 74 | + { Vector2(-.5, -.5) }, | ||
| 75 | + { Vector2( .5, -.5) }, | ||
| 76 | + { Vector2( .0, .0) }, | ||
| 77 | + | ||
| 78 | + // blue | ||
| 79 | + { Vector2(.5, -.5) }, | ||
| 80 | + { Vector2(.5, .0) }, | ||
| 81 | + { Vector2(.25, -.25) }, | ||
| 82 | + | ||
| 83 | + // red | ||
| 84 | + { Vector2(.25, -.25) }, | ||
| 85 | + { Vector2(.5, .0) }, | ||
| 86 | + { Vector2(.25, .25) }, | ||
| 87 | + { Vector2(.25, .25) }, | ||
| 88 | + { Vector2(.0, .0) }, | ||
| 89 | + { Vector2(.25, -.25) }, | ||
| 90 | + | ||
| 91 | + // cyan | ||
| 92 | + { Vector2( .0, .0) }, | ||
| 93 | + { Vector2( .25, .25) }, | ||
| 94 | + { Vector2(-.25, .25) }, | ||
| 95 | + | ||
| 96 | + // magenta | ||
| 97 | + { Vector2(-.25, .25) }, | ||
| 98 | + { Vector2( .25, .25) }, | ||
| 99 | + { Vector2( .0, .5) }, | ||
| 100 | + { Vector2( .0, .5) }, | ||
| 101 | + { Vector2(-.5, .5) }, | ||
| 102 | + { Vector2(-.25, .25) }, | ||
| 103 | + | ||
| 104 | + // orange | ||
| 105 | + { Vector2( .5, .0) }, | ||
| 106 | + { Vector2( .5, .5) }, | ||
| 107 | + { Vector2( .0, .5) }, | ||
| 108 | + }; | ||
| 109 | + | ||
| 110 | + float bigSide = 0.707106781; | ||
| 111 | + float side = bigSide * .5f; | ||
| 112 | + // float smallSide = side * .5f; | ||
| 113 | + | ||
| 114 | + Vector2 pA = Vector2( side, .25 ); | ||
| 115 | + Vector2 pB = pA + Vector2( 0., bigSide ); | ||
| 116 | + Vector2 pC = pB + Vector2( -bigSide, 0. ); | ||
| 117 | + Vector2 pD = pA + Vector2(-.5, -.5 ); | ||
| 118 | + Vector2 pE = pD + Vector2( .0, 1. ); | ||
| 119 | + Vector2 pF = pD + Vector2(-side, side ); | ||
| 120 | + Vector2 pF2 = pD + Vector2( 0., bigSide ); | ||
| 121 | + Vector2 pG = pD + Vector2(-.25, .25 ); | ||
| 122 | + Vector2 pH = pD + Vector2( -.5, .0 ); | ||
| 123 | + Vector2 pI = pD + Vector2(-.25, -.25 ); | ||
| 124 | + Vector2 pJ = pD + Vector2( 0., -.5); | ||
| 125 | + Vector2 pK = pD + Vector2(-.5, -.5); | ||
| 126 | + Vector2 pL = pB + Vector2(0, -side); | ||
| 127 | + Vector2 pM = pL + Vector2(side, -side); | ||
| 128 | + Vector2 pN = pB + Vector2(side, -side); | ||
| 129 | + | ||
| 130 | + VertexPosition cat[] = { | ||
| 131 | + // yellow | ||
| 132 | + { pA }, | ||
| 133 | + { pB }, | ||
| 134 | + { pC }, | ||
| 135 | + | ||
| 136 | + // green | ||
| 137 | + { pD }, | ||
| 138 | + { pA }, | ||
| 139 | + { pE }, | ||
| 140 | + | ||
| 141 | + // blue | ||
| 142 | + { pJ }, | ||
| 143 | + { pD }, | ||
| 144 | + { pI }, | ||
| 145 | + | ||
| 146 | + // red | ||
| 147 | + { pI }, | ||
| 148 | + { pD }, | ||
| 149 | + { pG }, | ||
| 150 | + { pG }, | ||
| 151 | + { pH }, | ||
| 152 | + { pI }, | ||
| 153 | + | ||
| 154 | + // cyan | ||
| 155 | + { pI }, | ||
| 156 | + { pH }, | ||
| 157 | + { pK }, | ||
| 158 | + | ||
| 159 | + // magenta | ||
| 160 | + { pL }, | ||
| 161 | + { pM }, | ||
| 162 | + { pN }, | ||
| 163 | + { pN }, | ||
| 164 | + { pB }, | ||
| 165 | + { pL }, | ||
| 166 | + | ||
| 167 | + // orange | ||
| 168 | + { pD }, | ||
| 169 | + { pF2 }, | ||
| 170 | + { pF }, | ||
| 171 | + }; | ||
| 172 | + | ||
| 173 | + VertexColor colors[] = { | ||
| 174 | + // yellow | ||
| 175 | + { Vector3( 1., 1., 0. ) }, | ||
| 176 | + { Vector3( 1., 1., 0. ) }, | ||
| 177 | + { Vector3( 1., 1., 0. ) }, | ||
| 178 | + | ||
| 179 | + // green | ||
| 180 | + { Vector3( 0., 1., 0. ) }, | ||
| 181 | + { Vector3( 0., 1., 0. ) }, | ||
| 182 | + { Vector3( 0., 1., 0. ) }, | ||
| 183 | + | ||
| 184 | + // blue | ||
| 185 | + { Vector3( 0., 0., 1. ) }, | ||
| 186 | + { Vector3( 0., 0., 1. ) }, | ||
| 187 | + { Vector3( 0., 0., 1. ) }, | ||
| 188 | + | ||
| 189 | + // red | ||
| 190 | + { Vector3( 1., 0., 0. ) }, | ||
| 191 | + { Vector3( 1., 0., 0. ) }, | ||
| 192 | + { Vector3( 1., 0., 0. ) }, | ||
| 193 | + { Vector3( 1., 0., 0. ) }, | ||
| 194 | + { Vector3( 1., 0., 0. ) }, | ||
| 195 | + { Vector3( 1., 0., 0. ) }, | ||
| 196 | + | ||
| 197 | + // cyan | ||
| 198 | + { Vector3( 0., 1., 1. ) }, | ||
| 199 | + { Vector3( 0., 1., 1. ) }, | ||
| 200 | + { Vector3( 0., 1., 1. ) }, | ||
| 201 | + | ||
| 202 | + // magenta | ||
| 203 | + { Vector3( 1., 0., 1. ) }, | ||
| 204 | + { Vector3( 1., 0., 1. ) }, | ||
| 205 | + { Vector3( 1., 0., 1. ) }, | ||
| 206 | + { Vector3( 1., 0., 1. ) }, | ||
| 207 | + { Vector3( 1., 0., 1. ) }, | ||
| 208 | + { Vector3( 1., 0., 1. ) }, | ||
| 209 | + | ||
| 210 | + // orange | ||
| 211 | + { Vector3( 1., 0.5, 0. ) }, | ||
| 212 | + { Vector3( 1., 0.5, 0. ) }, | ||
| 213 | + { Vector3( 1., 0.5, 0. ) }, | ||
| 214 | + | ||
| 215 | + }; | ||
| 216 | + | ||
| 217 | + unsigned int numberOfVertices = sizeof(quad)/sizeof(VertexPosition); | ||
| 218 | + | ||
| 219 | + Property::Map initialPositionVertexFormat; | ||
| 220 | + initialPositionVertexFormat["aInitPos"] = Property::VECTOR2; | ||
| 221 | + PropertyBuffer initialPositionVertices = PropertyBuffer::New( initialPositionVertexFormat, numberOfVertices ); | ||
| 222 | + initialPositionVertices.SetData(quad); | ||
| 223 | + | ||
| 224 | + Property::Map finalPositionVertexFormat; | ||
| 225 | + finalPositionVertexFormat["aFinalPos"] = Property::VECTOR2; | ||
| 226 | + PropertyBuffer finalPositionVertices = PropertyBuffer::New( finalPositionVertexFormat, numberOfVertices ); | ||
| 227 | + finalPositionVertices.SetData(cat); | ||
| 228 | + | ||
| 229 | + Property::Map colorVertexFormat; | ||
| 230 | + colorVertexFormat["aColor"] = Property::VECTOR3; | ||
| 231 | + PropertyBuffer colorVertices = PropertyBuffer::New( colorVertexFormat, numberOfVertices ); | ||
| 232 | + colorVertices.SetData(colors); | ||
| 233 | + | ||
| 234 | + // Create the geometry object | ||
| 235 | + Geometry texturedQuadGeometry = Geometry::New(); | ||
| 236 | + texturedQuadGeometry.AddVertexBuffer( initialPositionVertices ); | ||
| 237 | + texturedQuadGeometry.AddVertexBuffer( finalPositionVertices ); | ||
| 238 | + texturedQuadGeometry.AddVertexBuffer( colorVertices ); | ||
| 239 | + | ||
| 240 | + return texturedQuadGeometry; | ||
| 241 | +} | ||
| 242 | + | ||
| 243 | +inline float StationarySin( float progress ) ///< Single revolution | ||
| 244 | +{ | ||
| 245 | + float val = cosf(progress * 2.0f * Math::PI) + .5f; | ||
| 246 | + val = val > 1.f ? 1.f : val; | ||
| 247 | + val = val < 0.f ? 0.f : val; | ||
| 248 | + return val; | ||
| 249 | +} | ||
| 250 | + | ||
| 251 | +} // anonymous namespace | ||
| 252 | + | ||
| 253 | +// This example shows how to use a simple mesh | ||
| 254 | +// | ||
| 255 | +class ExampleController : public ConnectionTracker | ||
| 256 | +{ | ||
| 257 | +public: | ||
| 258 | + | ||
| 259 | + /** | ||
| 260 | + * The example controller constructor. | ||
| 261 | + * @param[in] application The application instance | ||
| 262 | + */ | ||
| 263 | + ExampleController( Application& application ) | ||
| 264 | + : mApplication( application ) | ||
| 265 | + { | ||
| 266 | + // Connect to the Application's Init signal | ||
| 267 | + mApplication.InitSignal().Connect( this, &ExampleController::Create ); | ||
| 268 | + } | ||
| 269 | + | ||
| 270 | + /** | ||
| 271 | + * The example controller destructor | ||
| 272 | + */ | ||
| 273 | + ~ExampleController() | ||
| 274 | + { | ||
| 275 | + // Nothing to do here; | ||
| 276 | + } | ||
| 277 | + | ||
| 278 | + /** | ||
| 279 | + * Invoked upon creation of application | ||
| 280 | + * @param[in] application The application instance | ||
| 281 | + */ | ||
| 282 | + void Create( Application& application ) | ||
| 283 | + { | ||
| 284 | + Stage stage = Stage::GetCurrent(); | ||
| 285 | + stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); | ||
| 286 | + | ||
| 287 | + mStageSize = stage.GetSize(); | ||
| 288 | + | ||
| 289 | + // The Init signal is received once (only) during the Application lifetime | ||
| 290 | + | ||
| 291 | + // Hide the indicator bar | ||
| 292 | + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); | ||
| 293 | + | ||
| 294 | + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); | ||
| 295 | + | ||
| 296 | + mMaterial = Material::New( mShader ); | ||
| 297 | + mGeometry = CreateGeometry(); | ||
| 298 | + | ||
| 299 | + mRenderer = Renderer::New( mGeometry, mMaterial ); | ||
| 300 | + | ||
| 301 | + mMeshActor = Actor::New(); | ||
| 302 | + mMeshActor.AddRenderer( mRenderer ); | ||
| 303 | + mMeshActor.SetSize(400, 400); | ||
| 304 | + | ||
| 305 | + Property::Index morphDeltaIndex = mMeshActor.RegisterProperty( "uDelta", 0.f ); | ||
| 306 | + | ||
| 307 | + mRenderer.SetDepthIndex(0); | ||
| 308 | + | ||
| 309 | + mMeshActor.SetParentOrigin( ParentOrigin::CENTER ); | ||
| 310 | + mMeshActor.SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 311 | + stage.Add( mMeshActor ); | ||
| 312 | + | ||
| 313 | + Animation animation = Animation::New(10); | ||
| 314 | + animation.AnimateTo( Property( mMeshActor, morphDeltaIndex ), 1.f, StationarySin ); | ||
| 315 | + animation.SetLooping( true ); | ||
| 316 | + animation.Play(); | ||
| 317 | + | ||
| 318 | + stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));; | ||
| 319 | + } | ||
| 320 | + | ||
| 321 | + /** | ||
| 322 | + * Invoked whenever the quit button is clicked | ||
| 323 | + * @param[in] button the quit button | ||
| 324 | + */ | ||
| 325 | + bool OnQuitButtonClicked( Toolkit::Button button ) | ||
| 326 | + { | ||
| 327 | + // quit the application | ||
| 328 | + mApplication.Quit(); | ||
| 329 | + return true; | ||
| 330 | + } | ||
| 331 | + | ||
| 332 | + void OnKeyEvent(const KeyEvent& event) | ||
| 333 | + { | ||
| 334 | + if(event.state == KeyEvent::Down) | ||
| 335 | + { | ||
| 336 | + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) | ||
| 337 | + { | ||
| 338 | + mApplication.Quit(); | ||
| 339 | + } | ||
| 340 | + } | ||
| 341 | + } | ||
| 342 | + | ||
| 343 | +private: | ||
| 344 | + | ||
| 345 | + Application& mApplication; ///< Application instance | ||
| 346 | + Vector3 mStageSize; ///< The size of the stage | ||
| 347 | + | ||
| 348 | + Shader mShader; | ||
| 349 | + Material mMaterial; | ||
| 350 | + Geometry mGeometry; | ||
| 351 | + Renderer mRenderer; | ||
| 352 | + Actor mMeshActor; | ||
| 353 | + Timer mMorphTimer; | ||
| 354 | +}; | ||
| 355 | + | ||
| 356 | +void RunTest( Application& application ) | ||
| 357 | +{ | ||
| 358 | + ExampleController test( application ); | ||
| 359 | + | ||
| 360 | + application.MainLoop(); | ||
| 361 | +} | ||
| 362 | + | ||
| 363 | +// Entry point for Linux & SLP applications | ||
| 364 | +// | ||
| 365 | +int main( int argc, char **argv ) | ||
| 366 | +{ | ||
| 367 | + Application application = Application::New( &argc, &argv ); | ||
| 368 | + | ||
| 369 | + RunTest( application ); | ||
| 370 | + | ||
| 371 | + return 0; | ||
| 372 | +} |
examples/mesh-sorting/mesh-sorting-example.cpp
0 โ 100644
| 1 | +/* | ||
| 2 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + | ||
| 18 | +// EXTERNAL INCLUDES | ||
| 19 | +#include <dali/devel-api/rendering/renderer.h> | ||
| 20 | +#include <dali-toolkit/dali-toolkit.h> | ||
| 21 | +#include <stdio.h> | ||
| 22 | +#include <sstream> | ||
| 23 | +#include <cstring> | ||
| 24 | + | ||
| 25 | +// INTERNAL INCLUDES | ||
| 26 | +#include "shared/view.h" | ||
| 27 | + | ||
| 28 | +using namespace Dali; | ||
| 29 | + | ||
| 30 | +namespace | ||
| 31 | +{ | ||
| 32 | + | ||
| 33 | +const char* MATERIAL_SAMPLES[] = | ||
| 34 | +{ | ||
| 35 | + DALI_IMAGE_DIR "people-medium-1.jpg", | ||
| 36 | + DALI_IMAGE_DIR "people-medium-4.jpg", | ||
| 37 | + DALI_IMAGE_DIR "people-medium-11.jpg", | ||
| 38 | + DALI_IMAGE_DIR "people-small-16.jpg", | ||
| 39 | + DALI_IMAGE_DIR "people-medium-15.jpg", | ||
| 40 | + DALI_IMAGE_DIR "people-medium-6.jpg", | ||
| 41 | +}; | ||
| 42 | +const unsigned int NUMBER_OF_SAMPLES(sizeof(MATERIAL_SAMPLES)/sizeof(const char*)); | ||
| 43 | + | ||
| 44 | + | ||
| 45 | +#define MAKE_SHADER(A)#A | ||
| 46 | + | ||
| 47 | +const char* VERTEX_SHADER = MAKE_SHADER( | ||
| 48 | +uniform highp float uHue; | ||
| 49 | +attribute mediump vec2 aPosition; | ||
| 50 | +attribute highp vec2 aTexCoord; | ||
| 51 | +varying mediump vec2 vTexCoord; | ||
| 52 | +uniform mediump mat4 uMvpMatrix; | ||
| 53 | +uniform mediump vec3 uSize; | ||
| 54 | +varying mediump vec3 vGlobColor; | ||
| 55 | + | ||
| 56 | +vec3 hsv2rgb(vec3 c) | ||
| 57 | +{ | ||
| 58 | + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); | ||
| 59 | + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); | ||
| 60 | + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +void main() | ||
| 64 | +{ | ||
| 65 | + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); | ||
| 66 | + vertexPosition.xyz *= uSize; | ||
| 67 | + vertexPosition = uMvpMatrix * vertexPosition; | ||
| 68 | + vGlobColor = hsv2rgb( vec3( clamp(uHue, 0.0, 1.0), 1.0, 1.0 ) ); | ||
| 69 | + | ||
| 70 | + vTexCoord = aTexCoord; | ||
| 71 | + gl_Position = vertexPosition; | ||
| 72 | +} | ||
| 73 | +); | ||
| 74 | + | ||
| 75 | +const char* FRAGMENT_SHADER = MAKE_SHADER( | ||
| 76 | +varying mediump vec2 vTexCoord; | ||
| 77 | +varying mediump vec3 vGlobColor; | ||
| 78 | +uniform lowp vec4 uColor; | ||
| 79 | +uniform sampler2D sTexture; | ||
| 80 | + | ||
| 81 | +void main() | ||
| 82 | +{ | ||
| 83 | + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * vec4(vGlobColor, 1.0) ; | ||
| 84 | +} | ||
| 85 | +); | ||
| 86 | + | ||
| 87 | +Geometry CreateGeometry() | ||
| 88 | +{ | ||
| 89 | + // Create vertices | ||
| 90 | + const float halfQuadSize = .5f; | ||
| 91 | + struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; | ||
| 92 | + TexturedQuadVertex texturedQuadVertexData[4] = { | ||
| 93 | + { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) }, | ||
| 94 | + { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) }, | ||
| 95 | + { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) }, | ||
| 96 | + { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } }; | ||
| 97 | + | ||
| 98 | + Property::Map texturedQuadVertexFormat; | ||
| 99 | + texturedQuadVertexFormat["aPosition"] = Property::VECTOR2; | ||
| 100 | + texturedQuadVertexFormat["aTexCoord"] = Property::VECTOR2; | ||
| 101 | + PropertyBuffer texturedQuadVertices = PropertyBuffer::New( texturedQuadVertexFormat, 4 ); | ||
| 102 | + texturedQuadVertices.SetData(texturedQuadVertexData); | ||
| 103 | + | ||
| 104 | + // Create indices | ||
| 105 | + unsigned int indexData[6] = { 0, 3, 1, 0, 2, 3 }; | ||
| 106 | + Property::Map indexFormat; | ||
| 107 | + indexFormat["indices"] = Property::UNSIGNED_INTEGER; | ||
| 108 | + PropertyBuffer indices = PropertyBuffer::New( indexFormat, 6 ); | ||
| 109 | + indices.SetData(indexData); | ||
| 110 | + | ||
| 111 | + // Create the geometry object | ||
| 112 | + Geometry texturedQuadGeometry = Geometry::New(); | ||
| 113 | + texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices ); | ||
| 114 | + texturedQuadGeometry.SetIndexBuffer( indices ); | ||
| 115 | + | ||
| 116 | + return texturedQuadGeometry; | ||
| 117 | +} | ||
| 118 | + | ||
| 119 | +} // anonymous namespace | ||
| 120 | + | ||
| 121 | +// This example shows how to use a simple mesh | ||
| 122 | +// | ||
| 123 | +class ExampleController : public ConnectionTracker | ||
| 124 | +{ | ||
| 125 | +public: | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * The example controller constructor. | ||
| 129 | + * @param[in] application The application instance | ||
| 130 | + */ | ||
| 131 | + ExampleController( Application& application ) | ||
| 132 | + : mApplication( application ), | ||
| 133 | + mZMode(0) | ||
| 134 | + { | ||
| 135 | + // Connect to the Application's Init signal | ||
| 136 | + mApplication.InitSignal().Connect( this, &ExampleController::Create ); | ||
| 137 | + memset(mDepthIndices, 0, sizeof(mDepthIndices)); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + /** | ||
| 141 | + * The example controller destructor | ||
| 142 | + */ | ||
| 143 | + ~ExampleController() | ||
| 144 | + { | ||
| 145 | + // Nothing to do here; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + /** | ||
| 149 | + * Invoked upon creation of application | ||
| 150 | + * @param[in] application The application instance | ||
| 151 | + */ | ||
| 152 | + void Create( Application& application ) | ||
| 153 | + { | ||
| 154 | + Stage stage = Stage::GetCurrent(); | ||
| 155 | + stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); | ||
| 156 | + | ||
| 157 | + mStageSize = stage.GetSize(); | ||
| 158 | + | ||
| 159 | + // The Init signal is received once (only) during the Application lifetime | ||
| 160 | + | ||
| 161 | + // Hide the indicator bar | ||
| 162 | + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); | ||
| 163 | + | ||
| 164 | + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); | ||
| 165 | + mGeometry = CreateGeometry(); | ||
| 166 | + | ||
| 167 | + Material firstMat; | ||
| 168 | + | ||
| 169 | + for( unsigned i=0; i<NUMBER_OF_SAMPLES; ++i) | ||
| 170 | + { | ||
| 171 | + Image image = ResourceImage::New( MATERIAL_SAMPLES[i] ); | ||
| 172 | + Sampler sampler = Sampler::New(image, "sTexture"); | ||
| 173 | + Material material = Material::New( mShader ); | ||
| 174 | + material.AddSampler( sampler ); | ||
| 175 | + if( i==0 ) { firstMat = material; } | ||
| 176 | + | ||
| 177 | + Renderer renderer = Renderer::New( mGeometry, material ); | ||
| 178 | + Actor meshActor = Actor::New(); | ||
| 179 | + mActors[i] = meshActor; | ||
| 180 | + meshActor.AddRenderer( renderer ); | ||
| 181 | + meshActor.SetSize(175, 175); | ||
| 182 | + meshActor.RegisterProperty("index", (int)i); | ||
| 183 | + | ||
| 184 | + renderer.SetDepthIndex(0); | ||
| 185 | + // Test with actor alpha | ||
| 186 | + meshActor.SetParentOrigin( ParentOrigin::CENTER ); | ||
| 187 | + meshActor.SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 188 | + meshActor.SetPosition( 40.0f*(i-(NUMBER_OF_SAMPLES*0.5f)), 40.0f*(i-(NUMBER_OF_SAMPLES*0.5f)), i*10 ); | ||
| 189 | + | ||
| 190 | + meshActor.SetOpacity( i%2?0.7f:1.0f ); | ||
| 191 | + | ||
| 192 | + meshActor.RegisterProperty("uHue", i/(float)NUMBER_OF_SAMPLES); | ||
| 193 | + | ||
| 194 | + meshActor.TouchedSignal().Connect(this, &ExampleController::OnTouched); | ||
| 195 | + std::ostringstream oss; | ||
| 196 | + oss << "Mesh Actor " << i; | ||
| 197 | + meshActor.SetName(oss.str()); | ||
| 198 | + stage.Add( meshActor ); | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + mActors[NUMBER_OF_SAMPLES-2].GetRendererAt(0).SetMaterial( firstMat ); | ||
| 202 | + | ||
| 203 | + stage.GetRootLayer().TouchedSignal().Connect(this, &ExampleController::OnStageTouched); | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + void PrintDepths() | ||
| 207 | + { | ||
| 208 | + switch( mZMode ) | ||
| 209 | + { | ||
| 210 | + case 0: | ||
| 211 | + { | ||
| 212 | + printf("Children Z ordered back to front\n"); | ||
| 213 | + break; | ||
| 214 | + } | ||
| 215 | + case 1: | ||
| 216 | + { | ||
| 217 | + printf("All children set to same Z=0\n"); | ||
| 218 | + break; | ||
| 219 | + } | ||
| 220 | + case 2: | ||
| 221 | + { | ||
| 222 | + printf("Children Z ordered front to back\n"); | ||
| 223 | + break; | ||
| 224 | + } | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + for( unsigned i=0; i<NUMBER_OF_SAMPLES; ++i) | ||
| 228 | + { | ||
| 229 | + printf("DepthIndex[%d]=%d\n", i, mDepthIndices[i]); | ||
| 230 | + } | ||
| 231 | + printf("\n"); | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + bool OnTouched( Actor actor, const TouchEvent& event ) | ||
| 235 | + { | ||
| 236 | + if( event.GetPoint(0).state == TouchPoint::Finished ) | ||
| 237 | + { | ||
| 238 | + int index = actor.GetProperty<int>(actor.GetPropertyIndex("index")); | ||
| 239 | + | ||
| 240 | + int newDepthIndex = (mDepthIndices[index] + 10) % 30; | ||
| 241 | + mDepthIndices[index] = newDepthIndex; | ||
| 242 | + | ||
| 243 | + Renderer renderer = actor.GetRendererAt(0); | ||
| 244 | + renderer.SetDepthIndex(newDepthIndex); | ||
| 245 | + | ||
| 246 | + PrintDepths(); | ||
| 247 | + } | ||
| 248 | + return true; | ||
| 249 | + } | ||
| 250 | + | ||
| 251 | + bool OnStageTouched( Actor rootLayer, const TouchEvent& event ) | ||
| 252 | + { | ||
| 253 | + if( event.GetPoint(0).state == TouchPoint::Finished ) | ||
| 254 | + { | ||
| 255 | + switch( mZMode ) | ||
| 256 | + { | ||
| 257 | + case 0: | ||
| 258 | + { | ||
| 259 | + mZMode = 1; | ||
| 260 | + for(unsigned int i=1; i < rootLayer.GetChildCount(); ++i) | ||
| 261 | + { | ||
| 262 | + Actor child = rootLayer.GetChildAt(i); | ||
| 263 | + child.SetZ( 0.0f ); | ||
| 264 | + } | ||
| 265 | + PrintDepths(); | ||
| 266 | + break; | ||
| 267 | + } | ||
| 268 | + case 1: | ||
| 269 | + { | ||
| 270 | + mZMode = 2; | ||
| 271 | + for(unsigned int i=1; i < rootLayer.GetChildCount(); ++i) | ||
| 272 | + { | ||
| 273 | + Actor child = rootLayer.GetChildAt(i); | ||
| 274 | + child.SetZ( 100-i*10 ); | ||
| 275 | + } | ||
| 276 | + PrintDepths(); | ||
| 277 | + break; | ||
| 278 | + } | ||
| 279 | + case 2: | ||
| 280 | + { | ||
| 281 | + mZMode = 0; | ||
| 282 | + for(unsigned int i=1; i < rootLayer.GetChildCount(); ++i) | ||
| 283 | + { | ||
| 284 | + Actor child = rootLayer.GetChildAt(i); | ||
| 285 | + child.SetZ( i*10 ); | ||
| 286 | + } | ||
| 287 | + PrintDepths(); | ||
| 288 | + break; | ||
| 289 | + } | ||
| 290 | + } | ||
| 291 | + } | ||
| 292 | + return true; | ||
| 293 | + } | ||
| 294 | + | ||
| 295 | + /** | ||
| 296 | + * Invoked whenever the quit button is clicked | ||
| 297 | + * @param[in] button the quit button | ||
| 298 | + */ | ||
| 299 | + bool OnQuitButtonClicked( Toolkit::Button button ) | ||
| 300 | + { | ||
| 301 | + // quit the application | ||
| 302 | + mApplication.Quit(); | ||
| 303 | + return true; | ||
| 304 | + } | ||
| 305 | + | ||
| 306 | + void OnKeyEvent(const KeyEvent& event) | ||
| 307 | + { | ||
| 308 | + if(event.state == KeyEvent::Down) | ||
| 309 | + { | ||
| 310 | + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) | ||
| 311 | + { | ||
| 312 | + mApplication.Quit(); | ||
| 313 | + } | ||
| 314 | + } | ||
| 315 | + } | ||
| 316 | + | ||
| 317 | +private: | ||
| 318 | + | ||
| 319 | + Application& mApplication; ///< Application instance | ||
| 320 | + Vector3 mStageSize; ///< The size of the stage | ||
| 321 | + | ||
| 322 | + Shader mShader; | ||
| 323 | + Geometry mGeometry; | ||
| 324 | + | ||
| 325 | + int mDepthIndices[NUMBER_OF_SAMPLES]; | ||
| 326 | + Actor mActors[NUMBER_OF_SAMPLES]; | ||
| 327 | + int mZMode; | ||
| 328 | +}; | ||
| 329 | + | ||
| 330 | +void RunTest( Application& application ) | ||
| 331 | +{ | ||
| 332 | + ExampleController test( application ); | ||
| 333 | + | ||
| 334 | + application.MainLoop(); | ||
| 335 | +} | ||
| 336 | + | ||
| 337 | +// Entry point for Linux & SLP applications | ||
| 338 | +// | ||
| 339 | +int main( int argc, char **argv ) | ||
| 340 | +{ | ||
| 341 | + Application application = Application::New( &argc, &argv ); | ||
| 342 | + | ||
| 343 | + RunTest( application ); | ||
| 344 | + | ||
| 345 | + return 0; | ||
| 346 | +} |
examples/motion-blur/motion-blur-example.cpp
| @@ -214,7 +214,12 @@ public: | @@ -214,7 +214,12 @@ public: | ||
| 214 | mContentLayer.Add( mMotionBlurImageActor ); | 214 | mContentLayer.Add( mMotionBlurImageActor ); |
| 215 | 215 | ||
| 216 | // Create shader used for doing motion blur | 216 | // Create shader used for doing motion blur |
| 217 | - mMotionBlurEffect = MotionBlurEffect::Apply(mMotionBlurImageActor); | 217 | + mMotionBlurEffect = Toolkit::CreateMotionBlurEffect(); |
| 218 | + Dali::Property::Index uModelProperty = mMotionBlurEffect.GetPropertyIndex( "uModelLastFrame" ); | ||
| 219 | + Constraint constraint = Constraint::New<Matrix>( mMotionBlurEffect, uModelProperty, EqualToConstraint() ); | ||
| 220 | + constraint.AddSource( Source( mMotionBlurImageActor , Actor::Property::WORLD_MATRIX ) ); | ||
| 221 | + constraint.Apply(); | ||
| 222 | + mMotionBlurImageActor.SetShaderEffect( mMotionBlurEffect ); | ||
| 218 | 223 | ||
| 219 | 224 | ||
| 220 | #ifdef MULTIPLE_MOTION_BLURRED_ACTORS | 225 | #ifdef MULTIPLE_MOTION_BLURRED_ACTORS |
| @@ -231,7 +236,7 @@ public: | @@ -231,7 +236,7 @@ public: | ||
| 231 | mMotionBlurImageActor.Add( mMotionBlurImageActor2 ); | 236 | mMotionBlurImageActor.Add( mMotionBlurImageActor2 ); |
| 232 | 237 | ||
| 233 | // Create shader used for doing motion blur | 238 | // Create shader used for doing motion blur |
| 234 | - mMotionBlurEffect2 = MotionBlurEffect::New(MOTION_BLUR_NUM_SAMPLES); | 239 | + mMotionBlurEffect2 = CreateMotionBlurEffect(MOTION_BLUR_NUM_SAMPLES); |
| 235 | 240 | ||
| 236 | // set actor shader to the blur one | 241 | // set actor shader to the blur one |
| 237 | mMotionBlurImageActor2.SetShaderEffect( mMotionBlurEffect2 ); | 242 | mMotionBlurImageActor2.SetShaderEffect( mMotionBlurEffect2 ); |
| @@ -249,7 +254,7 @@ public: | @@ -249,7 +254,7 @@ public: | ||
| 249 | mMotionBlurImageActor.Add( mMotionBlurImageActor3 ); | 254 | mMotionBlurImageActor.Add( mMotionBlurImageActor3 ); |
| 250 | 255 | ||
| 251 | // Create shader used for doing motion blur | 256 | // Create shader used for doing motion blur |
| 252 | - mMotionBlurEffect3 = MotionBlurEffect::New(MOTION_BLUR_NUM_SAMPLES); | 257 | + mMotionBlurEffect3 = CreateMotionBlurEffect(MOTION_BLUR_NUM_SAMPLES); |
| 253 | 258 | ||
| 254 | // set actor shader to the blur one | 259 | // set actor shader to the blur one |
| 255 | mMotionBlurImageActor3.SetShaderEffect( mMotionBlurEffect3 ); | 260 | mMotionBlurImageActor3.SetShaderEffect( mMotionBlurEffect3 ); |
| @@ -267,7 +272,7 @@ public: | @@ -267,7 +272,7 @@ public: | ||
| 267 | mMotionBlurImageActor.Add( mMotionBlurImageActor4 ); | 272 | mMotionBlurImageActor.Add( mMotionBlurImageActor4 ); |
| 268 | 273 | ||
| 269 | // Create shader used for doing motion blur | 274 | // Create shader used for doing motion blur |
| 270 | - mMotionBlurEffect4 = MotionBlurEffect::New(MOTION_BLUR_NUM_SAMPLES); | 275 | + mMotionBlurEffect4 = CreateMotionBlurEffect(MOTION_BLUR_NUM_SAMPLES); |
| 271 | 276 | ||
| 272 | // set actor shader to the blur one | 277 | // set actor shader to the blur one |
| 273 | mMotionBlurImageActor4.SetShaderEffect( mMotionBlurEffect4 ); | 278 | mMotionBlurImageActor4.SetShaderEffect( mMotionBlurEffect4 ); |
| @@ -285,7 +290,7 @@ public: | @@ -285,7 +290,7 @@ public: | ||
| 285 | mMotionBlurImageActor.Add( mMotionBlurImageActor5 ); | 290 | mMotionBlurImageActor.Add( mMotionBlurImageActor5 ); |
| 286 | 291 | ||
| 287 | // Create shader used for doing motion blur | 292 | // Create shader used for doing motion blur |
| 288 | - mMotionBlurEffect5 = MotionBlurEffect::New(MOTION_BLUR_NUM_SAMPLES); | 293 | + mMotionBlurEffect5 = CreateMotionBlurEffect(MOTION_BLUR_NUM_SAMPLES); |
| 289 | 294 | ||
| 290 | // set actor shader to the blur one | 295 | // set actor shader to the blur one |
| 291 | mMotionBlurImageActor5.SetShaderEffect( mMotionBlurEffect5 ); | 296 | mMotionBlurImageActor5.SetShaderEffect( mMotionBlurEffect5 ); |
| @@ -515,15 +520,15 @@ private: | @@ -515,15 +520,15 @@ private: | ||
| 515 | PushButton mActorEffectsButton; ///< The actor effects toggling Button. | 520 | PushButton mActorEffectsButton; ///< The actor effects toggling Button. |
| 516 | 521 | ||
| 517 | // Motion blur | 522 | // Motion blur |
| 518 | - MotionBlurEffect mMotionBlurEffect; | 523 | + ShaderEffect mMotionBlurEffect; |
| 519 | ImageActor mMotionBlurImageActor; | 524 | ImageActor mMotionBlurImageActor; |
| 520 | Size mMotionBlurActorSize; | 525 | Size mMotionBlurActorSize; |
| 521 | 526 | ||
| 522 | #ifdef MULTIPLE_MOTION_BLURRED_ACTORS | 527 | #ifdef MULTIPLE_MOTION_BLURRED_ACTORS |
| 523 | - MotionBlurEffect mMotionBlurEffect2; | ||
| 524 | - MotionBlurEffect mMotionBlurEffect3; | ||
| 525 | - MotionBlurEffect mMotionBlurEffect4; | ||
| 526 | - MotionBlurEffect mMotionBlurEffect5; | 528 | + ShaderEffect mMotionBlurEffect2; |
| 529 | + ShaderEffect mMotionBlurEffect3; | ||
| 530 | + ShaderEffect mMotionBlurEffect4; | ||
| 531 | + ShaderEffect mMotionBlurEffect5; | ||
| 527 | 532 | ||
| 528 | ImageActor mMotionBlurImageActor2; | 533 | ImageActor mMotionBlurImageActor2; |
| 529 | ImageActor mMotionBlurImageActor3; | 534 | ImageActor mMotionBlurImageActor3; |
examples/motion-stretch/motion-stretch-example.cpp
| @@ -184,7 +184,12 @@ public: | @@ -184,7 +184,12 @@ public: | ||
| 184 | mContentLayer.Add( mMotionStretchImageActor ); | 184 | mContentLayer.Add( mMotionStretchImageActor ); |
| 185 | 185 | ||
| 186 | // Create shader used for doing motion stretch | 186 | // Create shader used for doing motion stretch |
| 187 | - mMotionStretchEffect = MotionStretchEffect::Apply(mMotionStretchImageActor); | 187 | + mMotionStretchEffect = Toolkit::CreateMotionStretchEffect(); |
| 188 | + Dali::Property::Index uModelProperty = mMotionStretchEffect.GetPropertyIndex( "uModelLastFrame" ); | ||
| 189 | + Constraint constraint = Constraint::New<Matrix>( mMotionStretchEffect, uModelProperty, EqualToConstraint() ); | ||
| 190 | + constraint.AddSource( Source( mMotionStretchImageActor , Actor::Property::WORLD_MATRIX ) ); | ||
| 191 | + constraint.Apply(); | ||
| 192 | + mMotionStretchImageActor.SetShaderEffect( mMotionStretchEffect ); | ||
| 188 | } | 193 | } |
| 189 | 194 | ||
| 190 | ////////////////////////////////////////////////////////////// | 195 | ////////////////////////////////////////////////////////////// |
| @@ -408,7 +413,7 @@ private: | @@ -408,7 +413,7 @@ private: | ||
| 408 | PushButton mActorEffectsButton; ///< The actor effects toggling Button. | 413 | PushButton mActorEffectsButton; ///< The actor effects toggling Button. |
| 409 | 414 | ||
| 410 | // Motion stretch | 415 | // Motion stretch |
| 411 | - MotionStretchEffect mMotionStretchEffect; | 416 | + ShaderEffect mMotionStretchEffect; |
| 412 | ImageActor mMotionStretchImageActor; | 417 | ImageActor mMotionStretchImageActor; |
| 413 | 418 | ||
| 414 | // animate actor to position where user taps screen | 419 | // animate actor to position where user taps screen |
examples/new-window/new-window-example.cpp
| @@ -14,18 +14,17 @@ | @@ -14,18 +14,17 @@ | ||
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | +// EXTERNAL INCLUDES | ||
| 18 | +#include <dali/devel-api/rendering/renderer.h> | ||
| 17 | #include <dali-toolkit/dali-toolkit.h> | 19 | #include <dali-toolkit/dali-toolkit.h> |
| 18 | -#include <dali/devel-api/actors/mesh-actor.h> | ||
| 19 | -#include <dali/devel-api/modeling/material.h> | ||
| 20 | -#include <dali/devel-api/geometry/mesh.h> | ||
| 21 | #include <dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h> | 20 | #include <dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h> |
| 22 | -#include <dali-toolkit/devel-api/shader-effects/bubble-effect/color-adjuster.h> | ||
| 23 | 21 | ||
| 24 | - | ||
| 25 | -#include "shared/view.h" | ||
| 26 | #include <cstdio> | 22 | #include <cstdio> |
| 27 | #include <iostream> | 23 | #include <iostream> |
| 28 | 24 | ||
| 25 | +// INTERNAL INCLUDES | ||
| 26 | +#include "shared/view.h" | ||
| 27 | + | ||
| 29 | using namespace Dali; | 28 | using namespace Dali; |
| 30 | using namespace Dali::Toolkit; | 29 | using namespace Dali::Toolkit; |
| 31 | 30 | ||
| @@ -38,23 +37,76 @@ const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); | @@ -38,23 +37,76 @@ const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); | ||
| 38 | const char * const LOSE_CONTEXT_IMAGE( DALI_IMAGE_DIR "icon-cluster-wobble.png" ); | 37 | const char * const LOSE_CONTEXT_IMAGE( DALI_IMAGE_DIR "icon-cluster-wobble.png" ); |
| 39 | const char * const BASE_IMAGE( DALI_IMAGE_DIR "gallery-large-14.jpg" ); | 38 | const char * const BASE_IMAGE( DALI_IMAGE_DIR "gallery-large-14.jpg" ); |
| 40 | const char * const EFFECT_IMAGE( DALI_IMAGE_DIR "gallery-large-18.jpg" ); | 39 | const char * const EFFECT_IMAGE( DALI_IMAGE_DIR "gallery-large-18.jpg" ); |
| 40 | +const char * const LOGO_IMAGE(DALI_IMAGE_DIR "dali-logo.png"); | ||
| 41 | 41 | ||
| 42 | const float EXPLOSION_DURATION(1.2f); | 42 | const float EXPLOSION_DURATION(1.2f); |
| 43 | -const unsigned int EMIT_INTERVAL_IN_MS(80); | 43 | +const unsigned int EMIT_INTERVAL_IN_MS(40); |
| 44 | const float TRACK_DURATION_IN_MS(970); | 44 | const float TRACK_DURATION_IN_MS(970); |
| 45 | 45 | ||
| 46 | Application gApplication; | 46 | Application gApplication; |
| 47 | NewWindowController* gNewWindowController(NULL); | 47 | NewWindowController* gNewWindowController(NULL); |
| 48 | 48 | ||
| 49 | -const char*const FRAG_SHADER= | ||
| 50 | - "uniform mediump float alpha;\n" | ||
| 51 | - "\n" | ||
| 52 | - "void main()\n" | ||
| 53 | - "{\n" | ||
| 54 | - " mediump vec4 fragColor = texture2D(sTexture, vTexCoord);\n" | ||
| 55 | - " mediump vec4 fxColor = texture2D(sEffect, vTexCoord);\n" | ||
| 56 | - " gl_FragColor = mix(fragColor,fxColor, alpha);\n" | ||
| 57 | - "}\n"; | 49 | +#define MAKE_SHADER(A)#A |
| 50 | + | ||
| 51 | +const char* VERTEX_COLOR_MESH = MAKE_SHADER( | ||
| 52 | +attribute mediump vec3 aPosition;\n | ||
| 53 | +attribute lowp vec3 aColor;\n | ||
| 54 | +uniform mediump mat4 uMvpMatrix;\n | ||
| 55 | +uniform mediump vec3 uSize;\n | ||
| 56 | +varying lowp vec3 vColor;\n | ||
| 57 | +\n | ||
| 58 | +void main()\n | ||
| 59 | +{\n | ||
| 60 | + gl_Position = uMvpMatrix * vec4( aPosition*uSize, 1.0 );\n | ||
| 61 | + vColor = aColor;\n | ||
| 62 | +}\n | ||
| 63 | +); | ||
| 64 | + | ||
| 65 | +const char* FRAGMENT_COLOR_MESH = MAKE_SHADER( | ||
| 66 | +uniform lowp vec4 uColor;\n | ||
| 67 | +varying lowp vec3 vColor;\n | ||
| 68 | +\n | ||
| 69 | +void main()\n | ||
| 70 | +{\n | ||
| 71 | + gl_FragColor = vec4(vColor,1.0)*uColor; | ||
| 72 | +}\n | ||
| 73 | +); | ||
| 74 | + | ||
| 75 | +const char* VERTEX_TEXTURE_MESH = MAKE_SHADER( | ||
| 76 | +attribute mediump vec3 aPosition;\n | ||
| 77 | +attribute highp vec2 aTexCoord;\n | ||
| 78 | +uniform mediump mat4 uMvpMatrix;\n | ||
| 79 | +uniform mediump vec3 uSize;\n | ||
| 80 | +varying mediump vec2 vTexCoord;\n | ||
| 81 | +\n | ||
| 82 | +void main()\n | ||
| 83 | +{\n | ||
| 84 | + gl_Position = uMvpMatrix * vec4( aPosition*uSize, 1.0 );\n | ||
| 85 | + vTexCoord = aTexCoord;\n | ||
| 86 | +}\n | ||
| 87 | +); | ||
| 88 | + | ||
| 89 | +const char* FRAGMENT_TEXTURE_MESH = MAKE_SHADER( | ||
| 90 | +varying mediump vec2 vTexCoord;\n | ||
| 91 | +uniform lowp vec4 uColor;\n | ||
| 92 | +uniform sampler2D sTexture;\n | ||
| 93 | +\n | ||
| 94 | +void main()\n | ||
| 95 | +{\n | ||
| 96 | + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor; | ||
| 97 | +}\n | ||
| 98 | +); | ||
| 99 | + | ||
| 100 | +const char* FRAGMENT_BLEND_SHADER = MAKE_SHADER( | ||
| 101 | +uniform mediump float alpha;\n | ||
| 102 | +\n | ||
| 103 | +void main()\n | ||
| 104 | +{\n | ||
| 105 | + mediump vec4 fragColor = texture2D(sTexture, vTexCoord);\n | ||
| 106 | + mediump vec4 fxColor = texture2D(sEffect, vTexCoord);\n | ||
| 107 | + gl_FragColor = mix(fragColor,fxColor, alpha);\n | ||
| 108 | +}\n | ||
| 109 | +); | ||
| 58 | 110 | ||
| 59 | }; // anonymous namespace | 111 | }; // anonymous namespace |
| 60 | 112 | ||
| @@ -65,48 +117,39 @@ public: | @@ -65,48 +117,39 @@ public: | ||
| 65 | NewWindowController( Application& app ); | 117 | NewWindowController( Application& app ); |
| 66 | void Create( Application& app ); | 118 | void Create( Application& app ); |
| 67 | void Destroy( Application& app ); | 119 | void Destroy( Application& app ); |
| 68 | - void OnKeyEvent(const KeyEvent& event); | ||
| 69 | - bool OnLoseContextButtonClicked( Toolkit::Button button ); | ||
| 70 | - static void NewWindow(void); | ||
| 71 | 120 | ||
| 72 | - void OnContextLost(); | ||
| 73 | - void OnContextRegained(); | ||
| 74 | - void CreateMeshActor(); | ||
| 75 | - Mesh CreateMesh(bool, Material); | ||
| 76 | - void CreateBubbles(Vector2 stageSize); | ||
| 77 | - void CreateBlending(); | ||
| 78 | - void CreateText(); | ||
| 79 | - bool OnTrackTimerTick(); | ||
| 80 | - bool OnExplodeTimerTick(); | ||
| 81 | - void SetUpAnimation( Vector2 emitPosition, Vector2 direction ); | ||
| 82 | - FrameBufferImage CreateMirrorImage(const char* imageName); | 121 | + void AddBubbles(const Vector2& stageSize); |
| 122 | + void AddMeshActor(); | ||
| 123 | + void AddBlendingImageActor(); | ||
| 124 | + void AddTextLabel(); | ||
| 125 | + | ||
| 83 | ImageActor CreateBlurredMirrorImage(const char* imageName); | 126 | ImageActor CreateBlurredMirrorImage(const char* imageName); |
| 84 | FrameBufferImage CreateFrameBufferForImage(const char* imageName, Image image, ShaderEffect shaderEffect); | 127 | FrameBufferImage CreateFrameBufferForImage(const char* imageName, Image image, ShaderEffect shaderEffect); |
| 128 | + void SetUpBubbleEmission( const Vector2& emitPosition, const Vector2& direction ); | ||
| 129 | + Geometry CreateMeshGeometry(); | ||
| 130 | + ShaderEffect CreateColorModifierer( const Vector3& rgbDelta ); | ||
| 85 | 131 | ||
| 132 | + static void NewWindow(void); | ||
| 133 | + | ||
| 134 | + bool OnTrackTimerTick(); | ||
| 135 | + void OnKeyEvent(const KeyEvent& event); | ||
| 136 | + bool OnLoseContextButtonClicked( Toolkit::Button button ); | ||
| 137 | + void OnContextLost(); | ||
| 138 | + void OnContextRegained(); | ||
| 86 | 139 | ||
| 87 | private: | 140 | private: |
| 88 | Application mApplication; | 141 | Application mApplication; |
| 89 | - Actor mCastingLight; | ||
| 90 | TextLabel mTextActor; | 142 | TextLabel mTextActor; |
| 91 | - ImageActor mImageActor; | ||
| 92 | - ImageActor mBlendActor; | ||
| 93 | - Image mEffectImage; | ||
| 94 | - Image mBaseImage; | ||
| 95 | - MeshActor mMeshActor; | ||
| 96 | - MeshActor mAnimatedMeshActor; | ||
| 97 | 143 | ||
| 98 | Toolkit::Control mView; ///< The View instance. | 144 | Toolkit::Control mView; ///< The View instance. |
| 99 | Toolkit::ToolBar mToolBar; ///< The View's Toolbar. | 145 | Toolkit::ToolBar mToolBar; ///< The View's Toolbar. |
| 100 | - TextLabel mTitleActor; ///< The Toolbar's Title. | 146 | + TextLabel mTitleActor; ///< The Toolbar's Title. |
| 101 | Layer mContentLayer; ///< Content layer (scrolling cluster content) | 147 | Layer mContentLayer; ///< Content layer (scrolling cluster content) |
| 102 | Toolkit::PushButton mLoseContextButton; | 148 | Toolkit::PushButton mLoseContextButton; |
| 103 | - Vector3 mHSVDelta; | ||
| 104 | - Toolkit::BubbleEmitter mEmitter; | ||
| 105 | 149 | ||
| 150 | + Toolkit::BubbleEmitter mEmitter; | ||
| 106 | Timer mEmitTrackTimer; | 151 | Timer mEmitTrackTimer; |
| 107 | - Timer mExplodeTimer; | ||
| 108 | bool mNeedNewAnimation; | 152 | bool mNeedNewAnimation; |
| 109 | - | ||
| 110 | unsigned int mAnimateComponentCount; | 153 | unsigned int mAnimateComponentCount; |
| 111 | Animation mEmitAnimation; | 154 | Animation mEmitAnimation; |
| 112 | }; | 155 | }; |
| @@ -114,7 +157,6 @@ private: | @@ -114,7 +157,6 @@ private: | ||
| 114 | 157 | ||
| 115 | NewWindowController::NewWindowController( Application& application ) | 158 | NewWindowController::NewWindowController( Application& application ) |
| 116 | : mApplication(application), | 159 | : mApplication(application), |
| 117 | - mHSVDelta(0.5f, 0.0f, 0.5f), | ||
| 118 | mNeedNewAnimation(true) | 160 | mNeedNewAnimation(true) |
| 119 | { | 161 | { |
| 120 | mApplication.InitSignal().Connect(this, &NewWindowController::Create); | 162 | mApplication.InitSignal().Connect(this, &NewWindowController::Create); |
| @@ -136,10 +178,17 @@ void NewWindowController::Create( Application& app ) | @@ -136,10 +178,17 @@ void NewWindowController::Create( Application& app ) | ||
| 136 | mContentLayer = DemoHelper::CreateView( app, | 178 | mContentLayer = DemoHelper::CreateView( app, |
| 137 | mView, | 179 | mView, |
| 138 | mToolBar, | 180 | mToolBar, |
| 139 | - BACKGROUND_IMAGE, | 181 | + "", |
| 140 | TOOLBAR_IMAGE, | 182 | TOOLBAR_IMAGE, |
| 141 | "Context recovery" ); | 183 | "Context recovery" ); |
| 142 | 184 | ||
| 185 | + Size stageSize = stage.GetSize(); | ||
| 186 | + Image backgroundImage = ResourceImage::New( BACKGROUND_IMAGE, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); | ||
| 187 | + ImageActor backgroundActor = ImageActor::New( backgroundImage ); | ||
| 188 | + backgroundActor.SetParentOrigin( ParentOrigin::CENTER ); | ||
| 189 | + backgroundActor.SetZ(-2.f); | ||
| 190 | + mContentLayer.Add(backgroundActor); | ||
| 191 | + | ||
| 143 | // Point the default render task at the view | 192 | // Point the default render task at the view |
| 144 | RenderTaskList taskList = stage.GetRenderTaskList(); | 193 | RenderTaskList taskList = stage.GetRenderTaskList(); |
| 145 | RenderTask defaultTask = taskList.GetTask( 0u ); | 194 | RenderTask defaultTask = taskList.GetTask( 0u ); |
| @@ -153,29 +202,28 @@ void NewWindowController::Create( Application& app ) | @@ -153,29 +202,28 @@ void NewWindowController::Create( Application& app ) | ||
| 153 | mLoseContextButton.ClickedSignal().Connect( this, &NewWindowController::OnLoseContextButtonClicked ); | 202 | mLoseContextButton.ClickedSignal().Connect( this, &NewWindowController::OnLoseContextButtonClicked ); |
| 154 | mToolBar.AddControl( mLoseContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); | 203 | mToolBar.AddControl( mLoseContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); |
| 155 | 204 | ||
| 156 | - | ||
| 157 | Actor logoLayoutActor = Actor::New(); | 205 | Actor logoLayoutActor = Actor::New(); |
| 158 | logoLayoutActor.SetParentOrigin(ParentOrigin::CENTER); | 206 | logoLayoutActor.SetParentOrigin(ParentOrigin::CENTER); |
| 159 | logoLayoutActor.SetPosition(0.0f, -200.0f, 0.0f); | 207 | logoLayoutActor.SetPosition(0.0f, -200.0f, 0.0f); |
| 160 | logoLayoutActor.SetScale(0.5f); | 208 | logoLayoutActor.SetScale(0.5f); |
| 161 | mContentLayer.Add(logoLayoutActor); | 209 | mContentLayer.Add(logoLayoutActor); |
| 162 | 210 | ||
| 163 | - Image image = ResourceImage::New(DALI_IMAGE_DIR "dali-logo.png"); | ||
| 164 | - mImageActor = ImageActor::New(image); | ||
| 165 | - mImageActor.SetName("dali-logo"); | ||
| 166 | - mImageActor.SetParentOrigin(ParentOrigin::CENTER); | ||
| 167 | - mImageActor.SetAnchorPoint(AnchorPoint::BOTTOM_CENTER); | ||
| 168 | - logoLayoutActor.Add(mImageActor); | 211 | + Image image = ResourceImage::New(LOGO_IMAGE); |
| 212 | + ImageActor imageActor = ImageActor::New(image); | ||
| 213 | + imageActor.SetName("dali-logo"); | ||
| 214 | + imageActor.SetParentOrigin(ParentOrigin::CENTER); | ||
| 215 | + imageActor.SetAnchorPoint(AnchorPoint::BOTTOM_CENTER); | ||
| 216 | + logoLayoutActor.Add(imageActor); | ||
| 169 | 217 | ||
| 170 | - ImageActor mirrorImageActor = CreateBlurredMirrorImage(DALI_IMAGE_DIR "dali-logo.png"); | 218 | + ImageActor mirrorImageActor = CreateBlurredMirrorImage(LOGO_IMAGE); |
| 171 | mirrorImageActor.SetParentOrigin(ParentOrigin::CENTER); | 219 | mirrorImageActor.SetParentOrigin(ParentOrigin::CENTER); |
| 172 | mirrorImageActor.SetAnchorPoint(AnchorPoint::TOP_CENTER); | 220 | mirrorImageActor.SetAnchorPoint(AnchorPoint::TOP_CENTER); |
| 173 | logoLayoutActor.Add(mirrorImageActor); | 221 | logoLayoutActor.Add(mirrorImageActor); |
| 174 | 222 | ||
| 175 | - CreateBubbles(stage.GetSize()); | ||
| 176 | - CreateMeshActor(); | ||
| 177 | - CreateBlending(); | ||
| 178 | - CreateText(); | 223 | + AddBubbles(stage.GetSize()); |
| 224 | + AddMeshActor(); | ||
| 225 | + AddBlendingImageActor(); | ||
| 226 | + AddTextLabel(); | ||
| 179 | 227 | ||
| 180 | stage.ContextLostSignal().Connect(this, &NewWindowController::OnContextLost); | 228 | stage.ContextLostSignal().Connect(this, &NewWindowController::OnContextLost); |
| 181 | stage.ContextRegainedSignal().Connect(this, &NewWindowController::OnContextRegained); | 229 | stage.ContextRegainedSignal().Connect(this, &NewWindowController::OnContextRegained); |
| @@ -186,51 +234,109 @@ void NewWindowController::Destroy( Application& app ) | @@ -186,51 +234,109 @@ void NewWindowController::Destroy( Application& app ) | ||
| 186 | UnparentAndReset(mTextActor); | 234 | UnparentAndReset(mTextActor); |
| 187 | } | 235 | } |
| 188 | 236 | ||
| 189 | -bool NewWindowController::OnLoseContextButtonClicked( Toolkit::Button button ) | 237 | +void NewWindowController::AddBubbles(const Vector2& stageSize) |
| 190 | { | 238 | { |
| 191 | - // Add as an idle callback to avoid ProcessEvents being recursively called. | ||
| 192 | - mApplication.AddIdle( MakeCallback( NewWindowController::NewWindow ) ); | ||
| 193 | - return true; | 239 | + mEmitter = Toolkit::BubbleEmitter::New( stageSize, |
| 240 | + ResourceImage::New( DALI_IMAGE_DIR "bubble-ball.png" ), | ||
| 241 | + 200, Vector2( 5.0f, 5.0f ) ); | ||
| 242 | + | ||
| 243 | + Image background = ResourceImage::New(BACKGROUND_IMAGE); | ||
| 244 | + mEmitter.SetBackground( background, Vector3(0.5f, 0.f,0.5f) ); | ||
| 245 | + mEmitter.SetBubbleDensity( 9.f ); | ||
| 246 | + Actor bubbleRoot = mEmitter.GetRootActor(); | ||
| 247 | + mContentLayer.Add( bubbleRoot ); | ||
| 248 | + bubbleRoot.SetParentOrigin(ParentOrigin::CENTER); | ||
| 249 | + bubbleRoot.SetZ(0.1f); | ||
| 250 | + | ||
| 251 | + mEmitTrackTimer = Timer::New( EMIT_INTERVAL_IN_MS ); | ||
| 252 | + mEmitTrackTimer.TickSignal().Connect(this, &NewWindowController::OnTrackTimerTick); | ||
| 253 | + mEmitTrackTimer.Start(); | ||
| 194 | } | 254 | } |
| 195 | 255 | ||
| 196 | -void NewWindowController::CreateMeshActor() | 256 | +void NewWindowController::AddMeshActor() |
| 197 | { | 257 | { |
| 198 | - mEffectImage = ResourceImage::New(EFFECT_IMAGE); | ||
| 199 | - | ||
| 200 | - Material baseMaterial = Material::New( "Material1" ); | ||
| 201 | - Dali::MeshActor meshActor = MeshActor::New( CreateMesh(true, baseMaterial) ); | ||
| 202 | - meshActor.SetScale( 100.0f ); | ||
| 203 | - meshActor.SetParentOrigin( ParentOrigin::CENTER ); | ||
| 204 | - meshActor.SetPosition(Vector3( -150.0f, 200.0f, 0.0f )); | ||
| 205 | - meshActor.SetName("MeshActor"); | ||
| 206 | - mContentLayer.Add( meshActor ); | ||
| 207 | - | ||
| 208 | - Material orchidMaterial = Material::New( "Material2" ); | ||
| 209 | - orchidMaterial.SetDiffuseTexture(mEffectImage); | ||
| 210 | - | ||
| 211 | - Dali::MeshActor meshActor2 = MeshActor::New( CreateMesh(false, orchidMaterial) ); | ||
| 212 | - meshActor2.SetScale( 100.0f ); | ||
| 213 | - meshActor2.SetParentOrigin( ParentOrigin::CENTER ); | ||
| 214 | - meshActor2.SetPosition(Vector3( -150.0f, 310.0f, 0.0f )); | ||
| 215 | - meshActor2.SetName("MeshActor"); | ||
| 216 | - mContentLayer.Add( meshActor2 ); | 258 | + Geometry meshGeometry = CreateMeshGeometry(); |
| 259 | + | ||
| 260 | + // Create a coloured mesh | ||
| 261 | + Shader shaderColorMesh = Shader::New( VERTEX_COLOR_MESH, FRAGMENT_COLOR_MESH ); | ||
| 262 | + Material colorMeshmaterial = Material::New( shaderColorMesh ); | ||
| 263 | + Renderer colorMeshRenderer = Renderer::New( meshGeometry, colorMeshmaterial ); | ||
| 264 | + | ||
| 265 | + Actor colorMeshActor = Actor::New(); | ||
| 266 | + colorMeshActor.AddRenderer( colorMeshRenderer ); | ||
| 267 | + colorMeshActor.SetSize( 175.f,175.f ); | ||
| 268 | + colorMeshActor.SetParentOrigin( ParentOrigin::CENTER ); | ||
| 269 | + colorMeshActor.SetAnchorPoint(AnchorPoint::TOP_CENTER); | ||
| 270 | + colorMeshActor.SetPosition(Vector3(0.0f, 50.0f, 0.0f)); | ||
| 271 | + colorMeshActor.SetOrientation( Degree(75.f), Vector3::XAXIS ); | ||
| 272 | + colorMeshActor.SetName("ColorMeshActor"); | ||
| 273 | + mContentLayer.Add( colorMeshActor ); | ||
| 274 | + | ||
| 275 | + // Create a textured mesh | ||
| 276 | + Image effectImage = ResourceImage::New(EFFECT_IMAGE); | ||
| 277 | + Sampler sampler = Sampler::New(effectImage, "sTexture"); | ||
| 278 | + | ||
| 279 | + Shader shaderTextureMesh = Shader::New( VERTEX_TEXTURE_MESH, FRAGMENT_TEXTURE_MESH ); | ||
| 280 | + Material textureMeshMaterial = Material::New( shaderTextureMesh ); | ||
| 281 | + textureMeshMaterial.AddSampler( sampler ); | ||
| 282 | + Renderer textureMeshRenderer = Renderer::New( meshGeometry, textureMeshMaterial ); | ||
| 283 | + | ||
| 284 | + Actor textureMeshActor = Actor::New(); | ||
| 285 | + textureMeshActor.AddRenderer( textureMeshRenderer ); | ||
| 286 | + textureMeshActor.SetSize( 175.f,175.f ); | ||
| 287 | + textureMeshActor.SetParentOrigin( ParentOrigin::CENTER ); | ||
| 288 | + textureMeshActor.SetAnchorPoint(AnchorPoint::TOP_CENTER); | ||
| 289 | + textureMeshActor.SetPosition(Vector3(0.0f, 200.0f, 0.0f)); | ||
| 290 | + textureMeshActor.SetOrientation( Degree(75.f), Vector3::XAXIS ); | ||
| 291 | + textureMeshActor.SetName("TextureMeshActor"); | ||
| 292 | + mContentLayer.Add( textureMeshActor ); | ||
| 217 | } | 293 | } |
| 218 | 294 | ||
| 219 | -FrameBufferImage NewWindowController::CreateMirrorImage(const char* imageName) | 295 | +void NewWindowController::AddBlendingImageActor() |
| 220 | { | 296 | { |
| 221 | - FrameBufferImage fbo; | ||
| 222 | - Image image = ResourceImage::New(imageName); | ||
| 223 | - fbo = CreateFrameBufferForImage(imageName, image, ShaderEffect()); | ||
| 224 | - return fbo; | 297 | + ShaderEffect colorModifier = CreateColorModifierer(Vector3( 0.5f, 0.5f, 0.5f )); |
| 298 | + Image effectImage = ResourceImage::New(EFFECT_IMAGE); | ||
| 299 | + FrameBufferImage fb2 = CreateFrameBufferForImage( EFFECT_IMAGE, effectImage, colorModifier ); | ||
| 300 | + | ||
| 301 | + ImageActor tmpActor = ImageActor::New(fb2); | ||
| 302 | + mContentLayer.Add(tmpActor); | ||
| 303 | + tmpActor.SetParentOrigin(ParentOrigin::CENTER_RIGHT); | ||
| 304 | + tmpActor.SetAnchorPoint(AnchorPoint::TOP_RIGHT); | ||
| 305 | + tmpActor.SetPosition(Vector3(0.0f, 150.0f, 0.0f)); | ||
| 306 | + tmpActor.SetScale(0.25f); | ||
| 307 | + | ||
| 308 | + // create blending shader effect | ||
| 309 | + ShaderEffect blendShader = ShaderEffect::New( "", FRAGMENT_BLEND_SHADER ); | ||
| 310 | + blendShader.SetEffectImage( fb2 ); | ||
| 311 | + blendShader.SetUniform("alpha", 0.5f); | ||
| 312 | + | ||
| 313 | + Image baseImage = ResourceImage::New(BASE_IMAGE); | ||
| 314 | + ImageActor blendActor = ImageActor::New( baseImage ); | ||
| 315 | + blendActor.SetParentOrigin(ParentOrigin::CENTER_RIGHT); | ||
| 316 | + blendActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT); | ||
| 317 | + blendActor.SetPosition(Vector3(0.0f, 100.0f, 0.0f)); | ||
| 318 | + blendActor.SetSize(140, 140); | ||
| 319 | + blendActor.SetShaderEffect( blendShader ); | ||
| 320 | + mContentLayer.Add(blendActor); | ||
| 321 | +} | ||
| 322 | + | ||
| 323 | +void NewWindowController::AddTextLabel() | ||
| 324 | +{ | ||
| 325 | + mTextActor = TextLabel::New("Some text"); | ||
| 326 | + mTextActor.SetParentOrigin(ParentOrigin::CENTER); | ||
| 327 | + mTextActor.SetColor(Color::RED); | ||
| 328 | + mTextActor.SetName("PushMe text"); | ||
| 329 | + mContentLayer.Add( mTextActor ); | ||
| 225 | } | 330 | } |
| 226 | 331 | ||
| 227 | ImageActor NewWindowController::CreateBlurredMirrorImage(const char* imageName) | 332 | ImageActor NewWindowController::CreateBlurredMirrorImage(const char* imageName) |
| 228 | { | 333 | { |
| 229 | - FrameBufferImage fbo; | ||
| 230 | Image image = ResourceImage::New(imageName); | 334 | Image image = ResourceImage::New(imageName); |
| 335 | + | ||
| 231 | Uint16Pair intFboSize = ResourceImage::GetImageSize(imageName); | 336 | Uint16Pair intFboSize = ResourceImage::GetImageSize(imageName); |
| 232 | Vector2 FBOSize = Vector2( intFboSize.GetWidth(), intFboSize.GetHeight() ); | 337 | Vector2 FBOSize = Vector2( intFboSize.GetWidth(), intFboSize.GetHeight() ); |
| 233 | - fbo = FrameBufferImage::New( FBOSize.width, FBOSize.height, Pixel::RGBA8888); | 338 | + FrameBufferImage fbo = FrameBufferImage::New( FBOSize.width, FBOSize.height, Pixel::RGBA8888); |
| 339 | + | ||
| 234 | GaussianBlurView gbv = GaussianBlurView::New(5, 2.0f, Pixel::RGBA8888, 0.5f, 0.5f, true); | 340 | GaussianBlurView gbv = GaussianBlurView::New(5, 2.0f, Pixel::RGBA8888, 0.5f, 0.5f, true); |
| 235 | gbv.SetBackgroundColor(Color::TRANSPARENT); | 341 | gbv.SetBackgroundColor(Color::TRANSPARENT); |
| 236 | gbv.SetUserImageAndOutputRenderTarget( image, fbo ); | 342 | gbv.SetUserImageAndOutputRenderTarget( image, fbo ); |
| @@ -285,38 +391,7 @@ FrameBufferImage NewWindowController::CreateFrameBufferForImage(const char* imag | @@ -285,38 +391,7 @@ FrameBufferImage NewWindowController::CreateFrameBufferForImage(const char* imag | ||
| 285 | return framebuffer; | 391 | return framebuffer; |
| 286 | } | 392 | } |
| 287 | 393 | ||
| 288 | -void NewWindowController::CreateBubbles(Vector2 stageSize) | ||
| 289 | -{ | ||
| 290 | - mEmitter = Toolkit::BubbleEmitter::New( stageSize, | ||
| 291 | - ResourceImage::New( DALI_IMAGE_DIR "bubble-ball.png" ), | ||
| 292 | - 1000, Vector2( 5.0f, 5.0f ) ); | ||
| 293 | - | ||
| 294 | - Image background = ResourceImage::New(BACKGROUND_IMAGE); | ||
| 295 | - mEmitter.SetBackground( background, mHSVDelta ); | ||
| 296 | - Actor bubbleRoot = mEmitter.GetRootActor(); | ||
| 297 | - mContentLayer.Add( bubbleRoot ); | ||
| 298 | - bubbleRoot.SetParentOrigin(ParentOrigin::CENTER); | ||
| 299 | - bubbleRoot.SetZ(0.1f); | ||
| 300 | - | ||
| 301 | - mEmitTrackTimer = Timer::New( EMIT_INTERVAL_IN_MS ); | ||
| 302 | - mEmitTrackTimer.TickSignal().Connect(this, &NewWindowController::OnTrackTimerTick); | ||
| 303 | - mEmitTrackTimer.Start(); | ||
| 304 | - | ||
| 305 | - //mExplodeTimer = Timer::New( Random::Range(4000.f, 8000.f) ); | ||
| 306 | - //mExplodeTimer.TickSignal().Connect(this, &NewWindowController::OnExplodeTimerTick); | ||
| 307 | - //mExplodeTimer.Start(); | ||
| 308 | -} | ||
| 309 | - | ||
| 310 | -bool NewWindowController::OnExplodeTimerTick() | ||
| 311 | -{ | ||
| 312 | - mEmitter.StartExplosion( EXPLOSION_DURATION, 5.0f ); | ||
| 313 | - | ||
| 314 | - mExplodeTimer = Timer::New( Random::Range(4.f, 8.f) ); | ||
| 315 | - mExplodeTimer.TickSignal().Connect(this, &NewWindowController::OnExplodeTimerTick); | ||
| 316 | - return false; | ||
| 317 | -} | ||
| 318 | - | ||
| 319 | -void NewWindowController::SetUpAnimation( Vector2 emitPosition, Vector2 direction ) | 394 | +void NewWindowController::SetUpBubbleEmission( const Vector2& emitPosition, const Vector2& direction) |
| 320 | { | 395 | { |
| 321 | if( mNeedNewAnimation ) | 396 | if( mNeedNewAnimation ) |
| 322 | { | 397 | { |
| @@ -326,17 +401,97 @@ void NewWindowController::SetUpAnimation( Vector2 emitPosition, Vector2 directio | @@ -326,17 +401,97 @@ void NewWindowController::SetUpAnimation( Vector2 emitPosition, Vector2 directio | ||
| 326 | mAnimateComponentCount = 0; | 401 | mAnimateComponentCount = 0; |
| 327 | } | 402 | } |
| 328 | 403 | ||
| 329 | - mEmitter.EmitBubble( mEmitAnimation, emitPosition, direction, Vector2(1, 1) ); | 404 | + mEmitter.EmitBubble( mEmitAnimation, emitPosition, direction, Vector2(10,10) ); |
| 330 | 405 | ||
| 331 | mAnimateComponentCount++; | 406 | mAnimateComponentCount++; |
| 332 | 407 | ||
| 333 | - if( mAnimateComponentCount % 20 ==0 ) | 408 | + if( mAnimateComponentCount % 6 ==0 ) |
| 334 | { | 409 | { |
| 335 | mEmitAnimation.Play(); | 410 | mEmitAnimation.Play(); |
| 336 | mNeedNewAnimation = true; | 411 | mNeedNewAnimation = true; |
| 337 | } | 412 | } |
| 338 | } | 413 | } |
| 339 | 414 | ||
| 415 | +Geometry NewWindowController::CreateMeshGeometry() | ||
| 416 | +{ | ||
| 417 | + // Create vertices and specify their color | ||
| 418 | + struct Vertex | ||
| 419 | + { | ||
| 420 | + Vector3 position; | ||
| 421 | + Vector2 textureCoordinates; | ||
| 422 | + Vector3 color; | ||
| 423 | + }; | ||
| 424 | + | ||
| 425 | + Vertex vertexData[5] = { | ||
| 426 | + { Vector3( 0.0f, 0.0f, 0.5f ), Vector2(0.5f, 0.5f), Vector3(1.0f, 1.0f, 1.0f) }, | ||
| 427 | + { Vector3( -0.5f, -0.5f, 0.0f ), Vector2(0.0f, 0.0f), Vector3(1.0f, 0.0f, 0.0f) }, | ||
| 428 | + { Vector3( 0.5f, -0.5f, 0.0f ), Vector2(1.0f, 0.0f), Vector3(1.0f, 1.0f, 0.0f) }, | ||
| 429 | + { Vector3( -0.5f, 0.5f, 0.0f ), Vector2(0.0f, 1.0f), Vector3(0.0f, 1.0f, 0.0f) }, | ||
| 430 | + { Vector3( 0.5f, 0.5f, 0.0f ), Vector2(1.0f, 1.0f), Vector3(0.0f, 0.0f, 1.0f) } }; | ||
| 431 | + | ||
| 432 | + Property::Map vertexFormat; | ||
| 433 | + vertexFormat["aPosition"] = Property::VECTOR3; | ||
| 434 | + vertexFormat["aTexCoord"] = Property::VECTOR2; | ||
| 435 | + vertexFormat["aColor"] = Property::VECTOR3; | ||
| 436 | + PropertyBuffer vertices = PropertyBuffer::New( vertexFormat, 5 ); | ||
| 437 | + vertices.SetData( vertexData ); | ||
| 438 | + | ||
| 439 | + // Specify all the faces | ||
| 440 | + unsigned int indexData[12] = { 0,1,3,0,2,4,0,3,4,0,2,1 }; | ||
| 441 | + Property::Map indexFormat; | ||
| 442 | + indexFormat["indices"] = Property::UNSIGNED_INTEGER; | ||
| 443 | + PropertyBuffer indices = PropertyBuffer::New( indexFormat, 12 ); | ||
| 444 | + indices.SetData( indexData ); | ||
| 445 | + | ||
| 446 | + // Create the geometry object | ||
| 447 | + Geometry geometry = Geometry::New(); | ||
| 448 | + geometry.AddVertexBuffer( vertices ); | ||
| 449 | + geometry.SetIndexBuffer( indices ); | ||
| 450 | + | ||
| 451 | + return geometry; | ||
| 452 | +} | ||
| 453 | + | ||
| 454 | +ShaderEffect NewWindowController::CreateColorModifierer( const Vector3& rgbDelta ) | ||
| 455 | +{ | ||
| 456 | + std::string fragmentShader = MAKE_SHADER( | ||
| 457 | + precision highp float;\n | ||
| 458 | + uniform vec3 uRGBDelta;\n | ||
| 459 | + uniform float uIgnoreAlpha;\n | ||
| 460 | + float rand(vec2 co) \n | ||
| 461 | + {\n | ||
| 462 | + return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); \n} | ||
| 463 | + \n | ||
| 464 | + void main() {\n | ||
| 465 | + vec4 color = texture2D(sTexture, vTexCoord); \n | ||
| 466 | + // modify the hsv Value | ||
| 467 | + color.rgb += uRGBDelta * rand(vTexCoord); \n | ||
| 468 | + // if the new vale exceeds one, then decrease it | ||
| 469 | + color.rgb -= max(color.rgb*2.0 - vec3(2.0), 0.0);\n | ||
| 470 | + // if the new vale drops below zero, then increase it | ||
| 471 | + color.rgb -= min(color.rgb*2.0, 0.0);\n | ||
| 472 | + gl_FragColor = color; \n | ||
| 473 | + }\n | ||
| 474 | + ); | ||
| 475 | + | ||
| 476 | + ShaderEffect shaderEffect = ShaderEffect::New("", fragmentShader); | ||
| 477 | + shaderEffect.SetUniform( "uRGBDelta", rgbDelta ); | ||
| 478 | + | ||
| 479 | + return shaderEffect; | ||
| 480 | +} | ||
| 481 | + | ||
| 482 | +void NewWindowController::NewWindow(void) | ||
| 483 | +{ | ||
| 484 | + PositionSize posSize(0, 0, 720, 1280); | ||
| 485 | + gApplication.ReplaceWindow(posSize, "NewWindow"); // Generates a new window | ||
| 486 | +} | ||
| 487 | + | ||
| 488 | +bool NewWindowController::OnLoseContextButtonClicked( Toolkit::Button button ) | ||
| 489 | +{ | ||
| 490 | + // Add as an idle callback to avoid ProcessEvents being recursively called. | ||
| 491 | + mApplication.AddIdle( MakeCallback( NewWindowController::NewWindow ) ); | ||
| 492 | + return true; | ||
| 493 | +} | ||
| 494 | + | ||
| 340 | bool NewWindowController::OnTrackTimerTick() | 495 | bool NewWindowController::OnTrackTimerTick() |
| 341 | { | 496 | { |
| 342 | static int time=0; | 497 | static int time=0; |
| @@ -351,82 +506,13 @@ bool NewWindowController::OnTrackTimerTick() | @@ -351,82 +506,13 @@ bool NewWindowController::OnTrackTimerTick() | ||
| 351 | Vector2 direction = aimPos-position; | 506 | Vector2 direction = aimPos-position; |
| 352 | Vector2 stageSize = Stage::GetCurrent().GetSize(); | 507 | Vector2 stageSize = Stage::GetCurrent().GetSize(); |
| 353 | 508 | ||
| 354 | - for(int i=0; i<20; i++) | ||
| 355 | - { | ||
| 356 | - SetUpAnimation( stageSize*0.5f+position, direction ); | ||
| 357 | - } | 509 | + SetUpBubbleEmission( stageSize*0.5f+position, direction ); |
| 510 | + SetUpBubbleEmission( stageSize*0.5f+position*0.75f, direction ); | ||
| 511 | + SetUpBubbleEmission( stageSize*0.5f+position*0.7f, direction ); | ||
| 358 | 512 | ||
| 359 | return true; | 513 | return true; |
| 360 | } | 514 | } |
| 361 | 515 | ||
| 362 | - | ||
| 363 | -void NewWindowController::CreateBlending() | ||
| 364 | -{ | ||
| 365 | - Toolkit::ColorAdjuster colorAdjuster = ColorAdjuster::New(mHSVDelta); | ||
| 366 | - FrameBufferImage fb2 = CreateFrameBufferForImage( EFFECT_IMAGE, mEffectImage, colorAdjuster ); | ||
| 367 | - | ||
| 368 | - ImageActor tmpActor = ImageActor::New(fb2); | ||
| 369 | - mContentLayer.Add(tmpActor); | ||
| 370 | - tmpActor.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT); | ||
| 371 | - tmpActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT); | ||
| 372 | - tmpActor.SetScale(0.25f); | ||
| 373 | - | ||
| 374 | - // create blending shader effect | ||
| 375 | - ShaderEffect blendShader = ShaderEffect::New( "", FRAG_SHADER ); | ||
| 376 | - blendShader.SetEffectImage( fb2 ); | ||
| 377 | - blendShader.SetUniform("alpha", 0.5f); | ||
| 378 | - | ||
| 379 | - mBaseImage = ResourceImage::New(BASE_IMAGE); | ||
| 380 | - mBlendActor = ImageActor::New( mBaseImage ); | ||
| 381 | - mBlendActor.SetParentOrigin(ParentOrigin::CENTER); | ||
| 382 | - mBlendActor.SetPosition(Vector3(150.0f, 200.0f, 0.0f)); | ||
| 383 | - mBlendActor.SetSize(140, 140); | ||
| 384 | - mBlendActor.SetShaderEffect( blendShader ); | ||
| 385 | - mContentLayer.Add(mBlendActor); | ||
| 386 | -} | ||
| 387 | - | ||
| 388 | -void NewWindowController::CreateText() | ||
| 389 | -{ | ||
| 390 | - mTextActor = TextLabel::New("Some text"); | ||
| 391 | - mTextActor.SetParentOrigin(ParentOrigin::CENTER); | ||
| 392 | - mTextActor.SetColor(Color::RED); | ||
| 393 | - mTextActor.SetName("PushMe text"); | ||
| 394 | - mContentLayer.Add( mTextActor ); | ||
| 395 | -} | ||
| 396 | - | ||
| 397 | -Mesh NewWindowController::CreateMesh(bool hasColor, Material material) | ||
| 398 | -{ | ||
| 399 | - // Create vertices and specify their color | ||
| 400 | - MeshData::VertexContainer vertices(4); | ||
| 401 | - vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2(0.0f, 0.0f), Vector3(1.0f, 0.0f, 0.0f) ); | ||
| 402 | - vertices[ 1 ] = MeshData::Vertex( Vector3( 0.5f, -0.5f, 0.0f ), Vector2(1.0f, 0.0f), Vector3(1.0f, 1.0f, 0.0f) ); | ||
| 403 | - vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f, 0.5f, 0.0f ), Vector2(0.0f, 1.0f), Vector3(0.0f,1.0f,0.0f) ); | ||
| 404 | - vertices[ 3 ] = MeshData::Vertex( Vector3( 0.5f, 0.5f, 0.0f ), Vector2(1.0f, 1.0f), Vector3(0.0f,0.0f,1.0f) ); | ||
| 405 | - | ||
| 406 | - // Specify all the faces | ||
| 407 | - MeshData::FaceIndices faces; | ||
| 408 | - faces.reserve( 6 ); // 2 triangles in Quad | ||
| 409 | - faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 ); | ||
| 410 | - faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 ); | ||
| 411 | - | ||
| 412 | - // Create the mesh data from the vertices and faces | ||
| 413 | - MeshData meshData; | ||
| 414 | - meshData.SetHasColor( hasColor ); | ||
| 415 | - meshData.SetMaterial( material ); | ||
| 416 | - meshData.SetVertices( vertices ); | ||
| 417 | - meshData.SetFaceIndices( faces ); | ||
| 418 | - | ||
| 419 | - // Create a mesh from the data | ||
| 420 | - Dali::Mesh mesh = Mesh::New( meshData ); | ||
| 421 | - return mesh; | ||
| 422 | -} | ||
| 423 | - | ||
| 424 | -void NewWindowController::NewWindow(void) | ||
| 425 | -{ | ||
| 426 | - PositionSize posSize(0, 0, 720, 1280); | ||
| 427 | - gApplication.ReplaceWindow(posSize, "NewWindow"); // Generates a new window | ||
| 428 | -} | ||
| 429 | - | ||
| 430 | void NewWindowController::OnKeyEvent(const KeyEvent& event) | 516 | void NewWindowController::OnKeyEvent(const KeyEvent& event) |
| 431 | { | 517 | { |
| 432 | if(event.state == KeyEvent::Down) | 518 | if(event.state == KeyEvent::Down) |
| @@ -448,9 +534,6 @@ void NewWindowController::OnContextRegained() | @@ -448,9 +534,6 @@ void NewWindowController::OnContextRegained() | ||
| 448 | printf("Stage reporting context regain\n"); | 534 | printf("Stage reporting context regain\n"); |
| 449 | } | 535 | } |
| 450 | 536 | ||
| 451 | - | ||
| 452 | - | ||
| 453 | - | ||
| 454 | void RunTest(Application& app) | 537 | void RunTest(Application& app) |
| 455 | { | 538 | { |
| 456 | gNewWindowController = new NewWindowController(app); | 539 | gNewWindowController = new NewWindowController(app); |
| @@ -459,7 +542,6 @@ void RunTest(Application& app) | @@ -459,7 +542,6 @@ void RunTest(Application& app) | ||
| 459 | 542 | ||
| 460 | // Entry point for Linux & Tizen applications | 543 | // Entry point for Linux & Tizen applications |
| 461 | // | 544 | // |
| 462 | - | ||
| 463 | int main(int argc, char **argv) | 545 | int main(int argc, char **argv) |
| 464 | { | 546 | { |
| 465 | gApplication = Application::New(&argc, &argv, DALI_DEMO_THEME_PATH); | 547 | gApplication = Application::New(&argc, &argv, DALI_DEMO_THEME_PATH); |
examples/page-turn-view/page-turn-view-example.cpp
| @@ -17,7 +17,6 @@ | @@ -17,7 +17,6 @@ | ||
| 17 | 17 | ||
| 18 | #include <dali/dali.h> | 18 | #include <dali/dali.h> |
| 19 | #include <dali-toolkit/dali-toolkit.h> | 19 | #include <dali-toolkit/dali-toolkit.h> |
| 20 | -#include <dali-toolkit/devel-api/shader-effects/page-turn-effect.h> | ||
| 21 | #include <dali-toolkit/devel-api/controls/page-turn-view/page-factory.h> | 20 | #include <dali-toolkit/devel-api/controls/page-turn-view/page-factory.h> |
| 22 | #include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-landscape-view.h> | 21 | #include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-landscape-view.h> |
| 23 | #include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-portrait-view.h> | 22 | #include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-portrait-view.h> |
examples/path-animation/path-animation.cpp deleted
| 1 | -/* | ||
| 2 | - * Copyright (c) 2014 Samsung Electronics Co., Ltd. | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - * | ||
| 16 | - */ | ||
| 17 | - | ||
| 18 | -/** | ||
| 19 | - * This example shows how to use path animations in DALi | ||
| 20 | - */ | ||
| 21 | - | ||
| 22 | -// EXTERNAL INCLUDES | ||
| 23 | -#include <dali-toolkit/dali-toolkit.h> | ||
| 24 | -#include <dali/devel-api/actors/mesh-actor.h> | ||
| 25 | -#include <dali/devel-api/geometry/mesh.h> | ||
| 26 | -#include <dali/devel-api/geometry/mesh-factory.h> | ||
| 27 | -#include <dali-toolkit/devel-api/controls/slider/slider.h> | ||
| 28 | - | ||
| 29 | - | ||
| 30 | - | ||
| 31 | -// INTERNAL INCLUDES | ||
| 32 | -#include "shared/view.h" | ||
| 33 | - | ||
| 34 | -using namespace Dali; | ||
| 35 | -using namespace Dali::Toolkit; | ||
| 36 | - | ||
| 37 | - | ||
| 38 | -namespace | ||
| 39 | -{ | ||
| 40 | -const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-default.png" ); | ||
| 41 | -const char* ACTOR_IMAGE( DALI_IMAGE_DIR "dali-logo.png" ); | ||
| 42 | -const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); | ||
| 43 | -const char* APPLICATION_TITLE( "Path Animation Example" ); | ||
| 44 | -}; //Unnamed namespace | ||
| 45 | - | ||
| 46 | -/** | ||
| 47 | - * @brief The main class of the demo. | ||
| 48 | - */ | ||
| 49 | -class PathController : public ConnectionTracker | ||
| 50 | -{ | ||
| 51 | -public: | ||
| 52 | - | ||
| 53 | - PathController( Application& application ) | ||
| 54 | -: mApplication( application ) | ||
| 55 | -{ | ||
| 56 | - // Connect to the Application's Init signal | ||
| 57 | - mApplication.InitSignal().Connect( this, &PathController::Create ); | ||
| 58 | -} | ||
| 59 | - | ||
| 60 | - ~PathController() | ||
| 61 | - { | ||
| 62 | - // Nothing to do here. | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | - /* | ||
| 66 | - * Create a control composed of a label and an slider | ||
| 67 | - * @param[in] label The text to be displayed ny the label | ||
| 68 | - * @param[in] size The size of the slider | ||
| 69 | - * @param[in] callback Pointer to the callback function to be called when user moves the slider | ||
| 70 | - */ | ||
| 71 | - Actor CreateVectorComponentControl( const std::string& label, const Vector3& size, bool(PathController::*callback)(Dali::Toolkit::Slider,float) ) | ||
| 72 | - { | ||
| 73 | - TextLabel text = TextLabel::New(label); | ||
| 74 | - text.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH ); | ||
| 75 | - text.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); | ||
| 76 | - text.SetColor( Vector4(0.0f,0.0f,0.0f,1.0f)); | ||
| 77 | - | ||
| 78 | - Slider slider = Slider::New(); | ||
| 79 | - slider.SetAnchorPoint( AnchorPoint::CENTER_LEFT); | ||
| 80 | - slider.SetParentOrigin( ParentOrigin::CENTER_RIGHT); | ||
| 81 | - slider.SetProperty(Slider::Property::LOWER_BOUND, -1.0f ); | ||
| 82 | - slider.SetProperty(Slider::Property::UPPER_BOUND, 1.0f ); | ||
| 83 | - | ||
| 84 | - Property::Array marks; | ||
| 85 | - float mark = -1.0f; | ||
| 86 | - for(unsigned short i(0); i<21; ++i ) | ||
| 87 | - { | ||
| 88 | - marks.PushBack( mark ); | ||
| 89 | - mark += 0.1f; | ||
| 90 | - } | ||
| 91 | - | ||
| 92 | - slider.SetProperty(Slider::Property::MARKS, marks); | ||
| 93 | - slider.SetProperty(Slider::Property::SNAP_TO_MARKS, true ); | ||
| 94 | - slider.SetSize(size); | ||
| 95 | - slider.SetScale( 0.5f ); | ||
| 96 | - slider.ValueChangedSignal().Connect(this,callback); | ||
| 97 | - text.Add( slider ); | ||
| 98 | - return text; | ||
| 99 | - } | ||
| 100 | - | ||
| 101 | - /** | ||
| 102 | - * Crate all the GUI controls | ||
| 103 | - */ | ||
| 104 | - void CreateControls() | ||
| 105 | - { | ||
| 106 | - Stage stage = Stage::GetCurrent(); | ||
| 107 | - | ||
| 108 | - //TextInput | ||
| 109 | - Dali::Layer controlsLayer = Dali::Layer::New(); | ||
| 110 | - controlsLayer.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); | ||
| 111 | - controlsLayer.SetSizeModeFactor( Vector3( 1.0f, 0.3f, 1.0f ) ); | ||
| 112 | - controlsLayer.SetPosition( 0.0f, stage.GetSize().y*0.8f, 0.0f ); | ||
| 113 | - controlsLayer.SetAnchorPoint( AnchorPoint::TOP_LEFT); | ||
| 114 | - controlsLayer.SetParentOrigin( ParentOrigin::TOP_LEFT); | ||
| 115 | - controlsLayer.TouchedSignal().Connect(this, &PathController::OnTouchGuiLayer); | ||
| 116 | - stage.Add( controlsLayer ); | ||
| 117 | - | ||
| 118 | - Vector3 textInputSize( stage.GetSize().x, stage.GetSize().y*0.04f, 0.0f ); | ||
| 119 | - Actor control0 = CreateVectorComponentControl("x:", textInputSize, &PathController::OnSliderXValueChange ); | ||
| 120 | - control0.SetY( stage.GetSize().y*0.05f ); | ||
| 121 | - control0.SetAnchorPoint(AnchorPoint::TOP_LEFT); | ||
| 122 | - controlsLayer.Add( control0 ); | ||
| 123 | - | ||
| 124 | - Actor control1 = CreateVectorComponentControl("y:", textInputSize, &PathController::OnSliderYValueChange ); | ||
| 125 | - control1.SetAnchorPoint(AnchorPoint::TOP_LEFT); | ||
| 126 | - control1.SetParentOrigin( ParentOrigin::BOTTOM_LEFT ); | ||
| 127 | - control1.SetPosition(0.0f,stage.GetSize().y*0.01,0.0f); | ||
| 128 | - control0.Add( control1 ); | ||
| 129 | - | ||
| 130 | - Actor control2 =CreateVectorComponentControl("z:", textInputSize, &PathController::OnSliderZValueChange ); | ||
| 131 | - control2.SetAnchorPoint(AnchorPoint::TOP_LEFT); | ||
| 132 | - control2.SetParentOrigin( ParentOrigin::BOTTOM_LEFT ); | ||
| 133 | - control2.SetPosition(0.0f,stage.GetSize().y*0.01,0.0f); | ||
| 134 | - control1.Add( control2 ); | ||
| 135 | - } | ||
| 136 | - | ||
| 137 | - /** | ||
| 138 | - * Draws the path and the control points for the path | ||
| 139 | - * @param[in] resolution Number of segments for the path. | ||
| 140 | - */ | ||
| 141 | - void DrawPath( unsigned int resolution ) | ||
| 142 | - { | ||
| 143 | - //Create path mesh actor | ||
| 144 | - Dali::MeshData meshData = MeshFactory::NewPath( mPath, resolution ); | ||
| 145 | - Dali::Material material = Material::New("LineMaterial"); | ||
| 146 | - material.SetDiffuseColor( Vector4(0.0f,0.0f,0.0f,1.0f)); | ||
| 147 | - meshData.SetMaterial(material); | ||
| 148 | - Dali::Mesh mesh = Dali::Mesh::New( meshData ); | ||
| 149 | - if( mMeshPath ) | ||
| 150 | - { | ||
| 151 | - mContentLayer.Remove( mMeshPath ); | ||
| 152 | - } | ||
| 153 | - mMeshPath = Dali::MeshActor::New( mesh ); | ||
| 154 | - mMeshPath.SetAnchorPoint( AnchorPoint::TOP_LEFT ); | ||
| 155 | - mMeshPath.SetParentOrigin( ParentOrigin::TOP_LEFT ); | ||
| 156 | - mContentLayer.Add( mMeshPath ); | ||
| 157 | - | ||
| 158 | - | ||
| 159 | - ////Create mesh connecting interpolation points and control points | ||
| 160 | - std::vector<Dali::MeshData::Vertex> vVertex; | ||
| 161 | - std::vector<unsigned short> vIndex; | ||
| 162 | - size_t pointCount = mPath.GetPointCount(); | ||
| 163 | - size_t controlPointIndex = 0; | ||
| 164 | - for( size_t i(0); i<pointCount; ++i ) | ||
| 165 | - { | ||
| 166 | - vVertex.push_back( MeshData::Vertex(mPath.GetPoint(i),Vector2::ZERO, Vector3::ZERO ) ); | ||
| 167 | - if( i<pointCount-1) | ||
| 168 | - { | ||
| 169 | - vVertex.push_back( MeshData::Vertex(mPath.GetControlPoint(controlPointIndex),Vector2::ZERO, Vector3::ZERO )); | ||
| 170 | - vVertex.push_back( MeshData::Vertex(mPath.GetControlPoint(controlPointIndex+1),Vector2::ZERO, Vector3::ZERO )); | ||
| 171 | - } | ||
| 172 | - controlPointIndex += 2; | ||
| 173 | - } | ||
| 174 | - | ||
| 175 | - size_t segmentCount = 2*(pointCount-2)+2; | ||
| 176 | - unsigned short index=0; | ||
| 177 | - for( size_t i(0); i<segmentCount; ++i, ++index ) | ||
| 178 | - { | ||
| 179 | - vIndex.push_back(index); | ||
| 180 | - vIndex.push_back(index+1); | ||
| 181 | - | ||
| 182 | - if( ~i & 1 ) | ||
| 183 | - { | ||
| 184 | - index++; | ||
| 185 | - } | ||
| 186 | - } | ||
| 187 | - | ||
| 188 | - meshData.SetLineData( vVertex, vIndex, material ); | ||
| 189 | - meshData.SetMaterial(material); | ||
| 190 | - mesh = Dali::Mesh::New( meshData ); | ||
| 191 | - if( mMeshHandlers ) | ||
| 192 | - { | ||
| 193 | - mContentLayer.Remove( mMeshHandlers ); | ||
| 194 | - } | ||
| 195 | - mMeshHandlers = Dali::MeshActor::New( mesh ); | ||
| 196 | - mMeshHandlers.SetAnchorPoint( AnchorPoint::TOP_LEFT ); | ||
| 197 | - mMeshHandlers.SetParentOrigin( ParentOrigin::TOP_LEFT ); | ||
| 198 | - mContentLayer.Add( mMeshHandlers ); | ||
| 199 | - | ||
| 200 | - | ||
| 201 | - //Create actors representing interpolation points | ||
| 202 | - index = 0; | ||
| 203 | - for( size_t i(0); i<pointCount; ++i ) | ||
| 204 | - { | ||
| 205 | - if( !mControlPoint[index] ) | ||
| 206 | - { | ||
| 207 | - mControlPoint[index] = Toolkit::CreateSolidColorActor(Vector4(1.0f,1.0f,1.0f,1.0f)); | ||
| 208 | - mControlPoint[index].SetParentOrigin( ParentOrigin::TOP_LEFT); | ||
| 209 | - mControlPoint[index].SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 210 | - mControlPoint[index].SetSize( 20.0f, 20.0f ); | ||
| 211 | - mContentLayer.Add(mControlPoint[index]); | ||
| 212 | - } | ||
| 213 | - | ||
| 214 | - std::string name( "Knot"); | ||
| 215 | - name.push_back(i); | ||
| 216 | - mControlPoint[index].SetName( name ); | ||
| 217 | - mControlPoint[index].SetPosition( mPath.GetPoint(i) ); | ||
| 218 | - mControlPoint[index].SetColor( Vector4(0.0f,0.0f,0.0f,1.0f)); | ||
| 219 | - ++index; | ||
| 220 | - } | ||
| 221 | - | ||
| 222 | - //Create actors representing control points | ||
| 223 | - size_t controlPointCount=2*(pointCount-1); | ||
| 224 | - for( size_t i(0); i<controlPointCount; ++i ) | ||
| 225 | - { | ||
| 226 | - if( !mControlPoint[index]) | ||
| 227 | - { | ||
| 228 | - mControlPoint[index] = Toolkit::CreateSolidColorActor(Vector4(1.0f,1.0f,1.0f,1.0f)); | ||
| 229 | - mControlPoint[index].SetParentOrigin( ParentOrigin::TOP_LEFT); | ||
| 230 | - mControlPoint[index].SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 231 | - mControlPoint[index].SetSize( 20.0f, 20.0f ); | ||
| 232 | - mContentLayer.Add(mControlPoint[index]); | ||
| 233 | - } | ||
| 234 | - std::string name( "ControlPoint"); | ||
| 235 | - name.push_back(i); | ||
| 236 | - mControlPoint[index].SetName( name ); | ||
| 237 | - mControlPoint[index].SetPosition( mPath.GetControlPoint(i) ); | ||
| 238 | - mControlPoint[index].SetColor( Vector4(1.0f,0.0f,0.0f,1.0f)); | ||
| 239 | - ++index; | ||
| 240 | - } | ||
| 241 | - } | ||
| 242 | - | ||
| 243 | - /** | ||
| 244 | - * Create the path animation. | ||
| 245 | - */ | ||
| 246 | - void CreateAnimation() | ||
| 247 | - { | ||
| 248 | - if( !mAnimation ) | ||
| 249 | - { | ||
| 250 | - mAnimation = Animation::New( 2.0f ); | ||
| 251 | - } | ||
| 252 | - else | ||
| 253 | - { | ||
| 254 | - mAnimation.Pause(); | ||
| 255 | - mAnimation.Clear(); | ||
| 256 | - mActor.SetOrientation( Quaternion() ); | ||
| 257 | - } | ||
| 258 | - | ||
| 259 | - mAnimation.Animate( mActor, mPath, mForward ); | ||
| 260 | - mAnimation.SetLooping( true ); | ||
| 261 | - mAnimation.Play(); | ||
| 262 | - } | ||
| 263 | - | ||
| 264 | - /** | ||
| 265 | - * Get closest control point.void | ||
| 266 | - * @param[in] point Point from where the distance is computed | ||
| 267 | - * @return The closest actor if the distance is beyond 0.5cm or an uninitialized actor otherwise | ||
| 268 | - */ | ||
| 269 | - Actor GetClosestActor(const Vector3& point) | ||
| 270 | - { | ||
| 271 | - size_t pointCount = mPath.GetPointCount(); | ||
| 272 | - size_t controlPointCount = 3*pointCount - 2; | ||
| 273 | - Actor result; | ||
| 274 | - float minDistance = 1.0/0.0; | ||
| 275 | - | ||
| 276 | - for( size_t i(0); i<controlPointCount; ++i ) | ||
| 277 | - { | ||
| 278 | - Vector3 v = mControlPoint[i].GetCurrentPosition() - point; | ||
| 279 | - float distance = v.LengthSquared(); | ||
| 280 | - if( distance < minDistance ) | ||
| 281 | - { | ||
| 282 | - result = mControlPoint[i]; | ||
| 283 | - minDistance = distance; | ||
| 284 | - } | ||
| 285 | - } | ||
| 286 | - | ||
| 287 | - Vector2 dpi = Dali::Stage::GetCurrent().GetDpi(); | ||
| 288 | - float distanceTreshold = 0.2f * dpi.x * 0.2f * dpi.x; | ||
| 289 | - | ||
| 290 | - if( minDistance < distanceTreshold ) | ||
| 291 | - { | ||
| 292 | - return result; | ||
| 293 | - } | ||
| 294 | - else | ||
| 295 | - { | ||
| 296 | - return Actor(); | ||
| 297 | - } | ||
| 298 | - } | ||
| 299 | - | ||
| 300 | - /** | ||
| 301 | - * Callback called when the background layer is touched | ||
| 302 | - */ | ||
| 303 | - bool OnTouchLayer(Actor actor, const TouchEvent& event) | ||
| 304 | - { | ||
| 305 | - if(event.GetPointCount()>0) | ||
| 306 | - { | ||
| 307 | - const TouchPoint& point = event.GetPoint(0); | ||
| 308 | - | ||
| 309 | - if(point.state==TouchPoint::Up) | ||
| 310 | - { | ||
| 311 | - //Stop dragging | ||
| 312 | - mDragActor.Reset(); | ||
| 313 | - } | ||
| 314 | - else if(point.state==TouchPoint::Down) | ||
| 315 | - { | ||
| 316 | - Vector3 touchPoint = Vector3(event.GetPoint(0).screen.x, event.GetPoint(0).screen.y, 0.0f); | ||
| 317 | - if(!mDragActor ) | ||
| 318 | - { | ||
| 319 | - mDragActor = GetClosestActor( touchPoint ); | ||
| 320 | - if( !mDragActor && mPath.GetPointCount() < 10 ) | ||
| 321 | - { | ||
| 322 | - // Add new point | ||
| 323 | - Vector3 lastPoint = mPath.GetPoint( mPath.GetPointCount()-1); | ||
| 324 | - mPath.AddPoint( touchPoint ); | ||
| 325 | - Vector3 displacement = (touchPoint-lastPoint)/8; | ||
| 326 | - mPath.AddControlPoint( lastPoint + displacement ); | ||
| 327 | - mPath.AddControlPoint( touchPoint - displacement); | ||
| 328 | - | ||
| 329 | - DrawPath( 200u ); | ||
| 330 | - CreateAnimation(); | ||
| 331 | - } | ||
| 332 | - } | ||
| 333 | - } | ||
| 334 | - else if( mDragActor && point.state==TouchPoint::Motion ) | ||
| 335 | - { | ||
| 336 | - Vector3 touchPoint = Vector3(event.GetPoint(0).screen.x, event.GetPoint(0).screen.y, 0.0f); | ||
| 337 | - std::string actorName(mDragActor.GetName()); | ||
| 338 | - if( actorName.compare(0, 4, "Knot") == 0) | ||
| 339 | - { | ||
| 340 | - int index = actorName[4]; | ||
| 341 | - mPath.GetPoint(index) = touchPoint; | ||
| 342 | - } | ||
| 343 | - else | ||
| 344 | - { | ||
| 345 | - int index = actorName[12]; | ||
| 346 | - mPath.GetControlPoint(index) = touchPoint; | ||
| 347 | - } | ||
| 348 | - | ||
| 349 | - DrawPath( 200u ); | ||
| 350 | - CreateAnimation(); | ||
| 351 | - } | ||
| 352 | - } | ||
| 353 | - | ||
| 354 | - return true; | ||
| 355 | - } | ||
| 356 | - | ||
| 357 | - bool OnTouchGuiLayer(Actor actor, const TouchEvent& event) | ||
| 358 | - { | ||
| 359 | - mDragActor.Reset(); | ||
| 360 | - return false; | ||
| 361 | - } | ||
| 362 | - /** | ||
| 363 | - * Callback called when user changes slider X | ||
| 364 | - * @param[in] slider The slider that has generated the signal | ||
| 365 | - * @param[in] value The new value | ||
| 366 | - */ | ||
| 367 | - bool OnSliderXValueChange( Slider s, float value) | ||
| 368 | - { | ||
| 369 | - if( fabs( value ) - Math::MACHINE_EPSILON_1000 < 0.0f ) | ||
| 370 | - { | ||
| 371 | - mForward.x = 0.0f; | ||
| 372 | - } | ||
| 373 | - else | ||
| 374 | - { | ||
| 375 | - mForward.x = value; | ||
| 376 | - } | ||
| 377 | - | ||
| 378 | - CreateAnimation(); | ||
| 379 | - return true; | ||
| 380 | - } | ||
| 381 | - | ||
| 382 | - /** | ||
| 383 | - * Callback called when user changes slider Y | ||
| 384 | - * @param[in] slider The slider that has generated the signal | ||
| 385 | - * @param[in] value The new value | ||
| 386 | - */ | ||
| 387 | - bool OnSliderYValueChange( Slider s, float value) | ||
| 388 | - { | ||
| 389 | - if( fabs( value ) - Math::MACHINE_EPSILON_1000 < 0.0f ) | ||
| 390 | - { | ||
| 391 | - mForward.y = 0.0f; | ||
| 392 | - } | ||
| 393 | - else | ||
| 394 | - { | ||
| 395 | - mForward.y = value; | ||
| 396 | - } | ||
| 397 | - CreateAnimation(); | ||
| 398 | - return true; | ||
| 399 | - } | ||
| 400 | - | ||
| 401 | - /** | ||
| 402 | - * Callback called when user changes slider Z | ||
| 403 | - * @param[in] slider The slider that has generated the signal | ||
| 404 | - * @param[in] value The new value | ||
| 405 | - */ | ||
| 406 | - bool OnSliderZValueChange( Slider s, float value) | ||
| 407 | - { | ||
| 408 | - if( fabs( value ) - Math::MACHINE_EPSILON_1000 < 0.0f ) | ||
| 409 | - { | ||
| 410 | - mForward.z = 0.0f; | ||
| 411 | - } | ||
| 412 | - else | ||
| 413 | - { | ||
| 414 | - mForward.z = value; | ||
| 415 | - } | ||
| 416 | - | ||
| 417 | - CreateAnimation(); | ||
| 418 | - return true; | ||
| 419 | - } | ||
| 420 | - | ||
| 421 | - /** | ||
| 422 | - * Main key event handler. | ||
| 423 | - * Quit on escape key. | ||
| 424 | - */ | ||
| 425 | - void OnKeyEvent(const KeyEvent& event) | ||
| 426 | - { | ||
| 427 | - if( event.state == KeyEvent::Down ) | ||
| 428 | - { | ||
| 429 | - if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || | ||
| 430 | - IsKey( event, Dali::DALI_KEY_BACK ) ) | ||
| 431 | - { | ||
| 432 | - mApplication.Quit(); | ||
| 433 | - } | ||
| 434 | - } | ||
| 435 | - } | ||
| 436 | - | ||
| 437 | - /** | ||
| 438 | - * One-time setup in response to Application InitSignal. | ||
| 439 | - */ | ||
| 440 | - void Create( Application& application ) | ||
| 441 | - { | ||
| 442 | - // Get a handle to the stage: | ||
| 443 | - Stage stage = Stage::GetCurrent(); | ||
| 444 | - | ||
| 445 | - // Connect to input event signals: | ||
| 446 | - stage.KeyEventSignal().Connect(this, &PathController::OnKeyEvent); | ||
| 447 | - | ||
| 448 | - // Create a default view with a default tool bar: | ||
| 449 | - Toolkit::Control view; ///< The View instance. | ||
| 450 | - Toolkit::ToolBar toolBar; ///< The View's Toolbar. | ||
| 451 | - mContentLayer = DemoHelper::CreateView( mApplication, | ||
| 452 | - view, | ||
| 453 | - toolBar, | ||
| 454 | - BACKGROUND_IMAGE, | ||
| 455 | - TOOLBAR_IMAGE, | ||
| 456 | - "" ); | ||
| 457 | - mContentLayer.SetDrawMode( DrawMode::OVERLAY ); | ||
| 458 | - | ||
| 459 | - mContentLayer.TouchedSignal().Connect(this, &PathController::OnTouchLayer); | ||
| 460 | - | ||
| 461 | - //Title | ||
| 462 | - TextLabel title = DemoHelper::CreateToolBarLabel( APPLICATION_TITLE ); | ||
| 463 | - toolBar.AddControl( title, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter ); | ||
| 464 | - | ||
| 465 | - //Path | ||
| 466 | - mPath = Dali::Path::New(); | ||
| 467 | - mPath.AddPoint( Vector3( 10.0f, stage.GetSize().y*0.5f, 0.0f )); | ||
| 468 | - mPath.AddPoint( Vector3( stage.GetSize().x*0.5f, stage.GetSize().y*0.5f, 0.0f )); | ||
| 469 | - mPath.GenerateControlPoints(0.25f); | ||
| 470 | - DrawPath( 200u ); | ||
| 471 | - | ||
| 472 | - //Actor | ||
| 473 | - Image img = ResourceImage::New(ACTOR_IMAGE); | ||
| 474 | - mActor = ImageActor::New( img ); | ||
| 475 | - mActor.SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 476 | - mActor.SetSize( 100, 50, 1 ); | ||
| 477 | - mContentLayer.Add( mActor ); | ||
| 478 | - | ||
| 479 | - CreateAnimation(); | ||
| 480 | - CreateControls(); | ||
| 481 | - } | ||
| 482 | - | ||
| 483 | -private: | ||
| 484 | - Application& mApplication; | ||
| 485 | - | ||
| 486 | - Layer mContentLayer; ///< The content layer | ||
| 487 | - | ||
| 488 | - Path mPath; ///< The path used in the animation | ||
| 489 | - ImageActor mActor; ///< Actor being animated | ||
| 490 | - Vector3 mForward; ///< Current forward vector | ||
| 491 | - Animation mAnimation; ///< Path animation | ||
| 492 | - | ||
| 493 | - MeshActor mMeshPath; ///< Mesh actor for the path | ||
| 494 | - MeshActor mMeshHandlers; ///< Mesh actor for the handlers of the path | ||
| 495 | - | ||
| 496 | - Actor mControlPoint[28]; ///< ImageActors represeting control points of the path | ||
| 497 | - | ||
| 498 | - Actor mDragActor; ///< Reference to the actor currently being dragged | ||
| 499 | -}; | ||
| 500 | - | ||
| 501 | - | ||
| 502 | -void RunTest( Application& application ) | ||
| 503 | -{ | ||
| 504 | - PathController test( application ); | ||
| 505 | - | ||
| 506 | - application.MainLoop(); | ||
| 507 | -} | ||
| 508 | - | ||
| 509 | -/** Entry point for Linux & Tizen applications */ | ||
| 510 | -int main( int argc, char **argv ) | ||
| 511 | -{ | ||
| 512 | - Application application = Application::New( &argc, &argv, DALI_DEMO_THEME_PATH ); | ||
| 513 | - | ||
| 514 | - RunTest( application ); | ||
| 515 | - | ||
| 516 | - return 0; | ||
| 517 | -} |
examples/point-mesh/point-mesh-example.cpp
0 โ 100644
| 1 | +/* | ||
| 2 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + | ||
| 18 | +// EXTERNAL INCLUDES | ||
| 19 | +#include <dali/devel-api/rendering/renderer.h> | ||
| 20 | +#include <dali-toolkit/dali-toolkit.h> | ||
| 21 | + | ||
| 22 | +// INTERNAL INCLUDES | ||
| 23 | +#include "shared/view.h" | ||
| 24 | + | ||
| 25 | +using namespace Dali; | ||
| 26 | + | ||
| 27 | +namespace | ||
| 28 | +{ | ||
| 29 | +const char* MATERIAL_SAMPLE( DALI_IMAGE_DIR "gallery-small-48.jpg" ); | ||
| 30 | +const char* MATERIAL_SAMPLE2( DALI_IMAGE_DIR "gallery-medium-19.jpg" ); | ||
| 31 | + | ||
| 32 | +#define MAKE_SHADER(A)#A | ||
| 33 | + | ||
| 34 | +const char* VERTEX_SHADER = MAKE_SHADER( | ||
| 35 | +attribute mediump vec2 aPosition; | ||
| 36 | +attribute highp float aHue; | ||
| 37 | +varying mediump vec2 vTexCoord; | ||
| 38 | +uniform mediump mat4 uMvpMatrix; | ||
| 39 | +uniform mediump vec3 uSize; | ||
| 40 | +uniform mediump float uPointSize; | ||
| 41 | +uniform lowp vec4 uFadeColor; | ||
| 42 | +varying mediump vec3 vVertexColor; | ||
| 43 | +varying mediump float vHue; | ||
| 44 | + | ||
| 45 | +vec3 hsv2rgb(vec3 c) | ||
| 46 | +{ | ||
| 47 | + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); | ||
| 48 | + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); | ||
| 49 | + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +void main() | ||
| 53 | +{ | ||
| 54 | + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); | ||
| 55 | + vertexPosition.xyz *= (uSize-uPointSize); | ||
| 56 | + vertexPosition = uMvpMatrix * vertexPosition; | ||
| 57 | + vVertexColor = hsv2rgb( vec3( aHue, 0.7, 1.0 ) ); | ||
| 58 | + vHue = aHue; | ||
| 59 | + gl_PointSize = uPointSize; | ||
| 60 | + gl_Position = vertexPosition; | ||
| 61 | +} | ||
| 62 | +); | ||
| 63 | + | ||
| 64 | +const char* FRAGMENT_SHADER = MAKE_SHADER( | ||
| 65 | +varying mediump vec3 vVertexColor; | ||
| 66 | +varying mediump float vHue; | ||
| 67 | +uniform lowp vec4 uColor; | ||
| 68 | +uniform sampler2D sTexture1; | ||
| 69 | +uniform sampler2D sTexture2; | ||
| 70 | +uniform lowp vec4 uFadeColor; | ||
| 71 | + | ||
| 72 | +void main() | ||
| 73 | +{ | ||
| 74 | + mediump vec4 texCol1 = texture2D(sTexture1, gl_PointCoord); | ||
| 75 | + mediump vec4 texCol2 = texture2D(sTexture2, gl_PointCoord); | ||
| 76 | + gl_FragColor = vec4(vVertexColor, 1.0) * ((texCol1*vHue) + (texCol2*(1.0-vHue))); | ||
| 77 | +} | ||
| 78 | +); | ||
| 79 | + | ||
| 80 | +Geometry CreateGeometry() | ||
| 81 | +{ | ||
| 82 | + // Create vertices | ||
| 83 | + struct Vertex { Vector2 position; float hue; }; | ||
| 84 | + | ||
| 85 | + unsigned int numSides = 20; | ||
| 86 | + Vertex polyhedraVertexData[numSides]; | ||
| 87 | + float angle=0; | ||
| 88 | + float sectorAngle = 2.0f * Math::PI / (float) numSides; | ||
| 89 | + | ||
| 90 | + for(unsigned int i=0; i<numSides; ++i) | ||
| 91 | + { | ||
| 92 | + polyhedraVertexData[i].position.x = sinf(angle)*0.5f; | ||
| 93 | + polyhedraVertexData[i].position.y = cosf(angle)*0.5f; | ||
| 94 | + polyhedraVertexData[i].hue = angle / ( 2.0f * Math::PI); | ||
| 95 | + angle += sectorAngle; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + Property::Map polyhedraVertexFormat; | ||
| 99 | + polyhedraVertexFormat["aPosition"] = Property::VECTOR2; | ||
| 100 | + polyhedraVertexFormat["aHue"] = Property::FLOAT; | ||
| 101 | + PropertyBuffer polyhedraVertices = PropertyBuffer::New( polyhedraVertexFormat, numSides ); | ||
| 102 | + polyhedraVertices.SetData(polyhedraVertexData); | ||
| 103 | + | ||
| 104 | + // Create the geometry object | ||
| 105 | + Geometry polyhedraGeometry = Geometry::New(); | ||
| 106 | + polyhedraGeometry.AddVertexBuffer( polyhedraVertices ); | ||
| 107 | + polyhedraGeometry.SetGeometryType( Geometry::POINTS ); | ||
| 108 | + | ||
| 109 | + return polyhedraGeometry; | ||
| 110 | +} | ||
| 111 | + | ||
| 112 | +} // anonymous namespace | ||
| 113 | + | ||
| 114 | +// This example shows how to use a simple mesh | ||
| 115 | +// | ||
| 116 | +class ExampleController : public ConnectionTracker | ||
| 117 | +{ | ||
| 118 | +public: | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * The example controller constructor. | ||
| 122 | + * @param[in] application The application instance | ||
| 123 | + */ | ||
| 124 | + ExampleController( Application& application ) | ||
| 125 | + : mApplication( application ) | ||
| 126 | + { | ||
| 127 | + // Connect to the Application's Init signal | ||
| 128 | + mApplication.InitSignal().Connect( this, &ExampleController::Create ); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * The example controller destructor | ||
| 133 | + */ | ||
| 134 | + ~ExampleController() | ||
| 135 | + { | ||
| 136 | + // Nothing to do here; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + /** | ||
| 140 | + * Invoked upon creation of application | ||
| 141 | + * @param[in] application The application instance | ||
| 142 | + */ | ||
| 143 | + void Create( Application& application ) | ||
| 144 | + { | ||
| 145 | + Stage stage = Stage::GetCurrent(); | ||
| 146 | + stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); | ||
| 147 | + | ||
| 148 | + mStageSize = stage.GetSize(); | ||
| 149 | + | ||
| 150 | + // The Init signal is received once (only) during the Application lifetime | ||
| 151 | + | ||
| 152 | + // Hide the indicator bar | ||
| 153 | + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); | ||
| 154 | + | ||
| 155 | + mImage = ResourceImage::New( MATERIAL_SAMPLE ); | ||
| 156 | + Image image = ResourceImage::New( MATERIAL_SAMPLE2 ); | ||
| 157 | + mSampler1 = Sampler::New(mImage, "sTexture1"); | ||
| 158 | + mSampler2 = Sampler::New(image, "sTexture2"); | ||
| 159 | + | ||
| 160 | + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); | ||
| 161 | + | ||
| 162 | + mMaterial = Material::New( mShader ); | ||
| 163 | + mMaterial.AddSampler( mSampler1 ); | ||
| 164 | + mMaterial.AddSampler( mSampler2 ); | ||
| 165 | + | ||
| 166 | + mGeometry = CreateGeometry(); | ||
| 167 | + | ||
| 168 | + mRenderer = Renderer::New( mGeometry, mMaterial ); | ||
| 169 | + | ||
| 170 | + mMeshActor = Actor::New(); | ||
| 171 | + mMeshActor.AddRenderer( mRenderer ); | ||
| 172 | + mMeshActor.SetSize(400, 400); | ||
| 173 | + | ||
| 174 | + mMeshActor.RegisterProperty( "uFadeColor", Color::GREEN ); | ||
| 175 | + | ||
| 176 | + mRenderer.RegisterProperty( "uFadeColor", Color::MAGENTA ); | ||
| 177 | + mRenderer.RegisterProperty( "uPointSize", 80.0f ); | ||
| 178 | + mRenderer.SetDepthIndex(0); | ||
| 179 | + | ||
| 180 | + mMeshActor.SetParentOrigin( ParentOrigin::CENTER ); | ||
| 181 | + mMeshActor.SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 182 | + stage.Add( mMeshActor ); | ||
| 183 | + | ||
| 184 | + Animation animation = Animation::New(15); | ||
| 185 | + KeyFrames keyFrames = KeyFrames::New(); | ||
| 186 | + keyFrames.Add(0.0f, Vector4::ZERO); | ||
| 187 | + keyFrames.Add(1.0f, Vector4( 1.0f, 0.0f, 1.0f, 1.0f )); | ||
| 188 | + | ||
| 189 | + animation.AnimateBy( Property(mMeshActor, Actor::Property::ORIENTATION), Quaternion(Degree(360), Vector3::ZAXIS) ); | ||
| 190 | + | ||
| 191 | + animation.SetLooping(true); | ||
| 192 | + animation.Play(); | ||
| 193 | + | ||
| 194 | + stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));; | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + /** | ||
| 198 | + * Invoked whenever the quit button is clicked | ||
| 199 | + * @param[in] button the quit button | ||
| 200 | + */ | ||
| 201 | + bool OnQuitButtonClicked( Toolkit::Button button ) | ||
| 202 | + { | ||
| 203 | + // quit the application | ||
| 204 | + mApplication.Quit(); | ||
| 205 | + return true; | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + void OnKeyEvent(const KeyEvent& event) | ||
| 209 | + { | ||
| 210 | + if(event.state == KeyEvent::Down) | ||
| 211 | + { | ||
| 212 | + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) | ||
| 213 | + { | ||
| 214 | + mApplication.Quit(); | ||
| 215 | + } | ||
| 216 | + } | ||
| 217 | + } | ||
| 218 | + | ||
| 219 | +private: | ||
| 220 | + | ||
| 221 | + Application& mApplication; ///< Application instance | ||
| 222 | + Vector3 mStageSize; ///< The size of the stage | ||
| 223 | + | ||
| 224 | + Image mImage; | ||
| 225 | + Sampler mSampler1; | ||
| 226 | + Sampler mSampler2; | ||
| 227 | + Shader mShader; | ||
| 228 | + Material mMaterial; | ||
| 229 | + Geometry mGeometry; | ||
| 230 | + Renderer mRenderer; | ||
| 231 | + Actor mMeshActor; | ||
| 232 | + Renderer mRenderer2; | ||
| 233 | + Actor mMeshActor2; | ||
| 234 | + Timer mChangeImageTimer; | ||
| 235 | +}; | ||
| 236 | + | ||
| 237 | +void RunTest( Application& application ) | ||
| 238 | +{ | ||
| 239 | + ExampleController test( application ); | ||
| 240 | + | ||
| 241 | + application.MainLoop(); | ||
| 242 | +} | ||
| 243 | + | ||
| 244 | +// Entry point for Linux & SLP applications | ||
| 245 | +// | ||
| 246 | +int main( int argc, char **argv ) | ||
| 247 | +{ | ||
| 248 | + Application application = Application::New( &argc, &argv ); | ||
| 249 | + | ||
| 250 | + RunTest( application ); | ||
| 251 | + | ||
| 252 | + return 0; | ||
| 253 | +} |
examples/radial-menu/radial-menu-example.cpp
| 1 | /* | 1 | /* |
| 2 | - * Copyright (c) 2014 Samsung Electronics Co., Ltd. | 2 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| @@ -17,7 +17,6 @@ | @@ -17,7 +17,6 @@ | ||
| 17 | 17 | ||
| 18 | #include <dali/dali.h> | 18 | #include <dali/dali.h> |
| 19 | #include <dali-toolkit/dali-toolkit.h> | 19 | #include <dali-toolkit/dali-toolkit.h> |
| 20 | -#include <dali/devel-api/actors/mesh-actor.h> | ||
| 21 | #include "shared/view.h" | 20 | #include "shared/view.h" |
| 22 | #include "radial-sweep-view.h" | 21 | #include "radial-sweep-view.h" |
| 23 | #include "radial-sweep-view-impl.h" | 22 | #include "radial-sweep-view-impl.h" |
| @@ -70,10 +69,19 @@ private: | @@ -70,10 +69,19 @@ private: | ||
| 70 | */ | 69 | */ |
| 71 | RadialSweepView CreateSweepView( std::string imageName, Degree initial, Degree final ); | 70 | RadialSweepView CreateSweepView( std::string imageName, Degree initial, Degree final ); |
| 72 | 71 | ||
| 72 | + /** | ||
| 73 | + * Start the sweep animation on the menu | ||
| 74 | + */ | ||
| 73 | void StartAnimation(); | 75 | void StartAnimation(); |
| 74 | 76 | ||
| 77 | + /** | ||
| 78 | + * Play or pause the animation when the button is clicked | ||
| 79 | + */ | ||
| 75 | bool OnButtonClicked( Toolkit::Button button ); | 80 | bool OnButtonClicked( Toolkit::Button button ); |
| 76 | 81 | ||
| 82 | + /** | ||
| 83 | + * Update the state flag and change the button icon when the animation is finished | ||
| 84 | + */ | ||
| 77 | void OnAnimationFinished( Animation& source ); | 85 | void OnAnimationFinished( Animation& source ); |
| 78 | 86 | ||
| 79 | /** | 87 | /** |
| @@ -149,16 +157,15 @@ void RadialMenuExample::OnInit(Application& app) | @@ -149,16 +157,15 @@ void RadialMenuExample::OnInit(Application& app) | ||
| 149 | DemoHelper::DEFAULT_PLAY_PADDING ); | 157 | DemoHelper::DEFAULT_PLAY_PADDING ); |
| 150 | 158 | ||
| 151 | 159 | ||
| 152 | - const Uint16Pair intImgSize = ResourceImage::GetImageSize(TEST_OUTER_RING_FILENAME); | 160 | + const ImageDimensions intImgSize = ResourceImage::GetImageSize(TEST_OUTER_RING_FILENAME); |
| 153 | Vector2 imgSize = Vector2( intImgSize.GetWidth(), intImgSize.GetHeight() ); | 161 | Vector2 imgSize = Vector2( intImgSize.GetWidth(), intImgSize.GetHeight() ); |
| 154 | Vector2 stageSize = stage.GetSize(); | 162 | Vector2 stageSize = stage.GetSize(); |
| 155 | - float minStageDimension = std::min(stageSize.width, stageSize.height); | ||
| 156 | - | ||
| 157 | - if(stageSize.height <= stageSize.width) | 163 | + float scale = stageSize.width / imgSize.width; |
| 164 | + float availableHeight = stageSize.height - DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight * 2.0f; | ||
| 165 | + if(availableHeight <= stageSize.width) | ||
| 158 | { | 166 | { |
| 159 | - minStageDimension -= DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight * 2.0f; | 167 | + scale = availableHeight / imgSize.width; |
| 160 | } | 168 | } |
| 161 | - float scale = minStageDimension / imgSize.width; | ||
| 162 | 169 | ||
| 163 | mRadialSweepView1 = CreateSweepView( TEST_OUTER_RING_FILENAME, Degree(-90.0f), Degree(-90.0f)); | 170 | mRadialSweepView1 = CreateSweepView( TEST_OUTER_RING_FILENAME, Degree(-90.0f), Degree(-90.0f)); |
| 164 | mRadialSweepView2 = CreateSweepView( TEST_INNER_RING_FILENAME, Degree(90.0f), Degree(0.0f)); | 171 | mRadialSweepView2 = CreateSweepView( TEST_INNER_RING_FILENAME, Degree(90.0f), Degree(0.0f)); |
| @@ -208,6 +215,7 @@ bool RadialMenuExample::OnButtonClicked( Toolkit::Button button ) | @@ -208,6 +215,7 @@ bool RadialMenuExample::OnButtonClicked( Toolkit::Button button ) | ||
| 208 | case PLAYING: | 215 | case PLAYING: |
| 209 | { | 216 | { |
| 210 | mAnimation.Pause(); | 217 | mAnimation.Pause(); |
| 218 | + mAnimationState = PAUSED; | ||
| 211 | mPlayStopButton.SetBackgroundImage( mIconPlay ); | 219 | mPlayStopButton.SetBackgroundImage( mIconPlay ); |
| 212 | } | 220 | } |
| 213 | break; | 221 | break; |
| @@ -215,6 +223,7 @@ bool RadialMenuExample::OnButtonClicked( Toolkit::Button button ) | @@ -215,6 +223,7 @@ bool RadialMenuExample::OnButtonClicked( Toolkit::Button button ) | ||
| 215 | case PAUSED: | 223 | case PAUSED: |
| 216 | { | 224 | { |
| 217 | mAnimation.Play(); | 225 | mAnimation.Play(); |
| 226 | + mAnimationState = PLAYING; | ||
| 218 | mPlayStopButton.SetBackgroundImage( mIconStop ); | 227 | mPlayStopButton.SetBackgroundImage( mIconStop ); |
| 219 | } | 228 | } |
| 220 | break; | 229 | break; |
| @@ -249,7 +258,7 @@ RadialSweepView RadialMenuExample::CreateSweepView( std::string imageName, | @@ -249,7 +258,7 @@ RadialSweepView RadialMenuExample::CreateSweepView( std::string imageName, | ||
| 249 | mImageActor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); | 258 | mImageActor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); |
| 250 | 259 | ||
| 251 | // Create the stencil | 260 | // Create the stencil |
| 252 | - const Uint16Pair imageSize = ResourceImage::GetImageSize(imageName); | 261 | + const ImageDimensions imageSize = ResourceImage::GetImageSize(imageName); |
| 253 | float diameter = std::max(imageSize.GetWidth(), imageSize.GetHeight()); | 262 | float diameter = std::max(imageSize.GetWidth(), imageSize.GetHeight()); |
| 254 | RadialSweepView radialSweepView = RadialSweepView::New(); | 263 | RadialSweepView radialSweepView = RadialSweepView::New(); |
| 255 | radialSweepView.SetDiameter( diameter ); | 264 | radialSweepView.SetDiameter( diameter ); |
examples/radial-menu/radial-sweep-view-impl.cpp
| 1 | /* | 1 | /* |
| 2 | - * Copyright (c) 2014 Samsung Electronics Co., Ltd. | 2 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| @@ -17,47 +17,56 @@ | @@ -17,47 +17,56 @@ | ||
| 17 | 17 | ||
| 18 | #include "radial-sweep-view-impl.h" | 18 | #include "radial-sweep-view-impl.h" |
| 19 | 19 | ||
| 20 | +#include <dali/devel-api/rendering/renderer.h> | ||
| 21 | +#include <sstream> | ||
| 22 | + | ||
| 20 | using namespace Dali; | 23 | using namespace Dali; |
| 21 | 24 | ||
| 22 | namespace | 25 | namespace |
| 23 | { | 26 | { |
| 24 | 27 | ||
| 25 | -/** | ||
| 26 | - * Method to project a point on a circle of radius halfSide at given | ||
| 27 | - * angle onto a square of side 2 * halfSide | ||
| 28 | - */ | ||
| 29 | -void CircleSquareProjection( Vector3& position, Radian angle, float halfSide ) | ||
| 30 | -{ | ||
| 31 | - // 135 90 45 | ||
| 32 | - // +--+--+ | ||
| 33 | - // | \|/ | | ||
| 34 | - // 180 +--+--+ 0 | ||
| 35 | - // | /|\ | | ||
| 36 | - // +--+--+ | ||
| 37 | - // 225 270 315 | ||
| 38 | - if( angle >= Dali::ANGLE_45 && angle < Dali::ANGLE_135 ) | ||
| 39 | - { | ||
| 40 | - position.x = halfSide * cosf(angle) / sinf(angle); | ||
| 41 | - position.y = -halfSide; | ||
| 42 | - } | ||
| 43 | - else if( angle >= Dali::ANGLE_135 && angle < Dali::ANGLE_225 ) | ||
| 44 | - { | ||
| 45 | - position.x = -halfSide; | ||
| 46 | - position.y = halfSide * sinf(angle) / cosf(angle); | ||
| 47 | - } | ||
| 48 | - else if( angle >= Dali::ANGLE_225 && angle < Dali::ANGLE_315 ) | ||
| 49 | - { | ||
| 50 | - position.x = -halfSide * cosf(angle) / sinf(angle); | ||
| 51 | - position.y = halfSide; | ||
| 52 | - } | ||
| 53 | - else | ||
| 54 | - { | ||
| 55 | - position.x = halfSide; | ||
| 56 | - position.y = -halfSide * sinf(angle) / cosf(angle); | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | - position.z = 0.0f; | 28 | +const char* VERTEX_SHADER_PREFIX( "#define MATH_PI_2 1.570796\n#define MATH_PI_4 0.785398\n" ); |
| 29 | + | ||
| 30 | +const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( | ||
| 31 | +attribute mediump float aAngleIndex;\n | ||
| 32 | +attribute mediump vec2 aPosition1;\n | ||
| 33 | +attribute mediump vec2 aPosition2;\n | ||
| 34 | +uniform mediump mat4 uMvpMatrix;\n | ||
| 35 | +uniform mediump float uStartAngle;\n | ||
| 36 | +uniform mediump float uRotationAngle;\n | ||
| 37 | +\n | ||
| 38 | +void main()\n | ||
| 39 | +{\n | ||
| 40 | + float currentAngle = uStartAngle + uRotationAngle;\n | ||
| 41 | + float angleInterval1 = MATH_PI_4 * aAngleIndex;\n | ||
| 42 | + vec4 vertexPosition = vec4(0.0, 0.0, 0.0, 1.0);\n | ||
| 43 | + if( currentAngle >= angleInterval1)\n | ||
| 44 | + {\n | ||
| 45 | + float angleInterval2 = angleInterval1 + MATH_PI_2;\n | ||
| 46 | + float angle = currentAngle < angleInterval2 ? currentAngle : angleInterval2;\n | ||
| 47 | + float delta;\n | ||
| 48 | + if( mod( aAngleIndex+4.0, 4.0) < 2.0 )\n | ||
| 49 | + {\n | ||
| 50 | + delta = 0.5 - 0.5*cos(angle) / sin(angle);\n | ||
| 51 | + }\n | ||
| 52 | + else\n | ||
| 53 | + {\n | ||
| 54 | + delta = 0.5 + 0.5*sin(angle) / cos(angle);\n | ||
| 55 | + }\n | ||
| 56 | + vertexPosition.xy = mix( aPosition1, aPosition2, delta );\n | ||
| 57 | + }\n | ||
| 58 | + gl_Position = uMvpMatrix * vertexPosition;\n | ||
| 60 | } | 59 | } |
| 60 | +); | ||
| 61 | + | ||
| 62 | +const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | ||
| 63 | +uniform lowp vec4 uColor;\n | ||
| 64 | +\n | ||
| 65 | +void main()\n | ||
| 66 | +{\n | ||
| 67 | + gl_FragColor = uColor;\n | ||
| 68 | +}\n | ||
| 69 | +); | ||
| 61 | 70 | ||
| 62 | float HoldZeroFastEaseInOutHoldOne(float progress) | 71 | float HoldZeroFastEaseInOutHoldOne(float progress) |
| 63 | { | 72 | { |
| @@ -81,58 +90,23 @@ float HoldZeroFastEaseInOutHoldOne(float progress) | @@ -81,58 +90,23 @@ float HoldZeroFastEaseInOutHoldOne(float progress) | ||
| 81 | } | 90 | } |
| 82 | } | 91 | } |
| 83 | 92 | ||
| 84 | -struct SquareFanConstraint | ||
| 85 | -{ | ||
| 86 | - SquareFanConstraint(int sideIndex) | ||
| 87 | - : mSideIndex(sideIndex) | ||
| 88 | - { | ||
| 89 | - } | ||
| 90 | - | ||
| 91 | - void operator()( Vector3& current, const PropertyInputContainer& inputs ) | ||
| 92 | - { | ||
| 93 | - float degree = fmodf((inputs[0]->GetFloat() + inputs[1]->GetFloat()), 360.0f); | ||
| 94 | - if(degree < 0.0f) | ||
| 95 | - { | ||
| 96 | - degree += 360.0f; | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - float startAngle = (90.0f*mSideIndex)-45.0f; | ||
| 100 | - float endAngle = (90.0f*mSideIndex)+45.0f; | ||
| 101 | - if(degree < startAngle) | ||
| 102 | - { | ||
| 103 | - current = Vector3::ZERO; | ||
| 104 | - } | ||
| 105 | - else | ||
| 106 | - { | ||
| 107 | - if( degree >= endAngle ) | ||
| 108 | - { | ||
| 109 | - degree = endAngle; | ||
| 110 | - } | ||
| 111 | - CircleSquareProjection( current, Degree(degree), 0.5f ); | ||
| 112 | - current.x = -current.x; // Inverting X makes the animation go anti clockwise from left center | ||
| 113 | - } | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | - int mSideIndex; | ||
| 117 | -}; | ||
| 118 | - | ||
| 119 | } // anonymous namespace | 93 | } // anonymous namespace |
| 120 | 94 | ||
| 121 | 95 | ||
| 122 | RadialSweepView RadialSweepViewImpl::New( ) | 96 | RadialSweepView RadialSweepViewImpl::New( ) |
| 123 | { | 97 | { |
| 124 | - return New( 2.0f, 100.0f, Degree(0.0f), Degree(0.0f), Degree(0.0f), Degree(359.999f) ); | 98 | + return New( 2.0f, 100.0f, ANGLE_0, ANGLE_0, ANGLE_0, ANGLE_360 ); |
| 125 | } | 99 | } |
| 126 | 100 | ||
| 127 | 101 | ||
| 128 | -RadialSweepView RadialSweepViewImpl::New( float duration, float diameter, Degree initialAngle, Degree finalAngle, Degree initialSector, Degree finalSector ) | 102 | +RadialSweepView RadialSweepViewImpl::New( float duration, float diameter, Radian initialAngle, Radian finalAngle, Radian initialSector, Radian finalSector ) |
| 129 | { | 103 | { |
| 130 | RadialSweepViewImpl* impl= new RadialSweepViewImpl(duration, diameter, initialAngle, finalAngle, initialSector, finalSector); | 104 | RadialSweepViewImpl* impl= new RadialSweepViewImpl(duration, diameter, initialAngle, finalAngle, initialSector, finalSector); |
| 131 | RadialSweepView handle = RadialSweepView(*impl); | 105 | RadialSweepView handle = RadialSweepView(*impl); |
| 132 | return handle; | 106 | return handle; |
| 133 | } | 107 | } |
| 134 | 108 | ||
| 135 | -RadialSweepViewImpl::RadialSweepViewImpl( float duration, float diameter, Degree initialAngle, Degree finalAngle, Degree initialSector, Degree finalSector ) | 109 | +RadialSweepViewImpl::RadialSweepViewImpl( float duration, float diameter, Radian initialAngle, Radian finalAngle, Radian initialSector, Radian finalSector ) |
| 136 | : Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ), | 110 | : Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ), |
| 137 | mDuration(duration), | 111 | mDuration(duration), |
| 138 | mDiameter(diameter), | 112 | mDiameter(diameter), |
| @@ -165,33 +139,33 @@ void RadialSweepViewImpl::SetDiameter(float diameter) | @@ -165,33 +139,33 @@ void RadialSweepViewImpl::SetDiameter(float diameter) | ||
| 165 | mDiameter = diameter; | 139 | mDiameter = diameter; |
| 166 | } | 140 | } |
| 167 | 141 | ||
| 168 | -void RadialSweepViewImpl::SetInitialAngle( Dali::Degree initialAngle) | 142 | +void RadialSweepViewImpl::SetInitialAngle( Dali::Radian initialAngle) |
| 169 | { | 143 | { |
| 170 | mInitialAngle = initialAngle; | 144 | mInitialAngle = initialAngle; |
| 171 | } | 145 | } |
| 172 | 146 | ||
| 173 | -void RadialSweepViewImpl::SetFinalAngle( Dali::Degree finalAngle) | 147 | +void RadialSweepViewImpl::SetFinalAngle( Dali::Radian finalAngle) |
| 174 | { | 148 | { |
| 175 | mFinalAngle = finalAngle; | 149 | mFinalAngle = finalAngle; |
| 176 | } | 150 | } |
| 177 | 151 | ||
| 178 | -void RadialSweepViewImpl::SetInitialSector( Dali::Degree initialSector) | 152 | +void RadialSweepViewImpl::SetInitialSector( Dali::Radian initialSector) |
| 179 | { | 153 | { |
| 180 | mInitialSector = initialSector; | 154 | mInitialSector = initialSector; |
| 181 | } | 155 | } |
| 182 | 156 | ||
| 183 | -void RadialSweepViewImpl::SetFinalSector( Dali::Degree finalSector) | 157 | +void RadialSweepViewImpl::SetFinalSector( Dali::Radian finalSector) |
| 184 | { | 158 | { |
| 185 | mFinalSector = finalSector; | 159 | mFinalSector = finalSector; |
| 186 | } | 160 | } |
| 187 | 161 | ||
| 188 | -void RadialSweepViewImpl::SetInitialActorAngle( Dali::Degree initialAngle ) | 162 | +void RadialSweepViewImpl::SetInitialActorAngle( Dali::Radian initialAngle ) |
| 189 | { | 163 | { |
| 190 | mInitialActorAngle = initialAngle; | 164 | mInitialActorAngle = initialAngle; |
| 191 | mRotateActors = true; | 165 | mRotateActors = true; |
| 192 | } | 166 | } |
| 193 | 167 | ||
| 194 | -void RadialSweepViewImpl::SetFinalActorAngle( Dali::Degree finalAngle ) | 168 | +void RadialSweepViewImpl::SetFinalActorAngle( Dali::Radian finalAngle ) |
| 195 | { | 169 | { |
| 196 | mFinalActorAngle = finalAngle; | 170 | mFinalActorAngle = finalAngle; |
| 197 | mRotateActors = true; | 171 | mRotateActors = true; |
| @@ -207,32 +181,32 @@ float RadialSweepViewImpl::GetDiameter( ) | @@ -207,32 +181,32 @@ float RadialSweepViewImpl::GetDiameter( ) | ||
| 207 | return mDiameter; | 181 | return mDiameter; |
| 208 | } | 182 | } |
| 209 | 183 | ||
| 210 | -Dali::Degree RadialSweepViewImpl::GetInitialAngle( ) | 184 | +Dali::Radian RadialSweepViewImpl::GetInitialAngle( ) |
| 211 | { | 185 | { |
| 212 | return mInitialAngle; | 186 | return mInitialAngle; |
| 213 | } | 187 | } |
| 214 | 188 | ||
| 215 | -Dali::Degree RadialSweepViewImpl::GetFinalAngle( ) | 189 | +Dali::Radian RadialSweepViewImpl::GetFinalAngle( ) |
| 216 | { | 190 | { |
| 217 | return mFinalAngle; | 191 | return mFinalAngle; |
| 218 | } | 192 | } |
| 219 | 193 | ||
| 220 | -Dali::Degree RadialSweepViewImpl::GetInitialSector( ) | 194 | +Dali::Radian RadialSweepViewImpl::GetInitialSector( ) |
| 221 | { | 195 | { |
| 222 | return mInitialSector; | 196 | return mInitialSector; |
| 223 | } | 197 | } |
| 224 | 198 | ||
| 225 | -Dali::Degree RadialSweepViewImpl::GetFinalSector( ) | 199 | +Dali::Radian RadialSweepViewImpl::GetFinalSector( ) |
| 226 | { | 200 | { |
| 227 | return mFinalSector; | 201 | return mFinalSector; |
| 228 | } | 202 | } |
| 229 | 203 | ||
| 230 | -Dali::Degree RadialSweepViewImpl::GetInitialActorAngle( ) | 204 | +Dali::Radian RadialSweepViewImpl::GetInitialActorAngle( ) |
| 231 | { | 205 | { |
| 232 | return mInitialActorAngle; | 206 | return mInitialActorAngle; |
| 233 | } | 207 | } |
| 234 | 208 | ||
| 235 | -Dali::Degree RadialSweepViewImpl::GetFinalActorAngle( ) | 209 | +Dali::Radian RadialSweepViewImpl::GetFinalActorAngle( ) |
| 236 | { | 210 | { |
| 237 | return mFinalActorAngle; | 211 | return mFinalActorAngle; |
| 238 | } | 212 | } |
| @@ -269,11 +243,11 @@ void RadialSweepViewImpl::Activate( Animation anim, float offsetTime, float dura | @@ -269,11 +243,11 @@ void RadialSweepViewImpl::Activate( Animation anim, float offsetTime, float dura | ||
| 269 | { | 243 | { |
| 270 | CreateStencil( mInitialSector ); | 244 | CreateStencil( mInitialSector ); |
| 271 | mLayer.Add( mStencilActor ); | 245 | mLayer.Add( mStencilActor ); |
| 272 | - mStencilActor.SetSize(mDiameter, mDiameter); | 246 | + mStencilActor.SetScale(mDiameter); |
| 273 | } | 247 | } |
| 274 | 248 | ||
| 275 | - mStencilActor.SetOrientation( Degree(mInitialAngle), Vector3::ZAXIS ); | ||
| 276 | - mStencilActor.SetProperty( mRotationAngleIndex, mInitialSector.degree ); | 249 | + mStencilActor.SetOrientation( mInitialAngle, Vector3::ZAXIS ); |
| 250 | + mStencilActor.SetProperty( mRotationAngleIndex, mInitialSector.radian ); | ||
| 277 | 251 | ||
| 278 | if( mRotateActors ) | 252 | if( mRotateActors ) |
| 279 | { | 253 | { |
| @@ -287,7 +261,7 @@ void RadialSweepViewImpl::Activate( Animation anim, float offsetTime, float dura | @@ -287,7 +261,7 @@ void RadialSweepViewImpl::Activate( Animation anim, float offsetTime, float dura | ||
| 287 | } | 261 | } |
| 288 | } | 262 | } |
| 289 | 263 | ||
| 290 | - anim.AnimateTo( Property( mStencilActor, mRotationAngleIndex ), mFinalSector.degree, mEasingFunction, TimePeriod( offsetTime, duration ) ); | 264 | + anim.AnimateTo( Property( mStencilActor, mRotationAngleIndex ), mFinalSector.radian, mEasingFunction, TimePeriod( offsetTime, duration ) ); |
| 291 | anim.AnimateTo( Property( mStencilActor, Actor::Property::ORIENTATION ), Quaternion( Radian( mFinalAngle ), Vector3::ZAXIS ), mEasingFunction, TimePeriod( offsetTime, duration ) ); | 265 | anim.AnimateTo( Property( mStencilActor, Actor::Property::ORIENTATION ), Quaternion( Radian( mFinalAngle ), Vector3::ZAXIS ), mEasingFunction, TimePeriod( offsetTime, duration ) ); |
| 292 | 266 | ||
| 293 | if( mRotateActorsWithStencil ) | 267 | if( mRotateActorsWithStencil ) |
| @@ -297,7 +271,7 @@ void RadialSweepViewImpl::Activate( Animation anim, float offsetTime, float dura | @@ -297,7 +271,7 @@ void RadialSweepViewImpl::Activate( Animation anim, float offsetTime, float dura | ||
| 297 | Actor actor = mLayer.GetChildAt(i); | 271 | Actor actor = mLayer.GetChildAt(i); |
| 298 | if( actor != mStencilActor ) | 272 | if( actor != mStencilActor ) |
| 299 | { | 273 | { |
| 300 | - anim.AnimateTo( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( mFinalAngle.degree - mInitialAngle.degree ) ), Vector3::ZAXIS ), mEasingFunction, TimePeriod( offsetTime, duration ) ); | 274 | + anim.AnimateTo( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( mFinalAngle.radian - mInitialAngle.radian ) , Vector3::ZAXIS ), mEasingFunction, TimePeriod( offsetTime, duration ) ); |
| 301 | } | 275 | } |
| 302 | } | 276 | } |
| 303 | } | 277 | } |
| @@ -334,65 +308,58 @@ void RadialSweepViewImpl::Deactivate() | @@ -334,65 +308,58 @@ void RadialSweepViewImpl::Deactivate() | ||
| 334 | // mMaterial.Reset(); | 308 | // mMaterial.Reset(); |
| 335 | } | 309 | } |
| 336 | 310 | ||
| 337 | -void RadialSweepViewImpl::CreateStencil( Degree initialSector ) | 311 | +void RadialSweepViewImpl::CreateStencil( Radian initialSector ) |
| 338 | { | 312 | { |
| 339 | - mMaterial = Material::New("Material"); | ||
| 340 | - mMaterial.SetDiffuseColor(Color::WHITE); | ||
| 341 | - mMaterial.SetAmbientColor(Vector4(0.0, 0.1, 0.1, 1.0)); | ||
| 342 | - | ||
| 343 | - // Generate a square mesh with a point at the center: | ||
| 344 | - | ||
| 345 | - AnimatableMesh::Faces faces; | ||
| 346 | - // Create triangles joining up the verts | ||
| 347 | - faces.push_back(0); faces.push_back(1); faces.push_back(2); | ||
| 348 | - faces.push_back(0); faces.push_back(2); faces.push_back(3); | ||
| 349 | - faces.push_back(0); faces.push_back(3); faces.push_back(4); | ||
| 350 | - faces.push_back(0); faces.push_back(4); faces.push_back(5); | ||
| 351 | - faces.push_back(0); faces.push_back(5); faces.push_back(6); | ||
| 352 | - | ||
| 353 | - mMesh = AnimatableMesh::New(7, faces, mMaterial); | ||
| 354 | - mMesh[0].SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) ); // Center pt | ||
| 355 | - | ||
| 356 | - mStencilActor = MeshActor::New(mMesh); | ||
| 357 | - mStencilActor.SetCullFace(CullNone); // Allow clockwise & anticlockwise faces | ||
| 358 | - | ||
| 359 | - mStartAngleIndex = mStencilActor.RegisterProperty("start-angle", Property::Value(0.0f)); | ||
| 360 | - mRotationAngleIndex = mStencilActor.RegisterProperty("rotation-angle", Property::Value(initialSector.degree)); | ||
| 361 | - | ||
| 362 | - Source srcStart( mStencilActor, mStartAngleIndex ); | ||
| 363 | - Source srcRotation( mStencilActor, mRotationAngleIndex ); | ||
| 364 | - | ||
| 365 | - // Constrain the vertices of the square mesh to sweep out a sector as the | ||
| 366 | - // rotation angle is animated. | ||
| 367 | - Constraint constraint = Constraint::New<Vector3>( mMesh, mMesh.GetPropertyIndex(1, AnimatableVertex::Property::POSITION), SquareFanConstraint(0) ); | ||
| 368 | - constraint.AddSource( srcStart ); | ||
| 369 | - constraint.AddSource( srcStart ); | ||
| 370 | - constraint.Apply(); | ||
| 371 | - | ||
| 372 | - constraint = Constraint::New<Vector3>( mMesh, mMesh.GetPropertyIndex(2, AnimatableVertex::Property::POSITION), SquareFanConstraint(0) ); | ||
| 373 | - constraint.AddSource( srcStart ); | ||
| 374 | - constraint.AddSource( srcRotation ); | ||
| 375 | - constraint.Apply(); | ||
| 376 | - | ||
| 377 | - constraint = Constraint::New<Vector3>( mMesh, mMesh.GetPropertyIndex(3, AnimatableVertex::Property::POSITION), SquareFanConstraint(1) ); | ||
| 378 | - constraint.AddSource( srcStart ); | ||
| 379 | - constraint.AddSource( srcRotation ); | ||
| 380 | - constraint.Apply(); | ||
| 381 | - | ||
| 382 | - constraint = Constraint::New<Vector3>( mMesh, mMesh.GetPropertyIndex(4, AnimatableVertex::Property::POSITION), SquareFanConstraint(2) ); | ||
| 383 | - constraint.AddSource( srcStart ); | ||
| 384 | - constraint.AddSource( srcRotation ); | ||
| 385 | - constraint.Apply(); | ||
| 386 | - | ||
| 387 | - constraint = Constraint::New<Vector3>( mMesh, mMesh.GetPropertyIndex(5, AnimatableVertex::Property::POSITION), SquareFanConstraint(3) ); | ||
| 388 | - constraint.AddSource( srcStart ); | ||
| 389 | - constraint.AddSource( srcRotation ); | ||
| 390 | - constraint.Apply(); | ||
| 391 | - | ||
| 392 | - constraint = Constraint::New<Vector3>( mMesh, mMesh.GetPropertyIndex(6, AnimatableVertex::Property::POSITION), SquareFanConstraint(4) ); | ||
| 393 | - constraint.AddSource( srcStart ); | ||
| 394 | - constraint.AddSource( srcRotation ); | ||
| 395 | - constraint.Apply(); | 313 | + // Create the stencil mesh geometry |
| 314 | + // 3-----2 | ||
| 315 | + // | \ / | | ||
| 316 | + // | 0--1 , 6 | ||
| 317 | + // | / \ | | ||
| 318 | + // 4-----5 | ||
| 319 | + | ||
| 320 | + struct VertexPosition { float angleIndex; Vector2 position1; Vector2 position2; }; | ||
| 321 | + VertexPosition vertexData[7] = { // With X coordinate inverted to make the animation go anti clockwise from left center | ||
| 322 | + { 9.f, Vector2( 0.f, 0.f ), Vector2( 0.f, 0.f ) }, // center point, keep static | ||
| 323 | + { 0.f, Vector2( -0.5f, 0.f ), Vector2( -0.5f, 0.f ) }, // vertex 1, 0 degree, keep static | ||
| 324 | + { -1.f, Vector2( -0.5f, 0.5f ), Vector2( -0.5f, -0.5f ) }, // -45 ~ 45 degrees ( 0 ~ 45) | ||
| 325 | + { 1.f, Vector2( -0.5f, -0.5f ), Vector2( 0.5f, -0.5f ) }, // 45 ~ 135 degrees | ||
| 326 | + { 3.f, Vector2( 0.5f, -0.5f ), Vector2( 0.5f, 0.5f ) }, // 135 ~ 225 degrees | ||
| 327 | + { 5.f, Vector2( 0.5f, 0.5f ), Vector2( -0.5f, 0.5f ) }, // 225 ~ 315 degrees | ||
| 328 | + { 7.f, Vector2( -0.5f, 0.5f ), Vector2( -0.5f, -0.5f ) } // 315 ~ 405 degrees ( 315 ~ 359.999 ) | ||
| 329 | + }; | ||
| 330 | + Property::Map vertexFormat; | ||
| 331 | + vertexFormat["aAngleIndex"] = Property::FLOAT; | ||
| 332 | + vertexFormat["aPosition1"] = Property::VECTOR2; | ||
| 333 | + vertexFormat["aPosition2"] = Property::VECTOR2; | ||
| 334 | + PropertyBuffer vertices = PropertyBuffer::New( vertexFormat, 7u ); | ||
| 335 | + vertices.SetData( vertexData ); | ||
| 336 | + | ||
| 337 | + unsigned int indexData[15] = { 0,1,2,0,2,3,0,3,4,0,4,5,0,5,6 }; | ||
| 338 | + Property::Map indexFormat; | ||
| 339 | + indexFormat["indices"] = Property::UNSIGNED_INTEGER; | ||
| 340 | + PropertyBuffer indices = PropertyBuffer::New( indexFormat, 15u ); | ||
| 341 | + indices.SetData( indexData ); | ||
| 342 | + | ||
| 343 | + Geometry meshGeometry = Geometry::New(); | ||
| 344 | + meshGeometry.AddVertexBuffer( vertices ); | ||
| 345 | + meshGeometry.SetIndexBuffer( indices ); | ||
| 346 | + | ||
| 347 | + // Create material | ||
| 348 | + std::ostringstream vertexShaderStringStream; | ||
| 349 | + vertexShaderStringStream<<VERTEX_SHADER_PREFIX<<VERTEX_SHADER; | ||
| 350 | + Shader shader = Shader::New( vertexShaderStringStream.str(), FRAGMENT_SHADER ); | ||
| 351 | + Material material = Material::New( shader ); | ||
| 352 | + | ||
| 353 | + // Create renderer | ||
| 354 | + Renderer renderer = Renderer::New( meshGeometry, material ); | ||
| 355 | + | ||
| 356 | + mStencilActor = Actor::New(); | ||
| 357 | + mStencilActor.AddRenderer( renderer ); | ||
| 358 | + mStencilActor.SetSize(1.f, 1.f); | ||
| 359 | + | ||
| 360 | + // register properties | ||
| 361 | + mStartAngleIndex = mStencilActor.RegisterProperty("uStartAngle", 0.f); | ||
| 362 | + mRotationAngleIndex = mStencilActor.RegisterProperty("uRotationAngle", initialSector.radian); | ||
| 396 | 363 | ||
| 397 | mStencilActor.SetDrawMode( DrawMode::STENCIL ); | 364 | mStencilActor.SetDrawMode( DrawMode::STENCIL ); |
| 398 | mStencilActor.SetPositionInheritanceMode(USE_PARENT_POSITION); | 365 | mStencilActor.SetPositionInheritanceMode(USE_PARENT_POSITION); |
examples/radial-menu/radial-sweep-view-impl.h
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | #define DALI_DEMO_RADIAL_SWEEP_VIEW_IMPL_H | 2 | #define DALI_DEMO_RADIAL_SWEEP_VIEW_IMPL_H |
| 3 | 3 | ||
| 4 | /* | 4 | /* |
| 5 | - * Copyright (c) 2014 Samsung Electronics Co., Ltd. | 5 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. |
| 6 | * | 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. | 8 | * you may not use this file except in compliance with the License. |
| @@ -19,10 +19,6 @@ | @@ -19,10 +19,6 @@ | ||
| 19 | */ | 19 | */ |
| 20 | 20 | ||
| 21 | #include <dali-toolkit/dali-toolkit.h> | 21 | #include <dali-toolkit/dali-toolkit.h> |
| 22 | -#include <dali/devel-api/actors/mesh-actor.h> | ||
| 23 | -#include <dali/devel-api/modeling/material.h> | ||
| 24 | -#include <dali/devel-api/geometry/animatable-mesh.h> | ||
| 25 | - | ||
| 26 | #include "radial-sweep-view.h" | 22 | #include "radial-sweep-view.h" |
| 27 | 23 | ||
| 28 | 24 | ||
| @@ -36,37 +32,37 @@ public: | @@ -36,37 +32,37 @@ public: | ||
| 36 | 32 | ||
| 37 | static RadialSweepView New( float duration, | 33 | static RadialSweepView New( float duration, |
| 38 | float diameter, | 34 | float diameter, |
| 39 | - Dali::Degree initialAngle, | ||
| 40 | - Dali::Degree finalAngle, | ||
| 41 | - Dali::Degree initialSector, | ||
| 42 | - Dali::Degree finalSector ); | 35 | + Dali::Radian initialAngle, |
| 36 | + Dali::Radian finalAngle, | ||
| 37 | + Dali::Radian initialSector, | ||
| 38 | + Dali::Radian finalSector ); | ||
| 43 | 39 | ||
| 44 | RadialSweepViewImpl( float duration, | 40 | RadialSweepViewImpl( float duration, |
| 45 | float diameter, | 41 | float diameter, |
| 46 | - Dali::Degree initialAngle, | ||
| 47 | - Dali::Degree finalAngle, | ||
| 48 | - Dali::Degree initialSector, | ||
| 49 | - Dali::Degree finalSector ); | 42 | + Dali::Radian initialAngle, |
| 43 | + Dali::Radian finalAngle, | ||
| 44 | + Dali::Radian initialSector, | ||
| 45 | + Dali::Radian finalSector ); | ||
| 50 | 46 | ||
| 51 | void SetDuration(float duration); | 47 | void SetDuration(float duration); |
| 52 | void SetEasingFunction( Dali::AlphaFunction easingFunction ); | 48 | void SetEasingFunction( Dali::AlphaFunction easingFunction ); |
| 53 | 49 | ||
| 54 | void SetDiameter(float diameter); | 50 | void SetDiameter(float diameter); |
| 55 | - void SetInitialAngle( Dali::Degree initialAngle); | ||
| 56 | - void SetFinalAngle( Dali::Degree finalAngle); | ||
| 57 | - void SetInitialSector( Dali::Degree initialSector); | ||
| 58 | - void SetFinalSector( Dali::Degree finalSector); | ||
| 59 | - void SetInitialActorAngle( Dali::Degree initialAngle ); | ||
| 60 | - void SetFinalActorAngle( Dali::Degree finalAngle ); | 51 | + void SetInitialAngle( Dali::Radian initialAngle); |
| 52 | + void SetFinalAngle( Dali::Radian finalAngle); | ||
| 53 | + void SetInitialSector( Dali::Radian initialSector); | ||
| 54 | + void SetFinalSector( Dali::Radian finalSector); | ||
| 55 | + void SetInitialActorAngle( Dali::Radian initialAngle ); | ||
| 56 | + void SetFinalActorAngle( Dali::Radian finalAngle ); | ||
| 61 | 57 | ||
| 62 | float GetDuration( ); | 58 | float GetDuration( ); |
| 63 | float GetDiameter( ); | 59 | float GetDiameter( ); |
| 64 | - Dali::Degree GetInitialAngle( ); | ||
| 65 | - Dali::Degree GetFinalAngle( ); | ||
| 66 | - Dali::Degree GetInitialSector( ); | ||
| 67 | - Dali::Degree GetFinalSector( ); | ||
| 68 | - Dali::Degree GetInitialActorAngle( ); | ||
| 69 | - Dali::Degree GetFinalActorAngle( ); | 60 | + Dali::Radian GetInitialAngle( ); |
| 61 | + Dali::Radian GetFinalAngle( ); | ||
| 62 | + Dali::Radian GetInitialSector( ); | ||
| 63 | + Dali::Radian GetFinalSector( ); | ||
| 64 | + Dali::Radian GetInitialActorAngle( ); | ||
| 65 | + Dali::Radian GetFinalActorAngle( ); | ||
| 70 | 66 | ||
| 71 | void RotateActorsWithStencil(bool rotate); | 67 | void RotateActorsWithStencil(bool rotate); |
| 72 | 68 | ||
| @@ -81,23 +77,21 @@ private: | @@ -81,23 +77,21 @@ private: | ||
| 81 | /** | 77 | /** |
| 82 | * Create the stencil mask | 78 | * Create the stencil mask |
| 83 | */ | 79 | */ |
| 84 | - void CreateStencil(Dali::Degree initialSector ); | 80 | + void CreateStencil(Dali::Radian initialSector ); |
| 85 | 81 | ||
| 86 | private: | 82 | private: |
| 87 | Dali::Layer mLayer; | 83 | Dali::Layer mLayer; |
| 88 | Dali::Animation mAnim; | 84 | Dali::Animation mAnim; |
| 89 | float mDuration; | 85 | float mDuration; |
| 90 | float mDiameter; | 86 | float mDiameter; |
| 91 | - Dali::Degree mInitialAngle; | ||
| 92 | - Dali::Degree mFinalAngle; | ||
| 93 | - Dali::Degree mInitialSector; | ||
| 94 | - Dali::Degree mFinalSector; | ||
| 95 | - Dali::Degree mInitialActorAngle; | ||
| 96 | - Dali::Degree mFinalActorAngle; | 87 | + Dali::Radian mInitialAngle; |
| 88 | + Dali::Radian mFinalAngle; | ||
| 89 | + Dali::Radian mInitialSector; | ||
| 90 | + Dali::Radian mFinalSector; | ||
| 91 | + Dali::Radian mInitialActorAngle; | ||
| 92 | + Dali::Radian mFinalActorAngle; | ||
| 97 | Dali::AlphaFunction mEasingFunction; | 93 | Dali::AlphaFunction mEasingFunction; |
| 98 | - Dali::MeshActor mStencilActor; ///< Stencil actor which generates mask | ||
| 99 | - Dali::Material mMaterial; ///< Material for drawing mesh actor | ||
| 100 | - Dali::AnimatableMesh mMesh; ///< Animatable mesh | 94 | + Dali::Actor mStencilActor; ///< Stencil actor which generates mask |
| 101 | Dali::Property::Index mStartAngleIndex; ///< Index of start-angle property | 95 | Dali::Property::Index mStartAngleIndex; ///< Index of start-angle property |
| 102 | Dali::Property::Index mRotationAngleIndex; ///< Index of rotation-angle property | 96 | Dali::Property::Index mRotationAngleIndex; ///< Index of rotation-angle property |
| 103 | bool mRotateActorsWithStencil:1; | 97 | bool mRotateActorsWithStencil:1; |
examples/radial-menu/radial-sweep-view.cpp
| 1 | /* | 1 | /* |
| 2 | - * Copyright (c) 2014 Samsung Electronics Co., Ltd. | 2 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| @@ -18,10 +18,6 @@ | @@ -18,10 +18,6 @@ | ||
| 18 | #include "radial-sweep-view.h" | 18 | #include "radial-sweep-view.h" |
| 19 | #include "radial-sweep-view-impl.h" | 19 | #include "radial-sweep-view-impl.h" |
| 20 | 20 | ||
| 21 | -// EXTERNAL INCLUDES | ||
| 22 | -#include <dali/devel-api/actors/mesh-actor.h> | ||
| 23 | - | ||
| 24 | - | ||
| 25 | using namespace Dali; | 21 | using namespace Dali; |
| 26 | 22 | ||
| 27 | RadialSweepView::RadialSweepView() | 23 | RadialSweepView::RadialSweepView() |
| @@ -58,10 +54,10 @@ RadialSweepView RadialSweepView::New( ) | @@ -58,10 +54,10 @@ RadialSweepView RadialSweepView::New( ) | ||
| 58 | 54 | ||
| 59 | RadialSweepView RadialSweepView::New( float duration, | 55 | RadialSweepView RadialSweepView::New( float duration, |
| 60 | float diameter, | 56 | float diameter, |
| 61 | - Degree initialAngle, | ||
| 62 | - Degree finalAngle, | ||
| 63 | - Degree initialSector, | ||
| 64 | - Degree finalSector ) | 57 | + Radian initialAngle, |
| 58 | + Radian finalAngle, | ||
| 59 | + Radian initialSector, | ||
| 60 | + Radian finalSector ) | ||
| 65 | { | 61 | { |
| 66 | return RadialSweepViewImpl::New(duration, diameter, initialAngle, finalAngle, initialSector, finalSector ); | 62 | return RadialSweepViewImpl::New(duration, diameter, initialAngle, finalAngle, initialSector, finalSector ); |
| 67 | } | 63 | } |
| @@ -92,32 +88,32 @@ void RadialSweepView::SetDiameter(float diameter) | @@ -92,32 +88,32 @@ void RadialSweepView::SetDiameter(float diameter) | ||
| 92 | GetImpl(*this).SetDiameter(diameter); | 88 | GetImpl(*this).SetDiameter(diameter); |
| 93 | } | 89 | } |
| 94 | 90 | ||
| 95 | -void RadialSweepView::SetInitialAngle( Dali::Degree initialAngle) | 91 | +void RadialSweepView::SetInitialAngle( Dali::Radian initialAngle) |
| 96 | { | 92 | { |
| 97 | GetImpl(*this).SetInitialAngle(initialAngle); | 93 | GetImpl(*this).SetInitialAngle(initialAngle); |
| 98 | } | 94 | } |
| 99 | 95 | ||
| 100 | -void RadialSweepView::SetFinalAngle( Dali::Degree finalAngle) | 96 | +void RadialSweepView::SetFinalAngle( Dali::Radian finalAngle) |
| 101 | { | 97 | { |
| 102 | GetImpl(*this).SetFinalAngle(finalAngle); | 98 | GetImpl(*this).SetFinalAngle(finalAngle); |
| 103 | } | 99 | } |
| 104 | 100 | ||
| 105 | -void RadialSweepView::SetInitialSector( Dali::Degree initialSector) | 101 | +void RadialSweepView::SetInitialSector( Dali::Radian initialSector) |
| 106 | { | 102 | { |
| 107 | GetImpl(*this).SetInitialSector(initialSector); | 103 | GetImpl(*this).SetInitialSector(initialSector); |
| 108 | } | 104 | } |
| 109 | 105 | ||
| 110 | -void RadialSweepView::SetFinalSector( Dali::Degree finalSector) | 106 | +void RadialSweepView::SetFinalSector( Dali::Radian finalSector) |
| 111 | { | 107 | { |
| 112 | GetImpl(*this).SetFinalSector(finalSector); | 108 | GetImpl(*this).SetFinalSector(finalSector); |
| 113 | } | 109 | } |
| 114 | 110 | ||
| 115 | -void RadialSweepView::SetInitialActorAngle( Dali::Degree initialAngle ) | 111 | +void RadialSweepView::SetInitialActorAngle( Dali::Radian initialAngle ) |
| 116 | { | 112 | { |
| 117 | GetImpl(*this).SetInitialActorAngle(initialAngle); | 113 | GetImpl(*this).SetInitialActorAngle(initialAngle); |
| 118 | } | 114 | } |
| 119 | 115 | ||
| 120 | -void RadialSweepView::SetFinalActorAngle( Dali::Degree finalAngle ) | 116 | +void RadialSweepView::SetFinalActorAngle( Dali::Radian finalAngle ) |
| 121 | { | 117 | { |
| 122 | GetImpl(*this).SetFinalActorAngle(finalAngle); | 118 | GetImpl(*this).SetFinalActorAngle(finalAngle); |
| 123 | } | 119 | } |
| @@ -132,32 +128,32 @@ float RadialSweepView::GetDiameter( ) | @@ -132,32 +128,32 @@ float RadialSweepView::GetDiameter( ) | ||
| 132 | return GetImpl(*this).GetDiameter(); | 128 | return GetImpl(*this).GetDiameter(); |
| 133 | } | 129 | } |
| 134 | 130 | ||
| 135 | -Dali::Degree RadialSweepView::GetInitialAngle( ) | 131 | +Dali::Radian RadialSweepView::GetInitialAngle( ) |
| 136 | { | 132 | { |
| 137 | return GetImpl(*this).GetInitialAngle(); | 133 | return GetImpl(*this).GetInitialAngle(); |
| 138 | } | 134 | } |
| 139 | 135 | ||
| 140 | -Dali::Degree RadialSweepView::GetFinalAngle( ) | 136 | +Dali::Radian RadialSweepView::GetFinalAngle( ) |
| 141 | { | 137 | { |
| 142 | return GetImpl(*this).GetFinalAngle(); | 138 | return GetImpl(*this).GetFinalAngle(); |
| 143 | } | 139 | } |
| 144 | 140 | ||
| 145 | -Dali::Degree RadialSweepView::GetInitialSector( ) | 141 | +Dali::Radian RadialSweepView::GetInitialSector( ) |
| 146 | { | 142 | { |
| 147 | return GetImpl(*this).GetInitialSector(); | 143 | return GetImpl(*this).GetInitialSector(); |
| 148 | } | 144 | } |
| 149 | 145 | ||
| 150 | -Dali::Degree RadialSweepView::GetFinalSector( ) | 146 | +Dali::Radian RadialSweepView::GetFinalSector( ) |
| 151 | { | 147 | { |
| 152 | return GetImpl(*this).GetFinalSector(); | 148 | return GetImpl(*this).GetFinalSector(); |
| 153 | } | 149 | } |
| 154 | 150 | ||
| 155 | -Dali::Degree RadialSweepView::GetInitialActorAngle( ) | 151 | +Dali::Radian RadialSweepView::GetInitialActorAngle( ) |
| 156 | { | 152 | { |
| 157 | return GetImpl(*this).GetInitialActorAngle(); | 153 | return GetImpl(*this).GetInitialActorAngle(); |
| 158 | } | 154 | } |
| 159 | 155 | ||
| 160 | -Dali::Degree RadialSweepView::GetFinalActorAngle( ) | 156 | +Dali::Radian RadialSweepView::GetFinalActorAngle( ) |
| 161 | { | 157 | { |
| 162 | return GetImpl(*this).GetFinalActorAngle(); | 158 | return GetImpl(*this).GetFinalActorAngle(); |
| 163 | } | 159 | } |
examples/radial-menu/radial-sweep-view.h
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | #define DALI_DEMO_RADIAL_SWEEP_VIEW_H | 2 | #define DALI_DEMO_RADIAL_SWEEP_VIEW_H |
| 3 | 3 | ||
| 4 | /* | 4 | /* |
| 5 | - * Copyright (c) 2014 Samsung Electronics Co., Ltd. | 5 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. |
| 6 | * | 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. | 8 | * you may not use this file except in compliance with the License. |
| @@ -31,7 +31,7 @@ class RadialSweepView : public Dali::Toolkit::Control | @@ -31,7 +31,7 @@ class RadialSweepView : public Dali::Toolkit::Control | ||
| 31 | public: | 31 | public: |
| 32 | /** | 32 | /** |
| 33 | * Create a new RadialSweepView with default parameters (2 second animation, | 33 | * Create a new RadialSweepView with default parameters (2 second animation, |
| 34 | - * no rotation, sweeping out a full cicle). | 34 | + * no rotation, sweeping out a full circle). |
| 35 | */ | 35 | */ |
| 36 | static RadialSweepView New( ); | 36 | static RadialSweepView New( ); |
| 37 | 37 | ||
| @@ -43,7 +43,7 @@ public: | @@ -43,7 +43,7 @@ public: | ||
| 43 | * @param[in] finalAngle The final angle of the anticlockwise line of the sweep sector | 43 | * @param[in] finalAngle The final angle of the anticlockwise line of the sweep sector |
| 44 | * @param[in] initialSector The angle of the starting sector | 44 | * @param[in] initialSector The angle of the starting sector |
| 45 | * @param[in] finalSector The angle of the sector at the end of the animation. | 45 | * @param[in] finalSector The angle of the sector at the end of the animation. |
| 46 | - * Note, to cover the entire circle, use a value of 359.9999f, not zero or 360. | 46 | + * Note, to cover the entire circle, use a value of 359.9999 degrees, not zero or 360 degrees. |
| 47 | * | 47 | * |
| 48 | * initial sector | 48 | * initial sector |
| 49 | * \ | . | 49 | * \ | . |
| @@ -54,10 +54,10 @@ public: | @@ -54,10 +54,10 @@ public: | ||
| 54 | */ | 54 | */ |
| 55 | static RadialSweepView New( float duration, | 55 | static RadialSweepView New( float duration, |
| 56 | float diameter, | 56 | float diameter, |
| 57 | - Dali::Degree initialAngle, | ||
| 58 | - Dali::Degree finalAngle, | ||
| 59 | - Dali::Degree initialSector, | ||
| 60 | - Dali::Degree finalSector ); | 57 | + Dali::Radian initialAngle, |
| 58 | + Dali::Radian finalAngle, | ||
| 59 | + Dali::Radian initialSector, | ||
| 60 | + Dali::Radian finalSector ); | ||
| 61 | 61 | ||
| 62 | void SetDuration(float duration); | 62 | void SetDuration(float duration); |
| 63 | 63 | ||
| @@ -65,33 +65,33 @@ public: | @@ -65,33 +65,33 @@ public: | ||
| 65 | 65 | ||
| 66 | void SetDiameter(float diameter); | 66 | void SetDiameter(float diameter); |
| 67 | 67 | ||
| 68 | - void SetInitialAngle( Dali::Degree initialAngle); | 68 | + void SetInitialAngle( Dali::Radian initialAngle); |
| 69 | 69 | ||
| 70 | - void SetFinalAngle( Dali::Degree finalAngle); | 70 | + void SetFinalAngle( Dali::Radian finalAngle); |
| 71 | 71 | ||
| 72 | - void SetInitialSector( Dali::Degree initialSector); | 72 | + void SetInitialSector( Dali::Radian initialSector); |
| 73 | 73 | ||
| 74 | - void SetFinalSector( Dali::Degree finalSector); | 74 | + void SetFinalSector( Dali::Radian finalSector); |
| 75 | 75 | ||
| 76 | - void SetInitialActorAngle( Dali::Degree initialAngle ); | 76 | + void SetInitialActorAngle( Dali::Radian initialAngle ); |
| 77 | 77 | ||
| 78 | - void SetFinalActorAngle( Dali::Degree finalAngle ); | 78 | + void SetFinalActorAngle( Dali::Radian finalAngle ); |
| 79 | 79 | ||
| 80 | float GetDuration( ); | 80 | float GetDuration( ); |
| 81 | 81 | ||
| 82 | float GetDiameter( ); | 82 | float GetDiameter( ); |
| 83 | 83 | ||
| 84 | - Dali::Degree GetInitialAngle( ); | 84 | + Dali::Radian GetInitialAngle( ); |
| 85 | 85 | ||
| 86 | - Dali::Degree GetFinalAngle( ); | 86 | + Dali::Radian GetFinalAngle( ); |
| 87 | 87 | ||
| 88 | - Dali::Degree GetInitialSector( ); | 88 | + Dali::Radian GetInitialSector( ); |
| 89 | 89 | ||
| 90 | - Dali::Degree GetFinalSector( ); | 90 | + Dali::Radian GetFinalSector( ); |
| 91 | 91 | ||
| 92 | - Dali::Degree GetInitialActorAngle( ); | 92 | + Dali::Radian GetInitialActorAngle( ); |
| 93 | 93 | ||
| 94 | - Dali::Degree GetFinalActorAngle( ); | 94 | + Dali::Radian GetFinalActorAngle( ); |
| 95 | 95 | ||
| 96 | /** | 96 | /** |
| 97 | * @param[in] rotate True if the actors should rotate with the stencil | 97 | * @param[in] rotate True if the actors should rotate with the stencil |
examples/refraction-effect/refraction-effect-example.cpp
| 1 | /* | 1 | /* |
| 2 | - * Copyright (c) 2014 Samsung Electronics Co., Ltd. | 2 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| @@ -15,18 +15,18 @@ | @@ -15,18 +15,18 @@ | ||
| 15 | * | 15 | * |
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | +// EXTERNAL INCLUDES | ||
| 18 | #include <dali/dali.h> | 19 | #include <dali/dali.h> |
| 20 | +#include <dali/devel-api/rendering/renderer.h> | ||
| 19 | #include <dali-toolkit/dali-toolkit.h> | 21 | #include <dali-toolkit/dali-toolkit.h> |
| 20 | -#include <dali/devel-api/actors/mesh-actor.h> | ||
| 21 | -#include <dali/devel-api/modeling/material.h> | ||
| 22 | -#include <dali/devel-api/geometry/mesh.h> | ||
| 23 | - | ||
| 24 | -#include "shared/view.h" | ||
| 25 | 22 | ||
| 26 | #include <fstream> | 23 | #include <fstream> |
| 27 | #include <sstream> | 24 | #include <sstream> |
| 28 | #include <limits> | 25 | #include <limits> |
| 29 | 26 | ||
| 27 | +// INTERNAL INCLUDES | ||
| 28 | +#include "shared/view.h" | ||
| 29 | + | ||
| 30 | using namespace Dali; | 30 | using namespace Dali; |
| 31 | 31 | ||
| 32 | namespace | 32 | namespace |
| @@ -52,8 +52,6 @@ const char* TEXTURE_IMAGES[]= | @@ -52,8 +52,6 @@ const char* TEXTURE_IMAGES[]= | ||
| 52 | }; | 52 | }; |
| 53 | const unsigned int NUM_TEXTURE_IMAGES( sizeof( TEXTURE_IMAGES ) / sizeof( TEXTURE_IMAGES[0] ) ); | 53 | const unsigned int NUM_TEXTURE_IMAGES( sizeof( TEXTURE_IMAGES ) / sizeof( TEXTURE_IMAGES[0] ) ); |
| 54 | 54 | ||
| 55 | -#define MAKE_SHADER(A)#A | ||
| 56 | - | ||
| 57 | struct LightOffsetConstraint | 55 | struct LightOffsetConstraint |
| 58 | { | 56 | { |
| 59 | LightOffsetConstraint( float radius ) | 57 | LightOffsetConstraint( float radius ) |
| @@ -86,214 +84,134 @@ ResourceImage LoadStageFillingImage( const char * const imagePath ) | @@ -86,214 +84,134 @@ ResourceImage LoadStageFillingImage( const char * const imagePath ) | ||
| 86 | return ResourceImage::New( imagePath, ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); | 84 | return ResourceImage::New( imagePath, ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); |
| 87 | } | 85 | } |
| 88 | 86 | ||
| 89 | -} // namespace | ||
| 90 | - | ||
| 91 | -/************************************************************************************************ | ||
| 92 | - *** This shader is used when the MeshActor is not touched*** | ||
| 93 | - ************************************************************************************************/ | ||
| 94 | -class NoEffect : public ShaderEffect | 87 | +/** |
| 88 | + * structure of the vertex in the mesh | ||
| 89 | + */ | ||
| 90 | +struct Vertex | ||
| 95 | { | 91 | { |
| 96 | -public: | ||
| 97 | - /** | ||
| 98 | - * Create an empty handle. | ||
| 99 | - */ | ||
| 100 | - NoEffect() | ||
| 101 | - { | ||
| 102 | - } | 92 | + Vector3 position; |
| 93 | + Vector3 normal; | ||
| 94 | + Vector2 textureCoord; | ||
| 103 | 95 | ||
| 104 | - /** | ||
| 105 | - * Virtual destructor | ||
| 106 | - */ | ||
| 107 | - virtual ~NoEffect() | ||
| 108 | - { | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - /** | ||
| 112 | - * Create a NoEffect object. | ||
| 113 | - * @return A handle to a newly allocated NoEffect | ||
| 114 | - */ | ||
| 115 | - static NoEffect New() | ||
| 116 | - { | ||
| 117 | - std::string vertexShader = MAKE_SHADER( | ||
| 118 | - precision mediump float;\n | ||
| 119 | - uniform mediump vec4 uTextureRect;\n | ||
| 120 | - void main()\n | ||
| 121 | - {\n | ||
| 122 | - gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 );\n | ||
| 123 | - vTexCoord = aTexCoord.xy;\n | ||
| 124 | - }\n | ||
| 125 | - ); | ||
| 126 | - std::string fragmentShader = MAKE_SHADER( | ||
| 127 | - precision mediump float;\n | ||
| 128 | - void main()\n | ||
| 129 | - {\n | ||
| 130 | - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n | ||
| 131 | - }\n | ||
| 132 | - ); | ||
| 133 | - ShaderEffect shaderEffect = ShaderEffect::New( vertexShader, fragmentShader, | ||
| 134 | - GeometryType( GEOMETRY_TYPE_TEXTURED_MESH), | ||
| 135 | - ShaderEffect::GeometryHints( ShaderEffect::HINT_NONE ) ); | ||
| 136 | - NoEffect handle( shaderEffect ); | ||
| 137 | - return handle; | ||
| 138 | - } | 96 | + Vertex() |
| 97 | + {} | ||
| 139 | 98 | ||
| 140 | -private: | ||
| 141 | - /** | ||
| 142 | - * Helper for New() | ||
| 143 | - */ | ||
| 144 | - NoEffect( ShaderEffect handle ) | ||
| 145 | - : ShaderEffect( handle ) | ||
| 146 | - { | ||
| 147 | - } | 99 | + Vertex( const Vector3& position, const Vector3& normal, const Vector2& textureCoord ) |
| 100 | + : position( position ), normal( normal ), textureCoord( textureCoord ) | ||
| 101 | + {} | ||
| 148 | }; | 102 | }; |
| 149 | 103 | ||
| 150 | -/************************************************************/ | ||
| 151 | -/* Custom refraction effect shader******************************/ | ||
| 152 | -/************************************************************/ | ||
| 153 | - | ||
| 154 | -class RefractionEffect : public ShaderEffect | ||
| 155 | -{ | ||
| 156 | -public: | ||
| 157 | - | ||
| 158 | - /** | ||
| 159 | - * Create an empty RefractionEffect handle. | ||
| 160 | - */ | ||
| 161 | - RefractionEffect() | ||
| 162 | - { | ||
| 163 | - } | ||
| 164 | - | ||
| 165 | - /** | ||
| 166 | - * Virtual destructor | ||
| 167 | - */ | ||
| 168 | - virtual ~RefractionEffect() | ||
| 169 | - { | ||
| 170 | - } | ||
| 171 | - | ||
| 172 | - /** | ||
| 173 | - * Create a RefractionEffect object. | ||
| 174 | - * @return A handle to a newly allocated RefractionEffect | ||
| 175 | - */ | ||
| 176 | - static RefractionEffect New() | ||
| 177 | - { | ||
| 178 | - std::string vertexShader = MAKE_SHADER( | ||
| 179 | - precision mediump float;\n | ||
| 180 | - varying mediump vec2 vTextureOffset;\n | ||
| 181 | - void main()\n | ||
| 182 | - {\n | ||
| 183 | - gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 );\n | ||
| 184 | - vTexCoord = aTexCoord.xy;\n | ||
| 185 | - | ||
| 186 | - vNormal = aNormal;\n | ||
| 187 | - vVertex = vec4( aPosition, 1.0 );\n | ||
| 188 | - float length = max(0.01, length(aNormal.xy)) * 40.0;\n | ||
| 189 | - vTextureOffset = aNormal.xy / length;\n | ||
| 190 | - }\n | ||
| 191 | - ); | ||
| 192 | - | ||
| 193 | - std::string fragmentShader = MAKE_SHADER( | ||
| 194 | - precision mediump float;\n | ||
| 195 | - uniform mediump float uEffectStrength;\n | ||
| 196 | - uniform mediump vec3 uLightPosition;\n | ||
| 197 | - uniform mediump vec2 uLightXYOffset;\n | ||
| 198 | - uniform mediump vec2 uLightSpinOffset;\n | ||
| 199 | - uniform mediump float uLightIntensity;\n | ||
| 200 | - varying mediump vec2 vTextureOffset;\n | ||
| 201 | - | ||
| 202 | - vec3 rgb2hsl(vec3 rgb)\n | ||
| 203 | - {\n | ||
| 204 | - float epsilon = 1.0e-10;\n | ||
| 205 | - vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n | ||
| 206 | - vec4 P = mix(vec4(rgb.bg, K.wz), vec4(rgb.gb, K.xy), step(rgb.b, rgb.g));\n | ||
| 207 | - vec4 Q = mix(vec4(P.xyw, rgb.r), vec4(rgb.r, P.yzx), step(P.x, rgb.r));\n | ||
| 208 | - \n | ||
| 209 | - // RGB -> HCV | ||
| 210 | - float value = Q.x;\n | ||
| 211 | - float chroma = Q.x - min(Q.w, Q.y);\n | ||
| 212 | - float hue = abs(Q.z + (Q.w-Q.y) / (6.0*chroma+epsilon));\n | ||
| 213 | - // HCV -> HSL | ||
| 214 | - float lightness = value - chroma*0.5;\n | ||
| 215 | - return vec3( hue, chroma/max( 1.0-abs(lightness*2.0-1.0), 1.0e-1 ), lightness );\n | ||
| 216 | - }\n | ||
| 217 | - | ||
| 218 | - vec3 hsl2rgb( vec3 hsl ) | ||
| 219 | - { | ||
| 220 | - // pure hue->RGB | ||
| 221 | - vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n | ||
| 222 | - vec3 p = abs(fract(hsl.xxx + K.xyz) * 6.0 - K.www);\n | ||
| 223 | - vec3 RGB = clamp(p - K.xxx, 0.0, 1.0);\n | ||
| 224 | - \n | ||
| 225 | - float chroma = ( 1.0 - abs( hsl.z*2.0-1.0 ) ) * hsl.y;\n | ||
| 226 | - return ( RGB - 0.5 ) * chroma + hsl.z; | ||
| 227 | - } | ||
| 228 | - | ||
| 229 | - void main()\n | ||
| 230 | - {\n | ||
| 231 | - vec3 normal = normalize( vNormal);\n | ||
| 232 | - | ||
| 233 | - vec3 lightPosition = uLightPosition + vec3(uLightXYOffset+uLightSpinOffset, 0.0);\n | ||
| 234 | - mediump vec3 vecToLight = normalize( (lightPosition - vVertex.xyz) * 0.01 );\n | ||
| 235 | - mediump float spotEffect = pow( max(0.05, vecToLight.z ) - 0.05, 8.0);\n | ||
| 236 | - | ||
| 237 | - spotEffect = spotEffect * uEffectStrength;\n | ||
| 238 | - mediump float lightDiffuse = ( ( dot( vecToLight, normal )-0.75 ) *uLightIntensity ) * spotEffect;\n | ||
| 239 | - | ||
| 240 | - lowp vec4 color = texture2D( sTexture, vTexCoord + vTextureOffset * spotEffect );\n | ||
| 241 | - vec3 lightedColor = hsl2rgb( rgb2hsl(color.rgb) + vec3(0.0,0.0,lightDiffuse) );\n | ||
| 242 | - | ||
| 243 | - gl_FragColor = vec4( lightedColor, color.a ) * uColor;\n | ||
| 244 | - }\n | ||
| 245 | - ); | ||
| 246 | - | ||
| 247 | - ShaderEffect shaderEffect = ShaderEffect::New( vertexShader, fragmentShader, | ||
| 248 | - GeometryType( GEOMETRY_TYPE_TEXTURED_MESH), | ||
| 249 | - ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ) ); | ||
| 250 | - RefractionEffect handle( shaderEffect ); | ||
| 251 | - | ||
| 252 | - Vector2 stageSize = Stage::GetCurrent().GetSize(); | ||
| 253 | - handle.SetLightPosition( Vector2(stageSize.x, 0.f) ); | ||
| 254 | - handle.SetUniform( "uLightXYOffset", Vector2::ZERO ); | ||
| 255 | - handle.SetUniform( "uLightSpinOffset", Vector2::ZERO ); | ||
| 256 | - handle.SetUniform( "uEffectStrength", 0.f ); | ||
| 257 | - handle.SetUniform( "uLightIntensity", 2.5f ); | ||
| 258 | - | ||
| 259 | - Dali::Property::Index index = handle.RegisterProperty( "uSpinAngle", 0.f ); | ||
| 260 | - Constraint constraint = Constraint::New<Vector2>( handle, handle.GetPropertyIndex("uLightSpinOffset"), LightOffsetConstraint(stageSize.x*0.1f) ); | ||
| 261 | - constraint.AddSource( LocalSource(index) ); | ||
| 262 | - constraint.Apply(); | ||
| 263 | - | ||
| 264 | - return handle; | ||
| 265 | - } | ||
| 266 | - | ||
| 267 | - void SetLightPosition( const Vector2& position ) | ||
| 268 | - { | ||
| 269 | - Vector2 stageHalfSize = Stage::GetCurrent().GetSize() * 0.5f; | ||
| 270 | - SetUniform( "uLightPosition", Vector3( position.x - stageHalfSize.x, position.y - stageHalfSize.y, stageHalfSize.x ) ); | ||
| 271 | - } | ||
| 272 | - | ||
| 273 | - void SetLightXYOffset( const Vector2& offset ) | ||
| 274 | - { | ||
| 275 | - SetUniform( "uLightXYOffset", offset ); | ||
| 276 | - } | ||
| 277 | - | ||
| 278 | - void SetEffectStrength( float strength ) | ||
| 279 | - { | ||
| 280 | - SetUniform( "uEffectStrength", strength ); | ||
| 281 | - } | 104 | +/************************************************************************************************ |
| 105 | + *** The shader source is used when the MeshActor is not touched*** | ||
| 106 | + ************************************************************************************************/ | ||
| 107 | +const char* VERTEX_SHADER_FLAT = DALI_COMPOSE_SHADER( | ||
| 108 | +attribute mediump vec3 aPosition;\n | ||
| 109 | +attribute mediump vec3 aNormal;\n | ||
| 110 | +attribute highp vec2 aTexCoord;\n | ||
| 111 | +uniform mediump mat4 uMvpMatrix;\n | ||
| 112 | +varying mediump vec2 vTexCoord;\n | ||
| 113 | +void main()\n | ||
| 114 | +{\n | ||
| 115 | + gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 );\n | ||
| 116 | + vTexCoord = aTexCoord.xy;\n | ||
| 117 | +}\n | ||
| 118 | +); | ||
| 119 | + | ||
| 120 | +const char* FRAGMENT_SHADER_FLAT = DALI_COMPOSE_SHADER( | ||
| 121 | +uniform lowp vec4 uColor;\n | ||
| 122 | +uniform sampler2D sTexture;\n | ||
| 123 | +varying mediump vec2 vTexCoord;\n | ||
| 124 | +void main()\n | ||
| 125 | +{\n | ||
| 126 | + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n | ||
| 127 | +}\n | ||
| 128 | +); | ||
| 129 | + | ||
| 130 | +/************************************************************ | ||
| 131 | + ** Custom refraction effect shader*************************** | ||
| 132 | + ************************************************************/ | ||
| 133 | +const char* VERTEX_SHADER_REFRACTION = DALI_COMPOSE_SHADER( | ||
| 134 | +attribute mediump vec3 aPosition;\n | ||
| 135 | +attribute mediump vec3 aNormal;\n | ||
| 136 | +attribute highp vec2 aTexCoord;\n | ||
| 137 | +uniform mediump mat4 uMvpMatrix;\n | ||
| 138 | +varying mediump vec4 vVertex;\n | ||
| 139 | +varying mediump vec3 vNormal;\n | ||
| 140 | +varying mediump vec2 vTexCoord;\n | ||
| 141 | +varying mediump vec2 vTextureOffset;\n | ||
| 142 | +void main()\n | ||
| 143 | +{\n | ||
| 144 | + gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 );\n | ||
| 145 | + vTexCoord = aTexCoord.xy;\n | ||
| 146 | + | ||
| 147 | + vNormal = aNormal;\n | ||
| 148 | + vVertex = vec4( aPosition, 1.0 );\n | ||
| 149 | + float length = max(0.01, length(aNormal.xy)) * 40.0;\n | ||
| 150 | + vTextureOffset = aNormal.xy / length;\n | ||
| 151 | +}\n | ||
| 152 | +); | ||
| 153 | + | ||
| 154 | +const char* FRAGMENT_SHADER_REFRACTION = DALI_COMPOSE_SHADER( | ||
| 155 | +precision mediump float;\n | ||
| 156 | +uniform mediump float uEffectStrength;\n | ||
| 157 | +uniform mediump vec3 uLightPosition;\n | ||
| 158 | +uniform mediump vec2 uLightXYOffset;\n | ||
| 159 | +uniform mediump vec2 uLightSpinOffset;\n | ||
| 160 | +uniform mediump float uLightIntensity;\n | ||
| 161 | +uniform lowp vec4 uColor;\n | ||
| 162 | +uniform sampler2D sTexture;\n | ||
| 163 | +varying mediump vec4 vVertex;\n | ||
| 164 | +varying mediump vec3 vNormal;\n | ||
| 165 | +varying mediump vec2 vTexCoord;\n | ||
| 166 | +varying mediump vec2 vTextureOffset;\n | ||
| 167 | + | ||
| 168 | +vec3 rgb2hsl(vec3 rgb)\n | ||
| 169 | +{\n | ||
| 170 | + float epsilon = 1.0e-10;\n | ||
| 171 | + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n | ||
| 172 | + vec4 P = mix(vec4(rgb.bg, K.wz), vec4(rgb.gb, K.xy), step(rgb.b, rgb.g));\n | ||
| 173 | + vec4 Q = mix(vec4(P.xyw, rgb.r), vec4(rgb.r, P.yzx), step(P.x, rgb.r));\n | ||
| 174 | + \n | ||
| 175 | + // RGB -> HCV | ||
| 176 | + float value = Q.x;\n | ||
| 177 | + float chroma = Q.x - min(Q.w, Q.y);\n | ||
| 178 | + float hue = abs(Q.z + (Q.w-Q.y) / (6.0*chroma+epsilon));\n | ||
| 179 | + // HCV -> HSL | ||
| 180 | + float lightness = value - chroma*0.5;\n | ||
| 181 | + return vec3( hue, chroma/max( 1.0-abs(lightness*2.0-1.0), 1.0e-1 ), lightness );\n | ||
| 182 | +}\n | ||
| 183 | + | ||
| 184 | +vec3 hsl2rgb( vec3 hsl )\n | ||
| 185 | +{\n | ||
| 186 | + // pure hue->RGB | ||
| 187 | + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n | ||
| 188 | + vec3 p = abs(fract(hsl.xxx + K.xyz) * 6.0 - K.www);\n | ||
| 189 | + vec3 RGB = clamp(p - K.xxx, 0.0, 1.0);\n | ||
| 190 | + \n | ||
| 191 | + float chroma = ( 1.0 - abs( hsl.z*2.0-1.0 ) ) * hsl.y;\n | ||
| 192 | + return ( RGB - 0.5 ) * chroma + hsl.z;\n | ||
| 193 | +}\n | ||
| 194 | + | ||
| 195 | +void main()\n | ||
| 196 | +{\n | ||
| 197 | + vec3 normal = normalize( vNormal);\n | ||
| 198 | + | ||
| 199 | + vec3 lightPosition = uLightPosition + vec3(uLightXYOffset+uLightSpinOffset, 0.0);\n | ||
| 200 | + mediump vec3 vecToLight = normalize( (lightPosition - vVertex.xyz) * 0.01 );\n | ||
| 201 | + mediump float spotEffect = pow( max(0.05, vecToLight.z ) - 0.05, 8.0);\n | ||
| 202 | + | ||
| 203 | + spotEffect = spotEffect * uEffectStrength;\n | ||
| 204 | + mediump float lightDiffuse = ( ( dot( vecToLight, normal )-0.75 ) *uLightIntensity ) * spotEffect;\n | ||
| 205 | + | ||
| 206 | + lowp vec4 color = texture2D( sTexture, vTexCoord + vTextureOffset * spotEffect );\n | ||
| 207 | + vec3 lightedColor = hsl2rgb( rgb2hsl(color.rgb) + vec3(0.0,0.0,lightDiffuse) );\n | ||
| 208 | + | ||
| 209 | + gl_FragColor = vec4( lightedColor, color.a ) * uColor;\n | ||
| 210 | +}\n | ||
| 211 | +); | ||
| 282 | 212 | ||
| 283 | - void SetLightIntensity( float intensity ) | ||
| 284 | - { | ||
| 285 | - SetUniform( "uLightIntensity", intensity ); | ||
| 286 | - } | 213 | +} // namespace |
| 287 | 214 | ||
| 288 | -private: | ||
| 289 | - /** | ||
| 290 | - * Helper for New() | ||
| 291 | - */ | ||
| 292 | - RefractionEffect( ShaderEffect handle ) | ||
| 293 | - : ShaderEffect( handle ) | ||
| 294 | - { | ||
| 295 | - } | ||
| 296 | -}; | ||
| 297 | 215 | ||
| 298 | /*************************************************/ | 216 | /*************************************************/ |
| 299 | /*Demo using RefractionEffect*****************/ | 217 | /*Demo using RefractionEffect*****************/ |
| @@ -303,7 +221,6 @@ class RefractionEffectExample : public ConnectionTracker | @@ -303,7 +221,6 @@ class RefractionEffectExample : public ConnectionTracker | ||
| 303 | public: | 221 | public: |
| 304 | RefractionEffectExample( Application &application ) | 222 | RefractionEffectExample( Application &application ) |
| 305 | : mApplication( application ), | 223 | : mApplication( application ), |
| 306 | - mIsDown( false ), | ||
| 307 | mCurrentTextureId( 1 ), | 224 | mCurrentTextureId( 1 ), |
| 308 | mCurrentMeshId( 0 ) | 225 | mCurrentMeshId( 0 ) |
| 309 | { | 226 | { |
| @@ -321,7 +238,7 @@ private: | @@ -321,7 +238,7 @@ private: | ||
| 321 | void Create(Application& application) | 238 | void Create(Application& application) |
| 322 | { | 239 | { |
| 323 | Stage stage = Stage::GetCurrent(); | 240 | Stage stage = Stage::GetCurrent(); |
| 324 | - mStageHalfSize = stage.GetSize() * 0.5f; | 241 | + Vector2 stageSize = stage.GetSize(); |
| 325 | 242 | ||
| 326 | stage.KeyEventSignal().Connect(this, &RefractionEffectExample::OnKeyEvent); | 243 | stage.KeyEventSignal().Connect(this, &RefractionEffectExample::OnKeyEvent); |
| 327 | 244 | ||
| @@ -353,37 +270,68 @@ private: | @@ -353,37 +270,68 @@ private: | ||
| 353 | Toolkit::Alignment::HorizontalLeft, | 270 | Toolkit::Alignment::HorizontalLeft, |
| 354 | DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); | 271 | DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); |
| 355 | 272 | ||
| 356 | - // creates the shader effects applied on the mesh actor | ||
| 357 | - mRefractionEffect = RefractionEffect::New(); // used when the finger is touching the screen | ||
| 358 | - mNoEffect = NoEffect::New(); // used in the other situations, basic render shader | ||
| 359 | - // Create the mesh from the obj file and add to stage | ||
| 360 | - mMaterial = Material::New( "Material" ) ; | ||
| 361 | - mMaterial.SetDiffuseTexture( LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] ) ); | ||
| 362 | - CreateSurface( MESH_FILES[mCurrentMeshId] ); | 273 | + |
| 274 | + | ||
| 275 | + // shader used when the screen is not touched, render a flat surface | ||
| 276 | + mShaderFlat = Shader::New( VERTEX_SHADER_FLAT, FRAGMENT_SHADER_FLAT ); | ||
| 277 | + mGeometry = CreateGeometry( MESH_FILES[mCurrentMeshId] ); | ||
| 278 | + | ||
| 279 | + Image texture = LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] ); | ||
| 280 | + mSampler = Sampler::New( texture, "sTexture" ); | ||
| 281 | + mMaterial = Material::New( mShaderFlat ); | ||
| 282 | + mMaterial.AddSampler( mSampler ); | ||
| 283 | + | ||
| 284 | + mRenderer = Renderer::New( mGeometry, mMaterial ); | ||
| 285 | + | ||
| 286 | + mMeshActor = Actor::New(); | ||
| 287 | + mMeshActor.AddRenderer( mRenderer ); | ||
| 288 | + mMeshActor.SetSize( stageSize ); | ||
| 289 | + mMeshActor.SetParentOrigin(ParentOrigin::CENTER); | ||
| 290 | + mContent.Add( mMeshActor ); | ||
| 363 | 291 | ||
| 364 | // Connect the callback to the touch signal on the mesh actor | 292 | // Connect the callback to the touch signal on the mesh actor |
| 365 | mContent.TouchedSignal().Connect( this, &RefractionEffectExample::OnTouch ); | 293 | mContent.TouchedSignal().Connect( this, &RefractionEffectExample::OnTouch ); |
| 366 | 294 | ||
| 295 | + // shader used when the finger is touching the screen. render refraction effect | ||
| 296 | + mShaderRefraction = Shader::New( VERTEX_SHADER_REFRACTION, FRAGMENT_SHADER_REFRACTION ); | ||
| 297 | + | ||
| 298 | + // register uniforms | ||
| 299 | + mLightXYOffsetIndex = mMeshActor.RegisterProperty( "uLightXYOffset", Vector2::ZERO ); | ||
| 300 | + | ||
| 301 | + mLightIntensityIndex = mMeshActor.RegisterProperty( "uLightIntensity", 2.5f ); | ||
| 302 | + | ||
| 303 | + mEffectStrengthIndex = mMeshActor.RegisterProperty( "uEffectStrength", 0.f ); | ||
| 304 | + | ||
| 305 | + Vector3 lightPosition( -stageSize.x*0.5f, -stageSize.y*0.5f, stageSize.x*0.5f ); // top_left | ||
| 306 | + mMeshActor.RegisterProperty( "uLightPosition", lightPosition ); | ||
| 307 | + | ||
| 308 | + Property::Index lightSpinOffsetIndex = mMeshActor.RegisterProperty( "uLightSpinOffset", Vector2::ZERO ); | ||
| 309 | + | ||
| 310 | + mSpinAngleIndex = mMeshActor.RegisterProperty("uSpinAngle", 0.f ); | ||
| 311 | + Constraint constraint = Constraint::New<Vector2>( mMeshActor, lightSpinOffsetIndex, LightOffsetConstraint(stageSize.x*0.1f) ); | ||
| 312 | + constraint.AddSource( LocalSource(mSpinAngleIndex) ); | ||
| 313 | + constraint.Apply(); | ||
| 314 | + | ||
| 367 | // the animation which spin the light around the finger touch position | 315 | // the animation which spin the light around the finger touch position |
| 368 | - mLightPosition = Vector2( mStageHalfSize.x*2.f, 0.f); | ||
| 369 | mLightAnimation = Animation::New(2.f); | 316 | mLightAnimation = Animation::New(2.f); |
| 370 | - mLightAnimation.AnimateTo( Property( mRefractionEffect, "uSpinAngle" ), Math::PI*2.f ); | 317 | + mLightAnimation.AnimateTo( Property( mMeshActor, mSpinAngleIndex ), Math::PI*2.f ); |
| 371 | mLightAnimation.SetLooping( true ); | 318 | mLightAnimation.SetLooping( true ); |
| 372 | mLightAnimation.Pause(); | 319 | mLightAnimation.Pause(); |
| 373 | } | 320 | } |
| 374 | 321 | ||
| 322 | + void SetLightXYOffset( const Vector2& offset ) | ||
| 323 | + { | ||
| 324 | + mMeshActor.SetProperty( mLightXYOffsetIndex, offset ); | ||
| 325 | + } | ||
| 326 | + | ||
| 375 | /** | 327 | /** |
| 376 | * Create a mesh actor with different geometry to replace the current one | 328 | * Create a mesh actor with different geometry to replace the current one |
| 377 | */ | 329 | */ |
| 378 | bool OnChangeMesh( Toolkit::Button button ) | 330 | bool OnChangeMesh( Toolkit::Button button ) |
| 379 | { | 331 | { |
| 380 | - if( mMeshActor ) | ||
| 381 | - { | ||
| 382 | - UnparentAndReset( mMeshActor ); | ||
| 383 | - } | ||
| 384 | - | ||
| 385 | mCurrentMeshId = ( mCurrentMeshId + 1 ) % NUM_MESH_FILES; | 332 | mCurrentMeshId = ( mCurrentMeshId + 1 ) % NUM_MESH_FILES; |
| 386 | - CreateSurface( MESH_FILES[mCurrentMeshId] ); | 333 | + mGeometry = CreateGeometry( MESH_FILES[mCurrentMeshId] ); |
| 334 | + mRenderer.SetGeometry( mGeometry ); | ||
| 387 | 335 | ||
| 388 | return true; | 336 | return true; |
| 389 | } | 337 | } |
| @@ -391,21 +339,21 @@ private: | @@ -391,21 +339,21 @@ private: | ||
| 391 | bool OnChangeTexture( Toolkit::Button button ) | 339 | bool OnChangeTexture( Toolkit::Button button ) |
| 392 | { | 340 | { |
| 393 | mCurrentTextureId = ( mCurrentTextureId + 1 ) % NUM_TEXTURE_IMAGES; | 341 | mCurrentTextureId = ( mCurrentTextureId + 1 ) % NUM_TEXTURE_IMAGES; |
| 394 | - mMaterial.SetDiffuseTexture( LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] ) ); | ||
| 395 | - | 342 | + Image texture = LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] ); |
| 343 | + mSampler.SetImage( texture ); | ||
| 396 | return true; | 344 | return true; |
| 397 | } | 345 | } |
| 398 | 346 | ||
| 399 | bool OnTouch( Actor actor , const TouchEvent& event ) | 347 | bool OnTouch( Actor actor , const TouchEvent& event ) |
| 400 | { | 348 | { |
| 401 | const TouchPoint &point = event.GetPoint(0); | 349 | const TouchPoint &point = event.GetPoint(0); |
| 402 | - | ||
| 403 | switch(point.state) | 350 | switch(point.state) |
| 404 | { | 351 | { |
| 405 | case TouchPoint::Down: | 352 | case TouchPoint::Down: |
| 406 | { | 353 | { |
| 407 | - mIsDown = true; | ||
| 408 | - mDownPosition = point.screen; | 354 | + mMaterial.SetShader( mShaderRefraction ); |
| 355 | + | ||
| 356 | + SetLightXYOffset( point.screen ); | ||
| 409 | 357 | ||
| 410 | mLightAnimation.Play(); | 358 | mLightAnimation.Play(); |
| 411 | 359 | ||
| @@ -414,42 +362,32 @@ private: | @@ -414,42 +362,32 @@ private: | ||
| 414 | mStrenghAnimation.Clear(); | 362 | mStrenghAnimation.Clear(); |
| 415 | } | 363 | } |
| 416 | 364 | ||
| 417 | - mRefractionEffect.SetLightXYOffset( point.screen - mLightPosition ); | ||
| 418 | - mMeshActor.SetShaderEffect( mRefractionEffect ); | ||
| 419 | mStrenghAnimation= Animation::New(0.5f); | 365 | mStrenghAnimation= Animation::New(0.5f); |
| 420 | - mStrenghAnimation.AnimateTo( Property( mRefractionEffect, "uEffectStrength" ), 1.f ); | 366 | + mStrenghAnimation.AnimateTo( Property( mMeshActor, mEffectStrengthIndex ), 1.f ); |
| 421 | mStrenghAnimation.Play(); | 367 | mStrenghAnimation.Play(); |
| 422 | 368 | ||
| 423 | break; | 369 | break; |
| 424 | } | 370 | } |
| 425 | case TouchPoint::Motion: | 371 | case TouchPoint::Motion: |
| 426 | { | 372 | { |
| 427 | - if(mIsDown) | ||
| 428 | - { | ||
| 429 | - // make the light position following the finger movement | ||
| 430 | - mRefractionEffect.SetLightXYOffset( point.screen - mLightPosition ); | ||
| 431 | - } | 373 | + // make the light position following the finger movement |
| 374 | + SetLightXYOffset( point.screen ); | ||
| 432 | break; | 375 | break; |
| 433 | } | 376 | } |
| 434 | case TouchPoint::Up: | 377 | case TouchPoint::Up: |
| 435 | case TouchPoint::Leave: | 378 | case TouchPoint::Leave: |
| 436 | case TouchPoint::Interrupted: | 379 | case TouchPoint::Interrupted: |
| 437 | { | 380 | { |
| 438 | - if(mIsDown) | ||
| 439 | - { | ||
| 440 | - mLightAnimation.Pause(); | 381 | + mLightAnimation.Pause(); |
| 441 | 382 | ||
| 442 | - if( mStrenghAnimation ) | ||
| 443 | - { | ||
| 444 | - mStrenghAnimation.Clear(); | ||
| 445 | - } | ||
| 446 | - mStrenghAnimation = Animation::New(0.5f); | ||
| 447 | - mStrenghAnimation.AnimateTo( Property( mRefractionEffect, "uEffectStrength" ), 0.f ); | ||
| 448 | - mStrenghAnimation.FinishedSignal().Connect( this, &RefractionEffectExample::OnTouchFinished ); | ||
| 449 | - mStrenghAnimation.Play(); | 383 | + if( mStrenghAnimation ) |
| 384 | + { | ||
| 385 | + mStrenghAnimation.Clear(); | ||
| 450 | } | 386 | } |
| 451 | - | ||
| 452 | - mIsDown = false; | 387 | + mStrenghAnimation = Animation::New(0.5f); |
| 388 | + mStrenghAnimation.AnimateTo( Property( mMeshActor, mEffectStrengthIndex ), 0.f ); | ||
| 389 | + mStrenghAnimation.FinishedSignal().Connect( this, &RefractionEffectExample::OnTouchFinished ); | ||
| 390 | + mStrenghAnimation.Play(); | ||
| 453 | break; | 391 | break; |
| 454 | } | 392 | } |
| 455 | case TouchPoint::Stationary: | 393 | case TouchPoint::Stationary: |
| @@ -459,24 +397,21 @@ private: | @@ -459,24 +397,21 @@ private: | ||
| 459 | break; | 397 | break; |
| 460 | } | 398 | } |
| 461 | } | 399 | } |
| 400 | + | ||
| 462 | return true; | 401 | return true; |
| 463 | } | 402 | } |
| 464 | 403 | ||
| 465 | void OnTouchFinished( Animation& source ) | 404 | void OnTouchFinished( Animation& source ) |
| 466 | { | 405 | { |
| 467 | - mMeshActor.SetShaderEffect( mNoEffect ); | ||
| 468 | - mRefractionEffect.SetLightXYOffset( Vector2::ZERO ); | 406 | + mMaterial.SetShader( mShaderFlat ); |
| 407 | + SetLightXYOffset( Vector2::ZERO ); | ||
| 469 | } | 408 | } |
| 470 | 409 | ||
| 471 | - void CreateSurface( const std::string& objFileName ) | 410 | + Geometry CreateGeometry(const std::string& objFileName) |
| 472 | { | 411 | { |
| 473 | - MeshData::VertexContainer vertices; | ||
| 474 | - MeshData::FaceIndices faces; | ||
| 475 | - MeshData meshData; | ||
| 476 | - | ||
| 477 | - std::vector<float> boundingBox; | ||
| 478 | std::vector<Vector3> vertexPositions; | 412 | std::vector<Vector3> vertexPositions; |
| 479 | - std::vector<int> faceIndices; | 413 | + Vector<unsigned int> faceIndices; |
| 414 | + Vector<float> boundingBox; | ||
| 480 | // read the vertice and faces from the .obj file, and record the bounding box | 415 | // read the vertice and faces from the .obj file, and record the bounding box |
| 481 | ReadObjFile( objFileName, boundingBox, vertexPositions, faceIndices ); | 416 | ReadObjFile( objFileName, boundingBox, vertexPositions, faceIndices ); |
| 482 | 417 | ||
| @@ -486,53 +421,55 @@ private: | @@ -486,53 +421,55 @@ private: | ||
| 486 | 421 | ||
| 487 | // re-organize the mesh, the vertices are duplicated, each vertex only belongs to one triangle. | 422 | // re-organize the mesh, the vertices are duplicated, each vertex only belongs to one triangle. |
| 488 | // Without sharing vertex between triangle, so we can manipulate the texture offset on each triangle conveniently. | 423 | // Without sharing vertex between triangle, so we can manipulate the texture offset on each triangle conveniently. |
| 489 | - for( std::size_t i=0; i<faceIndices.size(); i=i+3 ) | 424 | + std::vector<Vertex> vertices; |
| 425 | + | ||
| 426 | + std::size_t size = faceIndices.Size(); | ||
| 427 | + vertices.reserve( size ); | ||
| 428 | + | ||
| 429 | + for( std::size_t i=0; i<size; i=i+3 ) | ||
| 490 | { | 430 | { |
| 491 | Vector3 edge1 = vertexPositions[ faceIndices[i+2] ] - vertexPositions[ faceIndices[i] ]; | 431 | Vector3 edge1 = vertexPositions[ faceIndices[i+2] ] - vertexPositions[ faceIndices[i] ]; |
| 492 | Vector3 edge2 = vertexPositions[ faceIndices[i+1] ] - vertexPositions[ faceIndices[i] ]; | 432 | Vector3 edge2 = vertexPositions[ faceIndices[i+1] ] - vertexPositions[ faceIndices[i] ]; |
| 493 | Vector3 normal = edge1.Cross(edge2); | 433 | Vector3 normal = edge1.Cross(edge2); |
| 494 | normal.Normalize(); | 434 | normal.Normalize(); |
| 495 | 435 | ||
| 436 | + // make sure all the faces are front-facing | ||
| 496 | if( normal.z > 0 ) | 437 | if( normal.z > 0 ) |
| 497 | { | 438 | { |
| 498 | - faces.push_back( i ); | ||
| 499 | - faces.push_back( i+1 ); | ||
| 500 | - faces.push_back( i+2 ); | 439 | + vertices.push_back( Vertex( vertexPositions[ faceIndices[i] ], normal, textureCoordinates[ faceIndices[i] ] ) ); |
| 440 | + vertices.push_back( Vertex( vertexPositions[ faceIndices[i+1] ], normal, textureCoordinates[ faceIndices[i+1] ] ) ); | ||
| 441 | + vertices.push_back( Vertex( vertexPositions[ faceIndices[i+2] ], normal, textureCoordinates[ faceIndices[i+2] ] ) ); | ||
| 501 | } | 442 | } |
| 502 | else | 443 | else |
| 503 | { | 444 | { |
| 504 | normal *= -1.f; | 445 | normal *= -1.f; |
| 505 | - faces.push_back( i ); | ||
| 506 | - faces.push_back( i+2 ); | ||
| 507 | - faces.push_back( i+1 ); | 446 | + vertices.push_back( Vertex( vertexPositions[ faceIndices[i] ], normal, textureCoordinates[ faceIndices[i] ] ) ); |
| 447 | + vertices.push_back( Vertex( vertexPositions[ faceIndices[i+2] ], normal, textureCoordinates[ faceIndices[i+2] ] ) ); | ||
| 448 | + vertices.push_back( Vertex( vertexPositions[ faceIndices[i+1] ], normal, textureCoordinates[ faceIndices[i+1] ] ) ); | ||
| 508 | } | 449 | } |
| 450 | + } | ||
| 509 | 451 | ||
| 510 | - vertices.push_back( MeshData::Vertex( vertexPositions[ faceIndices[i] ], textureCoordinates[ faceIndices[i] ], normal ) ); | ||
| 511 | - vertices.push_back( MeshData::Vertex( vertexPositions[ faceIndices[i+1] ], textureCoordinates[ faceIndices[i+1] ], normal ) ); | ||
| 512 | - vertices.push_back( MeshData::Vertex( vertexPositions[ faceIndices[i+2] ], textureCoordinates[ faceIndices[i+2] ], normal ) ); | 452 | + Property::Map vertexFormat; |
| 453 | + vertexFormat["aPosition"] = Property::VECTOR3; | ||
| 454 | + vertexFormat["aNormal"] = Property::VECTOR3; | ||
| 455 | + vertexFormat["aTexCoord"] = Property::VECTOR2; | ||
| 456 | + PropertyBuffer surfaceVertices = PropertyBuffer::New( vertexFormat, vertices.size() ); | ||
| 457 | + surfaceVertices.SetData( &vertices[0] ); | ||
| 513 | 458 | ||
| 514 | - } | 459 | + Geometry surface = Geometry::New(); |
| 460 | + surface.AddVertexBuffer( surfaceVertices ); | ||
| 515 | 461 | ||
| 516 | - // Now ready to construct the mesh actor | ||
| 517 | - meshData.SetMaterial( mMaterial ); | ||
| 518 | - meshData.SetVertices( vertices ); | ||
| 519 | - meshData.SetFaceIndices( faces ); | ||
| 520 | - meshData.SetHasTextureCoords(true); | ||
| 521 | - meshData.SetHasNormals(true); | ||
| 522 | - mMeshActor = MeshActor::New( Mesh::New( meshData ) ); | ||
| 523 | - mMeshActor.SetParentOrigin(ParentOrigin::CENTER); | ||
| 524 | - mMeshActor.SetShaderEffect( mNoEffect ); | ||
| 525 | - mContent.Add( mMeshActor ); | 462 | + return surface; |
| 526 | } | 463 | } |
| 527 | 464 | ||
| 528 | void ReadObjFile( const std::string& objFileName, | 465 | void ReadObjFile( const std::string& objFileName, |
| 529 | - std::vector<float>& boundingBox, | 466 | + Vector<float>& boundingBox, |
| 530 | std::vector<Vector3>& vertexPositions, | 467 | std::vector<Vector3>& vertexPositions, |
| 531 | - std::vector<int>& faceIndices) | 468 | + Vector<unsigned int>& faceIndices) |
| 532 | { | 469 | { |
| 533 | std::ifstream ifs( objFileName.c_str(), std::ios::in ); | 470 | std::ifstream ifs( objFileName.c_str(), std::ios::in ); |
| 534 | 471 | ||
| 535 | - boundingBox.resize( 6 ); | 472 | + boundingBox.Resize( 6 ); |
| 536 | boundingBox[0]=boundingBox[2]=boundingBox[4] = std::numeric_limits<float>::max(); | 473 | boundingBox[0]=boundingBox[2]=boundingBox[4] = std::numeric_limits<float>::max(); |
| 537 | boundingBox[1]=boundingBox[3]=boundingBox[5] = -std::numeric_limits<float>::max(); | 474 | boundingBox[1]=boundingBox[3]=boundingBox[5] = -std::numeric_limits<float>::max(); |
| 538 | 475 | ||
| @@ -568,20 +505,20 @@ private: | @@ -568,20 +505,20 @@ private: | ||
| 568 | } | 505 | } |
| 569 | 506 | ||
| 570 | std::istringstream iss(line.substr(2), std::istringstream::in); | 507 | std::istringstream iss(line.substr(2), std::istringstream::in); |
| 571 | - int indices[ numOfInt ]; | 508 | + unsigned int indices[ numOfInt ]; |
| 572 | unsigned int i=0; | 509 | unsigned int i=0; |
| 573 | while( iss >> indices[i++] && i < numOfInt); | 510 | while( iss >> indices[i++] && i < numOfInt); |
| 574 | unsigned int step = (i+1) / 3; | 511 | unsigned int step = (i+1) / 3; |
| 575 | - faceIndices.push_back( indices[0]-1 ); | ||
| 576 | - faceIndices.push_back( indices[step]-1 ); | ||
| 577 | - faceIndices.push_back( indices[2*step]-1 ); | 512 | + faceIndices.PushBack( indices[0]-1 ); |
| 513 | + faceIndices.PushBack( indices[step]-1 ); | ||
| 514 | + faceIndices.PushBack( indices[2*step]-1 ); | ||
| 578 | } | 515 | } |
| 579 | } | 516 | } |
| 580 | 517 | ||
| 581 | ifs.close(); | 518 | ifs.close(); |
| 582 | } | 519 | } |
| 583 | 520 | ||
| 584 | - void ShapeResizeAndTexureCoordinateCalculation( const std::vector<float>& boundingBox, | 521 | + void ShapeResizeAndTexureCoordinateCalculation( const Vector<float>& boundingBox, |
| 585 | std::vector<Vector3>& vertexPositions, | 522 | std::vector<Vector3>& vertexPositions, |
| 586 | std::vector<Vector2>& textureCoordinates) | 523 | std::vector<Vector2>& textureCoordinates) |
| 587 | { | 524 | { |
| @@ -592,12 +529,13 @@ private: | @@ -592,12 +529,13 @@ private: | ||
| 592 | Vector3 scale( stageSize.x / bBoxSize.x, stageSize.y / bBoxSize.y, 1.f ); | 529 | Vector3 scale( stageSize.x / bBoxSize.x, stageSize.y / bBoxSize.y, 1.f ); |
| 593 | scale.z = (scale.x + scale.y)/2.f; | 530 | scale.z = (scale.x + scale.y)/2.f; |
| 594 | 531 | ||
| 532 | + textureCoordinates.reserve(vertexPositions.size()); | ||
| 533 | + | ||
| 595 | for( std::vector<Vector3>::iterator iter = vertexPositions.begin(); iter != vertexPositions.end(); iter++ ) | 534 | for( std::vector<Vector3>::iterator iter = vertexPositions.begin(); iter != vertexPositions.end(); iter++ ) |
| 596 | { | 535 | { |
| 597 | Vector3 newPosition( (*iter) - bBoxMinCorner ) ; | 536 | Vector3 newPosition( (*iter) - bBoxMinCorner ) ; |
| 598 | 537 | ||
| 599 | - Vector2 textureCoord( newPosition.x / bBoxSize.x, newPosition.y / bBoxSize.y ); | ||
| 600 | - textureCoordinates.push_back( textureCoord ); | 538 | + textureCoordinates.push_back( Vector2( newPosition.x / bBoxSize.x, newPosition.y / bBoxSize.y ) ); |
| 601 | 539 | ||
| 602 | newPosition -= bBoxSize * 0.5f; | 540 | newPosition -= bBoxSize * 0.5f; |
| 603 | (*iter) = newPosition * scale; | 541 | (*iter) = newPosition * scale; |
| @@ -623,18 +561,22 @@ private: | @@ -623,18 +561,22 @@ private: | ||
| 623 | Application& mApplication; | 561 | Application& mApplication; |
| 624 | Layer mContent; | 562 | Layer mContent; |
| 625 | 563 | ||
| 626 | - bool mIsDown; | ||
| 627 | - Vector2 mDownPosition; | ||
| 628 | - Vector2 mLightPosition; | ||
| 629 | - Vector2 mStageHalfSize; | ||
| 630 | - | 564 | + Sampler mSampler; |
| 631 | Material mMaterial; | 565 | Material mMaterial; |
| 632 | - MeshActor mMeshActor; | 566 | + Geometry mGeometry; |
| 567 | + Renderer mRenderer; | ||
| 568 | + Actor mMeshActor; | ||
| 569 | + | ||
| 570 | + Shader mShaderFlat; | ||
| 571 | + Shader mShaderRefraction; | ||
| 572 | + | ||
| 573 | + Animation mLightAnimation; | ||
| 574 | + Animation mStrenghAnimation; | ||
| 633 | 575 | ||
| 634 | - RefractionEffect mRefractionEffect; | ||
| 635 | - NoEffect mNoEffect; | ||
| 636 | - Animation mLightAnimation; | ||
| 637 | - Animation mStrenghAnimation; | 576 | + Property::Index mLightXYOffsetIndex; |
| 577 | + Property::Index mSpinAngleIndex; | ||
| 578 | + Property::Index mLightIntensityIndex; | ||
| 579 | + Property::Index mEffectStrengthIndex; | ||
| 638 | 580 | ||
| 639 | Toolkit::PushButton mChangeTextureButton; | 581 | Toolkit::PushButton mChangeTextureButton; |
| 640 | Toolkit::PushButton mChangeMeshButton; | 582 | Toolkit::PushButton mChangeMeshButton; |
examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp
| @@ -167,6 +167,7 @@ public: | @@ -167,6 +167,7 @@ public: | ||
| 167 | // Setup | 167 | // Setup |
| 168 | mView.SetPosition(Vector3(0.0f, 0.0f, -50)); | 168 | mView.SetPosition(Vector3(0.0f, 0.0f, -50)); |
| 169 | 169 | ||
| 170 | + mContents.SetBehavior(Layer::LAYER_3D); | ||
| 170 | mContents.SetPosition(mTranslation); | 171 | mContents.SetPosition(mTranslation); |
| 171 | mContents.SetOrientation( CalculateWorldRotation( mSceneXRotation, mSceneYRotation ) ); | 172 | mContents.SetOrientation( CalculateWorldRotation( mSceneXRotation, mSceneYRotation ) ); |
| 172 | mContents.SetScale(mPinchScale, mPinchScale, mPinchScale); | 173 | mContents.SetScale(mPinchScale, mPinchScale, mPinchScale); |
examples/textured-mesh/textured-mesh-example.cpp
0 โ 100644
| 1 | +/* | ||
| 2 | + * Copyright (c) 2014 Samsung Electronics Co., Ltd. | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + | ||
| 18 | +// EXTERNAL INCLUDES | ||
| 19 | +#include <dali/devel-api/rendering/renderer.h> | ||
| 20 | +#include <dali-toolkit/dali-toolkit.h> | ||
| 21 | + | ||
| 22 | +// INTERNAL INCLUDES | ||
| 23 | +#include "shared/view.h" | ||
| 24 | + | ||
| 25 | +using namespace Dali; | ||
| 26 | + | ||
| 27 | +namespace | ||
| 28 | +{ | ||
| 29 | +const char* MATERIAL_SAMPLE( DALI_IMAGE_DIR "gallery-small-48.jpg" ); | ||
| 30 | +const char* MATERIAL_SAMPLE2( DALI_IMAGE_DIR "gallery-medium-19.jpg" ); | ||
| 31 | + | ||
| 32 | +#define MAKE_SHADER(A)#A | ||
| 33 | + | ||
| 34 | +const char* VERTEX_SHADER = MAKE_SHADER( | ||
| 35 | +attribute mediump vec2 aPosition; | ||
| 36 | +attribute highp vec2 aTexCoord; | ||
| 37 | +varying mediump vec2 vTexCoord; | ||
| 38 | +uniform mediump mat4 uMvpMatrix; | ||
| 39 | +uniform mediump vec3 uSize; | ||
| 40 | +uniform lowp vec4 uFadeColor; | ||
| 41 | + | ||
| 42 | +void main() | ||
| 43 | +{ | ||
| 44 | + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); | ||
| 45 | + vertexPosition.xyz *= uSize; | ||
| 46 | + vertexPosition = uMvpMatrix * vertexPosition; | ||
| 47 | + vTexCoord = aTexCoord; | ||
| 48 | + gl_Position = vertexPosition; | ||
| 49 | +} | ||
| 50 | +); | ||
| 51 | + | ||
| 52 | +const char* FRAGMENT_SHADER = MAKE_SHADER( | ||
| 53 | +varying mediump vec2 vTexCoord; | ||
| 54 | +uniform lowp vec4 uColor; | ||
| 55 | +uniform sampler2D sTexture; | ||
| 56 | +uniform lowp vec4 uFadeColor; | ||
| 57 | + | ||
| 58 | +void main() | ||
| 59 | +{ | ||
| 60 | + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * uFadeColor; | ||
| 61 | +} | ||
| 62 | +); | ||
| 63 | + | ||
| 64 | +Geometry CreateGeometry() | ||
| 65 | +{ | ||
| 66 | + // Create vertices | ||
| 67 | + const float halfQuadSize = .5f; | ||
| 68 | + struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; | ||
| 69 | + TexturedQuadVertex texturedQuadVertexData[4] = { | ||
| 70 | + { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) }, | ||
| 71 | + { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) }, | ||
| 72 | + { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) }, | ||
| 73 | + { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } }; | ||
| 74 | + | ||
| 75 | + Property::Map texturedQuadVertexFormat; | ||
| 76 | + texturedQuadVertexFormat["aPosition"] = Property::VECTOR2; | ||
| 77 | + texturedQuadVertexFormat["aTexCoord"] = Property::VECTOR2; | ||
| 78 | + PropertyBuffer texturedQuadVertices = PropertyBuffer::New( texturedQuadVertexFormat, 4 ); | ||
| 79 | + texturedQuadVertices.SetData(texturedQuadVertexData); | ||
| 80 | + | ||
| 81 | + // Create indices | ||
| 82 | + unsigned int indexData[6] = { 0, 3, 1, 0, 2, 3 }; | ||
| 83 | + Property::Map indexFormat; | ||
| 84 | + indexFormat["indices"] = Property::UNSIGNED_INTEGER; | ||
| 85 | + PropertyBuffer indices = PropertyBuffer::New( indexFormat, sizeof(indexData)/sizeof(indexData[0]) ); | ||
| 86 | + indices.SetData(indexData); | ||
| 87 | + | ||
| 88 | + // Create the geometry object | ||
| 89 | + Geometry texturedQuadGeometry = Geometry::New(); | ||
| 90 | + texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices ); | ||
| 91 | + texturedQuadGeometry.SetIndexBuffer( indices ); | ||
| 92 | + | ||
| 93 | + return texturedQuadGeometry; | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +/** | ||
| 97 | + * Sinusoidal curve starting at zero with 2 cycles | ||
| 98 | + */ | ||
| 99 | +float AlphaFunctionSineX2(float progress) | ||
| 100 | +{ | ||
| 101 | + return 0.5f - cosf(progress * 4.0f * Math::PI) * 0.5f; | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +} // anonymous namespace | ||
| 105 | + | ||
| 106 | +// This example shows how to use a simple mesh | ||
| 107 | +// | ||
| 108 | +class ExampleController : public ConnectionTracker | ||
| 109 | +{ | ||
| 110 | +public: | ||
| 111 | + | ||
| 112 | + /** | ||
| 113 | + * The example controller constructor. | ||
| 114 | + * @param[in] application The application instance | ||
| 115 | + */ | ||
| 116 | + ExampleController( Application& application ) | ||
| 117 | + : mApplication( application ) | ||
| 118 | + { | ||
| 119 | + // Connect to the Application's Init signal | ||
| 120 | + mApplication.InitSignal().Connect( this, &ExampleController::Create ); | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + /** | ||
| 124 | + * The example controller destructor | ||
| 125 | + */ | ||
| 126 | + ~ExampleController() | ||
| 127 | + { | ||
| 128 | + // Nothing to do here; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * Invoked upon creation of application | ||
| 133 | + * @param[in] application The application instance | ||
| 134 | + */ | ||
| 135 | + void Create( Application& application ) | ||
| 136 | + { | ||
| 137 | + // The Init signal is received once (only) during the Application lifetime | ||
| 138 | + | ||
| 139 | + Stage stage = Stage::GetCurrent(); | ||
| 140 | + stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); | ||
| 141 | + | ||
| 142 | + mStageSize = stage.GetSize(); | ||
| 143 | + | ||
| 144 | + // Hide the indicator bar | ||
| 145 | + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); | ||
| 146 | + | ||
| 147 | + mImage = ResourceImage::New( MATERIAL_SAMPLE, ResourceImage::ON_DEMAND, Image::NEVER ); | ||
| 148 | + mSampler1 = Sampler::New(mImage, "sTexture"); | ||
| 149 | + | ||
| 150 | + Image image = ResourceImage::New( MATERIAL_SAMPLE2 ); | ||
| 151 | + mSampler2 = Sampler::New(image, "sTexture"); | ||
| 152 | + | ||
| 153 | + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); | ||
| 154 | + mMaterial1 = Material::New( mShader ); | ||
| 155 | + mMaterial1.AddSampler( mSampler1 ); | ||
| 156 | + | ||
| 157 | + mMaterial2 = Material::New( mShader ); | ||
| 158 | + mMaterial2.AddSampler( mSampler2 ); | ||
| 159 | + | ||
| 160 | + mGeometry = CreateGeometry(); | ||
| 161 | + | ||
| 162 | + mRenderer = Renderer::New( mGeometry, mMaterial1 ); | ||
| 163 | + | ||
| 164 | + mMeshActor = Actor::New(); | ||
| 165 | + mMeshActor.AddRenderer( mRenderer ); | ||
| 166 | + mMeshActor.SetSize(400, 400); | ||
| 167 | + | ||
| 168 | + Property::Index fadeColorIndex = mMeshActor.RegisterProperty( "uFadeColor", Color::GREEN ); | ||
| 169 | + | ||
| 170 | + fadeColorIndex = mRenderer.RegisterProperty( "uFadeColor", Color::MAGENTA ); | ||
| 171 | + mRenderer.SetDepthIndex(0); | ||
| 172 | + | ||
| 173 | + mMeshActor.SetParentOrigin( ParentOrigin::TOP_CENTER ); | ||
| 174 | + mMeshActor.SetAnchorPoint( AnchorPoint::TOP_CENTER ); | ||
| 175 | + stage.Add( mMeshActor ); | ||
| 176 | + | ||
| 177 | + mRenderer2 = Renderer::New( mGeometry, mMaterial2 ); | ||
| 178 | + | ||
| 179 | + mMeshActor2 = Actor::New(); | ||
| 180 | + mMeshActor2.AddRenderer( mRenderer2 ); | ||
| 181 | + mMeshActor2.SetSize(400, 400); | ||
| 182 | + | ||
| 183 | + mMeshActor2.RegisterProperty( "a-n-other-property", Color::GREEN ); | ||
| 184 | + Property::Index fadeColorIndex2 = mMeshActor2.RegisterProperty( "uFadeColor", Color::GREEN ); | ||
| 185 | + | ||
| 186 | + mRenderer2.RegisterProperty( "a-n-other-property", Vector3::ZERO ); | ||
| 187 | + mRenderer2.RegisterProperty( "a-coefficient", 0.008f ); | ||
| 188 | + fadeColorIndex2 = mRenderer2.RegisterProperty( "uFadeColor", Color::BLUE ); | ||
| 189 | + mRenderer2.SetDepthIndex(0); | ||
| 190 | + | ||
| 191 | + mMeshActor2.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); | ||
| 192 | + mMeshActor2.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); | ||
| 193 | + stage.Add( mMeshActor2 ); | ||
| 194 | + | ||
| 195 | + Animation animation = Animation::New(5); | ||
| 196 | + KeyFrames keyFrames = KeyFrames::New(); | ||
| 197 | + keyFrames.Add(0.0f, Vector4::ZERO); | ||
| 198 | + keyFrames.Add(1.0f, Vector4( Color::GREEN )); | ||
| 199 | + | ||
| 200 | + KeyFrames keyFrames2 = KeyFrames::New(); | ||
| 201 | + keyFrames2.Add(0.0f, Vector4::ZERO); | ||
| 202 | + keyFrames2.Add(1.0f, Color::MAGENTA); | ||
| 203 | + | ||
| 204 | + animation.AnimateBetween( Property( mRenderer, fadeColorIndex ), keyFrames, AlphaFunction(AlphaFunction::SIN) ); | ||
| 205 | + animation.AnimateBetween( Property( mRenderer2, fadeColorIndex2 ), keyFrames2, AlphaFunction(AlphaFunctionSineX2) ); | ||
| 206 | + animation.SetLooping(true); | ||
| 207 | + animation.Play(); | ||
| 208 | + | ||
| 209 | + stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));; | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + BufferImage CreateBufferImage() | ||
| 213 | + { | ||
| 214 | + BufferImage image = BufferImage::New( 200, 200, Pixel::RGB888 ); | ||
| 215 | + PixelBuffer* pixelBuffer = image.GetBuffer(); | ||
| 216 | + unsigned int stride = image.GetBufferStride(); | ||
| 217 | + for( unsigned int x=0; x<200; x++ ) | ||
| 218 | + { | ||
| 219 | + for( unsigned int y=0; y<200; y++ ) | ||
| 220 | + { | ||
| 221 | + PixelBuffer* pixel = pixelBuffer + y*stride + x*3; | ||
| 222 | + if( ((int)(x/20.0f))%2 + ((int)(y/20.0f)%2) == 1 ) | ||
| 223 | + { | ||
| 224 | + pixel[0]=255; | ||
| 225 | + pixel[1]=0; | ||
| 226 | + pixel[2]=0; | ||
| 227 | + pixel[3]=255; | ||
| 228 | + } | ||
| 229 | + else | ||
| 230 | + { | ||
| 231 | + pixel[0]=0; | ||
| 232 | + pixel[1]=0; | ||
| 233 | + pixel[2]=255; | ||
| 234 | + pixel[3]=255; | ||
| 235 | + } | ||
| 236 | + } | ||
| 237 | + } | ||
| 238 | + image.Update(); | ||
| 239 | + return image; | ||
| 240 | + } | ||
| 241 | + | ||
| 242 | + /** | ||
| 243 | + * Invoked whenever the quit button is clicked | ||
| 244 | + * @param[in] button the quit button | ||
| 245 | + */ | ||
| 246 | + bool OnQuitButtonClicked( Toolkit::Button button ) | ||
| 247 | + { | ||
| 248 | + // quit the application | ||
| 249 | + mApplication.Quit(); | ||
| 250 | + return true; | ||
| 251 | + } | ||
| 252 | + | ||
| 253 | + void OnKeyEvent(const KeyEvent& event) | ||
| 254 | + { | ||
| 255 | + if(event.state == KeyEvent::Down) | ||
| 256 | + { | ||
| 257 | + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) | ||
| 258 | + { | ||
| 259 | + mApplication.Quit(); | ||
| 260 | + } | ||
| 261 | + } | ||
| 262 | + } | ||
| 263 | + | ||
| 264 | +private: | ||
| 265 | + | ||
| 266 | + Application& mApplication; ///< Application instance | ||
| 267 | + Vector3 mStageSize; ///< The size of the stage | ||
| 268 | + | ||
| 269 | + Image mImage; | ||
| 270 | + Sampler mSampler1; | ||
| 271 | + Sampler mSampler2; | ||
| 272 | + Shader mShader; | ||
| 273 | + Material mMaterial1; | ||
| 274 | + Material mMaterial2; | ||
| 275 | + Geometry mGeometry; | ||
| 276 | + Renderer mRenderer; | ||
| 277 | + Actor mMeshActor; | ||
| 278 | + Renderer mRenderer2; | ||
| 279 | + Actor mMeshActor2; | ||
| 280 | + Timer mChangeImageTimer; | ||
| 281 | +}; | ||
| 282 | + | ||
| 283 | +void RunTest( Application& application ) | ||
| 284 | +{ | ||
| 285 | + ExampleController test( application ); | ||
| 286 | + | ||
| 287 | + application.MainLoop(); | ||
| 288 | +} | ||
| 289 | + | ||
| 290 | +// Entry point for Linux & SLP applications | ||
| 291 | +// | ||
| 292 | +int main( int argc, char **argv ) | ||
| 293 | +{ | ||
| 294 | + Application application = Application::New( &argc, &argv ); | ||
| 295 | + | ||
| 296 | + RunTest( application ); | ||
| 297 | + | ||
| 298 | + return 0; | ||
| 299 | +} |
shared/dali-demo-strings.h
| @@ -53,11 +53,13 @@ extern "C" | @@ -53,11 +53,13 @@ extern "C" | ||
| 53 | #define DALI_DEMO_STR_TITLE_TEXT_LABEL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL") | 53 | #define DALI_DEMO_STR_TITLE_TEXT_LABEL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL") |
| 54 | #define DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE") | 54 | #define DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE") |
| 55 | #define DALI_DEMO_STR_TITLE_EMOJI_TEXT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_EMOJI_TEXT") | 55 | #define DALI_DEMO_STR_TITLE_EMOJI_TEXT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_EMOJI_TEXT") |
| 56 | -#define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES dgettext(DALI_DEMO_STR_TITLE_ANIMATED_SHAPES) | ||
| 57 | -#define DALI_DEMO_STR_TITLE_PATH_ANIMATION dgettext(DALI_DEMO_STR_TITLE_PATH_ANIMATION) | ||
| 58 | #define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE dgettext(DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE) | 56 | #define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE dgettext(DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE) |
| 59 | #define DALI_DEMO_STR_TITLE_BUTTONS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BUTTONS") | 57 | #define DALI_DEMO_STR_TITLE_BUTTONS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BUTTONS") |
| 60 | #define DALI_DEMO_STR_TITLE_LOGGING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_LOGGING") | 58 | #define DALI_DEMO_STR_TITLE_LOGGING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_LOGGING") |
| 59 | +#define DALI_DEMO_STR_TITLE_MESH_MORPH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_MESH_MORPH") | ||
| 60 | +#define DALI_DEMO_STR_TITLE_MESH_SORTING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_MESH_SORTING") | ||
| 61 | +#define DALI_DEMO_STR_TITLE_TEXTURED_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TEXTURED_MESH") | ||
| 62 | +#define DALI_DEMO_STR_TITLE_LINE_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_LINE_MESH") | ||
| 61 | 63 | ||
| 62 | #else // !INTERNATIONALIZATION_ENABLED | 64 | #else // !INTERNATIONALIZATION_ENABLED |
| 63 | 65 | ||
| @@ -82,11 +84,13 @@ extern "C" | @@ -82,11 +84,13 @@ extern "C" | ||
| 82 | #define DALI_DEMO_STR_TITLE_TEXT_LABEL "Text Label" | 84 | #define DALI_DEMO_STR_TITLE_TEXT_LABEL "Text Label" |
| 83 | #define DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE "Text Scripts" | 85 | #define DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE "Text Scripts" |
| 84 | #define DALI_DEMO_STR_TITLE_EMOJI_TEXT "Emoji Text" | 86 | #define DALI_DEMO_STR_TITLE_EMOJI_TEXT "Emoji Text" |
| 85 | -#define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES "Animated Shapes" | ||
| 86 | -#define DALI_DEMO_STR_TITLE_PATH_ANIMATION "Animated Path" | ||
| 87 | #define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE "Negotiate Size" | 87 | #define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE "Negotiate Size" |
| 88 | #define DALI_DEMO_STR_TITLE_BUTTONS "Buttons" | 88 | #define DALI_DEMO_STR_TITLE_BUTTONS "Buttons" |
| 89 | #define DALI_DEMO_STR_TITLE_LOGGING "Logging" | 89 | #define DALI_DEMO_STR_TITLE_LOGGING "Logging" |
| 90 | +#define DALI_DEMO_STR_TITLE_MESH_MORPH "Mesh Morph" | ||
| 91 | +#define DALI_DEMO_STR_TITLE_MESH_SORTING "Mesh Sorting" | ||
| 92 | +#define DALI_DEMO_STR_TITLE_TEXTURED_MESH "Mesh Texture" | ||
| 93 | +#define DALI_DEMO_STR_TITLE_LINE_MESH "Mesh Line" | ||
| 90 | 94 | ||
| 91 | #endif | 95 | #endif |
| 92 | 96 |
shared/view.h
| @@ -26,6 +26,13 @@ | @@ -26,6 +26,13 @@ | ||
| 26 | namespace DemoHelper | 26 | namespace DemoHelper |
| 27 | { | 27 | { |
| 28 | 28 | ||
| 29 | +enum ControlDepthIndexRanges | ||
| 30 | +{ | ||
| 31 | + BACKGROUND_DEPTH_INDEX = -10000000, | ||
| 32 | + CONTENT_DEPTH_INDEX = 0, | ||
| 33 | + DECORATION_DEPTH_INDEX = 10000000 | ||
| 34 | +}; | ||
| 35 | + | ||
| 29 | /** | 36 | /** |
| 30 | * Provide a style for the view and its tool bar. | 37 | * Provide a style for the view and its tool bar. |
| 31 | */ | 38 | */ |
| @@ -94,7 +101,6 @@ Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar, | @@ -94,7 +101,6 @@ Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar, | ||
| 94 | { | 101 | { |
| 95 | Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New(); | 102 | Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New(); |
| 96 | label.SetAnchorPoint( Dali::AnchorPoint::TOP_LEFT ); | 103 | label.SetAnchorPoint( Dali::AnchorPoint::TOP_LEFT ); |
| 97 | - label.SetDrawMode( Dali::DrawMode::OVERLAY ); | ||
| 98 | label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" ); | 104 | label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" ); |
| 99 | label.SetProperty( Dali::Toolkit::TextLabel::Property::TEXT, title ); | 105 | label.SetProperty( Dali::Toolkit::TextLabel::Property::TEXT, title ); |
| 100 | label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); | 106 | label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); |
| @@ -160,7 +166,6 @@ Dali::Toolkit::TextLabel CreateToolBarLabel( const std::string& text ) | @@ -160,7 +166,6 @@ Dali::Toolkit::TextLabel CreateToolBarLabel( const std::string& text ) | ||
| 160 | { | 166 | { |
| 161 | Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New( text ); | 167 | Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New( text ); |
| 162 | label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" ); | 168 | label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" ); |
| 163 | - label.SetDrawMode( Dali::DrawMode::OVERLAY ); | ||
| 164 | label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); | 169 | label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); |
| 165 | label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); | 170 | label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); |
| 166 | label.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT ); | 171 | label.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT ); |