summaryrefslogtreecommitdiff
path: root/main/src/effect/ivug-effect.c
blob: ea17ee5662285312e6ae698d7fc496aed3422488 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 * Copyright 2012  Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *	  http://www.tizenopensource.org/license
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#include "ivug-common.h"
#include "ivug-effect.h"

#define SIN_TABLE_NUM	91

/* Animation acceleration table */
static const float const EFFECT_SIN_TABLE[SIN_TABLE_NUM] = {
	0.0000f, 0.0174f, 0.0349f, 0.0523f, 0.0698f,
	0.0872f, 0.1045f, 0.1219f, 0.1392f, 0.1564f,
	0.1736f, 0.1908f, 0.2079f, 0.2249f, 0.2419f,
	0.2588f, 0.2756f, 0.2924f, 0.3090f, 0.3256f,
	0.3420f, 0.3584f, 0.3746f, 0.3907f, 0.4067f,
	0.4226f, 0.4384f, 0.4540f, 0.4695f, 0.4848f,
	0.5000f, 0.5150f, 0.5299f, 0.5446f, 0.5592f,
	0.5736f, 0.5878f, 0.6018f, 0.6157f, 0.6293f,
	0.6528f, 0.6561f, 0.6691f, 0.6820f, 0.6947f,
	0.7071f, 0.7193f, 0.7314f, 0.7431f, 0.7547f,
	0.7660f, 0.7772f, 0.7880f, 0.7986f, 0.8090f,
	0.8191f, 0.8290f, 0.8387f, 0.8480f, 0.8571f,
	0.8660f, 0.8746f, 0.8829f, 0.8910f, 0.8988f,
	0.9063f, 0.9135f, 0.9205f, 0.9272f, 0.9336f,
	0.9397f, 0.9455f, 0.9511f, 0.9563f, 0.9613f,
	0.9659f, 0.9703f, 0.9744f, 0.9781f, 0.9816f,
	0.9848f, 0.9877f, 0.9903f, 0.9926f, 0.9945f,
	0.9962f, 0.9976f, 0.9986f, 0.9994f, 0.9998f,
	1.0f
};

#define SLIDESHOW_ANI_TIME (1.0f)


static Eina_Bool
_on_effect_animator(void *data)
{
	IV_ASSERT( data != NULL);
	Effect_Engine *engine = data;

	int value = 0;

	if ( update_animation(engine->anim, ecore_loop_time_get() - engine->t_base, &value) == false ) 	 // If last frame
	{
		engine->animator = NULL;

		MSG_EFFECT_HIGH("Last effect frame. value=%d", value);

		engine->func.animate(engine->eng_data, value);		// Draw last frame.
		// Inform to user.
		if ( engine->pFinishedCB )
		{
			engine->pFinishedCB(engine->ClientData);
		}

		return ECORE_CALLBACK_CANCEL;
	}

	engine->func.animate(engine->eng_data, value);

	return ECORE_CALLBACK_RENEW;
}


bool ivug_effect_init(Effect_Engine *engine, Evas_Object *src, Evas_Object *dst, int w, int h, int rotation)
{
	IV_ASSERT(engine != NULL );

	void *data = engine->func.init(src, dst, w, h, rotation);
	if (data == NULL) {
		MSG_EFFECT_ERROR("init returned data is NULL");

		return false;
	}

	engine->eng_data = data;

	engine->anim = create_animation();
	return true;
}

bool ivug_effect_start(Effect_Engine *engine, FuncFinished pFunc, void *data)
{
	ivug_retvm_if(engine == NULL, false, "engine is NULL");

	IV_ASSERT(engine->func.animate != NULL);
	IV_ASSERT(engine->eng_data != NULL);

// Set up slide show animator
	engine->t_base = ecore_loop_time_get();

	double duration = SLIDESHOW_ANI_TIME;

	if (engine->func.get_duration )
	{
		duration = engine->func.get_duration(engine->eng_data);
	}

	set_animation_type(engine->anim, ANIM_TYPE_LINEAR);
	set_animation(engine->anim, 0, 100, duration);	// 0~100% during 1 seconds

	engine->pFinishedCB = pFunc;
	engine->ClientData = data;

	if (engine->animator == NULL)
	{
		engine->animator = ecore_animator_add(_on_effect_animator, engine);
	}

	return true;
}

bool ivug_effect_pause(Effect_Engine *engine)
{
/* Unused. */
	return true;
}

bool ivug_effect_resume(Effect_Engine *engine)
{
/* Unused. */
	return true;
}

bool ivug_effect_finalize(Effect_Engine *engine)
{
	ivug_retvm_if(engine == NULL, false, "engine is NULL");

	if ( engine->animator )
	{
		ecore_animator_del(engine->animator);
		engine->animator = NULL;
	}

	if (engine->eng_data)
	{
		if (engine->func.finalize)
		{
			MSG_EFFECT_HIGH("finalize");
			engine->func.finalize(engine->eng_data);
		}
		else
		{
			MSG_EFFECT_ERROR("engine->func.finalize is NULL");
		}

		engine->eng_data = NULL;
	}
	else
	{
		MSG_EFFECT_ERROR("engine->eng_data is NULL");
	}

	if ( engine->anim )
	{
		delete_animation(engine->anim);
	}

	free(engine);
	engine = NULL;

	return true;
}

Effect_Engine *ivug_effect_add(Effect_Type type)
{
	Effect_Engine *eng = NULL;

	switch (type) {
	case EFFECT_SLIDE:
		eng = ivug_slide_add();
		break;

	default:
		MSG_EFFECT_ERROR("Unknown effect type=%d", type);
		return NULL;
		break;
	}

	if (eng == NULL)
	{
		MSG_EFFECT_ERROR("Cannot create effect enigne. type=%d", type);
		return NULL;
	}

	return eng;
}