Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef SWATCHVIEWER_H
Toshihiro Shimizu 890ddd
#define SWATCHVIEWER_H
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
#pragma warning(disable : 4251)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
#include <qwidget></qwidget>
Toshihiro Shimizu 890ddd
#include "tfx.h"
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
#include "trenderer.h"
Toshihiro Shimizu 890ddd
#include "tthreadmessage.h"
Toshihiro Shimizu 890ddd
#include "tthread.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace TThread;
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
Shinya Kitaoka 120a6e
class DVAPI BgPainter {
Shinya Kitaoka 120a6e
  std::string m_name;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  BgPainter(std::string name) : m_name(name) {}
Shinya Kitaoka 120a6e
  virtual ~BgPainter() {}
Shinya Kitaoka 120a6e
  std::string getName() const { return m_name; }
Shinya Kitaoka 120a6e
  virtual void paint(const TRaster32P &ras) = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI SolidColorBgPainter : public BgPainter {
Shinya Kitaoka 120a6e
  TPixel32 m_color;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  SolidColorBgPainter(std::string name, TPixel32 color)
Shinya Kitaoka 120a6e
      : BgPainter(name), m_color(color) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void paint(const TRaster32P &ras) override { ras->fill(m_color); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI CheckboardBgPainter : public BgPainter {
Shinya Kitaoka 120a6e
  TPixel32 m_c0, m_c1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  CheckboardBgPainter(std::string name, TPixel32 c0, TPixel32 c1)
Shinya Kitaoka 120a6e
      : BgPainter(name), m_c0(c0), m_c1(c1) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void paint(const TRaster32P &ras) override {
Shinya Kitaoka 120a6e
    int n = 4, min = 4;
Shinya Kitaoka 120a6e
    TDimensionD d(std::max(min, ras->getLx() / n),
Shinya Kitaoka 120a6e
                  std::max(min, ras->getLy() / n));
Shinya Kitaoka 120a6e
    d.lx = d.ly = std::max(d.lx, d.ly);
Shinya Kitaoka 120a6e
    TRop::checkBoard(ras, m_c0, m_c1, d, TPointD());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \brief SwatchViewer.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
                Inherits \b QWidget.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
class DVAPI SwatchViewer : public QWidget {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! La classe \b Point gestisce un punto che e' collegato a parametri \b
Shinya Kitaoka 120a6e
  //! TPointParam.
Shinya Kitaoka 120a6e
  /*!Questo tipo di punti consentono di modificare alcuni parametri dell'effetto
Shinya Kitaoka 120a6e
  corrente e
Shinya Kitaoka 120a6e
  sono editabili dall'utente direttamente nello SwatchViewer*/
Shinya Kitaoka 120a6e
  class Point {
Shinya Kitaoka 120a6e
  public:
Shinya Kitaoka 120a6e
    int m_index;
Shinya Kitaoka 120a6e
    TPointParamP m_param;
Shinya Kitaoka 120a6e
    bool m_pairFlag;
Shinya Kitaoka 120a6e
    Point(int index, const TPointParamP ¶m)
Shinya Kitaoka 120a6e
        : m_index(index), m_param(param), m_pairFlag(false) {}
Shinya Kitaoka 120a6e
  };
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFxP m_fx;
Shinya Kitaoka 120a6e
  TFxP m_actualFxClone;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRaster32P m_raster;
Shinya Kitaoka 120a6e
  TRaster32P m_content;
Shinya Kitaoka 120a6e
  TAffine m_aff;
Shinya Kitaoka 120a6e
  TAffine m_fxAff;
Shinya Kitaoka 120a6e
  TAffine m_contentAff;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_cameraMode;
Shinya Kitaoka 120a6e
  TRect m_cameraRect;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Qt::MouseButton m_mouseButton;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::vector<point> m_points;</point>
Shinya Kitaoka 120a6e
  std::vector<std::pair<int, int="">> m_pointPairs;</std::pair<int,>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int m_selectedPoint;
Shinya Kitaoka 120a6e
  TPointD m_pointPosDelta;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_enabled;
Shinya Kitaoka 120a6e
  int m_frame;
Shinya Kitaoka 120a6e
  TThread::Executor m_executor;
Shinya Kitaoka 120a6e
  TThread::Mutex m_mutex;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRenderer m_renderer;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  BgPainter *m_bgPainter;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRaster32P m_crossIcon;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPoint m_pos;
Shinya Kitaoka 120a6e
  TPoint m_firstPos;
Shinya Kitaoka 120a6e
  TRaster32P m_oldContent, m_curContent;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_computing;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  friend class ContentRender;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  class ContentRender : public TThread::Runnable {
Shinya Kitaoka 120a6e
  public:
Shinya Kitaoka 120a6e
    TRasterFxP m_fx;
Shinya Kitaoka 120a6e
    TRasterP m_raster;
Shinya Kitaoka 120a6e
    int m_frame;
Shinya Kitaoka 120a6e
    TDimension m_size;
Shinya Kitaoka 120a6e
    TAffine m_aff;
Shinya Kitaoka 120a6e
    SwatchViewer *m_viewer;
Shinya Kitaoka 120a6e
    bool m_started;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    ContentRender(TRasterFx *fx, int frame, const TDimension &size,
Shinya Kitaoka 120a6e
                  SwatchViewer *viewer);
Shinya Kitaoka 120a6e
    ~ContentRender();
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
    void run() override;
Shinya Kitaoka 473e70
    int taskLoad() override;
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
    void onStarted(TThread::RunnableP task) override;
Shinya Kitaoka 473e70
    void onFinished(TThread::RunnableP task) override;
Shinya Kitaoka 473e70
    void onCanceled(TThread::RunnableP task) override;
Shinya Kitaoka 120a6e
  };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050500
Shinya Kitaoka 120a6e
  SwatchViewer(QWidget *parent = 0, Qt::WindowFlags flags = 0);
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  SwatchViewer(QWidget *parent = 0, Qt::WFlags flags = 0);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  ~SwatchViewer();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  static void suspendRendering(bool suspend, bool blocking = true);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setCameraMode(bool enabled) { m_cameraMode = enabled; }
Shinya Kitaoka 120a6e
  bool getCameraMode() const { return m_cameraMode; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setCameraSize(const TDimension &cameraSize);
Shinya Kitaoka 120a6e
  TDimension getCameraSize() const { return m_cameraRect.getSize(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setFx(const TFxP &fx, const TFxP &actualFx, int frame);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void updateFrame(int frame);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isEnabled() { return m_enabled; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public slots:
Shinya Kitaoka 120a6e
  void setEnable(bool enabled);
Shinya Kitaoka 120a6e
  void updateSize(const QSize &size);
Shinya Kitaoka 120a6e
  void setBgPainter(TPixel32 color1, TPixel32 color2 = TPixel32());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  void computeContent();
Shinya Kitaoka 120a6e
  TPoint world2win(const TPointD &p) const;
Shinya Kitaoka 120a6e
  TPointD win2world(const TPoint &p) const;
Shinya Kitaoka 120a6e
  void zoom(const TPoint &pos, double factor);
Shinya Kitaoka 120a6e
  void zoom(bool forward, bool reset);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void updateRaster();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const TRaster32P &getContent() const { return m_content; }
Shinya Kitaoka 120a6e
  void setContent(const TRaster32P &content, const TAffine &contentAff);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setAff(const TAffine &aff);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void paintEvent(QPaintEvent *event) override;
Shinya Kitaoka 473e70
  void mousePressEvent(QMouseEvent *event) override;
Shinya Kitaoka 473e70
  void mouseMoveEvent(QMouseEvent *event) override;
Shinya Kitaoka 473e70
  void mouseReleaseEvent(QMouseEvent *event) override;
Shinya Kitaoka 473e70
  void wheelEvent(QWheelEvent *) override;
Shinya Kitaoka 473e70
  void keyPressEvent(QKeyEvent *event) override;
Shinya Kitaoka 473e70
  void resizeEvent(QResizeEvent *event) override;
Shinya Kitaoka 473e70
  void hideEvent(QHideEvent *event) override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
signals:
Shinya Kitaoka 120a6e
  void pointPositionChanged(int index, const TPointD &p);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // SWATCHVIEWER_H