2 * Copyright (c) 2021 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 #include <dali-toolkit/dali-toolkit.h>
19 #include <dali/devel-api/actors/actor-devel.h>
21 #include <dali/devel-api/common/capabilities.h>
22 #include <dali/integration-api/debug.h>
25 using Dali::Toolkit::TextLabel;
27 // This example shows how to create and display Hello World! using a simple TextActor
29 class AdvancedBlendModeController : public ConnectionTracker
32 AdvancedBlendModeController(Application& application)
33 : mApplication(application)
35 // Connect to the Application's Init signal
36 mApplication.InitSignal().Connect(this, &AdvancedBlendModeController::Create);
39 ~AdvancedBlendModeController() = default; // Nothing to do in destructor
41 // The Init signal is received once (only) during the Application lifetime
42 void Create(Application& application)
44 // Get a handle to the stage
45 Window window = application.GetWindow();
46 window.SetBackgroundColor(Color::BLACK);
48 Toolkit::ImageView imageView = Toolkit::ImageView::New();
49 Property::Map imagePropertyMap;
50 imagePropertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
51 imagePropertyMap.Insert(Toolkit::ImageVisual::Property::URL, DEMO_IMAGE_DIR "gallery-large-19.jpg");
52 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
53 imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER);
54 imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
55 imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 600));
56 window.Add(imageView);
58 Toolkit::Control control_1 = Toolkit::Control::New();
59 Property::Map colorVisualMap_1;
60 colorVisualMap_1.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR);
61 colorVisualMap_1.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, Dali::Color::RED);
62 colorVisualMap_1.Insert(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA, true);
63 control_1.SetProperty(Toolkit::Control::Property::BACKGROUND, colorVisualMap_1);
64 control_1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER);
65 control_1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
66 control_1.SetProperty(Actor::Property::POSITION, Vector2(0, 0));
67 control_1.SetProperty(Actor::Property::SIZE, Vector2(600, 200));
68 if(Dali::Capabilities::IsBlendEquationSupported(Dali::DevelBlendEquation::SCREEN))
70 control_1.SetProperty(Dali::DevelActor::Property::BLEND_EQUATION, Dali::DevelBlendEquation::LUMINOSITY);
72 window.Add(control_1);
74 Toolkit::Control control_2 = Toolkit::Control::New();
75 Property::Map colorVisualMap_2;
76 colorVisualMap_2.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR);
77 colorVisualMap_2.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, Dali::Color::GREEN);
78 colorVisualMap_2.Insert(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA, true);
79 control_2.SetProperty(Toolkit::Control::Property::BACKGROUND, colorVisualMap_2);
80 control_2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER);
81 control_2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
82 control_2.SetProperty(Actor::Property::POSITION, Vector2(0, 200));
83 control_2.SetProperty(Actor::Property::SIZE, Vector2(600, 200));
84 if(Dali::Capabilities::IsBlendEquationSupported(Dali::DevelBlendEquation::SCREEN))
86 control_2.SetProperty(Dali::DevelActor::Property::BLEND_EQUATION, Dali::DevelBlendEquation::LUMINOSITY);
88 window.Add(control_2);
90 Toolkit::Control control_3 = Toolkit::Control::New();
91 Property::Map colorVisualMap_3;
92 colorVisualMap_3.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR);
93 colorVisualMap_3.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, Dali::Color::BLUE);
94 colorVisualMap_3.Insert(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA, true);
95 control_3.SetProperty(Toolkit::Control::Property::BACKGROUND, colorVisualMap_3);
96 control_3.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER);
97 control_3.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
98 control_3.SetProperty(Actor::Property::POSITION, Vector2(0, 400));
99 control_3.SetProperty(Actor::Property::SIZE, Vector2(600, 200));
100 if(Dali::Capabilities::IsBlendEquationSupported(Dali::DevelBlendEquation::SCREEN))
102 control_3.SetProperty(Dali::DevelActor::Property::BLEND_EQUATION, Dali::DevelBlendEquation::LUMINOSITY);
104 window.Add(control_3);
106 // Add text to explain what's being seen.
107 auto label = Toolkit::TextLabel::New("If your device supports advanced blending, this shows an image at different levels of luminosity. If not, it instead shows red/green/blue sections.");
109 label[Toolkit::TextLabel::Property::MULTI_LINE] = true;
110 label[Toolkit::TextLabel::Property::TEXT_COLOR] = Color::WHITE;
111 label[Toolkit::TextLabel::Property::POINT_SIZE] = 12.0f;
112 label[Actor::Property::PARENT_ORIGIN] = ParentOrigin::BOTTOM_CENTER;
113 label[Actor::Property::ANCHOR_POINT] = AnchorPoint::BOTTOM_CENTER;
114 label.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
117 // Respond to a touch anywhere on the window
118 window.GetRootLayer().TouchedSignal().Connect(this, &AdvancedBlendModeController::OnTouch);
120 // Respond to key events
121 window.KeyEventSignal().Connect(this, &AdvancedBlendModeController::OnKeyEvent);
124 bool OnTouch(Actor actor, const TouchEvent& touch)
126 // quit the application
131 void OnKeyEvent(const KeyEvent& event)
133 if(event.GetState() == KeyEvent::DOWN)
135 if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
143 Application& mApplication;
146 int DALI_EXPORT_API main(int argc, char** argv)
148 Application application = Application::New(&argc, &argv);
149 AdvancedBlendModeController test(application);
150 application.MainLoop();