bbc26f4ba4a20972a11c1ba543cba3ff04321f7a
[platform/core/api/maps-service.git] / src / view / runtime_data.cpp
1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
2  *
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 #include "runtime_data.h"
19 #include "maps_util.h"
20 #include "maps_view_plugin.h"
21 #include <glib.h>
22
23 view::touch_point::touch_point()
24         : _x(0)
25         , _y(0)
26         , _timestamp(0)
27 {
28         reset();
29 }
30
31 view::touch_point::~touch_point()
32 {
33 }
34
35 view::touch_point::touch_point(const int x,
36                                const int y,
37                                const unsigned int ts)
38         : _x(x)
39         , _y(y)
40         , _timestamp(ts)
41 {
42 }
43
44 view::touch_point::touch_point(const touch_point &src)
45         : _x(0)
46         , _y(0)
47         , _timestamp(0)
48 {
49         *this = src;
50 }
51
52 view::touch_point &view::touch_point::operator=(const touch_point &src)
53 {
54         if(this != &src) {
55                 _x = src._x;
56                 _y = src._y;
57                 _timestamp = src._timestamp;
58         }
59         return *this;
60 }
61
62 void view::touch_point::reset()
63 {
64         _x = 0;
65         _y = 0;
66         _timestamp = 0;
67 }
68
69 bool view::touch_point::empty() const
70 {
71         if(_x != 0)
72                 return false;
73         if(_y != 0)
74                 return false;
75         if(_timestamp != 0)
76                 return false;
77         return true;
78 }
79 /* ---------------------------------------------------------------------------*/
80
81
82 view::map_state::map_state()
83         : _center(NULL)
84         , _zoom_factor(.1)
85         , _rotation_angle(.0)
86         , _prev_zoom_factor(.1)
87         , _prev_rotation_angle(.0)
88 {
89         reset();
90 }
91
92 view::map_state::~map_state()
93 {
94         if(_center)
95                 maps_coordinates_destroy(_center);
96         _center = NULL;
97 }
98
99 view::map_state::map_state(const map_state &src)
100         : _center(NULL)
101         , _zoom_factor(.1)
102         , _rotation_angle(.0)
103         , _prev_zoom_factor(.1)
104         , _prev_rotation_angle(.0)
105 {
106         *this = src;
107 }
108
109 view::map_state &view::map_state::operator=(const map_state &src)
110 {
111         if(this != &src) {
112                 reset();
113                 maps_coordinates_clone(src._center, &_center);
114                 _zoom_factor = src._zoom_factor;
115                 _rotation_angle = src._rotation_angle;
116                 _prev_zoom_factor = src._prev_zoom_factor;
117                 _prev_rotation_angle = src._prev_rotation_angle;
118         }
119         return *this;
120 }
121
122 void view::map_state::reset()
123 {
124         if(_center)
125                 maps_coordinates_destroy(_center);
126         _center = NULL;
127
128         _zoom_factor = .1;
129         _rotation_angle = .0;
130         _prev_zoom_factor = .1;
131         _prev_rotation_angle = .0;
132
133 /*
134         MAPS_LOGI("%c[%d;%d;%dm"
135                   "central coordinates: RESET"
136                   "%c[%d;%d;%dm",
137                   0x1B, 1, 0, 31,
138                   0x1B, 0, 0, 0);
139 */
140 }
141
142 void view::map_state::capture(maps_view_h view)
143 {
144         if(!view)
145                 return;
146
147         reset();
148
149         maps_view_get_center(view, &_center);
150         maps_view_get_zoom_factor(view, &_zoom_factor);
151         maps_view_get_orientation(view, &_rotation_angle);
152         _prev_zoom_factor = _zoom_factor;
153         _prev_rotation_angle = _rotation_angle;
154
155         /* DEBUG */
156         maps_coordinates_h central_coords = NULL;
157         maps_view_get_center(view, &central_coords);
158         double lat = .0, lon = .0;
159         maps_coordinates_get_latitude_longitude(central_coords, &lat, &lon);
160         maps_coordinates_destroy(central_coords);
161         MAPS_LOGI("%c[%d;%d;%dm"
162                   "central coordinates: (%f, %f)"
163                   "%c[%d;%d;%dm",
164                   0x1B, 1, 0, 31,
165                   lat, lon,
166                   0x1B, 0, 0, 0);
167 }
168
169 void view::map_state::trace()
170 {
171         double latitude = .0;
172         double longitude = .0;
173         maps_coordinates_get_latitude_longitude(_center, &latitude, &longitude);
174
175         MAPS_LOGI("%c[%d;%d;%dm"
176                   "Map State: center(%f,%f), zoom(%f), angle(%f)"
177                   "%c[%d;%d;%dm",
178                   0x1B, 1, 0, 93,
179                   latitude, longitude, _zoom_factor, _rotation_angle,
180                   0x1B, 0, 0, 0);
181 }
182 /* ---------------------------------------------------------------------------*/
183
184 view::runtime_touch_info::runtime_touch_info()
185         : _fingers_pressed(0)
186           , _cur_gesture(MAPS_VIEW_GESTURE_NONE)
187           /*, _going(false)*/
188 {
189         reset();
190 }
191
192 view::runtime_touch_info::~runtime_touch_info()
193 {
194 }
195
196 view::runtime_touch_info::runtime_touch_info(const runtime_touch_info &src)
197 {
198         *this = src;
199 }
200
201 view::runtime_touch_info &view::runtime_touch_info::operator=(const
202                                                               runtime_touch_info
203                                                               &src)
204 {
205         if(this != &src) {
206                 _fingers_pressed = src._fingers_pressed;
207                 _cur_gesture = src._cur_gesture;
208                 /*_going = src._going;*/
209                 _start_view_state = src._start_view_state;
210
211                 for(unsigned int i = 0; i < MAX_FINGERS; i ++) {
212                         _finger_down[i] = src._finger_down[i];
213                         _finger_move[i] = src._finger_move[i];
214                         _prev_finger_down[i] = src._prev_finger_down[i];
215                         _finger_up[i] = src._finger_up[i];
216                         _is_finger_pressed[i] = src._is_finger_pressed[i];
217                 }
218         }
219         return *this;
220 }
221
222 void view::runtime_touch_info::reset()
223 {
224         /*_going = false;*/
225
226         _fingers_pressed = 0;
227
228         for(unsigned int i = 0; i < MAX_FINGERS; i ++) {
229                 _finger_down[i].reset();
230                 _finger_move[i].reset();
231                 _prev_finger_down[i].reset();
232                 _finger_up[i].reset();
233                 _is_finger_pressed[i] = false;
234         }
235
236         _cur_gesture = MAPS_VIEW_GESTURE_NONE;
237
238         _start_view_state.reset();
239 }
240
241 int view::runtime_touch_info::calc_finger_pressed()
242 {
243         int cnt = 0;
244         for(unsigned int i = 0; i < MAX_FINGERS; i ++)
245                 if(_is_finger_pressed[i])
246                         cnt++;
247         return cnt;
248 }