Shinya Kitaoka 810553
#pragma once
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
Shinya Kitaoka 120a6e
            a shared map container for fast retrieval upon repeated icon
Shinya Kitaoka 120a6e
  requests.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
            IconGenerator provides methods to submit icon requests, and to
Shinya Kitaoka 120a6e
  invalidate or
Shinya Kitaoka 120a6e
            remove icons from the internal database. In order to keep outer
Shinya Kitaoka 120a6e
  entities
Shinya Kitaoka 120a6e
            informed of the icon generation status, an iconGenerated() signal is
Shinya Kitaoka 120a6e
  emitted
Toshihiro Shimizu 890ddd
            once an icon has been generated.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI IconGenerator final : public QObject {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  class Settings {
Shinya Kitaoka 120a6e
  public:
Shinya Kitaoka 120a6e
    bool m_blackBgCheck;
Shinya Kitaoka 120a6e
    bool m_transparencyCheck;
Shinya Kitaoka 120a6e
    bool m_inksOnly;
Shinya Kitaoka 120a6e
    int m_inkIndex;
Shinya Kitaoka 120a6e
    int m_paintIndex;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    Settings()
Shinya Kitaoka 120a6e
        : m_transparencyCheck(false)
Shinya Kitaoka 120a6e
        , m_blackBgCheck(false)
Shinya Kitaoka 120a6e
        , m_inksOnly(false)
Shinya Kitaoka 120a6e
        , m_inkIndex(-1)
Shinya Kitaoka 120a6e
        , m_paintIndex(-1) {}
Shinya Kitaoka 120a6e
  };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  IconGenerator();
Shinya Kitaoka 120a6e
  ~IconGenerator();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  static IconGenerator *instance();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setSettings(const Settings &settings) { m_settings = settings; }
Shinya Kitaoka 120a6e
  const Settings getSettings() const { return m_settings; }
Shinya Kitaoka 120a6e
  static void setFilmstripIconSize(const TDimension &dim);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDimension getIconSize() const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TOfflineGL *getOfflineGLContext();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // icons from splines
Shinya Kitaoka 120a6e
  QPixmap getIcon(TStageObjectSpline *spline);
Shinya Kitaoka 120a6e
  void invalidate(TStageObjectSpline *spline);
Shinya Kitaoka 120a6e
  void remove(TStageObjectSpline *spline);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // icons from toonz levels
Shinya Kitaoka 120a6e
  QPixmap getIcon(TXshLevel *sl, const TFrameId &fid, bool filmStrip = true,
Shinya Kitaoka 120a6e
                  bool onDemand = false);
Jeremy Bullock 61fa79
  QPixmap getSizedIcon(TXshLevel *sl, const TFrameId &fid, std::string newId,
Jeremy Bullock 61fa79
                       TDimension dim = TDimension(0, 0));
Shinya Kitaoka 120a6e
  void invalidate(TXshLevel *sl, const TFrameId &fid,
Shinya Kitaoka 120a6e
                  bool onlyFilmStrip = false);
Shinya Kitaoka 120a6e
  void remove(TXshLevel *sl, const TFrameId &fid, bool onlyFilmStrip = false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // icons from files
Shinya Kitaoka 120a6e
  QPixmap getIcon(const TFilePath &path,
Shinya Kitaoka 120a6e
                  const TFrameId &fid = TFrameId::NO_FRAME);
Shinya Kitaoka 120a6e
  void invalidate(const TFilePath &path,
Shinya Kitaoka 120a6e
                  const TFrameId &fid = TFrameId::NO_FRAME);
Shinya Kitaoka 120a6e
  void remove(const TFilePath &path, const TFrameId &fid = TFrameId::NO_FRAME);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QPixmap getSceneIcon(ToonzScene *scene);  // Unused in Toonz
Shinya Kitaoka 120a6e
  void invalidateSceneIcon();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void remap(const std::string &newIconId, const std::string &oldIconId);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void clearRequests();
Shinya Kitaoka 120a6e
  void clearSceneIcons();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  static TRaster32P generateVectorFileIcon(const TFilePath &path,
Shinya Kitaoka 120a6e
                                           const TDimension &iconSize,
Shinya Kitaoka 120a6e
                                           const TFrameId &fid);
Shinya Kitaoka 120a6e
  static TRaster32P generateRasterFileIcon(const TFilePath &path,
Shinya Kitaoka 120a6e
                                           const TDimension &iconSize,
Shinya Kitaoka 120a6e
                                           const TFrameId &fid);
Shinya Kitaoka 120a6e
  static TRaster32P generateSceneFileIcon(const TFilePath &path,
Shinya Kitaoka 120a6e
                                          const TDimension &iconSize, int row);
Shinya Kitaoka 120a6e
  static TRaster32P generateSplineFileIcon(const TFilePath &path,
Shinya Kitaoka 120a6e
                                           const TDimension &iconSize);
Shinya Kitaoka 120a6e
  static TRaster32P generateMeshFileIcon(const TFilePath &path,
Shinya Kitaoka 120a6e
                                         const TDimension &iconSize,
Shinya Kitaoka 120a6e
                                         const TFrameId &fid);
Toshihiro Shimizu 890ddd
shun-iwasawa 18198a
  // This function is called when only colors of styles are changed in toonz
shun-iwasawa 18198a
  // raster levels. In such case it doesn't need to re-compute icons but needs
shun-iwasawa 18198a
  // to let panels to update. See TApp::onLevelColorStyleChanged() for details.
shun-iwasawa 18198a
  void notifyIconGenerated() { emit iconGenerated(); }
Toshihiro Shimizu 890ddd
signals:
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void iconGenerated();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public slots:
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void onStarted(TThread::RunnableP iconRenderer);
Shinya Kitaoka 120a6e
  void onCanceled(TThread::RunnableP iconRenderer);
Shinya Kitaoka 120a6e
  void onFinished(TThread::RunnableP iconRenderer);
Shinya Kitaoka 120a6e
  void onException(TThread::RunnableP iconRenderer);
Shinya Kitaoka 120a6e
  void onTerminated(TThread::RunnableP iconRenderer);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  TThread::Executor m_executor;
Shinya Kitaoka 120a6e
  QThreadStorage<tofflinegl *=""> m_contexts;</tofflinegl>
Shinya Kitaoka 120a6e
  TDimension m_iconSize;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QEventLoop m_iconsTerminationLoop;  //!< Event loop used to wait for icons
Shinya Kitaoka 38fd86
                                      //! termination.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Settings m_settings;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  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>
Shinya Kitaoka 120a6e
inline void invalidateIcons(TXshLevel *sl, It fBegin, It fEnd,
Shinya Kitaoka 120a6e
                            bool onlyFilmStrip = false) {
Shinya Kitaoka 120a6e
  for (It ft = fBegin; ft != fEnd; ++ft)
Shinya Kitaoka 120a6e
    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>
Shinya Kitaoka 120a6e
inline void invalidateIcons(TXshLevel *sl, const C &fids,
Shinya Kitaoka 120a6e
                            bool onlyFilmStrip = false) {
Shinya Kitaoka 120a6e
  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>
Shinya Kitaoka 120a6e
inline void removeIcons(TXshLevel *sl, It fBegin, It fEnd,
Shinya Kitaoka 120a6e
                        bool onlyFilmStrip = false) {
Shinya Kitaoka 120a6e
  for (It ft = fBegin; ft != fEnd; ++ft)
Shinya Kitaoka 120a6e
    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>
Shinya Kitaoka 120a6e
inline void removeIcons(TXshLevel *sl, const C &fids,
Shinya Kitaoka 120a6e
                        bool onlyFilmStrip = false) {
Shinya Kitaoka 120a6e
  removeIcons(sl, fids.begin(), fids.end(), onlyFilmStrip);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // ICON_GENERATOR_H