Commit c3bcccb0df2f4c71bb930ac60051778ea63535d0
1 parent
b4fc7c7d
(Gradient) Add a button for the rounded corner
Change-Id: I61646395e74b9eab7c72504e0ce44e97482a9514
Showing
1 changed file
with
49 additions
and
7 deletions
examples/gradients/gradients-example.cpp
| 1 | 1 | /* |
| 2 | - * Copyright (c) 2019 Samsung Electronics Co., Ltd. | |
| 2 | + * Copyright (c) 2020 Samsung Electronics Co., Ltd. | |
| 3 | 3 | * |
| 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | 5 | * you may not use this file except in compliance with the License. |
| ... | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | #include <dali-toolkit/dali-toolkit.h> |
| 19 | +#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h> | |
| 19 | 20 | #include "shared/view.h" |
| 20 | 21 | |
| 21 | 22 | using namespace Dali; |
| ... | ... | @@ -28,6 +29,11 @@ const char * const APPLICATION_TITLE( "Color Gradients" ); |
| 28 | 29 | const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); |
| 29 | 30 | const char * const CHANGE_ICON( DEMO_IMAGE_DIR "icon-change.png" ); |
| 30 | 31 | const char * const CHANGE_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" ); |
| 32 | +const char * const ROUNDED_CORNER_ICON( DEMO_IMAGE_DIR "icon-replace.png" ); | |
| 33 | +const char * const ROUNDED_CORNER_ICON_SELECTED( DEMO_IMAGE_DIR "icon-replace-selected.png" ); | |
| 34 | + | |
| 35 | +const float CORNER_RADIUS_VALUE( 20.0f ); | |
| 36 | + | |
| 31 | 37 | } |
| 32 | 38 | |
| 33 | 39 | // This example shows how to render color gradients |
| ... | ... | @@ -38,7 +44,8 @@ public: |
| 38 | 44 | |
| 39 | 45 | GradientController( Application& application ) |
| 40 | 46 | : mApplication( application ), |
| 41 | - mIndex( 0 ) | |
| 47 | + mIndex( 0 ), | |
| 48 | + mRoundedCorner( false ) | |
| 42 | 49 | { |
| 43 | 50 | // Connect to the Application's Init signal |
| 44 | 51 | mApplication.InitSignal().Connect( this, &GradientController::Create ); |
| ... | ... | @@ -75,6 +82,23 @@ public: |
| 75 | 82 | Toolkit::Alignment::HorizontalRight, |
| 76 | 83 | DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); |
| 77 | 84 | |
| 85 | + PushButton roundedCornerButton = Toolkit::PushButton::New(); | |
| 86 | + roundedCornerButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, ROUNDED_CORNER_ICON ); | |
| 87 | + roundedCornerButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, ROUNDED_CORNER_ICON_SELECTED ); | |
| 88 | + roundedCornerButton.ClickedSignal().Connect( this, &GradientController::OnRoundedCornerClicked ); | |
| 89 | + toolBar.AddControl( roundedCornerButton, | |
| 90 | + DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, | |
| 91 | + Toolkit::Alignment::HorizontalCenter, | |
| 92 | + DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); | |
| 93 | + | |
| 94 | + mGradientControl = Control::New(); | |
| 95 | + mGradientControl.SetAnchorPoint( AnchorPoint::CENTER ); | |
| 96 | + mGradientControl.SetParentOrigin( ParentOrigin::CENTER ); | |
| 97 | + mGradientControl.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); | |
| 98 | + Vector3 offset( 0.9f, 0.7f, 0.0f ); | |
| 99 | + mGradientControl.SetSizeModeFactor( offset ); | |
| 100 | + content.Add( mGradientControl ); | |
| 101 | + | |
| 78 | 102 | // ---- Gradient for background |
| 79 | 103 | |
| 80 | 104 | mGradientMap.Insert( Toolkit::Visual::Property::TYPE, Visual::GRADIENT ); |
| ... | ... | @@ -95,11 +119,30 @@ public: |
| 95 | 119 | stopColors.PushBack( Color::YELLOW ); |
| 96 | 120 | mGradientMap.Insert( GradientVisual::Property::STOP_COLOR, stopColors ); |
| 97 | 121 | |
| 98 | - OnChangeIconClicked( changeButton ); | |
| 122 | + mGradientMap.Insert( DevelVisual::Property::CORNER_RADIUS, mRoundedCorner ? CORNER_RADIUS_VALUE : 0.0f ); | |
| 123 | + | |
| 124 | + UpdateGradientMap(); | |
| 99 | 125 | } |
| 100 | 126 | |
| 101 | 127 | bool OnChangeIconClicked( Toolkit::Button button ) |
| 102 | 128 | { |
| 129 | + mIndex++; | |
| 130 | + UpdateGradientMap(); | |
| 131 | + return true; | |
| 132 | + } | |
| 133 | + | |
| 134 | + bool OnRoundedCornerClicked( Toolkit::Button button ) | |
| 135 | + { | |
| 136 | + mRoundedCorner = !mRoundedCorner; | |
| 137 | + mGradientMap[DevelVisual::Property::CORNER_RADIUS] = mRoundedCorner ? CORNER_RADIUS_VALUE : 0.0f; | |
| 138 | + | |
| 139 | + UpdateGradientMap(); | |
| 140 | + | |
| 141 | + return true; | |
| 142 | + } | |
| 143 | + | |
| 144 | + void UpdateGradientMap() | |
| 145 | + { | |
| 103 | 146 | Property::Map gradientMap; |
| 104 | 147 | |
| 105 | 148 | switch( mIndex%4 ) |
| ... | ... | @@ -135,10 +178,7 @@ public: |
| 135 | 178 | } |
| 136 | 179 | |
| 137 | 180 | gradientMap.Merge( mGradientMap ); |
| 138 | - mView.SetProperty( Control::Property::BACKGROUND, gradientMap ); | |
| 139 | - | |
| 140 | - mIndex++; | |
| 141 | - return true; | |
| 181 | + mGradientControl.SetProperty( Control::Property::BACKGROUND, gradientMap ); | |
| 142 | 182 | } |
| 143 | 183 | |
| 144 | 184 | void OnKeyEvent(const KeyEvent& event) |
| ... | ... | @@ -157,7 +197,9 @@ private: |
| 157 | 197 | |
| 158 | 198 | Property::Map mGradientMap; |
| 159 | 199 | Control mView; |
| 200 | + Control mGradientControl; | |
| 160 | 201 | unsigned mIndex; |
| 202 | + bool mRoundedCorner; | |
| 161 | 203 | }; |
| 162 | 204 | |
| 163 | 205 | int DALI_EXPORT_API main( int argc, char **argv ) | ... | ... |