Move image loader helper functions from safegtk to RTImage module.

This commit is contained in:
Adam Reichold
2015-12-25 22:39:53 +01:00
parent 0b32f12f6c
commit 13ebcb0dd0
14 changed files with 253 additions and 244 deletions

View File

@@ -38,41 +38,6 @@
#include <memory>
Glib::RefPtr<Gdk::Pixbuf> safe_create_from_file(const Glib::ustring& filename)
{
Glib::RefPtr<Gdk::Pixbuf> res;
Glib::ustring path = RTImage::findIconAbsolutePath(filename);
if (path.length()) {
try {
res = Gdk::Pixbuf::create_from_file (path);
} catch (Glib::Exception& ex) {
printf ("ERROR: (ustring) File \"%s\" not found.\n", ex.what().c_str());
}
}
return res;
}
Cairo::RefPtr<Cairo::ImageSurface> safe_create_from_png(const Glib::ustring& filename)
{
Cairo::RefPtr<Cairo::ImageSurface> res;
Glib::ustring path = RTImage::findIconAbsolutePath(filename);
if (path.length()) {
// files_test need a std::string which (as stated in its proto) but will only work if
// we use the Glib::ustring filename !?
try {
// create_from_png need a std::string converted from UTF8 with safe_locale_from_utf8
res = Cairo::ImageSurface::create_from_png (safe_locale_from_utf8(path));
} catch (...) {
printf("ERROR: (ustring) File \"%s\" not found.\n", path.c_str());
}
}
return res;
}
Glib::RefPtr<Gio::FileInfo> safe_query_file_info (Glib::RefPtr<Gio::File> &file)
{
Glib::RefPtr<Gio::FileInfo> info;

View File

@@ -5,9 +5,6 @@
#include <glibmm.h>
#include <giomm.h>
Glib::RefPtr<Gdk::Pixbuf> safe_create_from_file(const Glib::ustring& filename);
Cairo::RefPtr<Cairo::ImageSurface> safe_create_from_png(const Glib::ustring& filename);
Glib::RefPtr<Gio::FileInfo> safe_query_file_info (Glib::RefPtr<Gio::File> &file);
void safe_build_file_list (Glib::RefPtr<Gio::File> &dir, std::vector<Glib::ustring> &names, const Glib::ustring &directory = "", const std::vector<Glib::ustring> *extensions = NULL);
void safe_build_subdir_list (Glib::RefPtr<Gio::File> &dir, std::vector<Glib::ustring> &subDirs, bool add_hidden);

View File

@@ -17,8 +17,9 @@
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include "batchqueuebuttonset.h"
#include "multilangmgr.h"
#include "../rtengine/safegtk.h"
#include "rtimage.h"
extern Glib::ustring argv0;
@@ -32,9 +33,9 @@ BatchQueueButtonSet::BatchQueueButtonSet (BatchQueueEntry* myEntry)
{
if (!iconsLoaded) {
cancelIcon = safe_create_from_png ("gtk-close.png");
headIcon = safe_create_from_png ("toleftend.png");
tailIcon = safe_create_from_png ("torightend.png");
cancelIcon = RTImage::createFromPng ("gtk-close.png");
headIcon = RTImage::createFromPng ("toleftend.png");
tailIcon = RTImage::createFromPng ("torightend.png");
iconsLoaded = true;
}

View File

@@ -17,13 +17,14 @@
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include "batchqueueentry.h"
#include "thumbbrowserbase.h"
#include <cstring>
#include "guiutils.h"
#include "threadutils.h"
#include "../rtengine/safegtk.h"
#include "rtimage.h"
#include "multilangmgr.h"
#include "thumbbrowserbase.h"
bool BatchQueueEntry::iconsLoaded(false);
Glib::RefPtr<Gdk::Pixbuf> BatchQueueEntry::savedAsIcon;
@@ -46,7 +47,7 @@ BatchQueueEntry::BatchQueueEntry (rtengine::ProcessingJob* pjob, const rtengine:
#endif
if (!iconsLoaded) {
savedAsIcon = safe_create_from_file ("gtk-save.png");
savedAsIcon = RTImage::createFromFile ("gtk-save.png");
iconsLoaded = true;
}

View File

@@ -16,19 +16,21 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cropwindow.h"
#include <iomanip>
#include "cropwindow.h"
#include "options.h"
#include "guiutils.h"
#include "threadutils.h"
#include "../rtengine/mytime.h"
#include "imagearea.h"
#include "cursormanager.h"
#include "../rtengine/safegtk.h"
#include "../rtengine/rt_math.h"
#include "../rtengine/dcrop.h"
#include "guiutils.h"
#include "threadutils.h"
#include "rtimage.h"
#include "cursormanager.h"
#include "options.h"
#include "imagearea.h"
using namespace rtengine;
struct ZoomStep {
@@ -84,11 +86,11 @@ CropWindow::CropWindow (ImageArea* parent, rtengine::StagedImageProcessor* ipc_,
titleHeight = ih;
bZoomOut = new LWButton (safe_create_from_png ("gtk-zoom-out-small.png"), 0, NULL, LWButton::Left, LWButton::Center, "Zoom Out");
bZoomIn = new LWButton (safe_create_from_png ("gtk-zoom-in-small.png"), 1, NULL, LWButton::Left, LWButton::Center, "Zoom In");
bZoom100 = new LWButton (safe_create_from_png ("gtk-zoom-100-small.png"), 2, NULL, LWButton::Left, LWButton::Center, "Zoom 100/%");
//bZoomFit = new LWButton (safe_create_from_png ("gtk-zoom-fit.png"), 3, NULL, LWButton::Left, LWButton::Center, "Zoom Fit");
bClose = new LWButton (safe_create_from_png ("gtk-close-small.png"), 4, NULL, LWButton::Right, LWButton::Center, "Close");
bZoomOut = new LWButton (RTImage::createFromPng ("gtk-zoom-out-small.png"), 0, NULL, LWButton::Left, LWButton::Center, "Zoom Out");
bZoomIn = new LWButton (RTImage::createFromPng ("gtk-zoom-in-small.png"), 1, NULL, LWButton::Left, LWButton::Center, "Zoom In");
bZoom100 = new LWButton (RTImage::createFromPng ("gtk-zoom-100-small.png"), 2, NULL, LWButton::Left, LWButton::Center, "Zoom 100/%");
//bZoomFit = new LWButton (RTImage::createFromPng ("gtk-zoom-fit.png"), 3, NULL, LWButton::Left, LWButton::Center, "Zoom Fit");
bClose = new LWButton (RTImage::createFromPng ("gtk-close-small.png"), 4, NULL, LWButton::Right, LWButton::Center, "Close");
buttonSet.add (bZoomOut);
buttonSet.add (bZoomIn);

View File

@@ -17,8 +17,8 @@
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cursormanager.h"
#include "options.h"
#include "../rtengine/safegtk.h"
#include "rtimage.h"
CursorManager cursorManager;
@@ -41,14 +41,14 @@ void CursorManager::init (Glib::RefPtr<Gdk::Window> mainWin)
cAdd = new Gdk::Cursor (Gdk::PLUS);
cWait = new Gdk::Cursor (Gdk::CLOCK);
Glib::RefPtr<Gdk::Pixbuf> hand = safe_create_from_file("cross.png");
Glib::RefPtr<Gdk::Pixbuf> close_hand = safe_create_from_file("closedhand.png");
Glib::RefPtr<Gdk::Pixbuf> wbpick = safe_create_from_file("gtk-color-picker-small.png");
Glib::RefPtr<Gdk::Pixbuf> empty = safe_create_from_file("empty.png");
Glib::RefPtr<Gdk::Pixbuf> move2D = safe_create_from_file("move-2D.png");
Glib::RefPtr<Gdk::Pixbuf> move1DH = safe_create_from_file("move-1D-h.png");
Glib::RefPtr<Gdk::Pixbuf> move1DV = safe_create_from_file("move-1D-v.png");
Glib::RefPtr<Gdk::Pixbuf> moveRotate = safe_create_from_file("move-rotate.png");
Glib::RefPtr<Gdk::Pixbuf> hand = RTImage::createFromFile ("cross.png");
Glib::RefPtr<Gdk::Pixbuf> close_hand = RTImage::createFromFile ("closedhand.png");
Glib::RefPtr<Gdk::Pixbuf> wbpick = RTImage::createFromFile ("gtk-color-picker-small.png");
Glib::RefPtr<Gdk::Pixbuf> empty = RTImage::createFromFile ("empty.png");
Glib::RefPtr<Gdk::Pixbuf> move2D = RTImage::createFromFile ("move-2D.png");
Glib::RefPtr<Gdk::Pixbuf> move1DH = RTImage::createFromFile ("move-1D-h.png");
Glib::RefPtr<Gdk::Pixbuf> move1DV = RTImage::createFromFile ("move-1D-v.png");
Glib::RefPtr<Gdk::Pixbuf> moveRotate = RTImage::createFromFile ("move-rotate.png");
cHand = hand ? new Gdk::Cursor (cAdd->get_display(), hand, 10, 10) : new Gdk::Cursor (Gdk::HAND2);
cClosedHand = close_hand ? new Gdk::Cursor (cAdd->get_display(), close_hand, 10, 10) : new Gdk::Cursor (Gdk::HAND2);

View File

@@ -72,13 +72,13 @@ DirBrowser::DirBrowser () : dirTreeModel(),
void DirBrowser::fillDirTree ()
{
openfolder = safe_create_from_file ("gtk-open.png");
closedfolder = safe_create_from_file ("folder.png");
icdrom = safe_create_from_file ("drive-optical.png");
ifloppy = safe_create_from_file ("drive-removable-media.png");
ihdd = safe_create_from_file ("drive-harddisk.png");
iremovable = safe_create_from_file ("media-usb.png");
inetwork = safe_create_from_file ("network.png");
openfolder = RTImage::createFromFile ("gtk-open.png");
closedfolder = RTImage::createFromFile ("folder.png");
icdrom = RTImage::createFromFile ("drive-optical.png");
ifloppy = RTImage::createFromFile ("drive-removable-media.png");
ihdd = RTImage::createFromFile ("drive-harddisk.png");
iremovable = RTImage::createFromFile ("media-usb.png");
inetwork = RTImage::createFromFile ("network.png");
//Create the Tree model:
dirTreeModel = Gtk::TreeStore::create(dtColumns);

View File

@@ -17,7 +17,7 @@
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include "exifpanel.h"
#include "../rtengine/safegtk.h"
#include "guiutils.h"
#include "rtimage.h"
@@ -47,9 +47,9 @@ ExifPanel::ExifPanel () : idata(NULL)
exifTreeModel = Gtk::TreeStore::create(exifColumns);
exifTree->set_model (exifTreeModel);
delicon = safe_create_from_file ("gtk-close.png");
keepicon = safe_create_from_file ("gtk-apply.png");
editicon = safe_create_from_file ("gtk-add.png");
delicon = RTImage::createFromFile ("gtk-close.png");
keepicon = RTImage::createFromFile ("gtk-apply.png");
editicon = RTImage::createFromFile ("gtk-add.png");
Gtk::TreeView::Column *viewcol = Gtk::manage(new Gtk::TreeView::Column ("Field Name"));
Gtk::CellRendererPixbuf* render_pb = Gtk::manage(new Gtk::CellRendererPixbuf ());

View File

@@ -17,16 +17,17 @@
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include "filebrowserentry.h"
#include "thumbbrowserbase.h"
#include "cursormanager.h"
#include <iomanip>
#include <cstring>
#include "guiutils.h"
#include "threadutils.h"
#include "../rtengine/safegtk.h"
#include "rtimage.h"
#include "cursormanager.h"
#include "thumbbrowserbase.h"
#include "inspector.h"
#include <cstring>
#define CROPRESIZEBORDER 4
bool FileBrowserEntry::iconsLoaded(false);
@@ -51,9 +52,9 @@ FileBrowserEntry::FileBrowserEntry (Thumbnail* thm, const Glib::ustring& fname)
scale = 1;
if (!iconsLoaded) {
editedIcon = safe_create_from_file ("edited.png");
recentlySavedIcon = safe_create_from_file ("recent-save.png");
enqueuedIcon = safe_create_from_file ("processing.png");
editedIcon = RTImage::createFromFile ("edited.png");
recentlySavedIcon = RTImage::createFromFile ("recent-save.png");
enqueuedIcon = RTImage::createFromFile ("processing.png");
iconsLoaded = true;
}

View File

@@ -17,8 +17,9 @@
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include "filethumbnailbuttonset.h"
#include "rtimage.h"
#include "multilangmgr.h"
#include "../rtengine/safegtk.h"
extern Glib::ustring argv0;
@@ -41,19 +42,19 @@ FileThumbnailButtonSet::FileThumbnailButtonSet (FileBrowserEntry* myEntry)
{
if (!iconsLoaded) {
unRankIcon = safe_create_from_png ("ratednotg.png");
rankIcon = safe_create_from_png ("rated.png");
gRankIcon = safe_create_from_png ("grayrated.png");
trashIcon = safe_create_from_png ("trash-thumbnail.png");
unTrashIcon = safe_create_from_png ("undelete-thumbnail.png");
processIcon = safe_create_from_png ("processing-thumbnail.png");
unRankIcon = RTImage::createFromPng ("ratednotg.png");
rankIcon = RTImage::createFromPng ("rated.png");
gRankIcon = RTImage::createFromPng ("grayrated.png");
trashIcon = RTImage::createFromPng ("trash-thumbnail.png");
unTrashIcon = RTImage::createFromPng ("undelete-thumbnail.png");
processIcon = RTImage::createFromPng ("processing-thumbnail.png");
colorLabelIcon_0 = safe_create_from_png ("cglabel0.png"); //("nocolorlabel.png");
colorLabelIcon_1 = safe_create_from_png ("clabel1.png");
colorLabelIcon_2 = safe_create_from_png ("clabel2.png");
colorLabelIcon_3 = safe_create_from_png ("clabel3.png");
colorLabelIcon_4 = safe_create_from_png ("clabel4.png");
colorLabelIcon_5 = safe_create_from_png ("clabel5.png");
colorLabelIcon_0 = RTImage::createFromPng ("cglabel0.png"); //("nocolorlabel.png");
colorLabelIcon_1 = RTImage::createFromPng ("clabel1.png");
colorLabelIcon_2 = RTImage::createFromPng ("clabel2.png");
colorLabelIcon_3 = RTImage::createFromPng ("clabel3.png");
colorLabelIcon_4 = RTImage::createFromPng ("clabel4.png");
colorLabelIcon_5 = RTImage::createFromPng ("clabel5.png");
iconsLoaded = true;
}

View File

@@ -19,151 +19,179 @@
*/
#include "rtimage.h"
#include "../rtengine/safegtk.h"
extern Glib::ustring argv0;
extern Options options;
#include "options.h"
std::vector<Glib::ustring> imagesPaths;
std::map<Glib::ustring, Glib::RefPtr<Gdk::Pixbuf> > pixBufMap; // List of image buffers in order to live update them on theme switch and to avoid a lot of file accesses
/*
* RTImage is a derived class of Gtk::Image, in order to handle theme related iconsets
*/
RTImage::RTImage(Glib::ustring fileName, Glib::ustring rtlFileName) : Gtk::Image()
namespace
{
Glib::ustring mapKey;
if (rtlFileName.length()) {
if (get_direction() == Gtk::TEXT_DIR_RTL) {
mapKey = rtlFileName;
} else {
mapKey = fileName;
std::vector<Glib::ustring> imagePaths;
std::map<Glib::ustring, Glib::RefPtr<Gdk::Pixbuf>> pixbufCache;
bool loadIconSet(const Glib::ustring& iconSet)
{
try {
Glib::KeyFile keyFile;
keyFile.load_from_file (iconSet);
auto iconSetDir = keyFile.get_string ("General", "Iconset");
if (!iconSetDir.empty ()) {
imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir, "actions"));
imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir));
imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir, "devices"));
imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir, "places"));
}
iconSetDir = keyFile.get_string ("General", "FallbackIconset");
if (!iconSetDir.empty ()) {
imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir, "actions"));
imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir));
imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir, "devices"));
imagePaths.push_back (Glib::build_filename (argv0, "images", iconSetDir, "places"));
}
return true;
} catch (const Glib::Exception& exception) {
if (options.rtSettings.verbose) {
std::cerr << "Failed to load icon set \"" << iconSet << "\": " << exception.what() << std::endl;
}
return false;
}
}
}
RTImage::RTImage (const Glib::ustring& fileName, const Glib::ustring& rtlFileName) : Gtk::Image()
{
Glib::ustring imageName;
if (!rtlFileName.empty () && get_direction () == Gtk::TEXT_DIR_RTL) {
imageName = rtlFileName;
} else {
mapKey = fileName;
imageName = fileName;
}
std::map<Glib::ustring, Glib::RefPtr<Gdk::Pixbuf> >::iterator it;
it = pixBufMap.find(mapKey);
changeImage (imageName);
}
if (it != pixBufMap.end()) {
set(it->second);
} else {
Glib::RefPtr<Gdk::Pixbuf> tempPixPuf = Gdk::Pixbuf::create_from_file(findIconAbsolutePath(mapKey));
pixBufMap.insert(std::pair<Glib::ustring, Glib::RefPtr<Gdk::Pixbuf> >(mapKey, tempPixPuf));
set(tempPixPuf);
void RTImage::changeImage (const Glib::ustring& imageName)
{
clear ();
auto iterator = pixbufCache.find (imageName);
if (iterator == pixbufCache.end ()) {
const auto imagePath = findIconAbsolutePath (imageName);
const auto pixbuf = Gdk::Pixbuf::create_from_file (imagePath);
iterator = pixbufCache.emplace (imageName, pixbuf).first;
}
set(iterator->second);
}
void RTImage::updateImages()
{
std::map<Glib::ustring, Glib::RefPtr<Gdk::Pixbuf> >::iterator it;
for (it = pixBufMap.begin(); it != pixBufMap.end(); ++it) {
Glib::ustring fullPath = findIconAbsolutePath(it->first);
it->second = Gdk::Pixbuf::create_from_file(fullPath);
for (auto& entry : pixbufCache) {
const auto imagePath = findIconAbsolutePath (entry.first);
entry.second = Gdk::Pixbuf::create_from_file (imagePath);
}
}
// DONE (was TODO: Maybe this could be optimized: in order to avoid looking up for an icon file in the filesystem on each popupmenu selection, maybe we could find a way to copy the image data from another RTImage)
void RTImage::changeImage(Glib::ustring &newImage)
Glib::ustring RTImage::findIconAbsolutePath (const Glib::ustring& iconName)
{
clear();
std::map<Glib::ustring, Glib::RefPtr<Gdk::Pixbuf> >::iterator it;
it = pixBufMap.find(newImage);
if (it != pixBufMap.end()) {
set(it->second);
} else {
Glib::ustring fullPath = findIconAbsolutePath(newImage);
Glib::RefPtr<Gdk::Pixbuf> tempPixPuf = Gdk::Pixbuf::create_from_file(fullPath);
pixBufMap.insert(std::pair<Glib::ustring, Glib::RefPtr<Gdk::Pixbuf> >(newImage, tempPixPuf));
set(tempPixPuf);
}
}
Glib::ustring RTImage::findIconAbsolutePath(const Glib::ustring &iconFName)
{
Glib::ustring path;
for (unsigned int i = 0; i < imagesPaths.size(); i++) {
path = Glib::build_filename(imagesPaths[i], iconFName);
if (safe_file_test(path, Glib::FILE_TEST_EXISTS)) {
return path;
}
}
printf("\"%s\" not found!\n", iconFName.c_str());
return "";
}
void RTImage::setPaths(Options &opt)
{
Glib::ustring configFilename;
rtengine::SafeKeyFile keyFile;
bool hasKeyFile = true;
imagesPaths.clear();
// system theme will use the theme set in system.iconset
if (opt.useSystemTheme) {
configFilename = Glib::build_filename(argv0, Glib::build_filename("themes", "system.iconset"));
}
// Gtk theme will use the theme set in it's *.iconset fiel, if it exists
else {
configFilename = Glib::build_filename(argv0, Glib::build_filename("themes", Glib::ustring::format(opt.theme, ".iconset")));
}
try {
if (!safe_file_test(configFilename, Glib::FILE_TEST_EXISTS) || !keyFile.load_from_file (configFilename)) {
// ...otherwise fallback to the iconset set in default.iconset
configFilename = Glib::build_filename(argv0, Glib::build_filename("themes", "Default.iconset"));
if (!keyFile.load_from_file (configFilename)) {
hasKeyFile = false;
for (const auto& imagePath : imagePaths) {
const auto iconPath = Glib::build_filename(imagePath, iconName);
if (Glib::file_test(iconPath, Glib::FILE_TEST_IS_REGULAR)) {
return iconPath;
}
}
} catch (Glib::Error &err) {
if (options.rtSettings.verbose) {
printf("RTImage::setPaths / Error code %d while reading values from \"%s\":\n%s\n", err.code(), configFilename.c_str(), err.what().c_str());
}
} catch (...) {
if (options.rtSettings.verbose) {
printf("RTImage::setPaths / Unknown exception while trying to load \"%s\"!\n", configFilename.c_str());
}
} catch(const Glib::Exception&) {}
if (options.rtSettings.verbose) {
std::cerr << "Icon \"" << iconName << "\" could not be found!" << std::endl;
}
if (hasKeyFile && keyFile.has_group ("General")) {
Glib::ustring iSet;
if (keyFile.has_key ("General", "Iconset")) {
iSet = keyFile.get_string ("General", "Iconset");
}
if (iSet.length()) {
imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", Glib::build_filename(iSet, "actions"))));
imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", iSet)));
imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", Glib::build_filename(iSet, "devices"))));
imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", Glib::build_filename(iSet, "places"))));
}
iSet.clear();
if (keyFile.has_key ("General", "FallbackIconset")) {
iSet = keyFile.get_string ("General", "FallbackIconset");
}
if (iSet.length()) {
imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", Glib::build_filename(iSet, "actions"))));
imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", iSet)));
imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", Glib::build_filename(iSet, "devices"))));
imagesPaths.push_back (Glib::build_filename(argv0, Glib::build_filename("images", Glib::build_filename(iSet, "places"))));
}
}
// The images/ folder is the second fallback solution
imagesPaths.push_back (Glib::build_filename(argv0, "images"));
return Glib::ustring();
}
void RTImage::setPaths (const Options& options)
{
Glib::ustring iconSet;
// Either use the system icon set or the one specified in the options.
if (options.useSystemTheme) {
iconSet = Glib::build_filename (argv0, "themes", "system.iconset");
} else {
iconSet = Glib::build_filename (argv0, "themes", options.theme + ".iconset");
}
imagePaths.clear ();
if (!loadIconSet (iconSet)) {
// If the preferred icon set is unavailable, fall back to the default icon set.
loadIconSet (Glib::build_filename (argv0, "themes", "Default.iconset"));
}
// The images folder is the second fallback solution.
imagePaths.push_back (Glib::build_filename(argv0, "images"));
}
Glib::RefPtr<Gdk::Pixbuf> RTImage::createFromFile (const Glib::ustring& fileName)
{
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
try {
const auto filePath = findIconAbsolutePath (fileName);
if (!filePath.empty ()) {
pixbuf = Gdk::Pixbuf::create_from_file (filePath);
}
} catch (const Glib::Exception& exception) {
if (options.rtSettings.verbose) {
std::cerr << "Failed to load image \"" << fileName << "\": " << exception.what() << std::endl;
}
}
return pixbuf;
}
Cairo::RefPtr<Cairo::ImageSurface> RTImage::createFromPng (const Glib::ustring& fileName)
{
Cairo::RefPtr<Cairo::ImageSurface> surface;
try {
const auto filePath = findIconAbsolutePath (fileName);
if (!filePath.empty()) {
surface = Cairo::ImageSurface::create_from_png (Glib::locale_from_utf8 (filePath));
}
} catch (const Glib::Exception& exception) {
if (options.rtSettings.verbose) {
std::cerr << "Failed to load PNG \"" << fileName << "\": " << exception.what() << std::endl;
}
}
return surface;
}

View File

@@ -19,17 +19,26 @@
#ifndef _RTIMAGE_
#define _RTIMAGE_
#include <gtkmm.h>
#include "options.h"
#include <gtkmm/image.h>
class Options;
/**
* @brief A derived class of Gtk::Image in order to handle theme-related icon sets.
*/
class RTImage : public Gtk::Image
{
public:
RTImage(Glib::ustring fileName, Glib::ustring rtlFileName = "");
static void setPaths(Options &opt);
static void updateImages();
void changeImage(Glib::ustring &newImage);
static Glib::ustring findIconAbsolutePath(const Glib::ustring &iconFName);
RTImage (const Glib::ustring& fileName, const Glib::ustring& rtlFileName = Glib::ustring());
void changeImage (const Glib::ustring& imageName);
static void updateImages ();
static Glib::ustring findIconAbsolutePath (const Glib::ustring& iconName);
static void setPaths (const Options& options);
static Glib::RefPtr<Gdk::Pixbuf> createFromFile (const Glib::ustring& fileName);
static Cairo::RefPtr<Cairo::ImageSurface> createFromPng (const Glib::ustring& fileName);
};
#endif

View File

@@ -17,10 +17,14 @@
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include "splash.h"
#include "multilangmgr.h"
#include <glib/gstdio.h>
#include "../rtengine/safegtk.h"
#include "multilangmgr.h"
#include "rtimage.h"
extern Glib::ustring argv0;
extern Glib::ustring creditsPath;
extern Glib::ustring licensePath;
@@ -29,8 +33,7 @@ extern Glib::ustring versionSuffixString;
SplashImage::SplashImage ()
{
pixbuf = safe_create_from_file ("splash.png");
pixbuf = RTImage::createFromFile ("splash.png");
set_size_request (pixbuf->get_width(), pixbuf->get_height());
}

View File

@@ -17,10 +17,11 @@
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include "whitebalance.h"
#include <iomanip>
#include "rtimage.h"
#include "options.h"
#include "../rtengine/safegtk.h"
#define MINTEMP 1500 //1200
#define MAXTEMP 60000 //12000
@@ -42,19 +43,19 @@ Glib::RefPtr<Gdk::Pixbuf> WhiteBalance::wbCameraPB, WhiteBalance::wbAutoPB, Whit
void WhiteBalance::init ()
{
wbPixbufs[WBT_CAMERA] = safe_create_from_file("wb-camera.png");
wbPixbufs[WBT_AUTO] = safe_create_from_file("wb-auto.png");
wbPixbufs[WBT_DAYLIGHT] = safe_create_from_file("wb-sun.png");
wbPixbufs[WBT_CLOUDY] = safe_create_from_file("wb-cloudy.png");
wbPixbufs[WBT_SHADE] = safe_create_from_file("wb-shade.png");
wbPixbufs[WBT_WATER] = safe_create_from_file("wb-water.png");
// wbPixbufs[WBT_WATER2] = safe_create_from_file("wb-water.png");
wbPixbufs[WBT_TUNGSTEN] = safe_create_from_file("wb-tungsten.png");
wbPixbufs[WBT_FLUORESCENT] = safe_create_from_file("wb-fluorescent.png");
wbPixbufs[WBT_LAMP] = safe_create_from_file("wb-lamp.png");
wbPixbufs[WBT_FLASH] = safe_create_from_file("wb-flash.png");
wbPixbufs[WBT_LED] = safe_create_from_file("wb-led.png");
wbPixbufs[WBT_CUSTOM] = safe_create_from_file("wb-custom.png");
wbPixbufs[WBT_CAMERA] = RTImage::createFromFile ("wb-camera.png");
wbPixbufs[WBT_AUTO] = RTImage::createFromFile ("wb-auto.png");
wbPixbufs[WBT_DAYLIGHT] = RTImage::createFromFile ("wb-sun.png");
wbPixbufs[WBT_CLOUDY] = RTImage::createFromFile ("wb-cloudy.png");
wbPixbufs[WBT_SHADE] = RTImage::createFromFile ("wb-shade.png");
wbPixbufs[WBT_WATER] = RTImage::createFromFile ("wb-water.png");
// wbPixbufs[WBT_WATER2] = RTImage::createFromFile ("wb-water.png");
wbPixbufs[WBT_TUNGSTEN] = RTImage::createFromFile ("wb-tungsten.png");
wbPixbufs[WBT_FLUORESCENT] = RTImage::createFromFile ("wb-fluorescent.png");
wbPixbufs[WBT_LAMP] = RTImage::createFromFile ("wb-lamp.png");
wbPixbufs[WBT_FLASH] = RTImage::createFromFile ("wb-flash.png");
wbPixbufs[WBT_LED] = RTImage::createFromFile ("wb-led.png");
wbPixbufs[WBT_CUSTOM] = RTImage::createFromFile ("wb-custom.png");
}
void WhiteBalance::cleanup ()