Add ArcVisual 61/229461/1
authorHeeyong Song <heeyong.song@samsung.com>
Thu, 5 Mar 2020 06:03:46 +0000 (15:03 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Wed, 1 Apr 2020 06:11:47 +0000 (15:11 +0900)
Change-Id: I6a1838fc5db66d253bb1c41915e7d571387d968e

13 files changed:
automated-tests/src/dali-toolkit-internal/utc-Dali-Visuals-internal.cpp
automated-tests/src/dali-toolkit/CMakeLists.txt
automated-tests/src/dali-toolkit/utc-Dali-ArcVisual.cpp [new file with mode: 0644]
dali-toolkit/devel-api/file.list
dali-toolkit/devel-api/visuals/arc-visual-properties-devel.h [new file with mode: 0644]
dali-toolkit/devel-api/visuals/visual-properties-devel.h
dali-toolkit/internal/file.list
dali-toolkit/internal/visuals/arc/arc-visual.cpp [new file with mode: 0644]
dali-toolkit/internal/visuals/arc/arc-visual.h [new file with mode: 0644]
dali-toolkit/internal/visuals/visual-factory-cache.h
dali-toolkit/internal/visuals/visual-factory-impl.cpp
dali-toolkit/internal/visuals/visual-string-constants.cpp
dali-toolkit/internal/visuals/visual-string-constants.h

index 87345ea..d20cbcf 100644 (file)
@@ -29,6 +29,7 @@
 #include <dali-toolkit/internal/visuals/npatch-loader.h>
 #include <dummy-visual.h>
 #include <../dali-toolkit/dali-toolkit-test-utils/dummy-control.h>
+#include <dali-toolkit/devel-api/visuals/arc-visual-properties-devel.h>
 
 using namespace Dali;
 using namespace Toolkit;
@@ -369,3 +370,26 @@ int UtcDaliAnimatedVectorImageVisualSetProperties(void)
 
   END_TEST;
 }
