Ejemplo n.º 1
0
void
GestureManager::Update(int x, int y)
{
  // Calculate deltas
  int dx = x - drag_last.x;
  int dy = y - drag_last.y;

  // See if we've reached the threshold already
  if (compare_squared(dx, dy, threshold) != 1)
    return;

  // Save position for next call
  drag_last.x = x;
  drag_last.y = y;

  // Get current dragging direction
  char direction = getDirection(dx, dy);

  // Return if we are in an unclear direction
  if (direction == '\0')
    return;

  // Return if we are still in the same direction
  size_t length = strlen(gesture);
  if (length < sizeof(gesture) / sizeof(gesture[0]) - 1 &&
      gesture[length - 1] != direction) {
    gesture[length] = direction;
    gesture[length + 1] = '\0';
  }
}
Ejemplo n.º 2
0
void
GestureManager::Update(PixelScalar x, PixelScalar y)
{
  // Calculate deltas
  int dx = x - drag_last.x;
  int dy = y - drag_last.y;

  // See if we've reached the threshold already
  if (compare_squared(dx, dy, threshold) != 1)
    return;

  // Save position for next call
  drag_last.x = x;
  drag_last.y = y;

  // Get current dragging direction
  TCHAR direction = getDirection(dx, dy);

  // Return if we are in an unclear direction
  if (direction == '\0')
    return;

  // Return if we are still in the same direction
  if (gesture.empty() || gesture.last() != direction)
    gesture.Append(direction);
}
Ejemplo n.º 3
0
bool
GlueMapWindow::OnMouseUp(PixelScalar x, PixelScalar y)
{
    if (drag_mode != DRAG_NONE)
        ReleaseCapture();

    // Ignore single click event if double click detected
    if (ignore_single_click) {
        ignore_single_click = false;
        return true;
    }

    int click_time = mouse_down_clock.Elapsed();
    mouse_down_clock.Reset();

    DragMode old_drag_mode = drag_mode;
    drag_mode = DRAG_NONE;

    switch (old_drag_mode) {
    case DRAG_NONE:
        /* skip the arm_mapitem_list check below */
        return false;

#ifdef HAVE_MULTI_TOUCH
    case DRAG_MULTI_TOUCH_PAN:
        follow_mode = FOLLOW_SELF;
        EnterPan();
        return true;
#endif

    case DRAG_PAN:
#ifndef ENABLE_OPENGL
        /* allow the use of the stretched last buffer for the next two
           redraws */
        scale_buffer = 2;
#endif

#ifdef ENABLE_OPENGL
        kinetic_x.MouseUp(x);
        kinetic_y.MouseUp(y);
        kinetic_timer.Schedule(30);
#endif
        break;

    case DRAG_SIMULATOR:
        if (click_time > 50 &&
                compare_squared(drag_start.x - x, drag_start.y - y,
                                Layout::Scale(36)) == 1) {
            GeoPoint location = visible_projection.ScreenToGeo(x, y);

            double distance = hypot(drag_start.x - x, drag_start.y - y);

            // This drag moves the aircraft (changes speed and direction)
            const Angle old_bearing = CommonInterface::Basic().track;
            const fixed min_speed = fixed(1.1) *
                                    CommonInterface::GetComputerSettings().polar.glide_polar_task.GetVMin();
            const Angle new_bearing = drag_start_geopoint.Bearing(location);
            if (((new_bearing - old_bearing).AsDelta().AbsoluteDegrees() < fixed(30)) ||
                    (CommonInterface::Basic().ground_speed < min_speed))
                device_blackboard->SetSpeed(Clamp(fixed(distance) / Layout::FastScale(3),
                                                  min_speed, fixed(100)));

            device_blackboard->SetTrack(new_bearing);
            // change bearing without changing speed if direction change > 30
            // 20080815 JMW prevent dragging to stop glider

            return true;
        }

        break;

    case DRAG_GESTURE:
        const TCHAR* gesture = gestures.Finish();
        if (gesture && OnMouseGesture(gesture))
            return true;

        break;
    }

    if (click_time > 50 && arm_mapitem_list) {
        map_item_timer.Schedule(200);
        return true;
    }

    return false;
}
Ejemplo n.º 4
0
bool
GlueMapWindow::OnMouseDown(PixelScalar x, PixelScalar y)
{
    map_item_timer.Cancel();

#ifdef ENABLE_OPENGL
    kinetic_timer.Cancel();
#endif

    // Ignore single click event if double click detected
    if (ignore_single_click || drag_mode != DRAG_NONE)
        return true;

    if (is_simulator() && IsCtrlKeyPressed() && visible_projection.IsValid()) {
        /* clicking with Alt key held moves the simulator to the click
           location instantly */
        const GeoPoint location = visible_projection.ScreenToGeo(x, y);
        device_blackboard->SetSimulatorLocation(location);
        return true;
    }

    mouse_down_clock.Update();
    arm_mapitem_list = HasFocus();

    SetFocus();

    if (!visible_projection.IsValid()) {
        gestures.Start(x, y, Layout::Scale(20));
        drag_mode = DRAG_GESTURE;
        SetCapture();
        return true;
    }

    drag_start.x = x;
    drag_start.y = y;
    drag_start_geopoint = visible_projection.ScreenToGeo(x, y);

    switch (follow_mode) {
    case FOLLOW_SELF:
        break;

    case FOLLOW_PAN:
        drag_mode = DRAG_PAN;
        drag_projection = visible_projection;

#ifdef ENABLE_OPENGL
        kinetic_x.MouseDown(x);
        kinetic_y.MouseDown(y);
#endif

        break;
    }

    if (CommonInterface::Basic().gps.simulator && drag_mode == DRAG_NONE)
        if (compare_squared(visible_projection.GetScreenOrigin().x - x,
                            visible_projection.GetScreenOrigin().y - y,
                            Layout::Scale(30)) != 1)
            drag_mode = DRAG_SIMULATOR;
    if (drag_mode == DRAG_NONE ) {
        gestures.Start(x, y, Layout::Scale(20));
        drag_mode = DRAG_GESTURE;
    }

    if (drag_mode != DRAG_NONE)
        SetCapture();

    return true;
}