2 * Copyright (c) 2017 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/public-api/object/property-map.h>
20 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
21 #include <dali-toolkit/public-api/controls/slider/slider.h>
24 using namespace Dali::Toolkit;
29 const char* BUTTON_IMAGE_URL[] =
31 DEMO_IMAGE_DIR "sphere-button.png",
32 DEMO_IMAGE_DIR "cone-button.png",
33 DEMO_IMAGE_DIR "conical-frustrum-button.png",
34 DEMO_IMAGE_DIR "cylinder-button.png",
35 DEMO_IMAGE_DIR "cube-button.png",
36 DEMO_IMAGE_DIR "bevelled-cube-button.png",
37 DEMO_IMAGE_DIR "octahedron-button.png"
40 //Prefix of all shape titles.
41 const std::string SHAPE_TITLE_PREFIX = "Current Shape: ";
43 //Shape property defaults
44 const int DEFAULT_SLICES = 32;
45 const int DEFAULT_STACKS = 32;
46 const float DEFAULT_SCALE_HEIGHT = 16.0f;
47 const float DEFAULT_SCALE_BOTTOM_RADIUS = 8.0f;
48 const float DEFAULT_SCALE_TOP_RADIUS = 4.0f;
49 const float DEFAULT_SCALE_RADIUS = 8.0f;
50 const float DEFAULT_BEVEL_PERCENTAGE = 0.3f;
51 const float DEFAULT_BEVEL_SMOOTHNESS = 0.0f;
53 //Shape property limits
54 const int SLICES_LOWER_BOUND = 3;
55 const int SLICES_UPPER_BOUND = 16;
56 const int STACKS_LOWER_BOUND = 2;
57 const int STACKS_UPPER_BOUND = 16;
59 //Used to the control rate of rotation when panning an object.
60 const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
61 const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
63 const int NUM_MODELS = 7; //Total number of possible base shapes.
64 const int MAX_PROPERTIES = 3; //Maximum number of properties a shape may require. (For displaying sliders.)
68 class PrimitiveShapesController : public ConnectionTracker
72 PrimitiveShapesController( Application& application )
73 : mApplication( application ),
74 mColor( Vector4( 0.3f, 0.7f, 1.0f, 1.0f ) ),
75 mRotation( Vector2::ZERO )
77 // Connect to the Application's Init signal
78 mApplication.InitSignal().Connect( this, &PrimitiveShapesController::Create );
81 ~PrimitiveShapesController()
85 // The Init signal is received once (only) during the Application lifetime
86 void Create( Application& application )
88 // Get a handle to the stage
89 Stage stage = Stage::GetCurrent();
90 stage.SetBackgroundColor( Color::WHITE );
92 // Hide the indicator bar
93 application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
95 //Set up layer to place UI on.
96 Layer layer = Layer::New();
97 layer.SetParentOrigin( ParentOrigin::CENTER );
98 layer.SetAnchorPoint( AnchorPoint::CENTER );
99 layer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
100 layer.SetBehavior( Layer::LAYER_2D ); //We use a 2D layer as this is closer to UI work than full 3D scene creation.
101 layer.SetDepthTestDisabled( false ); //Enable depth testing, as otherwise the 2D layer would not do so.
104 //Set up model selection buttons.
105 SetupButtons( layer );
107 //Set up model parameter sliders.
108 SetupSliders( layer );
113 //Allow for exiting of the application via key presses.
114 stage.KeyEventSignal().Connect( this, &PrimitiveShapesController::OnKeyEvent );
117 //Place buttons on the top of the screen, which allow for selection of the shape to be displayed.
118 //A title above indicates the currently selected shape.
119 //The buttons are laid out like so:
121 // ^ +--------------------------------+
122 // | | Current Shape: ~~~~~ |
124 // | | +----+ +----+ +----+ +----+ |
125 // | | | | | | | | | | |
126 // 30% | | +----+ +----+ +----+ +----+ |
128 // | | +----+ +----+ +----+ |
130 // v | +----+ +----+ +----+ |
149 // +--------------------------------+
151 void SetupButtons( Layer layer )
153 float containerPadding = 10.0f;
154 float elementPadding = 5.0f;
156 //Used to layout the title and the buttons below it.
157 Control topAlignment = Control::New();
158 topAlignment.SetParentOrigin( ParentOrigin::TOP_CENTER );
159 topAlignment.SetAnchorPoint( AnchorPoint::TOP_CENTER );
160 topAlignment.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
161 topAlignment.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
162 layer.Add( topAlignment );
164 //Add a title to indicate the currently selected shape.
165 mShapeTitle = TextLabel::New( "DEFAULT" );
166 mShapeTitle.SetParentOrigin( ParentOrigin::CENTER );
167 mShapeTitle.SetAnchorPoint( AnchorPoint::CENTER );
168 mShapeTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
169 mShapeTitle.SetPadding( Padding( elementPadding, elementPadding, elementPadding, elementPadding ) );
170 topAlignment.Add( mShapeTitle );
172 //Create a variable-length container that can wrap buttons around as more are added.
173 FlexContainer buttonContainer = FlexContainer::New();
174 buttonContainer.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
175 buttonContainer.SetAnchorPoint( AnchorPoint::TOP_CENTER );
176 buttonContainer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
177 buttonContainer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
178 buttonContainer.SetPadding( Padding( containerPadding, containerPadding, containerPadding, containerPadding ) );
179 buttonContainer.SetProperty( FlexContainer::Property::FLEX_DIRECTION, FlexContainer::ROW );
180 buttonContainer.SetProperty( FlexContainer::Property::FLEX_WRAP, FlexContainer::WRAP );
181 topAlignment.Add( buttonContainer );
183 //Create buttons and place them in the container.
184 for( int modelNumber = 0; modelNumber < NUM_MODELS; modelNumber++ )
186 PushButton button = Toolkit::PushButton::New();
187 button.SetParentOrigin( ParentOrigin::CENTER );
188 button.SetAnchorPoint( AnchorPoint::CENTER );
189 button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
190 button.SetPadding( Padding( elementPadding, elementPadding, elementPadding, elementPadding ) );
191 button.SetProperty( DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_IMAGE_URL[modelNumber] );
192 button.SetProperty( DevelButton::Property::SELECTED_BACKGROUND_VISUAL, BUTTON_IMAGE_URL[modelNumber] );
193 button.RegisterProperty( "modelNumber", Property::Value( modelNumber ) );
194 button.ClickedSignal().Connect( this, &PrimitiveShapesController::OnChangeShapeClicked );
196 buttonContainer.Add( button );
200 //Add sliders to the bottom of the screen, which allow for control of shape properties such as radius.
201 //Each slider is placed next to a label that states the property it affects.
202 //The sliders are laid out like so:
204 // +--------------------------------+
224 // ^ | Label +----------O-----------+ |
227 // | | Label +--O-------------------+ |
230 // | | Label +----------------------O |
232 // v +--------------------------------+
234 void SetupSliders( Layer layer )
236 //Create table to hold sliders and their corresponding labels.
237 mSliderTable = Toolkit::TableView::New( MAX_PROPERTIES, 2 );
238 mSliderTable.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
239 mSliderTable.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
240 mSliderTable.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
241 mSliderTable.SetSizeModeFactor( Vector3( 0.9, 0.3, 0.0 ) ); //90% of width, 30% of height.
242 mSliderTable.SetFitWidth( 0 ); //Label column should fit to natural size of label.
243 mSliderTable.SetRelativeWidth( 1, 1.0f ); //Slider column should fill remaining space.
244 mSliderTable.SetCellPadding( Vector2( 10.0f, 0.0f ) ); //Leave a gap between the slider and its label.
245 layer.Add( mSliderTable );
247 //Set up sliders, and place labels next to them.
248 for( int i = 0; i < MAX_PROPERTIES; i++ )
251 Slider slider = Slider::New();
252 slider.SetParentOrigin( ParentOrigin::CENTER );
253 slider.SetAnchorPoint( AnchorPoint::CENTER );
254 slider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
255 slider.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
256 slider.ValueChangedSignal().Connect( this, &PrimitiveShapesController::OnSliderValueChanged );
257 mSliders.push_back( slider );
259 //Setup slider cell properties
260 mSliderTable.AddChild( slider, TableView::CellPosition( i, 1 ) );
261 mSliderTable.SetCellAlignment( TableView::CellPosition( i, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
263 //Create slider label
264 TextLabel sliderLabel = TextLabel::New();
265 sliderLabel.SetParentOrigin( ParentOrigin::CENTER );
266 sliderLabel.SetAnchorPoint( AnchorPoint::CENTER );
267 sliderLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
268 mSliderLabels.push_back( sliderLabel );
270 //Setup slider-label cell properties
271 mSliderTable.AddChild( sliderLabel, TableView::CellPosition( i, 0 ) );
272 mSliderTable.SetCellAlignment( TableView::CellPosition( i, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
276 //Adds a control to the centre of the stage to display the 3D shapes.
277 //The model is placed in the center of the screen, like so:
279 // +--------------------------------+
307 // +--------------------------------+
309 void SetupModel( Layer layer )
311 //Create a container to house the visual-holding actor, to provide a constant hitbox.
312 Actor container = Actor::New();
313 container.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
314 container.SetSizeModeFactor( Vector3( 0.9, 0.3, 0.0 ) ); //90% of width, 30% of height.
315 container.SetParentOrigin( ParentOrigin::CENTER );
316 container.SetAnchorPoint( AnchorPoint::CENTER );
317 layer.Add( container );
319 //Create control to display the 3D primitive.
320 mModel = Control::New();
321 mModel.SetParentOrigin( ParentOrigin::CENTER );
322 mModel.SetAnchorPoint( AnchorPoint::CENTER);
323 mModel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
324 container.Add( mModel );
326 //Load default shape.
329 //Make model spin to demonstrate 3D.
330 mRotationAnimation = Animation::New(15.0f);
331 mRotationAnimation.AnimateBy( Property( mModel, Actor::Property::ORIENTATION ),
332 Quaternion( Degree( 0.0f ), Degree( 360.0f ), Degree( 0.0f ) ) );
333 mRotationAnimation.SetLooping(true);
334 mRotationAnimation.Play();
336 //Attach gesture detector to pan models when rotated.
337 mPanGestureDetector = PanGestureDetector::New();
338 mPanGestureDetector.Attach( container );
339 mPanGestureDetector.DetectedSignal().Connect( this, &PrimitiveShapesController::OnPan );
342 //Clears all sliders and resets the primitive visual property map.
343 void InitialiseSlidersAndModel()
346 for( unsigned i = 0; i < mSliders.size(); i++ )
348 mSliders.at( i ).SetProperty( Slider::Property::MARKS, Property::Value( 0 ) ); //Remove marks
349 mSliders.at( i ).SetVisible( false );
350 mSliderLabels.at( i ).SetProperty( TextLabel::Property::TEXT, Property::Value( "Default" ) );
351 mSliderLabels.at( i ).SetVisible( false );
354 //Visual map for model
356 mVisualMap[ Visual::Property::TYPE ] = Visual::PRIMITIVE;
357 mVisualMap[ PrimitiveVisual::Property::MIX_COLOR ] = mColor;
360 //Sets the 3D model to a sphere and modifies the sliders appropriately.
363 InitialiseSlidersAndModel();
365 //Set up specific visual properties.
366 mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::SPHERE;
367 mVisualMap[ PrimitiveVisual::Property::SLICES ] = DEFAULT_SLICES;
368 mVisualMap[ PrimitiveVisual::Property::STACKS ] = DEFAULT_STACKS;
371 SetupSlider( 0, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::SLICES, "slices" );
372 SetupMarks( 0, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND );
373 mSliders.at( 0 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 0 ) );
375 SetupSlider( 1, STACKS_LOWER_BOUND, STACKS_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::STACKS, "stacks" );
376 SetupMarks( 1, STACKS_LOWER_BOUND, STACKS_UPPER_BOUND );
377 mSliders.at( 1 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 0 ) );
379 //Set model in control.
380 mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
383 mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Sphere" );
386 //Sets the 3D model to a cone and modifies the sliders appropriately.
389 InitialiseSlidersAndModel();
391 //Set up specific visual properties.
392 mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::CONE;
393 mVisualMap[ PrimitiveVisual::Property::SCALE_HEIGHT ] = DEFAULT_SCALE_HEIGHT;
394 mVisualMap[ PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS ] = DEFAULT_SCALE_BOTTOM_RADIUS;
395 mVisualMap[ PrimitiveVisual::Property::SLICES ] = DEFAULT_SLICES;
398 SetupSlider( 0, 1.0f, 32.0f, DEFAULT_SCALE_HEIGHT, PrimitiveVisual::Property::SCALE_HEIGHT, "scaleHeight" );
399 mSliders.at( 0 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) );
401 SetupSlider( 1, 1.0f, 32.0f, DEFAULT_SCALE_BOTTOM_RADIUS, PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, "scaleBottomRadius" );
402 mSliders.at( 1 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) );
404 SetupSlider( 2, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::SLICES, "slices" );
405 SetupMarks( 2, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND );
406 mSliders.at( 2 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 0 ) );
408 //Set model in control.
409 mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
412 mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Cone" );
415 //Sets the 3D model to a conical frustrum and modifies the sliders appropriately.
416 void LoadConicalFrustrum()
418 InitialiseSlidersAndModel();
420 //Set up specific visual properties.
421 mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::CONICAL_FRUSTRUM;
422 mVisualMap[ PrimitiveVisual::Property::SCALE_TOP_RADIUS ] = DEFAULT_SCALE_TOP_RADIUS;
423 mVisualMap[ PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS ] = DEFAULT_SCALE_BOTTOM_RADIUS;
424 mVisualMap[ PrimitiveVisual::Property::SCALE_HEIGHT ] = DEFAULT_SCALE_HEIGHT;
425 mVisualMap[ PrimitiveVisual::Property::SLICES ] = DEFAULT_SLICES;
427 //Set up used sliders.
428 SetupSlider( 0, 1.0f, 32.0f, DEFAULT_SCALE_HEIGHT, PrimitiveVisual::Property::SCALE_HEIGHT, "scaleHeight" );
429 mSliders.at( 0 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) );
431 SetupSlider( 1, 0.0f, 32.0f, DEFAULT_SCALE_BOTTOM_RADIUS, PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, "scaleBottomRadius" );
432 mSliders.at( 1 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) );
434 SetupSlider( 2, 0.0f, 32.0f, DEFAULT_SCALE_TOP_RADIUS, PrimitiveVisual::Property::SCALE_TOP_RADIUS, "scaleTopRadius" );
435 mSliders.at( 2 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) );
437 //Set model in control.
438 mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
441 mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Conical Frustrum" );
444 //Sets the 3D model to a cylinder and modifies the sliders appropriately.
447 InitialiseSlidersAndModel();
449 //Set up specific visual properties.
450 mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::CYLINDER;
451 mVisualMap[ PrimitiveVisual::Property::SCALE_HEIGHT ] = DEFAULT_SCALE_HEIGHT;
452 mVisualMap[ PrimitiveVisual::Property::SCALE_RADIUS ] = DEFAULT_SCALE_RADIUS;
453 mVisualMap[ PrimitiveVisual::Property::SLICES ] = DEFAULT_SLICES;
455 //Set up used sliders.
456 SetupSlider( 0, 1.0f, 32.0f, DEFAULT_SCALE_HEIGHT, PrimitiveVisual::Property::SCALE_HEIGHT, "scaleHeight" );
457 mSliders.at( 0 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) );
459 SetupSlider( 1, 1.0f, 32.0f, DEFAULT_SCALE_RADIUS, PrimitiveVisual::Property::SCALE_RADIUS, "scaleRadius" );
460 mSliders.at( 1 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) );
462 SetupSlider( 2, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::SLICES, "slices" );
463 SetupMarks( 2 , SLICES_LOWER_BOUND, SLICES_UPPER_BOUND );
464 mSliders.at( 2 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 0 ) );
466 //Set model in control.
467 mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
470 mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Cylinder" );
473 //Sets the 3D model to a cube and modifies the sliders appropriately.
476 InitialiseSlidersAndModel();
478 //Set up specific visual properties.
479 mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::CUBE;
481 //Set model in control.
482 mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
485 mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Cube" );
488 //Sets the 3D model to a bevelled cube and modifies the sliders appropriately.
489 void LoadBevelledCube()
491 InitialiseSlidersAndModel();
493 //Set up specific visual properties.
494 mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::BEVELLED_CUBE;
495 mVisualMap[ PrimitiveVisual::Property::BEVEL_PERCENTAGE ] = DEFAULT_BEVEL_PERCENTAGE;
496 mVisualMap[ PrimitiveVisual::Property::BEVEL_SMOOTHNESS ] = DEFAULT_BEVEL_SMOOTHNESS;
498 //Set up used sliders.
499 SetupSlider( 0, 0.0f, 1.0f, DEFAULT_BEVEL_PERCENTAGE, PrimitiveVisual::Property::BEVEL_PERCENTAGE, "bevelPercentage" );
500 mSliders.at( 0 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 2 ) );
502 SetupSlider( 1, 0.0f, 1.0f, DEFAULT_BEVEL_SMOOTHNESS, PrimitiveVisual::Property::BEVEL_SMOOTHNESS, "bevelSmoothness" );
503 mSliders.at( 1 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 2 ) );
505 //Set model in control.
506 mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
509 mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Bevelled Cube" );
512 //Sets the 3D model to an octahedron and modifies the sliders appropriately.
513 void LoadOctahedron()
515 InitialiseSlidersAndModel();
517 //Set up specific visual properties.
518 mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::OCTAHEDRON;
520 //Set model in control.
521 mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
524 mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Octahedron" );
527 //Sets up the slider at the given index for the supplied property, and labels it appropriately.
528 // visualProperty is the property that will be set by this slider.
529 void SetupSlider( int sliderIndex, float lowerBound, float upperBound, float startPoint,
530 Property::Index visualProperty, std::string visualPropertyLabel )
532 //Set up the slider itself.
533 mSliders.at( sliderIndex ).RegisterProperty( "visualProperty", Property::Value( visualProperty ), Property::READ_WRITE );
534 mSliders.at( sliderIndex ).SetProperty( Slider::Property::LOWER_BOUND, Property::Value( lowerBound ) );
535 mSliders.at( sliderIndex ).SetProperty( Slider::Property::UPPER_BOUND, Property::Value( upperBound ) );
536 mSliders.at( sliderIndex ).SetProperty( Slider::Property::VALUE, Property::Value( startPoint ) );
537 mSliders.at( sliderIndex ).SetVisible( true );
539 //Label the slider with the property.
540 //We reset the TextLabel to force a relayout of the table.
541 mSliderTable.RemoveChildAt( TableView::CellPosition(sliderIndex, 0) );
543 TextLabel sliderLabel = TextLabel::New( visualPropertyLabel );
544 sliderLabel.SetParentOrigin( ParentOrigin::CENTER );
545 sliderLabel.SetAnchorPoint( AnchorPoint::CENTER );
546 sliderLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
548 mSliderTable.AddChild( sliderLabel, TableView::CellPosition( sliderIndex, 0 ) );
549 mSliderTable.SetCellAlignment( TableView::CellPosition( sliderIndex, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
551 mSliderLabels.at( sliderIndex ).SetVisible( true );
552 mSliderLabels.at( sliderIndex) = sliderLabel;
555 //Setup snapping to integer values between the two given values.
556 void SetupMarks( int sliderIndex, int lower, int upper )
558 Property::Array marks;
560 for( int mark = lower; mark <= upper; mark++ )
562 marks.PushBack( Property::Value( mark ) );
565 mSliders.at( sliderIndex ).SetProperty( Slider::Property::MARKS, Property::Value( marks ) );
566 mSliders.at( sliderIndex ).SetProperty( Slider::Property::SNAP_TO_MARKS, Property::Value( true ) );
569 //When a shape button is tapped, switch to the corresponding shape.
570 bool OnChangeShapeClicked( Button button )
572 //Get the model number from the button.
574 button.GetProperty( button.GetPropertyIndex( "modelNumber" ) ).Get( modelNumber );
576 //Switch to the shape that corresponds to the model number.
577 switch( modelNumber )
591 LoadConicalFrustrum();
619 //When the slider is adjusted, change the corresponding shape property accordingly.
620 bool OnSliderValueChanged( Slider slider, float value )
622 //Update property map to reflect the change to the specific visual property.
624 slider.GetProperty( slider.GetPropertyIndex( "visualProperty" ) ).Get( visualProperty );
625 mVisualMap[ visualProperty ] = value;
627 //Reload the model to display the change.
628 mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
633 //Panning around the shape rotates it.
634 void OnPan( Actor actor, const PanGesture& gesture )
636 switch( gesture.state )
638 case Gesture::Started:
640 //Pause animation, as the gesture will be used to manually rotate the model
641 mRotationAnimation.Pause();
645 case Gesture::Continuing:
647 //Rotate based off the gesture.
648 mRotation.x -= gesture.displacement.y / X_ROTATION_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis
649 mRotation.y += gesture.displacement.x / Y_ROTATION_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis
650 Quaternion rotation = Quaternion( Radian( mRotation.x ), Vector3::XAXIS) *
651 Quaternion( Radian( mRotation.y ), Vector3::YAXIS);
653 mModel.SetOrientation( rotation );
657 case Gesture::Finished:
659 //Return to automatic animation
660 mRotationAnimation.Play();
664 case Gesture::Cancelled:
666 //Return to automatic animation
667 mRotationAnimation.Play();
678 //If escape or the back button is pressed, quit the application (and return to the launcher)
679 void OnKeyEvent( const KeyEvent& event )
681 if( event.state == KeyEvent::Down )
683 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
691 Application& mApplication;
693 std::vector<Slider> mSliders; ///< Holds the sliders on screen that each shape accesses.
694 std::vector<TextLabel> mSliderLabels; ///< Holds the labels to each slider.
695 TableView mSliderTable; ///< A table to layout the sliders next to their labels.
697 Property::Map mVisualMap; ///< Property map to create a primitive visual.
698 Control mModel; ///< Control to house the primitive visual.
699 TextLabel mShapeTitle; ///< Indicates what the currently selected shape is.
701 PanGestureDetector mPanGestureDetector; ///< Detects pan gestures for rotation of the model.
702 Animation mRotationAnimation; ///< Automatically rotates the model, unless it is being panned.
704 Vector4 mColor; ///< Color to set all shapes.
705 Vector2 mRotation; ///< Keeps track of model rotation.
708 void RunTest( Application& application )
710 PrimitiveShapesController test( application );
712 application.MainLoop();
715 // Entry point for Linux & Tizen applications
717 int main( int argc, char **argv )
719 Application application = Application::New( &argc, &argv );
721 RunTest( application );