예제 #1
0
/**************************************************************************
...
**************************************************************************/
void mapctrl_btn_mapcanvas(XEvent *event)
{
  XButtonEvent *ev=&event->xbutton;
  struct tile *ptile = canvas_pos_to_tile(ev->x, ev->y);

  if (!can_client_change_view()) {
    return;
  }

  if (ev->button == Button1 && (ev->state & ControlMask)) {
    action_button_pressed(ev->x, ev->y, SELECT_SEA);
  } else if (ev->button == Button1) {
    action_button_pressed(ev->x, ev->y, SELECT_POPUP);
  } else if (ev->button == Button2 && ptile) {
    popit(ev->x, ev->y, ptile);
  } else if (ev->button == Button3 && (ev->state & ControlMask)) {
    action_button_pressed(ev->x, ev->y, SELECT_LAND);
  } else if (ev->button == Button3) {
    recenter_button_pressed(ev->x, ev->y);
  }
}
예제 #2
0
파일: mapctrl.c 프로젝트: jheusala/freeciv
/**************************************************************************
 Handle all mouse button press on canvas.
 Future feature: User-configurable mouse clicks.
**************************************************************************/
gboolean butt_down_mapcanvas(GtkWidget *w, GdkEventButton *ev, gpointer data)
{
  struct city *pcity = NULL;
  struct tile *ptile = NULL;

  if (editor_is_active()) {
    return handle_edit_mouse_button_press(ev);
  }

  if (!can_client_change_view()) {
    return TRUE;
  }

  gtk_widget_grab_focus(map_canvas);
  ptile = canvas_pos_to_tile(ev->x, ev->y);
  pcity = ptile ? tile_city(ptile) : NULL;

  switch (ev->button) {

  case 1: /* LEFT mouse button */

    /* <SHIFT> + <CONTROL> + LMB : Adjust workers. */
    if ((ev->state & GDK_SHIFT_MASK) && (ev->state & GDK_CONTROL_MASK)) {
      adjust_workers_button_pressed(ev->x, ev->y);
    }
    /* <CONTROL> + LMB : Quickselect a sea unit. */
    else if (ev->state & GDK_CONTROL_MASK) {
      action_button_pressed(ev->x, ev->y, SELECT_SEA);
    }
    /* <SHIFT> + LMB: Append focus unit. */
    else if (ptile && (ev->state & GDK_SHIFT_MASK)) {
      action_button_pressed(ev->x, ev->y, SELECT_APPEND);
    }
    /* <ALT> + LMB: popit (same as middle-click) */
    /* FIXME: we need a general mechanism for letting freeciv work with
     * 1- or 2-button mice. */
    else if (ptile && (ev->state & GDK_MOD1_MASK)) {
      popit(ev, ptile);
    }
    /* LMB in Area Selection mode. */
    else if(tiles_hilited_cities) {
      if (ptile) {
        toggle_tile_hilite(ptile);
      }
    }
    /* Plain LMB click. */
    else {
      action_button_pressed(ev->x, ev->y, SELECT_POPUP);
    }
    break;

  case 2: /* MIDDLE mouse button */

    /* <CONTROL> + MMB: Wake up sentries. */
    if (ev->state & GDK_CONTROL_MASK) {
      wakeup_button_pressed(ev->x, ev->y);
    }
    /* Plain Middle click. */
    else if (ptile) {
      popit(ev, ptile);
    }
    break;

  case 3: /* RIGHT mouse button */

    /* <CONTROL> + <ALT> + RMB : insert city or tile chat link. */
    /* <CONTROL> + <ALT> + <SHIFT> + RMB : insert unit chat link. */
    if (ptile && (ev->state & GDK_MOD1_MASK)
        && (ev->state & GDK_CONTROL_MASK)) {
      inputline_make_chat_link(ptile, (ev->state & GDK_SHIFT_MASK) != 0);
    }
    /* <SHIFT> + <ALT> + RMB : Show/hide workers. */
    else if ((ev->state & GDK_SHIFT_MASK) && (ev->state & GDK_MOD1_MASK)) {
      key_city_overlay(ev->x, ev->y);
    }
    /* <SHIFT + CONTROL> + RMB: Paste Production. */
    else if ((ev->state & GDK_SHIFT_MASK) && (ev->state & GDK_CONTROL_MASK)
             && pcity != NULL) {
      clipboard_paste_production(pcity);
      cancel_tile_hiliting();
    }
    /* <SHIFT> + RMB on city/unit: Copy Production. */
    /* If nothing to copy, fall through to rectangle selection. */
    else if (ev->state & GDK_SHIFT_MASK
             && clipboard_copy_production(ptile)) {
      /* Already done the copy */
    }
    /* <CONTROL> + RMB : Quickselect a land unit. */
    else if (ev->state & GDK_CONTROL_MASK) {
      action_button_pressed(ev->x, ev->y, SELECT_LAND);
    }
    /* Plain RMB click. Area selection. */
    else {
      /*  A foolproof user will depress button on canvas,
       *  release it on another widget, and return to canvas
       *  to find rectangle still active.
       */
      if (rectangle_active) {
        release_right_button(ev->x, ev->y,
                             (ev->state & GDK_SHIFT_MASK) != 0);
        return TRUE;
      }
      if (hover_state == HOVER_NONE) {
        anchor_selection_rectangle(ev->x, ev->y);
        rbutton_down = TRUE; /* causes rectangle updates */
      }
    }
    break;

  default:
    break;
  }


  return TRUE;
}