Commit 77b171ef12e9a025d65b0806c5b6b92608cbec05

Authored by Andrew Poor
1 parent 1fdec445

Primitive shape title and slider granularity.

Change-Id: Id03410e559c061573522e2ff405442eca5f6c6e4
examples/primitive-shapes/primitive-shapes-example.cpp
... ... @@ -19,6 +19,9 @@ namespace
19 19 DEMO_IMAGE_DIR "octahedron-button.png"
20 20 };
21 21  
  22 + //Prefix of all shape titles.
  23 + const std::string SHAPE_TITLE_PREFIX = "Current Shape: ";
  24 +
22 25 //Shape property defaults
23 26 const int DEFAULT_SLICES = 32;
24 27 const int DEFAULT_STACKS = 32;
... ... @@ -94,9 +97,11 @@ public:
94 97 }
95 98  
96 99 //Place buttons on the top of the screen, which allow for selection of the shape to be displayed.
  100 + //A title above indicates the currently selected shape.
97 101 //The buttons are laid out like so:
98 102 //
99 103 // ^ +--------------------------------+
  104 + // | | Current Shape: ~~~~~ |
100 105 // | | |
101 106 // | | +----+ +----+ +----+ +----+ |
102 107 // | | | | | | | | | | |
... ... @@ -123,26 +128,39 @@ public:
123 128 // | |
124 129 // | |
125 130 // | |
126   - // | |
127 131 // +--------------------------------+
128 132 //
129 133 void SetupButtons( Layer layer )
130 134 {
131 135 float containerPadding = 10.0f;
132   - float buttonPadding = 5.0f;
  136 + float elementPadding = 5.0f;
  137 +
  138 + //Used to layout the title and the buttons below it.
  139 + Control topAlignment = Control::New();
  140 + topAlignment.SetParentOrigin( ParentOrigin::TOP_CENTER );
  141 + topAlignment.SetAnchorPoint( AnchorPoint::TOP_CENTER );
  142 + topAlignment.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
  143 + topAlignment.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
  144 + layer.Add( topAlignment );
  145 +
  146 + //Add a title to indicate the currently selected shape.
  147 + mShapeTitle = TextLabel::New( "DEFAULT" );
  148 + mShapeTitle.SetParentOrigin( ParentOrigin::CENTER );
  149 + mShapeTitle.SetAnchorPoint( AnchorPoint::CENTER );
  150 + mShapeTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
  151 + mShapeTitle.SetPadding( Padding( elementPadding, elementPadding, elementPadding, elementPadding ) );
  152 + topAlignment.Add( mShapeTitle );
133 153  
134 154 //Create a variable-length container that can wrap buttons around as more are added.
135 155 FlexContainer buttonContainer = FlexContainer::New();
136   - buttonContainer.SetParentOrigin( ParentOrigin::TOP_CENTER );
  156 + buttonContainer.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
137 157 buttonContainer.SetAnchorPoint( AnchorPoint::TOP_CENTER );
138 158 buttonContainer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
139   - buttonContainer.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT );
140   - buttonContainer.SetSizeModeFactor( Vector3( 0.0, 0.3, 0.0 ) ); //30% of height.
  159 + buttonContainer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
141 160 buttonContainer.SetPadding( Padding( containerPadding, containerPadding, containerPadding, containerPadding ) );
142 161 buttonContainer.SetProperty( FlexContainer::Property::FLEX_DIRECTION, FlexContainer::ROW );
143 162 buttonContainer.SetProperty( FlexContainer::Property::FLEX_WRAP, FlexContainer::WRAP );
144   -
145   - layer.Add( buttonContainer );
  163 + topAlignment.Add( buttonContainer );
146 164  
147 165 //Create buttons and place them in the container.
148 166 for( int modelNumber = 0; modelNumber < NUM_MODELS; modelNumber++ )
... ... @@ -151,7 +169,7 @@ public:
151 169 button.SetParentOrigin( ParentOrigin::CENTER );
152 170 button.SetAnchorPoint( AnchorPoint::CENTER );
153 171 button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
154   - button.SetPadding( Padding( buttonPadding, buttonPadding, buttonPadding, buttonPadding ) );
  172 + button.SetPadding( Padding( elementPadding, elementPadding, elementPadding, elementPadding ) );
