2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.ComponentModel;
20 namespace Tizen.NUI.BaseComponents.VectorGraphics
23 /// Drawable is a object class for drawing a vector primitive.
25 /// <since_tizen> 9 </since_tizen>
26 public class Drawable : BaseHandle
29 /// Creates an initialized drawable.
31 [EditorBrowsable(EditorBrowsableState.Never)]
32 private Drawable() { }
34 internal Drawable(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
39 /// Enumeration indicating the type used in the masking of two objects - the mask drawable and the own drawable.
41 [EditorBrowsable(EditorBrowsableState.Never)]
45 /// The pixels of the own drawable and the mask drawable are alpha blended. As a result, only the part of the own drawable, which intersects with the mask drawable is visible.
49 /// The pixels of the own drawable and the complement to the mask drawable's pixels are alpha blended. As a result, only the part of the own which is not covered by the mask is visible.
55 /// The transparency level [0 ~ 1.0], 0 means totally transparent, while 1 means opaque.
57 /// <since_tizen> 9 </since_tizen>
62 return Interop.Drawable.GetOpacity(BaseHandle.getCPtr(this));
66 Interop.Drawable.SetOpacity(BaseHandle.getCPtr(this), value);
67 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
72 /// The bounding box of the drawable object to which no transformation has been applied.
75 /// The bounding box doesn't indicate the rendering region in the result but primitive region of the object.
78 /// The float type Rectangle class is not ready yet.
79 /// Therefore, it transmits data in Vector4 class.
80 /// This type should later be changed to the appropriate data type.
83 /// Shape shape = new Shape()
85 /// FillColor = new Color(1.0f, 0.0f, 0.0f, 1.0f)
87 /// shape.AddRect(0.0f, 0.0f, 100.0f, 100.0f, 0.0f, 0.0f);
88 /// float boundingBoxX = shape.BoundingBox[0]; // boundingBoxX will be 0.
89 /// float boundingBoxY = shape.BoundingBox[1]; // boundingBoxY will be 0.
90 /// float boundingBoxWidth = shape.BoundingBox[2]; // boundingBoxWidth will be 100.
91 /// float boundingBoxHeight = shape.BoundingBox[3]; // boundingBoxHeight will be 100.
93 [EditorBrowsable(EditorBrowsableState.Never)]
94 public Vector4 BoundingBox
98 global::System.IntPtr cPtr = Interop.Drawable.GetBoundingBox(BaseHandle.getCPtr(this));
99 return Vector4.GetVector4FromPtr(cPtr);
104 /// The intersection with clip drawable is determined and only the resulting pixels from own drawable are rendered.
106 /// <param name="clip">The clip drawable object.</param>
107 /// <exception cref="Exception"> Drawable clpping failed. </exception>
108 /// <exception cref="ArgumentNullException"> Thrown when drawable is null. </exception>
109 [EditorBrowsable(EditorBrowsableState.Never)]
110 public void ClipPath(Drawable clip)
114 throw new ArgumentNullException(nameof(clip));
116 bool ret = Interop.Drawable.SetClipPath(View.getCPtr(this), BaseHandle.getCPtr(clip));
117 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
120 throw new Exception("Drawable clipping failed or clip drawable is already added other drawable or canvas.");
125 /// The pixels of mask drawable and own drawable are blended according to MaskType.
127 /// <param name="mask">The mask drawable object.</param>
128 /// <param name="type">The masking type.</param>
129 /// <exception cref="Exception"> Drawable masking failed. </exception>
130 /// <exception cref="ArgumentNullException"> Thrown when drawable is null. </exception>
131 [EditorBrowsable(EditorBrowsableState.Never)]
132 public void Mask(Drawable mask, MaskType type)
136 throw new ArgumentNullException(nameof(mask));
138 bool ret = Interop.Drawable.SetMask(View.getCPtr(this), BaseHandle.getCPtr(mask), (int)type);
139 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
142 throw new Exception("Drawable masking failed or mask drawable is already added other drawable or canvas.");
147 /// Set the angle of rotation transformation.
149 /// <param name="degree">The degree value of angle.</param>
150 /// <returns>True when it's successful. False otherwise.</returns>
151 /// <since_tizen> 9 </since_tizen>
152 public bool Rotate(float degree)
154 bool ret = Interop.Drawable.Rotate(BaseHandle.getCPtr(this), degree);
155 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160 /// Set the scale value of scale transformation.
162 /// <param name="factor">The scale factor value.</param>
163 /// <returns>True when it's successful. False otherwise.</returns>
164 /// <since_tizen> 9 </since_tizen>
165 public bool Scale(float factor)
167 bool ret = Interop.Drawable.Scale(BaseHandle.getCPtr(this), factor);
168 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173 /// Set the matrix value for affine transform.
175 /// <param name="matrix">The float type array of 3x3 matrix.</param>
176 /// <returns>True when it's successful. False otherwise.</returns>
177 /// <exception cref="ArgumentNullException"> Thrown when matrix is null. </exception>
178 /// <exception cref="ArgumentException"> Thrown when matrix array length is not 9. </exception>
179 /// <since_tizen> 9 </since_tizen>
180 public bool Transform(float[] matrix)
184 throw new ArgumentNullException(nameof(matrix));
186 if (matrix.Length != 9)
188 throw new ArgumentException("matrix array length is not 9.", nameof(matrix));
190 bool ret = Interop.Drawable.Transform(BaseHandle.getCPtr(this), matrix);
191 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196 /// Set the x, y movement value of translate transformation.
198 /// <param name="x">The x-axis movement value.</param>
199 /// <param name="y">The y-axis movement value.</param>
200 /// <returns>True when it's successful. False otherwise.</returns>
201 /// <since_tizen> 9 </since_tizen>
202 public bool Translate(float x, float y)
204 bool ret = Interop.Drawable.Translate(BaseHandle.getCPtr(this), x, y);
205 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();