atspi: remove undefined method
[platform/core/uifw/dali-adaptor.git] / dali / internal / canvas-renderer / tizen / shape-impl-tizen.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/canvas-renderer/tizen/shape-impl-tizen.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/object/type-registry.h>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace Adaptor
30 {
31 namespace // unnamed namespace
32 {
33 // Type Registration
34 Dali::BaseHandle Create()
35 {
36   return Dali::BaseHandle();
37 }
38
39 Dali::TypeRegistration type(typeid(Dali::CanvasRenderer::Shape), typeid(Dali::BaseHandle), Create);
40
41 } // unnamed namespace
42
43 ShapeTizen* ShapeTizen::New()
44 {
45   return new ShapeTizen();
46 }
47
48 ShapeTizen::ShapeTizen()
49 : mTvgShape(nullptr)
50 {
51   Initialize();
52 }
53
54 ShapeTizen::~ShapeTizen()
55 {
56 }
57
58 void ShapeTizen::Initialize()
59 {
60   mTvgShape = tvg::Shape::gen().release();
61   if(!mTvgShape)
62   {
63     DALI_LOG_ERROR("Shape is null [%p]\n", this);
64   }
65
66   Drawable::Create();
67   Drawable::SetObject(static_cast<void*>(mTvgShape));
68 }
69
70 bool ShapeTizen::AddRect(Rect<float> rect, Vector2 roundedCorner)
71 {
72   if(!mTvgShape)
73   {
74     DALI_LOG_ERROR("Shape is null [%p]\n", this);
75     return false;
76   }
77   if(static_cast<tvg::Shape*>(mTvgShape)->appendRect(rect.x, rect.y, rect.width, rect.height, roundedCorner.x, roundedCorner.y) != tvg::Result::Success)
78   {
79     DALI_LOG_ERROR("Add Rect Fail [%p]\n", this);
80     return false;
81   }
82   Drawable::SetChanged(true);
83   return true;
84 }
85
86 bool ShapeTizen::AddCircle(Vector2 center, Vector2 radius)
87 {
88   if(!mTvgShape)
89   {
90     DALI_LOG_ERROR("Shape is null [%p]\n", this);
91     return false;
92   }
93   if(static_cast<tvg::Shape*>(mTvgShape)->appendCircle(center.x, center.y, radius.x, radius.y) != tvg::Result::Success)
94   {
95     DALI_LOG_ERROR("Add Circle Fail [%p]\n", this);
96     return false;
97   }
98   Drawable::SetChanged(true);
99   return true;
100 }
101
102 bool ShapeTizen::AddArc(Vector2 center, float radius, float startAngle, float sweep, bool pie)
103 {
104   if(!mTvgShape)
105   {
106     DALI_LOG_ERROR("Shape is null\n");
107     return false;
108   }
109
110   if(static_cast<tvg::Shape*>(mTvgShape)->appendArc(center.x, center.y, radius, startAngle, sweep, pie) != tvg::Result::Success)
111   {
112     DALI_LOG_ERROR("Add arc fail.\n");
113     return false;
114   }
115   Drawable::SetChanged(true);
116   return true;
117 }
118
119 bool ShapeTizen::AddMoveTo(Vector2 point)
120 {
121   if(!mTvgShape)
122   {
123     DALI_LOG_ERROR("Shape is null\n");
124     return false;
125   }
126
127   if(static_cast<tvg::Shape*>(mTvgShape)->moveTo(point.x, point.y) != tvg::Result::Success)
128   {
129     DALI_LOG_ERROR("AddMoveTo() fail.\n");
130     return false;
131   }
132   Drawable::SetChanged(true);
133   return true;
134 }
135
136 bool ShapeTizen::AddLineTo(Vector2 line)
137 {
138   if(!mTvgShape)
139   {
140     DALI_LOG_ERROR("Shape is null\n");
141     return false;
142   }
143
144   if(static_cast<tvg::Shape*>(mTvgShape)->lineTo(line.x, line.y) != tvg::Result::Success)
145   {
146     DALI_LOG_ERROR("AddLineTo() fail.\n");
147     return false;
148   }
149   Drawable::SetChanged(true);
150   return true;
151 }
152
153 bool ShapeTizen::AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint)
154 {
155   if(!mTvgShape)
156   {
157     DALI_LOG_ERROR("Shape is null\n");
158     return false;
159   }
160
161   if(static_cast<tvg::Shape*>(mTvgShape)->cubicTo(controlPoint1.x, controlPoint1.y, controlPoint2.x, controlPoint2.y, endPoint.x, endPoint.y) != tvg::Result::Success)
162   {
163     DALI_LOG_ERROR("cubicTo() fail.\n");
164     return false;
165   }
166   Drawable::SetChanged(true);
167   return true;
168 }
169
170 bool ShapeTizen::Close()
171 {
172   if(!mTvgShape)
173   {
174     DALI_LOG_ERROR("Shape is null\n");
175     return false;
176   }
177
178   if(static_cast<tvg::Shape*>(mTvgShape)->close() != tvg::Result::Success)
179   {
180     DALI_LOG_ERROR("close() fail.\n");
181     return false;
182   }
183   Drawable::SetChanged(true);
184   return true;
185 }
186
187 bool ShapeTizen::SetFillColor(Vector4 color)
188 {
189   if(!mTvgShape)
190   {
191     DALI_LOG_ERROR("Shape is null [%p]\n", this);
192     return false;
193   }
194
195   if(static_cast<tvg::Shape*>(mTvgShape)->fill((uint8_t)(color.r * 255.f), (uint8_t)(color.g * 255.f), (uint8_t)(color.b * 255.f), (uint8_t)(color.a * 255.f)) != tvg::Result::Success)
196   {
197     DALI_LOG_ERROR("SetFillColor fail [%p]\n", this);
198     return false;
199   }
200   Drawable::SetChanged(true);
201   return true;
202 }
203
204 Vector4 ShapeTizen::GetFillColor() const
205 {
206   if(!mTvgShape)
207   {
208     DALI_LOG_ERROR("Shape is null [%p]\n", this);
209     return Vector4(0, 0, 0, 0);
210   }
211   uint8_t r, g, b, a;
212
213   if(static_cast<tvg::Shape*>(mTvgShape)->fillColor(&r, &g, &b, &a) != tvg::Result::Success)
214   {
215     DALI_LOG_ERROR("GetFillColor fail [%p]\n", this);
216     return Vector4(0, 0, 0, 0);
217   }
218   return Vector4(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
219 }
220
221 bool ShapeTizen::SetFillRule(Dali::CanvasRenderer::Shape::FillRule rule)
222 {
223   if(!mTvgShape)
224   {
225     DALI_LOG_ERROR("Shape is null\n");
226     return false;
227   }
228   if(static_cast<tvg::Shape*>(mTvgShape)->fill(static_cast<tvg::FillRule>(rule)) != tvg::Result::Success)
229   {
230     DALI_LOG_ERROR("SetFillRule fail.\n");
231     return false;
232   }
233   Drawable::SetChanged(true);
234   return true;
235 }
236
237 Dali::CanvasRenderer::Shape::FillRule ShapeTizen::GetFillRule() const
238 {
239   if(!mTvgShape)
240   {
241     DALI_LOG_ERROR("Shape is null\n");
242     return Dali::CanvasRenderer::Shape::FillRule::WINDING;
243   }
244
245   tvg::FillRule rule = static_cast<tvg::Shape*>(mTvgShape)->fillRule();
246
247   return static_cast<Dali::CanvasRenderer::Shape::FillRule>(rule);
248 }
249
250 bool ShapeTizen::SetStrokeWidth(float width)
251 {
252   if(!mTvgShape)
253   {
254     DALI_LOG_ERROR("Shape is null\n");
255     return false;
256   }
257
258   if(static_cast<tvg::Shape*>(mTvgShape)->stroke(width) != tvg::Result::Success)
259   {
260     DALI_LOG_ERROR("SetStrokeWidth fail.\n");
261     return false;
262   }
263   Drawable::SetChanged(true);
264   return true;
265 }
266
267 float ShapeTizen::GetStrokeWidth() const
268 {
269   if(!mTvgShape)
270   {
271     DALI_LOG_ERROR("Shape is null\n");
272     return false;
273   }
274   return static_cast<tvg::Shape*>(mTvgShape)->strokeWidth();
275 }
276
277 bool ShapeTizen::SetStrokeColor(Vector4 color)
278 {
279   if(!mTvgShape)
280   {
281     DALI_LOG_ERROR("Shape is null\n");
282     return false;
283   }
284
285   if(static_cast<tvg::Shape*>(mTvgShape)->stroke(color.r * 255.f, color.g * 255.f, color.b * 255.f, color.a * 255.f) != tvg::Result::Success)
286   {
287     DALI_LOG_ERROR("SetStrokeColor fail.\n");
288     return false;
289   }
290   Drawable::SetChanged(true);
291   return true;
292 }
293
294 Vector4 ShapeTizen::GetStrokeColor() const
295 {
296   if(!mTvgShape)
297   {
298     DALI_LOG_ERROR("Shape is null\n");
299     return Vector4(0, 0, 0, 0);
300   }
301
302   uint8_t r, g, b, a;
303
304   if(static_cast<tvg::Shape*>(mTvgShape)->strokeColor(&r, &g, &b, &a) != tvg::Result::Success)
305   {
306     DALI_LOG_ERROR("GetStrokeColor fail.\n");
307     return Vector4(0, 0, 0, 0);
308   }
309   return Vector4(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
310 }
311
312 bool ShapeTizen::SetStrokeDash(const Dali::Vector<float> dashPattern)
313 {
314   if(!mTvgShape)
315   {
316     DALI_LOG_ERROR("Shape is null\n");
317     return false;
318   }
319
320   float* tvgDashPattern = (float*)alloca(sizeof(float) * dashPattern.Count());
321
322   for(unsigned int i = 0u; i < dashPattern.Count(); ++i)
323   {
324     tvgDashPattern[i] = dashPattern[i];
325   }
326
327   if(static_cast<tvg::Shape*>(mTvgShape)->stroke(tvgDashPattern, dashPattern.Count()) != tvg::Result::Success)
328   {
329     DALI_LOG_ERROR("SetStrokeDash fail.\n");
330     return false;
331   }
332   Drawable::SetChanged(true);
333   return true;
334 }
335
336 Dali::Vector<float> ShapeTizen::GetStrokeDash() const
337 {
338   if(!mTvgShape)
339   {
340     DALI_LOG_ERROR("Shape is null\n");
341     return Vector<float>();
342   }
343   const float* tvgDashPattern = nullptr;
344   uint32_t     count          = 0;
345
346   count = static_cast<tvg::Shape*>(mTvgShape)->strokeDash(&tvgDashPattern);
347   if(!tvgDashPattern || count <= 0)
348   {
349     DALI_LOG_ERROR("GetStrokeDash() fail.\n");
350     return Vector<float>();
351   }
352
353   Dali::Vector<float> dashPattern;
354
355   dashPattern.Reserve(count);
356
357   for(unsigned int i = 0u; i < count; ++i)
358   {
359     dashPattern.PushBack(tvgDashPattern[i]);
360   }
361   return dashPattern;
362 }
363
364 bool ShapeTizen::SetStrokeCap(Dali::CanvasRenderer::Shape::StrokeCap cap)
365 {
366   if(!mTvgShape)
367   {
368     DALI_LOG_ERROR("Shape is null\n");
369     return false;
370   }
371
372   if(static_cast<tvg::Shape*>(mTvgShape)->stroke(static_cast<tvg::StrokeCap>(cap)) != tvg::Result::Success)
373   {
374     DALI_LOG_ERROR("SetStrokeCap fail.\n");
375     return false;
376   }
377   Drawable::SetChanged(true);
378   return true;
379 }
380
381 Dali::CanvasRenderer::Shape::StrokeCap ShapeTizen::GetStrokeCap() const
382 {
383   if(!mTvgShape)
384   {
385     DALI_LOG_ERROR("Shape is null\n");
386     return Dali::CanvasRenderer::Shape::StrokeCap::SQUARE;
387   }
388
389   tvg::StrokeCap cap = static_cast<tvg::Shape*>(mTvgShape)->strokeCap();
390
391   return static_cast<Dali::CanvasRenderer::Shape::StrokeCap>(cap);
392 }
393
394 bool ShapeTizen::SetStrokeJoin(Dali::CanvasRenderer::Shape::StrokeJoin join)
395 {
396   if(!mTvgShape)
397   {
398     DALI_LOG_ERROR("Shape is null\n");
399     return false;
400   }
401
402   if(static_cast<tvg::Shape*>(mTvgShape)->stroke(static_cast<tvg::StrokeJoin>(join)) != tvg::Result::Success)
403   {
404     DALI_LOG_ERROR("SetStrokejoin fail.\n");
405     return false;
406   }
407   Drawable::SetChanged(true);
408   return true;
409 }
410
411 Dali::CanvasRenderer::Shape::StrokeJoin ShapeTizen::GetStrokeJoin() const
412 {
413   if(!mTvgShape)
414   {
415     DALI_LOG_ERROR("Shape is null\n");
416     return Dali::CanvasRenderer::Shape::StrokeJoin::BEVEL;
417   }
418
419   tvg::StrokeJoin join = static_cast<tvg::Shape*>(mTvgShape)->strokeJoin();
420
421   return static_cast<Dali::CanvasRenderer::Shape::StrokeJoin>(join);
422 }
423
424 } // namespace Adaptor
425
426 } // namespace Internal
427
428 } // namespace Dali