diff options
| author | Jabier Arraiza <jabier.arraiza@marker.es> | 2019-01-27 00:36:47 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2019-01-27 00:36:47 +0000 |
| commit | 9bbc588e18f7b9647c3d9b03d257a45dda42520a (patch) | |
| tree | 08eb5c11645a019c556aa4f80149205d1b3779eb /src/ui/icon-loader.cpp | |
| parent | Add 'Theme Decide' option to symbolic icons color (diff) | |
| download | inkscape-9bbc588e18f7b9647c3d9b03d257a45dda42520a.tar.gz inkscape-9bbc588e18f7b9647c3d9b03d257a45dda42520a.zip | |
Improvements to icon loader code
Diffstat (limited to 'src/ui/icon-loader.cpp')
| -rw-r--r-- | src/ui/icon-loader.cpp | 118 |
1 files changed, 42 insertions, 76 deletions
diff --git a/src/ui/icon-loader.cpp b/src/ui/icon-loader.cpp index a6011773d..e2aaf5093 100644 --- a/src/ui/icon-loader.cpp +++ b/src/ui/icon-loader.cpp @@ -10,64 +10,63 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ + #include "icon-loader.h" #include "inkscape.h" -#include "io/resource.h" -#include "preferences.h" -#include "svg/svg-color.h" #include "widgets/toolbox.h" +#include <gtkmm/iconinfo.h> #include <gdkmm/display.h> #include <gdkmm/screen.h> #include <gtkmm/iconinfo.h> #include <gtkmm/icontheme.h> -#include <gtkmm/toolitem.h> -void sp_load_theme() {} +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gint size) +{ + Gtk::Image *icon = new Gtk::Image(); + icon->set_from_icon_name(icon_name, Gtk::IconSize(Gtk::ICON_SIZE_BUTTON)); + icon->set_pixel_size(size); + return icon; +} + +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, Gtk::IconSize icon_size) +{ + Gtk::Image *icon = new Gtk::Image(); + icon->set_from_icon_name(icon_name, icon_size); + return icon; +} + +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, Gtk::BuiltinIconSize icon_size) +{ + Gtk::Image *icon = new Gtk::Image(); + icon->set_from_icon_name(icon_name, icon_size); + return icon; +} + +GtkWidget *sp_get_icon_image(Glib::ustring icon_name, GtkIconSize icon_size) +{ + return gtk_image_new_from_icon_name(icon_name.c_str(), icon_size); +} + +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gchar const *prefs_size) +{ + Gtk::IconSize icon_size = Inkscape::UI::ToolboxFactory::prefToSize_mm(prefs_size); + return sp_get_icon_image(icon_name, icon_size); +} Glib::RefPtr<Gdk::Pixbuf> sp_get_icon_pixbuf(Glib::ustring icon_name, gint size) { Glib::RefPtr<Gdk::Display> display = Gdk::Display::get_default(); Glib::RefPtr<Gdk::Screen> screen = display->get_default_screen(); Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_for_screen(screen); - // TODO all calls to "sp_get_icon_pixbuf" need to be removed in thew furture - // Put here temporary for allow use symbolic in a few icons require pixbug instead Gtk::Image - // We coulden't acces to pixbuf of a symbolic ones with the next order - // icon_theme->load_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE); - // Maybe we can do with Gio, but not sure. Also can render a icon to pixbuf but need to be - // a stock-icon not on named ones I think or access directly to the icon.svg file - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::RefPtr<Gdk::Pixbuf> _icon_pixbuf; - try { - if (prefs->getBool("/theme/symbolicIcons", false)) { - gchar colornamed[64]; - int colorset = prefs->getInt("/theme/symbolicColor", 0x000000ff); - // Use in case the special widgets have inverse theme background and symbolic - sp_svg_write_color(colornamed, sizeof(colornamed), colorset); - Gdk::RGBA color; - color.set(colornamed); - Gtk::IconInfo iconinfo = - icon_theme->lookup_icon(icon_name + Glib::ustring("-symbolic"), size, Gtk::ICON_LOOKUP_FORCE_SIZE); - if (bool(iconinfo)) { - bool was_symbolic = false; - _icon_pixbuf = iconinfo.load_symbolic(color, color, color, color, was_symbolic); - } - else { - _icon_pixbuf = icon_theme->load_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE); - } - // g_warning("Icon Loader using a future dead function in this icon: %s", icon_name.c_str()); - // limit warns to 1 per run - static bool tmp_warn = true; - if (tmp_warn) { - tmp_warn = false; - g_warning("Icon Loader using a legacy function (sp_get_icon_pixbuf)."); - } - } - else { - _icon_pixbuf = icon_theme->load_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE); - } - } - catch (const Gtk::IconThemeError &e) { - g_warning("Icon Loader error loading icon file: %s", e.what().c_str()); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getBool("/theme/symbolicIcons", false)) { + Gtk::IconInfo iconinfo = icon_theme->lookup_icon(icon_name + Glib::ustring("-symbolic"), size, Gtk::ICON_LOOKUP_FORCE_SIZE); + bool was_sumbolic = false; + _icon_pixbuf = iconinfo.load_symbolic(SP_ACTIVE_DESKTOP->getToplevel()->get_style_context(), was_sumbolic); + } else { + Gtk::IconInfo iconinfo = icon_theme->lookup_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE); + _icon_pixbuf = iconinfo.load_icon(); } return _icon_pixbuf; } @@ -103,39 +102,6 @@ Glib::RefPtr<Gdk::Pixbuf> sp_get_icon_pixbuf(Glib::ustring icon_name, gchar cons return sp_get_icon_pixbuf(icon_name, icon_size); } - -Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, Gtk::BuiltinIconSize icon_size) -{ - - Gtk::Image *icon = new Gtk::Image(); - icon->set_from_icon_name(icon_name, Gtk::IconSize(icon_size)); - return icon; -} - -Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, Gtk::IconSize icon_size) -{ - - Gtk::Image *icon = new Gtk::Image(); - icon->set_from_icon_name(icon_name, icon_size); - return icon; -} - -Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gchar const *prefs_size) -{ - - Gtk::IconSize icon_size = Inkscape::UI::ToolboxFactory::prefToSize_mm(prefs_size); - Gtk::Image *icon = new Gtk::Image(); - icon->set_from_icon_name(icon_name, icon_size); - return icon; -} - - -GtkWidget *sp_get_icon_image(Glib::ustring icon_name, GtkIconSize icon_size) -{ - - return gtk_image_new_from_icon_name(icon_name.c_str(), icon_size); -} - /* Local Variables: mode:c++ |
