1 /* Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __MAPS_VIEW_GESTURE_PROCESSOR_H__
17 #define __MAPS_VIEW_GESTURE_PROCESSOR_H__
22 #include "maps_view.h"
24 #include "command_queue.h"
25 #include "runtime_data.h"
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
32 #define _MOVE_CENTER_COMMAND_DEFINED_
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
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.
49 class zoom_calculator {
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;
58 bool _rotation_happend;
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);
66 double get_zoom_factor() const
68 return _new_zoom_factor;
70 double get_rotation_angle() const
72 return _new_rotation_angle;
74 bool zoom_happend() const
78 bool rotation_happend() const
80 return _rotation_happend;
85 /* -------------------------------------------------------------------*/
88 /* This class prepares and sends session::commands, assigned with a
90 * Note, it doesn't know how to recognize gestures - it is the
91 * responsibility of gesture_detector. */
92 class gesture_processor {
94 class gesture_detector *_gd;
96 gesture_processor(class gesture_detector *gd);
100 void on_double_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);
110 session::command_queue *q();
112 session::command *construct_gesture_command(
113 maps_view_gesture_e gesture,
114 const maps_coordinates_h c,
115 const bool zoom_changed,
117 const bool rotation_changed,
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;
126 /* -------------------------------------------------------------------*/
129 class finger_event_stream {
131 class gesture_detector *_d;
132 bool _finger_pressed[MAX_FINGERS];
133 bool _finger_moving[MAX_FINGERS];
134 touch_point _finger_down[MAX_FINGERS];
136 finger_event_stream(maps_view_h v);
137 ~finger_event_stream();
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);
147 bool finger_dragged_enough(int finger_no,
148 const touch_point &tp);
150 void set_gesture_detector(class gesture_detector *d);
155 #endif /* __MAPS_VIEW_GESTURE_PROCESSOR_H__ */