From: David Steele Date: Mon, 11 Oct 2021 11:59:44 +0000 (+0100) Subject: Adding advanced blending example X-Git-Tag: dali_2.0.48~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=086a93e8dc4f5f0864230975f3ffcbdeeb08c1d9;p=platform%2Fcore%2Fuifw%2Fdali-demo.git Adding advanced blending example Change-Id: Ib81a3376864a98e496ddb73256b698ec6c6f6250 --- diff --git a/README.md b/README.md index 29c195f..3201631 100644 --- a/README.md +++ b/README.md @@ -187,3 +187,23 @@ To build, run: ```zsh % make install -j8 ``` + +# Creating an example +In the dali-demo/examples folder, add another folder. This will become the name of your example executable, so for example the "hello-world" folder generates a "hello-world.example" binary. +In this folder, you can add as many source code files as you need. + +Usually, create a single class file containing a main function that instantiates an Application. Usually, the class is named after your example, followed by "Controller", e.g. hello-world.cpp contains a class called HelloWorldController. + +There is a DemoHelper::CreateView method, which enables you to easiliy set up a title bar and buttons. + +Add at least a key handler such that Escape or Back keys can be used to quit the application. Some apps that only present a single thing also add a touch handler that quits the application. + +Add a launcher line to one of demo/dali-demo.cpp, examples-reel/dali-examples-reel.cpp or tests-reel/dali-tests-reel.cpp, depending on the nature of what you are demonstrating. Generally, dali-demo is for graphical showcase demos, dali-examples-reel is for reasonable examples that look ok, and dali-tests is for examples that are only for testing. This needs a language string defining for the title. + +Add 2 lines to shared/dali-demo-strings.h for the title of your application, please keep in alphabetic ordering. Add english strings and translations to each of the language files in resources/po. + +To ensure your application can run on a Tizen device through the launcher, add an entry to com.samsung.dali-demo.xml, ensuring that only tabs are used for XML indent. + + + + diff --git a/com.samsung.dali-demo.xml b/com.samsung.dali-demo.xml index 622c301..2c46609 100644 --- a/com.samsung.dali-demo.xml +++ b/com.samsung.dali-demo.xml @@ -19,6 +19,9 @@ + + + diff --git a/examples-reel/dali-examples-reel.cpp b/examples-reel/dali-examples-reel.cpp index e1ba60d..63ead6e 100644 --- a/examples-reel/dali-examples-reel.cpp +++ b/examples-reel/dali-examples-reel.cpp @@ -38,6 +38,7 @@ int DALI_EXPORT_API main(int argc, char** argv) // Create the demo launcher DaliTableView demo(app); + demo.AddExample(Example("advanced-blend-mode.example", DALI_DEMO_STR_TITLE_ADVANCED_BLENDING)); demo.AddExample(Example("animated-images.example", DALI_DEMO_STR_TITLE_ANIMATED_IMAGES)); demo.AddExample(Example("animated-shapes.example", DALI_DEMO_STR_TITLE_ANIMATED_SHAPES)); demo.AddExample(Example("animated-vector-images.example", DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES)); diff --git a/examples/advanced-blend-mode/advanced-blend-mode-example.cpp b/examples/advanced-blend-mode/advanced-blend-mode-example.cpp new file mode 100644 index 0000000..be5cab2 --- /dev/null +++ b/examples/advanced-blend-mode/advanced-blend-mode-example.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include +#include + +using namespace Dali; +using Dali::Toolkit::TextLabel; + +// This example shows how to create and display Hello World! using a simple TextActor +// +class AdvancedBlendModeController : public ConnectionTracker +{ +public: + AdvancedBlendModeController(Application& application) + : mApplication(application) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect(this, &AdvancedBlendModeController::Create); + } + + ~AdvancedBlendModeController() = default; // Nothing to do in destructor + + // The Init signal is received once (only) during the Application lifetime + void Create(Application& application) + { + // Get a handle to the stage + Window window = application.GetWindow(); + window.SetBackgroundColor(Color::BLACK); + + Toolkit::ImageView imageView = Toolkit::ImageView::New(); + Property::Map imagePropertyMap; + imagePropertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE); + imagePropertyMap.Insert(Toolkit::ImageVisual::Property::URL, DEMO_IMAGE_DIR "gallery-large-19.jpg"); + imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap); + imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 600)); + window.Add(imageView); + + Toolkit::Control control_1 = Toolkit::Control::New(); + Property::Map colorVisualMap_1; + colorVisualMap_1.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR); + colorVisualMap_1.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, Dali::Color::RED); + colorVisualMap_1.Insert(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA, true); + control_1.SetProperty(Toolkit::Control::Property::BACKGROUND, colorVisualMap_1); + control_1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + control_1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + control_1.SetProperty(Actor::Property::POSITION, Vector2(0, 0)); + control_1.SetProperty(Actor::Property::SIZE, Vector2(600, 200)); + if(Dali::Capabilities::IsBlendEquationSupported(Dali::DevelBlendEquation::SCREEN)) + { + control_1.SetProperty(Dali::DevelActor::Property::BLEND_EQUATION, Dali::DevelBlendEquation::LUMINOSITY); + } + window.Add(control_1); + + Toolkit::Control control_2 = Toolkit::Control::New(); + Property::Map colorVisualMap_2; + colorVisualMap_2.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR); + colorVisualMap_2.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, Dali::Color::GREEN); + colorVisualMap_2.Insert(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA, true); + control_2.SetProperty(Toolkit::Control::Property::BACKGROUND, colorVisualMap_2); + control_2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + control_2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + control_2.SetProperty(Actor::Property::POSITION, Vector2(0, 200)); + control_2.SetProperty(Actor::Property::SIZE, Vector2(600, 200)); + if(Dali::Capabilities::IsBlendEquationSupported(Dali::DevelBlendEquation::SCREEN)) + { + control_2.SetProperty(Dali::DevelActor::Property::BLEND_EQUATION, Dali::DevelBlendEquation::LUMINOSITY); + } + window.Add(control_2); + + Toolkit::Control control_3 = Toolkit::Control::New(); + Property::Map colorVisualMap_3; + colorVisualMap_3.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR); + colorVisualMap_3.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, Dali::Color::BLUE); + colorVisualMap_3.Insert(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA, true); + control_3.SetProperty(Toolkit::Control::Property::BACKGROUND, colorVisualMap_3); + control_3.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + control_3.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + control_3.SetProperty(Actor::Property::POSITION, Vector2(0, 400)); + control_3.SetProperty(Actor::Property::SIZE, Vector2(600, 200)); + if(Dali::Capabilities::IsBlendEquationSupported(Dali::DevelBlendEquation::SCREEN)) + { + control_3.SetProperty(Dali::DevelActor::Property::BLEND_EQUATION, Dali::DevelBlendEquation::LUMINOSITY); + } + window.Add(control_3); + + // Add text to explain what's being seen. + 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."); + + label[Toolkit::TextLabel::Property::MULTI_LINE] = true; + label[Toolkit::TextLabel::Property::TEXT_COLOR] = Color::WHITE; + label[Toolkit::TextLabel::Property::POINT_SIZE] = 12.0f; + label[Actor::Property::PARENT_ORIGIN] = ParentOrigin::BOTTOM_CENTER; + label[Actor::Property::ANCHOR_POINT] = AnchorPoint::BOTTOM_CENTER; + label.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + window.Add(label); + + // Respond to a touch anywhere on the window + window.GetRootLayer().TouchedSignal().Connect(this, &AdvancedBlendModeController::OnTouch); + + // Respond to key events + window.KeyEventSignal().Connect(this, &AdvancedBlendModeController::OnKeyEvent); + } + + bool OnTouch(Actor actor, const TouchEvent& touch) + { + // quit the application + mApplication.Quit(); + return true; + } + + void OnKeyEvent(const KeyEvent& event) + { + if(event.GetState() == KeyEvent::DOWN) + { + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) + { + mApplication.Quit(); + } + } + } + +private: + Application& mApplication; +}; + +int DALI_EXPORT_API main(int argc, char** argv) +{ + Application application = Application::New(&argc, &argv); + AdvancedBlendModeController test(application); + application.MainLoop(); + return 0; +} diff --git a/resources/po/as.po b/resources/po/as.po index bab37b3..d5931ff 100755 --- a/resources/po/as.po +++ b/resources/po/as.po @@ -1,3 +1,6 @@ +msgid "DALI_DEMO_STR_TITLE_ADVANCED_BLENDING" +msgstr "ফটোশ্বপ ব্লেণ্ড মোড" + msgid "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES" msgstr "অ্যানিমেটেড ইমেজ" diff --git a/resources/po/de.po b/resources/po/de.po index 6190e2a..1ca9969 100755 --- a/resources/po/de.po +++ b/resources/po/de.po @@ -1,3 +1,6 @@ +msgid "DALI_DEMO_STR_TITLE_ADVANCED_BLENDING" +msgstr "Photoshop-Mischmodus" + msgid "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES" msgstr "Animierte Bilder" diff --git a/resources/po/en_GB.po b/resources/po/en_GB.po index 8f89fc0..6207632 100755 --- a/resources/po/en_GB.po +++ b/resources/po/en_GB.po @@ -1,3 +1,6 @@ +msgid "DALI_DEMO_STR_TITLE_ADVANCED_BLENDING" +msgstr "Advanced Blending" + msgid "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES" msgstr "Animated Images" diff --git a/resources/po/en_US.po b/resources/po/en_US.po index 8afbc95..1c5dcc2 100755 --- a/resources/po/en_US.po +++ b/resources/po/en_US.po @@ -1,3 +1,6 @@ +msgid "DALI_DEMO_STR_TITLE_ADVANCED_BLENDING" +msgstr "Advanced Blending" + msgid "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES" msgstr "Animated Images" diff --git a/resources/po/es.po b/resources/po/es.po index 6b4458b..ca08afa 100755 --- a/resources/po/es.po +++ b/resources/po/es.po @@ -1,3 +1,6 @@ +msgid "DALI_DEMO_STR_TITLE_ADVANCED_BLENDING" +msgstr "Modo de fusión" + msgid "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES" msgstr "Imágenes animadas" diff --git a/resources/po/fi.po b/resources/po/fi.po index 5e7552e..132017c 100755 --- a/resources/po/fi.po +++ b/resources/po/fi.po @@ -1,5 +1,8 @@ +msgid "DALI_DEMO_STR_TITLE_ADVANCED_BLENDING" +msgstr "Photoshop sekoitus tila" + msgid "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES" -msgstr "animoituja kuvia" +msgstr "Animoituja kuvia" msgid "DALI_DEMO_STR_TITLE_ANIMATED_SHAPES" msgstr "Animoidut Muodot" diff --git a/resources/po/ko.po b/resources/po/ko.po index e4b522a..dfbaee3 100755 --- a/resources/po/ko.po +++ b/resources/po/ko.po @@ -1,3 +1,6 @@ +msgid "DALI_DEMO_STR_TITLE_ADVANCED_BLENDING" +msgstr "포토샵 블렌드 모드" + msgid "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES" msgstr "애니메이션 이미지" diff --git a/resources/po/ml.po b/resources/po/ml.po index 8873d62..9a24c30 100755 --- a/resources/po/ml.po +++ b/resources/po/ml.po @@ -1,3 +1,6 @@ +msgid "DALI_DEMO_STR_TITLE_ADVANCED_BLENDING" +msgstr "ഫോട്ടോഷോപ്പ് ബ്ലെൻഡ് മോഡ്" + msgid "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES" msgstr "അനിമേറ്റഡ് ചിത്രങ്ങൾ" diff --git a/resources/po/ur.po b/resources/po/ur.po index 324368c..204af54 100755 --- a/resources/po/ur.po +++ b/resources/po/ur.po @@ -1,3 +1,6 @@ +msgid "DALI_DEMO_STR_TITLE_ADVANCED_BLENDING" +msgstr "فوٹو شاپ بلینڈ موڈ" + msgid "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES" msgstr "متحرک تصاویر" diff --git a/resources/po/zn_CH.po b/resources/po/zn_CH.po index 68dfa53..d280944 100755 --- a/resources/po/zn_CH.po +++ b/resources/po/zn_CH.po @@ -1,3 +1,6 @@ +msgid "DALI_DEMO_STR_TITLE_ADVANCED_BLENDING" +msgstr "高级混合" + msgid "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES" msgstr "动态图" diff --git a/shared/dali-demo-strings.h b/shared/dali-demo-strings.h index b5884dc..f4b7a6b 100644 --- a/shared/dali-demo-strings.h +++ b/shared/dali-demo-strings.h @@ -34,6 +34,7 @@ extern "C" #ifdef INTERNATIONALIZATION_ENABLED +#define DALI_DEMO_STR_TITLE_ADVANCED_BLENDING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ADVANCED_BLENDING") #define DALI_DEMO_STR_TITLE_ANIMATED_IMAGES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES") #define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_SHAPES") #define DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES") @@ -141,6 +142,7 @@ extern "C" #else // !INTERNATIONALIZATION_ENABLED +#define DALI_DEMO_STR_TITLE_ADVANCED_BLENDING "Advanced Blending" #define DALI_DEMO_STR_TITLE_ANIMATED_IMAGES "Animated Images" #define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES "Animated Shapes" #define DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES "Animated Vector Images"