Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tgl.h"
Toshihiro Shimizu 890ddd
#include "tvectorgl.h"
Toshihiro Shimizu 890ddd
#include "tregion.h"
Toshihiro Shimizu 890ddd
#include "tregionprop.h"
Toshihiro Shimizu 890ddd
#include "tstrokeutil.h"
Toshihiro Shimizu 890ddd
#include "tvectorrenderdata.h"
Toshihiro Shimizu 890ddd
#include "tvectorimage.h"
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
#include "tcolorfunctions.h"
Toshihiro Shimizu 890ddd
#include "tsimplecolorstyles.h"
Toshihiro Shimizu 890ddd
#include "tthreadmessage.h"
Toshihiro Shimizu 890ddd
#include "tstrokeprop.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
#include "tcurves.h"
Toshihiro Shimizu 890ddd
#include "tstrokeoutline.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifndef _WIN32
Toshihiro Shimizu 890ddd
#define CALLBACK
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef checkErrorsByGL
Shinya Kitaoka 120a6e
#define checkErrorsByGL                                                        \
Shinya Kitaoka 120a6e
  {                                                                            \
Shinya Kitaoka 120a6e
    GLenum err = glGetError();                                                 \
Shinya Kitaoka 120a6e
    assert(err != GL_INVALID_ENUM);                                            \
Shinya Kitaoka 120a6e
    assert(err != GL_INVALID_VALUE);                                           \
Shinya Kitaoka 120a6e
    assert(err != GL_INVALID_OPERATION);                                       \
Shinya Kitaoka 120a6e
    assert(err != GL_STACK_OVERFLOW);                                          \
Shinya Kitaoka 120a6e
    assert(err != GL_STACK_UNDERFLOW);                                         \
Shinya Kitaoka 120a6e
    assert(err != GL_OUT_OF_MEMORY);                                           \
Shinya Kitaoka 120a6e
    assert(err == GL_NO_ERROR);                                                \
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef checkErrorsByGL
Toshihiro Shimizu 890ddd
#define checkErrorsByGL
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace std;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
DV_EXPORT_API void mylog(std::string s)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
  static TThread::Mutex mutex;
Toshihiro Shimizu 890ddd
  QMutexLocker sl(mutex);
Toshihiro Shimizu 890ddd
  std::ofstream os("C:\\gmt\\buttami\\bu.txt", std::ios::app);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  LARGE_INTEGER ticksPerSecond;
Shinya Kitaoka 120a6e
  LARGE_INTEGER tick;
Shinya Kitaoka 120a6e
  static LARGE_INTEGER firstTick;
Toshihiro Shimizu 890ddd
  static bool firstTime = true;
Toshihiro Shimizu 890ddd
  long dt = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  QueryPerformanceFrequency(&ticksPerSecond);
Toshihiro Shimizu 890ddd
  QueryPerformanceCounter(&tick);
Toshihiro Shimizu 890ddd
  if(firstTime) {firstTick = tick;firstTime=false;}
Toshihiro Shimizu 890ddd
  else
Toshihiro Shimizu 890ddd
  {
Shinya Kitaoka 120a6e
    dt =
Shinya Kitaoka 120a6e
(long)(1000000*(tick.QuadPart-firstTick.QuadPart)/ticksPerSecond.QuadPart);
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
  os << dt << ":" << s << std::endl;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool checkQuadraticDistance(TStroke *stroke, bool checkThickness) {
Shinya Kitaoka 120a6e
  UINT i, qCount = stroke->getChunkCount();
Shinya Kitaoka 120a6e
  const TThickQuadratic *q;
Shinya Kitaoka 120a6e
  TThickPoint p1, p2, p3;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // se i punti coincidono e' una stroke puntiforme ed e' ammessa
Shinya Kitaoka 120a6e
  if (qCount == 1) return true;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (i = 0; i != qCount; i++) {
Shinya Kitaoka 120a6e
    q  = stroke->getChunk(i);
Shinya Kitaoka 120a6e
    p1 = q->getThickP0();
Shinya Kitaoka 120a6e
    p2 = q->getThickP1();
Shinya Kitaoka 120a6e
    p3 = q->getThickP2();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (areAlmostEqual(p1.x, p2.x) && areAlmostEqual(p2.x, p3.x) &&
Shinya Kitaoka 120a6e
        areAlmostEqual(p1.y, p2.y) && areAlmostEqual(p2.y, p3.y) &&
Shinya Kitaoka 120a6e
        (!checkThickness || (areAlmostEqual(p1.thick, p2.thick) &&
Shinya Kitaoka 120a6e
                             areAlmostEqual(p2.thick, p3.thick))))
Shinya Kitaoka 120a6e
      return false;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void drawControlPoints(const TVectorRenderData &rd, TStroke *stroke,
Shinya Kitaoka 120a6e
                       double pixelSize, bool allPoints = true) {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  TPointD p;
Shinya Kitaoka 120a6e
  glPushMatrix();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  tglMultMatrix(rd.m_aff);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glPointSize(2.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
  glPopMatrix();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*TPixel TransparencyCheckBlackBgInk = TPixel(255,255,255);
Toshihiro Shimizu 890ddd
TPixel TransparencyCheckWhiteBgInk = TPixel(0,0,0);
Toshihiro Shimizu 890ddd
TPixel TransparencyCheckPaint = TPixel(127,127,127);*/
Toshihiro Shimizu 890ddd
static int Index = 0;
Shinya Kitaoka 120a6e
void tglDraw(const TVectorRenderData &rd, TRegion *r, bool pushAttribs) {
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
  assert(r);
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
  if (!r) return;
Shinya Kitaoka 120a6e
  bool alphaChannel = rd.m_alphaChannel;
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int j          = 0;
Shinya Kitaoka 120a6e
  bool visible   = false;
Shinya Kitaoka 120a6e
  int colorCount = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TColorStyleP style;
Shinya Kitaoka 120a6e
  if (rd.m_paintCheckEnabled && r->getStyle() == rd.m_colorCheckIndex) {
Shinya Kitaoka 120a6e
    static TSolidColorStyle *redColor = new TSolidColorStyle();
Shinya Kitaoka 120a6e
    redColor->addRef();
Shinya Kitaoka 120a6e
    redColor->setMainColor(TPixel::Red);
Shinya Kitaoka 120a6e
    style = redColor;
Shinya Kitaoka 120a6e
  } else if (rd.m_tcheckEnabled) {
Shinya Kitaoka 120a6e
    static TSolidColorStyle *color = new TSolidColorStyle();
Shinya Kitaoka 120a6e
    color->addRef();
Shinya Kitaoka 120a6e
    color->setMainColor(rd.m_tCheckPaint);
Shinya Kitaoka 120a6e
    style = color;
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    style = rd.m_palette->getStyle(r->getStyle());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  colorCount = style->getColorParamCount();
Shinya Kitaoka 120a6e
  if (colorCount == 0) {  // for example texture
Shinya Kitaoka 120a6e
    visible = true;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    visible = false;
Shinya Kitaoka 120a6e
    for (j = 0; j < colorCount && !visible; j++) {
Shinya Kitaoka 120a6e
      TPixel32 color            = style->getColorParamValue(j);
Shinya Kitaoka 120a6e
      if (rd.m_cf) color        = (*(rd.m_cf))(color);
Shinya Kitaoka 120a6e
      if (color.m != 0) visible = true;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (visible) {
Shinya Kitaoka 120a6e
    TRegionProp *prop = r->getProp(/*rd.m_palette*/);
Shinya Kitaoka 120a6e
    /// questo codice satva dentro tregion::getprop/////
Shinya Kitaoka 120a6e
    int styleId = r->getStyle();
Shinya Kitaoka 120a6e
    if (styleId) {
Shinya Kitaoka 120a6e
      // TColorStyle * style = rd.m_palette->getStyle(styleId);
Shinya Kitaoka 120a6e
      if (!style->isRegionStyle() || style->isEnabled() == false) {
Shinya Kitaoka 120a6e
        prop = 0;
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        // Warning: The same remark of stroke props holds here.
Shinya Kitaoka 120a6e
        if (!prop || style.getPointer() != prop->getColorStyle()) {
Shinya Kitaoka 120a6e
          r->setProp(style->makeRegionProp(r));
Shinya Kitaoka 120a6e
          prop = r->getProp();
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    ////// draw
Shinya Kitaoka 120a6e
    if (prop) {
Shinya Kitaoka 120a6e
      if (pushAttribs) glPushAttrib(GL_ALL_ATTRIB_BITS);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      tglEnableLineSmooth(true);
Toshihiro Shimizu 890ddd
//#define DRAW_EDGE_NUMBERS
Toshihiro Shimizu 890ddd
#ifdef DRAW_EDGE_NUMBERS
Shinya Kitaoka 120a6e
      glPushMatrix();
Shinya Kitaoka 120a6e
      tglMultMatrix(rd.m_aff);
Shinya Kitaoka 120a6e
      switch (Index % 7) {
Shinya Kitaoka 120a6e
      case 0:
Shinya Kitaoka 120a6e
        tglColor(TPixel::Red);
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      case 1:
Shinya Kitaoka 120a6e
        tglColor(TPixel::Green);
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      case 2:
Shinya Kitaoka 120a6e
        tglColor(TPixel::Blue);
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      case 3:
Shinya Kitaoka 120a6e
        tglColor(TPixel::Cyan);
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      case 4:
Shinya Kitaoka 120a6e
        tglColor(TPixel::Magenta);
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      case 5:
Shinya Kitaoka 120a6e
        tglColor(TPixel::Yellow);
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      case 6:
Shinya Kitaoka 120a6e
        tglColor(TPixel::Black);
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      default:
Shinya Kitaoka 120a6e
        tglColor(TPixel::Red);
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      Index++;
Shinya Kitaoka 120a6e
      if (rIndex == 2) {
Shinya Kitaoka 120a6e
        double y = r->getEdge(0)
Shinya Kitaoka 120a6e
                       ->m_s
Shinya Kitaoka 120a6e
                       ->getThickPoint(
Shinya Kitaoka 120a6e
                           (r->getEdge(0)->m_w0 + r->getEdge(0)->m_w1) / 2.0)
Shinya Kitaoka 120a6e
                       .y;
Shinya Kitaoka 120a6e
        tglDrawSegment(TPointD(-1000, y), TPointD(1000, y));
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      for (int i = 0; i < (int)r->getEdgeCount(); i++) {
Shinya Kitaoka 120a6e
        TEdge *e  = r->getEdge(i);
Shinya Kitaoka 120a6e
        TPointD p = e->m_s->getPoint(0.8 * e->m_w0 + 0.2 * e->m_w1);
Shinya Kitaoka 120a6e
        if (i == 0)
Shinya Kitaoka 120a6e
          tglDrawText(p,
Shinya Kitaoka 120a6e
                      (QString::number(rIndex) + QString("-0")).toStdString());
Shinya Kitaoka 120a6e
        else
Shinya Kitaoka 120a6e
          tglDrawText(p, QString::number(i).toStdString());
Shinya Kitaoka 120a6e
        if (e->m_index == 3) {
Shinya Kitaoka 120a6e
          tglColor(TPixel::Black);
Shinya Kitaoka 120a6e
          TStroke *s = e->m_s;
Shinya Kitaoka 120a6e
          drawPoint(s->getChunk(0)->getP0(), .3);
Shinya Kitaoka 120a6e
          tglColor(TPixel::Red);
Shinya Kitaoka 120a6e
          tglDrawText(s->getChunk(0)->getP0(),
Shinya Kitaoka 120a6e
                      QString::number(0).toStdString());
Shinya Kitaoka 120a6e
          for (int ii = 0; ii < s->getChunkCount(); ii++) {
Shinya Kitaoka 120a6e
            drawPoint(s->getChunk(ii)->getP2(), .3);
Shinya Kitaoka 120a6e
            if (ii < s->getChunkCount() - 1) {
Shinya Kitaoka 120a6e
              tglColor(TPixel::Red);
Shinya Kitaoka 120a6e
              tglDrawText(s->getChunk(ii)->getP2(),
Shinya Kitaoka 120a6e
                          QString::number(ii + 1).toStdString());
Shinya Kitaoka 120a6e
            }
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      glPopMatrix();
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      if (alphaChannel) {
Shinya Kitaoka 120a6e
        GLboolean red, green, blue, alpha;
Shinya Kitaoka 120a6e
        tglGetColorMask(red, green, blue, alpha);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        // Draw RGB channels
Shinya Kitaoka 120a6e
        tglEnableBlending(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Shinya Kitaoka 120a6e
        glColorMask(red, green, blue, GL_FALSE);
Shinya Kitaoka 120a6e
        prop->draw(rd);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        // Draw Matte channel
Shinya Kitaoka 120a6e
        tglEnableBlending(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
Shinya Kitaoka 120a6e
        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, alpha);
Shinya Kitaoka 120a6e
        prop->draw(rd);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        glColorMask(red, green, blue, alpha);
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        // pezza: in render, le aree fillate dei custom styles sparivano.
Shinya Kitaoka 120a6e
        if (!rd.m_isOfflineRender || !rd.m_isImagePattern)
Shinya Kitaoka 120a6e
          tglRgbOnlyColorMask();  // RGB components only
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        prop->draw(rd);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (pushAttribs) glPopAttrib();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (UINT i = 0; i < r->getSubregionCount(); i++)
Shinya Kitaoka 120a6e
    tglDraw(rd, r->getSubregion(i), pushAttribs);
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void tglDrawMask(const TVectorRenderData &rd1, const TVectorImage *vim) {
Shinya Kitaoka 120a6e
  UINT i;
Shinya Kitaoka 120a6e
  assert(vim);
Shinya Kitaoka 120a6e
  if (!vim) return;
Shinya Kitaoka 120a6e
  TVectorRenderData rd(rd1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glPushAttrib(GL_ALL_ATTRIB_BITS);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!rd.m_palette) {
Shinya Kitaoka 120a6e
    TPalette *vPalette = vim->getPalette();
Shinya Kitaoka 120a6e
    assert(vPalette);
Shinya Kitaoka 120a6e
    rd.m_palette = vPalette;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  for (i = 0; i < vim->getRegionCount(); i++)
Shinya Kitaoka 120a6e
    tglDraw(rd, vim->getRegion(i), false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glPopAttrib();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
bool isOThick(const TStroke *s) {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < s->getControlPointCount(); i++)
Shinya Kitaoka 120a6e
    if (s->getControlPoint(i).thick != 0) return false;
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void tglDraw(const TVectorRenderData &rd, const TStroke *s, bool pushAttribs) {
Shinya Kitaoka 120a6e
  assert(s);
Shinya Kitaoka 120a6e
  if (!s) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TStrokeProp *prop  = 0;
Shinya Kitaoka 120a6e
  bool pushedAttribs = false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    TColorStyleP style;
Shinya Kitaoka 120a6e
    TStroke *stroke = const_cast<tstroke *="">(s);</tstroke>
Shinya Kitaoka 120a6e
    if (rd.m_inkCheckEnabled && s->getStyle() == rd.m_colorCheckIndex) {
Shinya Kitaoka 120a6e
      static TSolidColorStyle *redColor = new TSolidColorStyle();
Shinya Kitaoka 120a6e
      redColor->addRef();
Shinya Kitaoka 120a6e
      redColor->setMainColor(TPixel::Red);
Shinya Kitaoka 120a6e
      style = redColor;
Shinya Kitaoka 120a6e
    } else if (rd.m_tcheckEnabled) {
Shinya Kitaoka 120a6e
      static TSolidColorStyle *color = new TSolidColorStyle();
Shinya Kitaoka 120a6e
      color->addRef();
Shinya Kitaoka 120a6e
      color->setMainColor(rd.m_tCheckInk);
Shinya Kitaoka 120a6e
      style = color;
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      style = rd.m_palette->getStyle(stroke->getStyle());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (!rd.m_show0ThickStrokes && isOThick(s) &&
Shinya Kitaoka 120a6e
        dynamic_cast<tsolidcolorstyle *="">(</tsolidcolorstyle>
Shinya Kitaoka 120a6e
            style.getPointer())  // This is probably to exclude
Shinya Kitaoka 120a6e
                                 // TCenterlineStrokeStyle-like styles
Shinya Kitaoka 120a6e
        && !rd.m_tcheckEnabled)  // I wonder why this?
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // const TStroke& stroke = *s;  //serve???
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    assert(rd.m_palette);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    prop = s->getProp(/*rd.m_palette*/);
Shinya Kitaoka 120a6e
    /////questo codice stava dentro tstroke::getprop/////////
Shinya Kitaoka 120a6e
    if (prop) prop->getMutex()->lock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (!style->isStrokeStyle() || style->isEnabled() == false) {
Shinya Kitaoka 120a6e
      if (prop) prop->getMutex()->unlock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      prop = 0;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      // Warning: the following pointers check is conceptually wrong - we
Shinya Kitaoka 120a6e
      // keep it because the props maintain SMART POINTER-like reference to
Shinya Kitaoka 120a6e
      // the associated style. This prevents the style from being destroyed
Shinya Kitaoka 120a6e
      // while still referenced by the prop.
Shinya Kitaoka 120a6e
      if (!prop || style.getPointer() != prop->getColorStyle()) {
Shinya Kitaoka 120a6e
        if (prop) prop->getMutex()->unlock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        stroke->setProp(style->makeStrokeProp(stroke));
Shinya Kitaoka 120a6e
        prop = stroke->getProp();
Shinya Kitaoka 120a6e
        if (prop) prop->getMutex()->lock();
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    //--------- draw ------------
Shinya Kitaoka 120a6e
    if (!prop) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (pushAttribs) glPushAttrib(GL_ALL_ATTRIB_BITS), pushedAttribs = true;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    bool alphaChannel = rd.m_alphaChannel, antialias = rd.m_antiAliasing;
Shinya Kitaoka 120a6e
    TVectorImagePatternStrokeProp *aux =
Shinya Kitaoka 120a6e
        dynamic_cast<tvectorimagepatternstrokeprop *="">(prop);</tvectorimagepatternstrokeprop>
Shinya Kitaoka 120a6e
    if (aux)  // gli image pattern vettoriali tornano in questa funzione....non
Shinya Kitaoka 120a6e
              // facendo il corpo dell'else'si evita di disegnarli due volte!
Shinya Kitaoka 120a6e
      prop->draw(rd);
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      if (antialias)
Shinya Kitaoka 120a6e
        tglEnableLineSmooth(true);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        tglEnableLineSmooth(false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (alphaChannel) {
Shinya Kitaoka 120a6e
        GLboolean red, green, blue, alpha;
Shinya Kitaoka 120a6e
        tglGetColorMask(red, green, blue, alpha);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        // Draw RGB channels
Shinya Kitaoka 120a6e
        tglEnableBlending(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Shinya Kitaoka 120a6e
        glColorMask(red, green, blue, GL_FALSE);
Shinya Kitaoka 120a6e
        prop->draw(rd);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        // Draw Matte channel
Shinya Kitaoka 120a6e
        tglEnableBlending(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
Shinya Kitaoka 120a6e
        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, alpha);
Shinya Kitaoka 120a6e
        prop->draw(rd);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        glColorMask(red, green, blue, alpha);
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        tglEnableBlending(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Shinya Kitaoka 120a6e
        prop->draw(rd);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (pushAttribs) glPopAttrib(), pushedAttribs = false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    prop->getMutex()->unlock();
Shinya Kitaoka 120a6e
    //---------------------
Shinya Kitaoka 120a6e
  } catch (...) {
Shinya Kitaoka 120a6e
    if (prop) prop->getMutex()->unlock();
Shinya Kitaoka 120a6e
    if (pushedAttribs) glPopAttrib();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Campbell Barton 8c6c57
static void tglDoDraw(const TVectorRenderData &rd, TRegion *r) {
Shinya Kitaoka 120a6e
  bool visible   = false;
Shinya Kitaoka 120a6e
  int colorCount = 0;
Shinya Kitaoka 120a6e
  if (!r) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TColorStyleP style = rd.m_palette->getStyle(r->getStyle());
Shinya Kitaoka 120a6e
  colorCount         = style->getColorParamCount();
Shinya Kitaoka 120a6e
  if (colorCount == 0)  // for example texture
Shinya Kitaoka 120a6e
    visible = true;
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    visible = false;
Shinya Kitaoka 120a6e
    for (int j = 0; j < colorCount && !visible; j++) {
Shinya Kitaoka 120a6e
      TPixel32 color            = style->getColorParamValue(j);
Shinya Kitaoka 120a6e
      if (rd.m_cf) color        = (*(rd.m_cf))(color);
Shinya Kitaoka 120a6e
      if (color.m != 0) visible = true;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (visible)
Shinya Kitaoka 120a6e
    tglDraw(rd, r, false);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    for (UINT j = 0; j < r->getSubregionCount(); j++)
Shinya Kitaoka 120a6e
      tglDraw(rd, r->getSubregion(j), false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Campbell Barton 8c6c57
static void tglDoDraw(const TVectorRenderData &rd, const TStroke *s) {
Shinya Kitaoka 120a6e
  bool visible   = false;
Shinya Kitaoka 120a6e
  int colorCount = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  const TPalette *palette = rd.m_palette;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int styleId = s->getStyle();
Shinya Kitaoka 120a6e
  // assert(0<=styleId && styleId
Shinya Kitaoka 120a6e
  TColorStyleP style = palette->getStyle(styleId);
Shinya Kitaoka 120a6e
  assert(style);
Shinya Kitaoka 120a6e
  colorCount = style->getColorParamCount();
Shinya Kitaoka 120a6e
  if (colorCount == 0)
Shinya Kitaoka 120a6e
    visible = true;
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    visible = false;
Shinya Kitaoka 120a6e
    for (int j = 0; j < style->getColorParamCount() && !visible; j++) {
Shinya Kitaoka 120a6e
      TPixel32 color            = style->getColorParamValue(j);
Shinya Kitaoka 120a6e
      if (rd.m_cf) color        = (*(rd.m_cf))(color);
Shinya Kitaoka 120a6e
      if (color.m != 0) visible = true;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
#if DISEGNO_OUTLINE == 0
Shinya Kitaoka 120a6e
  if (visible)
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    tglDraw(rd, s, false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Shinya Kitaoka 120a6e
// drawControlPoints(rd, vim->getStroke(i), sqrt(tglGetPixelSize2()), true);
Shinya Kitaoka 120a6e
// assert(checkQuadraticDistance(vim->getStroke(i),true));
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void doDraw(const TVectorImage *vim, const TVectorRenderData &_rd,
Shinya Kitaoka 120a6e
            bool drawEnteredGroup) {
Shinya Kitaoka 120a6e
  static TOnionFader *fade = new TOnionFader(TPixel::White, 0.5);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TVectorRenderData rd(_rd);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!rd.m_palette) {
Shinya Kitaoka 120a6e
    TPalette *vPalette = vim->getPalette();
Shinya Kitaoka 120a6e
    rd.m_palette       = vPalette;
Shinya Kitaoka 120a6e
    if (!vPalette) return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!drawEnteredGroup && !rd.m_isIcon && vim->isInsideGroup() > 0)
Shinya Kitaoka 120a6e
    rd.m_cf = fade;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TVectorRenderData rdRegions = rd;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*if (rd.m_drawRegions && rd.m_isImagePattern)//gli image pattern hanno
Shinya Kitaoka 120a6e
bisogno dell'antialiasig per le linee, ma sulle aree ci sarebbero un sacco di
Shinya Kitaoka 120a6e
assert
Shinya Kitaoka 120a6e
rdRegions.m_alphaChannel = rdRegions.m_antiAliasing = false;*/
Shinya Kitaoka 120a6e
  UINT strokeIndex = 0;
Shinya Kitaoka 120a6e
  Index            = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  while (strokeIndex <
Shinya Kitaoka 120a6e
         vim->getStrokeCount())  // ogni ciclo di while disegna un gruppo
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    int currStrokeIndex = strokeIndex;
Shinya Kitaoka 120a6e
    if (!rd.m_isIcon && vim->isInsideGroup() > 0 &&
Shinya Kitaoka 120a6e
        ((drawEnteredGroup && !vim->isEnteredGroupStroke(strokeIndex)) ||
Shinya Kitaoka 120a6e
         !drawEnteredGroup && vim->isEnteredGroupStroke(strokeIndex))) {
Shinya Kitaoka 120a6e
      while (strokeIndex < vim->getStrokeCount() &&
Shinya Kitaoka 120a6e
             vim->sameGroup(strokeIndex, currStrokeIndex))
Shinya Kitaoka 120a6e
        strokeIndex++;
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (rd.m_drawRegions)
Shinya Kitaoka 120a6e
      for (UINT regionIndex = 0; regionIndex < vim->getRegionCount();
Shinya Kitaoka 120a6e
           regionIndex++)
Shinya Kitaoka 120a6e
        if (vim->sameGroupStrokeAndRegion(currStrokeIndex, regionIndex))
Shinya Kitaoka 120a6e
          tglDoDraw(rdRegions, vim->getRegion(regionIndex));
Shinya Kitaoka 120a6e
    while (strokeIndex < vim->getStrokeCount() &&
Shinya Kitaoka 120a6e
           vim->sameGroup(strokeIndex, currStrokeIndex)) {
Toshihiro Shimizu 890ddd
#if DISEGNO_OUTLINE == 1
Shinya Kitaoka 120a6e
      CurrStrokeIndex = strokeIndex;
Shinya Kitaoka 120a6e
      CurrVimg        = vim;
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
      tglDoDraw(rd, vim->getStroke(strokeIndex));
Shinya Kitaoka 120a6e
      strokeIndex++;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void tglDraw(const TVectorRenderData &rd, const TVectorImage *vim) {
Shinya Kitaoka 120a6e
  assert(vim);
Shinya Kitaoka 120a6e
  if (!vim) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QMutexLocker sl(vim->getMutex());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glPushAttrib(GL_ALL_ATTRIB_BITS);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // if(!rd.m_palette) rd.m_palette = vim->getPalette();
Shinya Kitaoka 120a6e
  // mylog("tglDraw start; mutex=" + toString((unsigned long)&vim->getMutex()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glEnable(GL_ALPHA_TEST);
Shinya Kitaoka 120a6e
  glAlphaFunc(GL_GREATER, 0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  doDraw(vim, rd, false);
Shinya Kitaoka 120a6e
  if (!rd.m_isIcon && vim->isInsideGroup() > 0) doDraw(vim, rd, true);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glDisable(GL_ALPHA_TEST);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glPopAttrib();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Shinya Kitaoka 120a6e
  vim->drawAutocloses(rd);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  checkErrorsByGL;
Shinya Kitaoka 120a6e
  // mylog("tglDraw stop");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------