示例#1
0
文件: icon.c 项目: ksyz/darktable
static gboolean
_icon_expose (GtkWidget *widget, GdkEventExpose *event)
{
    g_return_val_if_fail (widget != NULL, FALSE);
    g_return_val_if_fail (DTGTK_IS_ICON(widget), FALSE);
    g_return_val_if_fail (event != NULL, FALSE);
    GtkStyle *style=gtk_widget_get_style(widget);
    int state = gtk_widget_get_state(widget);
    int border = 0;

    /* update paint flags depending of states */
    int flags = DTGTK_ICON(widget)->icon_flags;


    /* begin cairo drawing */
    cairo_t *cr;
    GtkAllocation allocation;
    gtk_widget_get_allocation(widget, &allocation);
    cr = gdk_cairo_create (gtk_widget_get_window(widget));

    int x = allocation.x;
    int y = allocation.y;
    int width = allocation.width;
    int height = allocation.height;

    /*
        cairo_rectangle (cr,x,y,width,height);
        cairo_set_source_rgba (cr,
                               style->bg[state].red/65535.0,
                               style->bg[state].green/65535.0,
                               style->bg[state].blue/65535.0,
                               0.5);
        cairo_fill (cr);
    */

    cairo_set_source_rgb (cr,
                          style->fg[state].red/65535.0,
                          style->fg[state].green/65535.0,
                          style->fg[state].blue/65535.0);

    /* draw icon */
    if (DTGTK_ICON(widget)->icon)
        DTGTK_ICON(widget)->icon(cr, x+border, y+border, width-(border*2), height-(border*2), flags);

    cairo_destroy (cr);

    return FALSE;
}
示例#2
0
文件: icon.c 项目: CarVac/darktable
static gboolean _icon_draw(GtkWidget *widget, cairo_t *cr)
{
  g_return_val_if_fail(widget != NULL, FALSE);
  g_return_val_if_fail(DTGTK_IS_ICON(widget), FALSE);

  /* begin cairo drawing */
  GtkAllocation allocation;
  gtk_widget_get_allocation(widget, &allocation);

  GtkStateFlags state = gtk_widget_get_state_flags(widget);

  GdkRGBA fg_color;
  GtkStyleContext *context = gtk_widget_get_style_context(widget);
  gtk_style_context_get_color(context, state, &fg_color);

  gdk_cairo_set_source_rgba(cr, &fg_color);

  /* draw icon */
  if(DTGTK_ICON(widget)->icon)
    DTGTK_ICON(widget)->icon(cr, 0, 0, allocation.width, allocation.height, DTGTK_ICON(widget)->icon_flags);

  return FALSE;
}