Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/scriptbinding.h"
Toshihiro Shimizu 890ddd
#include "toonz/scriptbinding_scene.h"
Toshihiro Shimizu 890ddd
#include "toonz/scriptbinding_image.h"
Toshihiro Shimizu 890ddd
#include "toonz/scriptbinding_level.h"
Toshihiro Shimizu 890ddd
#include "toonz/scriptbinding_files.h"
Toshihiro Shimizu 890ddd
#include "toonz/scriptbinding_renderer.h"
Toshihiro Shimizu 890ddd
#include "toonz/scriptbinding_outline_vectorizer.h"
Toshihiro Shimizu 890ddd
#include "toonz/scriptbinding_centerline_vectorizer.h"
Toshihiro Shimizu 890ddd
#include "toonz/scriptbinding_rasterizer.h"
Toshihiro Shimizu 890ddd
#include "toonz/scriptbinding_toonz_raster_converter.h"
Toshihiro Shimizu 890ddd
#include "toonz/scriptbinding_image_builder.h"
Toshihiro Shimizu 890ddd
#include <qscriptengine></qscriptengine>
Toshihiro Shimizu 890ddd
#include "tlevel_io.h"
Toshihiro Shimizu 890ddd
#include "tlevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcenterlinevectorizer.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcamera.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include "ttoonzimage.h"
Toshihiro Shimizu 890ddd
#include "tvectorimage.h"
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
#include "tofflinegl.h"
Toshihiro Shimizu 890ddd
#include "tvectorrenderdata.h"
Toshihiro Shimizu 890ddd
#include "tgeometry.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcamera.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshleveltypes.h"
Toshihiro Shimizu 890ddd
#include "toonz/levelproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "tfiletype.h"
Toshihiro Shimizu 890ddd
#include <qregexp></qregexp>
Toshihiro Shimizu 890ddd
#include <qcolor></qcolor>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace TScriptBinding
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===========================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
WRAPPER_STD_CTOR_IMPL(Void)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===========================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int Wrapper::m_count = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Wrapper::Wrapper()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_id = ++m_count;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Wrapper::~Wrapper()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Wrapper::print(const QString &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QScriptValueList lst;
Toshihiro Shimizu 890ddd
	lst << msg;
Toshihiro Shimizu 890ddd
	print(lst);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Wrapper::print(const QScriptValueList &lst)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QScriptValue print = engine()->globalObject().property("print");
Toshihiro Shimizu 890ddd
	print.call(print, lst);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Wrapper::warning(const QString &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QScriptValueList lst;
Toshihiro Shimizu 890ddd
	lst << msg;
Toshihiro Shimizu 890ddd
	QScriptValue f = engine()->globalObject().property("warning");
Toshihiro Shimizu 890ddd
	f.call(f, lst);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===========================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QScriptValue checkArgumentCount(QScriptContext *context, const QString &name, int minCount, int maxCount)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int count = context->argumentCount();
Toshihiro Shimizu 890ddd
	if (minCount <= count && count <= maxCount)
Toshihiro Shimizu 890ddd
		return QScriptValue();
Toshihiro Shimizu 890ddd
	QString range;
Toshihiro Shimizu 890ddd
	if (minCount != maxCount)
Toshihiro Shimizu 890ddd
		range = QObject::tr("%1-%2").arg(minCount).arg(maxCount);
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		range = QObject::tr("%1").arg(minCount);
Toshihiro Shimizu 890ddd
	return context->throwError(QObject::tr("Expected %1 argument(s) in %2, got %3").arg(range).arg(name).arg(count));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QScriptValue checkArgumentCount(QScriptContext *context, const QString &name, int count)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return checkArgumentCount(context, name, count, count);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QScriptValue checkColor(QScriptContext *context, const QString &colorName, QColor &color)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	color.setNamedColor(colorName);
Toshihiro Shimizu 890ddd
	if (!color.isValid())
Toshihiro Shimizu 890ddd
		return context->throwError(QObject::tr("%1 is not a valid color (valid color names are 'red', 'transparent', '#FF8800', ecc.)").arg(colorName));
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		return QScriptValue();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
void bindClass(QScriptEngine &engine, const QString &name)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const QMetaObject *metaObj = &T::staticMetaObject;
Toshihiro Shimizu 890ddd
	QScriptValue ctor = engine.newFunction(T::ctor);
Toshihiro Shimizu 890ddd
	QScriptValue proto = engine.newQMetaObject(metaObj, ctor);
Toshihiro Shimizu 890ddd
	engine.globalObject().setProperty(name, proto);
Toshihiro Shimizu 890ddd
	engine.setDefaultPrototype(qMetaTypeId<t *="">(), proto);</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename tp=""></typename>
Toshihiro Shimizu 890ddd
QScriptValue qScriptValueFromQObject(QScriptEngine *engine, Tp const &qobject) { return engine->newQObject(qobject); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename tp=""></typename>
Toshihiro Shimizu 890ddd
void qScriptValueToQObject(const QScriptValue &value, Tp &qobject) { qobject = qobject_cast<tp>(value.toQObject()); }</tp>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename tp=""></typename>
Toshihiro Shimizu 890ddd
int qScriptRegisterQObjectMetaType(QScriptEngine *engine, const QScriptValue &prototype = QScriptValue())
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return qScriptRegisterMetaType<tp>(engine, qScriptValueFromQObject,</tp>
Toshihiro Shimizu 890ddd
									   qScriptValueToQObject, prototype);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class (t::*method)(qscriptcontext="" *)="" *,="" qscriptengine="" qscriptvalue="" t,=""></class>
Toshihiro Shimizu 890ddd
class Dummy
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	static QScriptValue dummy(QScriptContext *context, QScriptEngine *engine)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		T *obj = qscriptvalue_cast<t *="">(context->thisObject());</t>
Toshihiro Shimizu 890ddd
		return (obj->*Method)(context, engine);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void deffoo(QScriptEngine &engine)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QScriptValue f = engine.newFunction(Dummy<toonzrasterconverter, &toonzrasterconverter::convert="">::dummy);</toonzrasterconverter,>
Toshihiro Shimizu 890ddd
	engine.globalObject().property("ToonzRasterConverter").setProperty("convert", f);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void bindAll(QScriptEngine &engine)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bindClass(engine, "Image");
Toshihiro Shimizu 890ddd
	bindClass<level>(engine, "Level");</level>
Toshihiro Shimizu 890ddd
	bindClass<scene>(engine, "Scene");</scene>
Toshihiro Shimizu 890ddd
	bindClass<transform>(engine, "Transform");</transform>
Toshihiro Shimizu 890ddd
	bindClass<imagebuilder>(engine, "ImageBuilder");</imagebuilder>
Toshihiro Shimizu 890ddd
	bindClass<outlinevectorizer>(engine, "OutlineVectorizer");</outlinevectorizer>
Toshihiro Shimizu 890ddd
	bindClass<centerlinevectorizer>(engine, "CenterlineVectorizer");</centerlinevectorizer>
Toshihiro Shimizu 890ddd
	bindClass<rasterizer>(engine, "Rasterizer");</rasterizer>
Toshihiro Shimizu 890ddd
	bindClass<toonzrasterconverter>(engine, "ToonzRasterConverter");</toonzrasterconverter>
Toshihiro Shimizu 890ddd
	deffoo(engine);
Toshihiro Shimizu 890ddd
	bindClass<filepath>(engine, "FilePath");</filepath>
Toshihiro Shimizu 890ddd
	bindClass<renderer>(engine, "Renderer");</renderer>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	qScriptRegisterQObjectMetaType<tscriptbinding::image *="">(&engine);</tscriptbinding::image>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	engine.evaluate("ToonzVersion='7.1'");
Toshihiro Shimizu 890ddd
	// engine.evaluate("toonz={version:'7.0', }; script={version:'1.0'};");
Toshihiro Shimizu 890ddd
	// engine.globalObject().setProperty("dir","C:\\Users\\gmt\\GMT to vectorize\\");
Toshihiro Shimizu 890ddd
	// QScriptValue test = engine.evaluate("function() { print('ok'); run(dir+'bu.js');}");
Toshihiro Shimizu 890ddd
	// engine.globalObject().setProperty("test",test);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace TScriptBinding