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.
18 * @file transition-application.cpp
19 * @brief Application class for showing stylable transitions
23 #include "transition-application.h"
26 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
30 #include "beat-control.h"
35 using namespace Dali::Toolkit;
39 void SetLabelText(Button button, const char* label)
41 button.SetProperty(Toolkit::Button::Property::LABEL, label);
48 const char* TransitionApplication::DEMO_THEME_ONE_PATH(DEMO_STYLE_DIR "style-example-theme-one.json");
49 const char* DALI_LOGO_PATH(DEMO_IMAGE_DIR "Logo-for-demo.png");
50 const char* DALI_ROBOT_MODEL_PATH(DEMO_MODEL_DIR "ToyRobot-Metal.obj");
51 const char* DALI_ROBOT_MATERIAL_PATH(DEMO_MODEL_DIR "ToyRobot-Metal.mtl");
53 TransitionApplication::TransitionApplication(Application& application)
54 : mApplication(application),
58 mVisualIndex(Property::INVALID_INDEX),
59 mActionIndex(Property::INVALID_INDEX)
61 application.InitSignal().Connect(this, &TransitionApplication::Create);
64 TransitionApplication::~TransitionApplication()
68 void TransitionApplication::Create(Application& application)
70 Window window = application.GetWindow();
71 window.KeyEventSignal().Connect(this, &TransitionApplication::OnKeyEvent);
72 window.SetBackgroundColor(Vector4(0.1f, 0.1f, 0.1f, 1.0f));
75 TableView contentLayout = TableView::New(4, 1);
76 contentLayout.SetProperty(Dali::Actor::Property::NAME, "ContentLayout");
77 contentLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
78 contentLayout.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
79 contentLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
80 contentLayout.SetCellPadding(Vector2(0.0f, 5.0f));
82 // Assign all rows the size negotiation property of fitting to children
84 window.Add(contentLayout);
86 mTitle = TextLabel::New("Custom Control Transition Example");
87 mTitle.SetProperty(Dali::Actor::Property::NAME, "Title");
88 mTitle.SetStyleName("Title");
89 mTitle.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
90 mTitle.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
91 mTitle.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER");
92 contentLayout.Add(mTitle);
93 contentLayout.SetFitHeight(0); // Fill width
95 mBeatControl = BeatControl::New();
96 mBeatControl.SetProperty(Dali::Actor::Property::NAME, "BeatControl");
97 mBeatControl.SetProperty(BeatControl::Property::BEAT_VISUAL, Property::Map().Add(Visual::Property::TRANSFORM, Property::Map().Add(Visual::Transform::Property::SIZE, Vector2(0.5f, 0.5f))));
99 mBeatControl.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
100 mBeatControl.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
101 mBeatControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
102 contentLayout.Add(mBeatControl);
103 // beat control should fill the tableview cell, so no change to default parameters
105 TableView visualTypeLayout = TableView::New(1, NUMBER_OF_VISUAL_BUTTONS);
106 visualTypeLayout.SetProperty(Dali::Actor::Property::NAME, "VisualTypeLayout");
107 visualTypeLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
108 visualTypeLayout.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT);
109 visualTypeLayout.SetFitHeight(0);
111 contentLayout.Add(visualTypeLayout);
112 contentLayout.SetFitHeight(2);
114 for(int i = 0; i < NUMBER_OF_VISUAL_BUTTONS; ++i)
117 CreateVisualMap(i, map);
118 map.Add(Visual::Property::TRANSFORM, Property::Map().Add(Visual::Transform::Property::SIZE, Vector2(0.8f, 0.8f)));
119 mVisualButtons[i] = BeatControl::New();
120 mVisualButtons[i].SetProperty(BeatControl::Property::BEAT_VISUAL, map);
121 mVisualButtons[i].SetProperty(Dali::Actor::Property::NAME, "VisualButton");
122 mVisualButtons[i].SetStyleName("VisualButton");
123 mVisualButtons[i].SetProperty(Actor::Property::SIZE, Vector2(0, 50));
124 mVisualButtons[i].SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
125 mVisualButtons[i].SetResizePolicy(ResizePolicy::FIXED, Dimension::HEIGHT);
126 mVisualIndex = mVisualButtons[i].RegisterProperty("visualId", i, Property::READ_WRITE);
127 mVisualButtons[i].TouchedSignal().Connect(this, &TransitionApplication::OnVisualButtonClicked);
128 visualTypeLayout.AddChild(mVisualButtons[i], TableView::CellPosition(0, i));
131 TableView actionButtonLayout = TableView::New(1, NUMBER_OF_ACTION_BUTTONS + 1);
132 actionButtonLayout.SetProperty(Dali::Actor::Property::NAME, "ThemeButtonsLayout");
133 actionButtonLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
134 actionButtonLayout.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT);
135 actionButtonLayout.SetFitHeight(0);
137 TextLabel label = TextLabel::New("Action: ");
138 label.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
139 label.SetStyleName("ActionLabel");
140 actionButtonLayout.AddChild(label, TableView::CellPosition(0, 0));
141 actionButtonLayout.SetCellAlignment(TableView::CellPosition(0, 0), HorizontalAlignment::LEFT, VerticalAlignment::CENTER);
143 for(int i = 0; i < NUMBER_OF_ACTION_BUTTONS; ++i)
145 mActionButtons[i] = PushButton::New();
146 mActionButtons[i].SetProperty(Dali::Actor::Property::NAME, "ActionButton");
147 mActionButtons[i].SetStyleName("ActionButton");
148 mActionButtons[i].SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
149 mActionButtons[i].SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
150 mActionIndex = mActionButtons[i].RegisterProperty("actionId", i, Property::READ_WRITE);
151 mActionButtons[i].ClickedSignal().Connect(this, &TransitionApplication::OnActionButtonClicked);
152 actionButtonLayout.AddChild(mActionButtons[i], TableView::CellPosition(0, 1 + i));
155 SetLabelText(mActionButtons[0], "Bounce");
156 SetLabelText(mActionButtons[1], "X");
157 SetLabelText(mActionButtons[2], "Y");
158 SetLabelText(mActionButtons[3], "Fade");
160 contentLayout.Add(actionButtonLayout);
161 contentLayout.SetFitHeight(3);
164 void TransitionApplication::CreateVisualMap(int index, Property::Map& map)
170 map[Toolkit::Visual::Property::TYPE] = Visual::COLOR;
171 map[ColorVisual::Property::MIX_COLOR] = Color::YELLOW;
176 map[Toolkit::Visual::Property::TYPE] = Visual::BORDER;
177 map[BorderVisual::Property::COLOR] = Color::GREEN;
178 map[BorderVisual::Property::SIZE] = 5;
183 map[Toolkit::Visual::Property::TYPE] = Visual::GRADIENT;
185 Property::Array stopOffsets;
186 stopOffsets.PushBack(0.0f);
187 stopOffsets.PushBack(0.3f);
188 stopOffsets.PushBack(0.6f);
189 stopOffsets.PushBack(0.8f);
190 stopOffsets.PushBack(1.0f);
191 map[GradientVisual::Property::STOP_OFFSET] = stopOffsets;
193 Property::Array stopColors;
194 stopColors.PushBack(Vector4(129.f, 198.f, 193.f, 255.f) / 255.f);
195 stopColors.PushBack(Vector4(196.f, 198.f, 71.f, 122.f) / 255.f);
196 stopColors.PushBack(Vector4(214.f, 37.f, 139.f, 191.f) / 255.f);
197 stopColors.PushBack(Vector4(129.f, 198.f, 193.f, 150.f) / 255.f);
198 stopColors.PushBack(Color::YELLOW);
199 map[GradientVisual::Property::STOP_COLOR] = stopColors;
200 map[GradientVisual::Property::START_POSITION] = Vector2(-0.5f, -0.5f);
201 map[GradientVisual::Property::END_POSITION] = Vector2(0.5f, 0.5f);
206 map[Toolkit::Visual::Property::TYPE] = Visual::IMAGE;
207 map[ImageVisual::Property::URL] = DALI_LOGO_PATH;
212 map[Toolkit::Visual::Property::TYPE] = Visual::IMAGE;
213 map[ImageVisual::Property::URL] = DEMO_IMAGE_DIR "preMultAlpha.png";
214 map[Visual::Property::PREMULTIPLIED_ALPHA] = true;
220 map[Toolkit::Visual::Property::TYPE] = Visual::MESH;
221 map[MeshVisual::Property::OBJECT_URL] = DALI_ROBOT_MODEL_PATH;
222 map[MeshVisual::Property::MATERIAL_URL] = DALI_ROBOT_MATERIAL_PATH;
223 map[MeshVisual::Property::TEXTURES_PATH] = DEMO_IMAGE_DIR;
224 map[MeshVisual::Property::SHADING_MODE] = MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING;
230 map[Toolkit::Visual::Property::TYPE] = Visual::PRIMITIVE;
232 map[PrimitiveVisual::Property::SHAPE] = PrimitiveVisual::Shape::BEVELLED_CUBE;
233 map[PrimitiveVisual::Property::BEVEL_PERCENTAGE] = 0.3f;
234 map[PrimitiveVisual::Property::BEVEL_SMOOTHNESS] = 0.0f;
235 map[PrimitiveVisual::Property::SCALE_DIMENSIONS] = Vector3(1.0f, 1.0f, 0.3f);
236 map[PrimitiveVisual::Property::MIX_COLOR] = Vector4(0.7f, 0.5f, 0.05f, 1.0f);
244 map[Toolkit::Visual::Property::TYPE] = Visual::IMAGE;
245 map[ImageVisual::Property::URL] = DEMO_IMAGE_DIR "button-up-16.9.png";
251 map[Toolkit::Visual::Property::TYPE] = Visual::IMAGE;
252 map[ImageVisual::Property::URL] = DEMO_IMAGE_DIR "Kid1.svg";
258 map[Toolkit::Visual::Property::TYPE] = Visual::TEXT;
259 map[TextVisual::Property::TEXT] = "Text";
260 map[TextVisual::Property::TEXT_COLOR] = Color::CYAN;
261 map[TextVisual::Property::POINT_SIZE] = 10;
267 map[Toolkit::Visual::Property::TYPE] = Visual::COLOR;
268 map[ColorVisual::Property::MIX_COLOR] = Color::MAGENTA;
274 bool TransitionApplication::OnVisualButtonClicked(Actor actor, const TouchEvent& touch)
276 if(touch.GetState(0) == PointState::FINISHED)
278 int visual = actor.GetProperty<int>(mVisualIndex);
280 CreateVisualMap(visual, map);
281 map.Add(Visual::Property::TRANSFORM, Property::Map().Add(Visual::Transform::Property::SIZE, Vector2(0.5f, 0.5f)));
282 mBeatControl.SetProperty(BeatControl::Property::BEAT_VISUAL, map);
287 bool TransitionApplication::OnActionButtonClicked(Button button)
289 int action = button.GetProperty<int>(mActionIndex);
294 mBeatControl.StartBounceAnimation();
299 mBeatControl.StartXAnimation();
304 mBeatControl.StartYAnimation();
309 mBeatControl.StartFadeAnimation();
317 void TransitionApplication::OnKeyEvent(const KeyEvent& keyEvent)
319 static int keyPressed = 0;
321 if(keyEvent.GetState() == KeyEvent::DOWN)
323 if(keyPressed == 0) // Is this the first down event?
325 printf("Key pressed: %s %d\n", keyEvent.GetKeyName().c_str(), keyEvent.GetKeyCode());
327 if(IsKey(keyEvent, DALI_KEY_ESCAPE) || IsKey(keyEvent, DALI_KEY_BACK))
331 else if(keyEvent.GetKeyName().compare("Return") == 0)
337 else if(keyEvent.GetState() == KeyEvent::UP)