Rotation High Level Class support in C#
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / dali-operator.i
index 9554651..29ed172 100644 (file)
@@ -38,7 +38,7 @@
   public static Vector2 operator+(Vector2 arg1, Vector2 arg2) {
     return arg1.Add(arg2);
   }
-  
+
   public static Vector2 operator-(Vector2 arg1, Vector2 arg2) {
     return arg1.Subtract(arg2);
   }
       return ValueOfIndex(index);
     }
   }
+
+  public static Vector2 GetVector2FromPtr(global::System.IntPtr cPtr) {
+    Vector2 ret = new Vector2(cPtr, false);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+       return ret;
+  }
+
 %}
 
 %typemap(cscode) Dali::Vector3 %{
   public static Vector3 operator+(Vector3 arg1, Vector3 arg2) {
     return arg1.Add(arg2);
   }
-  
+
   public static Vector3 operator-(Vector3 arg1, Vector3 arg2) {
     return arg1.Subtract(arg2);
   }
       return ValueOfIndex(index);
     }
   }
+
+  public static Vector3 GetVector3FromPtr(global::System.IntPtr cPtr) {
+    Vector3 ret = new Vector3(cPtr, false);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+       return ret;
+  }
+
 %}
 
 %typemap(cscode) Dali::Vector4 %{
   public static Vector4 operator+(Vector4 arg1, Vector4 arg2) {
     return arg1.Add(arg2);
   }
-  
+
   public static Vector4 operator-(Vector4 arg1, Vector4 arg2) {
     return arg1.Subtract(arg2);
   }
       return ValueOfIndex(index);
     }
   }
