atspi: remove undefined method
[platform/core/uifw/dali-adaptor.git] / dali / internal / canvas-renderer / tizen / drawable-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/drawable-impl-tizen.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/common/stage.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/public-api/object/type-registry.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 namespace Adaptor
31 {
32 namespace // unnamed namespace
33 {
34 // Type Registration
35 Dali::BaseHandle Create()
36 {
37   return Dali::BaseHandle();
38 }
39
40 Dali::TypeRegistration type(typeid(Dali::CanvasRenderer::Drawable), typeid(Dali::BaseHandle), Create);
41
42 } // unnamed namespace
43
44 DrawableTizen* DrawableTizen::New()
45 {
46   return new DrawableTizen();
47 }
48
49 DrawableTizen::DrawableTizen()
50 : mAdded(false),
51   mChanged(false),
52   mTvgPaint(nullptr)
53 {
54 }
55
56 DrawableTizen::~DrawableTizen()
57 {
58   if(mTvgPaint && !mAdded)
59   {
60     delete mTvgPaint;
61   }
62 }
63
64 bool DrawableTizen::SetOpacity(float opacity)
65 {
66   if(!mTvgPaint)
67   {
68     DALI_LOG_ERROR("Drawable is null [%p]\n", this);
69     return false;
70   }
71   if(mTvgPaint->opacity(round(opacity * 255.f)) != tvg::Result::Success)
72   {
73     DALI_LOG_ERROR("Set opacity fail [%p]\n", this);
74     return false;
75   }
76   SetChanged(true);
77   return true;
78 }
79
80 float DrawableTizen::GetOpacity() const
81 {
82   if(!mTvgPaint)
83   {
84     DALI_LOG_ERROR("Drawable is null [%p]\n", this);
85     return 0;
86   }
87   return (float)mTvgPaint->opacity() / 255.f;
88 }
89
90 bool DrawableTizen::Rotate(Degree degree)
91 {
92   if(!mTvgPaint)
93   {
94     DALI_LOG_ERROR("Drawable is null\n");
95     return false;
96   }
97
98   if(mTvgPaint->rotate(degree.degree) != tvg::Result::Success)
99   {
100     DALI_LOG_ERROR("Rotate fail.\n");
101     return false;
102   }
103   SetChanged(true);
104   return true;
105 }
106
107 bool DrawableTizen::Scale(float factor)
108 {
109   if(!mTvgPaint)
110   {
111     DALI_LOG_ERROR("Drawable is null\n");
112     return false;
113   }
114
115   if(mTvgPaint->scale(factor) != tvg::Result::Success)
116   {
117     DALI_LOG_ERROR("Scale fail.\n");
118     return false;
119   }
120   SetChanged(true);
121   return true;
122 }
123
124 bool DrawableTizen::Translate(Vector2 translate)
125 {
126   if(!mTvgPaint)
127   {
128     DALI_LOG_ERROR("Drawable is null\n");
129     return false;
130   }
131
132   if(mTvgPaint->translate(translate.x, translate.y) != tvg::Result::Success)
133   {
134     DALI_LOG_ERROR("Translate fail.\n");
135     return false;
136   }
137   SetChanged(true);
138   return true;
139 }
140
141 bool DrawableTizen::Transform(const Dali::Matrix3& matrix)
142 {
143   if(!mTvgPaint)
144   {
145     DALI_LOG_ERROR("Drawable is null\n");
146     return false;
147   }
148
149   tvg::Matrix tvgMatrix = {matrix.AsFloat()[0], matrix.AsFloat()[1], matrix.AsFloat()[2], matrix.AsFloat()[3], matrix.AsFloat()[4], matrix.AsFloat()[5], matrix.AsFloat()[6], matrix.AsFloat()[7], matrix.AsFloat()[8]};
150
151   if(mTvgPaint->transform(tvgMatrix) != tvg::Result::Success)
152   {
153     DALI_LOG_ERROR("Transform fail.\n");
154     return false;
155   }
156   SetChanged(true);
157   return true;
158 }
159
160 void DrawableTizen::SetDrawableAdded(bool added)
161 {
162   mAdded = !!added;
163 }
164
165 void* DrawableTizen::GetObject() const
166 {
167   return static_cast<void*>(mTvgPaint);
168 }
169
170 void DrawableTizen::SetObject(const void* object)
171 {
172   if(object)
173   {
174     mTvgPaint = static_cast<tvg::Paint*>((void*)object);
175   }
176   else
177   {
178     if(mAdded)
179     {
180       mTvgPaint = nullptr;
181     }
182     if(mTvgPaint)
183     {
184       delete mTvgPaint;
185     }
186   }
187 }
188
189 void DrawableTizen::SetChanged(bool changed)
190 {
191   if(!mChanged && changed) Dali::Stage::GetCurrent().KeepRendering(0.0f);
192   mChanged = !!changed;
193 }
194
195 bool DrawableTizen::GetChanged() const
196 {
197   return mChanged;
198 }
199 } // namespace Adaptor
200
201 } // namespace Internal
202
203 } // namespace Dali