155 173 button.SetProperty( Button::Property::UNSELECTED_STATE_IMAGE, Property::Value( BUTTON_IMAGE_URL[modelNumber] ) );
156 174 button.SetProperty( Button::Property::SELECTED_STATE_IMAGE, Property::Value( BUTTON_IMAGE_URL[modelNumber] ) );
157 175 button.RegisterProperty( "modelNumber", Property::Value( modelNumber ) );
... ... @@ -333,12 +351,18 @@ public:
333 351  
334 352 //Set up sliders.
335 353 SetupSlider( 0, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::SLICES, "slices" );
336   - SetupMarks( mSliders.at( 0 ), SLICES_LOWER_BOUND, SLICES_UPPER_BOUND );
  354 + SetupMarks( 0, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND );
  355 + mSliders.at( 0 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 0 ) );
  356 +
337 357 SetupSlider( 1, STACKS_LOWER_BOUND, STACKS_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::STACKS, "stacks" );
338   - SetupMarks( mSliders.at( 1 ), STACKS_LOWER_BOUND, STACKS_UPPER_BOUND );
  358 + SetupMarks( 1, STACKS_LOWER_BOUND, STACKS_UPPER_BOUND );
  359 + mSliders.at( 1 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 0 ) );
339 360  
340 361 //Set model in control.
341 362 mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
  363 +
  364 + //Update title.
  365 + mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Sphere" );
342 366 }
343 367  
344 368 //Sets the 3D model to a cone and modifies the sliders appropriately.
... ... @@ -354,12 +378,20 @@ public:
354 378  
355 379 //Set up sliders.
356 380 SetupSlider( 0, 1.0f, 32.0f, DEFAULT_SCALE_HEIGHT, PrimitiveVisual::Property::SCALE_HEIGHT, "scaleHeight" );
  381 + mSliders.at( 0 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) );
  382 +
357 383 SetupSlider( 1, 1.0f, 32.0f, DEFAULT_SCALE_BOTTOM_RADIUS, PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, "scaleBottomRadius" );
  384 + mSliders.at( 1 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) );
  385 +
358 386 SetupSlider( 2, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::SLICES, "slices" );
359   - SetupMarks( mSliders.at( 2 ), SLICES_LOWER_BOUND, SLICES_UPPER_BOUND );
  387 + SetupMarks( 2, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND );
  388 + mSliders.at( 2 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 0 ) );
360 389  
361 390 //Set model in control.
362 391 mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
  392 +
  393 + //Update title.
  394 + mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Cone" );
363 395 }
364 396  
365 397 //Sets the 3D model to a conical frustrum and modifies the sliders appropriately.
... ... @@ -376,11 +408,19 @@ public:
376 408  
377 409 //Set up used sliders.
378 410 SetupSlider( 0, 1.0f, 32.0f, DEFAULT_SCALE_HEIGHT, PrimitiveVisual::Property::SCALE_HEIGHT, "scaleHeight" );
  411 + mSliders.at( 0 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) );
  412 +
379 413 SetupSlider( 1, 0.0f, 32.0f, DEFAULT_SCALE_BOTTOM_RADIUS, PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, "scaleBottomRadius" );
  414 + mSliders.at( 1 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) );
  415 +
380 416 SetupSlider( 2, 0.0f, 32.0f, DEFAULT_SCALE_TOP_RADIUS, PrimitiveVisual::Property::SCALE_TOP_RADIUS, "scaleTopRadius" );
  417 + mSliders.at( 2 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) );
381 418  
382 419 //Set model in control.
383 420 mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
  421 +
  422 + //Update title.
  423 + mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Conical Frustrum" );
384 424 }
385 425  
386 426 //Sets the 3D model to a cylinder and modifies the sliders appropriately.
... ... @@ -396,12 +436,20 @@ public:
396 436  
397 437 //Set up used sliders.
398 438 SetupSlider( 0, 1.0f, 32.0f, DEFAULT_SCALE_HEIGHT, PrimitiveVisual::Property::SCALE_HEIGHT, "scaleHeight" );
  439 + mSliders.at( 0 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) );
  440 +
399 441 SetupSlider( 1, 1.0f, 32.0f, DEFAULT_SCALE_RADIUS, PrimitiveVisual::Property::SCALE_RADIUS, "scaleRadius" );
  442 + mSliders.at( 1 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) );
  443 +
400 444 SetupSlider( 2, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::SLICES, "slices" );
401   - SetupMarks( mSliders.at( 2 ), SLICES_LOWER_BOUND, SLICES_UPPER_BOUND );
  445 + SetupMarks( 2 , SLICES_LOWER_BOUND, SLICES_UPPER_BOUND );
  446 + mSliders.at( 2 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 0 ) );
402 447  
403 448 //Set model in control.
404 449 mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
  450 +
  451 + //Update title.
  452 + mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Cylinder" );
