[dali_1.0.42] Merge branch 'tizen'
[platform/core/uifw/dali-demo.git] / examples / refraction-effect / refraction-effect-example.cpp
index 32d8a90..a220490 100644 (file)
 
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
+#include <dali/devel-api/actors/mesh-actor.h>
+#include <dali/devel-api/modeling/material.h>
+#include <dali/devel-api/geometry/mesh.h>
+
 #include "shared/view.h"
 
 #include <fstream>
 #include <sstream>
+#include <limits>
 
 using namespace Dali;
 
@@ -56,15 +61,31 @@ struct LightOffsetConstraint
   {
   }
 
-  Vector2 operator()( const Vector2& current, const PropertyInput& spinAngleProperty)
+  void operator()( Vector2& current, const PropertyInputContainer& inputs )
   {
-    float spinAngle = spinAngleProperty.GetFloat();
-    return Vector2( cos(spinAngle ), sin( spinAngle ) ) * mRadius;
+    float spinAngle = inputs[0]->GetFloat();
+    current.x = cos( spinAngle );
+    current.y = sin( spinAngle );
+
+    current *= mRadius;
   }
 
   float mRadius;
 };
 
+/**
+ * @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 );
+}
+
 } // namespace
 
 /************************************************************************************************
@@ -235,11 +256,10 @@ public:
     handle.SetUniform( "uEffectStrength", 0.f );
     handle.SetUniform( "uLightIntensity",  2.5f );
 
-    Property::Index index = handle.RegisterProperty( "uSpinAngle", 0.f );
-    Constraint constraint = Constraint::New<Vector2>( handle.GetPropertyIndex("uLightSpinOffset"),
-                                                      LocalSource(index),
-                                                      LightOffsetConstraint(stageSize.x*0.1f));
-    handle.ApplyConstraint( constraint );
+    Dali::Property::Index index = handle.RegisterProperty( "uSpinAngle", 0.f );
+    Constraint constraint = Constraint::New<Vector2>( handle, handle.GetPropertyIndex("uLightSpinOffset"), LightOffsetConstraint(stageSize.x*0.1f) );
+    constraint.AddSource( LocalSource(index) );
+    constraint.Apply();
 
     return handle;
   }
@@ -308,7 +328,7 @@ private:
     // Creates a default view with a default tool bar.
     // The view is added to the stage.
     Toolkit::ToolBar toolBar;
-    Toolkit::View    view;
+    Toolkit::Control    view;
     mContent = DemoHelper::CreateView( application,
         view,
         toolBar,
@@ -338,7 +358,7 @@ private:
     mNoEffect = NoEffect::New(); // used in the other situations, basic render shader
     // Create the mesh from the obj file and add to stage
     mMaterial =  Material::New( "Material" ) ;
-    mMaterial.SetDiffuseTexture(ResourceImage::New(TEXTURE_IMAGES[mCurrentTextureId]));
+    mMaterial.SetDiffuseTexture( LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] ) );
     CreateSurface( MESH_FILES[mCurrentMeshId] );
 
     // Connect the callback to the touch signal on the mesh actor
@@ -371,7 +391,7 @@ private:
   bool OnChangeTexture( Toolkit::Button button )
   {
     mCurrentTextureId = ( mCurrentTextureId + 1 ) % NUM_TEXTURE_IMAGES;
-    mMaterial.SetDiffuseTexture(ResourceImage::New(TEXTURE_IMAGES[mCurrentTextureId]));
+    mMaterial.SetDiffuseTexture( LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] ) );
 
     return true;
   }
@@ -501,7 +521,6 @@ private:
     meshData.SetHasNormals(true);
     mMeshActor = MeshActor::New( Mesh::New( meshData ) );
     mMeshActor.SetParentOrigin(ParentOrigin::CENTER);
-    mMeshActor.SetAffectedByLighting( false );
     mMeshActor.SetShaderEffect( mNoEffect );
     mContent.Add( mMeshActor );
   }
@@ -637,7 +656,7 @@ RunTest(Application& app)
 int
 main(int argc, char **argv)
 {
-  Application app = Application::New(&argc, &argv);
+  Application app = Application::New(&argc, &argv, DALI_DEMO_THEME_PATH);
 
   RunTest(app);