Merged fixes from SPIN server for gesture events optimization 53/70853/1 accepted/tizen/common/20160524.150350 accepted/tizen/ivi/20160524.094636 accepted/tizen/mobile/20160524.094548 accepted/tizen/tv/20160524.094651 accepted/tizen/wearable/20160524.094557 submit/tizen/20160524.001451
authorchanywa <cbible.kim@samsung.com>
Mon, 23 May 2016 05:12:40 +0000 (14:12 +0900)
committerchanywa <cbible.kim@samsung.com>
Mon, 23 May 2016 05:12:40 +0000 (14:12 +0900)
Change-Id: I859427a9c0825d75512e6ed8b67a9b94f5a6b30a

13 files changed:
src/api/maps_view.cpp
src/api/maps_view_event_data.cpp
src/api/maps_view_object.cpp
src/view/gesture_detector_statemachine.cpp
src/view/gesture_detector_statemachine.h
src/view/gesture_processor.cpp
src/view/gesture_processor.h
src/view/inertial_camera.cpp
src/view/inertial_camera.h
src/view/inertial_gesture.cpp
src/view/inertial_gesture.h
src/view/runtime_data.cpp
src/view/runtime_data.h

index c762931..968157b 100644 (file)
 #include "inertial_gesture.h"
 #include "gesture_detector_statemachine.h"
 
-
-/* TODO: remove useless or duplicative includes */
-
-
 /*
  * The structure of callbacks info, Maps View is invoking during events
  */
@@ -54,8 +50,6 @@ typedef struct _maps_view_idle_listener_info_s {
        void *user_data;
 } maps_view_idle_listener_info_s;
 
-
-
 /*
  * The structure of Maps View internal data
  */
