Commit 224b50493e1780342175be99333566cf8da90e76
1 parent
76c81225
(ArcVisual) Add code to update properties
Change-Id: I3198285716b30dd1fdff57dde3bf8cb528c11581
Showing
1 changed file
with
115 additions
and
8 deletions
examples/arc-visual/arc-visual-example.cpp
| ... | ... | @@ -19,6 +19,8 @@ |
| 19 | 19 | #include <dali-toolkit/devel-api/controls/control-devel.h> |
| 20 | 20 | #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h> |
| 21 | 21 | #include <dali-toolkit/devel-api/visuals/arc-visual-properties-devel.h> |
| 22 | +#include <dali-toolkit/devel-api/visuals/arc-visual-actions-devel.h> | |
| 23 | +#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h> | |
| 22 | 24 | #include <dali-toolkit/devel-api/visual-factory/transition-data.h> |
| 23 | 25 | |
| 24 | 26 | using namespace Dali; |
| ... | ... | @@ -43,6 +45,13 @@ const Property::Value BACKGROUND |
| 43 | 45 | { DevelArcVisual::Property::THICKNESS, 20.0f } |
| 44 | 46 | }; |
| 45 | 47 | |
| 48 | +const Property::Value TEXT_BACKGROUND | |
| 49 | +{ | |
| 50 | + { Visual::Property::TYPE, Visual::COLOR }, | |
| 51 | + { ColorVisual::Property::MIX_COLOR, Vector4( 0.8f, 0.8f, 0.8f, 1.0f ) }, | |
| 52 | + { DevelVisual::Property::CORNER_RADIUS, 10.0f } | |
| 53 | +}; | |
| 54 | + | |
| 46 | 55 | const Property::Value TRANSITION_ANIMATOR |
| 47 | 56 | { |
| 48 | 57 | { "timePeriod", Property::Map().Add( "duration", ANIMATION_DURATION ) } |
| ... | ... | @@ -76,8 +85,7 @@ public: |
| 76 | 85 | |
| 77 | 86 | ArcVisualExample( Application& application ) |
| 78 | 87 | : mApplication( application ), |
| 79 | - mStartAngle( 0.0f ), | |
| 80 | - mSweepAngle( 0.0f ) | |
| 88 | + mSelectedPoperty( DevelArcVisual::Property::START_ANGLE ) | |
| 81 | 89 | { |
| 82 | 90 | // Connect to the Application's Init signal |
| 83 | 91 | mApplication.InitSignal().Connect( this, &ArcVisualExample::Create ); |
| ... | ... | @@ -96,11 +104,65 @@ private: |
| 96 | 104 | |
| 97 | 105 | mControl = Control::New(); |
| 98 | 106 | mControl.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); |
| 99 | - mControl.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) ); | |
| 107 | + mControl.SetProperty( Actor::Property::SIZE, Vector2( 300.0f, 300.0f ) ); | |
| 100 | 108 | mControl.SetProperty( Control::Property::BACKGROUND, BACKGROUND ); |
| 101 | - | |
| 102 | 109 | stage.Add( mControl ); |
| 103 | 110 | |
| 111 | + mStartAngleLabel = TextLabel::New( "1" ); | |
| 112 | + mStartAngleLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); | |
| 113 | + mStartAngleLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT ); | |
| 114 | + mStartAngleLabel.SetProperty( Actor::Property::POSITION, Vector2( -30.0f, -10.0f ) ); | |
| 115 | + mStartAngleLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND ); | |
| 116 | + mStartAngleLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); | |
| 117 | + mStartAngleLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); | |
| 118 | + mStartAngleLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) ); | |
| 119 | + mStartAngleLabel.TouchSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); | |
| 120 | + stage.Add( mStartAngleLabel ); | |
| 121 | + | |
| 122 | + mSweepAngleLabel = TextLabel::New( "2" ); | |
| 123 | + mSweepAngleLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); | |
| 124 | + mSweepAngleLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); | |
| 125 | + mSweepAngleLabel.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, -10.0f ) ); | |
| 126 | + mSweepAngleLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND ); | |
| 127 | + mSweepAngleLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); | |
| 128 | + mSweepAngleLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); | |
| 129 | + mSweepAngleLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) ); | |
| 130 | + mSweepAngleLabel.TouchSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); | |
| 131 | + stage.Add( mSweepAngleLabel ); | |
| 132 | + | |
| 133 | + mThicknessLabel = TextLabel::New( "3" ); | |
| 134 | + mThicknessLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); | |
| 135 | + mThicknessLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT ); | |
| 136 | + mThicknessLabel.SetProperty( Actor::Property::POSITION, Vector2( 30.0f, -10.0f ) ); | |
| 137 | + mThicknessLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND ); | |
| 138 | + mThicknessLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); | |
| 139 | + mThicknessLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); | |
| 140 | + mThicknessLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) ); | |
| 141 | + mThicknessLabel.TouchSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); | |
| 142 | + stage.Add( mThicknessLabel ); | |
| 143 | + | |
| 144 | + mPlusTextLabel = TextLabel::New( "+" ); | |
| 145 | + mPlusTextLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); | |
| 146 | + mPlusTextLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); | |
| 147 | + mPlusTextLabel.SetProperty( Actor::Property::POSITION, Vector2( 20.0f, 10.0f ) ); | |
| 148 | + mPlusTextLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND ); | |
| 149 | + mPlusTextLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); | |
| 150 | + mPlusTextLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); | |
| 151 | + mPlusTextLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) ); | |
| 152 | + mPlusTextLabel.TouchSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); | |
| 153 | + stage.Add( mPlusTextLabel ); | |
| 154 | + | |
| 155 | + mMinusTextLabel = TextLabel::New( "-" ); | |
| 156 | + mMinusTextLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); | |
| 157 | + mMinusTextLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT ); | |
| 158 | + mMinusTextLabel.SetProperty( Actor::Property::POSITION, Vector2( -20.0f, 10.0f ) ); | |
| 159 | + mMinusTextLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND ); | |
| 160 | + mMinusTextLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); | |
| 161 | + mMinusTextLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); | |
| 162 | + mMinusTextLabel.SetProperty( Control::Property::PADDING, Extents( 25.0f, 25.0f, 10.0f, 10.0f ) ); | |
| 163 | + mMinusTextLabel.TouchSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); | |
| 164 | + stage.Add( mMinusTextLabel ); | |
| 165 | + | |
| 104 | 166 | // Respond to a click anywhere on the stage |
| 105 | 167 | stage.GetRootLayer().TouchSignal().Connect( this, &ArcVisualExample::OnTouch ); |
| 106 | 168 | |
| ... | ... | @@ -108,6 +170,47 @@ private: |
| 108 | 170 | stage.KeyEventSignal().Connect( this, &ArcVisualExample::OnKeyEvent ); |
| 109 | 171 | } |
| 110 | 172 | |
| 173 | + bool OnButtonTouch( Actor actor, const TouchData& touch ) | |
| 174 | + { | |
| 175 | + if( touch.GetState( 0 ) == PointState::UP ) | |
| 176 | + { | |
| 177 | + Control control = Control::DownCast( actor ); | |
| 178 | + if( control == mStartAngleLabel ) | |
| 179 | + { | |
| 180 | + mSelectedPoperty = DevelArcVisual::Property::START_ANGLE; | |
| 181 | + } | |
| 182 | + else if( control == mSweepAngleLabel ) | |
| 183 | + { | |
| 184 | + mSelectedPoperty = DevelArcVisual::Property::SWEEP_ANGLE; | |
| 185 | + } | |
| 186 | + else if( control == mThicknessLabel ) | |
| 187 | + { | |
| 188 | + mSelectedPoperty = DevelArcVisual::Property::THICKNESS; | |
| 189 | + } | |
| 190 | + else if( control == mPlusTextLabel ) | |
| 191 | + { | |
| 192 | + Property::Map map = mControl.GetProperty< Property::Map >( Control::Property::BACKGROUND ); | |
| 193 | + Property::Value* value = map.Find( mSelectedPoperty ); | |
| 194 | + if( value ) | |
| 195 | + { | |
| 196 | + DevelControl::DoAction( mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY, | |
| 197 | + Property::Map().Add( mSelectedPoperty, value->Get< float >() + 5.0f ) ); | |
| 198 | + } | |
| 199 | + } | |
| 200 | + else | |
| 201 | + { | |
| 202 | + Property::Map map = mControl.GetProperty< Property::Map >( Control::Property::BACKGROUND ); | |
| 203 | + Property::Value* value = map.Find( mSelectedPoperty ); | |
| 204 | + if( value ) | |
| 205 | + { | |
| 206 | + DevelControl::DoAction( mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY, | |
| 207 | + Property::Map().Add( mSelectedPoperty, value->Get< float >() - 5.0f ) ); | |
| 208 | + } | |
| 209 | + } | |
| 210 | + } | |
| 211 | + return true; | |
| 212 | + } | |
| 213 | + | |
| 111 | 214 | bool OnTouch( Actor actor, const TouchData& touch ) |
| 112 | 215 | { |
| 113 | 216 | if( touch.GetState( 0 ) == PointState::UP ) |
| ... | ... | @@ -125,9 +228,9 @@ private: |
| 125 | 228 | |
| 126 | 229 | void OnKeyEvent( const KeyEvent& event ) |
| 127 | 230 | { |
| 128 | - if( event.state == KeyEvent::Down ) | |
| 231 | + if( event.state == KeyEvent::Up ) | |
| 129 | 232 | { |
| 130 | - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) | |
| 233 | + if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) | |
| 131 | 234 | { |
| 132 | 235 | mApplication.Quit(); |
| 133 | 236 | } |
| ... | ... | @@ -137,8 +240,12 @@ private: |
| 137 | 240 | private: |
| 138 | 241 | Application& mApplication; |
| 139 | 242 | Control mControl; |
| 140 | - float mStartAngle; | |
| 141 | - float mSweepAngle; | |
| 243 | + TextLabel mStartAngleLabel; | |
| 244 | + TextLabel mSweepAngleLabel; | |
| 245 | + TextLabel mThicknessLabel; | |
| 246 | + TextLabel mPlusTextLabel; | |
| 247 | + TextLabel mMinusTextLabel; | |
| 248 | + Property::Index mSelectedPoperty; | |
| 142 | 249 | }; |
| 143 | 250 | |
| 144 | 251 | int DALI_EXPORT_API main( int argc, char **argv ) | ... | ... |