Convert remaining RTPixbuf to RTSurface
Changes: - Remove RTPixbuf use in directory browser to use native GTK mechanism - Replace RTPixbuf by RTSurface for thumbnail icons - Remove now useless RTPixbuf class Fixes: - Elaborate RTSurface width / height based on the type
This commit is contained in:
@@ -26,12 +26,13 @@
|
||||
#include "multilangmgr.h"
|
||||
#include "thumbbrowserbase.h"
|
||||
#include "thumbnail.h"
|
||||
#include "rtsurface.h"
|
||||
|
||||
#include "../rtengine/procparams.h"
|
||||
#include "../rtengine/rtengine.h"
|
||||
|
||||
bool BatchQueueEntry::iconsLoaded(false);
|
||||
std::shared_ptr<RTPixbuf> BatchQueueEntry::savedAsIcon;
|
||||
std::shared_ptr<RTSurface> BatchQueueEntry::savedAsIcon(std::shared_ptr<RTSurface>(nullptr));
|
||||
|
||||
BatchQueueEntry::BatchQueueEntry (rtengine::ProcessingJob* pjob, const rtengine::procparams::ProcParams& pparams, Glib::ustring fname, int prevw, int prevh, Thumbnail* thm, bool overwrite) :
|
||||
ThumbBrowserEntryBase(fname),
|
||||
@@ -59,7 +60,7 @@ BatchQueueEntry::BatchQueueEntry (rtengine::ProcessingJob* pjob, const rtengine:
|
||||
#endif
|
||||
|
||||
if (!iconsLoaded) {
|
||||
savedAsIcon = std::shared_ptr<RTPixbuf>(new RTPixbuf("save-small", Gtk::ICON_SIZE_BUTTON));
|
||||
savedAsIcon = std::shared_ptr<RTSurface>(new RTSurface("save-small", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
iconsLoaded = true;
|
||||
}
|
||||
|
||||
@@ -153,13 +154,13 @@ void BatchQueueEntry::removeButtonSet ()
|
||||
buttonSet = nullptr;
|
||||
}
|
||||
|
||||
std::vector<Glib::RefPtr<Gdk::Pixbuf>> BatchQueueEntry::getIconsOnImageArea ()
|
||||
std::vector<std::shared_ptr<RTSurface>> BatchQueueEntry::getIconsOnImageArea ()
|
||||
{
|
||||
|
||||
std::vector<Glib::RefPtr<Gdk::Pixbuf> > ret;
|
||||
std::vector<std::shared_ptr<RTSurface>> ret;
|
||||
|
||||
if (!outFileName.empty()) {
|
||||
ret.push_back (savedAsIcon->get());
|
||||
ret.push_back (savedAsIcon);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@@ -29,7 +29,7 @@
|
||||
#include "../rtengine/noncopyable.h"
|
||||
|
||||
class Thumbnail;
|
||||
class RTPixbuf;
|
||||
class RTSurface;
|
||||
|
||||
namespace rtengine
|
||||
{
|
||||
@@ -62,7 +62,7 @@ class BatchQueueEntry final : public ThumbBrowserEntryBase, public BQEntryUpdate
|
||||
|
||||
public:
|
||||
|
||||
static std::shared_ptr<RTPixbuf> savedAsIcon;
|
||||
static std::shared_ptr<RTSurface> savedAsIcon;
|
||||
|
||||
rtengine::ProcessingJob* job;
|
||||
const std::unique_ptr<rtengine::procparams::ProcParams> params;
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
|
||||
void removeButtonSet ();
|
||||
|
||||
std::vector<Glib::RefPtr<Gdk::Pixbuf>> getIconsOnImageArea () override;
|
||||
std::vector<std::shared_ptr<RTSurface>> getIconsOnImageArea () override;
|
||||
void getIconSize (int& w, int& h) const override;
|
||||
std::tuple<Glib::ustring, bool> getToolTip (int x, int y) const override;
|
||||
|
||||
|
@@ -86,6 +86,15 @@ std::vector<Glib::ustring> listSubDirs (const Glib::RefPtr<Gio::File>& dir, bool
|
||||
DirBrowser::DirBrowser () : dirTreeModel(),
|
||||
dtColumns(),
|
||||
tvc(M("DIRBROWSER_FOLDERS")),
|
||||
|
||||
openfolder("folder-open-small"),
|
||||
closedfolder("folder-closed-small"),
|
||||
icdrom("device-optical"),
|
||||
ifloppy("device-floppy"),
|
||||
ihdd("device-hdd"),
|
||||
inetwork("device-network"),
|
||||
iremovable("device-usb"),
|
||||
|
||||
expandSuccess(false)
|
||||
#ifdef WIN32
|
||||
, volumes(0)
|
||||
@@ -120,15 +129,6 @@ DirBrowser::~DirBrowser()
|
||||
|
||||
void DirBrowser::fillDirTree ()
|
||||
{
|
||||
|
||||
openfolder = std::shared_ptr<RTPixbuf>(new RTPixbuf("folder-open-small", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
closedfolder = std::shared_ptr<RTPixbuf>(new RTPixbuf("folder-closed-small", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
icdrom = std::shared_ptr<RTPixbuf>(new RTPixbuf("device-optical", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
ifloppy = std::shared_ptr<RTPixbuf>(new RTPixbuf("device-floppy", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
ihdd = std::shared_ptr<RTPixbuf>(new RTPixbuf("device-hdd", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
iremovable = std::shared_ptr<RTPixbuf>(new RTPixbuf("device-usb", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
inetwork = std::shared_ptr<RTPixbuf>(new RTPixbuf("device-network", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
|
||||
//Create the Tree model:
|
||||
dirTreeModel = Gtk::TreeStore::create(dtColumns);
|
||||
dirtree->set_model (dirTreeModel);
|
||||
@@ -136,10 +136,9 @@ void DirBrowser::fillDirTree ()
|
||||
fillRoot ();
|
||||
|
||||
Gtk::CellRendererPixbuf* render_pb = Gtk::manage ( new Gtk::CellRendererPixbuf () );
|
||||
render_pb->property_stock_size() = Gtk::ICON_SIZE_SMALL_TOOLBAR;
|
||||
tvc.pack_start (*render_pb, false);
|
||||
tvc.add_attribute(*render_pb, "pixbuf-expander-closed", dtColumns.icon2);
|
||||
tvc.add_attribute(*render_pb, "pixbuf", dtColumns.icon2);
|
||||
tvc.add_attribute(*render_pb, "pixbuf-expander-open", dtColumns.icon1);
|
||||
tvc.add_attribute(*render_pb, "icon-name", dtColumns.icon_name);
|
||||
tvc.pack_start (crt);
|
||||
tvc.add_attribute(crt, "text", dtColumns.filename);
|
||||
|
||||
@@ -156,6 +155,7 @@ void DirBrowser::fillDirTree ()
|
||||
render_pb->property_ypad() = 0;
|
||||
|
||||
dirtree->signal_row_expanded().connect(sigc::mem_fun(*this, &DirBrowser::row_expanded));
|
||||
dirtree->signal_row_collapsed().connect(sigc::mem_fun(*this, &DirBrowser::row_collapsed));
|
||||
dirtree->signal_row_activated().connect(sigc::mem_fun(*this, &DirBrowser::row_activated));
|
||||
dirTreeModel->signal_sort_column_changed().connect(sigc::mem_fun(*this, &DirBrowser::on_sort_column_changed));
|
||||
}
|
||||
@@ -175,22 +175,17 @@ void DirBrowser::addRoot (char letter)
|
||||
int type = GetDriveType (volume);
|
||||
|
||||
if (type == DRIVE_CDROM) {
|
||||
root->set_value (0, icdrom->get());
|
||||
root->set_value (1, icdrom->get());
|
||||
root->set_value (dtColumns.icon_name, icdrom);
|
||||
} else if (type == DRIVE_REMOVABLE) {
|
||||
if (letter - 'A' < 2) {
|
||||
root->set_value (0, ifloppy->get());
|
||||
root->set_value (1, ifloppy->get());
|
||||
root->set_value (dtColumns.icon_name, ifloppy);
|
||||
} else {
|
||||
root->set_value (0, iremovable->get());
|
||||
root->set_value (1, iremovable->get());
|
||||
root->set_value (dtColumns.icon_name, iremovable);
|
||||
}
|
||||
} else if (type == DRIVE_REMOTE) {
|
||||
root->set_value (0, inetwork->get());
|
||||
root->set_value (1, inetwork->get());
|
||||
root->set_value (dtColumns.icon_name, inetwork);
|
||||
} else if (type == DRIVE_FIXED) {
|
||||
root->set_value (0, ihdd->get());
|
||||
root->set_value (1, ihdd->get());
|
||||
root->set_value (dtColumns.icon_name, ihdd);
|
||||
}
|
||||
|
||||
Gtk::TreeModel::iterator child = dirTreeModel->append (root->children());
|
||||
@@ -319,11 +314,20 @@ void DirBrowser::row_expanded (const Gtk::TreeModel::iterator& iter, const Gtk::
|
||||
|
||||
expandSuccess = true;
|
||||
|
||||
// Update row icon
|
||||
iter->set_value(dtColumns.icon_name, openfolder);
|
||||
|
||||
Glib::RefPtr<Gio::FileMonitor> monitor = dir->monitor_directory ();
|
||||
iter->set_value (dtColumns.monitor, monitor);
|
||||
monitor->signal_changed().connect (sigc::bind(sigc::mem_fun(*this, &DirBrowser::file_changed), iter, dir->get_parse_name()));
|
||||
}
|
||||
|
||||
void DirBrowser::row_collapsed (const Gtk::TreeModel::iterator& iter, const Gtk::TreeModel::Path& path)
|
||||
{
|
||||
// Update row icon
|
||||
iter->set_value(dtColumns.icon_name, closedfolder);
|
||||
}
|
||||
|
||||
void DirBrowser::updateDir (const Gtk::TreeModel::iterator& iter)
|
||||
{
|
||||
|
||||
@@ -366,8 +370,7 @@ void DirBrowser::addDir (const Gtk::TreeModel::iterator& iter, const Glib::ustri
|
||||
|
||||
Gtk::TreeModel::iterator child = dirTreeModel->append(iter->children());
|
||||
child->set_value (dtColumns.filename, dirname);
|
||||
child->set_value (dtColumns.icon1, openfolder->get());
|
||||
child->set_value (dtColumns.icon2, closedfolder->get());
|
||||
child->set_value (dtColumns.icon_name, closedfolder);
|
||||
Glib::ustring fullname = Glib::build_filename (iter->get_value (dtColumns.dirname), dirname);
|
||||
child->set_value (dtColumns.dirname, fullname);
|
||||
Gtk::TreeModel::iterator fooRow = dirTreeModel->append(child->children());
|
||||
|
@@ -23,8 +23,6 @@
|
||||
|
||||
#include "guiutils.h"
|
||||
|
||||
class RTPixbuf;
|
||||
|
||||
class DirBrowser : public Gtk::Box
|
||||
{
|
||||
public:
|
||||
@@ -37,15 +35,13 @@ private:
|
||||
struct DirTreeColumns : public Gtk::TreeModelColumnRecord {
|
||||
public:
|
||||
Gtk::TreeModelColumn<Glib::ustring> filename;
|
||||
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > icon1;
|
||||
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > icon2;
|
||||
Gtk::TreeModelColumn<Glib::ustring> icon_name;
|
||||
Gtk::TreeModelColumn<Glib::ustring> dirname;
|
||||
Gtk::TreeModelColumn<Glib::RefPtr<Gio::FileMonitor> > monitor;
|
||||
|
||||
DirTreeColumns()
|
||||
{
|
||||
add(icon1);
|
||||
add(icon2);
|
||||
add(icon_name);
|
||||
add(filename);
|
||||
add(dirname);
|
||||
add(monitor);
|
||||
@@ -55,7 +51,6 @@ private:
|
||||
DirTreeColumns dtColumns;
|
||||
Gtk::TreeViewColumn tvc;
|
||||
Gtk::CellRendererText crt;
|
||||
Gtk::CellRendererPixbuf crb;
|
||||
|
||||
|
||||
Gtk::TreeView *dirtree;
|
||||
@@ -64,13 +59,13 @@ private:
|
||||
|
||||
void fillRoot ();
|
||||
|
||||
std::shared_ptr<RTPixbuf> openfolder;
|
||||
std::shared_ptr<RTPixbuf> closedfolder;
|
||||
std::shared_ptr<RTPixbuf> icdrom;
|
||||
std::shared_ptr<RTPixbuf> ifloppy;
|
||||
std::shared_ptr<RTPixbuf> ihdd;
|
||||
std::shared_ptr<RTPixbuf> inetwork;
|
||||
std::shared_ptr<RTPixbuf> iremovable;
|
||||
Glib::ustring openfolder;
|
||||
Glib::ustring closedfolder;
|
||||
Glib::ustring icdrom;
|
||||
Glib::ustring ifloppy;
|
||||
Glib::ustring ihdd;
|
||||
Glib::ustring inetwork;
|
||||
Glib::ustring iremovable;
|
||||
|
||||
bool expandSuccess;
|
||||
|
||||
@@ -96,6 +91,7 @@ public:
|
||||
void fillDirTree ();
|
||||
void on_sort_column_changed() const;
|
||||
void row_expanded (const Gtk::TreeModel::iterator& iter, const Gtk::TreeModel::Path& path);
|
||||
void row_collapsed (const Gtk::TreeModel::iterator& iter, const Gtk::TreeModel::Path& path);
|
||||
void row_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);
|
||||
void file_changed (const Glib::RefPtr<Gio::File>& file, const Glib::RefPtr<Gio::File>& other_file, Gio::FileMonitorEvent event_type, const Gtk::TreeModel::iterator& iter, const Glib::ustring& dirName);
|
||||
void open (const Glib::ustring& dirName, const Glib::ustring& fileName = ""); // goes to dir "dirName" and selects file "fileName"
|
||||
|
@@ -38,11 +38,11 @@
|
||||
//extern Glib::Threads::Thread* mainThread;
|
||||
|
||||
bool FileBrowserEntry::iconsLoaded(false);
|
||||
std::shared_ptr<RTPixbuf> FileBrowserEntry::editedIcon(std::shared_ptr<RTPixbuf>(nullptr));
|
||||
std::shared_ptr<RTPixbuf> FileBrowserEntry::recentlySavedIcon(std::shared_ptr<RTPixbuf>(nullptr));
|
||||
std::shared_ptr<RTPixbuf> FileBrowserEntry::enqueuedIcon(std::shared_ptr<RTPixbuf>(nullptr));
|
||||
std::shared_ptr<RTPixbuf> FileBrowserEntry::hdr(std::shared_ptr<RTPixbuf>(nullptr));
|
||||
std::shared_ptr<RTPixbuf> FileBrowserEntry::ps(std::shared_ptr<RTPixbuf>(nullptr));
|
||||
std::shared_ptr<RTSurface> FileBrowserEntry::editedIcon(std::shared_ptr<RTSurface>(nullptr));
|
||||
std::shared_ptr<RTSurface> FileBrowserEntry::recentlySavedIcon(std::shared_ptr<RTSurface>(nullptr));
|
||||
std::shared_ptr<RTSurface> FileBrowserEntry::enqueuedIcon(std::shared_ptr<RTSurface>(nullptr));
|
||||
std::shared_ptr<RTSurface> FileBrowserEntry::hdr(std::shared_ptr<RTSurface>(nullptr));
|
||||
std::shared_ptr<RTSurface> FileBrowserEntry::ps(std::shared_ptr<RTSurface>(nullptr));
|
||||
|
||||
FileBrowserEntry::FileBrowserEntry (Thumbnail* thm, const Glib::ustring& fname)
|
||||
: ThumbBrowserEntryBase (fname), wasInside(false), iatlistener(nullptr), press_x(0), press_y(0), action_x(0), action_y(0), rot_deg(0.0), landscape(true), cropParams(new rtengine::procparams::CropParams), cropgl(nullptr), state(SNormal), crop_custom_ratio(0.f)
|
||||
@@ -61,11 +61,11 @@ FileBrowserEntry::FileBrowserEntry (Thumbnail* thm, const Glib::ustring& fname)
|
||||
scale = 1;
|
||||
|
||||
if (!iconsLoaded) {
|
||||
editedIcon = std::shared_ptr<RTPixbuf>(new RTPixbuf("tick-small", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
recentlySavedIcon = std::shared_ptr<RTPixbuf>(new RTPixbuf("save-small", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
enqueuedIcon = std::shared_ptr<RTPixbuf>(new RTPixbuf("gears-small", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
hdr = std::shared_ptr<RTPixbuf>(new RTPixbuf("filetype-hdr", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
ps = std::shared_ptr<RTPixbuf>(new RTPixbuf("filetype-ps", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
editedIcon = std::shared_ptr<RTSurface>(new RTSurface("tick-small", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
recentlySavedIcon = std::shared_ptr<RTSurface>(new RTSurface("save-small", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
enqueuedIcon = std::shared_ptr<RTSurface>(new RTSurface("gears-small", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
hdr = std::shared_ptr<RTSurface>(new RTSurface("filetype-hdr", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
ps = std::shared_ptr<RTSurface>(new RTSurface("filetype-ps", Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||
iconsLoaded = true;
|
||||
}
|
||||
|
||||
@@ -125,43 +125,43 @@ void FileBrowserEntry::calcThumbnailSize ()
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Glib::RefPtr<Gdk::Pixbuf>> FileBrowserEntry::getIconsOnImageArea ()
|
||||
std::vector<std::shared_ptr<RTSurface>> FileBrowserEntry::getIconsOnImageArea ()
|
||||
{
|
||||
if (!thumbnail) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<Glib::RefPtr<Gdk::Pixbuf>> ret;
|
||||
std::vector<std::shared_ptr<RTSurface>> ret;
|
||||
|
||||
if (thumbnail->hasProcParams() && editedIcon) {
|
||||
ret.push_back(editedIcon->get());
|
||||
ret.push_back(editedIcon);
|
||||
}
|
||||
|
||||
if (thumbnail->isRecentlySaved() && recentlySavedIcon) {
|
||||
ret.push_back(recentlySavedIcon->get());
|
||||
ret.push_back(recentlySavedIcon);
|
||||
}
|
||||
|
||||
if (thumbnail->isEnqueued () && enqueuedIcon) {
|
||||
ret.push_back(enqueuedIcon->get());
|
||||
ret.push_back(enqueuedIcon);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<Glib::RefPtr<Gdk::Pixbuf>> FileBrowserEntry::getSpecificityIconsOnImageArea ()
|
||||
std::vector<std::shared_ptr<RTSurface>> FileBrowserEntry::getSpecificityIconsOnImageArea ()
|
||||
{
|
||||
if (!thumbnail) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<Glib::RefPtr<Gdk::Pixbuf>> ret;
|
||||
std::vector<std::shared_ptr<RTSurface>> ret;
|
||||
|
||||
if (thumbnail->isHDR() && hdr) {
|
||||
ret.push_back (hdr->get());
|
||||
ret.push_back (hdr);
|
||||
}
|
||||
|
||||
if (thumbnail->isPixelShift() && ps) {
|
||||
ret.push_back (ps->get());
|
||||
ret.push_back (ps);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@@ -35,7 +35,7 @@
|
||||
|
||||
class FileBrowserEntry;
|
||||
class Thumbnail;
|
||||
class RTPixbuf;
|
||||
class RTSurface;
|
||||
|
||||
struct FileBrowserEntryIdleHelper {
|
||||
FileBrowserEntry* fbentry;
|
||||
@@ -73,11 +73,11 @@ class FileBrowserEntry final : public ThumbBrowserEntryBase,
|
||||
|
||||
public:
|
||||
|
||||
static std::shared_ptr<RTPixbuf> editedIcon;
|
||||
static std::shared_ptr<RTPixbuf> recentlySavedIcon;
|
||||
static std::shared_ptr<RTPixbuf> enqueuedIcon;
|
||||
static std::shared_ptr<RTPixbuf> hdr;
|
||||
static std::shared_ptr<RTPixbuf> ps;
|
||||
static std::shared_ptr<RTSurface> editedIcon;
|
||||
static std::shared_ptr<RTSurface> recentlySavedIcon;
|
||||
static std::shared_ptr<RTSurface> enqueuedIcon;
|
||||
static std::shared_ptr<RTSurface> hdr;
|
||||
static std::shared_ptr<RTSurface> ps;
|
||||
|
||||
FileBrowserEntry (Thumbnail* thm, const Glib::ustring& fname);
|
||||
~FileBrowserEntry () override;
|
||||
@@ -94,8 +94,8 @@ public:
|
||||
void refreshQuickThumbnailImage () override;
|
||||
void calcThumbnailSize () override;
|
||||
|
||||
std::vector<Glib::RefPtr<Gdk::Pixbuf>> getIconsOnImageArea () override;
|
||||
std::vector<Glib::RefPtr<Gdk::Pixbuf>> getSpecificityIconsOnImageArea () override;
|
||||
std::vector<std::shared_ptr<RTSurface>> getIconsOnImageArea () override;
|
||||
std::vector<std::shared_ptr<RTSurface>> getSpecificityIconsOnImageArea () override;
|
||||
void getIconSize (int& w, int& h) const override;
|
||||
|
||||
// thumbnaillistener interface
|
||||
|
@@ -138,7 +138,7 @@ Cairo::RefPtr<Cairo::ImageSurface> RTScalable::loadSurfaceFromSVG(const Glib::us
|
||||
// Directly use fname as a path
|
||||
path = fname;
|
||||
} else {
|
||||
// Look for PNG file in "images" folder
|
||||
// Look for SVG file in "images" folder
|
||||
Glib::ustring imagesFolder = Glib::build_filename(DATA_SEARCH_PATH, "images");
|
||||
path = Glib::build_filename(imagesFolder, fname);
|
||||
}
|
||||
|
@@ -88,18 +88,68 @@ RTSurface::RTSurface(const Glib::ustring &fname) :
|
||||
|
||||
int RTSurface::getWidth()
|
||||
{
|
||||
return
|
||||
surface
|
||||
? (surface->get_width() / RTScalable::getScale())
|
||||
: -1;
|
||||
int w, h;
|
||||
|
||||
if (hasSurface()) {
|
||||
switch (type) {
|
||||
case RTSurface::IconType:
|
||||
// Get width from Gtk::IconSize
|
||||
if (!Gtk::IconSize::lookup(icon_size, w, h)) { // Size in invalid
|
||||
w = h = -1; // Invalid case
|
||||
}
|
||||
|
||||
return w;
|
||||
|
||||
case RTSurface::PNGType:
|
||||
// Directly return surface width
|
||||
return surface->get_width();
|
||||
|
||||
case RTSurface::SVGType:
|
||||
// Returned size shall consider the scaling
|
||||
return (surface->get_width() / RTScalable::getScale());
|
||||
|
||||
case RTSurface::InvalidType:
|
||||
default:
|
||||
// Invalid case
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
// Invalid case
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int RTSurface::getHeight()
|
||||
{
|
||||
return
|
||||
surface
|
||||
? (surface->get_height() / RTScalable::getScale())
|
||||
: -1;
|
||||
int w, h;
|
||||
|
||||
if (hasSurface()) {
|
||||
switch (type) {
|
||||
case RTSurface::IconType:
|
||||
// Get width from Gtk::IconSize
|
||||
if (!Gtk::IconSize::lookup(icon_size, w, h)) { // Size in invalid
|
||||
w = h = -1; // Invalid case
|
||||
}
|
||||
|
||||
return h;
|
||||
|
||||
case RTSurface::PNGType:
|
||||
// Directly return surface width
|
||||
return surface->get_height();
|
||||
|
||||
case RTSurface::SVGType:
|
||||
// Returned size shall consider the scaling
|
||||
return (surface->get_height() / RTScalable::getScale());
|
||||
|
||||
case RTSurface::InvalidType:
|
||||
default:
|
||||
// Invalid case
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
// Invalid case
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
bool RTSurface::hasSurface()
|
||||
@@ -132,168 +182,3 @@ Cairo::RefPtr<Cairo::ImageSurface> RTSurface::get()
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
RTPixbuf::RTPixbuf()
|
||||
{
|
||||
// Initialize "back" parameters from RTScalable
|
||||
dpiBack = RTPixbuf::getDPI();
|
||||
scaleBack = RTPixbuf::getScale();
|
||||
|
||||
// Initialize other private parameters
|
||||
type = RTPixbuf::InvalidType;
|
||||
name = "";
|
||||
icon_size = Gtk::ICON_SIZE_INVALID;
|
||||
}
|
||||
|
||||
RTPixbuf::RTPixbuf(const Glib::ustring &icon_name, const Gtk::IconSize iconSize) :
|
||||
RTPixbuf()
|
||||
{
|
||||
// Create surface
|
||||
const Cairo::RefPtr<Cairo::ImageSurface> surface = RTScalable::loadSurfaceFromIcon(icon_name, iconSize);
|
||||
|
||||
if (surface) {
|
||||
// Downscale surface before creating pixbuf
|
||||
const Cairo::RefPtr<Cairo::Surface> _surface = Cairo::Surface::create(surface,
|
||||
Cairo::CONTENT_COLOR_ALPHA,
|
||||
surface->get_width() / RTScalable::getScale(),
|
||||
surface->get_height() / RTScalable::getScale());
|
||||
const auto c = Cairo::Context::create(_surface);
|
||||
c->scale(1. / static_cast<double>(RTScalable::getScale()), 1. / static_cast<double>(RTScalable::getScale()));
|
||||
c->set_source(surface, 0., 0.);
|
||||
c->paint();
|
||||
|
||||
// Create pixbuf from surface
|
||||
pixbuf = Gdk::Pixbuf::create(_surface,
|
||||
0,
|
||||
0,
|
||||
surface->get_width() / RTScalable::getScale(),
|
||||
surface->get_height() / RTScalable::getScale());
|
||||
|
||||
// Save private parameters
|
||||
type = RTPixbuf::IconType;
|
||||
name = icon_name;
|
||||
icon_size = iconSize;
|
||||
}
|
||||
}
|
||||
|
||||
RTPixbuf::RTPixbuf(const Glib::ustring &fname) :
|
||||
RTPixbuf()
|
||||
{
|
||||
// Create surface based on file extension
|
||||
const auto pos = fname.find_last_of('.');
|
||||
|
||||
if (pos >= 0 && pos < fname.length()) {
|
||||
const auto fext = fname.substr(pos + 1, fname.length()).lowercase();
|
||||
|
||||
// Case where fname is a PNG file
|
||||
if (fext == "png") {
|
||||
// Create surface from PNG file
|
||||
const Cairo::RefPtr<Cairo::ImageSurface> surface = RTScalable::loadSurfaceFromPNG(fname);
|
||||
|
||||
if (surface) {
|
||||
// Downscale surface before creating pixbuf
|
||||
const Cairo::RefPtr<Cairo::Surface> _surface = Cairo::Surface::create(surface,
|
||||
Cairo::CONTENT_COLOR_ALPHA,
|
||||
surface->get_width() / RTScalable::getScale(),
|
||||
surface->get_height() / RTScalable::getScale());
|
||||
const auto c = Cairo::Context::create(_surface);
|
||||
c->scale(1. / static_cast<double>(RTScalable::getScale()), 1. / static_cast<double>(RTScalable::getScale()));
|
||||
c->set_source(surface, 0., 0.);
|
||||
c->paint();
|
||||
|
||||
// Create pixbuf from surface
|
||||
pixbuf = Gdk::Pixbuf::create(_surface,
|
||||
0,
|
||||
0,
|
||||
surface->get_width() / RTScalable::getScale(),
|
||||
surface->get_height() / RTScalable::getScale());
|
||||
|
||||
// Save private parameter
|
||||
type = RTPixbuf::PNGType;
|
||||
name = fname;
|
||||
}
|
||||
}
|
||||
|
||||
// Case where fname is a SVG file
|
||||
if (fext == "svg") {
|
||||
// Create surface from SVG file
|
||||
const Cairo::RefPtr<Cairo::ImageSurface> surface = RTScalable::loadSurfaceFromSVG(fname);
|
||||
|
||||
if (surface) {
|
||||
// Downscale surface before creating pixbuf
|
||||
const Cairo::RefPtr<Cairo::Surface> _surface = Cairo::Surface::create(surface,
|
||||
Cairo::CONTENT_COLOR_ALPHA,
|
||||
surface->get_width() / RTScalable::getScale(),
|
||||
surface->get_height() / RTScalable::getScale());
|
||||
const auto c = Cairo::Context::create(_surface);
|
||||
c->scale(1. / static_cast<double>(RTScalable::getScale()), 1. / static_cast<double>(RTScalable::getScale()));
|
||||
c->set_source(surface, 0., 0.);
|
||||
c->paint();
|
||||
|
||||
// Create pixbuf from surface
|
||||
pixbuf = Gdk::Pixbuf::create(_surface,
|
||||
0,
|
||||
0,
|
||||
surface->get_width() / RTScalable::getScale(),
|
||||
surface->get_height() / RTScalable::getScale());
|
||||
|
||||
// Save private parameter
|
||||
type = RTPixbuf::SVGType;
|
||||
name = fname;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int RTPixbuf::getWidth()
|
||||
{
|
||||
return
|
||||
pixbuf
|
||||
? pixbuf->get_width()
|
||||
: -1;
|
||||
}
|
||||
|
||||
int RTPixbuf::getHeight()
|
||||
{
|
||||
return
|
||||
pixbuf
|
||||
? pixbuf->get_height()
|
||||
: -1;
|
||||
}
|
||||
|
||||
bool RTPixbuf::hasPixbuf()
|
||||
{
|
||||
return static_cast<bool>(pixbuf);
|
||||
}
|
||||
|
||||
Glib::RefPtr<Gdk::Pixbuf> RTPixbuf::get()
|
||||
{
|
||||
if (dpiBack != RTScalable::getDPI() ||
|
||||
scaleBack != RTScalable::getScale()) {
|
||||
Cairo::RefPtr<Cairo::ImageSurface> surface;
|
||||
|
||||
// Surface needs to be regenerated
|
||||
switch (type) {
|
||||
case RTPixbuf::IconType :
|
||||
surface = RTScalable::loadSurfaceFromIcon(name, icon_size);
|
||||
pixbuf = Gdk::Pixbuf::create(surface, 0, 0, surface->get_width(), surface->get_height());
|
||||
break;
|
||||
case RTPixbuf::PNGType :
|
||||
surface = RTScalable::loadSurfaceFromPNG(name);
|
||||
pixbuf = Gdk::Pixbuf::create(surface, 0, 0, surface->get_width(), surface->get_height());
|
||||
break;
|
||||
case RTPixbuf::SVGType :
|
||||
surface = RTScalable::loadSurfaceFromSVG(name);
|
||||
pixbuf = Gdk::Pixbuf::create(surface, 0, 0, surface->get_width(), surface->get_height());
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
// Save new DPI and scale
|
||||
dpiBack = RTScalable::getDPI();
|
||||
scaleBack = RTScalable::getScale();
|
||||
}
|
||||
|
||||
return pixbuf;
|
||||
}
|
||||
|
@@ -53,36 +53,3 @@ public:
|
||||
|
||||
Cairo::RefPtr<Cairo::ImageSurface> get();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A custom class in order to handle Hi-DPI pixbuf.
|
||||
*/
|
||||
class RTPixbuf final : public RTScalable
|
||||
{
|
||||
public:
|
||||
enum RTPixbufType {
|
||||
InvalidType = 1,
|
||||
IconType = 2,
|
||||
PNGType = 3,
|
||||
SVGType = 4
|
||||
};
|
||||
|
||||
private:
|
||||
double dpiBack; // Used to identify dpi change
|
||||
int scaleBack; // Used to identify scale change
|
||||
RTPixbufType type;
|
||||
Glib::ustring name;
|
||||
Gtk::IconSize icon_size;
|
||||
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
|
||||
|
||||
public:
|
||||
RTPixbuf();
|
||||
explicit RTPixbuf(const Glib::ustring &icon_name, const Gtk::IconSize iconSize);
|
||||
explicit RTPixbuf(const Glib::ustring &fname);
|
||||
|
||||
int getWidth();
|
||||
int getHeight();
|
||||
bool hasPixbuf();
|
||||
|
||||
Glib::RefPtr<Gdk::Pixbuf> get();
|
||||
};
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include "options.h"
|
||||
#include "thumbbrowserbase.h"
|
||||
#include "../rtengine/rt_math.h"
|
||||
#include "rtsurface.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -284,10 +285,10 @@ void ThumbBrowserEntryBase::updateBackBuffer ()
|
||||
int iheight = 0;
|
||||
|
||||
for (size_t i = 0; i < bbIcons.size(); i++) {
|
||||
iwidth += bbIcons[i]->get_width() + (i > 0 ? igap : 0);
|
||||
iwidth += bbIcons[i]->getWidth() + (i > 0 ? igap : 0);
|
||||
|
||||
if (bbIcons[i]->get_height() > iheight) {
|
||||
iheight = bbIcons[i]->get_height();
|
||||
if (bbIcons[i]->getHeight() > iheight) {
|
||||
iheight = bbIcons[i]->getHeight();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,10 +311,10 @@ void ThumbBrowserEntryBase::updateBackBuffer ()
|
||||
|
||||
for (size_t i = 0; i < bbIcons.size(); i++) {
|
||||
// Draw the image at 110, 90, except for the outermost 10 pixels.
|
||||
Gdk::Cairo::set_source_pixbuf(cc, bbIcons[i], istartx, istarty);
|
||||
cc->rectangle(istartx, istarty, bbIcons[i]->get_width(), bbIcons[i]->get_height());
|
||||
cc->set_source(bbIcons[i]->get(), istartx, istarty);
|
||||
cc->rectangle(istartx, istarty, bbIcons[i]->getWidth(), bbIcons[i]->getHeight());
|
||||
cc->fill();
|
||||
istartx += bbIcons[i]->get_width() + igap;
|
||||
istartx += bbIcons[i]->getWidth() + igap;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,9 +324,9 @@ void ThumbBrowserEntryBase::updateBackBuffer ()
|
||||
int istarty2 = prey + preh - igap - 1;
|
||||
|
||||
for (size_t i = 0; i < bbSpecificityIcons.size(); ++i) {
|
||||
istartx2 -= bbSpecificityIcons[i]->get_width() - igap;
|
||||
Gdk::Cairo::set_source_pixbuf(cc, bbSpecificityIcons[i], istartx2, istarty2 - bbSpecificityIcons[i]->get_height());
|
||||
cc->rectangle(istartx2, istarty2 - bbSpecificityIcons[i]->get_height(), bbSpecificityIcons[i]->get_width(), bbSpecificityIcons[i]->get_height());
|
||||
istartx2 -= bbSpecificityIcons[i]->getWidth() - igap;
|
||||
cc->set_source(bbSpecificityIcons[i]->get(), istartx2, istarty2 - bbSpecificityIcons[i]->getHeight());
|
||||
cc->rectangle(istartx2, istarty2 - bbSpecificityIcons[i]->getHeight(), bbSpecificityIcons[i]->getWidth(), bbSpecificityIcons[i]->getHeight());
|
||||
cc->fill();
|
||||
}
|
||||
}
|
||||
@@ -694,14 +695,14 @@ bool ThumbBrowserEntryBase::insideWindow (int x, int y, int w, int h) const
|
||||
return !(ofsX + startx > x + w || ofsX + startx + exp_width < x || ofsY + starty > y + h || ofsY + starty + exp_height < y);
|
||||
}
|
||||
|
||||
std::vector<Glib::RefPtr<Gdk::Pixbuf>> ThumbBrowserEntryBase::getIconsOnImageArea()
|
||||
std::vector<std::shared_ptr<RTSurface>> ThumbBrowserEntryBase::getIconsOnImageArea()
|
||||
{
|
||||
return std::vector<Glib::RefPtr<Gdk::Pixbuf> >();
|
||||
return std::vector<std::shared_ptr<RTSurface>>();
|
||||
}
|
||||
|
||||
std::vector<Glib::RefPtr<Gdk::Pixbuf> > ThumbBrowserEntryBase::getSpecificityIconsOnImageArea()
|
||||
std::vector<std::shared_ptr<RTSurface>> ThumbBrowserEntryBase::getSpecificityIconsOnImageArea()
|
||||
{
|
||||
return std::vector<Glib::RefPtr<Gdk::Pixbuf> >();
|
||||
return std::vector<std::shared_ptr<RTSurface>>();
|
||||
}
|
||||
|
||||
bool ThumbBrowserEntryBase::motionNotify (int x, int y)
|
||||
|
@@ -31,6 +31,7 @@
|
||||
|
||||
class Thumbnail;
|
||||
class ThumbBrowserBase;
|
||||
class RTSurface;
|
||||
class ThumbBrowserEntryBase
|
||||
{
|
||||
|
||||
@@ -83,8 +84,8 @@ protected:
|
||||
Glib::RefPtr<BackBuffer> backBuffer;
|
||||
bool bbSelected, bbFramed;
|
||||
guint8* bbPreview;
|
||||
std::vector<Glib::RefPtr<Gdk::Pixbuf>> bbIcons;
|
||||
std::vector<Glib::RefPtr<Gdk::Pixbuf>> bbSpecificityIcons;
|
||||
std::vector<std::shared_ptr<RTSurface>> bbIcons;
|
||||
std::vector<std::shared_ptr<RTSurface>> bbSpecificityIcons;
|
||||
CursorShape cursor_type;
|
||||
|
||||
void drawFrame (Cairo::RefPtr<Cairo::Context> cr, const Gdk::RGBA& bg, const Gdk::RGBA& fg);
|
||||
@@ -185,8 +186,8 @@ public:
|
||||
|
||||
virtual void drawProgressBar (Glib::RefPtr<Gdk::Window> win, const Gdk::RGBA& foregr, const Gdk::RGBA& backgr, int x, int w, int y, int h) {}
|
||||
|
||||
virtual std::vector<Glib::RefPtr<Gdk::Pixbuf>> getIconsOnImageArea ();
|
||||
virtual std::vector<Glib::RefPtr<Gdk::Pixbuf>> getSpecificityIconsOnImageArea ();
|
||||
virtual std::vector<std::shared_ptr<RTSurface>> getIconsOnImageArea ();
|
||||
virtual std::vector<std::shared_ptr<RTSurface>> getSpecificityIconsOnImageArea ();
|
||||
virtual void getIconSize (int& w, int& h) const = 0;
|
||||
|
||||
virtual bool motionNotify (int x, int y);
|
||||
|
Reference in New Issue
Block a user