4 * Copyright 2013 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.1 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://floralicense.org/license/
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include "smsc_debug.h"
24 #include "smsc_control.h"
27 int init_smsc_control(struct smsc_control *control,
28 struct smsc_position *position)
30 memset(control, 0, sizeof(struct smsc_control));
32 control->position = position;
34 control->is_pressed = 0;
36 control->move_anim = NULL;
37 //control->last_y = 0;
45 int smsc_control_remove_animator(struct smsc_control *control)
47 SMSC_RETV_IF(NULL == control, -1, "Argument error");
48 if (NULL == control->move_anim)
51 ecore_animator_del(control->move_anim);
52 control->move_anim = NULL;
58 int reset_smsc_control(struct smsc_control *control)
60 control->is_pressed = 0;
61 smsc_control_remove_animator(control);
66 int smsc_control_begin_move(struct smsc_control *control, int xpos)
68 SMSC_RETV_IF(NULL == control, -1, "Argument error");
70 control->is_pressed = 1;
71 control->last_x = xpos;
73 SMSC_DEBUG("smsc_control_begin_move()");
74 smsc_control_remove_animator(control);
80 int smsc_control_process_move(struct smsc_control *control, int xpos)
84 SMSC_RETV_IF(NULL == control, -1, "Argument error");
86 if (control->is_pressed) {
87 xpos_diff = control->last_x - xpos;
88 //int all_width = get_smsc_position_all_width(control->position);
89 /* simple stubbed logic */
90 /* TODO: inertia, fixation */
91 //SMSC_DEBUG("smsc_control_process_move(): moving");
92 move_smsc_position(control->position, xpos_diff);
93 control->last_x = xpos;
100 static Eina_Bool smsc_control_pagefix_anim(void *data, double pos)
102 struct smsc_control *control = (struct smsc_control*)data;
103 SMSC_RETV_IF(NULL == control, ECORE_CALLBACK_CANCEL, "Argument error");
105 set_smsc_position(control->position, pos * control->anim_xdiff
106 + control->anim_initial_offset);
107 return ECORE_CALLBACK_RENEW;
111 int smsc_control_finish_move(struct smsc_control *control, int xpos)
114 SMSC_RETV_IF(NULL == control, -1, "Argument error");
115 SMSC_DEBUG("smsc_control_finish_move()");
116 /* provide page center fixation */
117 /* provide animated fixation */
118 control->anim_xdiff = get_smsc_position_cur_page_center_xdiff(
119 control->position, &is_ok);
120 SMSC_RETV_IF(0 == is_ok, -1, "Current xdiff calculation ERROR");
121 control->anim_initial_offset = control->position->offset;
122 smsc_control_remove_animator(control);
123 control->move_anim = ecore_animator_timeline_add(
124 0.2, smsc_control_pagefix_anim, control);
126 control->last_x = xpos;
127 control->is_pressed = 0;