Web lists-archives.com

Re: gtk_icon_theme_load_icon and GDK_SCALE=2 results in blurry icon




Hi,

On Tue, 2017-10-03 at 20:13 +0200, infirit wrote:

> See bug 765167 [1] it has an example in python how you can still use a
> surface in the GtkIconView.  You should be able to translate this pretty
> easily to C/C++.
> 
> ~infirit
> 
> [1] https://bugzilla.gnome.org/show_bug.cgi?id=765167#c5.

Thanks a lot for the pointer. I was able to translate this into Gtkmm.
This fixes my issue, although I wish GTK would implement a proper
method for doing this.

This is the code, if anyone is interested:

class MainWindowIconView : public Gtk::IconView {
public:

	Gtk::CellRendererPixbuf cell_renderer_pixbuf;  ///< Cell renderer for icons.
	Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > col_pixbuf;  ///< Model column
	// ...

	MainWindowIconView()
	{
		// ...
		columns.add(col_pixbuf);

		// For high quality rendering with GDK_SCALE=2
		this->pack_start(cell_renderer_pixbuf, false);
		this->set_cell_data_func(cell_renderer_pixbuf,
				sigc::mem_fun(this, &MainWindowIconView::on_cell_data_render));
		// ...
	}

	/// Cell data renderer (needed for high quality icons in GDK_SCALE=2).
	/// We have to use Cairo surfaces, because pixbufs are scaled by GtkIconView.
	void on_cell_data_render(const Gtk::TreeModel::const_iterator& iter)
	{
		Gtk::TreeRow row = *iter;
		Glib::RefPtr<Gdk::Pixbuf> pixbuf = row[col_pixbuf];

		// Gtkmm property_surface() doesn't work, so use plain C.
		cairo_surface_t* surface = gdk_cairo_surface_create_from_pixbuf(
				pixbuf->gobj(), get_scale_factor(), get_window()->gobj());
		g_object_set(G_OBJECT(cell_renderer_pixbuf.gobj()), "surface", surface, NULL);
		cairo_surface_destroy(surface);
	}

	// ...
};



Thanks,
Alexander

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list