コード例 #1
0
ファイル: image.c プロジェクト: psychon/lualock
void image_draw_rectangle(image_t *image, gdouble x, gdouble y,
                          gdouble w, gdouble h, gboolean fill,
                          GdkRGBA *color) {
    cairo_t *cr = cairo_create(image->surface);
    gdk_cairo_set_source_rgba(cr, color);
    cairo_set_line_width(cr, 1);
    cairo_rectangle(cr, x, y, w, h);
    if (fill)
        cairo_fill(cr);
    else
        cairo_stroke(cr);
    
    cairo_destroy(cr);
}
コード例 #2
0
static void
camo_engine_render_background (GtkThemingEngine *engine,
                                  cairo_t          *cr,
                                  gdouble           x,
                                  gdouble           y,
                                  gdouble           width,
                                  gdouble           height)
{
  GdkRGBA color;
  GtkStateFlags flags = gtk_theming_engine_get_state (engine);
  gboolean generate = FALSE;
  gint scr_width, scr_height;

  gtk_theming_engine_get_background_color (engine, flags, &color);

  cairo_save (cr);

  if ((color.red == 0) && (color.green == 0) && (color.blue == 0)) {
    if (width > pool_width) {
      generate = TRUE;
      pool_width = width;
    }

    if (height > pool_height) {
      generate = TRUE;
      pool_height = height;
    }

    if (generate) {
      scr_width = gdk_screen_get_width (gdk_window_get_screen (gdk_get_default_root_window ()));
      scr_height = gdk_screen_get_height (gdk_window_get_screen (gdk_get_default_root_window ()));

      if (scr_width > pool_width)
        pool_width = scr_width;
      if (scr_height > pool_height)
        pool_height = scr_height;

      pool_gen ();
    }

    cairo_set_source_surface (cr, pool, 0, 0);
  }
  else
    gdk_cairo_set_source_rgba (cr, &color);

  cairo_rectangle (cr, x, y, width, height);
  cairo_fill (cr);

  cairo_restore (cr);
}
コード例 #3
0
static void
gb_source_gutter_renderer_diff_draw (GtkSourceGutterRenderer      *renderer,
                                     cairo_t                      *cr,
                                     GdkRectangle                 *bg_area,
                                     GdkRectangle                 *cell_area,
                                     GtkTextIter                  *begin,
                                     GtkTextIter                  *end,
                                     GtkSourceGutterRendererState  state)
{
   GbSourceGutterRendererDiffPrivate *priv;
   GbSourceGutterRendererDiff *diff = (GbSourceGutterRendererDiff *)renderer;
   GbSourceDiffState line_state;
   gint line;

   g_return_if_fail(GB_IS_SOURCE_GUTTER_RENDERER_DIFF(diff));

   priv = diff->priv;

   line = gtk_text_iter_get_line(begin);
   line_state = gb_source_diff_get_line_state(priv->diff, line + 1);

   switch (line_state) {
   case GB_SOURCE_DIFF_ADDED:
      gdk_cairo_rectangle(cr, cell_area);
      gdk_cairo_set_source_rgba(cr, &priv->rgba_added);
      cairo_fill(cr);
      break;
   case GB_SOURCE_DIFF_CHANGED:
      gdk_cairo_rectangle(cr, cell_area);
      gdk_cairo_set_source_rgba(cr, &priv->rgba_changed);
      cairo_fill(cr);
      break;
   case GB_SOURCE_DIFF_SAME:
   default:
      break;
   }
}
コード例 #4
0
static void
draw_volume_boxes (GsdMediaKeysWindow *window,
                   cairo_t            *cr,
                   double              percentage,
                   double              _x0,
                   double              _y0,
                   double              width,
                   double              height)
{
        gdouble   x1;
        GtkStyleContext *context;
        GdkRGBA  acolor;

        height = round (height) - 1;
        width = round (width) - 1;
        x1 = round ((width - 1) * percentage);
        context = gtk_widget_get_style_context (GTK_WIDGET (window));

        /* bar background */
        gtk_style_context_get_background_color (context, GTK_STATE_NORMAL, &acolor);
        gsd_osd_window_color_shade (&acolor, DARKNESS_MULT);
        gsd_osd_window_color_reverse (&acolor);
        acolor.alpha = GSD_OSD_WINDOW_FG_ALPHA / 2;
        gsd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0, _y0, height / 6, width, height);
        gdk_cairo_set_source_rgba (cr, &acolor);
        cairo_fill (cr);

        /* bar progress */
        if (percentage < 0.01)
                return;
        gtk_style_context_get_background_color (context, GTK_STATE_NORMAL, &acolor);
        acolor.alpha = GSD_OSD_WINDOW_FG_ALPHA;
        gsd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0, _y0, height / 6, x1, height);
        gdk_cairo_set_source_rgba (cr, &acolor);
        cairo_fill (cr);
}
コード例 #5
0
ファイル: colorsel.c プロジェクト: Pfiver/gtk
/* draw callback for the drawing area
 */