+
+  public static Vector4 GetVector4FromPtr(global::System.IntPtr cPtr) {
+    Vector4 ret = new Vector4(cPtr, false);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+       return ret;
+  }
+
 %}
 
 %typemap(cscode) Dali::Matrix %{
 %}
 
 %typemap(cscode) Dali::Quaternion %{
-  public static Quaternion operator+(Quaternion arg1, Quaternion arg2) {
+  public static Rotation operator+(Rotation arg1, Rotation arg2) {
     return arg1.Add(arg2);
   }
-  
-  public static Quaternion operator-(Quaternion arg1, Quaternion arg2) {
+
+  public static Rotation operator-(Rotation arg1, Rotation arg2) {
     return arg1.Subtract(arg2);
   }
 
-  public static Quaternion operator-(Quaternion arg1) {
+  public static Rotation operator-(Rotation arg1) {
     return arg1.Subtract();
   }
 
-  public static Quaternion operator*(Quaternion arg1, Quaternion arg2) {
+  public static Rotation operator*(Rotation arg1, Rotation arg2) {
     return arg1.Multiply(arg2);
   }
 
-  public static Vector3 operator*(Quaternion arg1, Vector3 arg2) {
+  public static Vector3 operator*(Rotation arg1, Vector3 arg2) {
     return arg1.Multiply(arg2);
   }
 
-  public static Quaternion operator*(Quaternion arg1, float arg2) {
+  public static Rotation operator*(Rotation arg1, float arg2) {
     return arg1.Multiply(arg2);
   }
 
-  public static Quaternion operator/(Quaternion arg1, Quaternion arg2) {
+  public static Rotation operator/(Rotation arg1, Rotation arg2) {
     return arg1.Divide(arg2);
   }
 
-  public static Quaternion operator/(Quaternion arg1, float arg2) {
+  public static Rotation operator/(Rotation arg1, float arg2) {
     return arg1.Divide(arg2);
   }
 %}
   public static bool operator<(Uint16Pair arg1, Uint16Pair arg2) {
     return arg1.LessThan(arg2);
   }
-  
+
   public static bool operator>(Uint16Pair arg1, Uint16Pair arg2) {
     return arg1.GreaterThan(arg2);
   }
 %}
 
 /**
  * This is because from C# we can't wrap the operator BooleanType() function
  */
 %extend Dali::BaseHandle {
-   bool IsHandleEmpty() const {
+   bool HasBody() const {
+
+     // C++ code. DALi uses Handle <-> Body design pattern.
+     // This function checks the Handle to see if it has a body attached ( possible to have empty handles).
+     // Handles in DALi can be converted into a boolean type
+     // to check if the handle has a valid body attached to it.
+     // Internally checking *$self will  checks IntrusivePtr<Dali::RefObject> mObjectHandle in BaseHandle;
      if( *$self )
      {
        return true;
        return false;
      }
     }
+
+     // Check if two handles point to the same body / ref-object.
+     bool IsEqual( const BaseHandle& rhs ) const {
+
+     // C++ code. Check if two handles reference the same implemtion
+     if( *$self == rhs)
+     {
+       return true;
+     }
+     else
+     {
+       return false;
+     }
+    }
+
 };
 
 /**
  */
 %typemap(cscode) Dali::BaseHandle %{
 
- public static bool operator true(BaseHandle  handle)
- {
-   if( handle!= null  )
-   {
-     return  handle.IsHandleEmpty();
-   }
-   else
-   {
-     return false;
-   }
- }
- public static bool operator false(BaseHandle  handle)
- {
-   return  handle.IsHandleEmpty();
- }
-%}
+  // Returns the bool value true to indicate that an operand is true and returns false otherwise.
+  public static bool operator true(BaseHandle handle)
+  {
+    // if the C# object is null, return false
+    if( BaseHandle.ReferenceEquals( handle, null ) )
+    {
+      return false;
+    }
+    // returns true if the handle has a body, false otherwise
+    return handle.HasBody();
+  }
+
+  // Returns the bool false  to indicate that an operand is false and returns true otherwise.
+  public static bool operator false(BaseHandle  handle)
+  {
+    // if the C# object is null, return true
+    if( BaseHandle.ReferenceEquals( handle, null ) )
+    {
+      return true;
+    }
+    return !handle.HasBody();
+  }
+
+  // Explicit conversion from Handle to bool.
+  public static explicit operator bool(BaseHandle handle)
+  {
+     // if the C# object is null, return false
+    if( BaseHandle.ReferenceEquals( handle, null ) )
+    {
+      return false;
+    }
+    // returns true if the handle has a body, false otherwise
+    return handle.HasBody();
+  }
+
+  // Equality operator
+  public static bool operator == (BaseHandle x, BaseHandle y)
+  {
+    // if the C# objects are the same return true
+    if(  BaseHandle.ReferenceEquals( x, y ) )
+    {
+      return true;
+    }
+    if ( !BaseHandle.ReferenceEquals( x, null ) && !BaseHandle.ReferenceEquals( y, null ) )
+    {
+      // drop into native code to see if both handles point to the same body
+      return x.IsEqual( y) ;
+    }
+    return false;
+
+  }
+
+  // Inequality operator. Returns Null if either operand is Null
+  public static bool operator !=(BaseHandle x, BaseHandle y)
+  {
+    return !(x==y);
+  }
 
+  // Logical AND operator for &&
+  // It's possible when doing a && this function (opBitwiseAnd) is never called due
+  // to short circuiting. E.g.
+  // If you perform x && y What actually is called is
+  // BaseHandle.op_False( x ) ? BaseHandle.op_True( x ) : BaseHandle.opTrue( BaseHandle.opBitwiseAnd(x,y) )
+  //
+  public static BaseHandle operator &(BaseHandle x, BaseHandle y)
+  {
+    if( x == y )
+    {
+      return x;
+    }
+    return null;
+  }
+
+  // Logical OR operator for ||
+  // It's possible when doing a || this function (opBitwiseOr) is never called due
+  // to short circuiting. E.g.
+  // If you perform x || y What actually is called is
+  // BaseHandle.op_True( x ) ? BaseHandle.op_True( x ) : BaseHandle.opTrue( BaseHandle.opBitwiseOr(x,y) )
+  public static BaseHandle operator |(BaseHandle x, BaseHandle y)
+  {
+    if ( !BaseHandle.ReferenceEquals( x, null ) || !BaseHandle.ReferenceEquals( y, null ) )
+    {
+       if( x.HasBody() )
+       {
+         return x;
+       }
+       if( y.HasBody() )
+       {
+         return y;
+       }
+       return null;
+    }
+    return null;
+  }
+
+  // Logical ! operator
+  public static bool operator !(BaseHandle x)
+  {
+    // if the C# object is null, return true
+    if( BaseHandle.ReferenceEquals( x, null ) )
+    {
+      return true;
+    }
+    if( x.HasBody() )
+    {
+      return false;
+    }
+    return true;
+  }
 
+%}
\ No newline at end of file