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