Exemplo n.º 1
0
void
mouse(int b, int s, int x, int y)
{
  float selx, sely;

  mousex = x;
  mousey = y;
  curX = x;
  curY = y;
  if (s == GLUT_DOWN) {
    switch (b) {
    case GLUT_LEFT_BUTTON:
      if (solving) {
        freeSolutions();
        solving = 0;
      glutChangeToMenuEntry(1, "Solving", 1);
        glutSetWindowTitle("glpuzzle");
        movingPiece = 0;
      }
      left_mouse = GL_TRUE;
      sel_piece = selectPiece(mousex, mousey);
      if (computeCoords(sel_piece, mousex, mousey, &selx, &sely)) {
        grabPiece(sel_piece, selx, sely);
      }
      glutPostRedisplay();
      break;
    case GLUT_MIDDLE_BUTTON:
      middle_mouse = GL_TRUE;
      glutPostRedisplay();
      break;
    }
  } else {
    switch (b) {
    case GLUT_LEFT_BUTTON:
      left_mouse = GL_FALSE;
      dropSelection();
      glutPostRedisplay();
      break;
    case GLUT_MIDDLE_BUTTON:
      middle_mouse = GL_FALSE;
      glutPostRedisplay();
      break;
    }
  }
  motion(x, y);
}
Exemplo n.º 2
0
int Puzzle_Window::handle(int event) {
  int x = Fl::event_x();
  int y = Fl::event_y();
  switch (event) {
  case FL_KEY:
    switch (Fl::event_key()) {
    case FL_Escape:
    case 'Q':
    case 'q':
      exit(0);
      break;
    case 'S':
    case 's':
      solve_cb(this,0);
      break;
    case 'D':
    case 'd':
      piece = selectPiece(x, y);
      delete_cb(this,0);
      break;
    case 'R':
    case 'r':
      reset_cb(this,0);
      break;
    case 'O':
    case 'o':
      reset_view_cb(this,0);
      break;
    default:
      break;
    }
    return 1;

  case FL_PUSH:
    mousex = curX = x;
    mousey = curY = y;
    switch (Fl::event_button()) {
    case 1:
      set_solving(0);
      left_mouse = true;
      sel_piece = selectPiece(mousex, mousey);
      if (!sel_piece) {
	left_mouse = false;
	middle_mouse = true; // let it rotate object
      } else {
	float selx, sely;
	if (computeCoords(sel_piece, mousex, mousey, &selx, &sely)) {
	  grabPiece(sel_piece, selx, sely);
	}
      }
      redraw();
      break;
    case 2:
      middle_mouse = true;
      redraw();
      break;
    default:
      piece = selectPiece(x, y);
      if (piece) menu->child(2)->activate(); else menu->child(2)->deactivate();
      menu->popup(x, y);
      return 1;
    }
    // fall through to drag handler:

  case FL_DRAG:
    if (middle_mouse && !left_mouse) {
      if (mousex != x || mousey != y) {
	trackball(lastquat,
		  (2.0*mousex - W) / W,
		  (H - 2.0*mousey) / H,
		  (2.0*x - W) / W,
		  (H - 2.0*y) / H);
	spinning = 1;
      } else {
	spinning = 0;
      }
      changeState();
    } else {
      float selx, sely;
      computeCoords(sel_piece, x, y, &selx, &sely);
      moveSelection(selx, sely);
    }
    mousex = x;
    mousey = y;
    redraw();
    return 1;

  case FL_RELEASE:
    if (left_mouse) {
      left_mouse = false;
      dropSelection();
      redraw();
    } else if (middle_mouse) {
      middle_mouse = GL_FALSE;
      redraw();
    }
    return 1;

  }
  return Fl_Gl_Window::handle(event);
}