Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef _RASTERSTYLES_H_
Toshihiro Shimizu 890ddd
#define _RASTERSTYLES_H_
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tcolorstyles.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "traster.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qcoreapplication></qcoreapplication>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TStroke;
Toshihiro Shimizu 890ddd
class TRegion;
Toshihiro Shimizu 890ddd
class TStrokeProp;
Toshihiro Shimizu 890ddd
class TRegionProp;
Toshihiro Shimizu 890ddd
class TInputStreamInterface;
Toshihiro Shimizu 890ddd
class TOutputStreamInterface;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TAirbrushRasterStyle : public TColorStyle, public TRasterStyleFx {
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  TPixel32 m_color;
Shinya Kitaoka 120a6e
  double m_blur;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TAirbrushRasterStyle(const TPixel32 &color, double blur)
Shinya Kitaoka 120a6e
      : m_color(color), m_blur(blur) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TColorStyle *clone() const override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  // n.b. per un plain color: isRasterStyle() == true, ma getRasterStyleFx() = 0
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  TStrokeProp *makeStrokeProp(const TStroke *stroke) override { return 0; }
Shinya Kitaoka 473e70
  TRegionProp *makeRegionProp(const TRegion *region) override { return 0; }
Shinya Kitaoka 473e70
  TRasterStyleFx *getRasterStyleFx() override { return this; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  bool isRegionStyle() const override { return false; }
Shinya Kitaoka 473e70
  bool isStrokeStyle() const override { return false; }
Shinya Kitaoka 473e70
  bool isRasterStyle() const override { return true; }
Shinya Kitaoka 473e70
  void getEnlargement(int &borderIn, int &borderOut) const override {
Shinya Kitaoka 120a6e
    borderIn  = tceil(2 * m_blur);
Shinya Kitaoka 120a6e
    borderOut = tceil(m_blur);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  bool hasMainColor() const override { return true; }
Shinya Kitaoka 473e70
  TPixel32 getMainColor() const override { return m_color; }
Shinya Kitaoka 473e70
  void setMainColor(const TPixel32 &color) override { m_color = color; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  int getColorParamCount() const override { return 1; }
Shinya Kitaoka 473e70
  TPixel32 getColorParamValue(int index) const override { return m_color; }
Shinya Kitaoka 38fd86
  void setColorParamValue(int index, const TPixel32 &color) override {
Shinya Kitaoka 38fd86
    m_color = color;
Shinya Kitaoka 38fd86
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  QString getDescription() const override {
Shinya Kitaoka 120a6e
    return QCoreApplication::translate("TAirbrushRasterStyle", "Airbrush");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  int getParamCount() const override { return 1; }
Shinya Kitaoka 473e70
  TColorStyle::ParamType getParamType(int index) const override {
Shinya Kitaoka 120a6e
    assert(index == 0);
Shinya Kitaoka 120a6e
    return TColorStyle::DOUBLE;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  QString getParamNames(int index) const override {
Shinya Kitaoka 120a6e
    assert(index == 0);
Shinya Kitaoka 120a6e
    return QCoreApplication::translate("TAirbrushRasterStyle", "Blur value");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  void getParamRange(int index, double &min, double &max) const override {
Shinya Kitaoka 120a6e
    assert(index == 0);
Shinya Kitaoka 120a6e
    min = 0;
Shinya Kitaoka 120a6e
    max = 30;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  double getParamValue(TColorStyle::double_tag, int index) const override {
Shinya Kitaoka 120a6e
    assert(index == 0);
Shinya Kitaoka 120a6e
    return m_blur;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  void setParamValue(int index, double value) override {
Shinya Kitaoka 120a6e
    assert(index == 0);
Shinya Kitaoka 120a6e
    m_blur = value;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void invalidateIcon();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // const TRaster32P &getIcon(const TDimension &d) {assert(false);return
Shinya Kitaoka 120a6e
  // (TRaster32P)0;}
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  TPixel32 getAverageColor() const override { return m_color; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  int getTagId() const override { return 1150; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  bool isInkStyle() const override { return true; }
Shinya Kitaoka 473e70
  bool isPaintStyle() const override { return false; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  bool compute(const Params ¶ms) const override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 473e70
  void makeIcon(const TDimension &d) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void arrangeIcon(const TDimension &d, const TRasterP &normalIc);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void loadData(TInputStreamInterface &) override;
Shinya Kitaoka 473e70
  void saveData(TOutputStreamInterface &) const override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // per la compatibilita' con il passato
Shinya Kitaoka 38fd86
  void loadData(int oldId, TInputStreamInterface &) override{};
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TBlendRasterStyle final : public TAirbrushRasterStyle {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TBlendRasterStyle(const TPixel32 &color, double blur)
Shinya Kitaoka 120a6e
      : TAirbrushRasterStyle(color, blur) {}
Shinya Kitaoka 473e70
  TColorStyle *clone() const override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  int getTagId() const override { return 1160; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  QString getDescription() const override {
Shinya Kitaoka 120a6e
    return QCoreApplication::translate("TBlendRasterStyle", "Blend");
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void makeIcon(const TDimension &d) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  bool compute(const TRasterStyleFx::Params ¶ms) const override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  double computeFactor(const TRasterStyleFx::Params ¶ms) const;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TNoColorRasterStyle final : public TColorStyle, TRasterStyleFx {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TNoColorRasterStyle() {}
Shinya Kitaoka 473e70
  TColorStyle *clone() const override { return new TNoColorRasterStyle(*this); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // n.b. per un plain color: isRasterStyle() == true, ma getRasterStyleFx() = 0
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TStrokeProp *makeStrokeProp(const TStroke *stroke) override { return 0; }
Shinya Kitaoka 473e70
  TRegionProp *makeRegionProp(const TRegion *region) override { return 0; }
Shinya Kitaoka 473e70
  TRasterStyleFx *getRasterStyleFx() override { return this; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  bool isRegionStyle() const override { return false; }
Shinya Kitaoka 473e70
  bool isStrokeStyle() const override { return false; }
Shinya Kitaoka 473e70
  bool isRasterStyle() const override { return true; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  QString getDescription() const override {
Shinya Kitaoka 120a6e
    return QCoreApplication::translate("TNoColorRasterStyle", "Markup");
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool hasMainColor() { return false; }
Shinya Kitaoka 120a6e
  // TPixel32 getMainColor() const {return m_color;}
Shinya Kitaoka 120a6e
  // void setMainColor(const TPixel32 &color) {m_color = color;}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  int getColorParamCount() const override { return 0; }
Shinya Kitaoka 473e70
  TPixel32 getColorParamValue(int index) const override {
Shinya Kitaoka 120a6e
    assert(false);
Shinya Kitaoka 120a6e
    return TPixel32();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 38fd86
  void setColorParamValue(int index, const TPixel32 &color) override {
Shinya Kitaoka 38fd86
    assert(false);
Shinya Kitaoka 38fd86
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  int getTagId() const override { return 1151; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  bool isInkStyle() const override { return true; }
Shinya Kitaoka 473e70
  bool isPaintStyle() const override { return true; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  bool compute(const Params ¶ms) const override { return false; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 473e70
  void makeIcon(const TDimension &d) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 38fd86
  void loadData(TInputStreamInterface &) override{};
Shinya Kitaoka 38fd86
  void saveData(TOutputStreamInterface &) const override{};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // per la compatibilita' con il passato
Shinya Kitaoka 38fd86
  void loadData(int oldId, TInputStreamInterface &) override{};
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif