Blob Blame Raw
#include <tools/replicator.h>
#include <tools/tool.h>
#include <toonz/tapplication.h>
#include <toonz/txsheet.h>
#include <toonz/txsheethandle.h>
#include <toonz/txshlevelhandle.h>
#include <toonz/tframehandle.h>
#include <toonz/tobjecthandle.h>
#include <toonz/dpiscale.h>
#include <tgl.h>
const int TReplicator::multiplierSoftLimit = 32;
const int TReplicator::multiplierLimit = 256;
//************************************************************************
// TReplicator implementation
//************************************************************************
TReplicator::TReplicator(TMetaObject &object):
TAssistantBase(object) { }
//---------------------------------------------------------------------------------------------------
int
TReplicator::getMultipler() const
{ return 1; }
//---------------------------------------------------------------------------------------------------
void
TReplicator::getModifiers(const TAffine&, TInputModifier::List&) const
{ }
//---------------------------------------------------------------------------------------------------
int
TReplicator::scanReplicators(
TTool *tool,
TInputModifier::List *outModifiers,
bool draw,
bool enabledOnly,
bool markEnabled,
TImage *skipImage )
{
long long multiplier = 0;
if (tool)
if (TToolViewer *viewer = tool->getViewer())
if (TApplication *application = tool->getApplication())
if (TXshLevelHandle *levelHandle = application->getCurrentLevel())
if (TXshLevel *level = levelHandle->getLevel())
if (TXshSimpleLevel *simpleLevel = level->getSimpleLevel())
if (TFrameHandle *frameHandle = application->getCurrentFrame())
if (TXsheetHandle *XsheetHandle = application->getCurrentXsheet())
if (TXsheet *Xsheet = XsheetHandle->getXsheet())
{
TPointD dpiScale = getCurrentDpiScale(simpleLevel, tool->getCurrentFid());
int frame = frameHandle->getFrame();
int count = Xsheet->getColumnCount();
TAffine worldToTrack;
if ( tool->getToolType() & TTool::LevelTool
&& !application->getCurrentObject()->isSpline() )
{
worldToTrack.a11 /= dpiScale.x;
worldToTrack.a22 /= dpiScale.y;
}
for(int i = 0; i < count; ++i)
if (TXshColumn *column = Xsheet->getColumn(i))
if (column->isCamstandVisible())
if (column->isPreviewVisible())
if (TImageP image = Xsheet->getCell(frame, i).getImage(false))
if (image != skipImage)
if (image->getType() == TImage::META)
if (TMetaImage *metaImage = dynamic_cast<TMetaImage*>(image.getPointer()))
{
TAffine imageToTrack = worldToTrack * tool->getColumnMatrix(i);
if (draw) { glPushMatrix(); tglMultMatrix(imageToTrack); }
TMetaImage::Reader reader(*metaImage);
for(TMetaObjectListCW::iterator i = reader->begin(); i != reader->end(); ++i)
if (*i)
if (const TReplicator *replicator = (*i)->getHandler<TReplicator>())
if (!enabledOnly || replicator->getEnabled())
{
if (!multiplier) multiplier = 1;
bool enabled = replicator->getEnabled();
if (enabled) {
int m = replicator->getMultipler();
if (m <= 0) m = 1;
multiplier *= m;
if (outModifiers)
replicator->getModifiers(imageToTrack, *outModifiers);
if (multiplier*m > multiplierLimit)
return multiplierLimit;
}
if (draw) replicator->draw(viewer, enabled && markEnabled);
}
if (draw) glPopMatrix();
}
}
return (int)multiplier;
}