예제 #1
0
void idle(void)
{
    if (deltaSinceDraw) {
	x += deltaSinceDraw;
	clamp_x();
	draw();
	deltaSinceDraw = 0;
    }
}
예제 #2
0
/* ARGSUSED */
void button(int button, int state, int xpos, int ypos)
{
    if (state == GLUT_DOWN) {
	mouseOriginX = xpos;
	deltaSinceDraw = 0;
	glutIdleFunc(idle);
	return;
    }

    if (!moveCalled) {
	if (button == GLUT_MIDDLE_BUTTON) x = 1.;
	else x = (float)xpos / ((float)w / 2.);
	clamp_x();
	deltaSinceDraw = 100000.;
    } 
    moveCalled = 0;
    if (deltaSinceDraw) draw();
    printf("x = %f\n", x);
    glutIdleFunc(NULL);
}
예제 #3
0
static void
paint_large_line (GooDemoLargeLine      *line,
		  cairo_t               *cr,
		  const GooCanvasBounds *bounds,
		  gdouble                line_width,
		  gdouble                x1,
		  gdouble                y1,
		  gdouble                x2,
		  gdouble                y2)
{
  GooCanvasItem *item = (GooCanvasItem*) line;
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) line;
  GooCanvas *canvas = simple->canvas;
  GooCanvasBounds tmp_bounds = *bounds;
  gdouble point1[2], point2[2], *p1, *p2;

  point1[0] = x1;
  point1[1] = y1;
  point2[0] = x2;
  point2[1] = y2;

  /* Transform the coordinates to the canvas device space, so we can clamp
     the line to the bounds to be painted. */
  goo_canvas_convert_from_item_space (canvas, item, &point1[0], &point1[1]);
  goo_canvas_convert_from_item_space (canvas, item, &point2[0], &point2[1]);

  /* Extend the bounds a bit to account for the line width. */
  tmp_bounds.x1 -= line_width;
  tmp_bounds.y1 -= line_width;
  tmp_bounds.x2 += line_width;
  tmp_bounds.y2 += line_width;

  /* Make p1 the left-most point. */
  if (point1[0] < point2[0])
    {
      p1 = point1;
      p2 = point2;
    }
  else
    {
      p1 = point2;
      p2 = point1;
    }

  /* Just return if the line is completely outside the bounds horizontally. */
  if (p2[0] < tmp_bounds.x1 || p1[0] > tmp_bounds.x2)
    return;

  /* Clamp each x coordinate to the bounds. */
  if (p1[0] < tmp_bounds.x1)
    clamp_x (p1, p2, tmp_bounds.x1);
  if (p2[0] > tmp_bounds.x2)
    clamp_x (p2, p1, tmp_bounds.x2);

  /* Now make p1 the top-most point. */
  if (point1[1] < point2[1])
    {
      p1 = point1;
      p2 = point2;
    }
  else
    {
      p1 = point2;
      p2 = point1;
    }

  /* Just return if the line is completely outside the bounds vertically. */
  if (p2[1] < tmp_bounds.y1 || p1[1] > tmp_bounds.y2)
    return;

  /* Clamp each y coordinate to the bounds. */
  if (p1[1] < tmp_bounds.y1)
    clamp_y (p1, p2, tmp_bounds.y1);
  if (p2[1] > tmp_bounds.y2)
    clamp_y (p2, p1, tmp_bounds.y2);

  /* Convert back to item space. */
  goo_canvas_convert_to_item_space (canvas, item, &point1[0], &point1[1]);
  goo_canvas_convert_to_item_space (canvas, item, &point2[0], &point2[1]);

  /* Draw the line. */
  cairo_move_to (cr, point1[0], point1[1]);
  cairo_line_to (cr, point2[0], point2[1]);
  cairo_stroke (cr);
}