Exemple #1
0
/*! \brief Fill inside of box with single line pattern.
 *  \par Function Description
 *  This function fills the inside of the box with a pattern made of lines.
 *  The lines are drawn inside the box with an angle <B>angle1</B> from the
 *  horizontal. The distance between two of these lines is given by
 *  <B>pitch1</B> and their width by <B>fill_width</B>.
 *  Parameters <B>angle2</B> and <B>pitch2</B> are unused here but kept for
 *  compatbility with other box filling functions.
 *
 *  The box is defined in the same way as it is in GDK : one point and the
 *  width and height of the box.
 *
 *  All parameters are given in pixel.
 *
 *  Negative or null values for <B>pitch1</B> are not allowed as it leads to
 *  an endless loop.
 *
 *  \param [in] w_current   Schematic top level
 *  \param [in] color       Box fill color.
 *  \param [in] box         Box definition
 *  \param [in] fill_width  BOX pattern fill width.
 *  \param [in] angle1      1st angle for pattern.
 *  \param [in] pitch1      1st pitch for pattern.
 *  \param [in] angle2      (unused)
 *  \param [in] pitch2      (unused)
 */
static void
o_box_fill_hatch (GSCHEM_TOPLEVEL *w_current,
                  COLOR *color, BOX *box,
                  gint fill_width,
                  gint angle1, gint pitch1,
                  gint angle2, gint pitch2)
{
  int i;
  GArray *lines;

  gschem_cairo_set_source_color (w_current, color);

  lines = g_array_new (FALSE, FALSE, sizeof (LINE));
  m_hatch_box (box, angle1, pitch1, lines);

  for (i=0; i < lines->len; i++) {
    LINE *line = &g_array_index (lines, LINE, i);

    gschem_cairo_line (w_current, END_NONE, fill_width, line->x[0], line->y[0],
                                                        line->x[1], line->y[1]);
  }
  gschem_cairo_stroke (w_current, TYPE_SOLID, END_NONE, fill_width, -1, -1);

  g_array_free (lines, TRUE);
}
Exemple #2
0
/*! \brief Print a hatch pattern BOX to Postscript document.
 *  \par Function Description
 *  The function prints a hatched box. No outline is printed. The box is
 *  defined by the coordinates of its upper left corner in (<B>x</B>,<B>y</B>) and
 *  its width and height given by the <B>width</B> and <B>height</B> parameters.
 *  The postscript file is defined by the file pointer <B>fp</B>. 
 *  <B>fill_width</B>, <B>angle1</B>, <B>pitch1</B> parameters define the way the box
 *  has to be hatched.
 *  <B>angle2</B> and <B>pitch2</B> parameters are unused but kept for compatibility
 *  with other fill functions.
 *
 *  Negative or null values for <B>pitch1</B> are not allowed as it leads to an
 *  endless loop.
 *
 *  All dimensions are in mils.
 *
 *  \param [in] toplevel   The TOPLEVEL object.
 *  \param [in] fp          FILE pointer to Postscript document.
 *  \param [in] x           Upper x coordinate of BOX.
 *  \param [in] y           Upper y coordinate of BOX.
 *  \param [in] width       Width of BOX.
 *  \param [in] height      Height of BOX.
 *  \param [in] color       BOX color.
 *  \param [in] fill_width  BOX fill width.
 *  \param [in] angle1      Angle of hatch pattern.
 *  \param [in] pitch1      Pitch of hatch pattern.
 *  \param [in] angle2      (unused).
 *  \param [in] pitch2      (unused).
 *  \param [in] origin_x    Page x coordinate to place BOX OBJECT.
 *  \param [in] origin_y    Page y coordinate to place BOX OBJECT.
 */
