/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
*
*/
+// EXTERNAL INCLUDES
#include <dali/dali.h>
#include <dali-toolkit/dali-toolkit.h>
-#include "shared/view.h"
+#include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
#include <fstream>
#include <sstream>
#include <limits>
+// INTERNAL INCLUDES
+#include "shared/view.h"
+#include "shared/utility.h"
+
using namespace Dali;
namespace
{
const char * const APPLICATION_TITLE( "Refraction Effect" );
-const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
-const char * const CHANGE_TEXTURE_ICON( DALI_IMAGE_DIR "icon-change.png" );
-const char * const CHANGE_MESH_ICON( DALI_IMAGE_DIR "icon-replace.png" );
+const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
+const char * const CHANGE_TEXTURE_ICON( DEMO_IMAGE_DIR "icon-change.png" );
+const char * const CHANGE_TEXTURE_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" );
+const char * const CHANGE_MESH_ICON( DEMO_IMAGE_DIR "icon-replace.png" );
+const char * const CHANGE_MESH_ICON_SELECTED( DEMO_IMAGE_DIR "icon-replace-selected.png" );
const char* MESH_FILES[] =
{
- DALI_MODEL_DIR "surface_pattern_v01.obj",
- DALI_MODEL_DIR "surface_pattern_v02.obj"
+ DEMO_MODEL_DIR "surface_pattern_v01.obj",
+ DEMO_MODEL_DIR "surface_pattern_v02.obj"
};
const unsigned int NUM_MESH_FILES( sizeof( MESH_FILES ) / sizeof( MESH_FILES[0] ) );
const char* TEXTURE_IMAGES[]=
{
- DALI_IMAGE_DIR "background-1.jpg",
- DALI_IMAGE_DIR "background-2.jpg",
- DALI_IMAGE_DIR "background-3.jpg",
- DALI_IMAGE_DIR "background-4.jpg"
+ DEMO_IMAGE_DIR "background-1.jpg",
+ DEMO_IMAGE_DIR "background-2.jpg",
+ DEMO_IMAGE_DIR "background-3.jpg",
+ DEMO_IMAGE_DIR "background-4.jpg"
};
const unsigned int NUM_TEXTURE_IMAGES( sizeof( TEXTURE_IMAGES ) / sizeof( TEXTURE_IMAGES[0] ) );
};
/**
- * @brief Load an image, scaled-down to no more than the stage dimensions.
- *
- * Uses image scaling mode SCALE_TO_FILL to resize the image at
- * load time to cover the entire stage with pixels with no borders,
- * and filter mode BOX_THEN_LINEAR to sample the image with maximum quality.
- */
-ResourceImage LoadStageFillingImage( const char * const imagePath )
-{
- Size stageSize = Stage::GetCurrent().GetSize();
- return ResourceImage::New( imagePath, ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR );
-}
-
-/**
* structure of the vertex in the mesh
*/
struct Vertex
public:
RefractionEffectExample( Application &application )
: mApplication( application ),
+ mContent(),
+ mTextureSet(),
+ mGeometry(),
+ mRenderer(),
+ mMeshActor(),
+ mShaderFlat(),
+ mShaderRefraction(),
+ mLightAnimation(),
+ mStrenghAnimation(),
+ mLightXYOffsetIndex( Property::INVALID_INDEX ),
+ mSpinAngleIndex( Property::INVALID_INDEX ),
+ mLightIntensityIndex( Property::INVALID_INDEX ),
+ mEffectStrengthIndex( Property::INVALID_INDEX ),
+ mChangeTextureButton(),
+ mChangeMeshButton(),
mCurrentTextureId( 1 ),
mCurrentMeshId( 0 )
{
// The Init signal is received once (only) during the Application lifetime
void Create(Application& application)
{
- DemoHelper::RequestThemeChange();
-
Stage stage = Stage::GetCurrent();
Vector2 stageSize = stage.GetSize();
// Add a button to change background. (right of toolbar)
mChangeTextureButton = Toolkit::PushButton::New();
- mChangeTextureButton.SetBackgroundImage( ResourceImage::New( CHANGE_TEXTURE_ICON ) );
+ mChangeTextureButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_TEXTURE_ICON );
+ mChangeTextureButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_TEXTURE_ICON_SELECTED );
mChangeTextureButton.ClickedSignal().Connect( this, &RefractionEffectExample::OnChangeTexture );
toolBar.AddControl( mChangeTextureButton,
DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
// Add a button to change mesh pattern. ( left of bar )
mChangeMeshButton = Toolkit::PushButton::New();
- mChangeMeshButton.SetBackgroundImage( ResourceImage::New( CHANGE_MESH_ICON ) );
+ mChangeMeshButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_MESH_ICON );
+ mChangeMeshButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_MESH_ICON_SELECTED );
mChangeMeshButton.ClickedSignal().Connect( this, &RefractionEffectExample::OnChangeMesh );
toolBar.AddControl( mChangeMeshButton,
DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
mShaderFlat = Shader::New( VERTEX_SHADER_FLAT, FRAGMENT_SHADER_FLAT );
mGeometry = CreateGeometry( MESH_FILES[mCurrentMeshId] );
- Image texture = LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] );
- mSampler = Sampler::New( texture, "sTexture" );
- mMaterial = Material::New( mShaderFlat );
- mMaterial.AddSampler( mSampler );
+ Texture texture = DemoHelper::LoadStageFillingTexture( TEXTURE_IMAGES[mCurrentTextureId] );
+ mTextureSet = TextureSet::New();
+ mTextureSet.SetTexture( 0u, texture );
- mRenderer = Renderer::New( mGeometry, mMaterial );
+ mRenderer = Renderer::New( mGeometry, mShaderFlat );
+ mRenderer.SetTextures( mTextureSet );
mMeshActor = Actor::New();
mMeshActor.AddRenderer( mRenderer );
mContent.Add( mMeshActor );
// Connect the callback to the touch signal on the mesh actor
- mContent.TouchedSignal().Connect( this, &RefractionEffectExample::OnTouch );
+ mContent.TouchSignal().Connect( this, &RefractionEffectExample::OnTouch );
// shader used when the finger is touching the screen. render refraction effect
mShaderRefraction = Shader::New( VERTEX_SHADER_REFRACTION, FRAGMENT_SHADER_REFRACTION );
// register uniforms
- mLightXYOffsetIndex = mMeshActor.RegisterProperty( "light-XY-offset", Vector2::ZERO );
- mMeshActor.AddUniformMapping( mLightXYOffsetIndex, "uLightXYOffset" );
+ mLightXYOffsetIndex = mMeshActor.RegisterProperty( "uLightXYOffset", Vector2::ZERO );
- mLightIntensityIndex = mMeshActor.RegisterProperty( "light-intensity", 2.5f );
- mMeshActor.AddUniformMapping( mLightIntensityIndex, "uLightIntensity" );
+ mLightIntensityIndex = mMeshActor.RegisterProperty( "uLightIntensity", 2.5f );
- mEffectStrengthIndex = mMeshActor.RegisterProperty( "effect-strength", 0.f );
- mMeshActor.AddUniformMapping( mEffectStrengthIndex, "uEffectStrength" );
+ mEffectStrengthIndex = mMeshActor.RegisterProperty( "uEffectStrength", 0.f );
Vector3 lightPosition( -stageSize.x*0.5f, -stageSize.y*0.5f, stageSize.x*0.5f ); // top_left
- Property::Index lightPositionIndex = mMeshActor.RegisterProperty( "light-position", lightPosition );
- mMeshActor.AddUniformMapping( lightPositionIndex, "uLightPosition");
+ mMeshActor.RegisterProperty( "uLightPosition", lightPosition );
- Property::Index lightSpinOffsetIndex = mMeshActor.RegisterProperty( "light-spin-offset", Vector2::ZERO );
- mMeshActor.AddUniformMapping( lightSpinOffsetIndex, "uLightSpinOffset" );
+ Property::Index lightSpinOffsetIndex = mMeshActor.RegisterProperty( "uLightSpinOffset", Vector2::ZERO );
- mSpinAngleIndex = mMeshActor.RegisterProperty("spin-angle", 0.f );
+ mSpinAngleIndex = mMeshActor.RegisterProperty("uSpinAngle", 0.f );
Constraint constraint = Constraint::New<Vector2>( mMeshActor, lightSpinOffsetIndex, LightOffsetConstraint(stageSize.x*0.1f) );
constraint.AddSource( LocalSource(mSpinAngleIndex) );
constraint.Apply();
bool OnChangeTexture( Toolkit::Button button )
{
mCurrentTextureId = ( mCurrentTextureId + 1 ) % NUM_TEXTURE_IMAGES;
- Image texture = LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] );
- mSampler.SetImage( texture );
+ Texture texture = DemoHelper::LoadStageFillingTexture( TEXTURE_IMAGES[mCurrentTextureId] );
+ mTextureSet.SetTexture( 0u, texture );
return true;
}
- bool OnTouch( Actor actor , const TouchEvent& event )
+ bool OnTouch( Actor actor, const TouchData& event )
{
- const TouchPoint &point = event.GetPoint(0);
- switch(point.state)
+ switch( event.GetState( 0 ) )
{
- case TouchPoint::Down:
+ case PointState::DOWN:
{
- mMaterial.SetShader( mShaderRefraction );
+ mRenderer.SetShader( mShaderRefraction );
- SetLightXYOffset( point.screen );
+ SetLightXYOffset( event.GetScreenPosition( 0 ) );
mLightAnimation.Play();
break;
}
- case TouchPoint::Motion:
+ case PointState::MOTION:
{
// make the light position following the finger movement
- SetLightXYOffset( point.screen );
+ SetLightXYOffset( event.GetScreenPosition( 0 ) );
break;
}
- case TouchPoint::Up:
- case TouchPoint::Leave:
- case TouchPoint::Interrupted:
+ case PointState::UP:
+ case PointState::LEAVE:
+ case PointState::INTERRUPTED:
{
mLightAnimation.Pause();
mStrenghAnimation.Play();
break;
}
- case TouchPoint::Stationary:
- case TouchPoint::Last:
- default:
+ case PointState::STATIONARY:
{
break;
}
void OnTouchFinished( Animation& source )
{
- mMaterial.SetShader( mShaderFlat );
+ mRenderer.SetShader( mShaderFlat );
SetLightXYOffset( Vector2::ZERO );
}
vertexFormat["aPosition"] = Property::VECTOR3;
vertexFormat["aNormal"] = Property::VECTOR3;
vertexFormat["aTexCoord"] = Property::VECTOR2;
- PropertyBuffer surfaceVertices = PropertyBuffer::New( vertexFormat, vertices.size() );
- surfaceVertices.SetData( &vertices[0] );
+ PropertyBuffer surfaceVertices = PropertyBuffer::New( vertexFormat );
+ surfaceVertices.SetData( &vertices[0], vertices.size() );
Geometry surface = Geometry::New();
surface.AddVertexBuffer( surfaceVertices );
Application& mApplication;
Layer mContent;
-
- Sampler mSampler;
- Material mMaterial;
+ TextureSet mTextureSet;
Geometry mGeometry;
Renderer mRenderer;
Actor mMeshActor;
/*****************************************************************************/
-static void
-RunTest(Application& app)
+int DALI_EXPORT_API main(int argc, char **argv)
{
+ Application app = Application::New(&argc, &argv, DEMO_THEME_PATH);
RefractionEffectExample theApp(app);
app.MainLoop();
-}
-
-/*****************************************************************************/
-
-int
-main(int argc, char **argv)
-{
- Application app = Application::New(&argc, &argv);
-
- RunTest(app);
-
return 0;
}