コード例 #1
0
static gboolean _tristatebutton_button_press(GtkWidget *widget, GdkEventButton *eb, gpointer data)
{
  gint cs = DTGTK_TRISTATEBUTTON(widget)->state + 1;
  /* handle left click on tristate button */
  if(eb->button == 1) cs %= 3;
  /* handle right click on tristate button */
  else if(eb->button == 2)
    cs = 0;

  dtgtk_tristatebutton_set_state(DTGTK_TRISTATEBUTTON(widget), cs);
  gtk_widget_queue_draw(widget);

  /* lets other connected get the signal... */
  return FALSE;
}
コード例 #2
0
ファイル: modulelist.c プロジェクト: sk1p/darktable
static void _lib_modulelist_populate_callback(gpointer instance, gpointer user_data)
{
  dt_lib_module_t *self = (dt_lib_module_t *)user_data;

  /* go thru list of iop modules and add tp table */
  GList *modules = g_list_last(darktable.develop->iop);
  int ti = 0, tj = 0;
  while(modules)
  {
    dt_iop_module_t *module = (dt_iop_module_t *)(modules->data);
    if(!dt_iop_is_hidden(module) && !(module->flags() & IOP_FLAGS_DEPRECATED))
    {
      module->showhide = dtgtk_tristatebutton_new(NULL,0);
      char filename[1024], datadir[1024];
      dt_loc_get_datadir(datadir, 1024);
      snprintf(filename, 1024, "%s/pixmaps/plugins/darkroom/%s.png", datadir, module->op);
      if(!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
	snprintf(filename, 1024, "%s/pixmaps/plugins/darkroom/template.png", datadir);
      GtkWidget *image = gtk_image_new_from_file(filename);
      gtk_button_set_image(GTK_BUTTON(module->showhide), image);

      /* set button state */
      char option[1024];
      snprintf(option, 1024, "plugins/darkroom/%s/visible", module->op);
      gboolean active = dt_conf_get_bool (option);
      snprintf(option, 1024, "plugins/darkroom/%s/favorite", module->op);
      gboolean favorite = dt_conf_get_bool (option);
      gint state=0;
      if(active)
      {
	state++;
	if(favorite) state++;
      }
      _lib_modulelist_tristate_set_state(module->showhide,state,module);
      dtgtk_tristatebutton_set_state(DTGTK_TRISTATEBUTTON(module->showhide), state);

      /* connect tristate button callback*/
      g_signal_connect(G_OBJECT(module->showhide), "tristate-changed",
		       G_CALLBACK(_lib_modulelist_tristate_changed_callback), module);
      gtk_table_attach(GTK_TABLE(self->widget), module->showhide, ti, ti+1, tj, tj+1,
		       GTK_FILL | GTK_EXPAND | GTK_SHRINK,
		       GTK_SHRINK,
		       0, 0);
      if(ti < 5) ti++;
      else { ti = 0; tj ++; }
    }

    modules = g_list_previous(modules);
  }
}
コード例 #3
0
static gboolean _tristatebutton_expose(GtkWidget *widget, GdkEventExpose *event)
{
  g_return_val_if_fail(widget != NULL, FALSE);
  g_return_val_if_fail(DTGTK_IS_TRISTATEBUTTON(widget), FALSE);
  g_return_val_if_fail(event != NULL, FALSE);
  GtkStyle *style = gtk_widget_get_style(widget);
  int state = gtk_widget_get_state(widget);

  /* fix text style */
  for(int i = 0; i < 5; i++) style->text[i] = style->fg[i];

  /* fetch flags */
  int flags = DTGTK_TRISTATEBUTTON(widget)->icon_flags;

  /* set inner border */
  int border = DT_PIXEL_APPLY_DPI((flags & CPF_DO_NOT_USE_BORDER) ? 2 : 6);

  /* update active state paint flag */
  gboolean active = DTGTK_TRISTATEBUTTON(widget)->state > 0;
  if(active)
    flags |= CPF_ACTIVE;
  else
    flags &= ~(CPF_ACTIVE);


  /* begin cairo drawing */
  cairo_t *cr;
  cr = gdk_cairo_create(gtk_widget_get_window(widget));

  GtkAllocation allocation;
  gtk_widget_get_allocation(widget, &allocation);
  int x = allocation.x;
  int y = allocation.y;
  int width = allocation.width;
  int height = allocation.height;

  /* draw standard button background if not transparent nor flat styled */
  if((flags & CPF_STYLE_FLAT))
  {
    if(state != GTK_STATE_NORMAL)
    {
      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);
    }
  }
  else if(!(flags & CPF_BG_TRANSPARENT))
  {
    cairo_rectangle(cr, x, y, width, height);
    float rs = 1.0, gs = 1.0, bs = 1.0;

    if(DTGTK_TRISTATEBUTTON(widget)->state == 1)
      rs = gs = bs = 3.0;
    else if(DTGTK_TRISTATEBUTTON(widget)->state == 2)
      rs = 3.0;

    cairo_set_source_rgba(cr, (style->bg[state].red / 65535.0) * rs, (style->bg[state].green / 65535.0) * gs,
                          (style->bg[state].blue / 65535.0) * bs, 0.5);
    cairo_fill(cr);
  }

  /* create pango text settings if label exists */
  PangoLayout *layout = NULL;
  int pw = 0, ph = 0;
  const gchar *text = gtk_button_get_label(GTK_BUTTON(widget));
  if(text)
  {
    layout = pango_cairo_create_layout(cr);
    pango_layout_set_font_description(layout, darktable.bauhaus->pango_font_desc);
    pango_cairo_context_set_resolution(pango_layout_get_context(layout), darktable.gui->dpi);
    pango_layout_set_text(layout, text, -1);
    pango_layout_get_pixel_size(layout, &pw, &ph);
  }

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

  /* draw button image if any */
  GtkWidget *image = gtk_button_get_image(GTK_BUTTON(widget));
  if(image)
  {
    GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));

    if(pixbuf)
    {
      /* Draw the pixbuf */
      gint pbw = gdk_pixbuf_get_width(pixbuf);
      gint pbh = gdk_pixbuf_get_height(pixbuf);
      gdk_cairo_set_source_pixbuf(cr, pixbuf, allocation.x + ((allocation.width / 2) - (pbw / 2)),
                                  allocation.y + ((allocation.height / 2) - (pbh / 2)));
      cairo_paint(cr);
    }
  }


  /* draw icon */
  if(DTGTK_TRISTATEBUTTON(widget)->icon)
  {
    //     if (flags & CPF_IGNORE_FG_STATE)
    //       state = GTK_STATE_NORMAL;


    if(text)
      DTGTK_TRISTATEBUTTON(widget)
          ->icon(cr, x + border, y + border, height - (border * 2), height - (border * 2), flags);
    else
      DTGTK_TRISTATEBUTTON(widget)
          ->icon(cr, x + border, y + border, width - (border * 2), height - (border * 2), flags);
  }


  /* draw label */
  if(text)
  {
    int lx = x + DT_PIXEL_APPLY_DPI(2), ly = y + ((height / 2.0) - (ph / 2.0));
    cairo_translate(cr, lx, ly);
    pango_cairo_show_layout(cr, layout);
    g_object_unref(layout);
  }

  cairo_destroy(cr);

  return FALSE;
}