Example #1
0
gboolean
ghid_note_event_location (GdkEventButton * ev)
{
  gint x, y;
  gboolean moved;

  if (!ev)
    {
      gdk_window_get_pointer (ghid_port.drawing_area->window, &x, &y, NULL);
      event_x = x;
      event_y = y;
    }
  else
    {
      event_x = ev->x;
      event_y = ev->y;
    }
  gport->view_x = event_x * gport->zoom + gport->view_x0;
  gport->view_y = event_y * gport->zoom + gport->view_y0;

  moved = MoveCrosshairAbsolute (SIDE_X (gport->view_x), 
				 SIDE_Y (gport->view_y));
  if (moved)
    {
      AdjustAttachedObjects ();
      RestoreCrosshair (false);
    }
  ghid_set_cursor_position_labels ();
  return moved;
}
Example #2
0
void
ghid_fill_circle (hidGC gc, int cx, int cy, int radius)
{
    gint w, h, vr;

    w = gport->width * gport->zoom;
    h = gport->height * gport->zoom;
    if (SIDE_X (cx) < gport->view_x0 - radius
            || SIDE_X (cx) > gport->view_x0 + w + radius
            || SIDE_Y (cy) < gport->view_y0 - radius
            || SIDE_Y (cy) > gport->view_y0 + h + radius)
        return;

    USE_GC (gc);
    vr = Vz (radius);
    gdk_draw_arc (gport->drawable, gport->u_gc, TRUE,
                  Vx (cx) - vr, Vy (cy) - vr, vr * 2, vr * 2, 0, 360 * 64);
}
Example #3
0
void
ghid_fill_circle (hidGC gc, Coord cx, Coord cy, Coord radius)
{
  gint w, h, vr;
  render_priv *priv = gport->render_priv;

  w = gport->width * gport->view.coord_per_px;
  h = gport->height * gport->view.coord_per_px;
  if (SIDE_X (cx) < gport->view.x0 - radius
      || SIDE_X (cx) > gport->view.x0 + w + radius
      || SIDE_Y (cy) < gport->view.y0 - radius
      || SIDE_Y (cy) > gport->view.y0 + h + radius)
    return;

  USE_GC (gc);
  vr = Vz (radius);
  gdk_draw_arc (gport->drawable, priv->u_gc, TRUE,
		Vx (cx) - vr, Vy (cy) - vr, vr * 2, vr * 2, 0, 360 * 64);
}
Example #4
0
void
ghid_draw_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
{
  gint w, h, lw;
  render_priv *priv = gport->render_priv;

  lw = gc->width;
  w = gport->width * gport->view.coord_per_px;
  h = gport->height * gport->view.coord_per_px;

  if ((SIDE_X (x1) < gport->view.x0 - lw
       && SIDE_X (x2) < gport->view.x0 - lw)
      || (SIDE_X (x1) > gport->view.x0 + w + lw
	  && SIDE_X (x2) > gport->view.x0 + w + lw)
      || (SIDE_Y (y1) < gport->view.y0 - lw
	  && SIDE_Y (y2) < gport->view.y0 - lw)
      || (SIDE_Y (y1) > gport->view.y0 + h + lw
	  && SIDE_Y (y2) > gport->view.y0 + h + lw))
    return;

  x1 = Vx (x1);
  y1 = Vy (y1);
  x2 = Vx (x2);
  y2 = Vy (y2);

  if (x1 > x2)
    {
      gint xt = x1;
      x1 = x2;
      x2 = xt;
    }
  if (y1 > y2)
    {
      gint yt = y1;
      y1 = y2;
      y2 = yt;
    }

  USE_GC (gc);
  gdk_draw_rectangle (gport->drawable, priv->u_gc, FALSE,
		      x1, y1, x2 - x1 + 1, y2 - y1 + 1);
}
Example #5
0
void
ghid_get_coords (const char *msg, int *x, int *y)
{
  if (!ghid_port.has_entered && msg)
    ghid_get_user_xy (msg);
  if (ghid_port.has_entered)
    {
      *x = SIDE_X (gport->view_x);
      *y = SIDE_Y (gport->view_y);
    }
}
Example #6
0
void
ghid_draw_rect (hidGC gc, int x1, int y1, int x2, int y2)
{
    gint w, h, lw;

    lw = gc->width;
    w = gport->width * gport->zoom;
    h = gport->height * gport->zoom;

    if ((SIDE_X (x1) < gport->view_x0 - lw
            && SIDE_X (x2) < gport->view_x0 - lw)
            || (SIDE_X (x1) > gport->view_x0 + w + lw
                && SIDE_X (x2) > gport->view_x0 + w + lw)
            || (SIDE_Y (y1) < gport->view_y0 - lw
                && SIDE_Y (y2) < gport->view_y0 - lw)
            || (SIDE_Y (y1) > gport->view_y0 + h + lw
                && SIDE_Y (y2) > gport->view_y0 + h + lw))
        return;

    x1 = Vx (x1);
    y1 = Vy (y1);
    x2 = Vx (x2);
    y2 = Vy (y2);

    if (x1 > x2)
    {
        gint xt = x1;
        x1 = x2;
        x2 = xt;
    }
    if (y1 > y2)
    {
        gint yt = y1;
        y1 = y2;
        y2 = yt;
    }

    USE_GC (gc);
    gdk_draw_rectangle (gport->drawable, gport->u_gc, FALSE,
                        x1, y1, x2 - x1 + 1, y2 - y1 + 1);
}
Example #7
0
void
ghid_fill_rect (hidGC gc, int x1, int y1, int x2, int y2)
{
    gint w, h, lw, xx, yy;

    lw = gc->width;
    w = gport->width * gport->zoom;
    h = gport->height * gport->zoom;

    if ((SIDE_X (x1) < gport->view_x0 - lw
            && SIDE_X (x2) < gport->view_x0 - lw)
            || (SIDE_X (x1) > gport->view_x0 + w + lw
                && SIDE_X (x2) > gport->view_x0 + w + lw)
            || (SIDE_Y (y1) < gport->view_y0 - lw
                && SIDE_Y (y2) < gport->view_y0 - lw)
            || (SIDE_Y (y1) > gport->view_y0 + h + lw
                && SIDE_Y (y2) > gport->view_y0 + h + lw))
        return;

    x1 = Vx (x1);
    y1 = Vy (y1);
    x2 = Vx (x2);
    y2 = Vy (y2);
    if (x2 < x1)
    {
        xx = x1;
        x1 = x2;
        x2 = xx;
    }
    if (y2 < y1)
    {
        yy = y1;
        y1 = y2;
        y2 = yy;
    }
    USE_GC (gc);
    gdk_draw_rectangle (gport->drawable, gport->u_gc, TRUE,
                        x1, y1, x2 - x1 + 1, y2 - y1 + 1);
}
Example #8
0
void
ghid_draw_arc (hidGC gc, Coord cx, Coord cy,
	       Coord xradius, Coord yradius, Angle start_angle, Angle delta_angle)
{
  gint vrx, vry;
  gint w, h, radius;
  render_priv *priv = gport->render_priv;

  w = gport->width * gport->view.coord_per_px;
  h = gport->height * gport->view.coord_per_px;
  radius = (xradius > yradius) ? xradius : yradius;
  if (SIDE_X (cx) < gport->view.x0 - radius
      || SIDE_X (cx) > gport->view.x0 + w + radius
      || SIDE_Y (cy) < gport->view.y0 - radius
      || SIDE_Y (cy) > gport->view.y0 + h + radius)
    return;

  USE_GC (gc);
  vrx = Vz (xradius);
  vry = Vz (yradius);

  if (gport->view.flip_x)
    {
      start_angle = 180 - start_angle;
      delta_angle = -delta_angle;
    }
  if (gport->view.flip_y)
    {
      start_angle = -start_angle;
      delta_angle = -delta_angle;
    }
  /* make sure we fall in the -180 to +180 range */
  start_angle = NormalizeAngle (start_angle);
  if (start_angle >= 180)  start_angle -= 360;

  gdk_draw_arc (gport->drawable, priv->u_gc, 0,
		Vx (cx) - vrx, Vy (cy) - vry,
		vrx * 2, vry * 2, (start_angle + 180) * 64, delta_angle * 64);
}
Example #9
0
void
ghid_draw_arc (hidGC gc, int cx, int cy,
               int xradius, int yradius, int start_angle, int delta_angle)
{
    gint vrx, vry;
    gint w, h, radius;

    w = gport->width * gport->zoom;
    h = gport->height * gport->zoom;
    radius = (xradius > yradius) ? xradius : yradius;
    if (SIDE_X (cx) < gport->view_x0 - radius
            || SIDE_X (cx) > gport->view_x0 + w + radius
            || SIDE_Y (cy) < gport->view_y0 - radius
            || SIDE_Y (cy) > gport->view_y0 + h + radius)
        return;

    USE_GC (gc);
    vrx = Vz (xradius);
    vry = Vz (yradius);

    if (ghid_flip_x)
    {
        start_angle = 180 - start_angle;
        delta_angle = -delta_angle;
    }
    if (ghid_flip_y)
    {
        start_angle = -start_angle;
        delta_angle = -delta_angle;
    }
    /* make sure we fall in the -180 to +180 range */
    start_angle = (start_angle + 360 + 180) % 360 - 180;

    gdk_draw_arc (gport->drawable, gport->u_gc, 0,
                  Vx (cx) - vrx, Vy (cy) - vry,
                  vrx * 2, vry * 2, (start_angle + 180) * 64, delta_angle * 64);
}
Example #10
0
static void
ghid_draw_grid (void)
{
    static GdkPoint *points = 0;
    static int npoints = 0;
    int x1, y1, x2, y2, n, i;
    double x, y;

    if (!Settings.DrawGrid)
        return;
    if (Vz (PCB->Grid) < MIN_GRID_DISTANCE)
        return;
    if (!gport->grid_gc)
    {
        if (gdk_color_parse (Settings.GridColor, &gport->grid_color))
        {
            gport->grid_color.red ^= gport->bg_color.red;
            gport->grid_color.green ^= gport->bg_color.green;
            gport->grid_color.blue ^= gport->bg_color.blue;
            gdk_color_alloc (gport->colormap, &gport->grid_color);
        }
        gport->grid_gc = gdk_gc_new (gport->drawable);
        gdk_gc_set_function (gport->grid_gc, GDK_XOR);
        gdk_gc_set_foreground (gport->grid_gc, &gport->grid_color);
    }
    x1 = GRIDFIT_X (SIDE_X (gport->view_x0), PCB->Grid);
    y1 = GRIDFIT_Y (SIDE_Y (gport->view_y0), PCB->Grid);
    x2 = GRIDFIT_X (SIDE_X (gport->view_x0 + gport->view_width - 1), PCB->Grid);
    y2 =
        GRIDFIT_Y (SIDE_Y (gport->view_y0 + gport->view_height - 1), PCB->Grid);
    if (x1 > x2)
    {
        int tmp = x1;
        x1 = x2;
        x2 = tmp;
    }
    if (y1 > y2)
    {
        int tmp = y1;
        y1 = y2;
        y2 = tmp;
    }
    if (Vx (x1) < 0)
        x1 += PCB->Grid;
    if (Vy (y1) < 0)
        y1 += PCB->Grid;
    if (Vx (x2) >= gport->width)
        x2 -= PCB->Grid;
    if (Vy (y2) >= gport->height)
        y2 -= PCB->Grid;
    n = (int) ((x2 - x1) / PCB->Grid + 0.5) + 1;
    if (n > npoints)
    {
        npoints = n + 10;
        points = (GdkPoint *)realloc (points, npoints * sizeof (GdkPoint));
    }
    n = 0;
    for (x = x1; x <= x2; x += PCB->Grid)
    {
        points[n].x = Vx (x);
        n++;
    }
    if (n == 0)
        return;
    for (y = y1; y <= y2; y += PCB->Grid)
    {
        int vy = Vy (y);
        for (i = 0; i < n; i++)
            points[i].y = vy;
        gdk_draw_points (gport->drawable, gport->grid_gc, points, n);
    }
}
Example #11
0
static void
ghid_draw_grid (void)
{
  static GdkPoint *points = 0;
  static int npoints = 0;
  Coord x1, y1, x2, y2, x, y;
  int n, i;
  render_priv *priv = gport->render_priv;

  if (!Settings.DrawGrid)
    return;
  if (Vz (PCB->Grid) < MIN_GRID_DISTANCE)
    return;
  if (!priv->grid_gc)
    {
      if (gdk_color_parse (Settings.GridColor, &gport->grid_color))
	{
	  gport->grid_color.red ^= gport->bg_color.red;
	  gport->grid_color.green ^= gport->bg_color.green;
	  gport->grid_color.blue ^= gport->bg_color.blue;
	  gdk_color_alloc (gport->colormap, &gport->grid_color);
	}
      priv->grid_gc = gdk_gc_new (gport->drawable);
      gdk_gc_set_function (priv->grid_gc, GDK_XOR);
      gdk_gc_set_foreground (priv->grid_gc, &gport->grid_color);
      gdk_gc_set_clip_origin (priv->grid_gc, 0, 0);
      set_clip (priv, priv->grid_gc);
    }
  x1 = GridFit (SIDE_X (gport->view.x0), PCB->Grid, PCB->GridOffsetX);
  y1 = GridFit (SIDE_Y (gport->view.y0), PCB->Grid, PCB->GridOffsetY);
  x2 = GridFit (SIDE_X (gport->view.x0 + gport->view.width - 1),
                PCB->Grid, PCB->GridOffsetX);
  y2 = GridFit (SIDE_Y (gport->view.y0 + gport->view.height - 1),
                PCB->Grid, PCB->GridOffsetY);
  if (x1 > x2)
    {
      Coord tmp = x1;
      x1 = x2;
      x2 = tmp;
    }
  if (y1 > y2)
    {
      Coord tmp = y1;
      y1 = y2;
      y2 = tmp;
    }
  if (Vx (x1) < 0)
    x1 += PCB->Grid;
  if (Vy (y1) < 0)
    y1 += PCB->Grid;
  if (Vx (x2) >= gport->width)
    x2 -= PCB->Grid;
  if (Vy (y2) >= gport->height)
    y2 -= PCB->Grid;
  n = (x2 - x1) / PCB->Grid + 1;
  if (n > npoints)
    {
      npoints = n + 10;
      points = (GdkPoint *)realloc (points, npoints * sizeof (GdkPoint));
    }
  n = 0;
  for (x = x1; x <= x2; x += PCB->Grid)
    {
      points[n].x = Vx (x);
      n++;
    }
  if (n == 0)
    return;
  for (y = y1; y <= y2; y += PCB->Grid)
    {
      for (i = 0; i < n; i++)
	points[i].y = Vy (y);
      gdk_draw_points (gport->drawable, priv->grid_gc, points, n);
    }
}
Example #12
0
/* Callback when the user clicks on a PCB node in the right node treeview.
 */
