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
Shinya Kitaoka 120a6e
namespace TScriptBinding {
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
Shinya Kitaoka 120a6e
Wrapper::Wrapper() { m_id = ++m_count; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Wrapper::~Wrapper() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Wrapper::print(const QString &msg) {
Shinya Kitaoka 120a6e
  QScriptValueList lst;
Shinya Kitaoka 120a6e
  lst << msg;
Shinya Kitaoka 120a6e
  print(lst);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Wrapper::print(const QScriptValueList &lst) {
Shinya Kitaoka 120a6e
  QScriptValue print = engine()->globalObject().property("print");
Shinya Kitaoka 120a6e
  print.call(print, lst);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Wrapper::warning(const QString &msg) {
Shinya Kitaoka 120a6e
  QScriptValueList lst;
Shinya Kitaoka 120a6e
  lst << msg;
Shinya Kitaoka 120a6e
  QScriptValue f = engine()->globalObject().property("warning");
Shinya Kitaoka 120a6e
  f.call(f, lst);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===========================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QScriptValue checkArgumentCount(QScriptContext *context, const QString &name,
Shinya Kitaoka 120a6e
                                int minCount, int maxCount) {
Shinya Kitaoka 120a6e
  int count = context->argumentCount();
Shinya Kitaoka 120a6e
  if (minCount <= count && count <= maxCount) return QScriptValue();
Shinya Kitaoka 120a6e
  QString range;
Shinya Kitaoka 120a6e
  if (minCount != maxCount)
Shinya Kitaoka 120a6e
    range = QObject::tr("%1-%2").arg(minCount).arg(maxCount);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    range = QObject::tr("%1").arg(minCount);
Shinya Kitaoka 120a6e
  return context->throwError(
Shinya Kitaoka 120a6e
      QObject::tr("Expected %1 argument(s) in %2, got %3")
Shinya Kitaoka 120a6e
          .arg(range)
Shinya Kitaoka 120a6e
          .arg(name)
Shinya Kitaoka 120a6e
          .arg(count));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QScriptValue checkArgumentCount(QScriptContext *context, const QString &name,
Shinya Kitaoka 120a6e
                                int count) {
Shinya Kitaoka 120a6e
  return checkArgumentCount(context, name, count, count);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QScriptValue checkColor(QScriptContext *context, const QString &colorName,
Shinya Kitaoka 120a6e
                        QColor &color) {
Shinya Kitaoka 120a6e
  color.setNamedColor(colorName);
Shinya Kitaoka 120a6e
  if (!color.isValid())
Shinya Kitaoka 120a6e
    return context->throwError(
Shinya Kitaoka 120a6e
        QObject::tr("%1 is not a valid color (valid color names are 'red', "
Shinya Kitaoka 120a6e
                    "'transparent', '#FF8800', ecc.)")
Shinya Kitaoka 120a6e
            .arg(colorName));
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return QScriptValue();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
void bindClass(QScriptEngine &engine, const QString &name) {
Shinya Kitaoka 120a6e
  const QMetaObject *metaObj = &T::staticMetaObject;
Shinya Kitaoka 120a6e
  QScriptValue ctor          = engine.newFunction(T::ctor);
Shinya Kitaoka 120a6e
  QScriptValue proto         = engine.newQMetaObject(metaObj, ctor);
Shinya Kitaoka 120a6e
  engine.globalObject().setProperty(name, proto);
Shinya Kitaoka 120a6e
  engine.setDefaultPrototype(qMetaTypeId<t *="">(), proto);</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename tp=""></typename>
Shinya Kitaoka 120a6e
QScriptValue qScriptValueFromQObject(QScriptEngine *engine, Tp const &qobject) {
Shinya Kitaoka 120a6e
  return engine->newQObject(qobject);
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename tp=""></typename>
Shinya Kitaoka 120a6e
void qScriptValueToQObject(const QScriptValue &value, Tp &qobject) {
Shinya Kitaoka 120a6e
  qobject = qobject_cast<tp>(value.toQObject());</tp>
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename tp=""></typename>
Shinya Kitaoka 120a6e
int qScriptRegisterQObjectMetaType(
Shinya Kitaoka 120a6e
    QScriptEngine *engine, const QScriptValue &prototype = QScriptValue()) {
Shinya Kitaoka 120a6e
  return qScriptRegisterMetaType<tp>(engine, qScriptValueFromQObject,</tp>
Shinya Kitaoka 120a6e
                                     qScriptValueToQObject, prototype);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class (t::*method)(qscriptcontext="" *)="" *,="" qscriptengine="" qscriptvalue="" t,=""></class>
Shinya Kitaoka 120a6e
class Dummy {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  static QScriptValue dummy(QScriptContext *context, QScriptEngine *engine) {
Shinya Kitaoka 120a6e
    T *obj = qscriptvalue_cast<t *="">(context->thisObject());</t>
Shinya Kitaoka 120a6e
    return (obj->*Method)(context, engine);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Campbell Barton b3bd84
static void deffoo(QScriptEngine &engine) {
Shinya Kitaoka 120a6e
  QScriptValue f = engine.newFunction(
Shinya Kitaoka 120a6e
      Dummy<toonzrasterconverter, &toonzrasterconverter::convert="">::dummy);</toonzrasterconverter,>
Shinya Kitaoka 120a6e
  engine.globalObject()
Shinya Kitaoka 120a6e
      .property("ToonzRasterConverter")
Shinya Kitaoka 120a6e
      .setProperty("convert", f);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void bindAll(QScriptEngine &engine) {
Shinya Kitaoka 120a6e
  bindClass(engine, "Image");
Shinya Kitaoka 120a6e
  bindClass<level>(engine, "Level");</level>
Shinya Kitaoka 120a6e
  bindClass<scene>(engine, "Scene");</scene>
Shinya Kitaoka 120a6e
  bindClass<transform>(engine, "Transform");</transform>
Shinya Kitaoka 120a6e
  bindClass<imagebuilder>(engine, "ImageBuilder");</imagebuilder>
Shinya Kitaoka 120a6e
  bindClass<outlinevectorizer>(engine, "OutlineVectorizer");</outlinevectorizer>
Shinya Kitaoka 120a6e
  bindClass<centerlinevectorizer>(engine, "CenterlineVectorizer");</centerlinevectorizer>
Shinya Kitaoka 120a6e
  bindClass<rasterizer>(engine, "Rasterizer");</rasterizer>
Shinya Kitaoka 120a6e
  bindClass<toonzrasterconverter>(engine, "ToonzRasterConverter");</toonzrasterconverter>
Shinya Kitaoka 120a6e
  deffoo(engine);
Shinya Kitaoka 120a6e
  bindClass<filepath>(engine, "FilePath");</filepath>
Shinya Kitaoka 120a6e
  bindClass<renderer>(engine, "Renderer");</renderer>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  qScriptRegisterQObjectMetaType<tscriptbinding::image *="">(&engine);</tscriptbinding::image>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  engine.evaluate("ToonzVersion='7.1'");
Shinya Kitaoka 120a6e
  // engine.evaluate("toonz={version:'7.0', }; script={version:'1.0'};");
Shinya Kitaoka 120a6e
  // engine.globalObject().setProperty("dir","C:\\Users\\gmt\\GMT to
Shinya Kitaoka 120a6e
  // vectorize\\");
Shinya Kitaoka 120a6e
  // QScriptValue test = engine.evaluate("function() { print('ok');
Shinya Kitaoka 120a6e
  // run(dir+'bu.js');}");
Shinya Kitaoka 120a6e
  // engine.globalObject().setProperty("test",test);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace TScriptBinding