405 453 }
406 454  
407 455 //Sets the 3D model to a cube and modifies the sliders appropriately.
... ... @@ -414,6 +462,9 @@ public:
414 462  
415 463 //Set model in control.
416 464 mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
  465 +
  466 + //Update title.
  467 + mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Cube" );
417 468 }
418 469  
419 470 //Sets the 3D model to a bevelled cube and modifies the sliders appropriately.
... ... @@ -428,10 +479,16 @@ public:
428 479  
429 480 //Set up used sliders.
430 481 SetupSlider( 0, 0.0f, 1.0f, DEFAULT_BEVEL_PERCENTAGE, PrimitiveVisual::Property::BEVEL_PERCENTAGE, "bevelPercentage" );
  482 + mSliders.at( 0 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 2 ) );
  483 +
431 484 SetupSlider( 1, 0.0f, 1.0f, DEFAULT_BEVEL_SMOOTHNESS, PrimitiveVisual::Property::BEVEL_SMOOTHNESS, "bevelSmoothness" );
  485 + mSliders.at( 1 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 2 ) );
432 486  
433 487 //Set model in control.
434 488 mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
  489 +
  490 + //Update title.
  491 + mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Bevelled Cube" );
435 492 }
436 493  
437 494 //Sets the 3D model to an octahedron and modifies the sliders appropriately.
... ... @@ -444,6 +501,9 @@ public:
444 501  
445 502 //Set model in control.
446 503 mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) );
  504 +
  505 + //Update title.
  506 + mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Octahedron" );
447 507 }
448 508  
449 509 //Sets up the slider at the given index for the supplied property, and labels it appropriately.
... ... @@ -475,7 +535,7 @@ public:
475 535 }
476 536  
477 537 //Setup snapping to integer values between the two given values.
478   - void SetupMarks( Slider& slider, int lower, int upper )
  538 + void SetupMarks( int sliderIndex, int lower, int upper )
479 539 {
480 540 Property::Array marks;
481 541  
... ... @@ -484,8 +544,8 @@ public:
484 544 marks.PushBack( Property::Value( mark ) );
485 545 }
486 546  
487   - slider.SetProperty( Slider::Property::MARKS, Property::Value( marks ) );
488   - slider.SetProperty( Slider::Property::SNAP_TO_MARKS, Property::Value( true ) );
  547 + mSliders.at( sliderIndex ).SetProperty( Slider::Property::MARKS, Property::Value( marks ) );
  548 + mSliders.at( sliderIndex ).SetProperty( Slider::Property::SNAP_TO_MARKS, Property::Value( true ) );
489 549 }
490 550  
491 551 //When a shape button is tapped, switch to the corresponding shape.
... ... @@ -612,18 +672,19 @@ public:
612 672 private:
613 673 Application& mApplication;
614 674  
615   - std::vector<Slider> mSliders; ///< Holds the sliders on screen that each shape accesses.
616   - std::vector<TextLabel> mSliderLabels; ///< Holds the labels to each slider.
617   - TableView mSliderTable; ///< A table to layout the sliders next to their labels.
  675 + std::vector<Slider> mSliders; ///< Holds the sliders on screen that each shape accesses.
  676 + std::vector<TextLabel> mSliderLabels; ///< Holds the labels to each slider.
  677 + TableView mSliderTable; ///< A table to layout the sliders next to their labels.
618 678  
619   - Property::Map mVisualMap; ///< Property map to create a primitive visual.
620   - Control mModel; ///< Control to house the primitive visual.
  679 + Property::Map mVisualMap; ///< Property map to create a primitive visual.
  680 + Control mModel; ///< Control to house the primitive visual.
  681 + TextLabel mShapeTitle; ///< Indicates what the currently selected shape is.
621 682  
622   - PanGestureDetector mPanGestureDetector; ///< Detects pan gestures for rotation of the model.
623   - Animation mRotationAnimation; ///< Automatically rotates the model, unless it is being panned.
  683 + PanGestureDetector mPanGestureDetector; ///< Detects pan gestures for rotation of the model.
  684 + Animation mRotationAnimation; ///< Automatically rotates the model, unless it is being panned.
624 685  
625   - Vector4 mColor; ///< Color to set all shapes.
626   - Vector2 mRotation; ///< Keeps track of model rotation.
  686 + Vector4 mColor; ///< Color to set all shapes.
  687 + Vector2 mRotation; ///< Keeps track of model rotation.
627 688 };
628 689  
629 690 void RunTest( Application& application )
... ...