2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/dali-toolkit.h>
22 #include "shared/utility.h"
23 #include "shared/view.h"
24 #include "generated/textured-mesh-vert.h"
25 #include "generated/textured-mesh-frag.h"
31 const char* MATERIAL_SAMPLE(DEMO_IMAGE_DIR "gallery-small-48.jpg");
32 const char* MATERIAL_SAMPLE2(DEMO_IMAGE_DIR "gallery-medium-19.jpg");
35 * Sinusoidal curve starting at zero with 2 cycles
37 float AlphaFunctionSineX2(float progress)
39 return 0.5f - cosf(progress * 4.0f * Math::PI) * 0.5f;
42 } // anonymous namespace
44 // This example shows how to use a simple mesh
46 class ExampleController : public ConnectionTracker
50 * The example controller constructor.
51 * @param[in] application The application instance
53 ExampleController(Application& application)
54 : mApplication(application)
56 // Connect to the Application's Init signal
57 mApplication.InitSignal().Connect(this, &ExampleController::Create);
61 * The example controller destructor
65 // Nothing to do here;
69 * Invoked upon creation of application
70 * @param[in] application The application instance
72 void Create(Application& application)
74 // The Init signal is received once (only) during the Application lifetime
76 Window window = application.GetWindow();
77 window.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent);
79 mWindowSize = window.GetSize();
81 Texture texture1 = DemoHelper::LoadTexture(MATERIAL_SAMPLE);
82 Texture texture2 = DemoHelper::LoadTexture(MATERIAL_SAMPLE2);
84 mShader = Shader::New(SHADER_TEXTURED_MESH_VERT, SHADER_TEXTURED_MESH_FRAG);
85 mTextureSet1 = TextureSet::New();
86 mTextureSet1.SetTexture(0u, texture1);
88 mTextureSet2 = TextureSet::New();
89 mTextureSet2.SetTexture(0u, texture2);
91 mGeometry = DemoHelper::CreateTexturedQuad();
93 mRenderer = Renderer::New(mGeometry, mShader);
94 mRenderer.SetTextures(mTextureSet1);
96 mMeshActor = Actor::New();
97 mMeshActor.AddRenderer(mRenderer);
98 mMeshActor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
100 Property::Index fadeColorIndex = mRenderer.RegisterProperty("uFadeColor", Color::MAGENTA);
101 mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, 0);
103 mMeshActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER);
104 mMeshActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
105 window.Add(mMeshActor);
107 mRenderer2 = Renderer::New(mGeometry, mShader);
108 mRenderer2.SetTextures(mTextureSet2);
110 mMeshActor2 = Actor::New();
111 mMeshActor2.AddRenderer(mRenderer2);
112 mMeshActor2.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
114 mMeshActor2.RegisterProperty("anotherProperty", Color::GREEN);
116 mRenderer2.RegisterProperty("anotherProperty", Vector3::ZERO);
117 mRenderer2.RegisterProperty("aCoefficient", 0.008f);
118 Property::Index fadeColorIndex2 = mRenderer2.RegisterProperty("uFadeColor", Color::BLUE);
119 mRenderer2.SetProperty(Renderer::Property::DEPTH_INDEX, 0);
121 mMeshActor2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER);
122 mMeshActor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER);
123 window.Add(mMeshActor2);
125 Animation animation = Animation::New(5);
126 KeyFrames keyFrames = KeyFrames::New();
127 keyFrames.Add(0.0f, Vector4::ZERO);
128 keyFrames.Add(1.0f, Vector4(Color::GREEN));
130 KeyFrames keyFrames2 = KeyFrames::New();
131 keyFrames2.Add(0.0f, Vector4::ZERO);
132 keyFrames2.Add(1.0f, Color::MAGENTA);
134 animation.AnimateBetween(Property(mRenderer, fadeColorIndex), keyFrames, AlphaFunction(AlphaFunction::SIN));
135 animation.AnimateBetween(Property(mRenderer2, fadeColorIndex2), keyFrames2, AlphaFunction(AlphaFunctionSineX2));
136 animation.SetLooping(true);
139 window.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));
143 * Invoked whenever the quit button is clicked
144 * @param[in] button the quit button
146 bool OnQuitButtonClicked(Toolkit::Button button)
148 // quit the application
153 void OnKeyEvent(const KeyEvent& event)
155 if(event.GetState() == KeyEvent::DOWN)
157 if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
165 Application& mApplication; ///< Application instance
166 Vector3 mWindowSize; ///< The size of the window
169 TextureSet mTextureSet1;
170 TextureSet mTextureSet2;
176 Timer mChangeImageTimer;
179 int DALI_EXPORT_API main(int argc, char** argv)
181 Application application = Application::New(&argc, &argv);
182 ExampleController test(application);
183 application.MainLoop();