From: Andrew Poor Date: Thu, 11 Aug 2016 10:53:34 +0000 (+0100) Subject: [3.0] Mesh visual buttons change. X-Git-Tag: accepted/tizen/common/20160830.150437~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d5cd2eff4006d5ba236c7715e0047fc05cec8b80;hp=adb2ef028c3034a236e7d822522216d1d80d9c40;p=platform%2Fcore%2Fuifw%2Fdali-demo.git [3.0] Mesh visual buttons change. Change-Id: I32ed8eb68cd099fc329a93fc6c370a4caada32a0 --- diff --git a/examples/mesh-visual/mesh-visual-example.cpp b/examples/mesh-visual/mesh-visual-example.cpp index 3340838..8376f61 100644 --- a/examples/mesh-visual/mesh-visual-example.cpp +++ b/examples/mesh-visual/mesh-visual-example.cpp @@ -39,11 +39,24 @@ namespace MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING }; + //Button labels. + const char * const PAUSE = " || "; + const char * const PLAY = " > "; + const char * const FIXED = "FIXED"; + const char * const MANUAL = "MANUAL"; + const char * const FRONT = "FRONT"; + const char * const BACK = "BACK"; + + //Image urls for the light. + const char * const LIGHT_URL_FRONT = DEMO_IMAGE_DIR "light-icon-front.png"; + const char * const LIGHT_URL_BACK = DEMO_IMAGE_DIR "light-icon-back.png"; + const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f; const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f; const float MODEL_SCALE = 0.75f; const float LIGHT_SCALE = 0.15f; - const float BUTTONS_OFFSET_BOTTOM = 0.9f; + const float BUTTONS_OFFSET_BOTTOM = 0.08f; + const float BUTTONS_OFFSET_SIDE = 0.2f; const int NUM_MESHES = 2; //Used to identify actors. @@ -60,11 +73,12 @@ public: MeshVisualController( Application& application ) : mApplication( application ), //Store handle to the application. mModelIndex( 1 ), //Start with metal robot. - mShadingModeIndex( 0 ), //Start with textured with detailed specular lighting. + mShadingModeIndex( 0 ), //Start with texture and detailed specular lighting. mTag( -1 ), //Non-valid default, which will get set to a correct value when used. mSelectedModelIndex( -1 ), //Non-valid default, which will get set to a correct value when used. mPaused( false ), //Animations play by default. - mLightFixed( true ) //The light is fixed by default. + mLightFixed( true ), //The light is fixed by default. + mLightFront( true ) //The light is in front by default. { // Connect to the Application's Init signal mApplication.InitSignal().Connect( this, &MeshVisualController::Create ); @@ -163,57 +177,78 @@ public: //Place the various buttons on the bottom of the screen, with title labels where necessary. void SetupButtons( Layer layer ) { - //Text label title for changing model or shader. - TextLabel changeTitleLabel = TextLabel::New( "Switch" ); - changeTitleLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - changeTitleLabel.SetProperty( TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}" ); - changeTitleLabel.SetParentOrigin( Vector3( 0.2, BUTTONS_OFFSET_BOTTOM, 0.5 ) ); - changeTitleLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); - layer.Add( changeTitleLabel ); + //Actor for positioning model and shading mode buttons. + Actor positionActorModel = Actor::New(); + positionActorModel.SetParentOrigin( Vector3( BUTTONS_OFFSET_SIDE, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) ); + positionActorModel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + layer.Add( positionActorModel ); - //Create button for model changing + //Create button for model changing. PushButton modelButton = Toolkit::PushButton::New(); modelButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); modelButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeModelClicked ); - modelButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); - modelButton.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); + modelButton.SetParentOrigin( ParentOrigin::TOP_CENTER ); + modelButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); modelButton.SetLabelText( "Model" ); - changeTitleLabel.Add( modelButton ); - - //Create button for shader changing - PushButton shaderButton = Toolkit::PushButton::New(); - shaderButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - shaderButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeShaderClicked ); - shaderButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); - shaderButton.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - shaderButton.SetLabelText( "Shader" ); - changeTitleLabel.Add( shaderButton ); - - //Create button for pausing animations + positionActorModel.Add( modelButton ); + + //Create button for shading mode changing. + PushButton shadingModeButton = Toolkit::PushButton::New(); + shadingModeButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + shadingModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeShadingModeClicked ); + shadingModeButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); + shadingModeButton.SetAnchorPoint( AnchorPoint::TOP_CENTER ); + shadingModeButton.SetLabelText( "Shading Mode" ); + positionActorModel.Add( shadingModeButton ); + + //Text label title for changing model or shading mode. + TextLabel changeTitleLabel = TextLabel::New( "Change" ); + changeTitleLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + changeTitleLabel.SetProperty( TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}" ); + changeTitleLabel.SetParentOrigin( ParentOrigin::TOP_CENTER ); + changeTitleLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + modelButton.Add( changeTitleLabel ); + + //Create button for pausing animations. PushButton pauseButton = Toolkit::PushButton::New(); pauseButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); pauseButton.ClickedSignal().Connect( this, &MeshVisualController::OnPauseClicked ); - pauseButton.SetParentOrigin( Vector3( 0.5, BUTTONS_OFFSET_BOTTOM, 0.5 ) ); - pauseButton.SetAnchorPoint( AnchorPoint::TOP_CENTER ); - pauseButton.SetLabelText( " || " ); + pauseButton.SetParentOrigin( Vector3( 0.5, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) ); + pauseButton.SetAnchorPoint( AnchorPoint::CENTER ); + pauseButton.SetLabelText( PAUSE ); layer.Add( pauseButton ); + //Actor for positioning light position buttons. + Actor positionActorLight = Actor::New(); + positionActorLight.SetParentOrigin( Vector3( 1.0 - BUTTONS_OFFSET_SIDE, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) ); + positionActorLight.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + layer.Add( positionActorLight ); + + //Create button for switching between manual and fixed light position. + PushButton lightModeButton = Toolkit::PushButton::New(); + lightModeButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + lightModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightModeClicked ); + lightModeButton.SetParentOrigin( ParentOrigin::TOP_CENTER ); + lightModeButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + lightModeButton.SetLabelText( FIXED ); + positionActorLight.Add( lightModeButton ); + + //Create button for switching between front and back light position. + PushButton lightSideButton = Toolkit::PushButton::New(); + lightSideButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + lightSideButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightSideClicked ); + lightSideButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); + lightSideButton.SetAnchorPoint( AnchorPoint::TOP_CENTER ); + lightSideButton.SetLabelText( FRONT ); + positionActorLight.Add( lightSideButton ); + //Text label title for light position mode. TextLabel lightTitleLabel = TextLabel::New( "Light Position" ); lightTitleLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); lightTitleLabel.SetProperty( TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}" ); - lightTitleLabel.SetParentOrigin( Vector3( 0.8, BUTTONS_OFFSET_BOTTOM, 0.5 ) ); + lightTitleLabel.SetParentOrigin( ParentOrigin::TOP_CENTER ); lightTitleLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); - layer.Add( lightTitleLabel ); - - //Create button for switching between manual and fixed light position. - PushButton lightButton = Toolkit::PushButton::New(); - lightButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - lightButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightModeClicked ); - lightButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); - lightButton.SetAnchorPoint( AnchorPoint::TOP_CENTER ); - lightButton.SetLabelText( "FIXED" ); - lightTitleLabel.Add( lightButton ); + lightModeButton.Add( lightTitleLabel ); } //Add a point light source the the scene, on a layer above the first. @@ -246,10 +281,7 @@ public: mLightSource.SetPosition( Stage::GetCurrent().GetSize().x * 0.85f, Stage::GetCurrent().GetSize().y * 0.125 ); //Supply an image to represent the light. - Property::Map lightMap; - lightMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); - lightMap.Insert( ImageVisual::Property::URL, DEMO_IMAGE_DIR "light-icon.png" ); - mLightSource.SetProperty( Control::Property::BACKGROUND, Property::Value( lightMap ) ); + SetLightImage(); //Connect to touch signal for dragging. mLightSource.TouchedSignal().Connect( this, &MeshVisualController::OnTouch ); @@ -264,14 +296,27 @@ public: upperLayer.Add( mLightSource ); //Decide which light to use to begin with. - if( mLightFixed ) + SetLightMode(); + } + + //Sets the image to use for the light source depending on whether the light is in front or behind. + void SetLightImage() + { + std::string imageUrl; + + if( mLightFront ) { - UseFixedLight(); + imageUrl = LIGHT_URL_FRONT; } else { - UseManualLight(); + imageUrl = LIGHT_URL_BACK; } + + Property::Map lightMap; + lightMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); + lightMap.Insert( ImageVisual::Property::URL, imageUrl ); + mLightSource.SetProperty( Control::Property::BACKGROUND, Property::Value( lightMap ) ); } //Updates the displayed models to account for parameter changes. @@ -292,16 +337,31 @@ public: } } + //Set the mode used to light the models. + void SetLightMode() + { + if( mLightFixed ) + { + UseFixedLight(); + } + else + { + UseManualLight(); + } + } + + //Make the models use a fixed, invisible light above the center of the stage. void UseFixedLight() { //Hide draggable source mLightSource.SetVisible( false ); - //Use stage dimensions to place light at center, offset outwards in z axis. + //Use stage dimensions to place light at center, offset in z axis. Stage stage = Stage::GetCurrent(); float width = stage.GetSize().width; float height = stage.GetSize().height; - Vector3 lightPosition = Vector3( width / 2.0f, height / 2.0f, std::max( width, height ) * 5.0f ); + Vector3 lightPosition = Vector3( width / 2.0f, height / 2.0f, + ( mLightFront ? 1 : -1 ) * std::max( width, height ) * 5.0f ); //Set global light position for( int i = 0; i < NUM_MESHES; ++i ) @@ -310,21 +370,23 @@ public: } } + //Make the models use a light source that the user can drag around. void UseManualLight() { //Show draggable source mLightSource.SetVisible( true ); - //Update to switch light position to that off the source. + //Update to switch light position of models to that of the source. UpdateLight(); } //Updates the light position for each model to account for changes in the source on screen. void UpdateLight() { - //Set light position to the x and y of the light control, offset out of the screen. + //Set light position to the x and y of the light control, offset into/out of the screen. Vector3 controlPosition = mLightSource.GetCurrentPosition(); - Vector3 lightPosition = Vector3( controlPosition.x, controlPosition.y, Stage::GetCurrent().GetSize().x / 2.0f ); + Vector3 lightPosition = Vector3( controlPosition.x, controlPosition.y, + ( mLightFront ? 1 : -1 ) * Stage::GetCurrent().GetSize().x / 2.0f ); for( int i = 0; i < NUM_MESHES; ++i ) { @@ -426,8 +488,8 @@ public: return true; } - //Cycle through the list of shaders. - bool OnChangeShaderClicked( Toolkit::Button button ) + //Cycle through the list of shading modes. + bool OnChangeShadingModeClicked( Toolkit::Button button ) { ++mShadingModeIndex %= 3; @@ -451,7 +513,7 @@ public: mModels[i].rotationAnimation.Pause(); } - button.SetLabelText( " > " ); + button.SetLabelText( PLAY ); } else //Unpause all animations again. { @@ -460,14 +522,14 @@ public: mModels[i].rotationAnimation.Play(); } - button.SetLabelText( " || " ); + button.SetLabelText( PAUSE ); } return true; } - //Switch between a fixed light source in front of the screen, and a light source the user can drag around. + //Switch between a fixed light source above/behind the screen, and a light source the user can drag around. bool OnChangeLightModeClicked( Toolkit::Button button ) { //Toggle state. @@ -475,17 +537,39 @@ public: if( mLightFixed ) { - UseFixedLight(); - - button.SetLabelText( "FIXED" ); + button.SetLabelText( FIXED ); } else { - UseManualLight(); + button.SetLabelText( MANUAL ); + } - button.SetLabelText( "MANUAL" ); + SetLightMode(); + + return true; + } + + //Switch between the light being in front of and behind the models. + bool OnChangeLightSideClicked( Toolkit::Button button ) + { + //Toggle state. + mLightFront = !mLightFront; + + if( mLightFront ) + { + button.SetLabelText( FRONT ); + } + else + { + button.SetLabelText( BACK ); } + //Change light image. + SetLightImage(); + + //Update light to account for the change. + SetLightMode(); + return true; } @@ -516,11 +600,12 @@ private: Vector2 mRotationStart; int mModelIndex; //Index of model to load. - int mShadingModeIndex; //Index of shader type to use. + int mShadingModeIndex; //Index of shading mode to use. int mTag; //Identifies what kind of actor has been selected in OnTouch. int mSelectedModelIndex; //Index of model selected on screen. bool mPaused; //If true, all animations are paused and should stay so. bool mLightFixed; //If false, the light is in manual. + bool mLightFront; //Bool for light being in front or behind the models. }; // Entry point for Linux & Tizen applications diff --git a/resources/images/light-icon-back.png b/resources/images/light-icon-back.png new file mode 100644 index 0000000..96b53f1 Binary files /dev/null and b/resources/images/light-icon-back.png differ diff --git a/resources/images/light-icon.png b/resources/images/light-icon-front.png similarity index 100% rename from resources/images/light-icon.png rename to resources/images/light-icon-front.png