tahoma2d/toonz/sources/common/tvrender/tstrokeprop.cpp

309 lines
9.9 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
//#include "tcolorstyles.h"
#include "tsimplecolorstyles.h"
//#include "tstrokeoutline.h"
#include "tstrokeprop.h"
#include "tgl.h"
//#include "tcolorfunctions.h"
#include "tvectorrenderdata.h"
#include "tmathutil.h"
//#include "tcurves.h"
//#include "tstrokeutil.h"
//#include "tstroke.h"
//#include "tflash.h"
//=============================================================================
2016-06-15 18:43:10 +12:00
TSimpleStrokeProp::TSimpleStrokeProp(const TStroke *stroke,
TSimpleStrokeStyle *style)
: TStrokeProp(stroke)
, m_colorStyle(style)
2016-03-19 06:57:51 +13:00
{
2016-06-15 18:43:10 +12:00
m_styleVersionNumber = m_colorStyle->getVersionNumber();
m_colorStyle->addRef();
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TSimpleStrokeProp::~TSimpleStrokeProp() { m_colorStyle->release(); }
2016-03-19 06:57:51 +13:00
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
const TColorStyle *TSimpleStrokeProp::getColorStyle() const {
return m_colorStyle;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TStrokeProp *TSimpleStrokeProp::clone(const TStroke *stroke) const {
TSimpleStrokeProp *prop = new TSimpleStrokeProp(stroke, m_colorStyle);
prop->m_strokeChanged = m_strokeChanged;
return prop;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TSimpleStrokeProp::draw(
const TVectorRenderData
&rd) /*assenza di const non e' una dimenticanza! Alcune sottoclassi
devono ridefinire questo metodo e serve che non sia const*/
2016-03-19 06:57:51 +13:00
{
2016-06-15 18:43:10 +12:00
if (rd.m_clippingRect != TRect() && !rd.m_is3dView &&
!convert(rd.m_aff * m_stroke->getBBox()).overlaps(rd.m_clippingRect))
return;
if (!rd.m_show0ThickStrokes) {
// >:( This is not an implementation detail of TCenterlineStrokeStyle
// because the drawStroke()
// function does not have access to rd - should modify the interface...
// it would be best.
const TCenterLineStrokeStyle *cs =
dynamic_cast<const TCenterLineStrokeStyle *>(m_colorStyle);
if (cs && cs->getParamValue(TColorStyle::double_tag(), 0) == 0) return;
}
glPushMatrix();
tglMultMatrix(rd.m_aff);
m_colorStyle->drawStroke(rd.m_cf, m_stroke);
glPopMatrix();
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TSimpleStrokeProp::draw(TFlash &flash) {
getColorStyle()->drawStroke(flash, getStroke());
2016-03-19 06:57:51 +13:00
}
//=============================================================================
2016-06-15 18:43:10 +12:00
TRasterImagePatternStrokeProp::TRasterImagePatternStrokeProp(
const TStroke *stroke, TRasterImagePatternStrokeStyle *style)
: TStrokeProp(stroke), m_colorStyle(style) {
m_styleVersionNumber = style->getVersionNumber();
m_colorStyle->addRef();
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TRasterImagePatternStrokeProp::~TRasterImagePatternStrokeProp() {
m_colorStyle->release();
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
const TColorStyle *TRasterImagePatternStrokeProp::getColorStyle() const {
return m_colorStyle;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TStrokeProp *TRasterImagePatternStrokeProp::clone(const TStroke *stroke) const {
TRasterImagePatternStrokeProp *prop =
new TRasterImagePatternStrokeProp(stroke, m_colorStyle);
prop->m_strokeChanged = m_strokeChanged;
prop->m_transformations = m_transformations;
return prop;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-20 14:23:05 +12:00
void TRasterImagePatternStrokeProp::draw(
const TVectorRenderData &rd) /*assenza di const non e' una
dimenticanza! Alcune
sottoclassi devono
ridefinire questo metodo e
serbve che non sia const*/
2016-03-19 06:57:51 +13:00
{
2016-06-15 18:43:10 +12:00
if (rd.m_clippingRect != TRect() && !rd.m_is3dView &&
!convert(rd.m_aff * m_stroke->getBBox()).overlaps(rd.m_clippingRect))
return;
if (m_strokeChanged ||
m_styleVersionNumber != m_colorStyle->getVersionNumber()) {
m_strokeChanged = false;
m_styleVersionNumber = m_colorStyle->getVersionNumber();
m_colorStyle->computeTransformations(m_transformations, m_stroke);
}
m_colorStyle->drawStroke(rd, m_transformations, m_stroke);
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TRasterImagePatternStrokeProp::draw(TFlash &flash) {
getColorStyle()->drawStroke(flash, getStroke());
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
//=============================================================================
2016-06-15 18:43:10 +12:00
TVectorImagePatternStrokeProp::TVectorImagePatternStrokeProp(
const TStroke *stroke, TVectorImagePatternStrokeStyle *style)
: TStrokeProp(stroke), m_colorStyle(style) {
m_styleVersionNumber = style->getVersionNumber();
m_colorStyle->addRef();
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TVectorImagePatternStrokeProp::~TVectorImagePatternStrokeProp() {
m_colorStyle->release();
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
const TColorStyle *TVectorImagePatternStrokeProp::getColorStyle() const {
return m_colorStyle;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TStrokeProp *TVectorImagePatternStrokeProp::clone(const TStroke *stroke) const {
TVectorImagePatternStrokeProp *prop =
new TVectorImagePatternStrokeProp(stroke, m_colorStyle);
prop->m_strokeChanged = m_strokeChanged;
prop->m_transformations = m_transformations;
return prop;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-20 14:23:05 +12:00
void TVectorImagePatternStrokeProp::draw(
const TVectorRenderData &rd) /*assenza di const non e' una
dimenticanza! Alcune
sottoclassi devono
ridefinire questo metodo e
serbve che non sia const*/
2016-03-19 06:57:51 +13:00
{
2016-06-15 18:43:10 +12:00
if (rd.m_clippingRect != TRect() && !rd.m_is3dView &&
!convert(rd.m_aff * m_stroke->getBBox()).overlaps(rd.m_clippingRect))
return;
if (m_strokeChanged ||
m_styleVersionNumber != m_colorStyle->getVersionNumber()) {
m_strokeChanged = false;
m_styleVersionNumber = m_colorStyle->getVersionNumber();
m_colorStyle->computeTransformations(m_transformations, m_stroke);
}
m_colorStyle->drawStroke(rd, m_transformations, m_stroke);
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TVectorImagePatternStrokeProp::draw(TFlash &flash) {
getColorStyle()->drawStroke(flash, getStroke());
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
/*
2016-06-15 18:43:10 +12:00
void TSimpleStrokeProp::draw(TFlash &flash)
2016-03-19 06:57:51 +13:00
{
// fintissima!!!! quella vera deve risalire per m_colorStyle->drawStroke()
// come la sua sorellina di sopra
int i, n = m_stroke->getControlPointCount();
flash.setColor(m_colorStyle->getMainColor());
for(i=0;i<n-1;i++)
{
TPointD a = m_stroke->getControlPoint(i);
TPointD b = m_stroke->getControlPoint(i+1);
flash.drawLine(a,b);
}
}
*/
//=============================================================================
2016-06-15 18:43:10 +12:00
OutlineStrokeProp::OutlineStrokeProp(const TStroke *stroke,
const TOutlineStyleP style)
: TStrokeProp(stroke)
, m_colorStyle(style)
, m_outline()
, m_outlinePixelSize(0) {
m_styleVersionNumber = m_colorStyle->getVersionNumber();
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TStrokeProp *OutlineStrokeProp::clone(const TStroke *stroke) const {
OutlineStrokeProp *prop = new OutlineStrokeProp(stroke, m_colorStyle);
prop->m_strokeChanged = m_strokeChanged;
prop->m_outline = m_outline;
prop->m_outlinePixelSize = m_outlinePixelSize;
return prop;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
const TColorStyle *OutlineStrokeProp::getColorStyle() const {
return m_colorStyle.getPointer();
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void OutlineStrokeProp::draw(const TVectorRenderData &rd) {
if (rd.m_clippingRect != TRect() && !rd.m_is3dView &&
!convert(rd.m_aff * m_stroke->getBBox()).overlaps(rd.m_clippingRect))
return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
glPushMatrix();
tglMultMatrix(rd.m_aff);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
double pixelSize = sqrt(tglGetPixelSize2());
2016-03-19 06:57:51 +13:00
#ifdef _DEBUG
2016-06-15 18:43:10 +12:00
if (m_stroke->isCenterLine() && m_colorStyle->getTagId() != 99)
2016-03-19 06:57:51 +13:00
#else
2016-06-15 18:43:10 +12:00
if (m_stroke->isCenterLine())
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
{
TCenterLineStrokeStyle *appStyle =
new TCenterLineStrokeStyle(m_colorStyle->getAverageColor(), 0, 0);
appStyle->drawStroke(rd.m_cf, m_stroke);
delete appStyle;
} else {
if (!isAlmostZero(pixelSize - m_outlinePixelSize, 1e-5) ||
m_strokeChanged ||
m_styleVersionNumber != m_colorStyle->getVersionNumber()) {
m_strokeChanged = false;
m_outlinePixelSize = pixelSize;
TOutlineUtil::OutlineParameter param;
m_outline.getArray().clear();
m_colorStyle->computeOutline(m_stroke, m_outline, param);
// TOutlineStyle::StrokeOutlineModifier *modifier =
// m_colorStyle->getStrokeOutlineModifier();
// if(modifier)
// modifier->modify(m_outline);
m_styleVersionNumber = m_colorStyle->getVersionNumber();
}
m_colorStyle->drawStroke(rd.m_cf, &m_outline, m_stroke);
}
glPopMatrix();
2016-03-19 06:57:51 +13:00
}
//=============================================================================
2016-06-15 18:43:10 +12:00
void OutlineStrokeProp::draw(TFlash &flash) {
m_colorStyle->drawStroke(flash, getStroke());
2016-03-19 06:57:51 +13:00
}
//=============================================================================
/* ora e' virtuale pura
2016-06-15 18:43:10 +12:00
void TStrokeProp::draw(TFlash &flash)
2016-03-19 06:57:51 +13:00
{
getColorStyle()->drawStroke(flash, getStroke());
}
*/
//=============================================================================