static gboolean
draw_callback (GtkWidget *widget,
               cairo_t   *cr,
               gpointer   data)
{
  GtkStyleContext *context;
  GdkRGBA rgba;

  context = gtk_widget_get_style_context (widget);
  gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &rgba);
  gdk_cairo_set_source_rgba (cr, &rgba);
  cairo_paint (cr);

  return TRUE;
}
コード例 #6
0
ファイル: gtkcssimagebuiltin.c プロジェクト: Distrotech/gtk
static void
gtk_css_image_builtin_draw_arrow (GtkCssImage            *image,
                                  cairo_t                *cr,
                                  double                  width,
                                  double                  height,
                                  GtkCssImageBuiltinType  image_type)
{
  GtkCssImageBuiltin *builtin = GTK_CSS_IMAGE_BUILTIN (image);
  double line_width;
  double size;

  size = MIN (width, height);

  cairo_translate (cr, width / 2.0, height / 2.0);
  switch (image_type)
  {
    case GTK_CSS_IMAGE_BUILTIN_ARROW_UP:
      break;
    case GTK_CSS_IMAGE_BUILTIN_ARROW_DOWN:
      cairo_rotate (cr, G_PI);
      break;
    case GTK_CSS_IMAGE_BUILTIN_ARROW_LEFT:
      cairo_rotate (cr, 3 * G_PI / 2);
      break;
    case GTK_CSS_IMAGE_BUILTIN_ARROW_RIGHT:
      cairo_rotate (cr, G_PI / 2);
      break;
    default:
      g_assert_not_reached ();
      break;
  }

  line_width = size / 3.0 / sqrt (2);
  cairo_set_line_width (cr, line_width);
  cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
  cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);

  cairo_scale (cr,
               (size / (size + line_width)),
               (size / (size + line_width)));

  cairo_move_to (cr, -size / 2.0, size / 4.0);
  cairo_rel_line_to (cr, size / 2.0, -size / 2.0);
  cairo_rel_line_to (cr, size / 2.0, size / 2.0);

  gdk_cairo_set_source_rgba (cr, &builtin->fg_color);
  cairo_stroke (cr);
}
コード例 #7
0
ファイル: ev-document-misc.c プロジェクト: Piiit/xreader
void
ev_document_misc_paint_one_page (cairo_t      *cr,
				 GtkWidget    *widget,
				 GdkRectangle *area,
				 GtkBorder    *border,
				 gboolean      highlight,
				 gboolean      inverted_colors)
{
	GtkStyleContext *context = gtk_widget_get_style_context (widget);
	GtkStateFlags state = gtk_widget_get_state_flags (widget);
    GdkRGBA fg, bg, shade_bg;

    gtk_style_context_save (context);
    gtk_style_context_get_background_color (context, state, &bg);
    gtk_style_context_get_color (context, state, &fg);
    gtk_style_context_get_color (context, state, &shade_bg);
    gtk_style_context_restore (context);
    shade_bg.alpha *= 0.5;

	gdk_cairo_set_source_rgba (cr, highlight ? &fg : &shade_bg);
	cairo_rectangle (cr,
			 area->x,
			 area->y,
			 area->width - border->right + border->left,
			 area->height - border->bottom + border->top);
	cairo_rectangle (cr,
			 area->x + area->width - border->right,
			 area->y + border->right - border->left,
			 border->right,
			 area->height - border->right + border->left);
	cairo_rectangle (cr,
			 area->x + border->bottom - border->top,
			 area->y + area->height - border->bottom,
			 area->width - border->bottom + border->top,
			 border->bottom);
	cairo_fill (cr);

	if (inverted_colors)
		cairo_set_source_rgb (cr, 0, 0, 0);
	else
		cairo_set_source_rgb (cr, 1, 1, 1);
	cairo_rectangle (cr,
			 area->x + border->left,
			 area->y + border->top,
			 area->width - (border->left + border->right),
			 area->height - (border->top + border->bottom));
	cairo_fill (cr);
}
コード例 #8
0
ファイル: colorsel.c プロジェクト: BYC/gtk
/* draw callback for the drawing area
 */
