Ejemplo n.º 1
0
static void
lookup_color (GtkStyleContext *style_context, const gchar *name, GdkRGBA *result)
{
	if (!gtk_style_context_lookup_color (style_context, name, result)) {
		g_warning ("Failed to look up color %s", name);
	}
}
Ejemplo n.º 2
0
static gboolean
draw_callback (GtkWidget *widget,
               cairo_t *cr,
               gpointer data)
{
  RenderGradientFunc func = data;
  GtkAllocation allocation;
  GtkStyleContext *style;
  GdkRGBA color;

  style = gtk_widget_get_style_context (widget);

  gtk_style_context_save (style);
  gtk_style_context_set_state (style, gtk_widget_get_state_flags (widget));
  gtk_style_context_lookup_color (style, "foreground-color", &color);
  gtk_style_context_restore (style);

  gtk_widget_get_allocation (widget, &allocation);

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

  (* func) (
            cr,
            allocation.width,
            allocation.height);

  return FALSE;
}
Ejemplo n.º 3
0
static void
set_custom_color_from_style (GdkRGBA         *color,
                             GtkStyleContext *context,
                             const gchar     *color_name,
                             MetaColorSpec   *fallback)
{
    if (!gtk_style_context_lookup_color (context, color_name, color))
        meta_color_spec_render (fallback, context, color);
}
Ejemplo n.º 4
0
static void
colorize_cell (GtkTreeViewColumn *tree_column,
               GtkCellRenderer *cell,
               GtkTreeModel *tree_model,
               GtkTreeIter *iter,
               gpointer data)
{
  GtrMsg *msg;

  GdkRGBA translated, fuzzy, untranslated;
  GtkStyleContext *style_context;
  style_context = gtk_widget_get_style_context (GTK_WIDGET (data));
  gtk_style_context_lookup_color (style_context, "theme_fg_color", &translated);
  gtk_style_context_lookup_color (style_context, "warning_color", &fuzzy);
  gtk_style_context_lookup_color (style_context, "error_color", &untranslated);

  gtk_tree_model_get (tree_model, iter,
                      GTR_MESSAGE_TABLE_MODEL_POINTER_COLUMN, &msg,
                      -1);

  if (gtr_msg_is_fuzzy (msg))
    {
      g_object_set (cell, "foreground-rgba", &fuzzy, NULL);
      g_object_set (cell, "style", PANGO_STYLE_ITALIC, NULL);
      g_object_set (cell, "weight", PANGO_WEIGHT_NORMAL, NULL);
    }
  else if (gtr_msg_is_translated (msg))
    {
      g_object_set (cell, "foreground-rgba", &translated, NULL);
      g_object_set (cell, "style", PANGO_STYLE_NORMAL, NULL);
      g_object_set (cell, "weight", PANGO_WEIGHT_NORMAL, NULL);
    }
  else
    {
      g_object_set (cell, "foreground-rgba", &untranslated, NULL);
      g_object_set (cell, "style", PANGO_STYLE_NORMAL, NULL);
      g_object_set (cell, "weight", PANGO_WEIGHT_BOLD, NULL);
    }
}
Ejemplo n.º 5
0
GtkWidget *gtk_paned_new_with_handle(GtkOrientation orientation)
{
	GtkWidget *pnd = gtk_paned_new(orientation);
	GtkStyleContext *context = gtk_widget_get_style_context(pnd);
	GtkCssProvider  *cssprv =  gtk_css_provider_new();
	GdkRGBA clrSel = {0.,0.,0.,0.};
	char css[2048];
	
	gtk_style_context_lookup_color(context, "bg_color", &clrSel);
	if (orientation == GTK_ORIENTATION_HORIZONTAL)
	{
		sprintf(css, "* {\n -GtkPaned-handle-size: 3; \n } \n .pane-separator.horizontal {\n background-image: -gtk-gradient (linear, left top, left bottom, from (%s), color-stop (0.5, shade (%s, 0.95)), to (%s)); \n -unico-centroid-texture: url(\"%s\");\n }\n", gdk_rgba_to_string(&clrSel), gdk_rgba_to_string(&clrSel), gdk_rgba_to_string(&clrSel), imgOrzHnd);
	}
	else
	{
		sprintf(css, "* {\n -GtkPaned-handle-size: 3; \n } \n \n .pane-separator.vertical {\n background-image: -gtk-gradient (linear, left top, right top, from (%s), color-stop (0.5, shade (%s, 0.95)), to (%s)); \n -unico-centroid-texture: url(\"%s\");\n }\n", gdk_rgba_to_string(&clrSel), gdk_rgba_to_string(&clrSel), gdk_rgba_to_string(&clrSel), imgVrtHnd);
	}
	gtk_style_context_remove_provider(context, GTK_STYLE_PROVIDER (cssprv));
	gtk_style_context_add_provider(context, GTK_STYLE_PROVIDER (cssprv), GTK_STYLE_PROVIDER_PRIORITY_USER);
	gtk_css_provider_load_from_data(cssprv, css, -1, NULL);
	g_object_unref(cssprv);
	return pnd;
}
Ejemplo n.º 6
0
static void 
xmr_label_init(XmrLabel *label)
{
	XmrLabelPrivate *priv;
	GtkStyleContext *context;

	label->priv = G_TYPE_INSTANCE_GET_PRIVATE(label, XMR_TYPE_LABEL, XmrLabelPrivate);
	priv = label->priv;

	priv->timeout_id = 0;
	priv->text = NULL;
	priv->layout = NULL;
	priv->current_x = 0;

	context = gtk_widget_get_style_context(GTK_WIDGET(label));

	gtk_style_context_lookup_color(context, "text_color", &priv->default_color);
	if (priv->default_color.alpha <= 0)
		priv->default_color.alpha = 1.0;

	priv->current_color = gdk_rgba_copy(&priv->default_color);
	
	gtk_widget_set_app_paintable(GTK_WIDGET(label), TRUE);
}
Ejemplo n.º 7
0
static gboolean
draw_callback (GtkWidget *widget,
               cairo_t   *cr,
               gpointer   data)
{
  RenderGradientFunc func = data;
  GtkStyleContext *style;
  GdkRGBA color;

  style = gtk_widget_get_style_context (widget);

  gtk_style_context_save (style);
  gtk_style_context_set_state (style, gtk_widget_get_state_flags (widget));
  gtk_style_context_lookup_color (style, "foreground-color", &color);
  gtk_style_context_restore (style);

  gdk_cairo_set_source_rgba (cr, &color);

  (* func) (cr,
            gtk_widget_get_allocated_width (widget),
            gtk_widget_get_allocated_height (widget));

  return FALSE;
}
Ejemplo n.º 8
0
void *dt_control_expose(void *voidptr)
{
  int width, height, pointerx, pointery;
  if(!darktable.gui->surface) return NULL;
  width = dt_cairo_image_surface_get_width(darktable.gui->surface);
  height = dt_cairo_image_surface_get_height(darktable.gui->surface);
  GtkWidget *widget = dt_ui_center(darktable.gui->ui);
  GdkDevice *device
      = gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gtk_widget_get_display(widget)));
  gdk_window_get_device_position(gtk_widget_get_window(widget), device, &pointerx, &pointery, NULL);

  // create a gtk-independent surface to draw on
  cairo_surface_t *cst = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
  cairo_t *cr = cairo_create(cst);

  // TODO: control_expose: only redraw the part not overlapped by temporary control panel show!
  //
  float tb = 8; // fmaxf(10, width/100.0);
  darktable.control->tabborder = tb;
  darktable.control->width = width;
  darktable.control->height = height;

  GdkRGBA color;
  GtkStyleContext *context = gtk_widget_get_style_context(widget);
  gboolean color_found = gtk_style_context_lookup_color (context, "bg_color", &color);
  if(!color_found)
  {
    color.red = 1.0;
    color.green = 0.0;
    color.blue = 0.0;
    color.alpha = 1.0;
  }
  gdk_cairo_set_source_rgba(cr, &color);

  cairo_set_line_width(cr, tb);
  cairo_rectangle(cr, tb / 2., tb / 2., width - tb, height - tb);
  cairo_stroke(cr);
  cairo_set_line_width(cr, 1.5);
  color_found = gtk_style_context_lookup_color (context, "really_dark_bg_color", &color);
  if(!color_found)
  {
    color.red = 1.0;
    color.green = 0.0;
    color.blue = 0.0;
    color.alpha = 1.0;
  }
  gdk_cairo_set_source_rgba(cr, &color);
  cairo_rectangle(cr, tb, tb, width - 2 * tb, height - 2 * tb);
  cairo_stroke(cr);

  cairo_save(cr);
  cairo_translate(cr, tb, tb);
  cairo_rectangle(cr, 0, 0, width - 2 * tb, height - 2 * tb);
  cairo_clip(cr);
  cairo_new_path(cr);
  // draw view
  dt_view_manager_expose(darktable.view_manager, cr, width - 2 * tb, height - 2 * tb, pointerx - tb,
                         pointery - tb);
  cairo_restore(cr);

  // draw log message, if any
  dt_pthread_mutex_lock(&darktable.control->log_mutex);
  if(darktable.control->log_ack != darktable.control->log_pos)
  {
    PangoRectangle ink;
    PangoLayout *layout;
    PangoFontDescription *desc = pango_font_description_copy_static(darktable.bauhaus->pango_font_desc);
    const float fontsize = DT_PIXEL_APPLY_DPI(14);
    pango_font_description_set_absolute_size(desc, fontsize * PANGO_SCALE);
    pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
    layout = pango_cairo_create_layout(cr);
    pango_layout_set_font_description(layout, desc);
    pango_layout_set_text(layout, darktable.control->log_message[darktable.control->log_ack], -1);
    pango_layout_get_pixel_extents(layout, &ink, NULL);
    const float pad = DT_PIXEL_APPLY_DPI(20.0f), xc = width / 2.0;
    const float yc = height * 0.85 + DT_PIXEL_APPLY_DPI(10), wd = pad + ink.width * .5f;
    float rad = DT_PIXEL_APPLY_DPI(14);
    cairo_set_line_width(cr, 1.);
    cairo_move_to(cr, xc - wd, yc + rad);
    for(int k = 0; k < 5; k++)
    {
      cairo_arc(cr, xc - wd, yc, rad, M_PI / 2.0, 3.0 / 2.0 * M_PI);
      cairo_line_to(cr, xc + wd, yc - rad);
      cairo_arc(cr, xc + wd, yc, rad, 3.0 * M_PI / 2.0, M_PI / 2.0);
      cairo_line_to(cr, xc - wd, yc + rad);
      if(k == 0)
      {
        color_found = gtk_style_context_lookup_color (context, "selected_bg_color", &color);
        if(!color_found)
        {
          color.red = 1.0;
          color.green = 0.0;
          color.blue = 0.0;
          color.alpha = 1.0;
        }
        gdk_cairo_set_source_rgba(cr, &color);
        cairo_fill_preserve(cr);
      }
      cairo_set_source_rgba(cr, 0., 0., 0., 1.0 / (1 + k));
      cairo_stroke(cr);
      rad += .5f;
    }
    color_found = gtk_style_context_lookup_color (context, "fg_color", &color);
    if(!color_found)
    {
      color.red = 1.0;
      color.green = 0.0;
      color.blue = 0.0;
      color.alpha = 1.0;
    }
    gdk_cairo_set_source_rgba(cr, &color);
    cairo_move_to(cr, xc - wd + .5f * pad, (yc + 1. / 3. * fontsize) - fontsize);
    pango_cairo_show_layout(cr, layout);
    pango_font_description_free(desc);
    g_object_unref(layout);
  }
  // draw busy indicator
  if(darktable.control->log_busy > 0)
  {
    PangoRectangle ink;
    PangoLayout *layout;
    PangoFontDescription *desc = pango_font_description_copy_static(darktable.bauhaus->pango_font_desc);
    const float fontsize = DT_PIXEL_APPLY_DPI(14);
    pango_font_description_set_absolute_size(desc, fontsize * PANGO_SCALE);
    pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
    layout = pango_cairo_create_layout(cr);
    pango_layout_set_font_description(layout, desc);
    pango_layout_set_text(layout, _("working.."), -1);
    pango_layout_get_pixel_extents(layout, &ink, NULL);
    const float xc = width / 2.0, yc = height * 0.85 - DT_PIXEL_APPLY_DPI(30), wd = ink.width * .5f;
    cairo_move_to(cr, xc - wd, yc + 1. / 3. * fontsize - fontsize);
    pango_cairo_layout_path(cr, layout);
    cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
    cairo_fill_preserve(cr);
    cairo_set_line_width(cr, 0.7);
    cairo_set_source_rgb(cr, 0.3, 0.3, 0.3);
    cairo_stroke(cr);
    pango_font_description_free(desc);
    g_object_unref(layout);
  }
  dt_pthread_mutex_unlock(&darktable.control->log_mutex);

  cairo_destroy(cr);

  cairo_t *cr_pixmap = cairo_create(darktable.gui->surface);
  cairo_set_source_surface(cr_pixmap, cst, 0, 0);
  cairo_paint(cr_pixmap);
  cairo_destroy(cr_pixmap);

  cairo_surface_destroy(cst);
  return NULL;
}
Ejemplo n.º 9
0
static void _lib_modulelist_populate_callback(gpointer instance, gpointer user_data)
{
    dt_lib_module_t *self = (dt_lib_module_t *)user_data;
    if(!self || !(self->data)) return;

    GtkListStore *store;
    GtkTreeIter iter;
    GtkWidget *view = GTK_WIDGET(((dt_lib_modulelist_t *)self->data)->tree);
    GtkCellRenderer *pix_renderer, *fav_renderer, *text_renderer;
    GdkRGBA color;
    GtkStyleContext *context = gtk_widget_get_style_context(view);
    gboolean color_found = gtk_style_context_lookup_color (context, "selected_bg_color", &color);
    if(!color_found)
    {
        color.red = 1.0;
        color.green = 0.0;
        color.blue = 0.0;
        color.alpha = 1.0;
    }

    store = gtk_list_store_new(NUM_COLS, GDK_TYPE_PIXBUF, G_TYPE_POINTER);
    gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
    g_object_unref(store);

    gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), COL_MODULE, _lib_modulelist_gui_sort, NULL, NULL);
    gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), COL_MODULE, GTK_SORT_ASCENDING);

    pix_renderer = gtk_cell_renderer_pixbuf_new();
    g_object_set(pix_renderer, "cell-background-rgba", &color, NULL);

    fav_renderer = gtk_cell_renderer_pixbuf_new();
    cairo_surface_t *fav_cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ICON_SIZE, ICON_SIZE);
    cairo_t *fav_cr = cairo_create(fav_cst);
    cairo_set_source_rgb(fav_cr, 0.7, 0.7, 0.7);
    dtgtk_cairo_paint_modulegroup_favorites(fav_cr, 0, 0, ICON_SIZE, ICON_SIZE, 0);
    guchar *data = cairo_image_surface_get_data(fav_cst);
    dt_draw_cairo_to_gdk_pixbuf(data, ICON_SIZE, ICON_SIZE);
    ((dt_lib_modulelist_t *)self->data)->fav_pixbuf
        = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE, 8, ICON_SIZE, ICON_SIZE,
                                   cairo_image_surface_get_stride(fav_cst), NULL, NULL);
    g_object_set(fav_renderer, "cell-background-rgba", &color, NULL);
    g_object_set(fav_renderer, "width", gdk_pixbuf_get_width(((dt_lib_modulelist_t *)self->data)->fav_pixbuf),
                 NULL);

    text_renderer = gtk_cell_renderer_text_new();
    g_object_set(text_renderer, "cell-background-rgba", &color, NULL);

    gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
    gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(view), FALSE);
    GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
    gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE);

    GtkTreeViewColumn *col;
    col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 0);
    if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col);
    gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 0, "favorite", fav_renderer,
            favorite_renderer_function, NULL, NULL);
    col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 1);
    if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col);
    gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 1, "image", pix_renderer,
            image_renderer_function, NULL, NULL);
    col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 2);
    if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col);
    gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 2, "name", text_renderer,
            text_renderer_function, NULL, NULL);

    /* go thru list of iop modules and add them to the list */
    GList *modules = g_list_last(darktable.develop->iop);

    char datadir[PATH_MAX] = { 0 };
    dt_loc_get_datadir(datadir, sizeof(datadir));

    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->multi_priority == 0)
        {
            GdkPixbuf *pixbuf;
            char filename[PATH_MAX] = { 0 };

            snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/%s.svg", datadir, module->op);
            pixbuf = load_image(filename);
            if(pixbuf) goto end;

            snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/%s.png", datadir, module->op);
            pixbuf = load_image(filename);
            if(pixbuf) goto end;

            snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/template.svg", datadir);
            pixbuf = load_image(filename);
            if(pixbuf) goto end;

            snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/template.png", datadir);
            pixbuf = load_image(filename);
            if(pixbuf) goto end;

            // wow, we could neither load the SVG nor the PNG files. something is f****d up.
            pixbuf = gdk_pixbuf_new_from_data(fallback_pixel, GDK_COLORSPACE_RGB, TRUE, 8, 1, 1, 4, NULL, NULL);

end:
            gtk_list_store_append(store, &iter);
            gtk_list_store_set(store, &iter, COL_IMAGE, pixbuf, COL_MODULE, module, -1);
            g_object_unref(pixbuf);
        }

        modules = g_list_previous(modules);
    }
}