Updated demos to use DALi clang-format
[platform/core/uifw/dali-demo.git] / examples / compressed-texture-formats / compressed-texture-formats-example.cpp
index cf081f5..1749a63 100644 (file)
@@ -16,9 +16,9 @@
  */
 
 // EXTERNAL INCLUDES
-#include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
+#include <dali/dali.h>
 
 // INTERNAL INCLUDES
 #include "shared/utility.h"
@@ -28,12 +28,11 @@ using Dali::Toolkit::TextLabel;
 
 namespace
 {
-
-const char* IMAGE_FILENAME_ETC         =        DEMO_IMAGE_DIR "tx-etc1.ktx";
-const char* IMAGE_FILENAME_ASTC_LINEAR =        DEMO_IMAGE_DIR "tx-astc-4x4-linear.ktx";
+const char* IMAGE_FILENAME_ETC                = DEMO_IMAGE_DIR "tx-etc1.ktx";
+const char* IMAGE_FILENAME_ASTC_LINEAR        = DEMO_IMAGE_DIR "tx-astc-4x4-linear.ktx";
 const char* IMAGE_FILENAME_ASTC_LINEAR_NATIVE = DEMO_IMAGE_DIR "tx-astc-4x4-linear-native.astc";
 
-
+// clang-format off
 static const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
     attribute mediump vec2 aPosition;\n
     attribute mediump vec2 aTexCoord;\n
@@ -58,6 +57,7 @@ static const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
       gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
     }\n
 );
+// clang-format on
 
 /**
  * @brief Create a renderer to render an image and adds it to an actor
@@ -66,23 +66,23 @@ static const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
  * @param[in[ geometry The geometry to use
  * @param[in] shader The shader to use
  */
-void AddImage( const char*imagePath, Actor& actor, Geometry& geometry, Shader& shader )
+void AddImage(const char* imagePath, Actor& actor, Geometry& geometry, Shader& shader)
 {
   //Load the texture
-  Texture texture = DemoHelper::LoadTexture( imagePath );
+  Texture    texture    = DemoHelper::LoadTexture(imagePath);
   TextureSet textureSet = TextureSet::New();
-  textureSet.SetTexture( 0u, texture );
+  textureSet.SetTexture(0u, texture);
 
   //Create the renderer
-  Renderer renderer = Renderer::New( geometry, shader );
-  renderer.SetTextures( textureSet );
+  Renderer renderer = Renderer::New(geometry, shader);
+  renderer.SetTextures(textureSet);
 
   //Set actor size and add the renderer
-  actor.SetProperty( Actor::Property::SIZE, Vector2( texture.GetWidth(), texture.GetHeight() ) );
-  actor.AddRenderer( renderer );
+  actor.SetProperty(Actor::Property::SIZE, Vector2(texture.GetWidth(), texture.GetHeight()));
+  actor.AddRenderer(renderer);
 }
 
