Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tcolorfunctions.h"
Toshihiro Shimizu 890ddd
#include "trandom.h"
Toshihiro Shimizu 890ddd
#include "tcurves.h"
Toshihiro Shimizu 890ddd
#include "tvectorrenderdata.h"
Toshihiro Shimizu 890ddd
#include "tmathutil.h"
Toshihiro Shimizu 890ddd
#include "colorfxutils.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Jeremy Bullock 175c6b
#include "tconvert.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// tcg includes
Toshihiro Shimizu 890ddd
#include "tcg/tcg_misc.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qcoreapplication></qcoreapplication>
Toshihiro Shimizu 890ddd
#include <qstringlist></qstringlist>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "strokestyles.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace std;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define MINTHICK 1.0
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka d1f6c4
class TOptimizedStrokePropT final : public TStrokeProp {
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  double m_pixelSize;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TOptimizedStrokeStyleT<t> *m_colorStyle;</t>
Shinya Kitaoka 120a6e
  T m_data;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TOptimizedStrokePropT(const TStroke *stroke,
Shinya Kitaoka 120a6e
                        TOptimizedStrokeStyleT<t> *style);</t>
Shinya Kitaoka 120a6e
  ~TOptimizedStrokePropT() { m_colorStyle->release(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  const TColorStyle *getColorStyle() const override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TStrokeProp *clone(const TStroke *stroke) const override;
Shinya Kitaoka 473e70
  void draw(const TVectorRenderData &rd) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
TOptimizedStrokePropT<t>::TOptimizedStrokePropT(</t>
Shinya Kitaoka 120a6e
    const TStroke *stroke, TOptimizedStrokeStyleT<t> *style)</t>
Shinya Kitaoka 120a6e
    : TStrokeProp(stroke), m_colorStyle(style), m_pixelSize(0) {
Shinya Kitaoka 120a6e
  m_styleVersionNumber = style->getVersionNumber();
Shinya Kitaoka 120a6e
  m_colorStyle->addRef();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
const TColorStyle *TOptimizedStrokePropT<t>::getColorStyle() const {</t>
Shinya Kitaoka 120a6e
  return m_colorStyle;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
TStrokeProp *TOptimizedStrokePropT<t>::clone(const TStroke *stroke) const {</t>
Shinya Kitaoka 120a6e
  TOptimizedStrokePropT<t> *prop =</t>
Shinya Kitaoka 120a6e
      new TOptimizedStrokePropT<t>(stroke, m_colorStyle);</t>
Shinya Kitaoka 120a6e
  prop->m_strokeChanged = m_strokeChanged;
Shinya Kitaoka 120a6e
  prop->m_data          = m_data;
Shinya Kitaoka 120a6e
  return prop;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
void TOptimizedStrokePropT<t>::draw(</t>
Shinya Kitaoka 120a6e
    const TVectorRenderData
Shinya Kitaoka 120a6e
        &rd) /*assenza di const non e' una dimenticanza! Alcune sottoclassi
Shinya Kitaoka 120a6e
                devono ridefinire questo metodo e serbve che non sia const*/
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
  if (rd.m_clippingRect != TRect() && !rd.m_is3dView &&
Shinya Kitaoka 120a6e
      !convert(rd.m_aff * m_stroke->getBBox()).overlaps(rd.m_clippingRect))
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glPushMatrix();
Shinya Kitaoka 120a6e
  tglMultMatrix(rd.m_aff);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double pixelSize = sqrt(tglGetPixelSize2());
Shinya Kitaoka 120a6e
  if (m_strokeChanged ||
Shinya Kitaoka 120a6e
      m_styleVersionNumber != m_colorStyle->getVersionNumber() ||
Shinya Kitaoka 120a6e
      !isAlmostZero(pixelSize - m_pixelSize, 1e-5)) {
Shinya Kitaoka 120a6e
    m_strokeChanged      = false;
Shinya Kitaoka 120a6e
    m_pixelSize          = pixelSize;
Shinya Kitaoka 120a6e
    m_styleVersionNumber = m_colorStyle->getVersionNumber();
Shinya Kitaoka 120a6e
    m_colorStyle->computeData(m_data, m_stroke, rd.m_cf);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_colorStyle->drawStroke(rd.m_cf, m_data, m_stroke);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glPopMatrix();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
TStrokeProp *TOptimizedStrokeStyleT<t>::makeStrokeProp(const TStroke *stroke) {</t>
Shinya Kitaoka 120a6e
  return new TOptimizedStrokePropT<t>(stroke, this);</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline void tglNormal(const T3DPointD &p) { glNormal3d(p.x, p.y, p.z); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline void tglVertex(const T3DPointD &p) { glVertex3d(p.x, p.y, p.z); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFurStrokeStyle::TFurStrokeStyle()
Shinya Kitaoka 120a6e
    : m_color(TPixel32::Black)
Shinya Kitaoka 120a6e
    , m_angle(120.0)
Shinya Kitaoka 120a6e
    , m_length(1.0)
Shinya Kitaoka 120a6e
    , m_cs(0.0)
Shinya Kitaoka 120a6e
    , m_sn(0.0) {
Shinya Kitaoka 120a6e
  double rad = m_angle * M_PI_180;
Shinya Kitaoka 120a6e
  m_cs       = cos(rad);
Shinya Kitaoka 120a6e
  m_sn       = sin(rad);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TFurStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TFurStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TFurStrokeStyle::getParamCount() const { return 2; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle::ParamType TFurStrokeStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TFurStrokeStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return index == 0 ? QCoreApplication::translate("TFurStrokeStyle", "Angle")
Shinya Kitaoka 120a6e
                    : QCoreApplication::translate("TFurStrokeStyle", "Size");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFurStrokeStyle::getParamRange(int index, double &min, double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  if (index == 0) {
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 180.0;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TFurStrokeStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                      int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return index == 0 ? m_angle : m_length;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFurStrokeStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  if (index == 0) {
Shinya Kitaoka 120a6e
    m_angle    = value;
Shinya Kitaoka 120a6e
    double rad = m_angle * M_PI_180;
Shinya Kitaoka 120a6e
    m_cs       = cos(rad);
Shinya Kitaoka 120a6e
    m_sn       = sin(rad);
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    m_length = value;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  updateVersionNumber();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
void TFurStrokeStyle::computeData(Points &positions, const TStroke *stroke,
Shinya Kitaoka 120a6e
                                  const TColorFunction *cf) const {
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double s  = 0.0;
Shinya Kitaoka 120a6e
  double ds = 4;
Shinya Kitaoka 120a6e
  double vs = 1;
Shinya Kitaoka 120a6e
  TRandom rnd;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  positions.clear();
Shinya Kitaoka 120a6e
  positions.reserve(tceil(length / ds) + 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  while (s <= length) {
Shinya Kitaoka 120a6e
    double w        = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    TThickPoint pos = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
    TPointD u       = stroke->getSpeed(w);
Shinya Kitaoka 120a6e
    if (norm2(u) == 0.0) {
Shinya Kitaoka 120a6e
      s += 0.5;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    u         = normalize(u);
Shinya Kitaoka 120a6e
    TPointD v = rotate90(u);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    double length = 0;
Shinya Kitaoka 120a6e
    if (pos.thick)
Shinya Kitaoka 120a6e
      length = m_length * pos.thick;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      length = 1.0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    vs = -vs;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    positions.push_back(pos);
Shinya Kitaoka 120a6e
    double q = 0.01 * (rnd.getFloat() * 2 - 1);
Shinya Kitaoka 120a6e
    positions.push_back(pos + length * ((m_cs + q) * u + (vs * m_sn) * v));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    s += ds;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
void TFurStrokeStyle::drawStroke(const TColorFunction *cf, Points &positions,
Shinya Kitaoka 120a6e
                                 const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = m_color;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tglColor(color);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (UINT i = 0; i < positions.size(); i += 2) {
Shinya Kitaoka 120a6e
    glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
    tglColor(color);
Shinya Kitaoka 120a6e
    tglVertex(positions[i]);
Shinya Kitaoka 120a6e
    glColor4d(1, 1, 1, 0.0);
Shinya Kitaoka 120a6e
    tglVertex(positions[i + 1]);
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TChainStrokeStyle::TChainStrokeStyle(const TPixel32 &color) : m_color(color) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TChainStrokeStyle::TChainStrokeStyle() : m_color(TPixel32(20, 10, 0)) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TChainStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TChainStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TChainStrokeStyle::computeData(Points &data, const TStroke *stroke,
Shinya Kitaoka 120a6e
                                    const TColorFunction *cf) const {
Shinya Kitaoka 120a6e
  // TStroke *stroke = getStroke();
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // spessore della catena = spessore "medio" dello stroke
Shinya Kitaoka 120a6e
  double thickness =
Shinya Kitaoka 120a6e
      0.25 *
Shinya Kitaoka 120a6e
      (stroke->getThickPoint(0).thick + stroke->getThickPoint(1.0 / 3.0).thick +
Shinya Kitaoka 120a6e
       stroke->getThickPoint(2.0 / 3.0).thick + stroke->getThickPoint(1).thick);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (thickness == 0) thickness = 0.1;
Shinya Kitaoka 120a6e
  double ringHeight             = thickness;
Shinya Kitaoka 120a6e
  double ringWidth              = 1.5 * ringHeight;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // distanza fra i centri degli anelli
Shinya Kitaoka 120a6e
  double ringDistance = 2 * 1.2 * ringWidth;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // distanza fra il centro dell'anello e il punto di attacco dell'anello
Shinya Kitaoka 120a6e
  // trasversale
Shinya Kitaoka 120a6e
  // double joinPos = 0.45 * ringWidth;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPointD oldPos;
Shinya Kitaoka 120a6e
  // bool firstRing = true;
Shinya Kitaoka 120a6e
  double s = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  data.clear();
Shinya Kitaoka 120a6e
  data.reserve(tceil(length / ringDistance) * 2 + 2);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  while (s <= length) {
Shinya Kitaoka 120a6e
    double w = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    // if(w<0) {s+=0.1; continue;} // per tamponare il baco della
Shinya Kitaoka 120a6e
    // getParameterAtLength()
Shinya Kitaoka 120a6e
    TThickPoint pos = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
    TPointD u       = stroke->getSpeed(w);
Shinya Kitaoka 120a6e
    if (norm2(u) == 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // non dovrebbe succedere mai, ma per prudenza....
Shinya Kitaoka 120a6e
    u = normalize(u);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    data.push_back(pos);
Shinya Kitaoka 120a6e
    data.push_back(u);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // se e' il caso unisco la catena alla precedente
Shinya Kitaoka 120a6e
    s += ringDistance;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TChainStrokeStyle::drawStroke(const TColorFunction *cf, Points &data,
Shinya Kitaoka 120a6e
                                   const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  // TStroke *stroke = getStroke();
Shinya Kitaoka 120a6e
  // double length = stroke->getLength();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // spessore della catena = spessore "medio" dello stroke
Shinya Kitaoka 120a6e
  double thickness =
Shinya Kitaoka 120a6e
      0.25 *
Shinya Kitaoka 120a6e
      (stroke->getThickPoint(0).thick + stroke->getThickPoint(1.0 / 3.0).thick +
Shinya Kitaoka 120a6e
       stroke->getThickPoint(2.0 / 3.0).thick + stroke->getThickPoint(1).thick);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (thickness * thickness < 4 * tglGetPixelSize2()) {
Shinya Kitaoka 120a6e
    TCenterLineStrokeStyle *appStyle =
Shinya Kitaoka 120a6e
        new TCenterLineStrokeStyle(m_color, 0x0, thickness);
Shinya Kitaoka 120a6e
    appStyle->drawStroke(cf, stroke);
Shinya Kitaoka 120a6e
    delete appStyle;
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(thickness);
Shinya Kitaoka 120a6e
  double ringHeight = thickness;
Shinya Kitaoka 120a6e
  double ringWidth  = 1.5 * ringHeight;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // distanza fra i centri degli anelli
Shinya Kitaoka 120a6e
  // double ringDistance = 2 * 1.2 * ringWidth;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // distanza fra il centro dell'anello e il punto di attacco dell'anello
Shinya Kitaoka 120a6e
  // trasversale
Shinya Kitaoka 120a6e
  double joinPos = 0.45 * ringWidth;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // definisco la forma dell'anello della catena
Shinya Kitaoka 120a6e
  GLuint ringId;
Shinya Kitaoka 120a6e
  ringId   = glGenLists(1);
Shinya Kitaoka 120a6e
  double a = .6, b = .6;
Shinya Kitaoka 120a6e
  glNewList(ringId, GL_COMPILE);
Shinya Kitaoka 120a6e
  glPushMatrix();
Shinya Kitaoka 120a6e
  glScaled(ringWidth, ringHeight, 1);
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  glVertex2d(1, b);
Shinya Kitaoka 120a6e
  glVertex2d(a, 1);
Shinya Kitaoka 120a6e
  glVertex2d(-a, 1);
Shinya Kitaoka 120a6e
  glVertex2d(-1, b);
Shinya Kitaoka 120a6e
  glVertex2d(-1, -b);
Shinya Kitaoka 120a6e
  glVertex2d(-a, -1);
Shinya Kitaoka 120a6e
  glVertex2d(a, -1);
Shinya Kitaoka 120a6e
  glVertex2d(1, -b);
Shinya Kitaoka 120a6e
  glVertex2d(1, b);
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  glPopMatrix();
Shinya Kitaoka 120a6e
  glEndList();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // disegno la catena
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    tglColor((*cf)(m_color));
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    tglColor(m_color);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPointD oldPos;
Shinya Kitaoka 120a6e
  // bool firstRing = true;
Shinya Kitaoka 120a6e
  // double s = 0;
Shinya Kitaoka 120a6e
  for (UINT i = 0; i < data.size(); i += 2) {
Shinya Kitaoka 120a6e
    TPointD pos = data[i];
Shinya Kitaoka 120a6e
    TPointD u   = data[i + 1];
Shinya Kitaoka 120a6e
    TPointD v   = rotate90(u);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // disegno un anello della catena
Shinya Kitaoka 120a6e
    glPushMatrix();
Shinya Kitaoka 120a6e
    TAffine aff(u.x, v.x, pos.x, u.y, v.y, pos.y);
Shinya Kitaoka 120a6e
    tglMultMatrix(aff);
Shinya Kitaoka 120a6e
    glCallList(ringId);
Shinya Kitaoka 120a6e
    glPopMatrix();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // se e' il caso unisco la catena alla precedente
Shinya Kitaoka 120a6e
    if (i != 0) {
Shinya Kitaoka 120a6e
      TPointD q = pos - u * joinPos;
Shinya Kitaoka 120a6e
      tglDrawSegment(oldPos, q);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    oldPos = pos + u * joinPos;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glDeleteLists(ringId, 1);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TSprayStrokeStyle::TSprayStrokeStyle()
Shinya Kitaoka 120a6e
    : m_color(TPixel32::Blue), m_blend(0.5), m_intensity(10.0), m_radius(0.3) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TSprayStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TSprayStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TSprayStrokeStyle::getParamCount() const { return 3; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle::ParamType TSprayStrokeStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TSprayStrokeStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 3);
Shinya Kitaoka 120a6e
  QString value;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TSprayStrokeStyle", "Border Fade");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TSprayStrokeStyle", "Density");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TSprayStrokeStyle", "Size");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return value;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TSprayStrokeStyle::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                      double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 3);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 100.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TSprayStrokeStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                        int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 3);
Shinya Kitaoka 120a6e
  double value = 0;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    value = m_blend;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    value = m_intensity;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    value = m_radius;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return value;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSprayStrokeStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 3);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    m_blend = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    m_intensity = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    m_radius = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  updateVersionNumber();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TSprayStrokeStyle::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                   const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  //  TStroke *stroke = getStroke();
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Shinya Kitaoka 120a6e
  double step   = 4;
Shinya Kitaoka 120a6e
Shinya Kitaoka 38fd86
  double blend = m_blend;          // distanza che controlla da dove il gessetto
Shinya Kitaoka 38fd86
                                   // comincia il fade out  (0, 1)
Shinya Kitaoka 120a6e
  double intensity = m_intensity;  // quanti punti vengono disegnati ad ogni
Shinya Kitaoka 120a6e
                                   // step
Shinya Kitaoka 120a6e
  double radius = m_radius;
Shinya Kitaoka 120a6e
  double decay  = 1 - blend;
Shinya Kitaoka 120a6e
  bool fill     = 0;
Shinya Kitaoka 120a6e
  TPointD pos1;
Shinya Kitaoka 120a6e
  TRandom rnd;
Shinya Kitaoka 120a6e
  TPixelD dcolor;
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color             = m_color;
Shinya Kitaoka 120a6e
  dcolor              = toPixelD(color);
Shinya Kitaoka 120a6e
  double s            = 0;
Shinya Kitaoka 120a6e
  double minthickness = MINTHICK * sqrt(tglGetPixelSize2());
Shinya Kitaoka 120a6e
  double thickness    = 0;
Shinya Kitaoka 120a6e
  while (s <= length) {
Shinya Kitaoka 120a6e
    double w = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    // if(w<0) {s+=0.1; continue;} // per tamponare il baco della
Shinya Kitaoka 120a6e
    // getParameterAtLength()
Shinya Kitaoka 120a6e
    TThickPoint pos = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
    TPointD u       = stroke->getSpeed(w);
Shinya Kitaoka 120a6e
    double normu    = norm2(u);
Shinya Kitaoka 120a6e
    if (normu == 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // non dovrebbe succedere mai, ma per prudenza....
Shinya Kitaoka 120a6e
    u         = normalize(u);
Shinya Kitaoka 120a6e
    TPointD v = rotate90(u);
Shinya Kitaoka 120a6e
    TPointD shift;
Shinya Kitaoka 120a6e
    if (pos.thick < MINTHICK)
Shinya Kitaoka 120a6e
      thickness = minthickness;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      thickness = pos.thick;
Shinya Kitaoka 120a6e
    for (int i = 0; i < intensity; i++) {
Shinya Kitaoka 120a6e
      double vrandnorm = (0.5 - rnd.getFloat()) * 2;
Shinya Kitaoka 120a6e
      double randomv   = vrandnorm * pos.thick;
Shinya Kitaoka 120a6e
      double randomu   = (0.5 - rnd.getFloat()) * step;
Shinya Kitaoka 120a6e
      shift            = u * randomu + v * randomv;
Shinya Kitaoka 120a6e
      pos1             = pos + shift;
Shinya Kitaoka 120a6e
      double mod       = fabs(vrandnorm);
Shinya Kitaoka 120a6e
      if (mod < decay)
Shinya Kitaoka 120a6e
        glColor4d(dcolor.r, dcolor.g, dcolor.b, rnd.getFloat() * dcolor.m);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        glColor4d(dcolor.r, dcolor.g, dcolor.b,
Shinya Kitaoka 120a6e
                  rnd.getFloat() * (1 - mod) * dcolor.m);
Shinya Kitaoka 120a6e
      if (fill)
Shinya Kitaoka 120a6e
        tglDrawDisk(pos1, radius * thickness * rnd.getFloat());
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        tglDrawCircle(pos1, radius * thickness * rnd.getFloat());
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    s += step;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TGraphicPenStrokeStyle::TGraphicPenStrokeStyle()
Shinya Kitaoka 120a6e
    : m_color(TPixel32::Black), m_intensity(10.0) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TGraphicPenStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TGraphicPenStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TGraphicPenStrokeStyle::getParamCount() const { return 1; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle::ParamType TGraphicPenStrokeStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TGraphicPenStrokeStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return QCoreApplication::translate("TGraphicPenStrokeStyle", "Density");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TGraphicPenStrokeStyle::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                           double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  min = 0.0;
Shinya Kitaoka 120a6e
  max = 10.0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TGraphicPenStrokeStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                             int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  return m_intensity;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TGraphicPenStrokeStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  m_intensity = value;
Shinya Kitaoka 120a6e
  updateVersionNumber();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TGraphicPenStrokeStyle::computeData(DrawmodePointsMatrix &data,
Shinya Kitaoka 120a6e
                                         const TStroke *stroke,
Shinya Kitaoka 120a6e
                                         const TColorFunction *cf) const {
Shinya Kitaoka 120a6e
  data.clear();
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Shinya Kitaoka 120a6e
  double step   = 10;
Shinya Kitaoka 120a6e
  TPointD pos1, pos2;
Shinya Kitaoka 120a6e
  TRandom rnd;
Shinya Kitaoka 120a6e
  double intensity = m_intensity;
Shinya Kitaoka 120a6e
  data.reserve(tceil(length / 10.0));
Shinya Kitaoka 120a6e
  double s = 0;
Shinya Kitaoka 120a6e
  while (s <= length) {
Shinya Kitaoka 120a6e
    double w = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    // if(w<0) {s+=0.1; continue;} // per tamponare il baco della
Shinya Kitaoka 120a6e
    // getParameterAtLength()
Shinya Kitaoka 120a6e
    TThickPoint pos = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
    TPointD u       = stroke->getSpeed(w);
Shinya Kitaoka 120a6e
    double normu    = norm2(u);
Shinya Kitaoka 120a6e
    if (normu == 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // non dovrebbe succedere mai, ma per prudenza....
Shinya Kitaoka 120a6e
    u         = normalize(u);
Shinya Kitaoka 120a6e
    TPointD v = rotate90(u);
Shinya Kitaoka 120a6e
    TPointD shift;
Shinya Kitaoka 120a6e
    Points tmpPoints;
Shinya Kitaoka 120a6e
    tmpPoints.clear();
Shinya Kitaoka 120a6e
    GLenum drawMode;
Shinya Kitaoka 120a6e
    for (int i = 0; i < intensity; i++) {
Shinya Kitaoka 120a6e
      if (pos.thick) {
Shinya Kitaoka 120a6e
        drawMode = GL_LINES;
Shinya Kitaoka 120a6e
        tmpPoints.reserve((int)(intensity * 2 + 1));
Shinya Kitaoka 120a6e
        double randomv = (0.5 - rnd.getFloat()) * pos.thick;
Shinya Kitaoka 120a6e
        double randomu = (0.5 - rnd.getFloat()) * step;
Shinya Kitaoka 120a6e
        shift          = randomu * u + randomv * v;
Shinya Kitaoka 120a6e
        pos1           = pos + shift + v * (pos.thick);
Shinya Kitaoka 120a6e
        pos2           = pos + shift - v * (pos.thick);
Shinya Kitaoka 120a6e
        tmpPoints.push_back(pos1);
Shinya Kitaoka 120a6e
        tmpPoints.push_back(pos2);
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        drawMode = GL_POINTS;
Shinya Kitaoka 120a6e
        tmpPoints.reserve((int)(intensity + 1));
Shinya Kitaoka 120a6e
        tmpPoints.push_back((TPointD)pos);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (!tmpPoints.empty()) {
Shinya Kitaoka 120a6e
      assert(drawMode == GL_POINTS || drawMode == GL_LINES);
Shinya Kitaoka 120a6e
      data.push_back(make_pair(drawMode, tmpPoints));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    s += step;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TGraphicPenStrokeStyle::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                        DrawmodePointsMatrix &data,
Shinya Kitaoka 120a6e
                                        const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = m_color;
Shinya Kitaoka 120a6e
  tglColor(color);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  DrawmodePointsMatrix::iterator it1 = data.begin();
Shinya Kitaoka 120a6e
  for (; it1 != data.end(); ++it1) {
Shinya Kitaoka 120a6e
    if (it1->first == GL_LINES) {
Shinya Kitaoka 120a6e
      Points::iterator it2 = it1->second.begin();
Shinya Kitaoka 120a6e
      glBegin(GL_LINES);
Shinya Kitaoka 120a6e
      for (; it2 != it1->second.end(); ++it2) tglVertex(*it2);
Shinya Kitaoka 120a6e
      glEnd();
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      assert(it1->first == GL_POINTS);
Shinya Kitaoka 120a6e
      Points::iterator it2 = it1->second.begin();
Shinya Kitaoka 120a6e
      glBegin(GL_POINTS);
Shinya Kitaoka 120a6e
      for (; it2 != it1->second.end(); ++it2) tglVertex(*it2);
Shinya Kitaoka 120a6e
      glEnd();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
double inline get_line_slope(double meter, double inmax, double linemax,
Shinya Kitaoka 120a6e
                             double outmax) {
Shinya Kitaoka 120a6e
  if (meter <= inmax)
Shinya Kitaoka 120a6e
    return meter / inmax;
Shinya Kitaoka 120a6e
  else if (meter <= inmax + linemax)
Shinya Kitaoka 120a6e
    return 1;
Shinya Kitaoka 120a6e
  else if (meter <= inmax + linemax + outmax)
Shinya Kitaoka 120a6e
    return (inmax + linemax - meter) / outmax + 1;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TDottedLineStrokeStyle::TDottedLineStrokeStyle()
Shinya Kitaoka 120a6e
    : m_color(TPixel32::Black)
Shinya Kitaoka 120a6e
    , m_in(10.0)
Shinya Kitaoka 120a6e
    , m_line(50.0)
Shinya Kitaoka 120a6e
    , m_out(10.0)
Shinya Kitaoka 120a6e
    , m_blank(10.0) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TDottedLineStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TDottedLineStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TDottedLineStrokeStyle::getParamCount() const { return 4; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle::ParamType TDottedLineStrokeStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TDottedLineStrokeStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 4);
Shinya Kitaoka 120a6e
  QString value;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TDottedLineStrokeStyle", "Fade In");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TDottedLineStrokeStyle", "Dash");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TDottedLineStrokeStyle", "Fade Out");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TDottedLineStrokeStyle", "Gap");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return value;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TDottedLineStrokeStyle::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                           double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 4);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    min = 1.0;
Shinya Kitaoka 120a6e
    max = 100.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    min = 1.0;
Shinya Kitaoka 120a6e
    max = 100.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    min = 1.;
Shinya Kitaoka 120a6e
    max = 100.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 100.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TDottedLineStrokeStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                             int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 4);
Shinya Kitaoka 120a6e
  double value = 0;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    value = m_in;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    value = m_line;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    value = m_out;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    value = m_blank;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return value;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TDottedLineStrokeStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 4);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    m_in = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    m_line = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    m_out = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    m_blank = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  updateVersionNumber();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TDottedLineStrokeStyle::computeData(Points &positions,
Shinya Kitaoka 120a6e
                                         const TStroke *stroke,
Shinya Kitaoka 120a6e
                                         const TColorFunction *cf) const {
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double step     = 5.0;
Shinya Kitaoka 120a6e
  double linemax  = m_line;
Shinya Kitaoka 120a6e
  double inmax    = (m_in / 100);
Shinya Kitaoka 120a6e
  double outmax   = (m_out / 100);
Shinya Kitaoka 120a6e
  double blankmax = m_blank;
Shinya Kitaoka 120a6e
  double total    = 0;
Shinya Kitaoka 120a6e
  TRandom rnd;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  positions.clear();
Shinya Kitaoka 120a6e
  positions.reserve(tceil(length / step) + 1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPointD oldPos1, oldPos2, oldPos3, oldPos4, pos1, pos2, pos3, pos4;
Shinya Kitaoka 120a6e
  // bool firstRing = true;
Shinya Kitaoka 120a6e
  double s            = 0;
Shinya Kitaoka 120a6e
  double meter        = 0;
Shinya Kitaoka 120a6e
  double center       = 0;
Shinya Kitaoka 120a6e
  double slopetmp     = 0;
Shinya Kitaoka 120a6e
  double minthickness = MINTHICK * sqrt(tglGetPixelSize2());
Shinya Kitaoka 120a6e
  double thickness    = 0;
Shinya Kitaoka 120a6e
  double line = 0, in = 0, out = 0, blank = 0;
Shinya Kitaoka 120a6e
  while (s <= length) {
Shinya Kitaoka 120a6e
    double w = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    if (w < 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // per tamponare il baco della getParameterAtLength()
Shinya Kitaoka 120a6e
    TThickPoint pos = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (pos.thick < MINTHICK)
Shinya Kitaoka 120a6e
      thickness = minthickness;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      thickness = pos.thick;
Shinya Kitaoka 120a6e
    if (meter >= total) {
Shinya Kitaoka 120a6e
      meter = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      line                        = linemax * (1 + rnd.getFloat()) * thickness;
Shinya Kitaoka 120a6e
      if (line > length - s) line = length - s;
Shinya Kitaoka 120a6e
      in                          = inmax * line;
Shinya Kitaoka 120a6e
      out                         = outmax * line;
Shinya Kitaoka 120a6e
      line                        = line - in - out;
Shinya Kitaoka 120a6e
      blank                       = blankmax * (1 + rnd.getFloat()) * thickness;
Shinya Kitaoka 120a6e
      if (in + out > length) {
Shinya Kitaoka 120a6e
        in   = rnd.getFloat() * (length / 2);
Shinya Kitaoka 120a6e
        out  = length - in;
Shinya Kitaoka 120a6e
        line = 0;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      total = in + line + out + blank;
Shinya Kitaoka 120a6e
    } else if (meter > in + line + out + step) {
Shinya Kitaoka 120a6e
      s += step;
Shinya Kitaoka 120a6e
      meter += step;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    TPointD u = stroke->getSpeed(w);
Shinya Kitaoka 120a6e
    if (norm2(u) == 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // non dovrebbe succedere mai, ma per prudenza....
Shinya Kitaoka 120a6e
    u            = normalize(u);
Shinya Kitaoka 120a6e
    double slope = 0;
Shinya Kitaoka 120a6e
    slope        = get_line_slope(meter, in, line, out);
Shinya Kitaoka 120a6e
    slopetmp     = slope;
Shinya Kitaoka 120a6e
    TPointD v    = rotate90(u) * (thickness)*slope;
Shinya Kitaoka 120a6e
    if (pos.thick * slope < 1)
Shinya Kitaoka 120a6e
      center = 0.0;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      center = 0.5;
Shinya Kitaoka 120a6e
    pos1     = pos + v;
Shinya Kitaoka 120a6e
    pos2     = pos + v * 0.5;
Shinya Kitaoka 120a6e
    pos3     = pos - v * 0.5;
Shinya Kitaoka 120a6e
    pos4     = pos - v;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    positions.push_back(pos1);
Shinya Kitaoka 120a6e
    positions.push_back(pos2);
Shinya Kitaoka 120a6e
    positions.push_back(pos3);
Shinya Kitaoka 120a6e
    positions.push_back(pos4);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    s += step;
Shinya Kitaoka 120a6e
    meter += step;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TDottedLineStrokeStyle::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                        Points &positions,
Shinya Kitaoka 120a6e
                                        const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = m_color;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (UINT i = 4; i < positions.size(); i += 4) {
Shinya Kitaoka 120a6e
    glBegin(GL_QUAD_STRIP);
Shinya Kitaoka 120a6e
    glColor4ub(color.r, color.g, color.b, 0);
Shinya Kitaoka 120a6e
    tglVertex(positions[i - 4]);
Shinya Kitaoka 120a6e
    tglVertex(positions[i]);
Shinya Kitaoka 120a6e
    glColor4ub(color.r, color.g, color.b, color.m);
Shinya Kitaoka 120a6e
    tglVertex(positions[i - 3]);
Shinya Kitaoka 120a6e
    tglVertex(positions[i + 1]);
Shinya Kitaoka 120a6e
    tglVertex(positions[i - 2]);
Shinya Kitaoka 120a6e
    tglVertex(positions[i + 2]);
Shinya Kitaoka 120a6e
    glColor4ub(color.r, color.g, color.b, 0);
Shinya Kitaoka 120a6e
    tglVertex(positions[i - 1]);
Shinya Kitaoka 120a6e
    tglVertex(positions[i + 3]);
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRopeStrokeStyle::TRopeStrokeStyle()
Shinya Kitaoka 120a6e
    : m_color(TPixel32(255, 135, 0)), m_bend(0.4) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TRopeStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TRopeStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TRopeStrokeStyle::getParamCount() const { return 1; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle::ParamType TRopeStrokeStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TRopeStrokeStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  return QCoreApplication::translate("TRopeStrokeStyle", "Tilt");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TRopeStrokeStyle::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                     double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  min = -1.0;
Shinya Kitaoka 120a6e
  max = 1.0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TRopeStrokeStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                       int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  return m_bend;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TRopeStrokeStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  m_bend = value;
Shinya Kitaoka 120a6e
  updateVersionNumber();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TRopeStrokeStyle::computeData(Points &positions, const TStroke *stroke,
Shinya Kitaoka 120a6e
                                   const TColorFunction *cf) const {
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Shinya Kitaoka 120a6e
  // spessore della catena = spessore "medio" dello stroke
Shinya Kitaoka 120a6e
  double step = 10.0;
Shinya Kitaoka 120a6e
  double bend;
Shinya Kitaoka 120a6e
  double bump;
Shinya Kitaoka 120a6e
  double bump_max = step / 4;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  positions.clear();
Shinya Kitaoka 120a6e
  positions.reserve(tceil(length / step) + 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPointD oldPos1, oldPos2;
Shinya Kitaoka 120a6e
  bool firstRing = true;
Shinya Kitaoka 120a6e
  double s       = 0;
Shinya Kitaoka 120a6e
  while (s <= length) {
Shinya Kitaoka 120a6e
    double w = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    if (w < 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // per tamponare il baco della getParameterAtLength()
Shinya Kitaoka 120a6e
    TThickPoint pos = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
    TPointD u       = stroke->getSpeed(w);
Shinya Kitaoka 120a6e
    if (norm2(u) == 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // non dovrebbe succedere mai, ma per prudenza....
Shinya Kitaoka 120a6e
    u                          = normalize(u);
Shinya Kitaoka 120a6e
    bend                       = pos.thick * m_bend;
Shinya Kitaoka 120a6e
    bump                       = pos.thick * 0.3;
Shinya Kitaoka 120a6e
    if (bump >= bump_max) bump = bump_max;
Shinya Kitaoka 120a6e
    TPointD v                  = rotate90(u) * pos.thick;
Shinya Kitaoka 120a6e
    TPointD v1                 = v * 0.2;
Shinya Kitaoka 120a6e
    if (firstRing) {
Shinya Kitaoka 120a6e
      firstRing = false;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      positions.push_back(pos + (bend + bump) * u + v - v1);
Shinya Kitaoka 120a6e
      positions.push_back(pos + (bend)*u + v);
Shinya Kitaoka 120a6e
      positions.push_back(oldPos1 + (bump)*u + v1);
Shinya Kitaoka 120a6e
      positions.push_back(oldPos1);
Shinya Kitaoka 120a6e
      positions.push_back(oldPos2);
Shinya Kitaoka 120a6e
      positions.push_back(oldPos2 + bump * u - v1);
Shinya Kitaoka 120a6e
      positions.push_back(pos + u * (-bend) - v);
Shinya Kitaoka 120a6e
      positions.push_back(pos + u * (bump - bend) - v + v1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    oldPos1 = pos + (bend + bump) * u + v - v1;
Shinya Kitaoka 120a6e
    oldPos2 = pos + u * (bump - bend) - v + v1;
Shinya Kitaoka 120a6e
    s += step;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  positions.push_back(oldPos1);
Shinya Kitaoka 120a6e
  positions.push_back(oldPos2);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TRopeStrokeStyle::drawStroke(const TColorFunction *cf, Points &positions,
Shinya Kitaoka 120a6e
                                  const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  if (positions.size() <= 1) return;
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = m_color;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //  GLuint  rope_id;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPixel32 blackcolor(TPixel32::Black);
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    blackcolor = (*(cf))(blackcolor);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    blackcolor = blackcolor;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // rope_id = glGenLists(1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  static const int stride = sizeof(TPointD);
Shinya Kitaoka 120a6e
  glEnableClientState(GL_VERTEX_ARRAY);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  UINT i = 0;
Shinya Kitaoka 120a6e
  for (; i < positions.size() - 2; i += 8) {
Shinya Kitaoka 120a6e
    /*
Shinya Kitaoka 120a6e
glNewList(rope_id,GL_COMPILE);
Shinya Kitaoka 120a6e
      tglVertex(positions[i]);
Shinya Kitaoka 120a6e
      tglVertex(positions[i+1]);
Shinya Kitaoka 120a6e
      tglVertex(positions[i+2]);
Shinya Kitaoka 120a6e
      tglVertex(positions[i+3]);
Shinya Kitaoka 120a6e
      tglVertex(positions[i+4]);
Shinya Kitaoka 120a6e
      tglVertex(positions[i+5]);
Shinya Kitaoka 120a6e
      tglVertex(positions[i+6]);
Shinya Kitaoka 120a6e
      tglVertex(positions[i+7]);
Shinya Kitaoka 120a6e
glEndList();
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
    tglColor(color);
Shinya Kitaoka 120a6e
    // glBegin(GL_POLYGON);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    glVertexPointer(2, GL_DOUBLE, stride, &positions[i]);
Shinya Kitaoka 120a6e
    glDrawArrays(GL_POLYGON, 0, 8);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // glCallList(rope_id);
Shinya Kitaoka 120a6e
    // glEnd();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    tglColor(blackcolor);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
    glVertexPointer(2, GL_DOUBLE, stride, &positions[i]);
Shinya Kitaoka 120a6e
    glDrawArrays(GL_LINE_STRIP, 0, 8);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // glCallList(rope_id);
Shinya Kitaoka 120a6e
    // glEnd();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glDisableClientState(GL_VERTEX_ARRAY);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  tglVertex(positions[i]);
Shinya Kitaoka 120a6e
  tglVertex(positions[i + 1]);
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // glDeleteLists(rope_id,1);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TCrystallizeStrokeStyle::TCrystallizeStrokeStyle()
Shinya Kitaoka 120a6e
    : m_color(TPixel32(255, 150, 150, 255)), m_period(10.0), m_opacity(0.5) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TCrystallizeStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TCrystallizeStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TCrystallizeStrokeStyle::getParamCount() const { return 2; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle::ParamType TCrystallizeStrokeStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TCrystallizeStrokeStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  return index == 0
Shinya Kitaoka 120a6e
             ? QCoreApplication::translate("TCrystallizeStrokeStyle", "Crease")
Shinya Kitaoka 120a6e
             : QCoreApplication::translate("TCrystallizeStrokeStyle",
Shinya Kitaoka 120a6e
                                           "Opacity");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TCrystallizeStrokeStyle::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                            double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  if (index == 0) {
Shinya Kitaoka 120a6e
    min = 1.0;
Shinya Kitaoka 120a6e
    max = 100.0;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TCrystallizeStrokeStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                              int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  return index == 0 ? m_period : m_opacity;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TCrystallizeStrokeStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  if (index == 0)
Shinya Kitaoka 120a6e
    m_period = value;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    m_opacity = value;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // updateVersionNumber(); non serve perche' i parametri vengono sfrutttati
Shinya Kitaoka 120a6e
  // direttamente nella draw
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TCrystallizeStrokeStyle::computeData(Points &positions,
Shinya Kitaoka 120a6e
                                          const TStroke *stroke,
Shinya Kitaoka 120a6e
                                          const TColorFunction *cf) const {
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Shinya Kitaoka 120a6e
  double step   = 10.0;
Shinya Kitaoka 120a6e
  TRandom rnd;
Shinya Kitaoka 120a6e
  positions.clear();
Shinya Kitaoka 120a6e
  positions.reserve(tceil((length + 1) / step));
Shinya Kitaoka 120a6e
  double s = 0;
Shinya Kitaoka 120a6e
  while (s <= length) {
Shinya Kitaoka 120a6e
    double w = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    if (w < 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // per tamponare il baco della getParameterAtLength()
Shinya Kitaoka 120a6e
    TThickPoint pos = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
    TPointD u       = stroke->getSpeed(w);
Shinya Kitaoka 120a6e
    if (norm2(u) == 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // non dovrebbe succedere mai, ma per prudenza....
Shinya Kitaoka 120a6e
    u         = normalize(u);
Shinya Kitaoka 120a6e
    TPointD v = rotate90(u) * (pos.thick / 2);
Shinya Kitaoka 120a6e
    positions.push_back(pos + v * (1 + rnd.getFloat()) +
Shinya Kitaoka 120a6e
                        u * 2 * rnd.getFloat());
Shinya Kitaoka 120a6e
    positions.push_back(pos - v * (1 + rnd.getFloat()) -
Shinya Kitaoka 120a6e
                        u * 2 * rnd.getFloat());
Shinya Kitaoka 120a6e
    s += step;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TCrystallizeStrokeStyle::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                         Points &positions,
Shinya Kitaoka 120a6e
                                         const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  // double length = stroke->getLength();
Shinya Kitaoka 120a6e
  double step    = 10.0;
Shinya Kitaoka 120a6e
  double period  = (101 - m_period) * step;
Shinya Kitaoka 120a6e
  double counter = 0;
Shinya Kitaoka 120a6e
  double opacity = m_opacity;
Shinya Kitaoka 120a6e
  TRandom rnd;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = m_color;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPixelD dcolor = toPixelD(color);
Shinya Kitaoka 120a6e
  // double s = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glBegin(GL_QUAD_STRIP);
Shinya Kitaoka 120a6e
  for (int i = 0; i < (int)positions.size() / 2; i++) {
Shinya Kitaoka 120a6e
    if (counter > period) counter = 0;
Shinya Kitaoka 120a6e
    glColor4d(dcolor.r, dcolor.g, dcolor.b,
Shinya Kitaoka 120a6e
              (opacity + (counter / period) * rnd.getFloat()) * dcolor.m);
Shinya Kitaoka 120a6e
    tglVertex(positions[i * 2]);
Shinya Kitaoka 120a6e
    tglVertex(positions[i * 2 + 1]);
Shinya Kitaoka 120a6e
    counter += step;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  counter = 0;
Shinya Kitaoka 120a6e
  glColor4d(dcolor.r, dcolor.g, dcolor.b, dcolor.m);
Shinya Kitaoka 120a6e
  for (int j = 1; j < (int)positions.size() / 2; j++) {
Shinya Kitaoka 120a6e
    glBegin(GL_LINES);
Shinya Kitaoka 120a6e
    tglVertex(positions[(j - 1) * 2]);
Shinya Kitaoka 120a6e
    tglVertex(positions[j * 2]);
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
    glBegin(GL_LINES);
Shinya Kitaoka 120a6e
    tglVertex(positions[(j - 1) * 2 + 1]);
Shinya Kitaoka 120a6e
    tglVertex(positions[j * 2 + 1]);
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class Stripe {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TPointD oldpos1;
Shinya Kitaoka 120a6e
  TPointD oldpos2;
Shinya Kitaoka 120a6e
  TPointD pos1;
Shinya Kitaoka 120a6e
  TPointD pos2;
Shinya Kitaoka 120a6e
  int phase;
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  Stripe();
Shinya Kitaoka 120a6e
  void drawpolygon();
Shinya Kitaoka 120a6e
  void drawlines(TPixel32 blackcolor);
Shinya Kitaoka 120a6e
  void addToSegment(vector<tsegment> *sv, vector<tsegment> &scontour,</tsegment></tsegment>
Shinya Kitaoka 120a6e
                    TPixel32 *colors);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Stripe::Stripe() {
Shinya Kitaoka 120a6e
  oldpos1 = TPointD(0, 0);
Shinya Kitaoka 120a6e
  oldpos2 = TPointD(0, 0);
Shinya Kitaoka 120a6e
  pos1    = TPointD(0, 0);
Shinya Kitaoka 120a6e
  pos2    = TPointD(0, 0);
Shinya Kitaoka 120a6e
  color   = TPixel32(0, 0, 0);
Shinya Kitaoka 120a6e
  phase   = 0;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void Stripe::drawpolygon() {
Shinya Kitaoka 120a6e
  tglColor(color);
Shinya Kitaoka 120a6e
  glBegin(GL_POLYGON);
Shinya Kitaoka 120a6e
  tglVertex(oldpos1);
Shinya Kitaoka 120a6e
  tglVertex(pos1);
Shinya Kitaoka 120a6e
  tglVertex(pos2);
Shinya Kitaoka 120a6e
  tglVertex(oldpos2);
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Stripe::addToSegment(vector<tsegment> *sv, vector<tsegment> &scontour,</tsegment></tsegment>
Shinya Kitaoka 120a6e
                          TPixel32 *colors) {
Shinya Kitaoka 120a6e
  TPointD p0 = (oldpos1 + oldpos2) * 0.5;
Shinya Kitaoka 120a6e
  TPointD p1 = (pos1 + pos2) * 0.5;
Shinya Kitaoka 120a6e
  //	TPointD p0=oldpos1;
Shinya Kitaoka 120a6e
  //	TPointD p1=pos1;
Shinya Kitaoka 120a6e
  if (color == colors[0]) sv[0].push_back(TSegment(p0, p1));
Shinya Kitaoka 120a6e
  if (color == colors[1]) sv[1].push_back(TSegment(p0, p1));
Shinya Kitaoka 120a6e
  if (color == colors[2]) sv[2].push_back(TSegment(p0, p1));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  scontour.push_back(TSegment(oldpos1, pos1));
Shinya Kitaoka 120a6e
  scontour.push_back(TSegment(oldpos2, pos2));
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void Stripe::drawlines(TPixel32 blackcolor) {
Shinya Kitaoka 120a6e
  tglColor(blackcolor);
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  tglVertex(oldpos1);
Shinya Kitaoka 120a6e
  tglVertex(pos1);
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  tglVertex(pos2);
Shinya Kitaoka 120a6e
  tglVertex(oldpos2);
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TBraidStrokeStyle::TBraidStrokeStyle()
Shinya Kitaoka 120a6e
    : m_period(80.0)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  m_colors[0] = TPixel32::Red;
Shinya Kitaoka 120a6e
  m_colors[1] = TPixel32::Green;
Shinya Kitaoka 120a6e
  m_colors[2] = TPixel32::Blue;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TBraidStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TBraidStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TBraidStrokeStyle::getParamCount() const { return 1; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle::ParamType TBraidStrokeStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TBraidStrokeStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return QCoreApplication::translate("TBraidStrokeStyle", "Twirl");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBraidStrokeStyle::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                      double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  min = 1.0;
Shinya Kitaoka 120a6e
  max = 100.0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TBraidStrokeStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                        int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  return m_period;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBraidStrokeStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  m_period = value;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  updateVersionNumber();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPixel32 TBraidStrokeStyle::getColorParamValue(int index) const {
Shinya Kitaoka 120a6e
  TPixel32 tmp;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case (0):
Shinya Kitaoka 120a6e
    tmp = m_colors[0];
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case (1):
Shinya Kitaoka 120a6e
    tmp = m_colors[1];
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case (2):
Shinya Kitaoka 120a6e
    tmp = m_colors[2];
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return tmp;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBraidStrokeStyle::setColorParamValue(int index, const TPixel32 &color) {
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case (0):
Shinya Kitaoka 120a6e
    m_colors[0] = color;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case (1):
Shinya Kitaoka 120a6e
    m_colors[1] = color;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case (2):
Shinya Kitaoka 120a6e
    m_colors[2] = color;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBraidStrokeStyle::loadData(int ids, TInputStreamInterface &is) {
Shinya Kitaoka 120a6e
  if (ids != 112)
Shinya Kitaoka 120a6e
    throw TException("Braid stroke style: unknown obsolete format");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  is >> m_colors[0] >> m_period;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_period /= 10.0;
Shinya Kitaoka 120a6e
  m_colors[0] = TPixel32::Red;
Shinya Kitaoka 120a6e
  m_colors[1] = TPixel32::Green;
Shinya Kitaoka 120a6e
  m_colors[2] = TPixel32::Blue;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBraidStrokeStyle::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                   const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  double length                = stroke->getLength();
Shinya Kitaoka 120a6e
  const int ntick              = 81;
Shinya Kitaoka 120a6e
  const double stripethickness = 0.3;
Shinya Kitaoka 120a6e
  int period                   = (int)(101 - m_period) * 20;
Shinya Kitaoka 120a6e
  double step                  = period / (double)ntick;
Shinya Kitaoka 120a6e
  double freq                  = M_2PI / ntick;
Shinya Kitaoka 120a6e
  int swapcount                = 0;
Shinya Kitaoka 120a6e
  int count                    = 0;
Shinya Kitaoka 120a6e
  bool firstRing               = true;
Shinya Kitaoka 120a6e
  double s                     = 0;
Shinya Kitaoka 120a6e
  double swap;
Shinya Kitaoka 120a6e
  vector<stripe> braid;</stripe>
Shinya Kitaoka 120a6e
  vector<double> ssin;</double>
Shinya Kitaoka 120a6e
  int k = 0;
Shinya Kitaoka 120a6e
  TPixel32 colors[3];
Shinya Kitaoka 120a6e
  for (k = 0; k < 3; k++) {
Shinya Kitaoka 120a6e
    if (cf)
Shinya Kitaoka 120a6e
      colors[k] = (*(cf))(m_colors[k]);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      colors[k] = m_colors[k];
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  TPixel32 blackcolor = TPixel32::Black;
Jeremy Bullock 175c6b
  if (cf) blackcolor  = (*(cf))(blackcolor);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (k = 0; k < 3; k++) {
Shinya Kitaoka 120a6e
    Stripe tmp;
Shinya Kitaoka 120a6e
    tmp.phase = (ntick * k) / 3;
Shinya Kitaoka 120a6e
    tmp.color = colors[k];
Shinya Kitaoka 120a6e
    braid.push_back(tmp);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int z = 0; z < ntick; z++) {
Shinya Kitaoka 120a6e
    double tmpsin = sin(z * freq);
Shinya Kitaoka 120a6e
    ssin.push_back(tmpsin);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  while (s <= length) {
Shinya Kitaoka 120a6e
    count++;
Shinya Kitaoka 120a6e
    double w = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    if (w < 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // per tamponare il baco della getParameterAtLength()
Shinya Kitaoka 120a6e
    TThickPoint pos = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
    TPointD u       = stroke->getSpeed(w);
Shinya Kitaoka 120a6e
    if (norm2(u) == 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // non dovrebbe succedere mai, ma per prudenza....
Shinya Kitaoka 120a6e
    u          = normalize(u);
Shinya Kitaoka 120a6e
    TPointD v  = rotate90(u) * pos.thick;
Shinya Kitaoka 120a6e
    TPointD v1 = v * stripethickness;
Shinya Kitaoka 120a6e
    v          = v * 0.5;
Shinya Kitaoka 120a6e
    // int modper=(int)s%(int)period;
Shinya Kitaoka 120a6e
    if (firstRing) {
Shinya Kitaoka 120a6e
      firstRing = false;
Shinya Kitaoka 120a6e
      swap      = 0;
Shinya Kitaoka 120a6e
      for (int j = 0; j < (int)braid.size(); j++) {
Shinya Kitaoka 120a6e
        int tmp          = (count + braid[j].phase) % ntick;
Shinya Kitaoka 120a6e
        braid[j].oldpos1 = pos + v * ssin[tmp];
Shinya Kitaoka 120a6e
        braid[j].oldpos2 = pos + v * ssin[tmp] + v1;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      for (int i = 0; i < (int)braid.size(); i++) {
Shinya Kitaoka 120a6e
        int tmp       = (count + braid[i].phase) % ntick;
Shinya Kitaoka 120a6e
        braid[i].pos1 = pos + v * ssin[tmp];
Shinya Kitaoka 120a6e
        braid[i].pos2 = pos + v * ssin[tmp] + v1;
Jeremy Bullock 175c6b
        braid[i].drawpolygon();
Jeremy Bullock 175c6b
        braid[i].drawlines(blackcolor);
Shinya Kitaoka 120a6e
        braid[i].oldpos1 = pos + v * ssin[tmp];
Shinya Kitaoka 120a6e
        braid[i].oldpos2 = pos + v * ssin[tmp] + v1;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    s += step;
Shinya Kitaoka 120a6e
    swap += step;
Shinya Kitaoka 120a6e
    if (swap > (period / 3.0)) {
Shinya Kitaoka 120a6e
      swapcount++;
otakuto ed7dcd
      std::swap(braid[0], braid[1 + (swapcount & 1)]);
Shinya Kitaoka 120a6e
      swap -= period / 3.0;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TSketchStrokeStyle::TSketchStrokeStyle()
Shinya Kitaoka 120a6e
    : m_color(TPixel32(100, 100, 150, 127)), m_density(0.4) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TSketchStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TSketchStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TSketchStrokeStyle::getParamCount() const { return 1; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle::ParamType TSketchStrokeStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TSketchStrokeStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return QCoreApplication::translate("TSketchStrokeStyle", "Density");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSketchStrokeStyle::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                       double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  min = 0.0;
Shinya Kitaoka 120a6e
  max = 1.0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TSketchStrokeStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                         int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  return m_density;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSketchStrokeStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  m_density = value;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  updateVersionNumber();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSketchStrokeStyle::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                    const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Shinya Kitaoka 120a6e
  if (length <= 0) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int count = (int)(length * m_density);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double maxDw = std::min(1.0, 20.0 / length);
Shinya Kitaoka 120a6e
  double minDw = 1.0 / length;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = m_color;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tglColor(color);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRandom rnd;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (int i = 0; i < count; i++) {
Shinya Kitaoka 120a6e
    double r    = rnd.getFloat();
Shinya Kitaoka 120a6e
    double dw   = (1 - r) * minDw + r * maxDw;
Shinya Kitaoka 120a6e
    double wmin = dw, wmax = 1 - dw;
Shinya Kitaoka 120a6e
    if (wmin >= wmax) continue;
Shinya Kitaoka 120a6e
    r        = rnd.getFloat();
Shinya Kitaoka 120a6e
    double w = (1 - r) * wmin + r * wmax;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    double w0 = w - dw;
Shinya Kitaoka 120a6e
    double w1 = w + dw;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TThickPoint p0 = stroke->getThickPoint(w0);
Shinya Kitaoka 120a6e
    TThickPoint p1 = stroke->getThickPoint(w1);
Shinya Kitaoka 120a6e
    double d01     = tdistance(p0, p1);
Shinya Kitaoka 120a6e
    if (d01 == 0) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int count = (int)(d01);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TPointD v0 = stroke->getSpeed(w0);
Shinya Kitaoka 120a6e
    TPointD v1 = stroke->getSpeed(w1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (norm2(v0) == 0 || norm2(v1) == 0)
Shinya Kitaoka 120a6e
      continue;  // non dovrebbe succedere mai, ma....
Shinya Kitaoka 120a6e
    v0 = rotate90(normalize(v0));
Shinya Kitaoka 120a6e
    v1 = rotate90(normalize(v1));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    double delta  = 0.5 * (rnd.getFloat() - 0.5) * (p0.thick + p1.thick);
Shinya Kitaoka 120a6e
    double d      = 0.1 * d01;
Shinya Kitaoka 120a6e
    double delta0 = delta - d;
Shinya Kitaoka 120a6e
    double delta1 = delta + d;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
    tglVertex(p0 + v0 * delta0);
Shinya Kitaoka 120a6e
    for (int j = 1; j < count; j++) {
Shinya Kitaoka 120a6e
      double t  = j / (double)count;
Shinya Kitaoka 120a6e
      w         = (1 - t) * w0 + t * w1;
Shinya Kitaoka 120a6e
      TPointD v = rotate90(normalize(stroke->getSpeed(w)));
Shinya Kitaoka 120a6e
      assert(0 <= w && w <= 1);
Shinya Kitaoka 120a6e
      TPointD p      = stroke->getPoint(w);
Shinya Kitaoka 120a6e
      double delta_t = (1 - t) * delta0 + t * delta1;
Shinya Kitaoka 120a6e
      tglVertex(p + v * delta_t);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    tglVertex(p1 + v1 * delta1);
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glColor4d(0, 0, 0, 1);
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TBubbleStrokeStyle::TBubbleStrokeStyle()
Shinya Kitaoka 120a6e
    : m_color0(TPixel32::Red), m_color1(TPixel32::Green) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle *TBubbleStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TBubbleStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBubbleStrokeStyle::loadData(int ids, TInputStreamInterface &is) {
Shinya Kitaoka 120a6e
  if (ids != 114)
Shinya Kitaoka 120a6e
    throw TException("Bubble  stroke style: unknown obsolete format");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_color0 = TPixel32::Red;
Shinya Kitaoka 120a6e
  m_color1 = TPixel32::Green;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBubbleStrokeStyle::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                    const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Shinya Kitaoka 120a6e
  if (length <= 0) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRandom rnd(0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPixel32 color0, color1;
Shinya Kitaoka 120a6e
  if (cf) {
Shinya Kitaoka 120a6e
    color0 = (*(cf))(m_color0);
Shinya Kitaoka 120a6e
    color1 = (*(cf))(m_color1);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    color0 = m_color0;
Shinya Kitaoka 120a6e
    color1 = m_color1;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double minthickness = MINTHICK * sqrt(tglGetPixelSize2());
Shinya Kitaoka 120a6e
  double thickness    = 0;
Shinya Kitaoka 120a6e
  for (double s = 0; s < length; s += 5) {
Shinya Kitaoka 120a6e
    TPointD p = stroke->getPointAtLength(s);
Shinya Kitaoka 120a6e
    double w  = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    if (w < 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // per tamponare il baco della getParameterAtLength()
Shinya Kitaoka 120a6e
    TThickPoint pos = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
    int toff        = rnd.getInt(0, 999);
Shinya Kitaoka 120a6e
    int t           = (m_currentFrame + toff) % 1000;
Shinya Kitaoka 120a6e
    TRandom rnd2(t >> 2);
Shinya Kitaoka 120a6e
    p += 2 * TPointD(-0.5 + rnd2.getFloat(), -0.5 + rnd2.getFloat());
Shinya Kitaoka 120a6e
    if (pos.thick < MINTHICK)
Shinya Kitaoka 120a6e
      thickness = minthickness;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      thickness = pos.thick;
Shinya Kitaoka 120a6e
    tglColor(blend(color0, color1, rnd.getFloat()));
Shinya Kitaoka 120a6e
    double radius = (t & ((int)(thickness)));
Shinya Kitaoka 120a6e
    tglDrawCircle(p, radius);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//=============================================================================
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TTissueStrokeStyle::TTissueStrokeStyle()
Shinya Kitaoka 120a6e
    : m_color(TPixel32::Black), m_density(3.0), m_border(1.0) {}
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TTissueStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TTissueStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TTissueStrokeStyle::getParamCount() const { return 2; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle::ParamType TTissueStrokeStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TTissueStrokeStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  return index == 0
Shinya Kitaoka 120a6e
             ? QCoreApplication::translate("TTissueStrokeStyle", "Density")
Shinya Kitaoka 120a6e
             : QCoreApplication::translate("TTissueStrokeStyle", "Border Size");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TTissueStrokeStyle::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                       double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  if (index == 0) {
Shinya Kitaoka 120a6e
    min = 2.0;
Shinya Kitaoka 120a6e
    max = 10.0;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TTissueStrokeStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                         int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  return index == 0 ? m_density : m_border;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TTissueStrokeStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  if (index == 0)
Shinya Kitaoka 120a6e
    m_density = value;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    m_border = value;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  updateVersionNumber();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TTissueStrokeStyle::computeData(PointMatrix &data, const TStroke *stroke,
Shinya Kitaoka 120a6e
                                     const TColorFunction *cf) const {
Shinya Kitaoka 120a6e
  data.clear();
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Shinya Kitaoka 120a6e
  double step   = 5.0;
Shinya Kitaoka 120a6e
  double border = m_border;
Shinya Kitaoka 120a6e
  TPointD pos1, oldPos1;
Shinya Kitaoka 120a6e
  TRandom rnd;
Shinya Kitaoka 120a6e
  double increment = 0.0;
Shinya Kitaoka 120a6e
  int intensity    = (int)m_density + 2;
Shinya Kitaoka 120a6e
  vector<tpointd> points;</tpointd>
Shinya Kitaoka 120a6e
  vector<tpointd> oldpoints;</tpointd>
Shinya Kitaoka 120a6e
  double s       = 0;
Shinya Kitaoka 120a6e
  bool firstRing = true;
Shinya Kitaoka 120a6e
  while (s <= length) {
Shinya Kitaoka 120a6e
    double w = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    if (w < 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // per tamponare il baco della getParameterAtLength()
Shinya Kitaoka 120a6e
    TThickPoint pos = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
    TPointD u       = stroke->getSpeed(w);
Shinya Kitaoka 120a6e
    if (norm2(u) == 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // non dovrebbe succedere mai, ma per prudenza....
Shinya Kitaoka 120a6e
    u         = normalize(u);
Shinya Kitaoka 120a6e
    TPointD v = rotate90(u);
Shinya Kitaoka 120a6e
    increment = (2 * pos.thick) / (intensity - 1);
Shinya Kitaoka 120a6e
    for (int i = 1; i < intensity - 1; i++) {
Shinya Kitaoka 120a6e
      pos1 = pos + v * (-pos.thick + i * increment);
Shinya Kitaoka 120a6e
      points.push_back(pos1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (firstRing) {
Shinya Kitaoka 120a6e
      firstRing = false;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      Points tmpPoints1;
Shinya Kitaoka 120a6e
      tmpPoints1.clear();
Shinya Kitaoka 120a6e
      tmpPoints1.reserve(intensity);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      for (int i = 1; i < intensity - 1; i++) {
Shinya Kitaoka 120a6e
        pos1    = points[i - 1];
Shinya Kitaoka 120a6e
        oldPos1 = oldpoints[i - 1];
Shinya Kitaoka 120a6e
        tmpPoints1.push_back(oldPos1);
Shinya Kitaoka 120a6e
        tmpPoints1.push_back(pos1);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      data.push_back(tmpPoints1);
Shinya Kitaoka 120a6e
      if (increment > 1) {
Shinya Kitaoka 120a6e
        int count = tceil(step / increment + 1);
Shinya Kitaoka 120a6e
        Points tmpPoints2;
Shinya Kitaoka 120a6e
        tmpPoints2.clear();
Shinya Kitaoka 120a6e
        tmpPoints2.reserve(count);
Shinya Kitaoka 120a6e
        double startpoint = -step - increment / 2.0;
Shinya Kitaoka 120a6e
        for (int j = 1; j < step / increment + 1; j++) {
Shinya Kitaoka 120a6e
          tmpPoints2.push_back(points[0] -
Shinya Kitaoka 120a6e
                               v * border * increment * rnd.getFloat() +
Shinya Kitaoka 120a6e
                               u * (startpoint + j * (increment)));
Shinya Kitaoka 120a6e
          tmpPoints2.push_back(points[intensity - 3] +
Shinya Kitaoka 120a6e
                               v * border * increment * rnd.getFloat() +
Shinya Kitaoka 120a6e
                               u * (startpoint + j * (increment)));
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        data.push_back(tmpPoints2);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    oldpoints = points;
Shinya Kitaoka 120a6e
    points.clear();
Shinya Kitaoka 120a6e
    s += step;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TTissueStrokeStyle::drawStroke(const TColorFunction *cf, PointMatrix &data,
Shinya Kitaoka 120a6e
                                    const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = m_color;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tglColor(color);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  PointMatrix::iterator it1 = data.begin();
Shinya Kitaoka 120a6e
  for (; it1 != data.end(); ++it1) {
Shinya Kitaoka 120a6e
    glBegin(GL_LINES);
Shinya Kitaoka 120a6e
    Points::iterator it2 = (*it1).begin();
Shinya Kitaoka 120a6e
    for (; it2 != (*it1).end(); ++it2) {
Shinya Kitaoka 120a6e
      tglVertex(*it2);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TBiColorStrokeStyle::TBiColorStrokeStyle()
Shinya Kitaoka 120a6e
    : m_color0(TPixel32::Red), m_color1(TPixel32::Black) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TBiColorStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TBiColorStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBiColorStrokeStyle::loadData(TInputStreamInterface &is) {
Shinya Kitaoka 120a6e
  is >> m_color0 >> m_color1 >> m_parameter;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBiColorStrokeStyle::saveData(TOutputStreamInterface &os) const {
Shinya Kitaoka 120a6e
  os << m_color0 << m_color1 << m_parameter;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBiColorStrokeStyle::drawRegion(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                     const bool antiAliasing,
Shinya Kitaoka 120a6e
                                     TRegionOutline &boundary) const {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBiColorStrokeStyle::loadData(int ids, TInputStreamInterface &is) {
Shinya Kitaoka 120a6e
  if (ids != 115 && ids != 119)
Shinya Kitaoka 120a6e
    throw TException("Bicolor stroke style: unknown obsolete format");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  is >> m_color0 >> m_parameter;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_color1 = TPixel32::Black;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBiColorStrokeStyle::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                     TStrokeOutline *outline,
Shinya Kitaoka 120a6e
                                     const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  TPixel32 color0 = m_color0;
Shinya Kitaoka 120a6e
  TPixel32 color1 = m_color1;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (cf) {
Shinya Kitaoka 120a6e
    color0 = (*(cf))(m_color0);
Shinya Kitaoka 120a6e
    color1 = (*(cf))(m_color1);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    color0 = m_color0;
Shinya Kitaoka 120a6e
    color1 = m_color1;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  UINT i;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const std::vector<toutlinepoint> &v = outline->getArray();</toutlinepoint>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (v.empty()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // outline with antialiasing
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  tglColor(color0);
Shinya Kitaoka 120a6e
  for (i = 0; i < v.size(); i += 2) glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  tglColor(color1);
Shinya Kitaoka 120a6e
  for (i = 1; i < v.size(); i += 2) glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glBegin(GL_QUAD_STRIP);
Shinya Kitaoka 120a6e
  for (i = 0; i < v.size(); i += 2) {
Shinya Kitaoka 120a6e
    tglColor(color0);
Shinya Kitaoka 120a6e
    glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
    tglColor(color1);
Shinya Kitaoka 120a6e
    glVertex2dv(&v[i + 1].x);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNormal2StrokeStyle::TNormal2StrokeStyle()
Shinya Kitaoka 120a6e
    : m_color(TPixel32::Yellow)
Shinya Kitaoka 120a6e
    , m_lightx(45.0)
Shinya Kitaoka 120a6e
    , m_lighty(200.0)
Shinya Kitaoka 120a6e
    , m_shininess(50.0)
Shinya Kitaoka 120a6e
    , m_metal(0.5)
Shinya Kitaoka 120a6e
    , m_bend(1.0) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TNormal2StrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TNormal2StrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TNormal2StrokeStyle::getParamCount() const { return 5; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle::ParamType TNormal2StrokeStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TNormal2StrokeStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 5);
Shinya Kitaoka 120a6e
  QString value;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TNormal2StrokeStyle", "Light X Pos");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TNormal2StrokeStyle", "Light Y Pos");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TNormal2StrokeStyle", "Shininess");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TNormal2StrokeStyle", "Plastic");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TNormal2StrokeStyle", "Bump");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return value;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TNormal2StrokeStyle::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                        double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 5);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    min = -100.0;
Shinya Kitaoka 120a6e
    max = 100.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    min = -100.0;
Shinya Kitaoka 120a6e
    max = 100.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    min = 0.1;
Shinya Kitaoka 120a6e
    max = 128.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TNormal2StrokeStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                          int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 5);
Shinya Kitaoka 120a6e
  double value;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    value = m_lightx;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    value = m_lighty;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    value = m_shininess;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    value = m_metal;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    value = m_bend;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return value;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TNormal2StrokeStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 5);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    m_lightx = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    m_lighty = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    m_shininess = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    m_metal = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    m_bend = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  updateVersionNumber();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TNormal2StrokeStyle::loadData(int ids, TInputStreamInterface &is) {
Shinya Kitaoka 120a6e
  if (ids != 121)
Shinya Kitaoka 120a6e
    throw TException("Normal  stroke style: unknown obsolete format");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  is >> m_color >> m_lightx >> m_lighty >> m_shininess >> m_metal;
Shinya Kitaoka 120a6e
  m_bend = 1.0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TNormal2StrokeStyle::drawRegion(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                     const bool antiAliasing,
Shinya Kitaoka 120a6e
                                     TRegionOutline &boundary) const {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TNormal2StrokeStyle::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                     TStrokeOutline *outline,
Shinya Kitaoka 120a6e
                                     const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = m_color;
Shinya Kitaoka 120a6e
  TPixelD dcolor;
Shinya Kitaoka 120a6e
  dcolor = toPixelD(color);
Shinya Kitaoka 120a6e
  UINT i;
Shinya Kitaoka 120a6e
  double bend                         = 2 * m_bend;
Shinya Kitaoka 120a6e
  const std::vector<toutlinepoint> &v = outline->getArray();</toutlinepoint>
Shinya Kitaoka 120a6e
  if (v.empty()) return;
Shinya Kitaoka 120a6e
  vector<t3dpointd> normal;</t3dpointd>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  GLfloat light_position[] = {(float)(m_lightx), (float)(m_lighty), 100.0, 0.0};
Shinya Kitaoka 120a6e
  glLightfv(GL_LIGHT0, GL_POSITION, light_position);
Shinya Kitaoka 120a6e
  glEnable(GL_LIGHTING);
Shinya Kitaoka 120a6e
  glEnable(GL_LIGHT0);
Shinya Kitaoka 120a6e
  glEnable(GL_NORMALIZE);
Shinya Kitaoka 120a6e
  GLfloat mat_ambient[] = {(float)dcolor.r, (float)dcolor.g, (float)dcolor.b,
Shinya Kitaoka 120a6e
                           1.0};
Shinya Kitaoka 120a6e
  GLfloat mat_specular[] = {(float)(m_metal * (1 - dcolor.r) + dcolor.r),
Shinya Kitaoka 120a6e
                            (float)(m_metal * (1 - dcolor.g) + dcolor.g),
Shinya Kitaoka 120a6e
                            (float)(m_metal * (1 - dcolor.b) + dcolor.b), 1.0};
Shinya Kitaoka 120a6e
  GLfloat mat_shininess[] = {(float)m_shininess};
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
Shinya Kitaoka 120a6e
  glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
Shinya Kitaoka 120a6e
  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_ambient);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // outline with antialiasing
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  for (i = 0; i < v.size(); i += 2) {
Shinya Kitaoka 120a6e
    T3DPointD pointa(v[i].x, v[i].y, 0);
Shinya Kitaoka 120a6e
    T3DPointD pointb(v[i + 1].x, v[i + 1].y, 0);
Shinya Kitaoka 120a6e
    T3DPointD d           = pointb - pointa;
Shinya Kitaoka 120a6e
    if (norm2(d) > 0.0) d = normalize(d);
Shinya Kitaoka 120a6e
    normal.push_back(d);
Shinya Kitaoka 120a6e
    T3DPointD pointaNormal = T3DPointD(0, 0, 1) - bend * d;
Shinya Kitaoka 120a6e
    tglNormal(pointaNormal);
Shinya Kitaoka 120a6e
    tglVertex(pointa);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int normalcounter = 0;
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  for (i = 1; i < v.size(); i += 2) {
Shinya Kitaoka 120a6e
    T3DPointD pointa(v[i].x, v[i].y, 0);
Shinya Kitaoka 120a6e
    T3DPointD pointaNormal =
Shinya Kitaoka 120a6e
        T3DPointD(0, 0, 1) + bend * normal[normalcounter++];
Shinya Kitaoka 120a6e
    tglNormal(pointaNormal);
Shinya Kitaoka 120a6e
    tglVertex(pointa);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  normalcounter = 0;
Shinya Kitaoka 120a6e
  for (i = 0; i <= v.size() - 4; i += 2) {
Shinya Kitaoka 120a6e
    glBegin(GL_QUAD_STRIP);
Shinya Kitaoka 120a6e
    T3DPointD olda(v[i].x, v[i].y, 0);
Shinya Kitaoka 120a6e
    T3DPointD oldb(v[i + 1].x, v[i + 1].y, 0);
Shinya Kitaoka 120a6e
    T3DPointD oldcenter = 0.5 * (olda + oldb);
Shinya Kitaoka 120a6e
    T3DPointD oldcenterNormal(0, 0, 1);
Shinya Kitaoka 120a6e
    T3DPointD oldaNormal = T3DPointD(0, 0, 1) - bend * normal[normalcounter];
Shinya Kitaoka 120a6e
    T3DPointD oldbNormal = T3DPointD(0, 0, 1) + bend * normal[normalcounter];
Shinya Kitaoka 120a6e
    T3DPointD a(v[i + 2].x, v[i + 2].y, 0);
Shinya Kitaoka 120a6e
    T3DPointD b(v[i + 3].x, v[i + 3].y, 0);
Shinya Kitaoka 120a6e
    T3DPointD center = 0.5 * (a + b);
Shinya Kitaoka 120a6e
    T3DPointD centerNormal(0, 0, 1);
Shinya Kitaoka 120a6e
    T3DPointD aNormal = T3DPointD(0, 0, 1) - bend * normal[normalcounter++];
Shinya Kitaoka 120a6e
    T3DPointD bNormal = T3DPointD(0, 0, 1) + bend * normal[normalcounter];
Shinya Kitaoka 120a6e
    tglNormal(oldaNormal);
Shinya Kitaoka 120a6e
    tglVertex(olda);
Shinya Kitaoka 120a6e
    tglNormal(aNormal);
Shinya Kitaoka 120a6e
    tglVertex(a);
Shinya Kitaoka 120a6e
    tglNormal(oldcenterNormal);
Shinya Kitaoka 120a6e
    tglVertex(oldcenter);
Shinya Kitaoka 120a6e
    tglNormal(centerNormal);
Shinya Kitaoka 120a6e
    tglVertex(center);
Shinya Kitaoka 120a6e
    tglNormal(oldbNormal);
Shinya Kitaoka 120a6e
    tglVertex(oldb);
Shinya Kitaoka 120a6e
    tglNormal(bNormal);
Shinya Kitaoka 120a6e
    tglVertex(b);
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glDisable(GL_NORMALIZE);
Shinya Kitaoka 120a6e
  glDisable(GL_LIGHTING);
Shinya Kitaoka 120a6e
  glDisable(GL_LIGHT0);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
double get_inout_intensityslope(double in, double out, double t) {
Shinya Kitaoka 120a6e
  if (out < in) out = in;
Shinya Kitaoka 120a6e
  if (t < in)
Shinya Kitaoka 120a6e
    return t / in;
Shinya Kitaoka 120a6e
  else if (t > out)
Shinya Kitaoka 120a6e
    return (t - 1) / (out - 1);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return 1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TChalkStrokeStyle2::TChalkStrokeStyle2()
Shinya Kitaoka 120a6e
    : m_color(TPixel32::Black)
Shinya Kitaoka 120a6e
    , m_blend(1.0)
Shinya Kitaoka 120a6e
    , m_intensity(50.0)
Shinya Kitaoka 120a6e
    , m_in(0.25)
Shinya Kitaoka 120a6e
    , m_out(0.25)
Shinya Kitaoka 120a6e
    , m_noise(0.0) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle *TChalkStrokeStyle2::clone() const {
Shinya Kitaoka 120a6e
  return new TChalkStrokeStyle2(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TChalkStrokeStyle2::getParamCount() const { return 5; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle::ParamType TChalkStrokeStyle2::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TChalkStrokeStyle2::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 5);
Shinya Kitaoka 120a6e
  QString value;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TChalkStrokeStyle2", "Border Fade");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TChalkStrokeStyle2", "Density");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TChalkStrokeStyle2", "Fade In");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TChalkStrokeStyle2", "Fade Out");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TChalkStrokeStyle2", "Noise");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return value;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TChalkStrokeStyle2::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                       double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 5);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 100.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TChalkStrokeStyle2::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                         int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 5);
Shinya Kitaoka 120a6e
  double value = 0;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    value = m_blend;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    value = m_intensity;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    value = m_in;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    value = m_out;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    value = m_noise;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return value;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TChalkStrokeStyle2::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 5);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    m_blend = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    m_intensity = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    m_in = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    m_out = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    m_noise = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // updateVersionNumber(); non serve perche' i parametri vengono sfrutttati
Shinya Kitaoka 120a6e
  // direttamente nella draw
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TChalkStrokeStyle2::loadData(int ids, TInputStreamInterface &is) {
Shinya Kitaoka 120a6e
  if (ids != 105)
Shinya Kitaoka 120a6e
    throw TException("chalk stroke style: unknown obsolete format");
Shinya Kitaoka 120a6e
  m_in = 0.0, m_out = 0.0, m_noise = 0.0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  is >> m_color >> m_blend >> m_intensity;
Shinya Kitaoka 120a6e
  m_blend = 1 - m_blend;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TChalkStrokeStyle2::computeData(Doubles &data, const TStroke *stroke,
Shinya Kitaoka 120a6e
                                     const TColorFunction *cf) const {
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Shinya Kitaoka 120a6e
  double step   = 4;
Shinya Kitaoka 120a6e
  double s      = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  data.clear();
Shinya Kitaoka 120a6e
  data.reserve(tceil(length / step) * 6 + 6);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  while (s <= length) {
Shinya Kitaoka 120a6e
    double w = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    // if(w<0) {s+=0.1; continue;} // per tamponare il baco della
Shinya Kitaoka 120a6e
    // getParameterAtLength()
Shinya Kitaoka 120a6e
    TThickPoint pos = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
    TPointD u       = stroke->getSpeed(w);
Shinya Kitaoka 120a6e
    double normu    = norm2(u);
Shinya Kitaoka 120a6e
    if (normu == 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // non dovrebbe succedere mai, ma per prudenza....
Shinya Kitaoka 120a6e
    u = normalize(u);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    data.push_back(pos.x);
Shinya Kitaoka 120a6e
    data.push_back(pos.y);
Shinya Kitaoka 120a6e
    data.push_back(pos.thick);
Shinya Kitaoka 120a6e
    data.push_back(u.x);
Shinya Kitaoka 120a6e
    data.push_back(u.y);
Shinya Kitaoka 120a6e
    data.push_back(s / length);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    s += step;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TChalkStrokeStyle2::drawStroke(const TColorFunction *cf, Doubles &data,
Shinya Kitaoka 120a6e
                                    const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  double step = 4;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double blend = m_blend;  // distanza che controlla da dove il gessetto
Shinya Kitaoka 120a6e
                           // comincia il fade out  (0, 1)
Shinya Kitaoka 120a6e
  double intensitymax =
Shinya Kitaoka 120a6e
      m_intensity;  // quanti punti vengono disegnati ad ogni step
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRandom rnd;
Shinya Kitaoka 120a6e
  TRandom rnd_noise;
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = m_color;
Shinya Kitaoka 120a6e
  TPixelD dcolor;
Shinya Kitaoka 120a6e
  dcolor             = toPixelD(color);
Shinya Kitaoka 120a6e
  double mattedcolor = 0.5 * dcolor.m;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double noise      = 0;
Shinya Kitaoka 120a6e
  double noiseslope = 0;
Shinya Kitaoka 120a6e
  double tmpnoise   = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  GLuint chalkId;
Shinya Kitaoka 120a6e
  chalkId = glGenLists(1);
Shinya Kitaoka 120a6e
  glNewList(chalkId, GL_COMPILE);
Shinya Kitaoka 120a6e
  glBegin(GL_QUADS);
Shinya Kitaoka 120a6e
  glVertex2d(1, 1);
Shinya Kitaoka 120a6e
  glVertex2d(-1, 1);
Shinya Kitaoka 120a6e
  glVertex2d(-1, -1);
Shinya Kitaoka 120a6e
  glVertex2d(1, -1);
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  glEndList();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (UINT i = 0; i < data.size(); i += 6) {
Shinya Kitaoka 120a6e
    TThickPoint pos;
Shinya Kitaoka 120a6e
    pos.x     = data[i];
Shinya Kitaoka 120a6e
    pos.y     = data[i + 1];
Shinya Kitaoka 120a6e
    pos.thick = data[i + 2];
Shinya Kitaoka 120a6e
    TPointD u;
Shinya Kitaoka 120a6e
    u.x       = data[i + 3];
Shinya Kitaoka 120a6e
    u.y       = data[i + 4];
Shinya Kitaoka 120a6e
    TPointD v = rotate90(u);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TPointD shift;
Shinya Kitaoka 120a6e
    double intslope    = get_inout_intensityslope(m_in, 1 - m_out, data[i + 5]);
Shinya Kitaoka 120a6e
    double transpslope = (intslope / blend) * dcolor.m;
Shinya Kitaoka 120a6e
    if (m_noise) {
Shinya Kitaoka 120a6e
      if (tmpnoise <= 0) {
Shinya Kitaoka 120a6e
        noise    = (100 / m_noise) * rnd_noise.getFloat();
Shinya Kitaoka 120a6e
        tmpnoise = noise;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      noiseslope = get_inout_intensityslope(0.5, 0.5, tmpnoise / noise);
Shinya Kitaoka 120a6e
      tmpnoise -= step;
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      noiseslope = 1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    for (int i = 0; i < intensitymax * intslope * noiseslope; i++) {
Shinya Kitaoka 120a6e
      double vrandnorm = rnd.getFloat(-1.0, 1.0);
Shinya Kitaoka 120a6e
      double randomv   = vrandnorm * pos.thick * noiseslope;
Shinya Kitaoka 120a6e
      double randomu   = (0.5 - rnd.getFloat()) * step;
Shinya Kitaoka 120a6e
      shift            = pos + u * randomu + v * randomv;
Shinya Kitaoka 120a6e
      double mod       = fabs(vrandnorm);
Shinya Kitaoka 120a6e
      if (mod > 1 - blend)
Shinya Kitaoka 120a6e
        glColor4d(dcolor.r, dcolor.g, dcolor.b,
Shinya Kitaoka 120a6e
                  (double)rnd.getFloat() * ((1 - mod) * transpslope));
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        glColor4d(dcolor.r, dcolor.g, dcolor.b, mattedcolor);
Shinya Kitaoka 120a6e
      glPushMatrix();
Shinya Kitaoka 120a6e
      glTranslated(shift.x, shift.y, 0.0);
Shinya Kitaoka 120a6e
      glCallList(chalkId);
Shinya Kitaoka 120a6e
      glPopMatrix();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glDeleteLists(chalkId, 1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TBlendStrokeStyle2::TBlendStrokeStyle2()
Shinya Kitaoka 120a6e
    : m_color(TPixel32::Red), m_blend(1.0), m_in(0.25), m_out(0.25) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TBlendStrokeStyle2::clone() const {
Shinya Kitaoka 120a6e
  return new TBlendStrokeStyle2(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TBlendStrokeStyle2::getParamCount() const { return 3; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle::ParamType TBlendStrokeStyle2::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TBlendStrokeStyle2::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 3);
Shinya Kitaoka 120a6e
  QString value;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TBlendStrokeStyle2", "Border Fade");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TBlendStrokeStyle2", "Fade In");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TBlendStrokeStyle2", "Fade Out");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return value;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBlendStrokeStyle2::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                       double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 3);
Shinya Kitaoka 120a6e
  min = 0.0;
Shinya Kitaoka 120a6e
  max = 1.0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TBlendStrokeStyle2::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                         int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 3);
Shinya Kitaoka 120a6e
  double value = 0;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    value = m_blend;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    value = m_in;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    value = m_out;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return value;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBlendStrokeStyle2::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 3);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    m_blend = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    m_in = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    m_out = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  updateVersionNumber();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TBlendStrokeStyle2::loadData(int ids, TInputStreamInterface &is) {
Shinya Kitaoka 120a6e
  if (ids != 110)
Shinya Kitaoka 120a6e
    throw TException("Blend  stroke style: unknown obsolete format");
Shinya Kitaoka 120a6e
  m_in = 0.0, m_out = 0.0;
Shinya Kitaoka 120a6e
  is >> m_color >> m_blend;
Shinya Kitaoka 120a6e
  m_blend = 1 - m_blend;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TBlendStrokeStyle2::computeData(PointsAndDoubles &data,
Shinya Kitaoka 120a6e
                                     const TStroke *stroke,
Shinya Kitaoka 120a6e
                                     const TColorFunction *cf) const {
Shinya Kitaoka 120a6e
  data.clear();
Shinya Kitaoka 120a6e
  // TStroke *stroke = getStroke();
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Shinya Kitaoka 120a6e
  double step   = 10.0;
Shinya Kitaoka 120a6e
  TPointD pos1, pos2, pos3, pos4, oldPos1, oldPos2, oldPos3, oldPos4;
Shinya Kitaoka 120a6e
  double oldintslope;
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = m_color;
Shinya Kitaoka 120a6e
  TPixelD dcolor;
Shinya Kitaoka 38fd86
  dcolor           = toPixelD(color);
Shinya Kitaoka 38fd86
  bool firstRing   = true;
Shinya Kitaoka 38fd86
  double s         = 0;
Shinya Kitaoka 120a6e
  double maxfactor = 2 * m_blend / step;  // max definisce il numero di
Shinya Kitaoka 120a6e
                                          // intervalli in cui la regione viene
Shinya Kitaoka 120a6e
                                          // divisa
Shinya Kitaoka 120a6e
  // per evitare il problema del blend poco efficiente sui triangoli
Shinya Kitaoka 120a6e
  double minthickness = MINTHICK * sqrt(tglGetPixelSize2());
Shinya Kitaoka 120a6e
  double thickness    = 0;
Shinya Kitaoka 120a6e
  while (s <= length) {
Shinya Kitaoka 120a6e
    double w = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    if (w < 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // per tamponare il baco della getParameterAtLength()
Shinya Kitaoka 120a6e
    TThickPoint pos = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
    TPointD u       = stroke->getSpeed(w);
Shinya Kitaoka 120a6e
    if (norm2(u) == 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // non dovrebbe succedere mai, ma per prudenza....
Shinya Kitaoka 120a6e
    u = normalize(u);
Shinya Kitaoka 120a6e
    if (pos.thick < MINTHICK)
Shinya Kitaoka 120a6e
      thickness = minthickness;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      thickness = pos.thick;
Shinya Kitaoka 120a6e
    TPointD v   = rotate90(u) * thickness;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TPointD v1 = v * (1 - m_blend);
Shinya Kitaoka 120a6e
    pos1       = pos + v;
Shinya Kitaoka 120a6e
    pos2       = pos + v1;
Shinya Kitaoka 120a6e
    pos3       = pos - v1;
Shinya Kitaoka 120a6e
    pos4       = pos - v;
Shinya Kitaoka 120a6e
    double intslope =
Shinya Kitaoka 120a6e
        get_inout_intensityslope(m_in, 1 - m_out, s / length) * dcolor.m;
Shinya Kitaoka 120a6e
    if (firstRing) {
Shinya Kitaoka 120a6e
      firstRing = false;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      int max       = (int)(maxfactor * thickness);
Shinya Kitaoka 120a6e
      double invmax = 1.0 / max;
Shinya Kitaoka 120a6e
      data.push_back(make_pair(oldPos1, 0.0));
Shinya Kitaoka 120a6e
      data.push_back(make_pair(pos1, 0.0));
Shinya Kitaoka 120a6e
      int i;
Shinya Kitaoka 120a6e
      for (i = 1; i < max; i++) {
Shinya Kitaoka 120a6e
        data.push_back(make_pair(i * (oldPos2 - oldPos1) * invmax + oldPos1,
Shinya Kitaoka 120a6e
                                 (i * oldintslope) * invmax));
Shinya Kitaoka 120a6e
        data.push_back(make_pair(i * (pos2 - pos1) * invmax + pos1,
Shinya Kitaoka 120a6e
                                 (i * intslope) * invmax));
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      data.push_back(make_pair(oldPos2, oldintslope));
Shinya Kitaoka 120a6e
      data.push_back(make_pair(pos2, intslope));
Shinya Kitaoka 120a6e
      data.push_back(make_pair(oldPos3, oldintslope));
Shinya Kitaoka 120a6e
      data.push_back(make_pair(pos3, intslope));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      for (i = 0; i < max; i++) {
Shinya Kitaoka 120a6e
        data.push_back(make_pair(i * (oldPos4 - oldPos3) * invmax + oldPos3,
Shinya Kitaoka 120a6e
                                 (oldintslope * invmax) * (max - i)));
Shinya Kitaoka 120a6e
        data.push_back(make_pair(i * (pos4 - pos3) * invmax + pos3,
Shinya Kitaoka 120a6e
                                 (intslope * invmax) * (max - i)));
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      data.push_back(make_pair(oldPos4, 0.0));
Shinya Kitaoka 120a6e
      data.push_back(make_pair(pos4, 0.0));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    oldPos1     = pos1;
Shinya Kitaoka 120a6e
    oldPos2     = pos2;
Shinya Kitaoka 120a6e
    oldPos3     = pos3;
Shinya Kitaoka 120a6e
    oldPos4     = pos4;
Shinya Kitaoka 120a6e
    oldintslope = intslope;
Shinya Kitaoka 120a6e
    s += step;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TBlendStrokeStyle2::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                    PointsAndDoubles &data,
Shinya Kitaoka 120a6e
                                    const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = m_color;
Shinya Kitaoka 120a6e
  TPixelD dcolor;
Shinya Kitaoka 120a6e
  dcolor = toPixelD(color);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  PointsAndDoubles::iterator it = data.begin();
Shinya Kitaoka 120a6e
  glBegin(GL_QUAD_STRIP);
Shinya Kitaoka 120a6e
  for (; it != data.end(); ++it) {
Shinya Kitaoka 120a6e
    glColor4d(dcolor.r, dcolor.g, dcolor.b, it->second);
Shinya Kitaoka 120a6e
    tglVertex(it->first);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTwirlStrokeStyle::TTwirlStrokeStyle()
Shinya Kitaoka 120a6e
    : m_color(TPixel32::Green), m_period(30.0), m_blend(0.5) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle *TTwirlStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TTwirlStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TTwirlStrokeStyle::getParamCount() const { return 2; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle::ParamType TTwirlStrokeStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TTwirlStrokeStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  return index == 0 ? QCoreApplication::translate("TTwirlStrokeStyle", "Twirl")
Shinya Kitaoka 120a6e
                    : QCoreApplication::translate("TTwirlStrokeStyle", "Shade");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TTwirlStrokeStyle::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                      double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  if (index == 0) {
Shinya Kitaoka 120a6e
    min = 1.0;
Shinya Kitaoka 120a6e
    max = 100.0;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TTwirlStrokeStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                        int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  return index == 0 ? m_period : m_blend;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TTwirlStrokeStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  if (index == 0)
Shinya Kitaoka 120a6e
    m_period = value;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    m_blend = value;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  updateVersionNumber();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TTwirlStrokeStyle::computeData(Doubles &data, const TStroke *stroke,
Shinya Kitaoka 120a6e
                                    const TColorFunction *cf) const {
Shinya Kitaoka 120a6e
  double length   = stroke->getLength();
Shinya Kitaoka 120a6e
  double step     = 5.0;
Shinya Kitaoka 120a6e
  double period   = 10 * (102 - m_period);
Shinya Kitaoka 120a6e
  double hperiod  = period / 2;
Shinya Kitaoka 120a6e
  double blendval = 0;
Shinya Kitaoka 120a6e
  TRandom rnd;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  data.clear();
Shinya Kitaoka 120a6e
  data.reserve(tceil(length / step) + 1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double s = 0;
Shinya Kitaoka 120a6e
  TPointD app;
Shinya Kitaoka 120a6e
  while (s <= length) {
Shinya Kitaoka 120a6e
    double w = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    if (w < 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // per tamponare il baco della getParameterAtLength()
Shinya Kitaoka 120a6e
    TThickPoint pos = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
    TPointD u       = stroke->getSpeed(w);
Shinya Kitaoka 120a6e
    if (norm2(u) == 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // non dovrebbe succedere mai, ma per prudenza....
Shinya Kitaoka 120a6e
    u            = normalize(u);
Shinya Kitaoka 120a6e
    TPointD v    = rotate90(u) * (pos.thick);
Shinya Kitaoka 120a6e
    double shift = sin((M_PI / hperiod) * s);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    app = pos + v * shift;
Shinya Kitaoka 120a6e
    data.push_back(app.x);
Shinya Kitaoka 120a6e
    data.push_back(app.y);
Shinya Kitaoka 120a6e
    app = pos - v * shift;
Shinya Kitaoka 120a6e
    data.push_back(app.x);
Shinya Kitaoka 120a6e
    data.push_back(app.y);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    blendval = get_inout_intensityslope(
Shinya Kitaoka 120a6e
        m_blend, 1.0 - m_blend, (s - ((int)(s / hperiod) * hperiod)) / hperiod);
Shinya Kitaoka 120a6e
    data.push_back(blendval);
Shinya Kitaoka 120a6e
    s += step;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TTwirlStrokeStyle::drawStroke(const TColorFunction *cf, Doubles &data,
Shinya Kitaoka 120a6e
                                   const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  TPixel32 blackcolor = TPixel32::Black;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf) {
Shinya Kitaoka 120a6e
    color      = (*(cf))(m_color);
Shinya Kitaoka 120a6e
    blackcolor = (*(cf))(blackcolor);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    color = m_color;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  blackcolor.m = m_color.m;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPointD app;
Shinya Kitaoka 120a6e
  UINT i = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glBegin(GL_QUAD_STRIP);
Shinya Kitaoka 120a6e
  for (; i < data.size(); i += 5) {
Shinya Kitaoka 120a6e
    tglColor(blend(blackcolor, color, data[i + 4]));
Shinya Kitaoka 120a6e
    app.x = data[i];
Shinya Kitaoka 120a6e
    app.y = data[i + 1];
Shinya Kitaoka 120a6e
    tglVertex(app);
Shinya Kitaoka 120a6e
    app.x = data[i + 2];
Shinya Kitaoka 120a6e
    app.y = data[i + 3];
Shinya Kitaoka 120a6e
    tglVertex(app);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (i = 5; i < data.size(); i += 5) {
Shinya Kitaoka 120a6e
    tglColor(blend(color, blackcolor, data[i + 4]));
Shinya Kitaoka 120a6e
    glBegin(GL_LINES);
Shinya Kitaoka 120a6e
    app.x = data[i - 5];
Jeremy Bullock 175c6b
    app.y = data[i - 4];
Jeremy Bullock 175c6b
    tglVertex(app);
Jeremy Bullock 175c6b
    app.x = data[i];
Jeremy Bullock 175c6b
    app.y = data[i + 1];
Jeremy Bullock 175c6b
    tglVertex(app);
Jeremy Bullock 175c6b
    glEnd();
Jeremy Bullock 175c6b
    glBegin(GL_LINES);
Jeremy Bullock 175c6b
    app.x = data[i - 3];
Jeremy Bullock 175c6b
    app.y = data[i - 2];
Jeremy Bullock 175c6b
    tglVertex(app);
Jeremy Bullock 175c6b
    app.x = data[i + 2];
Jeremy Bullock 175c6b
    app.y = data[i + 3];
Jeremy Bullock 175c6b
    tglVertex(app);
Jeremy Bullock 175c6b
    glEnd();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TSawToothStrokeStyle::TSawToothStrokeStyle(TPixel32 color, double parameter)
Shinya Kitaoka 120a6e
    : m_color(color), m_parameter(parameter) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle *TSawToothStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TSawToothStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSawToothStrokeStyle::computeOutline(
Shinya Kitaoka 120a6e
    const TStroke *stroke, TStrokeOutline &outline,
Shinya Kitaoka 120a6e
    TOutlineUtil::OutlineParameter param) const {
Shinya Kitaoka 120a6e
  param.m_lengthStep = m_parameter;
Shinya Kitaoka 120a6e
  TOutlineStyle::computeOutline(stroke, outline, param);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSawToothStrokeStyle::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                      TStrokeOutline *outline,
Shinya Kitaoka 120a6e
                                      const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  UINT i;
Shinya Kitaoka 120a6e
  int counter = 0;
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = m_color;
Shinya Kitaoka 120a6e
  tglColor(color);
Shinya Kitaoka 120a6e
  const std::vector<toutlinepoint> &v = outline->getArray();</toutlinepoint>
Shinya Kitaoka 120a6e
  if (v.empty()) return;
Shinya Kitaoka 120a6e
  double old[2];
Shinya Kitaoka 120a6e
  // outline with antialiasing
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  for (i = 0; i < v.size() - 2; i += 2) {
Shinya Kitaoka 120a6e
    if (0 != v[i].stepCount) {
Shinya Kitaoka 120a6e
      if (counter) {
Shinya Kitaoka 120a6e
        glVertex2dv(old);
Shinya Kitaoka 120a6e
        glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
        glVertex2dv(&v[i + 1].x);
Shinya Kitaoka 120a6e
        glVertex2dv(old);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      old[0] = v[i].x;
Shinya Kitaoka 120a6e
      old[1] = v[i].y;
Shinya Kitaoka 120a6e
      counter++;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  counter = 0;
Shinya Kitaoka 120a6e
  glBegin(GL_TRIANGLES);
Shinya Kitaoka 120a6e
  for (i = 0; i < v.size() - 2; i += 2) {
Shinya Kitaoka 120a6e
    if (0 != v[i].stepCount) {
Shinya Kitaoka 120a6e
      if (counter) {
Shinya Kitaoka 120a6e
        glVertex2dv(old);
Shinya Kitaoka 120a6e
        glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
        glVertex2dv(&v[i + 1].x);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      old[0] = v[i].x;
Shinya Kitaoka 120a6e
      old[1] = v[i].y;
Shinya Kitaoka 120a6e
      counter++;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TSawToothStrokeStyle::getParamCount() const { return 1; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle::ParamType TSawToothStrokeStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TSawToothStrokeStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return QCoreApplication::translate("TSawToothStrokeStyle", "Distance");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSawToothStrokeStyle::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                         double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  min = 0.1;
Shinya Kitaoka 120a6e
  max = 100.0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TSawToothStrokeStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                           int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  return m_parameter;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSawToothStrokeStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  m_parameter = value;
Shinya Kitaoka 120a6e
  updateVersionNumber();  // questo si chiama per ogno cambiamento di parametro
Shinya Kitaoka 120a6e
                          // per cui di deve ricalcolare l'outline
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TMultiLineStrokeStyle2::TMultiLineStrokeStyle2()
Shinya Kitaoka 120a6e
    : m_color0(TPixel32(0, 255, 0))
Shinya Kitaoka 120a6e
    , m_color1(TPixel32(0, 0, 0))
Shinya Kitaoka 120a6e
    , m_intensity(0.2)
Shinya Kitaoka 120a6e
    , m_length(20.0)
Shinya Kitaoka 120a6e
    , m_thick(0.3)
Shinya Kitaoka 120a6e
    , m_noise(0.5) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TMultiLineStrokeStyle2::clone() const {
Shinya Kitaoka 120a6e
  return new TMultiLineStrokeStyle2(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef struct {
Shinya Kitaoka 120a6e
  TPointD u, v;
Shinya Kitaoka 120a6e
  TThickPoint p;
Toshihiro Shimizu 890ddd
} myLineData;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TMultiLineStrokeStyle2::getParamCount() const { return 4; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle::ParamType TMultiLineStrokeStyle2::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TMultiLineStrokeStyle2::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 4);
Shinya Kitaoka 120a6e
  QString value;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TMultiLineStrokeStyle2", "Density");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TMultiLineStrokeStyle2", "Size");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TMultiLineStrokeStyle2", "Thickness");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TMultiLineStrokeStyle2", "Noise");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return value;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TMultiLineStrokeStyle2::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                           double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 4);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 100.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
double TMultiLineStrokeStyle2::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                             int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 4);
Shinya Kitaoka 120a6e
  double value = 0;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    value = m_intensity;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    value = m_length;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    value = m_thick;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    value = m_noise;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return value;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TMultiLineStrokeStyle2::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 4);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    m_intensity = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    m_length = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    m_thick = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    m_noise = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  updateVersionNumber();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TMultiLineStrokeStyle2::loadData(int ids, TInputStreamInterface &is) {
Shinya Kitaoka 120a6e
  if (ids != 118 && ids != 128)
Shinya Kitaoka 120a6e
    throw TException("Multi Line stroke style: unknown obsolete format");
Shinya Kitaoka 120a6e
  if (ids == 118) {
Shinya Kitaoka 120a6e
    m_length = 20.0, m_thick = 0.3, m_noise = 0.0;
Shinya Kitaoka 120a6e
    is >> m_color0 >> m_intensity;
Shinya Kitaoka 120a6e
    m_color1 = TPixel32::Black;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    is >> m_color0 >> m_intensity >> m_length >> m_thick >> m_noise;
Shinya Kitaoka 120a6e
    m_color1 = TPixel32::Black;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TMultiLineStrokeStyle2::computeData(BlendAndPoints &data,
Shinya Kitaoka 120a6e
                                         const TStroke *stroke,
Shinya Kitaoka 120a6e
                                         const TColorFunction *cf) const {
Shinya Kitaoka 120a6e
  // TStroke *stroke = getStroke();
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Shinya Kitaoka 120a6e
  double step   = 4.0;
Shinya Kitaoka 120a6e
  int maxlength = (int)m_length;
Shinya Kitaoka 120a6e
  double factor = 0;
Shinya Kitaoka 120a6e
  TRandom rnd;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  vector<mylinedata> LineData;</mylinedata>
Shinya Kitaoka 120a6e
  myLineData Data;
Shinya Kitaoka 120a6e
  double s = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double minthickness = MINTHICK * sqrt(tglGetPixelSize2());
Shinya Kitaoka 120a6e
  double thickness    = 0;
Shinya Kitaoka 120a6e
  double strokethick  = m_thick;
Shinya Kitaoka 120a6e
  while (s <= length) {
Shinya Kitaoka 120a6e
    double w = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    if (w < 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // per tamponare il baco della getParameterAtLength()
Shinya Kitaoka 120a6e
    Data.p = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
    Data.u = stroke->getSpeed(w);
Shinya Kitaoka 120a6e
    if (norm2(Data.u) == 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // non dovrebbe succedere mai, ma per prudenza....
Shinya Kitaoka 120a6e
    Data.u = normalize(Data.u);
Shinya Kitaoka 120a6e
    if (Data.p.thick < MINTHICK)
Shinya Kitaoka 120a6e
      thickness = minthickness;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      thickness = Data.p.thick;
Shinya Kitaoka 120a6e
    Data.v      = rotate90(Data.u) * thickness;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    LineData.push_back(Data);
Shinya Kitaoka 120a6e
    s += step;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  BlendAndPoint appData;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  data.clear();
Shinya Kitaoka 120a6e
  data.reserve(LineData.size());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int i = 0; i < m_intensity * LineData.size(); i++) {
Shinya Kitaoka 120a6e
    appData.points.clear();
Shinya Kitaoka 120a6e
    int start = rnd.getInt(0, LineData.size());
Shinya Kitaoka 120a6e
    int end   = start + maxlength + rnd.getInt(0, maxlength);
Shinya Kitaoka 120a6e
    if (end > (int)LineData.size()) end = LineData.size();
Shinya Kitaoka 120a6e
    double halfcount                    = (end - start) / 2.0;
Shinya Kitaoka 120a6e
    double vshift                       = (0.5 - rnd.getFloat());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    appData.blend = rnd.getFloat();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    for (int j = 0; j < (end - start); j++) {
Shinya Kitaoka 120a6e
      if (j < halfcount)
Shinya Kitaoka 120a6e
        factor = j / halfcount;
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        factor = 1 - (j - halfcount) / halfcount;
Shinya Kitaoka 120a6e
      appData.points.push_back(
Shinya Kitaoka 120a6e
          LineData[j + start].p +
Shinya Kitaoka 120a6e
          LineData[j + start].v *
Shinya Kitaoka 120a6e
              (vshift -
Shinya Kitaoka 120a6e
               strokethick * factor * (1 - m_noise * (1 - rnd.getFloat()))));
Shinya Kitaoka 120a6e
      appData.points.push_back(
Shinya Kitaoka 120a6e
          LineData[j + start].p +
Shinya Kitaoka 120a6e
          LineData[j + start].v *
Shinya Kitaoka 120a6e
              (vshift +
Shinya Kitaoka 120a6e
               strokethick * factor * (1 - m_noise * (1 - rnd.getFloat()))));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    data.push_back(appData);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TMultiLineStrokeStyle2::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                        BlendAndPoints &data,
Shinya Kitaoka 120a6e
                                        const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  TPixel32 color0, color1;
Shinya Kitaoka 120a6e
  if (cf) {
Shinya Kitaoka 120a6e
    color0 = (*(cf))(m_color0);
Shinya Kitaoka 120a6e
    color1 = (*(cf))(m_color1);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    color0 = m_color0;
Shinya Kitaoka 120a6e
    color1 = m_color1;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glEnable(GL_POLYGON_SMOOTH);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (UINT i = 0; i < data.size(); i++) {
Shinya Kitaoka 120a6e
    tglColor(blend(color0, color1, data[i].blend));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    glBegin(GL_QUAD_STRIP);
Shinya Kitaoka 120a6e
    for (UINT j = 0; j < data[i].points.size(); j++)
Shinya Kitaoka 120a6e
      tglVertex(data[i].points[j]);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glDisable(GL_POLYGON_SMOOTH);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TZigzagStrokeStyle::TZigzagStrokeStyle()
Shinya Kitaoka 120a6e
    : m_color(TPixel32(0, 0, 0))
Shinya Kitaoka 120a6e
    , m_minDist(0.5)
Shinya Kitaoka 120a6e
    , m_maxDist(6.0)
Shinya Kitaoka 120a6e
    , m_minAngle(30.0)
Shinya Kitaoka 120a6e
    , m_maxAngle(60.0)
Shinya Kitaoka 120a6e
    , m_thickness(1.0) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle *TZigzagStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TZigzagStrokeStyle(*this);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
int TZigzagStrokeStyle::getParamCount() const { return 5; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle::ParamType TZigzagStrokeStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
QString TZigzagStrokeStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 5);
Shinya Kitaoka 120a6e
  QString value;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TZigzagStrokeStyle", "Min Distance");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TZigzagStrokeStyle", "Max Distance");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TZigzagStrokeStyle", "Min Angle");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TZigzagStrokeStyle", "Max Angle");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    value = QCoreApplication::translate("TZigzagStrokeStyle", "Thickness");
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return value;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TZigzagStrokeStyle::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                       double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 5);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    min = 0.5;
Shinya Kitaoka 120a6e
    max = 50.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    min = 0.5;
Shinya Kitaoka 120a6e
    max = 50.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    min = -90.0;
Shinya Kitaoka 120a6e
    max = 90.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    min = -90.0;
Shinya Kitaoka 120a6e
    max = 90.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 3.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TZigzagStrokeStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                         int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 5);
Shinya Kitaoka 120a6e
  double value = 0;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    value = m_minDist;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    value = m_maxDist;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    value = m_minAngle;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    value = m_maxAngle;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    value = m_thickness;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return value;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TZigzagStrokeStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 5);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    m_minDist = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    m_maxDist = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    m_minAngle = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    m_maxAngle = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    m_thickness = value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  updateVersionNumber();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TZigzagStrokeStyle::getZigZagPosition(const TStroke *stroke, TRandom &rnd,
Shinya Kitaoka 120a6e
                                           const double s, const int first,
Shinya Kitaoka 120a6e
                                           const double minTranslLength,
Shinya Kitaoka 120a6e
                                           TThickPoint &pos,
Shinya Kitaoka 120a6e
                                           TThickPoint &pos1) const {
Shinya Kitaoka 120a6e
  double w  = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
  pos       = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
  TPointD u = stroke->getSpeed(w);
Shinya Kitaoka 120a6e
  if (norm2(u) < TConsts::epsilon) return false;
Shinya Kitaoka 120a6e
  u          = normalize(u);
Shinya Kitaoka 120a6e
  TPointD uu = u;
Shinya Kitaoka 120a6e
  double angle =
Shinya Kitaoka 120a6e
      m_minAngle + (m_maxAngle - m_minAngle) * (double)rnd.getUInt(101) * 0.01;
Shinya Kitaoka 120a6e
  TRotation rotM(angle);
Shinya Kitaoka 120a6e
  u                      = rotM * u;
Shinya Kitaoka 120a6e
  double maxTranslLength = angle == 90 ? 1.0 : 2.0;
Shinya Kitaoka 120a6e
  if (angle > 30 && angle < 90) {
Shinya Kitaoka 120a6e
    double rta      = 1.0 / tan(degree2rad(angle));
Shinya Kitaoka 120a6e
    maxTranslLength = sqrt(sq(rta) + 1.0);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  double r =
Shinya Kitaoka 120a6e
      (minTranslLength + (maxTranslLength - minTranslLength) * rnd.getFloat()) *
Shinya Kitaoka 120a6e
      pos.thick * first;
Shinya Kitaoka 120a6e
  pos  = pos + r * u;
Shinya Kitaoka 120a6e
  pos1 = pos + uu * m_thickness;
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TZigzagStrokeStyle::setRealMinMax() const {
Shinya Kitaoka 120a6e
  TZigzagStrokeStyle *ncpthis = const_cast<tzigzagstrokestyle *="">(this);</tzigzagstrokestyle>
Shinya Kitaoka 120a6e
  double minDist              = std::min(m_minDist, m_maxDist);
Shinya Kitaoka 120a6e
  double maxDist              = std::max(m_minDist, m_maxDist);
Shinya Kitaoka 120a6e
  double minAngle             = std::min(m_minAngle, m_maxAngle);
Shinya Kitaoka 120a6e
  double maxAngle             = std::max(m_minAngle, m_maxAngle);
Shinya Kitaoka 120a6e
  ncpthis->m_minDist          = minDist;
Shinya Kitaoka 120a6e
  ncpthis->m_maxDist          = maxDist;
Shinya Kitaoka 120a6e
  ncpthis->m_minAngle         = minAngle;
Shinya Kitaoka 120a6e
  ncpthis->m_maxAngle         = maxAngle;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TZigzagStrokeStyle::computeData(Points &points, const TStroke *stroke,
Shinya Kitaoka 120a6e
                                     const TColorFunction *cf) const {
Shinya Kitaoka 120a6e
  assert(glGetError() == GL_NO_ERROR);
Shinya Kitaoka 120a6e
  assert(!!stroke);
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Shinya Kitaoka 120a6e
  if (length <= 0) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setRealMinMax();
Shinya Kitaoka 120a6e
  // e.g minimum translation length is the half of the thickness
Shinya Kitaoka 120a6e
  const double minTranslLength = 0.7;
Shinya Kitaoka 120a6e
  // const bool isTransparent=m_color.m<255;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int first = 1;
Shinya Kitaoka 120a6e
  TThickPoint pos;
Shinya Kitaoka 120a6e
  TThickPoint pos1;
Shinya Kitaoka 120a6e
  TRandom rnd;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  points.clear();
Shinya Kitaoka 120a6e
  points.reserve(tceil(length / m_minDist) * 2 + 2);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (double s = 0.0; s <= length; first = -first) {
Shinya Kitaoka 120a6e
    if (getZigZagPosition(stroke, rnd, s, first, minTranslLength, pos, pos1)) {
Shinya Kitaoka 120a6e
      // TRectD rec(pos.x,pos.y,pos1.x,pos1.y);
Shinya Kitaoka 120a6e
      points.push_back(pos);
Shinya Kitaoka 120a6e
      points.push_back(pos1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    s += m_minDist + (m_maxDist - m_minDist) * (double)rnd.getUInt(101) * 0.01;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (getZigZagPosition(stroke, rnd, length - TConsts::epsilon, first,
Shinya Kitaoka 120a6e
                        minTranslLength, pos, pos1)) {
Shinya Kitaoka 120a6e
    points.push_back(pos);
Shinya Kitaoka 120a6e
    points.push_back(pos1);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TZigzagStrokeStyle::drawStroke(const TColorFunction *cf, Points &points,
Shinya Kitaoka 120a6e
                                    const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  if (points.size() <= 1) return;
Shinya Kitaoka 120a6e
  TPixel32 color;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = m_color;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tglColor(m_color);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glEnableClientState(GL_VERTEX_ARRAY);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glVertexPointer(2, GL_DOUBLE, sizeof(TPointD), &points[0]);
Shinya Kitaoka 120a6e
  glDrawArrays(GL_QUAD_STRIP, 0, points.size());
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
glBegin(GL_QUAD_STRIP);
Shinya Kitaoka 120a6e
for(UINT i=0; i
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
tglVertex(rects[i].getP00());
Shinya Kitaoka 120a6e
tglVertex(rects[i].getP11());
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
glEnd();
Shinya Kitaoka 120a6e
*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glVertexPointer(2, GL_DOUBLE, sizeof(TPointD) * 2, &points[0]);
Shinya Kitaoka 120a6e
  glDrawArrays(GL_LINE_STRIP, 0, points.size() / 2);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glVertexPointer(2, GL_DOUBLE, sizeof(TPointD) * 2, &points[1]);
Shinya Kitaoka 120a6e
  glDrawArrays(GL_LINE_STRIP, 0, points.size() / 2);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glVertexPointer(2, GL_DOUBLE, sizeof(TPointD), &points[0]);
Shinya Kitaoka 120a6e
  glDrawArrays(GL_LINES, 0, points.size());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glDisableClientState(GL_VERTEX_ARRAY);
Shinya Kitaoka 120a6e
  // drawBLines(rects);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TSinStrokeStyle::TSinStrokeStyle()
Shinya Kitaoka 120a6e
    : m_color(TPixel32::Black), m_frequency(10.0), m_thick(0.4) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle *TSinStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TSinStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TSinStrokeStyle::getParamCount() const { return 2; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle::ParamType TSinStrokeStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TSinStrokeStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  return index == 0
Shinya Kitaoka 120a6e
             ? QCoreApplication::translate("TSinStrokeStyle", "Frequency")
Shinya Kitaoka 120a6e
             : QCoreApplication::translate("TZigzTSinStrokeStyleagStrokeStyle",
Shinya Kitaoka 120a6e
                                           "Thickness");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSinStrokeStyle::getParamRange(int index, double &min, double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  if (index == 0) {
Shinya Kitaoka 120a6e
    min = 1.0;
Shinya Kitaoka 120a6e
    max = 20.0;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TSinStrokeStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                      int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  return index == 0 ? m_frequency : m_thick;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSinStrokeStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  if (index == 0)
Shinya Kitaoka 120a6e
    m_frequency = value;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    m_thick = value;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  updateVersionNumber();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSinStrokeStyle::computeData(Points &positions, const TStroke *stroke,
Shinya Kitaoka 120a6e
                                  const TColorFunction *cf) const {
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Shinya Kitaoka 120a6e
  double step   = 5.0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  positions.clear();
Shinya Kitaoka 120a6e
  positions.reserve(tceil((length + 1) / step));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double frequency = m_frequency / 100;
Shinya Kitaoka 120a6e
  ;
Shinya Kitaoka 120a6e
  double s = 0;
Shinya Kitaoka 120a6e
  // bool firstRing = true;
Shinya Kitaoka 120a6e
  double thick = 1 - m_thick;
Shinya Kitaoka 120a6e
  while (s <= length) {
Shinya Kitaoka 120a6e
    double w = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    // if(w<0) {s+=0.1; continue;} // per tamponare il baco della
Shinya Kitaoka 120a6e
    // getParameterAtLength()
Shinya Kitaoka 120a6e
    TThickPoint pos = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
    TPointD u       = stroke->getSpeed(w);
Shinya Kitaoka 120a6e
    double normu    = norm2(u);
Shinya Kitaoka 120a6e
    if (normu == 0) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }  // non dovrebbe succedere mai, ma per prudenza....
Shinya Kitaoka 120a6e
    u               = normalize(u);
Shinya Kitaoka 120a6e
    TPointD v       = rotate90(u);
Shinya Kitaoka 120a6e
    double sinvalue = sin(frequency * s);
Shinya Kitaoka 120a6e
    positions.push_back(pos + v * pos.thick * sinvalue);
Shinya Kitaoka 120a6e
    positions.push_back(pos + v * thick * pos.thick * sinvalue);
Shinya Kitaoka 120a6e
    s += step;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSinStrokeStyle::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                 std::vector<tpointd> &positions,</tpointd>
Shinya Kitaoka 120a6e
                                 const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = m_color;
Shinya Kitaoka 120a6e
  tglColor(color);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glBegin(GL_QUAD_STRIP);
Shinya Kitaoka 120a6e
  int i = 0;
Shinya Kitaoka 120a6e
  for (; i < (int)positions.size(); i += 2) {
Shinya Kitaoka 120a6e
    tglVertex(positions[i]);
Shinya Kitaoka 120a6e
    tglVertex(positions[i + 1]);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  for (i = 0; i < (int)positions.size(); i += 2) {
Shinya Kitaoka 120a6e
    tglVertex(positions[i]);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  for (i = 1; i < (int)positions.size() - 1; i += 2) {
Shinya Kitaoka 120a6e
    tglVertex(positions[i]);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFriezeStrokeStyle2::TFriezeStrokeStyle2()
Shinya Kitaoka 120a6e
    : m_color(TPixel32::Black), m_parameter(0.7), m_thick(0.3) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle *TFriezeStrokeStyle2::clone() const {
Shinya Kitaoka 120a6e
  return new TFriezeStrokeStyle2(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TFriezeStrokeStyle2::getParamCount() const { return 2; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle::ParamType TFriezeStrokeStyle2::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TFriezeStrokeStyle2::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  if (index == 0)
Shinya Kitaoka 120a6e
    return QCoreApplication::translate("TFriezeStrokeStyle2", "Twirl");
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return QCoreApplication::translate("TFriezeStrokeStyle2", "Thickness");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFriezeStrokeStyle2::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                        double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  if (index == 0) {
Shinya Kitaoka 120a6e
    min = -1.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TFriezeStrokeStyle2::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                          int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  if (index == 0)
Shinya Kitaoka 120a6e
    return m_parameter;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return m_thick;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFriezeStrokeStyle2::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  if (index == 0)
Shinya Kitaoka 120a6e
    m_parameter = value;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    m_thick = value;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  updateVersionNumber();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFriezeStrokeStyle2::loadData(int ids, TInputStreamInterface &is) {
Shinya Kitaoka 120a6e
  if (ids != 102)
Shinya Kitaoka 120a6e
    throw TException("Frieze  stroke style: unknown obsolete format");
Shinya Kitaoka 120a6e
  m_thick = 0.0;
Shinya Kitaoka 120a6e
  is >> m_color >> m_parameter;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFriezeStrokeStyle2::computeData(Points &positions, const TStroke *stroke,
Shinya Kitaoka 120a6e
                                      const TColorFunction *cf) const {
Shinya Kitaoka 120a6e
  // TStroke *stroke = getStroke();
Shinya Kitaoka 120a6e
  double length = stroke->getLength();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double ds = 0.5;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  positions.clear();
Shinya Kitaoka 120a6e
  positions.reserve(tceil((length + 1) / ds));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double s     = 0.01;
Shinya Kitaoka 120a6e
  double lastS = 0;
Shinya Kitaoka 120a6e
  double phi   = 0;
Shinya Kitaoka 120a6e
  double lastW = 0;
Shinya Kitaoka 120a6e
  double thick = 1 - m_thick;
Shinya Kitaoka 120a6e
  vector<tpointd> points;</tpointd>
Shinya Kitaoka 120a6e
  while (s <= length) {
Shinya Kitaoka 120a6e
    double w = stroke->getParameterAtLength(s);
Shinya Kitaoka 120a6e
    if (w < lastW) {
Shinya Kitaoka 120a6e
      s += 0.1;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    lastW           = w;
Shinya Kitaoka 120a6e
    TThickPoint pos = stroke->getThickPoint(w);
Shinya Kitaoka 120a6e
    TPointD u       = normalize(stroke->getSpeed(w));
Shinya Kitaoka 120a6e
    TPointD v       = rotate90(u);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    double thickness = pos.thick;  // 5; //(1-t)*40 + t * 10;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (thickness > 0) {
Shinya Kitaoka 120a6e
      double omega = M_PI / thickness;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      double q        = 0.5 * (1 - cos(phi));
Shinya Kitaoka 120a6e
      double theta    = M_PI_2 - M_PI * m_parameter * q;
Shinya Kitaoka 120a6e
      double r        = thickness * sin(phi);
Shinya Kitaoka 120a6e
      double r1       = r * thick;
Shinya Kitaoka 120a6e
      double costheta = cos(theta);
Shinya Kitaoka 120a6e
      double sintheta = sin(theta);
Shinya Kitaoka 120a6e
      positions.push_back(pos + u * (r * costheta) + v * (r * sintheta));
Shinya Kitaoka 120a6e
      positions.push_back(pos + u * (r1 * costheta) + v * (r1 * sintheta));
Shinya Kitaoka 120a6e
      phi += (s - lastS) * omega;
Shinya Kitaoka 120a6e
      lastS = s;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      positions.push_back(pos);
Shinya Kitaoka 120a6e
      positions.push_back(pos);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    s += ds;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFriezeStrokeStyle2::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                     Points &positions,
Shinya Kitaoka 120a6e
                                     const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(m_color);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = m_color;
Shinya Kitaoka 120a6e
  tglColor(color);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glBegin(GL_QUAD_STRIP);
Shinya Kitaoka 120a6e
  int i = 0;
Shinya Kitaoka 120a6e
  for (; i < (int)positions.size(); i += 2) {
Shinya Kitaoka 120a6e
    tglVertex(positions[i]);
Shinya Kitaoka 120a6e
    tglVertex(positions[i + 1]);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  for (i = 0; i < (int)positions.size(); i += 2) {
Shinya Kitaoka 120a6e
    tglVertex(positions[i]);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  for (i = 1; i < (int)positions.size() - 1; i += 2) {
Shinya Kitaoka 120a6e
    tglVertex(positions[i]);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TDualColorStrokeStyle2::TDualColorStrokeStyle2(TPixel32 color0, TPixel32 color1,
Shinya Kitaoka 120a6e
                                               double parameter)
Shinya Kitaoka 120a6e
    : m_color0(color0), m_color1(color1), m_parameter(parameter) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TDualColorStrokeStyle2::clone() const {
Shinya Kitaoka 120a6e
  return new TDualColorStrokeStyle2(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TDualColorStrokeStyle2::computeOutline(
Shinya Kitaoka 120a6e
    const TStroke *stroke, TStrokeOutline &outline,
Shinya Kitaoka 120a6e
    TOutlineUtil::OutlineParameter param) const {
Shinya Kitaoka 120a6e
  param.m_lengthStep = m_parameter;
Shinya Kitaoka 120a6e
  TOutlineStyle::computeOutline(stroke, outline, param);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TDualColorStrokeStyle2::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                        TStrokeOutline *outline,
Shinya Kitaoka 120a6e
                                        const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  UINT i;
Shinya Kitaoka 120a6e
  const std::vector<toutlinepoint> &v = outline->getArray();</toutlinepoint>
Shinya Kitaoka 120a6e
  TPixel32 colorv[2];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (cf) {
Shinya Kitaoka 120a6e
    colorv[0] = (*(cf))(m_color0);
Shinya Kitaoka 120a6e
    colorv[1] = (*(cf))(m_color1);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    colorv[0] = m_color0;
Shinya Kitaoka 120a6e
    colorv[1] = m_color1;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  int colorindex = 0;
Shinya Kitaoka 120a6e
  if (v.empty()) return;
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  tglColor(colorv[0]);
Shinya Kitaoka 120a6e
  for (i = 0; i < v.size(); i += 2) {
Shinya Kitaoka 120a6e
    glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
    if (0 != v[i].stepCount) {
Shinya Kitaoka 120a6e
      colorindex++;
Shinya Kitaoka 120a6e
      tglColor(colorv[colorindex & 1]);
Shinya Kitaoka 120a6e
      glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  colorindex = 0;
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  tglColor(colorv[0]);
Shinya Kitaoka 120a6e
  for (i = 1; i < v.size(); i += 2) {
Shinya Kitaoka 120a6e
    glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
    if (0 != v[i].stepCount) {
Shinya Kitaoka 120a6e
      colorindex++;
Shinya Kitaoka 120a6e
      tglColor(colorv[colorindex & 1]);
Shinya Kitaoka 120a6e
      glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  colorindex = 0;
Shinya Kitaoka 120a6e
  glBegin(GL_QUAD_STRIP);
Shinya Kitaoka 120a6e
  tglColor(colorv[0]);
Shinya Kitaoka 120a6e
  for (i = 0; i < v.size(); i += 2) {
Shinya Kitaoka 120a6e
    glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
    glVertex2dv(&v[i + 1].x);
Shinya Kitaoka 120a6e
    if (0 != v[i].stepCount) {
Shinya Kitaoka 120a6e
      colorindex++;
Shinya Kitaoka 120a6e
      tglColor(colorv[colorindex & 1]);
Shinya Kitaoka 120a6e
      glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
      glVertex2dv(&v[i + 1].x);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // antialias delle linee normali
Shinya Kitaoka 120a6e
  tglColor(colorv[0]);
Shinya Kitaoka 120a6e
  for (i = 0; i < v.size(); i += 2) {
Shinya Kitaoka 120a6e
    if (0 != v[i].stepCount) {
Shinya Kitaoka 120a6e
      glBegin(GL_LINES);
Shinya Kitaoka 120a6e
      glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
      glVertex2dv(&v[i + 1].x);
Shinya Kitaoka 120a6e
      glEnd();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TDualColorStrokeStyle2::getParamCount() const { return 1; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle::ParamType TDualColorStrokeStyle2::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TDualColorStrokeStyle2::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return QCoreApplication::translate("TDualColorStrokeStyle2", "Distance");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TDualColorStrokeStyle2::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                           double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  min = 1.0;
Shinya Kitaoka 120a6e
  max = 100.0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TDualColorStrokeStyle2::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                             int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  return m_parameter;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TDualColorStrokeStyle2::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  m_parameter = value;
Shinya Kitaoka 120a6e
  updateVersionNumber();  // questo si chiama per ogno cambiamento di parametro
Shinya Kitaoka 120a6e
                          // per cui di deve ricalcolare l'outline
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TLongBlendStrokeStyle2::TLongBlendStrokeStyle2(TPixel32 color0, TPixel32 color1,
Shinya Kitaoka 120a6e
                                               double parameter)
Shinya Kitaoka 120a6e
    : m_color0(color0), m_color1(color1), m_parameter(parameter) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle *TLongBlendStrokeStyle2::clone() const {
Shinya Kitaoka 120a6e
  return new TLongBlendStrokeStyle2(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TLongBlendStrokeStyle2::computeOutline(
Shinya Kitaoka 120a6e
    const TStroke *stroke, TStrokeOutline &outline,
Shinya Kitaoka 120a6e
    TOutlineUtil::OutlineParameter param) const {
Shinya Kitaoka 120a6e
  param.m_lengthStep = m_parameter;
Shinya Kitaoka 120a6e
  TOutlineStyle::computeOutline(stroke, outline, param);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TLongBlendStrokeStyle2::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                        TStrokeOutline *outline,
Shinya Kitaoka 120a6e
                                        const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  TPixel32 color0, color1;
Shinya Kitaoka 120a6e
  if (cf) {
Shinya Kitaoka 120a6e
    color0 = (*(cf))(m_color0);
Shinya Kitaoka 120a6e
    color1 = (*(cf))(m_color1);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    color0 = m_color0;
Shinya Kitaoka 120a6e
    color1 = m_color1;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  UINT i;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  const std::vector<toutlinepoint> &v = outline->getArray();</toutlinepoint>
Shinya Kitaoka 120a6e
  if (v.empty()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // outline with antialiasing
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  int mystepCount = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double totallength = stroke->getLength();
Shinya Kitaoka 120a6e
  double ntick       = totallength / m_parameter + 1;
Shinya Kitaoka 120a6e
  tglColor(color0);
Shinya Kitaoka 120a6e
  for (i = 0; i < v.size(); i += 2) {
Shinya Kitaoka 120a6e
    if (0 != v[i].stepCount) {
Shinya Kitaoka 120a6e
      tglColor(blend(color0, color1, (double)mystepCount / ntick));
Shinya Kitaoka 120a6e
      mystepCount++;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  mystepCount = 0;
Shinya Kitaoka 120a6e
  tglColor(color0);
Shinya Kitaoka 120a6e
  for (i = 1; i < v.size(); i += 2) {
Shinya Kitaoka 120a6e
    if (0 != v[i].stepCount) {
Shinya Kitaoka 120a6e
      tglColor(blend(color0, color1, (double)mystepCount / ntick));
Shinya Kitaoka 120a6e
      mystepCount++;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glBegin(GL_QUAD_STRIP);
Shinya Kitaoka 120a6e
  mystepCount = 0;
Shinya Kitaoka 120a6e
  tglColor(color0);
Shinya Kitaoka 120a6e
  for (i = 0; i < v.size(); i += 2) {
Shinya Kitaoka 120a6e
    if (0 != v[i].stepCount) {
Shinya Kitaoka 120a6e
      tglColor(blend(color0, color1, (double)mystepCount / ntick));
Shinya Kitaoka 120a6e
      mystepCount++;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
    glVertex2dv(&v[i + 1].x);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TLongBlendStrokeStyle2::getParamCount() const { return 1; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TColorStyle::ParamType TLongBlendStrokeStyle2::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TLongBlendStrokeStyle2::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Toshihiro Shimizu 890ddd
shun-iwasawa 27b0cf
  return QCoreApplication::translate("TLongBlendStrokeStyle2",
shun-iwasawa 27b0cf
                                     "Distance");  // W_Watercolor_Distance
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TLongBlendStrokeStyle2::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                           double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  min = 0.1;
Shinya Kitaoka 120a6e
  max = 100.0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TLongBlendStrokeStyle2::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                             int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  return m_parameter;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TLongBlendStrokeStyle2::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Shinya Kitaoka 120a6e
  m_parameter = value;
Shinya Kitaoka 120a6e
  updateVersionNumber();  // questo si chiama per ogno cambiamento di parametro
Shinya Kitaoka 120a6e
                          // per cui di deve ricalcolare l'outline
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
OutlineViewerStyle::OutlineViewerStyle(TPixel32 color, double parameter0,
Shinya Kitaoka 120a6e
                                       double parameter1, double parameter2,
Shinya Kitaoka 120a6e
                                       double parameter3)
Shinya Kitaoka 120a6e
    : TSolidColorStyle(color)
Shinya Kitaoka 120a6e
    , m_boolPar(false)
Shinya Kitaoka 120a6e
    , m_intPar(1)
Shinya Kitaoka 120a6e
    , m_enumPar(2)
Shinya Kitaoka 120a6e
    , m_pathPar("testPath") {
Shinya Kitaoka 120a6e
  m_parameter[0] = parameter0;
Shinya Kitaoka 120a6e
  m_parameter[1] = parameter1;
Shinya Kitaoka 120a6e
  m_parameter[2] = parameter2;
Shinya Kitaoka 120a6e
  m_parameter[3] = parameter3;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *OutlineViewerStyle::clone() const {
Shinya Kitaoka 120a6e
  return new OutlineViewerStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int OutlineViewerStyle::getParamCount() const { return 8; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle::ParamType OutlineViewerStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  static const TColorStyle::ParamType types[8] = {
Shinya Kitaoka 120a6e
      TColorStyle::DOUBLE, TColorStyle::DOUBLE,  TColorStyle::DOUBLE,
Shinya Kitaoka 120a6e
      TColorStyle::DOUBLE, TColorStyle::BOOL,    TColorStyle::INT,
Shinya Kitaoka 120a6e
      TColorStyle::ENUM,   TColorStyle::FILEPATH};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return types[index];
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString OutlineViewerStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 8);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    return QCoreApplication::translate("OutlineViewerStyle", "Control Point");
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    return QCoreApplication::translate("OutlineViewerStyle", "Center Line");
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    return QCoreApplication::translate("OutlineViewerStyle", "Outline Mode");
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    return QCoreApplication::translate("OutlineViewerStyle", "Distance");
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    return "Bool";
Shinya Kitaoka 120a6e
  case 5:
Shinya Kitaoka 120a6e
    return "Int";
Shinya Kitaoka 120a6e
  case 6:
Shinya Kitaoka 120a6e
    return "Enum";
Shinya Kitaoka 120a6e
  case 7:
Shinya Kitaoka 120a6e
    return "Path";
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(0);
Shinya Kitaoka 120a6e
  return QCoreApplication::translate("OutlineViewerStyle", "distance");
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void OutlineViewerStyle::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                       double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 4);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 0:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 2.99;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 1.99;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    min = 0.0;
Shinya Kitaoka 120a6e
    max = 3.99;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 3:
Shinya Kitaoka 120a6e
    min = 3.0;
Shinya Kitaoka 120a6e
    max = 100.0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void OutlineViewerStyle::getParamRange(int index, int &min, int &max) const {
Shinya Kitaoka 120a6e
  assert(5 <= index && index < 7);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case 5:
Shinya Kitaoka 120a6e
    min = 0, max = 10;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 6:
Shinya Kitaoka 120a6e
    min = 0, max = 4;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void OutlineViewerStyle::getParamRange(int index,
Shinya Kitaoka 120a6e
                                       QStringList &enumItems) const {
Shinya Kitaoka 120a6e
  enumItems << "Prova 1"
Shinya Kitaoka 120a6e
            << "Prova 2"
Shinya Kitaoka 120a6e
            << "Prova 3"
Shinya Kitaoka 120a6e
            << "Prova 4";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool OutlineViewerStyle::getParamValue(TColorStyle::bool_tag, int index) const {
Shinya Kitaoka 120a6e
  assert(index == 4);
Shinya Kitaoka 120a6e
  return m_boolPar;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int OutlineViewerStyle::getParamValue(TColorStyle::int_tag, int index) const {
Shinya Kitaoka 120a6e
  assert(5 <= index && index < 7);
Shinya Kitaoka 120a6e
  return (index == 5) ? m_intPar : m_enumPar;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double OutlineViewerStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                         int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 4);
Shinya Kitaoka 120a6e
  return m_parameter[index];
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath OutlineViewerStyle::getParamValue(TColorStyle::TFilePath_tag,
Shinya Kitaoka 120a6e
                                            int index) const {
Shinya Kitaoka 120a6e
  assert(index == 7);
Shinya Kitaoka 120a6e
  return m_pathPar;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void OutlineViewerStyle::setParamValue(int index, bool value) {
Shinya Kitaoka 120a6e
  assert(index == 4);
Shinya Kitaoka 120a6e
  m_boolPar = value;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void OutlineViewerStyle::setParamValue(int index, int value) {
Shinya Kitaoka 120a6e
  assert(5 <= index && index < 7);
Shinya Kitaoka 120a6e
  (index == 5) ? m_intPar = value : m_enumPar = value;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void OutlineViewerStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 4);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (index >= 2 && (int)m_parameter[index] != (int)value)  // cambia l'outline
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    updateVersionNumber();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_parameter[index] = value;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void OutlineViewerStyle::setParamValue(int index, const TFilePath &value) {
Shinya Kitaoka 120a6e
  assert(index == 7);
Shinya Kitaoka 120a6e
  m_pathPar = value;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void OutlineViewerStyle::loadData(TInputStreamInterface &is) {
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  is >> color;
Shinya Kitaoka 120a6e
  TSolidColorStyle::setMainColor(color);
Shinya Kitaoka 120a6e
  is >> m_parameter[0];
Shinya Kitaoka 120a6e
  is >> m_parameter[1];
Shinya Kitaoka 120a6e
  is >> m_parameter[2];
Shinya Kitaoka 120a6e
  is >> m_parameter[3];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int boolPar;
Shinya Kitaoka 120a6e
  is >> boolPar;
Shinya Kitaoka 120a6e
  m_boolPar = boolPar;
Shinya Kitaoka 120a6e
  is >> m_intPar;
Shinya Kitaoka 120a6e
  is >> m_enumPar;
Shinya Kitaoka 120a6e
  std::string str;
Shinya Kitaoka 120a6e
  is >> str;
Shinya Kitaoka 120a6e
  m_pathPar = TFilePath(::to_wstring(str));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void OutlineViewerStyle::saveData(TOutputStreamInterface &os) const {
Shinya Kitaoka 120a6e
  os << TSolidColorStyle::getMainColor();
Shinya Kitaoka 120a6e
  os << m_parameter[0];
Shinya Kitaoka 120a6e
  os << m_parameter[1];
Shinya Kitaoka 120a6e
  os << m_parameter[2];
Shinya Kitaoka 120a6e
  os << m_parameter[3];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  os << int(m_boolPar);
Shinya Kitaoka 120a6e
  os << m_intPar;
Shinya Kitaoka 120a6e
  os << m_enumPar;
Shinya Kitaoka 120a6e
  os << ::to_string(m_pathPar.getWideString());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void OutlineViewerStyle::computeOutline(
Shinya Kitaoka 120a6e
    const TStroke *stroke, TStrokeOutline &outline,
Shinya Kitaoka 120a6e
    TOutlineUtil::OutlineParameter param) const {
Shinya Kitaoka 120a6e
  if (m_parameter[2] >= 1.0) {
Shinya Kitaoka 120a6e
    param.m_lengthStep = (m_parameter[2] >= 3.0) ? m_parameter[3] : 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    TOutlineStyle::computeOutline(stroke, outline, param);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void drawOutline(TStrokeOutline *outline, bool cut) {
Shinya Kitaoka 120a6e
  const std::vector<toutlinepoint> &v = outline->getArray();</toutlinepoint>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (v.empty()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  UINT i;
Shinya Kitaoka 120a6e
  // outline with antialiasing
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  for (i = 0; i < v.size(); i += 2) glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  for (i = 1; i < v.size(); i += 2) glVertex2dv(&v[i].x);
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (cut) {
Shinya Kitaoka 120a6e
    static const int stride = sizeof(TOutlinePoint);
Shinya Kitaoka 120a6e
    glEnableClientState(GL_VERTEX_ARRAY);
Shinya Kitaoka 120a6e
    glVertexPointer(2, GL_DOUBLE, stride, &v[0]);
Shinya Kitaoka 120a6e
    glDrawArrays(GL_LINES, 0, v.size());
Shinya Kitaoka 120a6e
    glDisableClientState(GL_VERTEX_ARRAY);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void drawControlPoints(const TStroke *stroke, bool allPoints) {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  TPointD p;
Shinya Kitaoka 120a6e
  glPointSize(4.0);
Shinya Kitaoka 120a6e
  glBegin(GL_POINTS);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (allPoints) {
Shinya Kitaoka 120a6e
    int n = stroke->getControlPointCount();
Shinya Kitaoka 120a6e
    for (i = 0; i < n; ++i) {
Shinya Kitaoka 120a6e
      p = stroke->getControlPoint(i);
Shinya Kitaoka 120a6e
      glColor3d((i + 1) & 1, i & 1, 0.0);
Shinya Kitaoka 120a6e
      glVertex2d(p.x, p.y);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    int n = stroke->getChunkCount();
Shinya Kitaoka 120a6e
    for (i = 0; i < n; ++i) {
Shinya Kitaoka 120a6e
      const TThickQuadratic *chunk = stroke->getChunk(i);
Shinya Kitaoka 120a6e
      p                            = chunk->getP0();
Shinya Kitaoka 120a6e
      glColor3d(1.0, 0.0, 0.0);
Shinya Kitaoka 120a6e
      glVertex2d(p.x, p.y);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    const TThickQuadratic *chunk = stroke->getChunk(n - 1);
Shinya Kitaoka 120a6e
    glColor3d(1.0, 0.0, 0.0);
Shinya Kitaoka 120a6e
    p = chunk->getP2();
Shinya Kitaoka 120a6e
    glVertex2d(p.x, p.y);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void drawCenterline(const TStroke *stroke) {
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  int n = stroke->getChunkCount();
Shinya Kitaoka 120a6e
  int i = 0;
Shinya Kitaoka 120a6e
  for (i = 0; i < n; ++i) {
Shinya Kitaoka 120a6e
    const TThickQuadratic *chunk = stroke->getChunk(i);
Shinya Kitaoka 120a6e
    double length                = chunk->getLength(0, 1);
Shinya Kitaoka 120a6e
    int maxCount  = std::max(tceil(length / (5 * sqrt(tglGetPixelSize2()))), 1);
Shinya Kitaoka 120a6e
    double deltaT = 1.0 / maxCount;
Shinya Kitaoka 120a6e
    double t      = 0;
Shinya Kitaoka 120a6e
    for (t = 0; t < 1 + (deltaT / 2); t += deltaT) {
Shinya Kitaoka 120a6e
      TPointD point = chunk->getPoint(t);
Shinya Kitaoka 120a6e
      glVertex2d(point.x, point.y);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  return;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void OutlineViewerStyle::drawStroke(const TColorFunction *cf,
Shinya Kitaoka 120a6e
                                    TStrokeOutline *outline,
Shinya Kitaoka 120a6e
                                    const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  if (cf)
Shinya Kitaoka 120a6e
    color = (*(cf))(getMainColor());
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = getMainColor();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tglColor(color);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_parameter[1] >= 1.0) drawCenterline(stroke);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_parameter[2] >= 1.0) drawOutline(outline, m_parameter[2] >= 2.0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_parameter[0] >= 1.0) drawControlPoints(stroke, m_parameter[0] >= 2.0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TMatrioskaStrokeProp::TMatrioskaStrokeProp(const TStroke *stroke,
Shinya Kitaoka 120a6e
                                           TMatrioskaStrokeStyle *style)
Shinya Kitaoka 120a6e
    : TStrokeProp(stroke)
Shinya Kitaoka 120a6e
    , m_colorStyle(style)
Shinya Kitaoka 120a6e
    , m_outline()
Shinya Kitaoka 120a6e
    , m_outlinePixelSize(0) {
Shinya Kitaoka 120a6e
  m_styleVersionNumber = m_colorStyle->getVersionNumber();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TStrokeProp *TMatrioskaStrokeProp::clone(const TStroke *stroke) const {
Shinya Kitaoka 120a6e
  TMatrioskaStrokeProp *prop = new TMatrioskaStrokeProp(stroke, m_colorStyle);
Shinya Kitaoka 120a6e
  prop->m_strokeChanged      = m_strokeChanged;
Shinya Kitaoka 120a6e
  prop->m_outline            = m_outline;
Shinya Kitaoka 120a6e
  prop->m_outlinePixelSize   = m_outlinePixelSize;
Shinya Kitaoka 120a6e
  return prop;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const TColorStyle *TMatrioskaStrokeProp::getColorStyle() const {
Shinya Kitaoka 120a6e
  return m_colorStyle;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
void recomputeStrokes(const TStroke *stroke, vector<tstroke *=""> &strokes,</tstroke>
Shinya Kitaoka 120a6e
                      int strokeNumber) {
Shinya Kitaoka 120a6e
  clearPointerContainer(strokes);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  strokes.resize(strokeNumber);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int nCP = stroke->getControlPointCount();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double reduction;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (int strokeId = 0; strokeId != strokeNumber; strokeId++) {
Shinya Kitaoka 120a6e
    strokes[strokeId] = new TStroke(*stroke);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    reduction = ((double)strokeId + 0.5) / (double)(strokeNumber + 0.5);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    for (int i = 0; i < nCP; i++) {
Shinya Kitaoka 120a6e
      TThickPoint tp = strokes[strokeId]->getControlPoint(i);
Shinya Kitaoka 120a6e
      tp.thick *= reduction;
Shinya Kitaoka 120a6e
      strokes[strokeId]->setControlPoint(i, tp);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void recomputeOutlines(const TStroke *stroke, vector<tstroke *=""> &strokes,</tstroke>
Shinya Kitaoka 120a6e
                       vector<tstrokeoutline> &outlines,</tstrokeoutline>
Shinya Kitaoka 120a6e
                       const TSolidColorStyle *style) {
Shinya Kitaoka 120a6e
  TOutlineUtil::OutlineParameter param;
Shinya Kitaoka 120a6e
  int strokeNumber = strokes.size();
Shinya Kitaoka 120a6e
  outlines.resize(strokeNumber + 1);
Shinya Kitaoka 120a6e
  int strokeId;
Shinya Kitaoka 120a6e
  for (strokeId = 0; strokeId != strokeNumber; strokeId++) {
Shinya Kitaoka 120a6e
    outlines[strokeId].getArray().clear();
Shinya Kitaoka 120a6e
    style->computeOutline(strokes[strokeId], outlines[strokeId], param);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  outlines[strokeId].getArray().clear();
Shinya Kitaoka 120a6e
  style->computeOutline(stroke, outlines[strokeId], param);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TMatrioskaStrokeProp::draw(const TVectorRenderData &rd) {
Shinya Kitaoka 120a6e
  if (rd.m_clippingRect != TRect() && !rd.m_is3dView &&
Shinya Kitaoka 120a6e
      !convert(rd.m_aff * m_stroke->getBBox()).overlaps(rd.m_clippingRect))
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int strokeId;
Shinya Kitaoka 120a6e
  glPushMatrix();
Shinya Kitaoka 120a6e
  tglMultMatrix(rd.m_aff);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double pixelSize = sqrt(tglGetPixelSize2());
Shinya Kitaoka 120a6e
  int strokeNumber =
Shinya Kitaoka 120a6e
      (int)(m_colorStyle->getParamValue(TColorStyle::double_tag(), 0)) - 1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_strokeChanged || (UINT)strokeNumber != m_appStrokes.size()) {
Shinya Kitaoka 120a6e
    m_strokeChanged    = false;
Shinya Kitaoka 120a6e
    m_outlinePixelSize = pixelSize;
Shinya Kitaoka 120a6e
    recomputeStrokes(m_stroke, m_appStrokes, strokeNumber);
Shinya Kitaoka 120a6e
    recomputeOutlines(m_stroke, m_appStrokes, m_outline, m_colorStyle);
Shinya Kitaoka 120a6e
  } else if (!isAlmostZero(pixelSize - m_outlinePixelSize, 1e-5)
Shinya Kitaoka 120a6e
             //      || m_styleVersionNumber != m_colorStyle->getVersionNumber()
Shinya Kitaoka 120a6e
             ) {
Shinya Kitaoka 120a6e
    m_strokeChanged    = false;
Shinya Kitaoka 120a6e
    m_outlinePixelSize = pixelSize;
Shinya Kitaoka 120a6e
    recomputeOutlines(m_stroke, m_appStrokes, m_outline, m_colorStyle);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_colorStyle->drawStroke(rd.m_cf, &m_outline[m_appStrokes.size()], m_stroke);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TSolidColorStyle appStyle(m_colorStyle->getColorParamValue(1));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //  if(m_colorStyle->isAlternate())
Shinya Kitaoka 120a6e
  //  {
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (strokeId = strokeNumber - 1; strokeId >= 0; strokeId--) {
Shinya Kitaoka 120a6e
    if ((m_appStrokes.size() - strokeId) & 1)
Shinya Kitaoka 120a6e
      appStyle.drawStroke(rd.m_cf, &m_outline[strokeId],
Shinya Kitaoka 120a6e
                          m_appStrokes[strokeId]);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      m_colorStyle->drawStroke(rd.m_cf, &m_outline[strokeId],
Shinya Kitaoka 120a6e
                               m_appStrokes[strokeId]);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //  }
Shinya Kitaoka 120a6e
  //  else
Shinya Kitaoka 120a6e
  //  {
Shinya Kitaoka 120a6e
  //    TPixel32 color0=m_colorStyle->getColorParamValue(0);
Shinya Kitaoka 120a6e
  //    TPixel32 color1=m_colorStyle->getColorParamValue(1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //    for(strokeId=strokeNumber-1; strokeId>=0;strokeId--)
Shinya Kitaoka 120a6e
  //    {
Shinya Kitaoka 120a6e
  //      double r2=(double)strokeId/(double)(strokeNumber);
Shinya Kitaoka 120a6e
  //      double r1=1-r2;
Shinya Kitaoka 120a6e
  //      TPixel32  color((int)(color0.r*r2+color1.r*r1),
Shinya Kitaoka 120a6e
  //                    (int)(color0.g*r2+color1.g*r1),
Shinya Kitaoka 120a6e
  //                    (int)(color0.b*r2+color1.b*r1),
Shinya Kitaoka 120a6e
  //                    (int)(color0.m*r2+color1.m*r1)
Shinya Kitaoka 120a6e
  //                    );
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //      appStyle.setMainColor(color);
Shinya Kitaoka 120a6e
  //      appStyle.drawStroke(rd.m_cf,
Shinya Kitaoka 120a6e
  //      &m_outline[strokeId],m_appStrokes[strokeId]);
Shinya Kitaoka 120a6e
  //    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glPopMatrix();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TMatrioskaStrokeProp::~TMatrioskaStrokeProp() {
Shinya Kitaoka 120a6e
  clearPointerContainer(m_appStrokes);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TMatrioskaStrokeStyle::TMatrioskaStrokeStyle(TPixel32 color1, TPixel32 color2,
Shinya Kitaoka 120a6e
                                             double parameter, bool alternate)
Shinya Kitaoka 120a6e
    : TSolidColorStyle(color1), m_color2(color2), m_parameter(parameter) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle *TMatrioskaStrokeStyle::clone() const {
Shinya Kitaoka 120a6e
  return new TMatrioskaStrokeStyle(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TStrokeProp *TMatrioskaStrokeStyle::makeStrokeProp(const TStroke *stroke) {
Shinya Kitaoka 120a6e
  return new TMatrioskaStrokeProp(stroke, this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TMatrioskaStrokeStyle::getParamCount() const { return 1; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TColorStyle::ParamType TMatrioskaStrokeStyle::getParamType(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getParamCount());
Shinya Kitaoka 120a6e
  return TColorStyle::DOUBLE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TMatrioskaStrokeStyle::getParamNames(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //  if(index)
Shinya Kitaoka 120a6e
  //    return "alter/gradual";
Shinya Kitaoka 120a6e
  //  else
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return QCoreApplication::translate("TMatrioskaStrokeStyle", "Stripes");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TMatrioskaStrokeStyle::getParamRange(int index, double &min,
Shinya Kitaoka 120a6e
                                          double &max) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //  if(index)
Shinya Kitaoka 120a6e
  //  {
Shinya Kitaoka 120a6e
  //    min = 0;
Shinya Kitaoka 120a6e
  //    max = 1;
Shinya Kitaoka 120a6e
  //  }
Shinya Kitaoka 120a6e
  //  else
Shinya Kitaoka 120a6e
  //  {
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  min = 1.0;
Shinya Kitaoka 120a6e
  max = 10.0;
Shinya Kitaoka 120a6e
  //}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TMatrioskaStrokeStyle::getParamValue(TColorStyle::double_tag,
Shinya Kitaoka 120a6e
                                            int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //  if(index)
Shinya Kitaoka 120a6e
  //    return (m_alternate)? 0 : 1;
Shinya Kitaoka 120a6e
  //  else
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return m_parameter;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TMatrioskaStrokeStyle::setParamValue(int index, double value) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //  if(index)
Shinya Kitaoka 120a6e
  //    m_alternate = value<0.5;
Shinya Kitaoka 120a6e
  //  else
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_parameter = value;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  updateVersionNumber();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPixel32 TMatrioskaStrokeStyle::getColorParamValue(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  TPixel32 tmp;
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case (0):
Shinya Kitaoka 120a6e
    tmp = TSolidColorStyle::getMainColor();
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case (1):
Shinya Kitaoka 120a6e
    tmp = m_color2;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return tmp;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TMatrioskaStrokeStyle::setColorParamValue(int index,
Shinya Kitaoka 120a6e
                                               const TPixel32 &color) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < 2);
Shinya Kitaoka 120a6e
  switch (index) {
Shinya Kitaoka 120a6e
  case (0):
Shinya Kitaoka 120a6e
    TSolidColorStyle::setMainColor(color);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case (1):
Shinya Kitaoka 120a6e
    m_color2 = color;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
void TMatrioskaStrokeStyle::loadData(TInputStreamInterface &is) {
Shinya Kitaoka 120a6e
  TSolidColorStyle::loadData(is);
Shinya Kitaoka 120a6e
  is >> m_parameter;
Shinya Kitaoka 120a6e
  is >> m_color2;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TMatrioskaStrokeStyle::saveData(TOutputStreamInterface &os) const {
Shinya Kitaoka 120a6e
  TSolidColorStyle::saveData(os);
Shinya Kitaoka 120a6e
  os << m_parameter;
Shinya Kitaoka 120a6e
  os << m_color2;
Toshihiro Shimizu 890ddd
}