2 * Copyright (c) 2012 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
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 #include "sclanimator.h"
20 #include "sclanimator-win32.h"
21 #elif defined(__EFL__)
22 #include "sclanimator-efl.h"
23 #elif defined(__NUI__)
24 #include "sclanimator-nui.h"
26 #include "sclanimator-gtk.h"
28 #include "sclanimator-cairo.h"
32 #include "sclevents.h"
33 #include "sclwindows.h"
37 CSCLAnimator::CSCLAnimator()
43 CSCLAnimator::~CSCLAnimator()
53 void CSCLAnimator::init()
55 CSCLAnimatorImpl *impl = get_scl_animator_impl();
61 void CSCLAnimator::fini()
63 CSCLAnimatorImpl *impl = get_scl_animator_impl();
69 sclboolean CSCLAnimator::check_animation_supported()
71 sclboolean ret = FALSE;
73 CSCLAnimatorImpl *impl = get_scl_animator_impl();
75 ret = impl->check_animation_supported();
80 CSCLAnimatorImpl* CSCLAnimator::get_scl_animator_impl()
85 m_impl = new CSCLAnimatorImplWin32;
86 #elif defined(__EFL__)
87 m_impl = new CSCLAnimatorImplEfl;
88 #elif defined(__NUI__)
89 m_impl = new CSCLAnimatorImplNui;
91 m_impl = new CSCLAnimatorImplGtk;
93 m_impl = new CSCLAnimatorImplCairo;
99 CSCLAnimator* CSCLAnimator::get_instance()
101 static CSCLAnimator instance;
106 CSCLAnimator::create_animator(SclAnimationDesc *desc)
108 static sclint animator_id = 0;
112 /* Just in case for overflow */
113 if (animator_id < 0) animator_id = 0;
115 SclAnimationState state;
116 state.active = FALSE;
117 state.rect_cur = desc->rect_from;
122 destroy_animator(animator_id);
123 m_animators[animator_id] = state;
132 CSCLAnimator::destroy_animator(sclint id)
134 sclboolean ret = TRUE;
136 std::map<sclint, SclAnimationState>::iterator iter;
137 iter = m_animators.find(id);
138 if (iter != m_animators.end()) {
139 SclAnimationState *state = &(iter->second);
140 state->active = FALSE;
141 m_animators.erase(iter->first);
146 sclboolean destroy_timer = TRUE;
147 for (iter = m_animators.begin();iter != m_animators.end();std::advance(iter, 1)) {
148 if (iter != m_animators.end()) {
149 SclAnimationState *state = &(iter->second);
151 destroy_timer = FALSE;
157 CSCLEvents *events = CSCLEvents::get_instance();
159 events->destroy_timer(SCL_TIMER_ANIMATION);
167 CSCLAnimator::find_animator_by_type(SCLAnimationType type)
169 sclint ret = NOT_USED;
171 for (std::map<sclint, SclAnimationState>::iterator iter = m_animators.begin();
172 iter != m_animators.end();std::advance(iter, 1)) {
173 if (iter != m_animators.end()) {
174 SclAnimationState *state = &(iter->second);
175 if (state->desc.type == type) {
186 CSCLAnimator::get_animation_state(sclint id)
188 SclAnimationState *ret = NULL;
190 std::map<sclint, SclAnimationState>::iterator iter = m_animators.find(id);
191 if (iter != m_animators.end()) {
192 ret = &(iter->second);
201 CSCLAnimator::start_animator(sclint id)
203 sclboolean ret = TRUE;
205 std::map<sclint, SclAnimationState>::iterator iter = m_animators.find(id);
206 if (iter != m_animators.end()) {
207 SclAnimationState *state = &(iter->second);
208 state->active = TRUE;
214 sclboolean start_timer = TRUE;
215 for(std::map<sclint, SclAnimationState>::iterator iter = m_animators.begin();
216 iter != m_animators.end();std::advance(iter, 1)) {
217 if (iter != m_animators.end()) {
218 SclAnimationState *state = &(iter->second);
226 CSCLEvents *events = CSCLEvents::get_instance();
228 events->create_timer(SCL_TIMER_ANIMATION, SCL_ANIMATION_TIMER_INTERVAL, 0);
232 CSCLEvents *events = CSCLEvents::get_instance();
234 events->destroy_timer(SCL_TIMER_ANIMATION);
235 events->create_timer(SCL_TIMER_ANIMATION, SCL_ANIMATION_TIMER_INTERVAL, 0);
242 CSCLAnimator::stop_animator(sclint id)
244 sclboolean ret = TRUE;
246 std::map<sclint, SclAnimationState>::iterator iter;
247 iter = m_animators.find(id);
248 if (iter != m_animators.end()) {
249 SclAnimationState *state = &(iter->second);
250 state->active = FALSE;
251 m_animators.erase(iter->first);
256 sclboolean destroy_timer = TRUE;
257 for (iter = m_animators.begin();iter != m_animators.end();std::advance(iter, 1)) {
258 if (iter != m_animators.end()) {
259 SclAnimationState *state = &(iter->second);
261 destroy_timer = FALSE;
267 CSCLEvents *events = CSCLEvents::get_instance();
269 events->destroy_timer(SCL_TIMER_ANIMATION);
277 CSCLAnimator::animator_timer_highlight_ui(SclAnimationState *state)
279 sclboolean ret = TRUE;
281 CSCLWindows *windows = CSCLWindows::get_instance();
283 if (state && windows) {
284 SclRectangle rect_from = state->desc.rect_from;
285 SclRectangle rect_to = state->desc.rect_to;
287 sclint delta_x = 0; /* We will calculate the X considering circulation */
288 sclint delta_y = rect_to.y - rect_from.y;
289 sclint delta_width = rect_to.width - rect_from.width;
290 sclint delta_height = rect_to.height - rect_from.height;
292 state->rect_cur.y = rect_from.y +
293 ((delta_y) * state->step * SCL_ANIMATION_TIMER_INTERVAL) / state->desc.length;
294 state->rect_cur.width = rect_from.width +
295 ((delta_width) * state->step * SCL_ANIMATION_TIMER_INTERVAL) / state->desc.length;
296 state->rect_cur.height = rect_from.height +
297 ((delta_height) * state->step * SCL_ANIMATION_TIMER_INTERVAL) / state->desc.length;
299 if (state->desc.circular) {
300 SclWindowContext *base_window_context = windows->get_window_context(windows->get_base_window());
301 if (base_window_context) {
302 if (rect_from.x > rect_to.x) {
304 delta_x += (base_window_context->geometry.width - rect_from.x);
306 delta_x = -(rect_from.x);
307 delta_x -= (base_window_context->geometry.width - rect_to.x);
310 state->rect_cur.x = rect_from.x +
311 ((delta_x) * state->step * SCL_ANIMATION_TIMER_INTERVAL) / state->desc.length;
313 if (state->rect_cur.x + state->rect_cur.width <= 0) {
314 /* Make the highlight UI come out from the right side of the window */
315 state->rect_cur.x += base_window_context->geometry.width;
316 } else if (state->rect_cur.x > base_window_context->geometry.width) {
317 state->rect_cur.x -= base_window_context->geometry.width;
321 delta_x = rect_to.x - rect_from.x;
323 state->rect_cur.x = rect_from.x +
324 ((delta_x) * state->step * SCL_ANIMATION_TIMER_INTERVAL) / state->desc.length;
331 CSCLAnimator::animator_timer()
333 sclboolean destroy_timer = TRUE;
334 for (std::map<sclint, SclAnimationState>::iterator iter = m_animators.begin();
335 iter != m_animators.end();std::advance(iter, 1)) {
336 if (iter != m_animators.end()) {
337 CSCLWindows *windows = CSCLWindows::get_instance();
338 SclAnimationState *state = &(iter->second);
339 if (state && state->active && windows) {
341 if (SCL_ANIMATION_TIMER_INTERVAL * state->step >= state->desc.length) {
342 state->active = FALSE;
344 if (state->desc.type == ANIMATION_TYPE_HIGHLIGHT_UI) {
345 animator_timer_highlight_ui(state);
349 CSCLAnimatorImpl *impl = get_scl_animator_impl();
351 impl->animator_timer(state);
354 if (state->active == FALSE) {
355 windows->update_window(state->desc.window_to,
356 state->desc.rect_to.x, state->desc.rect_to.y,
357 state->desc.rect_to.width, state->desc.rect_to.height);
359 destroy_timer = FALSE;
365 CSCLEvents *events = CSCLEvents::get_instance();
367 events->destroy_timer(SCL_TIMER_ANIMATION);