void o_box_print_hatch(TOPLEVEL *toplevel, FILE *fp,
		       int x, int y,
		       int width, int height,
		       int color,
		       int fill_width,
		       int angle1, int pitch1,
		       int angle2, int pitch2,
		       int origin_x, int origin_y)
{
  BOX box;
  gint index;
  GArray *lines;

  g_return_if_fail(toplevel != NULL);
  g_return_if_fail(fp != NULL);

  f_print_set_color(toplevel, fp, color);

  /* Avoid printing line widths too small */
  if (fill_width <= 1) fill_width = 2;

  lines = g_array_new(FALSE, FALSE, sizeof(LINE));

  box.upper_x = x;
  box.upper_y = y;
  box.lower_x = x + width;
  box.lower_y = y - height;    /* Hmmm... */

  m_hatch_box(&box, angle1, pitch1, lines);

  for(index=0; index<lines->len; index++) {
    LINE *line = &g_array_index(lines, LINE, index);

    fprintf(fp,"%d %d %d %d %d line\n",
            line->x[0], line->y[0],
            line->x[1], line->y[1],
            fill_width);
  }

  g_array_free(lines, TRUE);
}
/*! \private
 *  \brief Render the swatch into the cell
 *
 *  \param [in] cell this cell renderer
 *  \param [in] window the window to renter to
 *  \param [in] widget the widget owning the window
 *  \param [in] background_area entire cell area
 *  \param [in] cell_area area rendered normally
 *  \param [in] expose_area the area requiring update
 *  \param [in] flags
 */
static void
render (GtkCellRenderer      *cell,
        GdkWindow            *window,
        GtkWidget            *widget,
        GdkRectangle         *background_area,
        GdkRectangle         *cell_area,
        GdkRectangle         *expose_area,
        GtkCellRendererState flags)
{
  GschemFillSwatchCellRenderer *swatch = GSCHEM_FILL_SWATCH_CELL_RENDERER (cell);

  if (swatch->enabled) {
    GdkColor color;
    cairo_t *cr = gdk_cairo_create (window);
    double offset = SWATCH_BORDER_WIDTH / 2.0;
    gboolean success;

    if (expose_area) {
      gdk_cairo_rectangle (cr, expose_area);
      cairo_clip (cr);
    }

    /* Paint the swatch using the text color to match the user's desktop theme.
     */

    success = gtk_style_lookup_color (gtk_widget_get_style (widget),
                                      "text_color",
                                      &color);

    if (success) {
      cairo_set_source_rgb (cr,
                            color.red   / 65535.0,
                            color.green / 65535.0,
                            color.blue  / 65535.0);
    }

    cairo_move_to (cr,
                   (double) cell_area->x + offset,
                   (double) cell_area->y + offset);

    cairo_line_to (cr,
                   (double) cell_area->x + (double) cell_area->width - offset,
                   (double) cell_area->y + offset);

    cairo_line_to (cr,
                   (double) cell_area->x + (double) cell_area->width - offset,
                   (double) cell_area->y + (double) cell_area->height - offset);

    cairo_line_to (cr,
                   (double) cell_area->x + offset,
                   (double) cell_area->y + (double) cell_area->height - offset);

    cairo_close_path (cr);

    if ((swatch->fill_type == FILLING_HATCH) || (swatch->fill_type == FILLING_MESH)) {
      BOX box;
      int index;
      GArray *lines = g_array_new (FALSE, FALSE, sizeof (LINE));
      cairo_path_t *save_path = cairo_copy_path (cr);

      cairo_save (cr);
      cairo_clip (cr);

      box.lower_x = cell_area->x;
      box.lower_y = cell_area->y;
      box.upper_x = cell_area->x + cell_area->width;
      box.upper_y = cell_area->y + cell_area->height;

      m_hatch_box (&box, 135, SWATCH_LINE_PITCH, lines);

      if (swatch->fill_type == FILLING_MESH) {
        m_hatch_box (&box, 45, SWATCH_LINE_PITCH, lines);
      }

      for (index=0; index<lines->len; index++) {
        LINE *line = &g_array_index (lines, LINE, index);

        cairo_move_to (cr, line->x[0], line->y[0]);
        cairo_line_to (cr, line->x[1], line->y[1]);
      }

      g_array_free (lines, TRUE);

      cairo_set_line_width (cr, SWATCH_LINE_WIDTH);
      cairo_stroke (cr);
      cairo_restore (cr);

      cairo_append_path (cr, save_path);
      cairo_path_destroy (save_path);
    }

    if (swatch->fill_type == FILLING_FILL) {
      cairo_fill_preserve (cr);
    }

    cairo_set_line_width (cr, SWATCH_BORDER_WIDTH);
    cairo_stroke (cr);
    cairo_destroy (cr);
  }
}