+
+int UtcDaliArcVisualCreateInstancePropertyMap(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "UtcDaliArcVisualCreateInstancePropertyMap" );
+
+  Property::Map propertyMap;
+  propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ARC )
+             .Add( DevelArcVisual::Property::THICKNESS, 20.0f );
+
+  // request ArcVisual with a property map
+  VisualFactory factory = VisualFactory::Get();
+  Visual::Base visual = factory.CreateVisual( propertyMap );
+  Toolkit::Internal::Visual::Base& visualImpl = GetImplementation( visual );
+
+  Property::Map resultMap;
+  visualImpl.CreateInstancePropertyMap( resultMap );
+
+  // check the property values from the returned map from a visual
+  DALI_TEST_CHECK( resultMap.Empty() );   // Now the map is empty
+
+  END_TEST;
+}
index 2db3264..de0513d 100755 (executable)
@@ -10,6 +10,7 @@ SET(TC_SOURCES
   utc-Dali-Alignment.cpp
   utc-Dali-AnimatedImageVisual.cpp
   utc-Dali-AnimatedVectorImageVisual.cpp
+  utc-Dali-ArcVisual.cpp
   utc-Dali-BloomView.cpp
   utc-Dali-BubbleEmitter.cpp
   utc-Dali-Builder.cpp
diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ArcVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ArcVisual.cpp
new file mode 100644 (file)
index 0000000..be12290
--- /dev/null
@@ -0,0 +1,201 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <iostream>
+#include <stdlib.h>
+//#include <chrono>
+//#include <thread>
+#include <dali-toolkit-test-suite-utils.h>
+//#include <toolkit-timer.h>
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
+#include <dali-toolkit/devel-api/visuals/arc-visual-properties-devel.h>
+#include <dali/devel-api/rendering/renderer-devel.h>
+#include "dummy-control.h"
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+
+void dali_arc_visual_startup(void)
+{
+  test_return_value = TET_UNDEF;
+}
+
+void dali_arc_visual_cleanup(void)
+{
+  test_return_value = TET_PASS;
+}
+
+int UtcDaliVisualFactoryGetArcVisual01(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "UtcDaliVisualFactoryGetArcVisual01: Request arc visual with a Property::Map" );
+
+  Property::Map propertyMap;
+  propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ARC )
+             .Add( Visual::Property::MIX_COLOR, Color::RED )
+             .Add( DevelArcVisual::Property::THICKNESS, 20.0f );
+
+  Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
+  DALI_TEST_CHECK( visual );
+
+  DummyControl actor = DummyControl::New( true );
+  DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
+  dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
+  actor.SetSize( 200.0f, 200.0f );
+  Stage::GetCurrent().Add( actor );
+
+  application.SendNotification();
+  application.Render();
+
+  // renderer is added to actor
+  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+  Renderer renderer = actor.GetRendererAt( 0u );
+  DALI_TEST_CHECK( renderer );
+
+  actor.Unparent( );
+  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+
+  END_TEST;
+}
+
+int UtcDaliVisualFactoryGetArcVisual02(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "UtcDaliVisualFactoryGetArcVisual02: Request arc visual with a Property::Map" );
+
+  Property::Map propertyMap;
+  propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ARC )
+             .Add( Visual::Property::MIX_COLOR, Color::RED )
+             .Add( DevelArcVisual::Property::THICKNESS, 20.0f )
+             .Add( DevelArcVisual::Property::START_ANGLE, 0.0f )
+             .Add( DevelArcVisual::Property::SWEEP_ANGLE, 90.0f )
+             .Add( DevelArcVisual::Property::CAP, DevelArcVisual::Cap::ROUND );
+
+  Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
+  DALI_TEST_CHECK( visual );
+
+  DummyControl actor = DummyControl::New( true );
+  DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
+  dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
+  actor.SetSize( 200.0f, 200.0f );
+  Stage::GetCurrent().Add( actor );
+
+  application.SendNotification();
+  application.Render();
+
+  // renderer is added to actor
+  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+  Renderer renderer = actor.GetRendererAt( 0u );
+  DALI_TEST_CHECK( renderer );
+
+  actor.Unparent( );
+  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+
+  END_TEST;
+}
+
+int UtcDaliArcVisualGetPropertyMap01(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "UtcDaliArcVisualGetPropertyMap01" );
+
+  float thickness = 20.0f;
+  float startAngle = 0.0f, sweepAngle = 90.0f;
+
+  Property::Map propertyMap;
+  propertyMap.Add( "visualType", DevelVisual::ARC )
+             .Add( "mixColor", Color::RED )
+             .Add( "thickness", thickness )
+             .Add( "startAngle", startAngle )
+             .Add( "sweepAngle", sweepAngle )
+             .Add( "cap", DevelArcVisual::Cap::ROUND );
+
+  Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
+  DALI_TEST_CHECK( visual );
+
+  DummyControl actor = DummyControl::New( true );
+  DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() );
+  dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
+  actor.SetSize( 200.0f, 200.0f );
+  Stage::GetCurrent().Add( actor );
+
+  application.SendNotification();
+  application.Render();
+
+  // renderer is added to actor
+  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+  Renderer renderer = actor.GetRendererAt( 0u );
+  DALI_TEST_CHECK( renderer );
+
+  Property::Map resultMap;
+  visual.CreatePropertyMap( resultMap );
+
+  // check the property values from the returned map from a visual
+  Property::Value* value = resultMap.Find( Visual::Property::MIX_COLOR, Property::VECTOR4 );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( value->Get< Vector4 >(), Color::RED, TEST_LOCATION );
+
+  value = resultMap.Find( DevelArcVisual::Property::THICKNESS, Property::FLOAT );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( value->Get< float >(), thickness, TEST_LOCATION );
+
+  value = resultMap.Find( DevelArcVisual::Property::START_ANGLE, Property::FLOAT );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( value->Get< float >(), startAngle, TEST_LOCATION );
+
+  value = resultMap.Find( DevelArcVisual::Property::SWEEP_ANGLE, Property::FLOAT );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( value->Get< float >(), sweepAngle, TEST_LOCATION );
+
+  value = resultMap.Find( DevelArcVisual::Property::CAP, Property::INTEGER );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_CHECK( value->Get< int >() == DevelArcVisual::Cap::ROUND );
+
+  // Test wrong values
+  propertyMap[DevelArcVisual::Property::THICKNESS] = "3.0f";
+  propertyMap[DevelArcVisual::Property::START_ANGLE] = "0.0f";
+  propertyMap[DevelArcVisual::Property::SWEEP_ANGLE] = "90.0f";
+  propertyMap[DevelArcVisual::Property::CAP] = "1";
+
+  visual = VisualFactory::Get().CreateVisual( propertyMap );
+  DALI_TEST_CHECK( visual );
+
+  visual.CreatePropertyMap( resultMap );
+
+  value = resultMap.Find( DevelArcVisual::Property::THICKNESS, Property::FLOAT );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( value->Get< float >(), 0.0f, TEST_LOCATION );
+
+  value = resultMap.Find( DevelArcVisual::Property::START_ANGLE, Property::FLOAT );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( value->Get< float >(), 0.0f, TEST_LOCATION );
+
+  value = resultMap.Find( DevelArcVisual::Property::SWEEP_ANGLE, Property::FLOAT );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( value->Get< float >(), 360.0f, TEST_LOCATION );
+
+  value = resultMap.Find( DevelArcVisual::Property::CAP, Property::INTEGER );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_CHECK( value->Get< int >() == DevelArcVisual::Cap::BUTT );
+
+  actor.Unparent( );
+  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+
+  END_TEST;
+}
index fad069b..77d3d5e 100755 (executable)
@@ -125,6 +125,7 @@ SET( devel_api_visuals_header_files
   ${devel_api_src_dir}/visuals/animated-image-visual-actions-devel.h
   ${devel_api_src_dir}/visuals/animated-vector-image-visual-actions-devel.h
   ${devel_api_src_dir}/visuals/animated-vector-image-visual-signals-devel.h
+  ${devel_api_src_dir}/visuals/arc-visual-properties-devel.h
   ${devel_api_src_dir}/visuals/color-visual-properties-devel.h
   ${devel_api_src_dir}/visuals/image-visual-properties-devel.h
   ${devel_api_src_dir}/visuals/image-visual-actions-devel.h
diff --git a/dali-toolkit/devel-api/visuals/arc-visual-properties-devel.h b/dali-toolkit/devel-api/visuals/arc-visual-properties-devel.h
new file mode 100644 (file)
index 0000000..a10df8a
--- /dev/null
@@ -0,0 +1,97 @@
+#ifndef DALI_TOOLKIT_ARC_VISUAL_PROPERTIES_DEVEL_H
+#define DALI_TOOLKIT_ARC_VISUAL_PROPERTIES_DEVEL_H
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/toolkit-property-index-ranges.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace DevelArcVisual
+{
+
+/**
+ * @brief ArcVisual Properties.
+ */
+namespace Property
+{
+
+/**
+ * @brief Enumeration for the instance of properties belonging to the ArcVisual.
+ */
+enum
+{
+  /**
+   * @brief The thickness of the arc.
+   * @details Name "thickness", type Property::FLOAT.
+   * @note Mandatory.
+   */
+  THICKNESS = VISUAL_PROPERTY_START_INDEX,
+
+  /**
+   * @brief The start angle where the arc begins in degrees.
+   * @details Name "startAngle", type Property::FLOAT.
+   * @note Optional. If not specified, the default is 0.
+   */
+  START_ANGLE,
+
+  /**
+   * @brief The sweep angle of the arc in degrees.
+   * @details Name "sweepAngle", type Property::FLOAT.
+   * The arc starts at a specified start angle and sweeps clockwise, drawing slices of pie.
+   * @note Optional. If not specified, the default is 360.
+   */
+  SWEEP_ANGLE,
+
+  /**
+   * @brief The cap of the arc.
+   * @details Name "cap", Type Cap::Type (Property::INTEGER)
+   * It specifies the shape of the endpoints.
+   * @note Optional. If not specified, the default is Cap::BUTT.
+   */
+  CAP,
+};
+
+} // namespace Property
+
+/**
+ * @brief Enumeration for the cap style.
+ */
+namespace Cap
+{
+
+enum Type
+{
+  BUTT,      ///< The arc does not extend beyond its two endpoints.
+  ROUND      ///< The arc will be extended by a half circle with the center at the end.
+};
+
+} // namespace Cap
+
+} // namespace DevelArcVisual
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_ARC_VISUAL_PROPERTIES_DEVEL_H
index 8dfb3cc..3d304a1 100644 (file)
@@ -49,6 +49,7 @@ enum Type
 
   ANIMATED_GRADIENT     = ANIMATED_IMAGE + 1,  ///< Renders an animated gradient.
   ANIMATED_VECTOR_IMAGE = ANIMATED_IMAGE + 2,  ///< Renders an animated vector image.
+  ARC                   = ANIMATED_IMAGE + 3,  ///< Renders an arc.
 };
 
 /**
index 9642ef8..8f3b2f2 100644 (file)
@@ -22,6 +22,7 @@ SET( toolkit_src_files
    ${toolkit_src_dir}/visuals/animated-vector-image/vector-animation-task.cpp
    ${toolkit_src_dir}/visuals/animated-vector-image/vector-animation-thread.cpp
    ${toolkit_src_dir}/visuals/animated-vector-image/vector-rasterize-thread.cpp
+   ${toolkit_src_dir}/visuals/arc/arc-visual.cpp
    ${toolkit_src_dir}/visuals/border/border-visual.cpp
    ${toolkit_src_dir}/visuals/color/color-visual.cpp
    ${toolkit_src_dir}/visuals/gradient/gradient-visual.cpp
diff --git a/dali-toolkit/internal/visuals/arc/arc-visual.cpp b/dali-toolkit/internal/visuals/arc/arc-visual.cpp
new file mode 100644 (file)
index 0000000..a1eb02a
--- /dev/null
@@ -0,0 +1,287 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/internal/visuals/arc/arc-visual.h>
+
+// EXTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+
+//INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
+#include <dali-toolkit/internal/visuals/visual-factory-impl.h>
+#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
+#include <dali-toolkit/internal/visuals/visual-string-constants.h>
+#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+namespace
+{
+
+// cap
+DALI_ENUM_TO_STRING_TABLE_BEGIN( CAP )
+DALI_ENUM_TO_STRING_WITH_SCOPE( DevelArcVisual::Cap, BUTT )
+DALI_ENUM_TO_STRING_WITH_SCOPE( DevelArcVisual::Cap, ROUND )
+DALI_ENUM_TO_STRING_TABLE_END( CAP )
+
+const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
+  attribute mediump vec2 aPosition;\n
+  uniform highp   mat4 uMvpMatrix;\n
+  uniform mediump vec3 uSize;\n
+  \n
+  varying mediump vec2 vPosition;\n
+  \n
+  //Visual size and offset
+  uniform mediump vec2 offset;\n
+  uniform mediump vec2 size;\n
+  uniform mediump vec4 offsetSizeMode;\n
+  uniform mediump vec2 origin;\n
+  uniform mediump vec2 anchorPoint;\n
+
+  vec4 ComputeVertexPosition()\n
+  {\n
+    vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
+    vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
+    vPosition = aPosition* visualSize;\n
+    return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n
+  }\n
+
+  void main()\n
+  {\n
+    gl_Position = uMvpMatrix * ComputeVertexPosition();\n
+  }\n
+);
+
+const char* FRAGMENT_SHADER_BUTT_CAP = DALI_COMPOSE_SHADER(
+  varying mediump vec2 vPosition;\n
+  uniform lowp vec4 uColor;\n
+  uniform lowp vec3 mixColor;\n
+  uniform mediump float thickness;\n
+  uniform mediump float radius;\n
+  uniform mediump float startAngle;\n
+  uniform mediump float sweepAngle;\n
+  \n
+  const mediump float M_PI_OVER_2 = 1.57079632679;\n
+  const mediump float M_PI = 3.14159265359;\n
+  const mediump float M_PI_2 = 6.28318530718;\n
+  \n
+  mediump float GetOpacity()\n
+  {\n
+      mediump float start = radians( mod( startAngle, 360.0 ) );\n
+      mediump float angle = mod( atan( vPosition.y, vPosition.x ) + M_PI_OVER_2 - start, M_PI_2 );\n
+      mediump float dist = length( vPosition );\n
+      if( angle <= radians( sweepAngle ) )\n
+      {\n
+        return smoothstep( -1.0, 1.0, thickness / 2.0 - ( abs( dist - radius ) ) );\n
+      }\n
+      mediump float end = radians( mod( startAngle + sweepAngle, 360.0 ) );\n
+      mediump vec2 q0 = vec2( dist * cos( start - M_PI_OVER_2 ), dist * sin( start - M_PI_OVER_2 ) );\n
+      mediump vec2 q1 = vec2( dist * cos( end - M_PI_OVER_2 ), dist * sin( end - M_PI_OVER_2 ) );\n
+      mediump float opacity = 1.0 - smoothstep( 0.0, 2.0, min( length( vPosition - q0 ), length( vPosition - q1 ) ) );\n
+      opacity *= step( 0.0, thickness / 2.0 - abs( dist - radius ) );\n
+      return opacity;\n
+  }\n
+  void main()\n
+  {\n
+    gl_FragColor = vec4( mixColor, 1.0 ) * uColor;\n
+    gl_FragColor.a *= GetOpacity();\n
+  }\n
+);
+
+const char* FRAGMENT_SHADER_ROUND_CAP = DALI_COMPOSE_SHADER(
+  varying mediump vec2 vPosition;\n
+  uniform lowp vec4 uColor;\n
+  uniform lowp vec3 mixColor;\n
+  uniform mediump float thickness;\n
+  uniform mediump float radius;\n
+  uniform mediump float startAngle;\n
+  uniform mediump float sweepAngle;\n
+  \n
+  const mediump float M_PI_OVER_2 = 1.57079632679;\n
+  const mediump float M_PI_2 = 6.28318530718;\n
+  \n
+  mediump float GetOpacity()\n
+  {\n
+      mediump float start = radians( mod( startAngle, 360.0 ) );\n
+      mediump float angle = mod( atan( vPosition.y, vPosition.x ) + M_PI_OVER_2 - start, M_PI_2 );\n
+      mediump float dist = length( vPosition );\n
+      if( angle <= radians( sweepAngle ) )\n
+      {\n
+        return smoothstep( -1.0, 1.0, thickness / 2.0 - ( abs( dist - radius ) ) );\n
+      }\n
+      mediump float end = radians( mod( startAngle + sweepAngle, 360.0 ) );\n
+      mediump vec2 q0 = vec2( radius * cos( start - M_PI_OVER_2 ), radius * sin( start - M_PI_OVER_2 ) );\n
+      mediump vec2 q1 = vec2( radius * cos( end - M_PI_OVER_2 ), radius * sin( end - M_PI_OVER_2 ) );\n
+      return smoothstep( -1.0, 1.0, thickness / 2.0 - min( length( vPosition - q0 ), length( vPosition - q1 ) ) );\n
+  }\n
+  void main()\n
+  {\n
+    gl_FragColor = vec4( mixColor, 1.0 ) * uColor;\n
+    gl_FragColor.a *= GetOpacity();\n
+  }\n
+);
+
+}
+
+ArcVisualPtr ArcVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
+{
+  ArcVisualPtr arcVisualPtr( new ArcVisual( factoryCache ) );
+  arcVisualPtr->SetProperties( properties );
+  return arcVisualPtr;
+}
+
+ArcVisual::ArcVisual( VisualFactoryCache& factoryCache )
+: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+  mThickness( 0.0f ),
+  mRadius( 0.0f ),
+  mStartAngle( 0.0f ),
+  mSweepAngle( 360.0f ),
+  mRadiusIndex( Property::INVALID_INDEX ),
+  mCapType( DevelArcVisual::Cap::BUTT )
+{
+}
+
+ArcVisual::~ArcVisual()
+{
+}
+
+void ArcVisual::DoSetProperties( const Property::Map& propertyMap )
+{
+  Property::Value* thicknessValue = propertyMap.Find( Toolkit::DevelArcVisual::Property::THICKNESS, THICKNESS_NAME );
+  if( thicknessValue )
+  {
+    if( !thicknessValue->Get( mThickness ) )
+    {
+      DALI_LOG_ERROR( "ArcVisual:DoSetProperties:: THICKNESS property has incorrect type: %d\n", thicknessValue->GetType() );
+    }
+  }
+
+  Property::Value* startAngleValue = propertyMap.Find( Toolkit::DevelArcVisual::Property::START_ANGLE, START_ANGLE_NAME );
+  if( startAngleValue )
+  {
+    if( !startAngleValue->Get( mStartAngle ) )
+    {
+      DALI_LOG_ERROR( "ArcVisual:DoSetProperties:: START_ANGLE property has incorrect type: %d\n", startAngleValue->GetType() );
+    }
+  }
+
+  Property::Value* sweepAngleValue = propertyMap.Find( Toolkit::DevelArcVisual::Property::SWEEP_ANGLE, SWEEP_ANGLE_NAME );
+  if( sweepAngleValue )
+  {
+    if( !sweepAngleValue->Get( mSweepAngle ) )
+    {
+      DALI_LOG_ERROR( "ArcVisual:DoSetProperties:: SWEEP_ANGLE property has incorrect type: %d\n", sweepAngleValue->GetType() );
+    }
+  }
+
+  Property::Value* capValue = propertyMap.Find( Toolkit::DevelArcVisual::Property::CAP, CAP_NAME );
+  if( capValue )
+  {
+    int capType = 0;
+    Scripting::GetEnumerationProperty( *capValue, CAP_TABLE, CAP_TABLE_COUNT, capType );
+    mCapType = Toolkit::DevelArcVisual::Cap::Type( capType );
+  }
+}
+
+void ArcVisual::DoSetOnStage( Actor& actor )
+{
+  InitializeRenderer();
+
+  actor.AddRenderer( mImpl->mRenderer );
+
+  // Arc Visual generated and ready to display
+  ResourceReady( Toolkit::Visual::ResourceStatus::READY );
+}
+
+void ArcVisual::DoCreatePropertyMap( Property::Map& map ) const
+{
+  map.Clear();
+  map.Insert( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::ARC );
+  map.Insert( Toolkit::DevelArcVisual::Property::THICKNESS, mThickness );
+  map.Insert( Toolkit::DevelArcVisual::Property::START_ANGLE, mStartAngle );
+  map.Insert( Toolkit::DevelArcVisual::Property::SWEEP_ANGLE, mSweepAngle );
+  map.Insert( Toolkit::DevelArcVisual::Property::CAP, mCapType );
+}
+
+void ArcVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
+{
+  // Do nothing
+}
+
+void ArcVisual::OnSetTransform()
+{
+  Vector2 visualSize = mImpl->mTransform.GetVisualSize( mImpl->mControlSize );
+  mRadius = ( std::min( visualSize.width, visualSize.height ) - mThickness ) / 2.0f;
+
+  if( mImpl->mRenderer )
+  {
+    mImpl->mRenderer.SetProperty( mRadiusIndex, mRadius );
+  }
+}
+
+void ArcVisual::InitializeRenderer()
+{
+  Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY );
+
+  Shader shader;
+  if( mCapType == DevelArcVisual::Cap::BUTT )
+  {
+    shader = mFactoryCache.GetShader( VisualFactoryCache::ARC_BUTT_CAP_SHADER );
+    if( !shader )
+    {
+      shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_BUTT_CAP );
+      mFactoryCache.SaveShader( VisualFactoryCache::ARC_BUTT_CAP_SHADER, shader );
+    }
+  }
+  else
+  {
+    shader = mFactoryCache.GetShader( VisualFactoryCache::ARC_ROUND_CAP_SHADER );
+    if( !shader )
+    {
+      shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_ROUND_CAP );
+      mFactoryCache.SaveShader( VisualFactoryCache::ARC_ROUND_CAP_SHADER, shader );
+    }
+  }
+
+  mImpl->mRenderer = Renderer::New( geometry, shader );
+
+  mImpl->mRenderer.RegisterProperty( THICKNESS_NAME, mThickness );
+  mImpl->mRenderer.RegisterProperty( START_ANGLE_NAME, mStartAngle );
+  mImpl->mRenderer.RegisterProperty( SWEEP_ANGLE_NAME, mSweepAngle );
+  mImpl->mRenderer.RegisterProperty( CAP_NAME, 0.0f );
+
+  mRadiusIndex = mImpl->mRenderer.RegisterProperty( RADIUS_NAME, mRadius );
+
+  mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
+
+  // Register transform properties
+  mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT );
+}
+
+} // namespace Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
diff --git a/dali-toolkit/internal/visuals/arc/arc-visual.h b/dali-toolkit/internal/visuals/arc/arc-visual.h
new file mode 100644 (file)
index 0000000..e9fa083
--- /dev/null
@@ -0,0 +1,137 @@
+#ifndef DALI_TOOLKIT_INTERNAL_ARC_VISUAL_H
+#define DALI_TOOLKIT_INTERNAL_ARC_VISUAL_H
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/common/intrusive-ptr.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/visuals/visual-base-impl.h>
+#include <dali-toolkit/devel-api/visuals/arc-visual-properties-devel.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+class ArcVisual;
+typedef IntrusivePtr< ArcVisual > ArcVisualPtr;
+
+/**
+ * The visual which renders an arc to the control's quad
+ *
+ * The following properties are required for create an ArcVisual
+ *
+ * | %Property Name  | Type        |
+ * |-----------------|-------------|
+ * | THICKNESS       | FLOAT       |
+ * | START_ANGLE     | FLOAT       |
+ * | SWEEP_ANGLE     | FLOAT       |
+ * | CAP             | INTEGER     |
+ */
+class ArcVisual: public Visual::Base
+{
+public:
+
+  /**
+   * @brief Create a new arc visual.
+   *
+   * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
+   * @param[in] properties A Property::Map containing settings for this visual
+   * @return A smart-pointer to the newly allocated visual.
+   */
+  static ArcVisualPtr New( VisualFactoryCache& factoryCache, const Property::Map& properties );
+
+public:  // from Visual
+
+  /**
+   * @copydoc Visual::Base::CreatePropertyMap
+   */
+  void DoCreatePropertyMap( Property::Map& map ) const override;
+
+  /**
+   * @copydoc Visual::Base::CreateInstancePropertyMap
+   */
+  void DoCreateInstancePropertyMap( Property::Map& map ) const override;
+
+protected:
+
+  /**
+   * @brief Constructor.
+   *
+   * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
+   */
+  ArcVisual( VisualFactoryCache& factoryCache );
+
+  /**
+   * @brief A reference counted object may only be deleted by calling Unreference().
+   */
+  virtual ~ArcVisual();
+
+  /**
+   * @copydoc Visual::Base::DoSetProperties
+   */
+  void DoSetProperties( const Property::Map& propertyMap ) override;
+
+  /**
+   * @copydoc Visual::Base::DoSetOnStage
+   */
+  void DoSetOnStage( Actor& actor ) override;
+
+  /**
+   * @copydoc Visual::Base::OnSetTransform
+   */
+  void OnSetTransform() override;
+
+private:
+
+  /**
+   * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
+   */
+  void InitializeRenderer();
+
+private:
+
+  // Undefined
+  ArcVisual( const ArcVisual& arcVisual ) = delete;
+
+  // Undefined
+  ArcVisual& operator=( const ArcVisual& arcVisual ) = delete;
+
+private:
+
+  float mThickness;                    ///< The thickness of the arc.
+  float mRadius;                       ///< The radius of the arc.
+  float mStartAngle;                   ///< The start angle of the arc.
+  float mSweepAngle;                   ///< The sweep angle of the arc.
+  Property::Index mRadiusIndex;        ///< The index of the radius property.
+  DevelArcVisual::Cap::Type mCapType;  ///< The cap type.
+};
+
+} // namespace Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif /* DALI_TOOLKIT_INTERNAL_ARC_VISUAL_H */
index 44b61f5..e3629d3 100644 (file)
@@ -91,7 +91,9 @@ public:
     ANIMATED_GRADIENT_SHADER_RADIAL_USER_REPEAT,
     ANIMATED_GRADIENT_SHADER_RADIAL_USER_CLAMP,
     WIREFRAME_SHADER,