-}
+} // namespace
 /**
  * @brief This example shows 3 images, each of a different compressed texture type.
  * If built and run on a OpenGL ES 3.1 compatable target, then all 3 images will display.
@@ -91,12 +91,11 @@ void AddImage( const char*imagePath, Actor& actor, Geometry& geometry, Shader& s
 class CompressedTextureFormatsController : public ConnectionTracker
 {
 public:
-
-  CompressedTextureFormatsController( Application& application )
-  : mApplication( application )
+  CompressedTextureFormatsController(Application& application)
+  : mApplication(application)
   {
     // Connect to the Application's Init signal
-    mApplication.InitSignal().Connect( this, &CompressedTextureFormatsController::Create );
+    mApplication.InitSignal().Connect(this, &CompressedTextureFormatsController::Create);
   }
 
   ~CompressedTextureFormatsController()
@@ -105,83 +104,82 @@ public:
   }
 
   // The Init signal is received once (only) during the Application lifetime
-  void Create( Application& application )
+  void Create(Application& application)
   {
     // Get a handle to the window
     Window window = application.GetWindow();
-    window.SetBackgroundColor( Color::WHITE );
+    window.SetBackgroundColor(Color::WHITE);
 
     // Setup a TableView to hold a grid of images and labels.
-    Toolkit::TableView table = Toolkit::TableView::New( 3u, 2u );
-    table.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
-    table.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
-    table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    table.SetRelativeWidth( 0u, 0.5f );
-    table.SetRelativeWidth( 1u, 0.5f );
-    table.SetRelativeHeight( 0u, 1.0f / 3.0f );
-    table.SetRelativeHeight( 1u, 1.0f / 3.0f );
-    table.SetRelativeHeight( 2u, 1.0f / 3.0f );
-
+    Toolkit::TableView table = Toolkit::TableView::New(3u, 2u);
+    table.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+    table.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+    table.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
+    table.SetRelativeWidth(0u, 0.5f);
+    table.SetRelativeWidth(1u, 0.5f);
+    table.SetRelativeHeight(0u, 1.0f / 3.0f);
+    table.SetRelativeHeight(1u, 1.0f / 3.0f);
+    table.SetRelativeHeight(2u, 1.0f / 3.0f);
 
     // Add text labels.
-    TextLabel textLabel = TextLabel::New( "ETC1 (KTX):" );
-    textLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
-    textLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
-    textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
-    table.AddChild( textLabel, Toolkit::TableView::CellPosition( 0u, 0u ) );
-    table.SetCellAlignment( Toolkit::TableView::CellPosition( 0u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
-
-    textLabel = TextLabel::New( "ASTC (KTX) 4x4 linear:" );
-    textLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
-    textLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
-    textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
-    table.AddChild( textLabel, Toolkit::TableView::CellPosition( 1u, 0u ) );
-    table.SetCellAlignment( Toolkit::TableView::CellPosition( 1u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
-
-    textLabel = TextLabel::New( "ASTC (Native) 4x4 linear:" );
-    textLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
-    textLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
-    textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
-    table.AddChild( textLabel, Toolkit::TableView::CellPosition( 2u, 0u ) );
-    table.SetCellAlignment( Toolkit::TableView::CellPosition( 2u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
+    TextLabel textLabel = TextLabel::New("ETC1 (KTX):");
+    textLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+    textLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+    textLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
+    textLabel.SetProperty(Toolkit::TextLabel::Property::MULTI_LINE, true);
+    table.AddChild(textLabel, Toolkit::TableView::CellPosition(0u, 0u));
+    table.SetCellAlignment(Toolkit::TableView::CellPosition(0u, 0u), HorizontalAlignment::LEFT, VerticalAlignment::CENTER);
+
+    textLabel = TextLabel::New("ASTC (KTX) 4x4 linear:");
+    textLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+    textLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+    textLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
+    textLabel.SetProperty(Toolkit::TextLabel::Property::MULTI_LINE, true);
+    table.AddChild(textLabel, Toolkit::TableView::CellPosition(1u, 0u));
+    table.SetCellAlignment(Toolkit::TableView::CellPosition(1u, 0u), HorizontalAlignment::LEFT, VerticalAlignment::CENTER);
+
+    textLabel = TextLabel::New("ASTC (Native) 4x4 linear:");
+    textLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+    textLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+    textLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
+    textLabel.SetProperty(Toolkit::TextLabel::Property::MULTI_LINE, true);
+    table.AddChild(textLabel, Toolkit::TableView::CellPosition(2u, 0u));
+    table.SetCellAlignment(Toolkit::TableView::CellPosition(2u, 0u), HorizontalAlignment::LEFT, VerticalAlignment::CENTER);
 
     //Create the geometry and the shader renderers will use
     Geometry geometry = DemoHelper::CreateTexturedQuad();
-    Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE );
+    Shader   shader   = Shader::New(VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE);
 
     // Add images.
     Actor actor = Actor::New();
-    actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
-    actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
-    AddImage( IMAGE_FILENAME_ETC, actor, geometry, shader  );
-    table.AddChild( actor, Toolkit::TableView::CellPosition( 0u, 1u ) );
-    table.SetCellAlignment( Toolkit::TableView::CellPosition( 0u, 1u ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
+    actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+    actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+    AddImage(IMAGE_FILENAME_ETC, actor, geometry, shader);
+    table.AddChild(actor, Toolkit::TableView::CellPosition(0u, 1u));
+    table.SetCellAlignment(Toolkit::TableView::CellPosition(0u, 1u), HorizontalAlignment::CENTER, VerticalAlignment::CENTER);
 
     actor = Actor::New();
-    actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
-    actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
-    AddImage( IMAGE_FILENAME_ASTC_LINEAR, actor, geometry, shader );
-    table.AddChild( actor, Toolkit::TableView::CellPosition( 1u, 1u ) );
-    table.SetCellAlignment( Toolkit::TableView::CellPosition( 1u, 1u ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
+    actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+    actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+    AddImage(IMAGE_FILENAME_ASTC_LINEAR, actor, geometry, shader);
+    table.AddChild(actor, Toolkit::TableView::CellPosition(1u, 1u));
+    table.SetCellAlignment(Toolkit::TableView::CellPosition(1u, 1u), HorizontalAlignment::CENTER, VerticalAlignment::CENTER);
 
     actor = Actor::New();
-    actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
-    actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
-    AddImage( IMAGE_FILENAME_ASTC_LINEAR_NATIVE, actor, geometry, shader );
-    table.AddChild( actor, Toolkit::TableView::CellPosition( 2u, 1u ) );
-    table.SetCellAlignment( Toolkit::TableView::CellPosition( 2u, 1u ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
+    actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+    actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+    AddImage(IMAGE_FILENAME_ASTC_LINEAR_NATIVE, actor, geometry, shader);
+    table.AddChild(actor, Toolkit::TableView::CellPosition(2u, 1u));
+    table.SetCellAlignment(Toolkit::TableView::CellPosition(2u, 1u), HorizontalAlignment::CENTER, VerticalAlignment::CENTER);
 
-    window.Add( table );
+    window.Add(table);
 
     // Respond to touch and key signals
-    window.GetRootLayer().TouchedSignal().Connect( this, &CompressedTextureFormatsController::OnTouch );
+    window.GetRootLayer().TouchedSignal().Connect(this, &CompressedTextureFormatsController::OnTouch);
     window.KeyEventSignal().Connect(this, &CompressedTextureFormatsController::OnKeyEvent);
   }
 
-  bool OnTouch( Actor actor, const TouchEvent& touch )
+  bool OnTouch(Actor actor, const TouchEvent& touch)
   {
     // quit the application
     mApplication.Quit();
@@ -192,7 +190,7 @@ public:
   {
     if(event.GetState() == KeyEvent::DOWN)
     {
-      if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
+      if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
       {
         mApplication.Quit();
       }
@@ -200,13 +198,13 @@ public:
   }
 
 private:
-  Application&  mApplication;
+  Application& mApplication;
 };
 
-int DALI_EXPORT_API main( int argc, char **argv )
+int DALI_EXPORT_API main(int argc, char** argv)
 {
-  Application application = Application::New( &argc, &argv );
-  CompressedTextureFormatsController test( application );
+  Application                        application = Application::New(&argc, &argv);
+  CompressedTextureFormatsController test(application);
   application.MainLoop();
   return 0;
 }