X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fprimitive-shapes%2Fprimitive-shapes-example.cpp;h=b6139800eaf15710f9b58b532f456cc819e33195;hb=6c3ce4efbe8f7cd80fd86fd007af6c14c5689ef5;hp=cce4f3c1fdc61486f0ddb77cdb2a46d9cd42c856;hpb=3b1f0cb34f2a4d93167b78f62280d0e0758cead2;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/primitive-shapes/primitive-shapes-example.cpp b/examples/primitive-shapes/primitive-shapes-example.cpp index cce4f3c..b613980 100644 --- a/examples/primitive-shapes/primitive-shapes-example.cpp +++ b/examples/primitive-shapes/primitive-shapes-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -16,11 +16,7 @@ */ #include -#include -#include -#include -#include -#include +#include using namespace Dali; using namespace Dali::Toolkit; @@ -32,7 +28,7 @@ namespace { DEMO_IMAGE_DIR "sphere-button.png", DEMO_IMAGE_DIR "cone-button.png", - DEMO_IMAGE_DIR "conical-frustrum-button.png", + DEMO_IMAGE_DIR "conical-frustum-button.png", DEMO_IMAGE_DIR "cylinder-button.png", DEMO_IMAGE_DIR "cube-button.png", DEMO_IMAGE_DIR "bevelled-cube-button.png", @@ -87,21 +83,18 @@ public: // The Init signal is received once (only) during the Application lifetime void Create( Application& application ) { - // Get a handle to the stage - Stage stage = Stage::GetCurrent(); - stage.SetBackgroundColor( Color::WHITE ); - - // Hide the indicator bar - application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); + // Get a handle to the window + Window window = application.GetWindow(); + window.SetBackgroundColor( Color::WHITE ); //Set up layer to place UI on. Layer layer = Layer::New(); - layer.SetParentOrigin( ParentOrigin::CENTER ); - layer.SetAnchorPoint( AnchorPoint::CENTER ); + layer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + layer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); layer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - layer.SetBehavior( Layer::LAYER_2D ); //We use a 2D layer as this is closer to UI work than full 3D scene creation. - layer.SetDepthTestDisabled( false ); //Enable depth testing, as otherwise the 2D layer would not do so. - stage.Add( layer ); + layer.SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_UI ); //We use a 2D layer as this is closer to UI work than full 3D scene creation. + layer.SetProperty( Layer::Property::DEPTH_TEST, true ); //Enable depth testing, as otherwise the 2D layer would not do so. + window.Add( layer ); //Set up model selection buttons. SetupButtons( layer ); @@ -113,7 +106,7 @@ public: SetupModel( layer ); //Allow for exiting of the application via key presses. - stage.KeyEventSignal().Connect( this, &PrimitiveShapesController::OnKeyEvent ); + window.KeyEventSignal().Connect( this, &PrimitiveShapesController::OnKeyEvent ); } //Place buttons on the top of the screen, which allow for selection of the shape to be displayed. @@ -157,27 +150,27 @@ public: //Used to layout the title and the buttons below it. Control topAlignment = Control::New(); - topAlignment.SetParentOrigin( ParentOrigin::TOP_CENTER ); - topAlignment.SetAnchorPoint( AnchorPoint::TOP_CENTER ); + topAlignment.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); + topAlignment.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); topAlignment.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); topAlignment.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); layer.Add( topAlignment ); //Add a title to indicate the currently selected shape. mShapeTitle = TextLabel::New( "DEFAULT" ); - mShapeTitle.SetParentOrigin( ParentOrigin::CENTER ); - mShapeTitle.SetAnchorPoint( AnchorPoint::CENTER ); + mShapeTitle.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mShapeTitle.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); mShapeTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - mShapeTitle.SetPadding( Padding( elementPadding, elementPadding, elementPadding, elementPadding ) ); + mShapeTitle.SetProperty( Actor::Property::PADDING, Padding( elementPadding, elementPadding, elementPadding, elementPadding ) ); topAlignment.Add( mShapeTitle ); //Create a variable-length container that can wrap buttons around as more are added. FlexContainer buttonContainer = FlexContainer::New(); - buttonContainer.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); - buttonContainer.SetAnchorPoint( AnchorPoint::TOP_CENTER ); + buttonContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); + buttonContainer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); buttonContainer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); buttonContainer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT ); - buttonContainer.SetPadding( Padding( containerPadding, containerPadding, containerPadding, containerPadding ) ); + buttonContainer.SetProperty( Actor::Property::PADDING, Padding( containerPadding, containerPadding, containerPadding, containerPadding ) ); buttonContainer.SetProperty( FlexContainer::Property::FLEX_DIRECTION, FlexContainer::ROW ); buttonContainer.SetProperty( FlexContainer::Property::FLEX_WRAP, FlexContainer::WRAP ); topAlignment.Add( buttonContainer ); @@ -186,12 +179,12 @@ public: for( int modelNumber = 0; modelNumber < NUM_MODELS; modelNumber++ ) { PushButton button = Toolkit::PushButton::New(); - button.SetParentOrigin( ParentOrigin::CENTER ); - button.SetAnchorPoint( AnchorPoint::CENTER ); + button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - button.SetPadding( Padding( elementPadding, elementPadding, elementPadding, elementPadding ) ); - button.SetProperty( DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_IMAGE_URL[modelNumber] ); - button.SetProperty( DevelButton::Property::SELECTED_BACKGROUND_VISUAL, BUTTON_IMAGE_URL[modelNumber] ); + button.SetProperty( Actor::Property::PADDING, Padding( elementPadding, elementPadding, elementPadding, elementPadding ) ); + button.SetProperty( Button::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_IMAGE_URL[modelNumber] ); + button.SetProperty( Button::Property::SELECTED_BACKGROUND_VISUAL, BUTTON_IMAGE_URL[modelNumber] ); button.RegisterProperty( "modelNumber", Property::Value( modelNumber ) ); button.ClickedSignal().Connect( this, &PrimitiveShapesController::OnChangeShapeClicked ); @@ -237,10 +230,10 @@ public: { //Create table to hold sliders and their corresponding labels. mSliderTable = Toolkit::TableView::New( MAX_PROPERTIES, 2 ); - mSliderTable.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); - mSliderTable.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + mSliderTable.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); + mSliderTable.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); mSliderTable.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mSliderTable.SetSizeModeFactor( Vector3( 0.9, 0.3, 0.0 ) ); //90% of width, 30% of height. + mSliderTable.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.9, 0.3, 0.0 ) ); //90% of width, 30% of height. mSliderTable.SetFitWidth( 0 ); //Label column should fit to natural size of label. mSliderTable.SetRelativeWidth( 1, 1.0f ); //Slider column should fill remaining space. mSliderTable.SetCellPadding( Vector2( 10.0f, 0.0f ) ); //Leave a gap between the slider and its label. @@ -251,8 +244,8 @@ public: { //Create slider Slider slider = Slider::New(); - slider.SetParentOrigin( ParentOrigin::CENTER ); - slider.SetAnchorPoint( AnchorPoint::CENTER ); + slider.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + slider.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); slider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); slider.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); slider.ValueChangedSignal().Connect( this, &PrimitiveShapesController::OnSliderValueChanged ); @@ -264,8 +257,8 @@ public: //Create slider label TextLabel sliderLabel = TextLabel::New(); - sliderLabel.SetParentOrigin( ParentOrigin::CENTER ); - sliderLabel.SetAnchorPoint( AnchorPoint::CENTER ); + sliderLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + sliderLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); sliderLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); mSliderLabels.push_back( sliderLabel ); @@ -275,7 +268,7 @@ public: } } - //Adds a control to the centre of the stage to display the 3D shapes. + //Adds a control to the centre of the window to display the 3D shapes. //The model is placed in the center of the screen, like so: // // +--------------------------------+ @@ -313,15 +306,15 @@ public: //Create a container to house the visual-holding actor, to provide a constant hitbox. Actor container = Actor::New(); container.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - container.SetSizeModeFactor( Vector3( 0.9, 0.3, 0.0 ) ); //90% of width, 30% of height. - container.SetParentOrigin( ParentOrigin::CENTER ); - container.SetAnchorPoint( AnchorPoint::CENTER ); + container.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.9, 0.3, 0.0 ) ); //90% of width, 30% of height. + container.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + container.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); layer.Add( container ); //Create control to display the 3D primitive. mModel = Control::New(); - mModel.SetParentOrigin( ParentOrigin::CENTER ); - mModel.SetAnchorPoint( AnchorPoint::CENTER); + mModel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mModel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); mModel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); container.Add( mModel ); @@ -348,18 +341,18 @@ public: for( unsigned i = 0; i < mSliders.size(); i++ ) { mSliders.at( i ).SetProperty( Slider::Property::MARKS, Property::Value( 0 ) ); //Remove marks - mSliders.at( i ).SetVisible( false ); + mSliders.at( i ).SetProperty( Actor::Property::VISIBLE, false ); mSliderLabels.at( i ).SetProperty( TextLabel::Property::TEXT, Property::Value( "Default" ) ); - mSliderLabels.at( i ).SetVisible( false ); + mSliderLabels.at( i ).SetProperty( Actor::Property::VISIBLE, false ); } //Visual map for model mVisualMap.Clear(); - mVisualMap[ Visual::Property::TYPE ] = Visual::PRIMITIVE; + mVisualMap[ Toolkit::Visual::Property::TYPE ] = Visual::PRIMITIVE; mVisualMap[ PrimitiveVisual::Property::MIX_COLOR ] = mColor; - mVisualMap[ DevelVisual::Property::TRANSFORM ] = - Property::Map().Add( DevelVisual::Transform::Property::ORIGIN, Align::CENTER ) - .Add( DevelVisual::Transform::Property::ANCHOR_POINT, Align::CENTER ); + mVisualMap[ Visual::Property::TRANSFORM ] = + Property::Map().Add( Visual::Transform::Property::ORIGIN, Align::CENTER ) + .Add( Visual::Transform::Property::ANCHOR_POINT, Align::CENTER ); } //Sets the 3D model to a sphere and modifies the sliders appropriately. @@ -417,13 +410,13 @@ public: mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Cone" ); } - //Sets the 3D model to a conical frustrum and modifies the sliders appropriately. - void LoadConicalFrustrum() + //Sets the 3D model to a conical frustum and modifies the sliders appropriately. + void LoadConicalFrustum() { InitialiseSlidersAndModel(); //Set up specific visual properties. - mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::CONICAL_FRUSTRUM; + mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::CONICAL_FRUSTUM; mVisualMap[ PrimitiveVisual::Property::SCALE_TOP_RADIUS ] = DEFAULT_SCALE_TOP_RADIUS; mVisualMap[ PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS ] = DEFAULT_SCALE_BOTTOM_RADIUS; mVisualMap[ PrimitiveVisual::Property::SCALE_HEIGHT ] = DEFAULT_SCALE_HEIGHT; @@ -443,7 +436,7 @@ public: mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) ); //Update title. - mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Conical Frustrum" ); + mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Conical Frustum" ); } //Sets the 3D model to a cylinder and modifies the sliders appropriately. @@ -539,21 +532,21 @@ public: mSliders.at( sliderIndex ).SetProperty( Slider::Property::LOWER_BOUND, Property::Value( lowerBound ) ); mSliders.at( sliderIndex ).SetProperty( Slider::Property::UPPER_BOUND, Property::Value( upperBound ) ); mSliders.at( sliderIndex ).SetProperty( Slider::Property::VALUE, Property::Value( startPoint ) ); - mSliders.at( sliderIndex ).SetVisible( true ); + mSliders.at( sliderIndex ).SetProperty( Actor::Property::VISIBLE, true ); //Label the slider with the property. //We reset the TextLabel to force a relayout of the table. mSliderTable.RemoveChildAt( TableView::CellPosition(sliderIndex, 0) ); TextLabel sliderLabel = TextLabel::New( visualPropertyLabel ); - sliderLabel.SetParentOrigin( ParentOrigin::CENTER ); - sliderLabel.SetAnchorPoint( AnchorPoint::CENTER ); + sliderLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + sliderLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); sliderLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); mSliderTable.AddChild( sliderLabel, TableView::CellPosition( sliderIndex, 0 ) ); mSliderTable.SetCellAlignment( TableView::CellPosition( sliderIndex, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER ); - mSliderLabels.at( sliderIndex ).SetVisible( true ); + mSliderLabels.at( sliderIndex ).SetProperty( Actor::Property::VISIBLE, true ); mSliderLabels.at( sliderIndex) = sliderLabel; } @@ -593,7 +586,7 @@ public: } case 2: { - LoadConicalFrustrum(); + LoadConicalFrustum(); break; } case 3: @@ -655,7 +648,7 @@ public: Quaternion rotation = Quaternion( Radian( mRotation.x ), Vector3::XAXIS) * Quaternion( Radian( mRotation.y ), Vector3::YAXIS); - mModel.SetOrientation( rotation ); + mModel.SetProperty( Actor::Property::ORIENTATION, rotation ); break; } @@ -683,7 +676,7 @@ public: //If escape or the back button is pressed, quit the application (and return to the launcher) void OnKeyEvent( const KeyEvent& event ) { - if( event.state == KeyEvent::Down ) + if( event.GetState() == KeyEvent::Down ) { if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) { @@ -710,20 +703,10 @@ private: Vector2 mRotation; ///< Keeps track of model rotation. }; -void RunTest( Application& application ) +int DALI_EXPORT_API main( int argc, char **argv ) { + Application application = Application::New( &argc, &argv ); PrimitiveShapesController test( application ); - application.MainLoop(); -} - -// Entry point for Linux & Tizen applications -// -int main( int argc, char **argv ) -{ - Application application = Application::New( &argc, &argv ); - - RunTest( application ); - return 0; }