/* * This file is part of RawTherapee. * * Copyright (c) 2004-2010 Gabor Horvath * Copyright (c) 2018 Jean-Christophe FRISCH * Copyright (c) 2022 Pierre CABRERA * * RawTherapee is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * RawTherapee is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ #include "rtimage.h" #include "rtsurface.h" std::map, std::shared_ptr> RTImageCache::cache; std::shared_ptr RTImageCache::getCachedSurface(const Glib::ustring &icon_name, const Gtk::IconSize icon_size) { // Look for an existing cached icon const auto key = std::pair(icon_name, icon_size); const auto item = cache.find(key); if (item != cache.end()) { // A cached icon exists return item->second; } else { // Create the icon auto surface = std::shared_ptr(new RTSurface(icon_name, icon_size)); // Add the surface to the cache if the icon exist if (surface) { cache.insert({key, surface}); } return surface; } } void RTImageCache::updateCache() { // Iterate over cache to updated RTSurface for (auto const& item : cache) { item.second->updateSurface(); } } RTImage::RTImage () {} RTImage::RTImage (const Glib::ustring& iconName, const Gtk::IconSize iconSize) : Gtk::Image(), size(iconSize), icon_name(iconName) { // Set surface from icon cache surface = RTImageCache::getCachedSurface(this->icon_name, this->size); // Add it to the RTImage if surface exists if (surface) { set(surface->get()); } } void RTImage::set_from_icon_name(const Glib::ustring& iconName) { this->icon_name = iconName; // Set surface from icon cache surface = RTImageCache::getCachedSurface(this->icon_name, this->size); // Add it to the RTImage if surface exists if (surface) { set(surface->get()); } } void RTImage::set_from_icon_name(const Glib::ustring& iconName, const Gtk::IconSize iconSize) { this->icon_name = iconName; this->size = iconSize; // Set surface from icon cache surface = RTImageCache::getCachedSurface(this->icon_name, this->size); // Add it to the RTImage if surface exists if (surface) { set(surface->get()); } } int RTImage::get_width() { if (surface) { return surface->getWidth(); } return -1; } int RTImage::get_height() { if (surface) { return surface->getHeight(); } return -1; }