Add LCOV remarkers to increase line coverage rate
[platform/core/api/maps-service.git] / src / view / gesture_processor.h
1 /* Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef __MAPS_VIEW_GESTURE_PROCESSOR_H__
17 #define __MAPS_VIEW_GESTURE_PROCESSOR_H__
18
19
20 #include <Ecore.h>
21 #include <Evas.h>
22 #include "maps_view.h"
23 #include "command.h"
24 #include "command_queue.h"
25 #include "runtime_data.h"
26
27
28 /* Select the way of panning: shift center on delta coordinates or move to the
29  * specified central coordinate.
30  * If the following MACRO is defined, the shift is performed
31  */
32 #define _MOVE_CENTER_COMMAND_DEFINED_
33
34
35 //LCOV_EXCL_START
36 namespace view
37 {
38
39         /* The service class, allowing to calculate the zoom and rotation
40          *  changes, caused bu two-finger gesture.
41          *  Briefly speaking, the zoom equals to a current distance between two
42          *  fingers, divided on distance, between two fingers in the begining of
43          *  the gesture.
44          *  The rotation angle is an angle between imaginary lines,
45          *  connecting finger positions on the Map View; first line connects
46          *  finger positions in the beginning of the gesture, while the second
47          *  line connects the current finger positions.
48          */
49         class zoom_calculator {
50         protected:
51                 touch_point _start_tp_f1;
52                 touch_point _cur_tp_f1;
53                 touch_point _start_tp_f2;
54                 touch_point _cur_tp_f2;
55                 double _new_zoom_factor;
56                 double _new_rotation_angle;
57                 bool _zoom_happend;
58                 bool _rotation_happend;
59         public:
60                 zoom_calculator(const touch_point &start_tp_f1,
61                                 const touch_point &cur_tp_f1,
62                                 const touch_point &start_tp_f2,
63                                 const touch_point &cur_tp_f2);
64                 ~zoom_calculator() {}
65         public:
66                 double get_zoom_factor() const
67                 {
68                         return _new_zoom_factor;
69                 }
70                 double get_rotation_angle() const
71                 {
72                         return _new_rotation_angle;
73                 }
74                 bool zoom_happend() const
75                 {
76                         return _zoom_happend;
77                 }
78                 bool rotation_happend() const
79                 {
80                         return _rotation_happend;
81                 }
82         };
83
84
85         /* -------------------------------------------------------------------*/
86
87
88         /* This class prepares and sends session::commands, assigned with a
89          *  gestures.
90          *  Note, it doesn't know how to recognize gestures - it is the
91          *  responsibility of gesture_detector. */
92         class gesture_processor {
93         public:
94                 class gesture_detector *_gd;
95         public:
96                 gesture_processor(class gesture_detector *gd);
97                 ~gesture_processor();
98         public:
99                 void on_long_press();
100                 void on_double_tap();
101                 void on_tap();
102                 void on_two_finger_tap();
103                 void on_pan(int finger_no);
104                 void on_panning_finished(int finger_no);
105                 bool on_zoom(bool zoom_changed, bool rotation_changed, double &zoom_factor);
106                 bool on_rotate(bool zoom_changed, bool rotation_changed, double &rotation_angle);
107                 bool on_two_fingers_pan(bool panning_changed, int *delta_x, int *delta_y);
108                 void on_zoom_rotate(bool zoom_changed, double zoom_factor, bool rotation_changed, double rotation_angle, bool panning_changed, int panning_x, int panning_y);
109         private:
110                 session::command_queue *q();
111                 void *get_maps();
112                 session::command *construct_gesture_command(
113                                                 maps_view_gesture_e gesture,
114                                                 const maps_coordinates_h c,
115                                                 const bool zoom_changed,
116                                                 const double zoom,
117                                                 const bool rotation_changed,
118                                                 const double angle);
119         protected:
120                 touch_point calc_center(const touch_point &tp1, const touch_point &tp2) const;
121                 double calc_angle(const double angle1, const double angle2) const;
122                 double calc_angle(const touch_point tp1, const touch_point tp2) const;
123         };
124
125
126         /* -------------------------------------------------------------------*/
127
128
129         class finger_event_stream {
130         private:
131                 class gesture_detector *_d;
132                 bool _finger_pressed[MAX_FINGERS];
133                 bool _finger_moving[MAX_FINGERS];
134                 touch_point _finger_down[MAX_FINGERS];
135         public:
136                 finger_event_stream(maps_view_h v);
137                 ~finger_event_stream();
138         public:
139
140                 void tap(Evas_Event_Mouse_Down *ev);
141                 void move(Evas_Event_Mouse_Move *ev);
142                 void up(Evas_Event_Mouse_Up *ev);
143                 void multi_tap(Evas_Event_Multi_Down *ev);
144                 void multi_move(Evas_Event_Multi_Move *ev);
145                 void multi_up(Evas_Event_Multi_Up *ev);
146         private:
147                 bool finger_dragged_enough(int finger_no,
148                                            const touch_point &tp);
149         public:
150                 void set_gesture_detector(class gesture_detector *d);
151         };
152 };
153 //LCOV_EXCL_STOP
154
155 #endif                          /* __MAPS_VIEW_GESTURE_PROCESSOR_H__ */