Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef ICON_GENERATOR_H
Toshihiro Shimizu 890ddd
#define ICON_GENERATOR_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tthread.h"
Toshihiro Shimizu 890ddd
#include "tgeometry.h"
Toshihiro Shimizu 890ddd
#include "tfilepath.h"
Toshihiro Shimizu 890ddd
#include "traster.h"
Toshihiro Shimizu 890ddd
#include "timage.h"
Toshihiro Shimizu 890ddd
#include "tpixel.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qpixmap></qpixmap>
Toshihiro Shimizu 890ddd
#include <qthreadstorage></qthreadstorage>
Toshihiro Shimizu 890ddd
#include <qeventloop></qeventloop>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// STD includes
Toshihiro Shimizu 890ddd
#include <map></map>
Toshihiro Shimizu 890ddd
#include <vector></vector>
Toshihiro Shimizu 890ddd
#include <set></set>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TOONZQT_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//    Forward declarations
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TFilePath;
Toshihiro Shimizu 890ddd
class TXshLevel;
Toshihiro Shimizu 890ddd
class TStageObjectSpline;
Toshihiro Shimizu 890ddd
class ToonzScene;
Toshihiro Shimizu 890ddd
class TOfflineGL;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
//    IconGenerator  definition
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  \brief    The class responsible for icons management in Toonz.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \details  It's a singleton class - in particular, rendered icons are stored in
Toshihiro Shimizu 890ddd
            a shared map container for fast retrieval upon repeated icon requests.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
            IconGenerator provides methods to submit icon requests, and to invalidate or
Toshihiro Shimizu 890ddd
            remove icons from the internal database. In order to keep outer entities
Toshihiro Shimizu 890ddd
            informed of the icon generation status, an iconGenerated() signal is emitted
Toshihiro Shimizu 890ddd
            once an icon has been generated.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI IconGenerator : public QObject
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	Q_OBJECT
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	class Settings
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	public:
Toshihiro Shimizu 890ddd
		bool m_blackBgCheck;
Toshihiro Shimizu 890ddd
		bool m_transparencyCheck;
Toshihiro Shimizu 890ddd
		bool m_inksOnly;
Toshihiro Shimizu 890ddd
		int m_inkIndex;
Toshihiro Shimizu 890ddd
		int m_paintIndex;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		Settings()
Toshihiro Shimizu 890ddd
			: m_transparencyCheck(false), m_blackBgCheck(false), m_inksOnly(false), m_inkIndex(-1), m_paintIndex(-1)
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	IconGenerator();
Toshihiro Shimizu 890ddd
	~IconGenerator();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	static IconGenerator *instance();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setSettings(const Settings &settings) { m_settings = settings; }
Toshihiro Shimizu 890ddd
	const Settings getSettings() const { return m_settings; }
Toshihiro Shimizu 890ddd
	static void setFilmstripIconSize(const TDimension &dim);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDimension getIconSize() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TOfflineGL *getOfflineGLContext();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// icons from splines
Toshihiro Shimizu 890ddd
	QPixmap getIcon(TStageObjectSpline *spline);
Toshihiro Shimizu 890ddd
	void invalidate(TStageObjectSpline *spline);
Toshihiro Shimizu 890ddd
	void remove(TStageObjectSpline *spline);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// icons from toonz levels
Toshihiro Shimizu 890ddd
	QPixmap getIcon(TXshLevel *sl, const TFrameId &fid, bool filmStrip = true, bool onDemand = false);
Toshihiro Shimizu 890ddd
	void invalidate(TXshLevel *sl, const TFrameId &fid, bool onlyFilmStrip = false);
Toshihiro Shimizu 890ddd
	void remove(TXshLevel *sl, const TFrameId &fid, bool onlyFilmStrip = false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// icons from files
Toshihiro Shimizu 890ddd
	QPixmap getIcon(const TFilePath &path, const TFrameId &fid = TFrameId::NO_FRAME);
Toshihiro Shimizu 890ddd
	void invalidate(const TFilePath &path, const TFrameId &fid = TFrameId::NO_FRAME);
Toshihiro Shimizu 890ddd
	void remove(const TFilePath &path, const TFrameId &fid = TFrameId::NO_FRAME);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QPixmap getSceneIcon(ToonzScene *scene); //Unused in Toonz
Toshihiro Shimizu 890ddd
	void invalidateSceneIcon();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void remap(const string &newIconId, const string &oldIconId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void clearRequests();
Toshihiro Shimizu 890ddd
	void clearSceneIcons();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	static TRaster32P generateVectorFileIcon(const TFilePath &path, const TDimension &iconSize, const TFrameId &fid);
Toshihiro Shimizu 890ddd
	static TRaster32P generateRasterFileIcon(const TFilePath &path, const TDimension &iconSize, const TFrameId &fid);
Toshihiro Shimizu 890ddd
	static TRaster32P generateSceneFileIcon(const TFilePath &path, const TDimension &iconSize, int row);
Toshihiro Shimizu 890ddd
	static TRaster32P generateSplineFileIcon(const TFilePath &path, const TDimension &iconSize);
Toshihiro Shimizu 890ddd
	static TRaster32P generateMeshFileIcon(const TFilePath &path, const TDimension &iconSize, const TFrameId &fid);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
signals:
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void iconGenerated();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public slots:
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onStarted(TThread::RunnableP iconRenderer);
Toshihiro Shimizu 890ddd
	void onCanceled(TThread::RunnableP iconRenderer);
Toshihiro Shimizu 890ddd
	void onFinished(TThread::RunnableP iconRenderer);
Toshihiro Shimizu 890ddd
	void onException(TThread::RunnableP iconRenderer);
Toshihiro Shimizu 890ddd
	void onTerminated(TThread::RunnableP iconRenderer);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	TThread::Executor m_executor;
Toshihiro Shimizu 890ddd
	QThreadStorage<tofflinegl *=""> m_contexts;</tofflinegl>
Toshihiro Shimizu 890ddd
	TDimension m_iconSize;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QEventLoop m_iconsTerminationLoop; //!< Event loop used to wait for icons termination.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Settings m_settings;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	void addTask(const std::string &id, TThread::RunnableP iconRenderer);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
//    Related non-member functions
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class it=""></class>
Toshihiro Shimizu 890ddd
inline void invalidateIcons(TXshLevel *sl, It fBegin, It fEnd, bool onlyFilmStrip = false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (It ft = fBegin; ft != fEnd; ++ft)
Toshihiro Shimizu 890ddd
		IconGenerator::instance()->invalidate(sl, *ft, onlyFilmStrip);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class c=""></class>
Toshihiro Shimizu 890ddd
inline void invalidateIcons(TXshLevel *sl, const C &fids, bool onlyFilmStrip = false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	invalidateIcons(sl, fids.begin(), fids.end(), onlyFilmStrip);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename it=""></typename>
Toshihiro Shimizu 890ddd
inline void removeIcons(TXshLevel *sl, It fBegin, It fEnd, bool onlyFilmStrip = false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (It ft = fBegin; ft != fEnd; ++ft)
Toshihiro Shimizu 890ddd
		IconGenerator::instance()->remove(sl, *ft, onlyFilmStrip);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename c=""></typename>
Toshihiro Shimizu 890ddd
inline void removeIcons(TXshLevel *sl, const C &fids, bool onlyFilmStrip = false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	removeIcons(sl, fids.begin(), fids.end(), onlyFilmStrip);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif // ICON_GENERATOR_H