-    SHADER_TYPE_MAX = WIREFRAME_SHADER
+    ARC_BUTT_CAP_SHADER,
+    ARC_ROUND_CAP_SHADER,
+    SHADER_TYPE_MAX = ARC_ROUND_CAP_SHADER
   };
 
   /**
index dcc997b..73c0afc 100644 (file)
@@ -42,6 +42,7 @@
 #include <dali-toolkit/internal/visuals/text/text-visual.h>
 #include <dali-toolkit/internal/visuals/animated-image/animated-image-visual.h>
 #include <dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h>
+#include <dali-toolkit/internal/visuals/arc/arc-visual.h>
 #include <dali-toolkit/internal/visuals/wireframe/wireframe-visual.h>
 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
 #include <dali-toolkit/internal/visuals/visual-url.h>
@@ -275,6 +276,12 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property
       }
       break;
     }
+
+    case Toolkit::DevelVisual::ARC:
+    {
+      visualPtr = ArcVisual::New( GetFactoryCache(), propertyMap );
+      break;
+    }
   }
 
   DALI_LOG_INFO( gLogFilter, Debug::Concise, "VisualFactory::CreateVisual( VisualType:%s %s%s)\n",
index ff07979..4c4f3b1 100644 (file)
@@ -45,6 +45,7 @@ DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Visual, ANIMATED_IMAGE )
 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Visual, WIREFRAME )
 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::DevelVisual, ANIMATED_GRADIENT )
 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::DevelVisual, ANIMATED_VECTOR_IMAGE )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::DevelVisual, ARC )
 DALI_ENUM_TO_STRING_TABLE_END( VISUAL_TYPE )
 
 // Visual Type
@@ -210,6 +211,11 @@ const char * const BEVEL_PERCENTAGE( "bevelPercentage" );
 const char * const BEVEL_SMOOTHNESS( "bevelSmoothness" );
 const char * const LIGHT_POSITION_UNIFORM_NAME( "lightPosition" );
 
+// Arc visual
+const char * const THICKNESS_NAME( "thickness" );
+const char * const START_ANGLE_NAME( "startAngle" );
+const char * const SWEEP_ANGLE_NAME( "sweepAngle" );
+const char * const CAP_NAME( "cap" );
 
 } // namespace Internal
 
index 6959905..c1a13e9 100644 (file)
@@ -195,6 +195,12 @@ extern const char * const BEVEL_PERCENTAGE;
 extern const char * const BEVEL_SMOOTHNESS;
 extern const char * const LIGHT_POSITION_UNIFORM_NAME;
 
+// Arc visual
+extern const char * const THICKNESS_NAME;
+extern const char * const START_ANGLE_NAME;
+extern const char * const SWEEP_ANGLE_NAME;
+extern const char * const CAP_NAME;
+
 } // namespace Internal
 
 } // namespace Toolkit