static gboolean
draw_callback (GtkWidget *widget,
               cairo_t   *cr,
               gpointer   data)
{
  GtkStyleContext *context;
  GdkRGBA *bg;

  context = gtk_widget_get_style_context (widget);
  gtk_style_context_get (context, 0, "background-color", &bg, NULL);
  gdk_cairo_set_source_rgba (cr, bg);
  cairo_paint (cr);
  gdk_rgba_free (bg);

  return TRUE;
}
コード例 #9
0
ファイル: gtkthemingbackground.c プロジェクト: 3v1n0/gtk
static void
_gtk_theming_background_paint_color (GtkThemingBackground *bg,
                                     cairo_t              *cr,
                                     const GdkRGBA        *bg_color,
                                     GtkCssValue          *background_image)
{
  gint n_values = _gtk_css_array_value_get_n_values (background_image);
  GtkCssArea clip = _gtk_css_area_value_get 
    (_gtk_css_array_value_get_nth 
     (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_CLIP), 
      n_values - 1));

  _gtk_rounded_box_path (&bg->boxes[clip], cr);
  gdk_cairo_set_source_rgba (cr, bg_color);
  cairo_fill (cr);
}
コード例 #10
0
ファイル: mate-rr-labeler.c プロジェクト: dnk/mate-desktop
label_window_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
#endif
{
#if GTK_CHECK_VERSION (3, 0, 0)
	GdkRGBA *color;
#else
	GdkColor *color;
#endif
	GtkAllocation allocation;

	color = g_object_get_data (G_OBJECT (widget), "color");
	gtk_widget_get_allocation (widget, &allocation);

#if !GTK_CHECK_VERSION (3, 0, 0)
	cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
#endif

	/* edge outline */

	cairo_set_source_rgb (cr, 0, 0, 0);
	cairo_rectangle (cr,
			 LABEL_WINDOW_EDGE_THICKNESS / 2.0,
			 LABEL_WINDOW_EDGE_THICKNESS / 2.0,
			 allocation.width - LABEL_WINDOW_EDGE_THICKNESS,
			 allocation.height - LABEL_WINDOW_EDGE_THICKNESS);
	cairo_set_line_width (cr, LABEL_WINDOW_EDGE_THICKNESS);
	cairo_stroke (cr);

	/* fill */
#if GTK_CHECK_VERSION (3, 0, 0)
	gdk_cairo_set_source_rgba (cr, color);
#else
	gdk_cairo_set_source_color (cr, color);
#endif
	cairo_rectangle (cr,
			 LABEL_WINDOW_EDGE_THICKNESS,
			 LABEL_WINDOW_EDGE_THICKNESS,
			 allocation.width - LABEL_WINDOW_EDGE_THICKNESS * 2,
			 allocation.height - LABEL_WINDOW_EDGE_THICKNESS * 2);
	cairo_fill (cr);

#if !GTK_CHECK_VERSION (3, 0, 0)
	cairo_destroy (cr);
#endif

	return FALSE;
}
コード例 #11
0
ファイル: canvas.c プロジェクト: valisc/freeciv
/****************************************************************************
  Draw a colored curved line for the Technology Tree connectors
  A curved line is: 1 horizontal line, 2 arcs, 1 horizontal line
****************************************************************************/
void canvas_put_curved_line(struct canvas *pcanvas,
                            struct color *pcolor,
                            enum line_type ltype, int start_x, int start_y,
                            int dx, int dy)
{
  int end_x = start_x + dx;
  int end_y = start_y + dy;
  cairo_t *cr;
  double dashes[2] = {4.0, 4.0};

  if (!pcanvas->drawable) {
    cr = cairo_create(pcanvas->surface);
  } else {
    cr = pcanvas->drawable;
  }

  if (pcanvas->drawable) {
    cairo_save(cr);
  }

  switch (ltype) {
  case LINE_NORMAL:
    cairo_set_line_width(cr, 1.);
    break;
  case LINE_BORDER:
    cairo_set_dash(cr, dashes, 2, 0);
    cairo_set_line_width(cr, (double)BORDER_WIDTH);
    break;
  case LINE_TILE_FRAME:
    cairo_set_line_width(cr, 2.);
    break;
  case LINE_GOTO:
    cairo_set_line_width(cr, 2.);
    break;
  }

  gdk_cairo_set_source_rgba(cr, &pcolor->color);
  cairo_move_to(cr, start_x, start_y);
  cairo_curve_to(cr, end_x, start_y, start_x, end_y, end_x, end_y);
  cairo_stroke(cr);

  if (!pcanvas->drawable) {
    cairo_destroy(cr);
  } else {
    cairo_restore(cr);
  }
}
コード例 #12
0
static GdkPixbuf *
logged_in_pixbuf (GdkPixbuf *pixbuf, gint scale)
{
        cairo_format_t format;
        cairo_surface_t *surface;
        cairo_pattern_t *pattern;
        cairo_t *cr;
        gint width, height;
        GdkRGBA color;

        width = gdk_pixbuf_get_width (pixbuf);
        height = gdk_pixbuf_get_height (pixbuf);

        g_return_val_if_fail (width > 15 && height > 15, pixbuf);

        format = gdk_pixbuf_get_has_alpha (pixbuf) ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24;
        surface = cairo_image_surface_create (format, width, height);
        cr = cairo_create (surface);

        gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
        cairo_paint (cr);

        /* Draw pattern */
        cairo_rectangle (cr, 0, 0, width, height);
        pattern = cairo_pattern_create_radial (width - 9.5 * scale, height - 10 * scale, 0,
                                               width - 8.5 * scale, height - 7.5 * scale, 7.7 * scale);
        cairo_pattern_add_color_stop_rgb (pattern, 0, 0.4, 0.9, 0);
        cairo_pattern_add_color_stop_rgb (pattern, 0.7, 0.3, 0.6, 0);
        cairo_pattern_add_color_stop_rgb (pattern, 0.8, 0.4, 0.4, 0.4);
        cairo_pattern_add_color_stop_rgba (pattern, 1.0, 0, 0, 0, 0);
        cairo_set_source (cr, pattern);
        cairo_fill (cr);

        /* Draw border */
        cairo_set_line_width (cr, 0.9 * scale);
        cairo_arc (cr, width - 8.5 * scale, height - 8.5 * scale, 6 * scale, 0, 2 * G_PI);
        gdk_rgba_parse (&color, "#ffffff");
        gdk_cairo_set_source_rgba (cr, &color);
        cairo_stroke (cr);

        pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);

        cairo_surface_finish (surface);
        cairo_destroy (cr);

        return pixbuf;
}
コード例 #13
0
ファイル: unico-draw.c プロジェクト: Distrotech/unico
static void
unico_draw_arrow (GtkThemingEngine *engine,
                  cairo_t          *cr,
                  gdouble           angle,
                  gdouble           x,
                  gdouble           y,
                  gdouble           size)
{
  GtkStateFlags state;
  GdkRGBA color;
  gdouble size_reduction = 4;

  if (draw_arrow_texture (engine, cr, angle, x, y, size))
    return;

  state = gtk_theming_engine_get_state (engine);

  gtk_theming_engine_get_color (engine, state, &color);

  cairo_save (cr);

  /* use floor function to adjust doubles */
  y = floor (y);
  x = floor (x);
  size = floor (size);

  size -= size_reduction;

  cairo_translate (cr, size_reduction / 2, size_reduction / 2);

  cairo_translate (cr, x + (gint)(size / 2) - 0.5, y + (gint)(size / 2) + 0.5);
  cairo_rotate (cr, angle);

  cairo_move_to (cr, 0, - (gint)(size / 2));
  cairo_line_to (cr, - (gint)(size / 2), (gint)(size / 4));
  cairo_line_to (cr, (gint)(size / 2), (gint)(size / 4));
  cairo_close_path (cr);

  cairo_set_source_rgba (cr, color.red, color.green, color.blue, color.alpha * 0.75);
  cairo_fill_preserve (cr);

  gdk_cairo_set_source_rgba (cr, &color);
  cairo_stroke (cr);

  cairo_restore (cr);
}
コード例 #14
0
static void
apply_style (GtkSourceGutter *gutter,
	     GtkSourceView   *view,
	     GtkStyleContext *style_context,
	     cairo_t         *cr)
{
	const gchar *class;
	GdkRGBA fg_color;

	switch (gutter->priv->window_type)
	{
		case GTK_TEXT_WINDOW_TOP:
			class = GTK_STYLE_CLASS_TOP;
			break;

		case GTK_TEXT_WINDOW_RIGHT:
			class = GTK_STYLE_CLASS_RIGHT;
			break;

		case GTK_TEXT_WINDOW_BOTTOM:
			class = GTK_STYLE_CLASS_BOTTOM;
			break;

		case GTK_TEXT_WINDOW_LEFT:
			class = GTK_STYLE_CLASS_LEFT;
			break;

		case GTK_TEXT_WINDOW_PRIVATE:
		case GTK_TEXT_WINDOW_WIDGET:
		case GTK_TEXT_WINDOW_TEXT:
		default:
			g_return_if_reached ();
	}

	/* Apply classes ourselves, since we are in connect_after and so they
	 * are not set by gtk.
	 */
	gtk_style_context_add_class (style_context, class);

	gtk_style_context_get_color (style_context,
	                             gtk_widget_get_state_flags (GTK_WIDGET (view)),
	                             &fg_color);

	gdk_cairo_set_source_rgba (cr, &fg_color);
}
コード例 #15
0
static gboolean
gstyle_slidein_draw (GtkWidget *widget,
                     cairo_t   *cr)
{
  GstyleSlidein *self = (GstyleSlidein *)widget;
  GtkStyleContext *context;
  GtkAllocation shade_box;
  GtkWidget *child;
  GdkRGBA rgba;

  g_assert (GSTYLE_IS_SLIDEIN (self));
  g_assert (cr != NULL);

  /* To draw the shade effect in between the regular child and the slides,
   * we bypass gtk_event_box_draw (we use a windowless one so not a problem),
   * and provide your own container draw implementation.
   */

  child = gtk_bin_get_child (GTK_BIN (self));
  if (child == NULL)
    return GDK_EVENT_STOP;

  gtk_container_propagate_draw (GTK_CONTAINER (self), child, cr);

  if (self->offset > 0.0)
    {
      context = gtk_widget_get_style_context (widget);
      gtk_style_context_save (context);
      gtk_style_context_add_class (context, "shade");
      gtk_style_context_get_color (context, gtk_style_context_get_state (context), &rgba);
      gtk_style_context_restore (context);
      rgba.alpha = rgba.alpha * self->offset;

      /* We shade the whole surface in case of slide tranparency */
      gtk_widget_get_allocated_size (widget, &shade_box, NULL);
      cairo_rectangle (cr, shade_box.x, shade_box.y, shade_box.width, shade_box.height);
      gdk_cairo_set_source_rgba (cr, &rgba);
      cairo_fill (cr);
    }

  if (self->overlay_child != NULL)
   gtk_container_propagate_draw (GTK_CONTAINER (self), self->overlay_child, cr);

  return GDK_EVENT_STOP;
}
コード例 #16
0
ファイル: gtkcolorswatch.c プロジェクト: grubersjoe/adwaita
static void
drag_set_color_icon (GdkDragContext *context,
                     const GdkRGBA  *color)
{
    cairo_surface_t *surface;
    cairo_t *cr;

    surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 48, 32);
    cr = cairo_create (surface);
    gdk_cairo_set_source_rgba (cr, color);
    cairo_paint (cr);

    cairo_surface_set_device_offset (surface, -4, -4);
    gtk_drag_set_icon_surface (context, surface);

    cairo_destroy (cr);
    cairo_surface_destroy (surface);
}
コード例 #17
0
static void
gimp_ruler_draw_pos (GimpRuler *ruler,
                     cairo_t   *cr)
{
  GtkWidget        *widget  = GTK_WIDGET (ruler);
  GtkStyleContext  *context = gtk_widget_get_style_context (widget);
  GimpRulerPrivate *priv    = GIMP_RULER_GET_PRIVATE (ruler);
  GdkRectangle      pos_rect;

  if (! gtk_widget_is_drawable (widget))
    return;

  pos_rect = gimp_ruler_get_pos_rect (ruler, gimp_ruler_get_position (ruler));

  if ((pos_rect.width > 0) && (pos_rect.height > 0))
    {
      GdkRGBA color;

      gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget),
                                   &color);
      gdk_cairo_set_source_rgba (cr, &color);

      cairo_move_to (cr, pos_rect.x, pos_rect.y);

      if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
        {
          cairo_line_to (cr, pos_rect.x + pos_rect.width / 2.0,
                             pos_rect.y + pos_rect.height);
          cairo_line_to (cr, pos_rect.x + pos_rect.width,
                             pos_rect.y);
        }
      else
        {
          cairo_line_to (cr, pos_rect.x + pos_rect.width,
                             pos_rect.y + pos_rect.height / 2.0);
          cairo_line_to (cr, pos_rect.x,
                             pos_rect.y + pos_rect.height);
        }

      cairo_fill (cr);
    }

  priv->last_pos_rect = pos_rect;
}
コード例 #18
0
ファイル: gtkcellview.c プロジェクト: BYC/gtk
static gboolean
gtk_cell_view_draw (GtkWidget *widget,
                    cairo_t   *cr)
{
  GtkCellView *cellview;
  GdkRectangle area;
  GtkCellRendererState state;

  cellview = GTK_CELL_VIEW (widget);

  /* render cells */
  area.x = 0;
  area.y = 0;
  area.width  = gtk_widget_get_allocated_width (widget);
  area.height = gtk_widget_get_allocated_height (widget);

  /* "blank" background */
  if (cellview->priv->background_set)
    {
      gdk_cairo_rectangle (cr, &area);
      gdk_cairo_set_source_rgba (cr, &cellview->priv->background);
      cairo_fill (cr);
    }

  /* set cell data (if available) */
  if (cellview->priv->displayed_row)
    gtk_cell_view_set_cell_data (cellview);
  else if (cellview->priv->model)
    return FALSE;

  if (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_PRELIGHT)
    state = GTK_CELL_RENDERER_PRELIT;
  else if (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_INSENSITIVE)
    state = GTK_CELL_RENDERER_INSENSITIVE;
  else
    state = 0;
      
  /* Render the cells */
  gtk_cell_area_render (cellview->priv->area, cellview->priv->context, 
			widget, cr, &area, &area, state, FALSE);

  return FALSE;
}
コード例 #19
0
ファイル: tile-preview.c プロジェクト: adzymaniac/muffin
static gboolean
meta_tile_preview_draw (GtkWidget *widget,
                        cairo_t   *cr,
                        gpointer   user_data)
{
  MetaTilePreview *preview = user_data;

  cairo_set_line_width (cr, 1.0);

  if (preview->has_alpha)
    {
      /* Fill the preview area with a transparent color */
      gdk_cairo_set_source_rgba (cr, preview->preview_color);

      cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
      cairo_paint (cr);

      /* Use the opaque color for the border */
      cairo_set_source_rgb (cr,
                            preview->preview_color->red,
                            preview->preview_color->green,
                            preview->preview_color->blue);
    }
  else
    {
      cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);

      cairo_rectangle (cr,
                       OUTLINE_WIDTH - 0.5, OUTLINE_WIDTH - 0.5,
                       preview->tile_rect.width - 2 * (OUTLINE_WIDTH - 1) - 1,
                       preview->tile_rect.height - 2 * (OUTLINE_WIDTH - 1) - 1);
      cairo_stroke (cr);
    }

  cairo_rectangle (cr,
                   0.5, 0.5,
                   preview->tile_rect.width - 1,
                   preview->tile_rect.height - 1);
  cairo_stroke (cr);

  return FALSE;
}
コード例 #20
0
static void
renderer_draw_impl (GtkSourceGutterRenderer      *renderer,
                    cairo_t                      *cr,
                    GdkRectangle                 *background_area,
                    GdkRectangle                 *cell_area,
                    GtkTextIter                  *start,
                    GtkTextIter                  *end,
                    GtkSourceGutterRendererState  state)
{
	if (renderer->priv->background_set)
	{
		cairo_save (cr);

		gdk_cairo_rectangle (cr, background_area);
		gdk_cairo_set_source_rgba (cr, &renderer->priv->background_color);

		cairo_fill (cr);
		cairo_restore (cr);
	}
}
コード例 #21
0
ファイル: wire.c プロジェクト: neuroidss/oregano
static void wire_print (ItemData *data, cairo_t *cr, SchematicPrintContext *ctx)
{
    Coords start_pos, end_pos;
    Wire *wire;

    g_return_if_fail (data != NULL);
    g_return_if_fail (IS_WIRE (data));

    wire = WIRE (data);

    wire_get_start_pos (wire, &start_pos);
    wire_get_end_pos (wire, &end_pos);

    cairo_save (cr);
    gdk_cairo_set_source_rgba (cr, &ctx->colors.wires);
    cairo_move_to (cr, start_pos.x, start_pos.y);
    cairo_line_to (cr, end_pos.x, end_pos.y);
    cairo_stroke (cr);
    cairo_restore (cr);
}
コード例 #22
0
//!
//! @brief To be written
//!
void gw_kanjipadwindow_draw_candidates (GwKanjipadWindow *window)
{
    //Declarations
    GwKanjipadWindowPrivate *priv;
    //gint width;
    //gint height;
    int i;
    cairo_t *cr;
    GtkStyleContext *context;
    GtkStateFlags state;
    GdkRGBA bgcolor;

    //Initializations
    priv = window->priv;
    //height = gtk_widget_get_allocated_height (GTK_WIDGET (priv->candidates));
    //width = gtk_widget_get_allocated_width (GTK_WIDGET (priv->candidates));
    cr = cairo_create (priv->ksurface);
    context = gtk_widget_get_style_context (GTK_WIDGET (priv->candidates));
    state = gtk_widget_get_state_flags (GTK_WIDGET (priv->drawingarea));
    gtk_style_context_get_background_color (context, state, &bgcolor);

    cairo_save (cr);
    gdk_cairo_set_source_rgba (cr, &bgcolor);
    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
    cairo_paint (cr);
    cairo_fill (cr);
    cairo_restore (cr);

    for (i = 0; i < priv->total_candidates; i++)
    {
      if (strcmp (priv->kselected, priv->kanji_candidates[i]) == 0)
        _kanjipadwindow_draw_candidate_character (window, i, 1);
      else
        _kanjipadwindow_draw_candidate_character (window, i, -1);
    }

    gtk_widget_queue_draw (GTK_WIDGET (priv->candidates));

    cairo_destroy (cr);
    cr = NULL;
}
コード例 #23
0
ファイル: biji-note-obj.c プロジェクト: Abdillah/bijiben
static GdkPixbuf *
biji_note_obj_get_emblem (BijiItem *item)
{
  GdkRGBA                note_color;
  cairo_t               *cr;
  cairo_surface_t       *surface = NULL;
  BijiNoteObj           *note = BIJI_NOTE_OBJ (item);

  if (note->priv->emblem)
    return note->priv->emblem;

  /* Create & Draw surface */
  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                        BIJI_EMBLEM_WIDTH,
                                        BIJI_EMBLEM_HEIGHT) ;
  cr = cairo_create (surface);

  /* Background */
  cairo_rectangle (cr, 0, 0, BIJI_EMBLEM_WIDTH, BIJI_EMBLEM_HEIGHT);
  if (biji_note_obj_get_rgba (note, &note_color))
    gdk_cairo_set_source_rgba (cr, &note_color);

  cairo_fill (cr);

  /* Border */
  cairo_set_source_rgba (cr, 0.3, 0.3, 0.3, 1);
  cairo_set_line_width (cr, 1);
  cairo_rectangle (cr, 0, 0, BIJI_EMBLEM_WIDTH, BIJI_EMBLEM_HEIGHT);
  cairo_stroke (cr);

  cairo_destroy (cr);

  note->priv->emblem = gdk_pixbuf_get_from_surface (surface,
                                                    0, 0,
                                                    BIJI_EMBLEM_WIDTH,
                                                    BIJI_EMBLEM_HEIGHT);

  cairo_surface_destroy (surface);

  return note->priv->emblem;
}
コード例 #24
0
ファイル: gtkcssimagefallback.c プロジェクト: Vort/gtk
static void
gtk_css_image_fallback_draw (GtkCssImage *image,
                             cairo_t     *cr,
                             double       width,
                             double       height)
{
  GtkCssImageFallback *fallback = GTK_CSS_IMAGE_FALLBACK (image);

  if (fallback->used < 0)
    {
      if (fallback->color)
        gdk_cairo_set_source_rgba (cr, _gtk_css_rgba_value_get_rgba (fallback->color));
      else
        cairo_set_source_rgb (cr, 1, 0, 9);

      cairo_rectangle (cr, 0, 0, width, height);
      cairo_fill (cr);
    }
  else
    _gtk_css_image_draw (fallback->images[fallback->used], cr, width, height);
}
コード例 #25
0
static gboolean
color_swatch_draw_cb (GtkWidget *drawing_area,
                      cairo_t *cr)
{
	GtkStyleContext *style_context;
	GdkRGBA rgba;
	GdkRectangle rect;

	style_context = gtk_widget_get_style_context (drawing_area);
	if (!style_context)
		return FALSE;

	gtk_style_context_get_background_color (style_context, GTK_STATE_FLAG_NORMAL, &rgba);

	gdk_cairo_get_clip_rectangle (cr, &rect);
	gdk_cairo_set_source_rgba (cr, &rgba);
	gdk_cairo_rectangle (cr, &rect);
	cairo_fill (cr);

	return FALSE;
}
コード例 #26
0
static gboolean
ido_media_player_menu_item_draw (GtkWidget *widget,
                                 cairo_t   *cr)
{
  IdoMediaPlayerMenuItem *self = IDO_MEDIA_PLAYER_MENU_ITEM (widget);

  GTK_WIDGET_CLASS (ido_media_player_menu_item_parent_class)->draw (widget, cr);

  /* draw a triangle next to the application name if the app is running */
  if (self->running)
    {
      const int arrow_width = 5;
      const int half_arrow_height = 4;

      GdkRGBA color;
      GtkAllocation allocation;
      GtkAllocation label_allocation;
      int x;
      int y;

      gtk_style_context_get_color (gtk_widget_get_style_context (widget),
                                   gtk_widget_get_state (widget),
                                   &color);

      gtk_widget_get_allocation (widget, &allocation);
      gtk_widget_get_allocation (self->player_label, &label_allocation);
      x = allocation.x;
      y = label_allocation.y - allocation.y + label_allocation.height / 2;

      cairo_move_to (cr, x, y - half_arrow_height);
      cairo_line_to (cr, x, y + half_arrow_height);
      cairo_line_to (cr, x + arrow_width, y);
      cairo_close_path (cr);

      gdk_cairo_set_source_rgba (cr, &color);
      cairo_fill (cr);
    }

  return FALSE;
}
コード例 #27
0
static gboolean
cb_treeview_draw (GtkWidget *widget,
		  cairo_t *cr,
		  StfDialogData *pagedata)
{
	int ruler_x = pagedata->fixed.ruler_x;
	int height;
	GtkAllocation a;
	GdkWindow *bin_window;
	GdkRGBA ruler_color;
	GtkStyleContext *context;

	if (ruler_x < 0)
		return FALSE;

	bin_window = gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget));
	if (!gtk_cairo_should_draw_window (cr, bin_window))
		return FALSE;

	gtk_widget_get_allocation (widget, &a);
	height = a.height;

	context = gtk_widget_get_style_context (GTK_WIDGET (pagedata->dialog));
	gtk_style_context_save (context);
	gtk_style_context_add_region (context, "fixed-format-ruler", 0);
	gnm_style_context_get_color (context, GTK_STATE_FLAG_NORMAL,
				     &ruler_color);
	gtk_style_context_restore (context);

	cairo_save (cr);
	cairo_rectangle (cr, ruler_x, 0, ruler_x + 1, height);
	cairo_clip (cr);
	gdk_cairo_set_source_rgba (cr, &ruler_color);
	cairo_move_to (cr, ruler_x, 0);
	cairo_line_to (cr, ruler_x, height);
	cairo_stroke (cr);
	cairo_restore (cr);

	return FALSE;
}
コード例 #28
0
static gboolean
label_draw(GtkWidget *label, cairo_t *cr, gpointer data)
{
  UIMCandWinHorizontalGtk *horizontal_cwin = data;
  struct index_button *selected;
  GtkWidget *selected_label = NULL;
  GdkRGBA *bg_color, *fg_color;
  GtkStyleContext *context;
  PangoLayout *layout;
  gint x, y;
  GtkStateFlags state;

  selected = horizontal_cwin->selected;
  if (selected)
    selected_label = gtk_bin_get_child(GTK_BIN(selected->button));

  layout = gtk_label_get_layout(GTK_LABEL(label));
  gtk_label_get_layout_offsets(GTK_LABEL(label), &x, &y);

  context = gtk_widget_get_style_context(label);

  if (label == selected_label)
    state = GTK_STATE_FLAG_SELECTED;
  else
    state = GTK_STATE_FLAG_NORMAL;

  gtk_style_context_get (context, state, "background-color", &bg_color, "color", &fg_color, NULL);

  cairo_save(cr);
  gdk_cairo_set_source_rgba(cr, bg_color);
  cairo_paint(cr);
  cairo_restore(cr);
  gdk_rgba_free(bg_color);
  gdk_rgba_free(fg_color);

  gtk_style_context_set_state (context, state);
  gtk_render_layout (context, cr, x, y, layout);

  return FALSE;
}
コード例 #29
0
/* create a menu-sized pixbuf filled with specified color */
static GdkPixbuf *
create_color_icon_pixbuf (const char * color_spec)
{
  static int width = -1;
  static int height = -1;
  GdkPixbuf * pixbuf = NULL;

  if (width == -1)
    {
      gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
      width = CLAMP (width, 10, 30);
      height = CLAMP (height, 10, 30);
    }

  if (color_spec && *color_spec)
    {
      cairo_surface_t * surface;
      cairo_t * cr;
      GdkRGBA rgba;

      surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
      cr = cairo_create (surface);

      if (gdk_rgba_parse (&rgba, color_spec))
        gdk_cairo_set_source_rgba (cr, &rgba);

      cairo_paint (cr);
      cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
      cairo_set_line_width (cr, 1);
      cairo_rectangle (cr, 0.5, 0.5, width-1, height-1);
      cairo_stroke (cr);

      pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);

      cairo_destroy (cr);
      cairo_surface_destroy (surface);
    }

  return pixbuf;
}
コード例 #30
0
static void
gimp_cell_renderer_dashes_render (GtkCellRenderer      *cell,
                                  cairo_t              *cr,
                                  GtkWidget            *widget,
                                  const GdkRectangle   *background_area,
                                  const GdkRectangle   *cell_area,
                                  GtkCellRendererState  flags)
{
  GimpCellRendererDashes *dashes = GIMP_CELL_RENDERER_DASHES (cell);
  GtkStyleContext        *style  = gtk_widget_get_style_context (widget);
  GtkStateType            state;
  GdkRGBA                 color;
  gint                    xpad, ypad;
  gint                    width;
  gint                    x, y;

  gtk_cell_renderer_get_padding (cell, &xpad, &ypad);

  state = gtk_cell_renderer_get_state (cell, widget, flags);

  y = cell_area->y + (cell_area->height - DASHES_HEIGHT) / 2;
  width = cell_area->width - 2 * xpad;

  for (x = 0; x < width + BLOCK_WIDTH; x += BLOCK_WIDTH)
    {
      guint index = ((guint) x / BLOCK_WIDTH) % N_SEGMENTS;

      if (dashes->segments[index])
        {
          cairo_rectangle (cr,
                           cell_area->x + xpad + x, y,
                           MIN (BLOCK_WIDTH, width - x), DASHES_HEIGHT);
        }
    }

  gtk_style_context_get_color (style, state, &color);
  gdk_cairo_set_source_rgba (cr, &color);

  cairo_fill (cr);
}