1. Changed license year
[apps/home/mobileprint.git] / mobileprint / smsc / lib / smsc_control.c
1 /*
2 *  Mobileprint
3 *
4 * Copyright 2013  Samsung Electronics Co., Ltd
5
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
9
10 * http://floralicense.org/license/
11
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.
17 *
18 */
19
20 #include <string.h>
21
22 #include "smsc_debug.h"
23
24 #include "smsc_control.h"
25
26
27 int init_smsc_control(struct smsc_control *control,
28                 struct smsc_position *position)
29 {
30         memset(control, 0, sizeof(struct smsc_control));
31
32         control->position = position;
33
34         control->is_pressed = 0;
35         control->last_x = 0;
36         control->move_anim = NULL;
37         //control->last_y = 0;
38         //control->cur_x = 0;
39         //control->cur_y = 0;
40
41         return 0;
42 }
43
44
45 int smsc_control_remove_animator(struct smsc_control *control)
46 {
47         SMSC_RETV_IF(NULL == control, -1, "Argument error");
48         if (NULL == control->move_anim)
49                 return 0;
50
51         ecore_animator_del(control->move_anim);
52         control->move_anim = NULL;
53
54         return 0;
55 }
56
57
58 int reset_smsc_control(struct smsc_control *control)
59 {
60         control->is_pressed = 0;
61         smsc_control_remove_animator(control);
62         return 0;
63 }
64
65
66 int smsc_control_begin_move(struct smsc_control *control, int xpos)
67 {
68         SMSC_RETV_IF(NULL == control, -1, "Argument error");
69
70         control->is_pressed = 1;
71         control->last_x = xpos;
72
73         SMSC_DEBUG("smsc_control_begin_move()");
74         smsc_control_remove_animator(control);
75
76         return 0;
77 }
78
79
80 int smsc_control_process_move(struct smsc_control *control, int xpos)
81 {
82         int xpos_diff;
83
84         SMSC_RETV_IF(NULL == control, -1, "Argument error");
85
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;
94         }
95
96         return 0;
97 }
98
99
100 static Eina_Bool smsc_control_pagefix_anim(void *data, double pos)
101 {
102         struct smsc_control *control = (struct smsc_control*)data;
103         SMSC_RETV_IF(NULL == control, ECORE_CALLBACK_CANCEL, "Argument error");
104         /* TODO */
105         set_smsc_position(control->position, pos * control->anim_xdiff
106                         + control->anim_initial_offset);
107         return ECORE_CALLBACK_RENEW;
108 }
109
110
111 int smsc_control_finish_move(struct smsc_control *control, int xpos)
112 {
113         int is_ok;
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);
125
126         control->last_x = xpos;
127         control->is_pressed = 0;
128
129         return 0;
130 }
131