static void
node_selection_changed_cb (GtkTreeSelection * selection, gpointer data)
{
  GtkTreeIter iter;
  GtkTreeModel *model;
  LibraryMenuType *node_net;
  LibraryEntryType *node;
  static gchar *node_name;
	gint		x0, y0, margin;

  if (selection_holdoff)	/* PCB is highlighting, user is not selecting */
    return;

  /* Toggle off the previous selection.  Look up node_name to make sure
  |  it still exists.  This toggling can get out of sync if a node is
  |  toggled selected, then the net that includes the node is selected
  |  then unselected.
  */
  if ((node = node_get_node_from_name (node_name, &node_net)) != NULL)
    {
      /* If net node belongs to has been highlighted/unhighighed, toggling
      |  if off here will get our on/off toggling out of sync.
      */
      if (node_net == node_selected_net)
	SelectPin (node, TRUE);
      g_free (node_name);
      node_name = NULL;
    }

  /* Get the selected treeview row.
   */
  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
    {
      if (node)
        ghid_invalidate_all ();
      return;
    }

  /* From the treeview row, extract the node pointer stored there and
  |  we've got a pointer to the LibraryEntryType (node) the row
  |  represents.
  */
  gtk_tree_model_get (model, &iter, NODE_LIBRARY_COLUMN, &node, -1);

  dup_string (&node_name, node->ListEntry);
  node_selected_net = selected_net;

  /* Now just toggle a select of the node on the layout and pan.
   */
  SelectPin (node, TRUE);
  IncrementUndoSerialNumber ();
	margin = gport->view_width / 20;
	if (   Crosshair.X < gport->view_x0 + margin
	    || Crosshair.X > gport->view_x0 + gport->view_width - margin
	    || Crosshair.Y < gport->view_y0 + margin
	    || Crosshair.Y > gport->view_y0 + gport->view_height - margin
	   )
	  {

	    x0 = SIDE_X (Crosshair.X) - gport->view_width / 2;
	    y0 = SIDE_Y (Crosshair.Y) - gport->view_height / 2;
	    gport->view_x0 = x0;
	    gport->view_y0 = y0;
	    ghid_pan_fixup ();
	    gui->set_crosshair (Crosshair.X, Crosshair.Y, HID_SC_WARP_POINTER);
	  }
	ghid_screen_update();
}