@@ -72,6 +66,7 @@ typedef struct _maps_view_s {
 
        /* Camera inertial transition data */
        view::inertial_camera *inertial_camera;
+       view::inertial_gesture *inertial_gesture;
        maps_view_idle_listener_info_s idle_listener;
 
        /* We'd better to store that values in order to easily limit zoom level
@@ -388,15 +383,20 @@ static Eina_Bool __maps_view_on_idle_cb(void *data)
        if(!v)
                return ECORE_CALLBACK_RENEW; // same as EINA_TRUE
 
-       view::inertial_camera *ic = v->inertial_camera;
-       if(!ic)
-               return ECORE_CALLBACK_RENEW; // same as EINA_TRUE
+       bool is_transiting = false;
+       bool is_continue = false;
 
-       if(v->idle_listener.callback)
-               v->idle_listener.callback(v->idle_listener.user_data);
+       view::inertial_gesture *ig = v->inertial_gesture;
+       if(ig && ig->is_transiting()) {
+               is_transiting |= true;
+               is_continue |= ig->next_transition_step();
+               g_usleep(5*1000);
+       }
 
-       if(ic->is_transiting()) {
-               ic->next_transition_step();
+       view::inertial_camera *ic = v->inertial_camera;
+       if(ic && ic->is_transiting()) {
+               is_transiting |= true;
+               is_continue |= ic->next_transition_step();
                __maps_plugin_render_map(v,
                                         ic->get_cur_center(),
                                         ic->get_cur_zoom_factor(),
@@ -404,6 +404,14 @@ static Eina_Bool __maps_view_on_idle_cb(void *data)
                g_usleep(10*1000);
        }
 
+       if (is_transiting && !is_continue) {
+               maps_view_event_data_h ed = _maps_view_create_event_data(MAPS_VIEW_EVENT_READY);
+               if(ed) {
+                       _maps_view_invoke_event_callback(v, ed);
+                       maps_view_event_data_destroy(ed);
+               }
+       }
+
        return ECORE_CALLBACK_RENEW; // same as EINA_TRUE
 }
 
@@ -1030,36 +1038,47 @@ int _maps_view_set_inertia_enabled(maps_view_h view, bool enabled)
        maps_view_s *v = (maps_view_s *) view;
 
        if(enabled) {
-               if(v->inertial_camera)
-                       return MAPS_ERROR_NONE;
-
-               /* Set Inertial Gesture */
-               v->finger_stream->set_gesture_detector(
-                                       new view::inertial_gesture(view));
-
-               /* Set inertial Camera */
-               v->inertial_camera = new view::inertial_camera(view);
-               if (!v->inertial_camera) {
-                       MAPS_LOGE("OUT_OF_MEMORY(0x%08x)",
-                                 MAPS_ERROR_OUT_OF_MEMORY);
-                       return MAPS_ERROR_OUT_OF_MEMORY;
+               if(!v->inertial_gesture) {      
+                       v->inertial_gesture = new view::inertial_gesture(view);
+                       if (!v->inertial_gesture) {
+                               MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
+                               return MAPS_ERROR_OUT_OF_MEMORY;
+                       }
+               }
+
+               if(!v->inertial_camera) {       
+                       v->inertial_camera = new view::inertial_camera(view);
+                       if (!v->inertial_camera) {
+                               MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
+                               return MAPS_ERROR_OUT_OF_MEMORY;
+                       }
                }
+
+               v->finger_stream->set_gesture_detector(v->inertial_gesture);
        } else {
-               if(!v->inertial_camera)
-                       return MAPS_ERROR_NONE;
+               v->finger_stream->set_gesture_detector(new view::gesture_detector_statemachine(view));
 
-               /* Set Non-Inertial Gesture */
-               v->finger_stream->set_gesture_detector(
-                       new view::gesture_detector_statemachine(view));
+               if(v->inertial_gesture) {
+                       /* Unset Inertial Camera */
+                       if(v->inertial_gesture->is_transiting()) {
+                               v->inertial_gesture->set_transiting(false);
+                               sleep(0);
+                       }
+                       view::inertial_gesture *inertial_gesture = v->inertial_gesture;
+                       v->inertial_gesture = NULL;
+                       delete inertial_gesture;
+               }
 
-               /* Unset Inertial Camera */
-               if(v->inertial_camera->is_transiting()) {
-                       v->inertial_camera->set_transiting(false);
-                       sleep(0);
+               if(v->inertial_camera) {
+                       /* Unset Inertial Camera */
+                       if(v->inertial_camera->is_transiting()) {
+                               v->inertial_camera->set_transiting(false);
+                               sleep(0);
+                       }
+                       view::inertial_camera *inertial_camera = v->inertial_camera;
+                       v->inertial_camera = NULL;
+                       delete inertial_camera;
                }
-               view::inertial_camera *inertial_camera = v->inertial_camera;
-               v->inertial_camera = NULL;
-               delete inertial_camera;
        }
        return MAPS_ERROR_NONE;
 }
index 8444c02..7a86480 100644 (file)
@@ -167,6 +167,8 @@ int _maps_view_event_data_set_center(maps_view_event_data_h event, maps_coordina
        if (!event || !center)
                return MAPS_ERROR_INVALID_PARAMETER;
        maps_view_event_data_s *e = (maps_view_event_data_s *) event;
+       if (e->center)
+               maps_coordinates_destroy(e->center);
        return maps_coordinates_clone(center, &e->center);
 }
 
@@ -287,8 +289,10 @@ EXPORT_API int maps_view_event_data_get_center(const maps_view_event_data_h even
        if (!event || !center)
                return MAPS_ERROR_INVALID_PARAMETER;
        maps_view_event_data_s *e = (maps_view_event_data_s *) event;
-       if((e->event_type != MAPS_VIEW_EVENT_ACTION) && (e->event_type != MAPS_VIEW_EVENT_GESTURE))
+       if (e->event_type != MAPS_VIEW_EVENT_ACTION)
                return MAPS_ERROR_INVALID_PARAMETER;
+       if (!e->center)
+               return MAPS_ERROR_NOT_FOUND;
        return maps_coordinates_clone(e->center, center);
 }
 
@@ -309,7 +313,7 @@ EXPORT_API int maps_view_event_data_get_position(const maps_view_event_data_h ev
        if (!event || !x || !y)
                return MAPS_ERROR_INVALID_PARAMETER;
        maps_view_event_data_s *e = (maps_view_event_data_s *) event;
-       if(e->event_type != MAPS_VIEW_EVENT_GESTURE)
+       if(e->event_type != MAPS_VIEW_EVENT_GESTURE && e->event_type != MAPS_VIEW_EVENT_OBJECT)
                return MAPS_ERROR_INVALID_PARAMETER;
        *x = e->x;
        *y = e->y;
index b2e99ea..2a04d99 100644 (file)
@@ -88,8 +88,7 @@ typedef struct _maps_view_object_s {
 
 } maps_view_object_s;
 
-
-extern int  _maps_view_on_object_operation(maps_view_h view, maps_view_object_h object,        maps_view_object_operation_e operation);
+extern int _maps_view_on_object_operation(maps_view_h view, maps_view_object_h object, maps_view_object_operation_e operation);
 
 static maps_view_h __get_view(const maps_view_object_h object);
 static maps_view_polyline_data_s *__get_polyline_data(const maps_view_object_h object);
index 057cb8c..804db20 100644 (file)
@@ -22,6 +22,8 @@
 view::gesture_detector_statemachine::gesture_detector_statemachine(maps_view_h v)
        : gesture_detector(v)
        , _current_state(STATE_NONE)
+       , is_rotating(false)
+       , is_zoomming(false)
 {
        for(int i = 0; i < MAX_FINGERS; i ++)
                is_panning[i] = false;
@@ -465,6 +467,11 @@ void view::gesture_detector_statemachine::state_machine_on_event(view_event_e ev
        }
 
        case STATE_2FINGERS_PRESSED: {
+               if(event != FINGER_MOVE && event != FINGER2_MOVE) {
+                       finish_zoomming();
+                       finish_rotating();
+               }
+
                switch(event) {
                case FINGER_UP:
                        _current_state = STATE_FINGER2_PRESSED;
@@ -554,10 +561,11 @@ void view::gesture_detector_statemachine::state_machine_on_event(view_event_e ev
        }
 
        case STATE_2FINGERS_MOVING: {
-
-               if((event != FINGER_MOVE) && (event != FINGER2_MOVE))
-                       /* Finish zooming */
+               if(event != FINGER_MOVE && event != FINGER2_MOVE) {
+                       finish_zoomming();
+                       finish_rotating();
                        _info._start_view_state.capture(_view);
+               }
 
                switch(event) {
                case FINGER_MOVE:
@@ -683,7 +691,23 @@ void view::gesture_detector_statemachine::detected_zoom_rotate()
                return;
 
        log("GESTURE ZOOM ROTATE DETECTED", FG_GREEN);
+#if 1
+       bool zoom_changed = false;
+       bool rotation_changed = false;
+       double zoom_factor = .0;
+       double rotation_angle = .0;
+
+       zoom_changed = _gp.on_zoom(is_zoomming, zoom_factor);
+       if (zoom_changed)
+               start_zoomming();
+       rotation_changed = _gp.on_rotate(is_rotating, rotation_angle);
+       if (rotation_changed)
+               start_rotating();
+
+       _gp.on_zoom_rotate(zoom_changed, zoom_factor, rotation_changed, rotation_angle);
+#else
        _gp.on_zoom_rotate();
+#endif
 }
 
 void view::gesture_detector_statemachine::detected_2finger_tap()       /* 2Finger Tap */
index b1a7a98..f93255d 100644 (file)
@@ -89,6 +89,8 @@ namespace view
                detector_states_e _current_state;
 
                bool is_panning[MAX_FINGERS];
+               bool is_rotating;
+               bool is_zoomming;
 
        public:
                gesture_detector_statemachine(maps_view_h v);
@@ -115,6 +117,10 @@ namespace view
        private:
                void start_panning(int finger_no);
                void finish_panning(int finger_no);
+               void start_rotating() { is_rotating = true; }
+               void finish_rotating() { is_rotating = false; }
+               void start_zoomming() { is_zoomming = true; }
+               void finish_zoomming() { is_zoomming = false; }
 
        private:
                void log_state(view_event_e event, detector_states_e state);
index 739006e..91e0acb 100644 (file)
@@ -41,7 +41,6 @@ extern int _maps_view_event_data_set_rotation_angle(maps_view_event_data_h event
 extern maps_view_event_data_h _maps_view_create_event_data(maps_view_event_type_e type);
 extern void _maps_view_invoke_event_callback(maps_view_h view, maps_view_event_data_h event_data);
 
-
 #ifdef _MOVE_CENTER_COMMAND_DEFINED_
 extern int _maps_view_set_center_directly(maps_view_h view, maps_coordinates_h coordinates);
 extern int _maps_view_get_plugin_center(const maps_view_h view, maps_coordinates_h *center);
@@ -257,12 +256,10 @@ void view::gesture_processor::on_long_press()
        if(ed) {
                _maps_view_event_data_set_gesture_type(ed, MAPS_VIEW_GESTURE_LONG_PRESS);
                _maps_view_event_data_set_position(ed, tp._x, tp._y);
-               _maps_view_event_data_set_center(ed, c);
                _maps_view_event_data_set_fingers(ed, 1);
                _maps_view_invoke_event_callback(_gd->_view, ed);
                maps_view_event_data_destroy(ed);
        }
-
        maps_coordinates_destroy(c);
 }
 
@@ -418,9 +415,26 @@ view::touch_point view::gesture_processor::calc_center(
                           timestamp);
 }
 
-void view::gesture_processor::on_zoom_rotate()
+double view::gesture_processor::calc_angle(
+                                               const double angle1,
+                                               const double angle2) const
 {
-       gesture_detector::log("view::gesture_processor::on_zoom_rotate",
+       const double _angle1 = (angle1 >= 0 ? angle1 : angle1 + 360);
+       const double _angle2 = (angle2 >= 0 ? angle2 : angle2 + 360);
+
+       const double angle = (_angle1 > _angle2)
+               ? MIN(_angle1 - _angle2, (360 - angle1) + _angle2)
+               : MIN(_angle2 - _angle1, (360 - angle2) + _angle1);
+       return angle;
+}
+
+bool view::gesture_processor::on_zoom(bool zoom_changed, double &zoom_factor)
+{
+       /* Check if the gesture is available */
+       if (!_maps_view_is_gesture_available(_gd->_view, MAPS_VIEW_GESTURE_ZOOM))
+               return false;
+
+       gesture_detector::log("view::gesture_processor::on_zoom",
                              gesture_detector::FG_LITE_GREEN);
        /* Assumed that we can zoom&rotate using only a pair of fingers */
 
@@ -428,7 +442,6 @@ void view::gesture_processor::on_zoom_rotate()
        const touch_point start_tp_f1 = _gd->_info._finger_down[0];
        const touch_point cur_tp_f1 = _gd->_info._finger_move[0];
 
-
        /* Second finger effective way by now */
        const touch_point start_tp_f2 = _gd->_info._finger_down[1];
        const touch_point cur_tp_f2 = _gd->_info._finger_move[1];
@@ -444,17 +457,16 @@ void view::gesture_processor::on_zoom_rotate()
                  0x1B, 0, 0, 0);
        /***********************/
 
+       /* Calcurating center position */
+       const touch_point start_center = calc_center(start_tp_f1, start_tp_f2);
+       const touch_point cur_center = calc_center(cur_tp_f1, cur_tp_f2);
 
-       /* Calculating the current zoom factor, accordingly to effecitve ways
-        *  of fingers */
+       /* Calculating the current zoom factor, accordingly to effecitve ways of fingers */
        zoom_calculator zc(start_tp_f1, cur_tp_f1, start_tp_f2, cur_tp_f2);
        double new_zoom_factor = zc.get_zoom_factor();
-       double new_rotation_angle = zc.get_rotation_angle();
-
 
        /* Analyse zoom factor changes */
-       bool zoom_changed = false;
-       if(zc.zoom_happend() && _maps_view_is_gesture_available(_gd->_view, MAPS_VIEW_GESTURE_ZOOM)) {
+       if(zc.zoom_happend()) {
                /* Apply newly calculated zoom factor */
                new_zoom_factor += _gd->_info._start_view_state._zoom_factor;
 
@@ -470,87 +482,197 @@ void view::gesture_processor::on_zoom_rotate()
                        new_zoom_factor = max_zoom_level;
 
                /* Check if the zoom changed relatively to initial state */
-               zoom_changed = (_gd->_info._start_view_state._zoom_factor != new_zoom_factor);
+               double diff = _gd->_info._start_view_state._prev_zoom_factor - new_zoom_factor;
+               if ((!zoom_changed && (diff > 0.10 || diff < -0.10)) ||
+                       ( zoom_changed && (diff > 0.02 || diff < -0.02))) {
+                       _gd->_info._start_view_state._prev_zoom_factor = new_zoom_factor;
+                       zoom_changed = true;
+                       MAPS_LOGD("[zoom_changed] %f, %f -> %f",
+                               diff, _gd->_info._start_view_state._prev_zoom_factor, new_zoom_factor);
+               }
+               else
+                       zoom_changed = false;
        }
 
+       if(!zoom_changed)
+               return false;
+
+       zoom_factor = new_zoom_factor;
+       return true;
+}
+
+bool view::gesture_processor::on_rotate(bool rotation_changed, double &rotation_angle)
+{
+       /* Check if the gesture is available */
+       if (!_maps_view_is_gesture_available(_gd->_view, MAPS_VIEW_GESTURE_ROTATE))
+               return false;
+
+       gesture_detector::log("view::gesture_processor::on_zoom",
+                             gesture_detector::FG_LITE_GREEN);
+       /* Assumed that we can zoom&rotate using only a pair of fingers */
+
+       /* First finger effective way by now */
+       const touch_point start_tp_f1 = _gd->_info._finger_down[0];
+       const touch_point cur_tp_f1 = _gd->_info._finger_move[0];
+
+       /* Second finger effective way by now */
+       const touch_point start_tp_f2 = _gd->_info._finger_down[1];
+       const touch_point cur_tp_f2 = _gd->_info._finger_move[1];
+
+       /***********************/
+       MAPS_LOGI("%c[%d;%d;%dm"
+                 "Finger1: start(%d, %d), cur(%d, %d)\t"
+                 "Finger2: start(%d, %d), cur(%d, %d)\t"
+                 "%c[%d;%d;%dm",
+                 0x1B, 1, 0, gesture_detector::FG_YELLOW,
+                 start_tp_f1._x, start_tp_f1._y, cur_tp_f1._x, cur_tp_f1._y,
+                 start_tp_f2._x, start_tp_f2._y, cur_tp_f2._x, cur_tp_f2._y,
+                 0x1B, 0, 0, 0);
+       /***********************/
+
+       /* Calcurating center position */
+       const touch_point start_center = calc_center(start_tp_f1, start_tp_f2);
+       const touch_point cur_center = calc_center(cur_tp_f1, cur_tp_f2);
+
+       /* Calculating the current zoom factor, accordingly to effecitve ways of fingers */
+       zoom_calculator zc(start_tp_f1, cur_tp_f1, start_tp_f2, cur_tp_f2);
+       double new_rotation_angle = zc.get_rotation_angle();
+
        /* Analyze rotation angle changes */
-       bool rotation_changed = false;
-       if(zc.rotation_happend() && _maps_view_is_gesture_available(_gd->_view, MAPS_VIEW_GESTURE_ROTATE)) {
+       if(zc.rotation_happend()) {
                /* Apply newly calculated rotation angle */
-               new_rotation_angle =
-                       _gd->_info._start_view_state._rotation_angle + new_rotation_angle;
+               new_rotation_angle += _gd->_info._start_view_state._rotation_angle;
 
                /* Correct the rotation angle to normalize it
                 *  inside the diapazone of 0..360 degree */
                new_rotation_angle -= 360. * (int(new_rotation_angle) / 360);
                new_rotation_angle += 360. * (int(new_rotation_angle) / 360);
 
-               /* Check if the angle changed relatively to initial state */
-               rotation_changed = (_gd->_info._start_view_state._rotation_angle != new_rotation_angle);
+               /* Check if the zoom changed relatively to initial state */
+               double diff = calc_angle(_gd->_info._start_view_state._prev_rotation_angle, new_rotation_angle);
+               if ((!rotation_changed && (diff > 4.0 || diff < -4.0)) ||
+                       ( rotation_changed && (diff > 0.5 || diff < -0.5))) {
+                       _gd->_info._start_view_state._prev_rotation_angle = new_rotation_angle;
+                       rotation_changed = true;
+                       MAPS_LOGD("[rotation_changed] %f, %f -> %f",
+                               diff, _gd->_info._start_view_state._prev_rotation_angle, new_rotation_angle);
+               }
+               else
+                       rotation_changed = false;
        }
 
-       /* Invoke user registered event callback for ZOOM */
-       do {
-               if(!zoom_changed)
-                       break;
-               maps_view_event_data_h ed = _maps_view_create_event_data(MAPS_VIEW_EVENT_GESTURE);
-               if(!ed)
-                       break;
-               _maps_view_event_data_set_gesture_type(ed, MAPS_VIEW_GESTURE_ZOOM);
-               _maps_view_event_data_set_zoom_factor(ed, new_zoom_factor);
-               _maps_view_event_data_set_fingers(ed, 2);
+       if(!rotation_changed)
+               return false; // Seems nothing changed, we can return
 
-               /* Find the current center of the gesture */
-               const touch_point cur_center = calc_center(cur_tp_f1, cur_tp_f2);
-               _maps_view_event_data_set_position(ed, cur_center._x, cur_center._y);
-               _maps_view_invoke_event_callback(_gd->_view, ed);
-               maps_view_event_data_destroy(ed);
-       } while(false);
+       rotation_angle = new_rotation_angle;
+       return true;
+}
 
-       /* Invoke user registered event callback for ROTATION */
-       do {
-               if(rotation_changed)
-                       break;
-               maps_view_event_data_h ed = _maps_view_create_event_data(MAPS_VIEW_EVENT_GESTURE);
-               if(!ed)
-                       break;
-               _maps_view_event_data_set_gesture_type(ed, MAPS_VIEW_GESTURE_ROTATE);
-               _maps_view_event_data_set_rotation_angle(ed, new_rotation_angle);
-               _maps_view_event_data_set_fingers(ed, 2);
+void view::gesture_processor::on_zoom_rotate(bool zoom_changed, double zoom_factor, bool rotation_changed, double rotation_angle)
+{
+#if 1
+       const touch_point start_tp_f1 = _gd->_info._finger_down[0];
+       const touch_point cur_tp_f1 = _gd->_info._finger_move[0];
 
-               /* Find the current center of the gesture */
-               const touch_point cur_center = calc_center(cur_tp_f1, cur_tp_f2);
-               _maps_view_event_data_set_position(ed, cur_center._x, cur_center._y);
-               _maps_view_invoke_event_callback(_gd->_view, ed);
-               maps_view_event_data_destroy(ed);
-       } while(false);
+       /* Second finger effective way by now */
+       const touch_point start_tp_f2 = _gd->_info._finger_down[1];
+       const touch_point cur_tp_f2 = _gd->_info._finger_move[1];
 
+       /* Calcurating center position */
+       const touch_point start_center = calc_center(start_tp_f1, start_tp_f2);
+       const touch_point cur_center = calc_center(cur_tp_f1, cur_tp_f2);
 
-       if(!zoom_changed && !rotation_changed)
-               return; // Seems nothing changed, we can return
+       /* a. Find delta in screen coordinates */
+       const int delta_x = cur_center._x - start_center._x;
+       const int delta_y = cur_center._y - start_center._y;
 
-       /* Ignore center move if zoom is not available */
-       const bool movable_center =
-               _maps_view_is_gesture_available(_gd->_view, MAPS_VIEW_GESTURE_ZOOM);
-       if(!movable_center) {
-               q()->push(construct_gesture_command(MAPS_VIEW_GESTURE_ZOOM,
-                       NULL, zoom_changed, new_zoom_factor, rotation_changed, new_rotation_angle));
-               return;
+       /* b. Get the initial screen coordinates of the center */
+       int center_x = 0;
+       int center_y = 0;
+       double lat, lon;
+       maps_coordinates_get_latitude_longitude(_gd->_info._start_view_state._center, &lat, &lon);
+       maps_view_geolocation_to_screen(_gd->_view, _gd->_info._start_view_state._center, &center_x, &center_y);
+
+       /* c. Apply the delta to the intital center coordinates */
+       center_x -= delta_x;
+       center_y -= delta_y;
+
+       /* d. Send event data */
+       maps_coordinates_h center = NULL;
+       maps_view_screen_to_geolocation(_gd->_view, center_x, center_y, &center);
+
+#if 1
+       if (zoom_changed || rotation_changed) {
+               maps_view_event_data_h ed = _maps_view_create_event_data(MAPS_VIEW_EVENT_GESTURE);
+               if (ed) {
+                       _maps_view_event_data_set_position(ed, cur_center._x, cur_center._y);
+                       _maps_view_event_data_set_fingers(ed, 2);
+
+                       if (zoom_changed) {
+                               _maps_view_event_data_set_gesture_type(ed, MAPS_VIEW_GESTURE_ZOOM);
+                               _maps_view_event_data_set_zoom_factor(ed, zoom_factor);
+                               _maps_view_event_data_set_rotation_angle(ed, 0.);
+                               _maps_view_invoke_event_callback(_gd->_view, ed);
+                       }
+                       if (rotation_changed) {
+                               _maps_view_event_data_set_gesture_type(ed, MAPS_VIEW_GESTURE_ROTATE);
+                               _maps_view_event_data_set_zoom_factor(ed, 0.);
+                               _maps_view_event_data_set_rotation_angle(ed, rotation_angle);
+                               _maps_view_invoke_event_callback(_gd->_view, ed);
+                       }
+                       maps_view_event_data_destroy(ed);                               
+               }
+       }
+#else
+       if (zoom_changed) {
+               maps_view_event_data_h ed = _maps_view_create_event_data(MAPS_VIEW_EVENT_GESTURE);
+               if (ed) {
+                       _maps_view_event_data_set_gesture_type(ed, MAPS_VIEW_GESTURE_ZOOM);
+                       _maps_view_event_data_set_position(ed, cur_center._x, cur_center._y);
+                       _maps_view_event_data_set_fingers(ed, 2);
+                       _maps_view_event_data_set_zoom_factor(ed, zoom_factor);
+                       _maps_view_event_data_set_rotation_angle(ed, rotation_angle);
+                       _maps_view_invoke_event_callback(_gd->_view, ed);
+                       maps_view_event_data_destroy(ed);
+               }
+       }
+
+       if (rotation_changed) {
+               maps_view_event_data_h ed = _maps_view_create_event_data(MAPS_VIEW_EVENT_GESTURE);
+               if (ed) {
+                       _maps_view_event_data_set_gesture_type(ed, MAPS_VIEW_GESTURE_ROTATE);
+                       _maps_view_event_data_set_position(ed, cur_center._x, cur_center._y);
+                       _maps_view_event_data_set_fingers(ed, 2);
+                       _maps_view_event_data_set_zoom_factor(ed, zoom_factor);
+                       _maps_view_event_data_set_rotation_angle(ed, rotation_angle);
+                       _maps_view_invoke_event_callback(_gd->_view, ed);
+                       maps_view_event_data_destroy(ed);
+               }
        }
+#endif
 
+       /* e. Enque the command to move the center */
+       q()->push(new session::command_view_set_center(get_maps(), _gd->_view, center));
 
-       /* Shift center accordingly to performed zoom and/or rotation:
-        *  - get the original gesture center coordinates
-        *  - get the current gesture center coordinates
-        *  - calculate the coordinates delta
-        *  - move map center to the opposite value of this delta
-        *  Now we have a map, perfectly responding to the
-        *  double finger zoom and/or rotate action */
+       /* f. Enqueue the detected zomm command */
+       maps_view_gesture_e gesture = (zoom_changed ? MAPS_VIEW_GESTURE_ZOOM : MAPS_VIEW_GESTURE_ROTATE);
+       q()->push(construct_gesture_command(gesture, center,
+               zoom_changed, zoom_factor, rotation_changed, rotation_angle));
 
+       maps_coordinates_destroy(center);
+#else
+       const touch_point start_tp_f1 = _gd->_info._finger_down[0];
+       const touch_point cur_tp_f1 = _gd->_info._finger_move[0];
 
-       /* a. Find delta in screen coordinates */
+       /* Second finger effective way by now */
+       const touch_point start_tp_f2 = _gd->_info._finger_down[1];
+       const touch_point cur_tp_f2 = _gd->_info._finger_move[1];
+
+       /* Calcurating center position */
        const touch_point start_center = calc_center(start_tp_f1, start_tp_f2);
        const touch_point cur_center = calc_center(cur_tp_f1, cur_tp_f2);
+
+       /* a. Find delta in screen coordinates */
        const int delta_x = cur_center._x - start_center._x;
        const int delta_y = cur_center._y - start_center._y;
 
@@ -574,10 +696,12 @@ void view::gesture_processor::on_zoom_rotate()
        q()->push(new session::command_view_set_center(get_maps(), _gd->_view, new_center));
 
        /* f. Enqueue the detected zomm command */
-       q()->push(construct_gesture_command(MAPS_VIEW_GESTURE_ZOOM,
-               new_center, zoom_changed, new_zoom_factor, rotation_changed, new_rotation_angle));
+       maps_view_gesture_e gesture = (zoom_changed ? MAPS_VIEW_GESTURE_ZOOM : MAPS_VIEW_GESTURE_ROTATE);
+       q()->push(construct_gesture_command(gesture, new_center,
+               zoom_changed, zoom_factor, rotation_changed, rotation_angle));
 
        maps_coordinates_destroy(new_center);
+#endif
 }
 
 
index c4b6c10..b8a1255 100644 (file)
@@ -101,7 +101,9 @@ namespace view
                void on_two_finger_tap();
                void on_pan(int finger_no);
                void on_panning_finished(int finger_no);
-               void on_zoom_rotate();
+               bool on_zoom(bool zoom_changed, double &zoom_factor);
+               bool on_rotate(bool rotation_changed, double &rotation_angle);
+               void on_zoom_rotate(bool zoom_changed, double zoom_factor, bool rotation_changed, double rotation_angle);
        private:
                session::command_queue *q();
                void *get_maps();
@@ -115,6 +117,8 @@ namespace view
        protected:
                touch_point calc_center(const touch_point &tp1,
                                                const touch_point &tp2) const;
+               double calc_angle(const double angle1,
+                                               const double angle2) const;
        };
 
 
index 95624b1..a9e3486 100644 (file)
@@ -162,10 +162,10 @@ double view::inertial_camera::calc_next_step(const double &start,
        return new_pos;
 }
 
-void view::inertial_camera::next_transition_step()
+bool view::inertial_camera::next_transition_step()
 {
        if(!_view)
-               return;
+               return false;
 
        transiting = false;
 
@@ -216,4 +216,6 @@ void view::inertial_camera::next_transition_step()
                transiting = true;
        else
                cur_rotation_angle = target_rotation_angle;
+
+       return transiting;
 }
index f2addcf..a412f4d 100644 (file)
@@ -55,7 +55,7 @@ namespace view
                void set_zoom_target(const double &zoom_factor);
                void set_rotation_target(const double &rotation_angle);
 
-               void next_transition_step();
+               bool next_transition_step();
 
                bool is_transiting() const { return transiting; }
                void set_transiting(bool b) { transiting = b; }
index 8738790..e036902 100644 (file)
@@ -37,12 +37,12 @@ view::inertial_gesture::inertial_gesture(maps_view_h view)
 
        _d = new gesture_detector_statemachine(view);
 
-       _maps_view_set_idle_listener(view, on_idle, this);
+       //_maps_view_set_idle_listener(view, on_idle, this);
 }
 
 view::inertial_gesture::~inertial_gesture()
 {
-       _maps_view_set_idle_listener(_view, NULL, NULL);
+       //_maps_view_set_idle_listener(_view, NULL, NULL);
 
        if(_d)
                delete _d;
@@ -140,7 +140,7 @@ void view::inertial_gesture::up(int finger_no, const touch_point &tp)
        transiting = true;
 }
 
-void view::inertial_gesture::next_transition_step()
+bool view::inertial_gesture::next_transition_step()
 {
        MAPS_LOGI("TRANSITION get next transition step");
        transiting = false;
@@ -193,6 +193,8 @@ void view::inertial_gesture::next_transition_step()
 
        if(!transiting)
                reset();
+
+       return transiting;
 }
 
 double view::inertial_gesture::get_next_point(const double &start,
@@ -234,6 +236,7 @@ unsigned int view::inertial_gesture::get_transition_time(int finger_no) const
        return get_cur_time() - transiting_start[finger_no];
 }
 
+/*
 void view::inertial_gesture::on_idle(void *data)
 {
        inertial_gesture *ig = (inertial_gesture *)data;
@@ -243,6 +246,7 @@ void view::inertial_gesture::on_idle(void *data)
                g_usleep(5*1000);
        }
 }
+*/
 
 void view::inertial_gesture::reset()
 {
index 1112d89..289cba7 100644 (file)
@@ -47,10 +47,13 @@ namespace view
                virtual void tap(int finger_no, const touch_point &tp);
                virtual void move(int finger_no, const touch_point &tp);
                virtual void up(int finger_no, const touch_point &tp);
+
+               bool is_transiting() const { return transiting; }
+               void set_transiting(bool b) { transiting = b; }
+               bool next_transition_step();
        public:
-               static void on_idle(void *data);
+               //static void on_idle(void *data);
        protected:
-               void next_transition_step();
                double get_next_point(const double &start,
                                      const double &derivative,
                                      const double &dt);
index ab6dcc7..b23e918 100644 (file)
@@ -84,6 +84,8 @@ view::map_state::map_state()
        : _center(NULL)
        , _zoom_factor(.1)
        , _rotation_angle(.0)
+       , _prev_zoom_factor(.1)
+       , _prev_rotation_angle(.0)
 {
        reset();
 }
@@ -99,6 +101,8 @@ view::map_state::map_state(const map_state &src)
        : _center(NULL)
        , _zoom_factor(.1)
        , _rotation_angle(.0)
+       , _prev_zoom_factor(.1)
+       , _prev_rotation_angle(.0)
 {
        *this = src;
 }
@@ -110,6 +114,8 @@ view::map_state &view::map_state::operator=(const map_state &src)
                maps_coordinates_clone(src._center, &_center);
                _zoom_factor = src._zoom_factor;
                _rotation_angle = src._rotation_angle;
+               _prev_zoom_factor = src._prev_zoom_factor;
+               _prev_rotation_angle = src._prev_rotation_angle;
        }
        return *this;
 }
@@ -122,6 +128,8 @@ void view::map_state::reset()
 
        _zoom_factor = .1;
        _rotation_angle = .0;
+       _prev_zoom_factor = .1;
+       _prev_rotation_angle = .0;
 
        MAPS_LOGI("%c[%d;%d;%dm"
                  "central coordinates: RESET"
@@ -140,7 +148,8 @@ void view::map_state::capture(maps_view_h view)
        maps_view_get_center(view, &_center);
        maps_view_get_zoom_factor(view, &_zoom_factor);
        maps_view_get_orientation(view, &_rotation_angle);
-
+       _prev_zoom_factor = _zoom_factor;
+       _prev_rotation_angle = _rotation_angle;
 
        /* DEBUG */
        maps_coordinates_h central_coords = NULL;
index 741c8b9..8654346 100644 (file)
@@ -53,6 +53,8 @@ namespace view
                maps_coordinates_h _center;
                double _zoom_factor;
                double _rotation_angle;
+               double _prev_zoom_factor;
+               double _prev_rotation_angle;
        public:
                map_state();
                map_state(const map_state &src);