Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tools/tool.h"
Toshihiro Shimizu 890ddd
#include "tools/cursors.h"
Toshihiro Shimizu 890ddd
#include "tproperty.h"
Toshihiro Shimizu 890ddd
#include "toonz/stageobjectutil.h"
Toshihiro Shimizu 890ddd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
#include "tgl.h"
Toshihiro Shimizu 890ddd
#include "tenv.h"
Jeremy Bullock 63e8da
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/tstageobjecttree.h"
Toshihiro Shimizu 890ddd
#include "toonz/tstageobjectspline.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshcolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcamera.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tools/toolhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tobjecthandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tscenehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tfxhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tstageobjectcmd.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "edittoolgadgets.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// For Qt translation support
Toshihiro Shimizu 890ddd
#include <qcoreapplication></qcoreapplication>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qdebug></qdebug>
shun_iwasawa 1fbdc9
#include <qapplication></qapplication>
shun_iwasawa 1fbdc9
#include <qdesktopwidget></qdesktopwidget>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// Scale Constraints
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace ScaleConstraints {
Shinya Kitaoka 120a6e
enum { None = 0, AspectRatio, Mass };
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TEnv::IntVar LockCenterX("EditToolLockCenterX", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockCenterY("EditToolLockCenterY", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockPositionX("EditToolLockPositionX", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockPositionY("EditToolLockPositionY", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockRotation("EditToolLockRotation", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockShearH("EditToolLockShearH", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockShearV("EditToolLockShearV", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockScaleH("EditToolLockScaleH", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockScaleV("EditToolLockScaleV", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockGlobalScale("EditToolLockGlobalScale", 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowEWNSposition("EditToolShowEWNSposition", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowZposition("EditToolShowZposition", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowSOposition("EditToolShowSOposition", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowRotation("EditToolShowRotation", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowGlobalScale("EditToolShowGlobalScale", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowHVscale("EditToolShowHVscale", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowShear("EditToolShowShear", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowCenterPosition("EditToolShowCenterPosition", 0);
Toshihiro Shimizu 890ddd
TEnv::StringVar Active("EditToolActiveAxis", "Position");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using EditToolGadgets::DragTool;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragCenterTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DragCenterTool final : public DragTool {
Shinya Kitaoka 120a6e
  TStageObjectId m_objId;
Shinya Kitaoka 120a6e
  int m_frame;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_lockCenterX;
Shinya Kitaoka 120a6e
  bool m_lockCenterY;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPointD m_firstPos;
Shinya Kitaoka 120a6e
  TPointD m_oldCenter;
Shinya Kitaoka 120a6e
  TPointD m_center;
Shinya Kitaoka 120a6e
  TAffine m_affine;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DragCenterTool(bool lockCenterX, bool lockCenterY)
Shinya Kitaoka 120a6e
      : m_objId(
Shinya Kitaoka 120a6e
            TTool::getApplication()->getCurrentTool()->getTool()->getObjectId())
Shinya Kitaoka 120a6e
      , m_frame(
Shinya Kitaoka 120a6e
            TTool::getApplication()->getCurrentTool()->getTool()->getFrame())
Shinya Kitaoka 120a6e
      , m_lockCenterX(lockCenterX)
Shinya Kitaoka 120a6e
      , m_lockCenterY(lockCenterY) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &) override {
Shinya Kitaoka 120a6e
    if (m_lockCenterX && m_lockCenterY) return;
Shinya Kitaoka 120a6e
    TXsheet *xsh =
Shinya Kitaoka 120a6e
        TTool::getApplication()->getCurrentTool()->getTool()->getXsheet();
Shinya Kitaoka 120a6e
    m_center = m_oldCenter = xsh->getCenter(m_objId, m_frame);
Shinya Kitaoka 120a6e
    m_firstPos             = pos;
Shinya Kitaoka 120a6e
    m_affine               = xsh->getPlacement(m_objId, m_frame).inv() *
Shinya Kitaoka 120a6e
               xsh->getParentPlacement(m_objId, m_frame);
Shinya Kitaoka 120a6e
    m_affine.a13 = m_affine.a23 = 0;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
shun-iwasawa bce58d
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override {
Shinya Kitaoka 120a6e
    if (m_lockCenterX && m_lockCenterY) return;
Shinya Kitaoka 120a6e
    double factor = 1.0 / Stage::inch;
shun-iwasawa bce58d
    // precise control with pressing Alt key
shun-iwasawa bce58d
    if (e.isAltPressed()) factor *= 0.1;
Shinya Kitaoka 120a6e
    TPointD delta = pos - m_firstPos;
Shinya Kitaoka 120a6e
    if (m_lockCenterX)
Shinya Kitaoka 120a6e
      delta = TPointD(0.0, delta.y);
Shinya Kitaoka 120a6e
    else if (m_lockCenterY)
shun-iwasawa bce58d
      delta = TPointD(delta.x, 0.0);
Shinya Kitaoka 120a6e
    m_center = m_oldCenter + (m_affine * delta) * factor;
Shinya Kitaoka 120a6e
    TTool::getApplication()
Shinya Kitaoka 120a6e
        ->getCurrentTool()
Shinya Kitaoka 120a6e
        ->getTool()
Shinya Kitaoka 120a6e
        ->getXsheet()
Shinya Kitaoka 120a6e
        ->setCenter(m_objId, m_frame, m_center);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  void leftButtonUp(const TPointD &pos, const TMouseEvent &) override {
Shinya Kitaoka 120a6e
    if ((m_lockCenterX && m_lockCenterY) || m_firstPos == pos) return;
Shinya Kitaoka 120a6e
    UndoStageObjectCenterMove *undo =
Shinya Kitaoka 120a6e
        new UndoStageObjectCenterMove(m_objId, m_frame, m_oldCenter, m_center);
Shinya Kitaoka 120a6e
    TTool::Application *app = TTool::getApplication();
Shinya Kitaoka 120a6e
    undo->setObjectHandle(app->getCurrentObject());
Shinya Kitaoka 120a6e
    undo->setXsheetHandle(app->getCurrentXsheet());
Shinya Kitaoka 120a6e
    TUndoManager::manager()->add(undo);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragChannelTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DragChannelTool : public DragTool {
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  TStageObjectValues m_before, m_after;
Shinya Kitaoka 120a6e
  bool m_globalKeyframesEnabled;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_isStarted;
Shinya Kitaoka 120a6e
  TPointD m_firstPos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DragChannelTool(TStageObject::Channel a0, bool globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      : m_globalKeyframesEnabled(globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      , m_isStarted(false)
Shinya Kitaoka 120a6e
      , m_firstPos() {
Shinya Kitaoka 120a6e
    TTool::Application *app = TTool::getApplication();
Shinya Kitaoka 120a6e
    m_before.setFrameHandle(app->getCurrentFrame());
Shinya Kitaoka 120a6e
    m_before.setObjectHandle(app->getCurrentObject());
Shinya Kitaoka 120a6e
    m_before.setXsheetHandle(app->getCurrentXsheet());
Shinya Kitaoka 120a6e
    m_before.add(a0);
Shinya Kitaoka 120a6e
    if (m_globalKeyframesEnabled) {
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_Angle);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_X);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_Y);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_Z);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_SO);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_ScaleX);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_ScaleY);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_Scale);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_Path);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_ShearX);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_ShearY);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    m_after = m_before;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  DragChannelTool(TStageObject::Channel a0, TStageObject::Channel a1,
Shinya Kitaoka 120a6e
                  bool globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      : m_globalKeyframesEnabled(globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      , m_isStarted(false)
Shinya Kitaoka 120a6e
      , m_firstPos() {
Shinya Kitaoka 120a6e
    TTool::Application *app = TTool::getApplication();
Shinya Kitaoka 120a6e
    m_before.setFrameHandle(app->getCurrentFrame());
Shinya Kitaoka 120a6e
    m_before.setObjectHandle(app->getCurrentObject());
Shinya Kitaoka 120a6e
    m_before.setXsheetHandle(app->getCurrentXsheet());
Shinya Kitaoka 120a6e
    m_before.add(a0);
Shinya Kitaoka 120a6e
    m_before.add(a1);
Shinya Kitaoka 120a6e
    if (m_globalKeyframesEnabled) {
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_Angle);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_X);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_Y);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_Z);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_SO);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_ScaleX);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_ScaleY);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_Scale);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_Path);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_ShearX);
Shinya Kitaoka 120a6e
      m_before.add(TStageObject::T_ShearY);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    m_after = m_before;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void enableGlobalKeyframes(bool enabled) override {
Shinya Kitaoka 120a6e
    m_globalKeyframesEnabled = enabled;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void start() {
Shinya Kitaoka 120a6e
    m_isStarted = true;
Shinya Kitaoka 120a6e
    m_before.updateValues();
Shinya Kitaoka 120a6e
    m_after = m_before;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPointD getCenter() {
Shinya Kitaoka 120a6e
    TTool *tool          = TTool::getApplication()->getCurrentTool()->getTool();
Shinya Kitaoka 120a6e
    TStageObjectId objId = tool->getObjectId();
Shinya Kitaoka 120a6e
    int frame            = tool->getFrame();
Shinya Kitaoka 120a6e
    TXsheet *xsh         = tool->getXsheet();
Shinya Kitaoka 120a6e
    return xsh->getParentPlacement(objId, frame).inv() *
Shinya Kitaoka 120a6e
           xsh->getPlacement(objId, frame) *
Shinya Kitaoka 120a6e
           (Stage::inch * xsh->getCenter(objId, frame));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double getOldValue(int index) const { return m_before.getValue(index); }
Shinya Kitaoka 120a6e
  double getValue(int index) const { return m_after.getValue(index); }
Shinya Kitaoka 120a6e
  void setValue(double v) {
Shinya Kitaoka 120a6e
    m_after.setValue(v);
Shinya Kitaoka 120a6e
    m_after.applyValues();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  void setValues(double v0, double v1) {
Shinya Kitaoka 120a6e
    m_after.setValues(v0, v1);
Shinya Kitaoka 120a6e
    m_after.applyValues();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonUp(const TPointD &pos, const TMouseEvent &) override {
Shinya Kitaoka 120a6e
    if (!m_isStarted || m_firstPos == pos)
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      m_isStarted = false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TTool::Application *app   = TTool::getApplication();
Shinya Kitaoka 120a6e
    UndoStageObjectMove *undo = new UndoStageObjectMove(m_before, m_after);
Shinya Kitaoka 120a6e
    undo->setObjectHandle(app->getCurrentObject());
Shinya Kitaoka 120a6e
    TUndoManager::manager()->add(undo);
Shinya Kitaoka 120a6e
    app->getCurrentScene()->setDirtyFlag(true);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragPositionTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DragPositionTool final : public DragChannelTool {
Shinya Kitaoka 120a6e
  bool m_lockPositionX;
Shinya Kitaoka 120a6e
  bool m_lockPositionY;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DragPositionTool(bool lockPositionX, bool lockPositionY,
Shinya Kitaoka 120a6e
                   bool globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      : DragChannelTool(TStageObject::T_X, TStageObject::T_Y,
Shinya Kitaoka 120a6e
                        globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      , m_lockPositionX(lockPositionX)
Shinya Kitaoka 120a6e
      , m_lockPositionY(lockPositionY) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &) override {
Shinya Kitaoka 120a6e
    if (m_lockPositionX && m_lockPositionY) return;
Shinya Kitaoka 120a6e
    start();
Shinya Kitaoka 120a6e
    m_firstPos = pos;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override {
Shinya Kitaoka 120a6e
    if (m_lockPositionX && m_lockPositionY) return;
Shinya Kitaoka 120a6e
    TPointD delta = pos - m_firstPos;
Shinya Kitaoka 120a6e
    if (m_lockPositionX)
Shinya Kitaoka 120a6e
      delta = TPointD(0, delta.y);
Shinya Kitaoka 120a6e
    else if (m_lockPositionY)
Shinya Kitaoka 120a6e
      delta = TPointD(delta.x, 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (e.isShiftPressed()) {
Shinya Kitaoka 120a6e
      if (fabs(delta.x) > fabs(delta.y))
Shinya Kitaoka 120a6e
        delta.y = 0;
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        delta.x = 0;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    double factor = 1.0 / Stage::inch;
shun-iwasawa bce58d
    // precise control with pressing Alt key
shun-iwasawa bce58d
    if (e.isAltPressed()) factor *= 0.1;
Shinya Kitaoka 120a6e
    setValues(getOldValue(0) + delta.x * factor,
Shinya Kitaoka 120a6e
              getOldValue(1) + delta.y * factor);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragSplinePositionTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DragSplinePositionTool final : public DragChannelTool {
Shinya Kitaoka 120a6e
  const TStroke *m_spline;
Shinya Kitaoka 120a6e
  std::vector<double> m_lengthAtCPs;</double>
Shinya Kitaoka 120a6e
  double m_offset;
Shinya Kitaoka 120a6e
  double m_splineLength;
Shinya Kitaoka 120a6e
  double m_tolerance;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
shun_iwasawa 1fbdc9
  DragSplinePositionTool(const TStroke *spline, bool globalKeyframesEnabled,
shun_iwasawa 1fbdc9
                         double pixelSize)
Shinya Kitaoka 120a6e
      : DragChannelTool(TStageObject::T_Path, globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      , m_spline(spline)
Shinya Kitaoka 120a6e
      , m_offset(0.0)
Shinya Kitaoka 120a6e
      , m_splineLength(0)
shun_iwasawa 1fbdc9
      , m_tolerance(pixelSize * 10.0) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double getLengthAtPos(const TPointD &pos) const {
Shinya Kitaoka 120a6e
    assert(m_spline);
Shinya Kitaoka 120a6e
    double t = m_spline->getW(pos);
Shinya Kitaoka 120a6e
    return m_spline->getLength(t);
Shinya Kitaoka 120a6e
    /*
Shinya Kitaoka 120a6e
double length = m_spline->getLength();
Shinya Kitaoka 120a6e
if(length>0) return 100 * m_spline->getLength(t) / length;
Shinya Kitaoka 120a6e
else return 0.0;
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double paramValueToLength(double s) const {
Shinya Kitaoka 120a6e
    return s * m_splineLength * 0.01;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  double lengthToParamValue(double len) const {
Shinya Kitaoka 120a6e
    if (m_splineLength > 0)
Shinya Kitaoka 120a6e
      return 100 * len / m_splineLength;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      return 0.0;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &) override {
Shinya Kitaoka 120a6e
    m_firstPos = pos;
Shinya Kitaoka 120a6e
    start();
Shinya Kitaoka 120a6e
    assert(m_spline);
Shinya Kitaoka 120a6e
    m_splineLength = m_spline->getLength();
Shinya Kitaoka 120a6e
    m_lengthAtCPs.clear();
Shinya Kitaoka 120a6e
    int n = m_spline->getControlPointCount();
Shinya Kitaoka 120a6e
    for (int i = 0; i < n; i += 4)
Shinya Kitaoka 120a6e
      m_lengthAtCPs.push_back(m_spline->getLengthAtControlPoint(i));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_offset = paramValueToLength(getOldValue(0)) - getLengthAtPos(pos);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool snapLengthToControlPoint(double &len) const {
Shinya Kitaoka 120a6e
    int n = (int)m_lengthAtCPs.size();
Shinya Kitaoka 120a6e
    if (n <= 0) return false;
Shinya Kitaoka 120a6e
    double cpLen = len;
Shinya Kitaoka 120a6e
    int k        = 0;
Shinya Kitaoka 120a6e
    while (k < n && m_lengthAtCPs[k] <= len) k++;
Shinya Kitaoka 120a6e
    if (k >= n) {
Shinya Kitaoka 120a6e
      // len is >= all CP lengths. The closest is the last
Shinya Kitaoka 120a6e
      cpLen = m_lengthAtCPs.back();
Shinya Kitaoka 120a6e
    } else if (k == 0) {
Shinya Kitaoka 120a6e
      // len is < all CP lengths. the closest is the first
Shinya Kitaoka 120a6e
      cpLen = m_lengthAtCPs.front();
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      // m_lengthAtCPs[k-1]<=len && len < m_lengthAtCPs[k]
Shinya Kitaoka 120a6e
      double cpLen0 = m_lengthAtCPs[k - 1];
Shinya Kitaoka 120a6e
      double cpLen1 = m_lengthAtCPs[k];
Shinya Kitaoka 120a6e
      assert(cpLen0 <= len && len < cpLen1);
Shinya Kitaoka 120a6e
      cpLen = (len - cpLen0 < cpLen1 - len) ? cpLen0 : cpLen1;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (fabs(cpLen - len) < m_tolerance) {
Shinya Kitaoka 120a6e
      len = cpLen;
Shinya Kitaoka 120a6e
      return true;
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      return false;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &) override {
Shinya Kitaoka 120a6e
    double len = tcrop(getLengthAtPos(pos) + m_offset, 0.0, m_splineLength);
Shinya Kitaoka 120a6e
    snapLengthToControlPoint(len);
Shinya Kitaoka 120a6e
    setValue(lengthToParamValue(len));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragRotationTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DragRotationTool final : public DragChannelTool {
Shinya Kitaoka 120a6e
  TPointD m_lastPos;
Shinya Kitaoka 120a6e
  TPointD m_center;
Shinya Kitaoka 120a6e
  bool m_lockRotation;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DragRotationTool(bool lockRotation, bool globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      : DragChannelTool(TStageObject::T_Angle, globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      , m_lockRotation(lockRotation) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &) override {
Shinya Kitaoka 120a6e
    if (m_lockRotation) return;
Shinya Kitaoka 120a6e
    m_firstPos = pos;
Shinya Kitaoka 120a6e
    m_lastPos  = pos;
Shinya Kitaoka 120a6e
    m_center   = getCenter();
Shinya Kitaoka 120a6e
    start();
Shinya Kitaoka 120a6e
  }
shun-iwasawa bce58d
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override {
Shinya Kitaoka 120a6e
    if (m_lockRotation) return;
Shinya Kitaoka 120a6e
    TPointD a = m_lastPos - m_center;
Shinya Kitaoka 120a6e
    TPointD b = pos - m_center;
Shinya Kitaoka 120a6e
    m_lastPos = pos;
Shinya Kitaoka 120a6e
    /*
Shinya Kitaoka 120a6e
if(cameraFlag)
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
// m_viewer->updateViewMatrix();
Shinya Kitaoka 120a6e
b = m_viewer->mouseToTool(gb) - m_curCenter;
Shinya Kitaoka 120a6e
a = m_viewer->mouseToTool(gc) - m_curCenter;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    double a2 = norm2(a), b2 = norm2(b);
Shinya Kitaoka 120a6e
    const double eps = 1e-8;
Shinya Kitaoka 120a6e
    if (a2 < eps || b2 < eps) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    double dang = asin(cross(a, b) / sqrt(a2 * b2)) * M_180_PI;
shun-iwasawa bce58d
    // precise control with pressing Alt key
shun-iwasawa bce58d
    if (e.isAltPressed()) dang *= 0.1;
Shinya Kitaoka 120a6e
    setValue(getValue(0) + dang);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragIsotropicScaleTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DragIsotropicScaleTool final : public DragChannelTool {
Shinya Kitaoka 120a6e
  TPointD m_center;
Shinya Kitaoka 120a6e
  double m_r0;
Shinya Kitaoka 120a6e
  bool m_lockGlobalScale;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DragIsotropicScaleTool(bool lockGlobalScale, bool globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      : DragChannelTool(TStageObject::T_Scale, globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      , m_lockGlobalScale(lockGlobalScale)
Shinya Kitaoka 120a6e
      , m_r0(0) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &) override {
Shinya Kitaoka 120a6e
    if (m_lockGlobalScale) return;
Shinya Kitaoka 120a6e
    m_firstPos = pos;
Shinya Kitaoka 120a6e
    m_center   = getCenter();
Shinya Kitaoka 120a6e
    start();
Shinya Kitaoka 120a6e
    m_r0 = norm(m_firstPos - m_center);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override {
Shinya Kitaoka 120a6e
    if (m_lockGlobalScale) return;
Shinya Kitaoka 120a6e
    if (m_r0 < 0.001) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // TPointD a = m_firstPos - m_center;
Shinya Kitaoka 120a6e
    double r1 = norm(pos - m_center);
Shinya Kitaoka 120a6e
    if (r1 < 0.0001) return;
shun-iwasawa bce58d
    // precise control with pressing Alt key
shun-iwasawa bce58d
    if (e.isAltPressed()) r1 = m_r0 + (r1 - m_r0) * 0.1;
Shinya Kitaoka 120a6e
    setValue(getOldValue(0) * r1 / m_r0);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragScaleTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DragScaleTool final : public DragChannelTool {
Shinya Kitaoka 120a6e
  TPointD m_center;
Shinya Kitaoka 120a6e
  int m_constraint;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_lockScaleH;
Shinya Kitaoka 120a6e
  bool m_lockScaleV;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DragScaleTool(int constraint, bool lockScaleH, bool lockScaleV,
Shinya Kitaoka 120a6e
                bool globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      : DragChannelTool(TStageObject::T_ScaleX, TStageObject::T_ScaleY,
Shinya Kitaoka 120a6e
                        globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      , m_constraint(constraint)
Shinya Kitaoka 120a6e
      , m_lockScaleH(lockScaleH)
Shinya Kitaoka 120a6e
      , m_lockScaleV(lockScaleV) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &) override {
Shinya Kitaoka 120a6e
    if (m_lockScaleH && m_lockScaleV) return;
Shinya Kitaoka 120a6e
    m_firstPos = pos;
Shinya Kitaoka 120a6e
    m_center   = getCenter();
Shinya Kitaoka 120a6e
    start();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override {
Shinya Kitaoka 120a6e
    if (m_lockScaleH && m_lockScaleV) return;
Shinya Kitaoka 120a6e
    TPointD center = m_center + TPointD(40, 40);
Shinya Kitaoka 120a6e
    TPointD a      = m_firstPos - center;
Shinya Kitaoka 120a6e
    TPointD b      = pos - center;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    const double eps = 1e-8;
Shinya Kitaoka 120a6e
    if (norm2(a) < eps || norm2(b) < eps) return;
Shinya Kitaoka 120a6e
shun-iwasawa bce58d
    double fx = b.x / a.x;
Rozhuk Ivan 823a31
    if (fabs(fx) > 1) fx = tsign(fx) * sqrt(std::abs(fx));
shun-iwasawa bce58d
    double fy = b.y / a.y;
Rozhuk Ivan 823a31
    if (fabs(fy) > 1) fy = tsign(fy) * sqrt(std::abs(fy));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int constraint = m_constraint;
Shinya Kitaoka 120a6e
    if (constraint == ScaleConstraints::None && e.isShiftPressed())
Shinya Kitaoka 120a6e
      constraint = ScaleConstraints::AspectRatio;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (constraint == ScaleConstraints::AspectRatio) {
Shinya Kitaoka 120a6e
      TPointD c = pos - m_firstPos;
Shinya Kitaoka 120a6e
      if (fabs(c.x) > fabs(c.y))
Shinya Kitaoka 120a6e
        fy = fx;
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        fx = fy;
Shinya Kitaoka 120a6e
    } else if (constraint == ScaleConstraints::Mass) {
Shinya Kitaoka 120a6e
      double bxay = b.x * a.y;
Shinya Kitaoka 120a6e
      double byax = b.y * a.x;
Shinya Kitaoka 120a6e
      if (fabs(bxay) < eps || fabs(byax) < eps) return;
Shinya Kitaoka 120a6e
      fx = bxay / byax;
Shinya Kitaoka 120a6e
      fy = byax / bxay;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (fabs(fx) > eps && fabs(fy) > eps) {
shun-iwasawa bce58d
      double oldv0 = getOldValue(0);
shun-iwasawa bce58d
      double oldv1 = getOldValue(1);
Shinya Kitaoka 120a6e
      if (fabs(oldv0) < 0.001) oldv0 = 0.001;
Shinya Kitaoka 120a6e
      if (fabs(oldv1) < 0.001) oldv1 = 0.001;
shun-iwasawa bce58d
      // precise control with pressing Alt key
shun-iwasawa bce58d
      if (e.isAltPressed()) {
shun-iwasawa bce58d
        fx = 1.0 + (fx - 1.0) * 0.1;
shun-iwasawa bce58d
        fy = 1.0 + (fy - 1.0) * 0.1;
shun-iwasawa bce58d
      }
Shinya Kitaoka 120a6e
      double valueX = oldv0 * fx;
Shinya Kitaoka 120a6e
      double valueY = oldv1 * fy;
Shinya Kitaoka 120a6e
      if (m_lockScaleH)
Shinya Kitaoka 120a6e
        valueX = oldv0;
Shinya Kitaoka 120a6e
      else if (m_lockScaleV)
Shinya Kitaoka 120a6e
        valueY = oldv1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      setValues(valueX, valueY);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragShearTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DragShearTool final : public DragChannelTool {
Shinya Kitaoka 120a6e
  TPointD m_center;
Shinya Kitaoka 120a6e
  bool m_lockShearH;
Shinya Kitaoka 120a6e
  bool m_lockShearV;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DragShearTool(bool lockShearH, bool lockShearV, bool globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      : DragChannelTool(TStageObject::T_ShearX, TStageObject::T_ShearY,
Shinya Kitaoka 120a6e
                        globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      , m_lockShearH(lockShearH)
Shinya Kitaoka 120a6e
      , m_lockShearV(lockShearV) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &) override {
Shinya Kitaoka 120a6e
    if (m_lockShearH && m_lockShearV) return;
Shinya Kitaoka 120a6e
    m_firstPos = pos;
Shinya Kitaoka 120a6e
    m_center   = getCenter();
Shinya Kitaoka 120a6e
    start();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override {
Shinya Kitaoka 120a6e
    if (m_lockShearH && m_lockShearV) return;
Shinya Kitaoka 120a6e
    TPointD a = m_firstPos - m_center;
Shinya Kitaoka 120a6e
    TPointD b = pos - m_center;
Shinya Kitaoka 120a6e
    double fx = a.x - b.x;
Shinya Kitaoka 120a6e
    double fy = b.y - a.y;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (m_lockShearH)
Shinya Kitaoka 120a6e
      fx = 0;
Shinya Kitaoka 120a6e
    else if (m_lockShearV)
Shinya Kitaoka 120a6e
      fy = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (e.isShiftPressed()) {
Shinya Kitaoka 120a6e
      if (fabs(fx) > fabs(fy))
Shinya Kitaoka 120a6e
        fy = 0;
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        fx = 0;
Shinya Kitaoka 120a6e
    }
shun-iwasawa bce58d
    // precise control with pressing Alt key
shun-iwasawa bce58d
    if (e.isAltPressed()) {
shun-iwasawa bce58d
      fx *= 0.1;
shun-iwasawa bce58d
      fy *= 0.1;
shun-iwasawa bce58d
    }
Shinya Kitaoka 120a6e
    setValues(getOldValue(0) + 0.01 * fx, getOldValue(1) + 0.01 * fy);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragZTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DragZTool final : public DragChannelTool {
shun_iwasawa bc352c
  TPointD m_lastPos;
Shinya Kitaoka 120a6e
  TTool::Viewer *m_viewer;
Shinya Kitaoka 120a6e
  double m_dz;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DragZTool(TTool::Viewer *viewer, bool globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      : DragChannelTool(TStageObject::T_Z, globalKeyframesEnabled)
Shinya Kitaoka 120a6e
      , m_viewer(viewer) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override {
Shinya Kitaoka 120a6e
    m_lastPos  = e.m_pos;
Shinya Kitaoka 120a6e
    m_firstPos = pos;
Shinya Kitaoka 120a6e
    m_dz       = 0;
Shinya Kitaoka 120a6e
    start();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override {
Shinya Kitaoka 120a6e
    double dz = m_viewer->projectToZ(e.m_pos - m_lastPos);
shun-iwasawa bce58d
    // precise control with pressing Alt key
shun-iwasawa bce58d
    if (e.isAltPressed()) dz *= 0.1;
Shinya Kitaoka 120a6e
    m_lastPos = e.m_pos;
Shinya Kitaoka 120a6e
    if (dz != 0.0) {
Shinya Kitaoka 120a6e
      m_dz += dz;
Shinya Kitaoka 120a6e
      setValue(getOldValue(0) + m_dz);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
shun-iwasawa d464a1
bool hasVisibleChildColumn(const TStageObject *obj, const TXsheet *xsh) {
shun-iwasawa 58f115
  if (!(obj->getId().isColumn())) return false;  // just in case
shun-iwasawa 58f115
  TXshColumn *column = xsh->getColumn(obj->getId().getIndex());
shun-iwasawa 58f115
  if (!column) return false;
shun-iwasawa 58f115
  if (column->isCamstandVisible()) return true;
shun-iwasawa d464a1
  for (const auto child : obj->getChildren()) {
shun-iwasawa d464a1
    if (hasVisibleChildColumn(child, xsh)) return true;
shun-iwasawa d464a1
  }
shun-iwasawa d464a1
  return false;
shun-iwasawa d464a1
}
shun-iwasawa d464a1
Toshihiro Shimizu 890ddd
//=============================================================================
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// EditTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class EditTool final : public TTool {
Shinya Kitaoka 120a6e
  Q_DECLARE_TR_FUNCTIONS(EditTool)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  DragTool *m_dragTool;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool m_firstTime;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  enum {
Shinya Kitaoka 120a6e
    None        = -1,
Shinya Kitaoka 120a6e
    Translation = 1,
Shinya Kitaoka 120a6e
    Rotation,
Shinya Kitaoka 120a6e
    Scale,
Shinya Kitaoka 120a6e
    ScaleX,
Shinya Kitaoka 120a6e
    ScaleY,
Shinya Kitaoka 120a6e
    ScaleXY,
Shinya Kitaoka 120a6e
    Center,
Shinya Kitaoka 120a6e
    ZTranslation,
Shinya Kitaoka 120a6e
    Shear,
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // DragInfo m_dragInfo;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPointD m_lastPos;
Shinya Kitaoka 120a6e
  TPointD m_curPos;
Shinya Kitaoka 120a6e
  TPointD m_firstPos;
Shinya Kitaoka 120a6e
  TPointD m_curCenter;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool m_active;
Shinya Kitaoka 120a6e
  bool m_keyFrameAdded;
Shinya Kitaoka 120a6e
  int m_what;
Shinya Kitaoka 120a6e
  int m_highlightedDevice;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double m_oldValues[2];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double m_currentScaleFactor;
Shinya Kitaoka 120a6e
  FxGadgetController *m_fxGadgetController;
Shinya Kitaoka 120a6e
shun-iwasawa bce58d
  bool m_isAltPressed;
shun-iwasawa bce58d
Shinya Kitaoka 120a6e
  TEnumProperty m_scaleConstraint;
Shinya Kitaoka 120a6e
  TEnumProperty m_autoSelect;
Shinya Kitaoka 120a6e
  TBoolProperty m_globalKeyframes;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TBoolProperty m_lockCenterX;
Shinya Kitaoka 120a6e
  TBoolProperty m_lockCenterY;
Shinya Kitaoka 120a6e
  TBoolProperty m_lockPositionX;
Shinya Kitaoka 120a6e
  TBoolProperty m_lockPositionY;
Shinya Kitaoka 120a6e
  TBoolProperty m_lockRotation;
Shinya Kitaoka 120a6e
  TBoolProperty m_lockShearH;
Shinya Kitaoka 120a6e
  TBoolProperty m_lockShearV;
Shinya Kitaoka 120a6e
  TBoolProperty m_lockScaleH;
Shinya Kitaoka 120a6e
  TBoolProperty m_lockScaleV;
Shinya Kitaoka 120a6e
  TBoolProperty m_lockGlobalScale;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TBoolProperty m_showEWNSposition;
Shinya Kitaoka 120a6e
  TBoolProperty m_showZposition;
Shinya Kitaoka 120a6e
  TBoolProperty m_showSOposition;
Shinya Kitaoka 120a6e
  TBoolProperty m_showRotation;
Shinya Kitaoka 120a6e
  TBoolProperty m_showGlobalScale;
Shinya Kitaoka 120a6e
  TBoolProperty m_showHVscale;
Shinya Kitaoka 120a6e
  TBoolProperty m_showShear;
Shinya Kitaoka 120a6e
  TBoolProperty m_showCenterPosition;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TEnumProperty m_activeAxis;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPropertyGroup m_prop;
Toshihiro Shimizu 890ddd
shun-iwasawa 59484b
  void drawMainHandle();
shun-iwasawa 59484b
  void onEditAllLeftButtonDown(TPointD &pos, const TMouseEvent &e);
shun-iwasawa 59484b
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  EditTool();
Shinya Kitaoka 120a6e
  ~EditTool();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  ToolType getToolType() const override { return TTool::ColumnTool; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool doesApply() const;  // ritorna vero se posso deformare l'oggetto corrente
Shinya Kitaoka 120a6e
  void saveOldValues();
shun-iwasawa d464a1
  bool transformEnabled() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const TStroke *getSpline() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void rotate();
Shinya Kitaoka 120a6e
  void move();
Shinya Kitaoka 120a6e
  void moveCenter();
Shinya Kitaoka 120a6e
  void scale();
Shinya Kitaoka 120a6e
  void isoScale();
Shinya Kitaoka 120a6e
  void squeeze();
Shinya Kitaoka 120a6e
  void shear(const TPointD &pos, bool single);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void updateTranslation() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &) override;
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &) override;
Shinya Kitaoka 473e70
  void leftButtonUp(const TPointD &pos, const TMouseEvent &) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void mouseMove(const TPointD &, const TMouseEvent &e) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void draw() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void transform(const TAffine &aff);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void onActivate() override;
Shinya Kitaoka 473e70
  void onDeactivate() override;
Shinya Kitaoka 473e70
  bool onPropertyChanged(std::string propertyName) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void computeBBox();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  int getCursorId() const override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TPropertyGroup *getProperties(int targetType) override { return &m_prop; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void updateMatrix() override {
Shinya Kitaoka 120a6e
    setMatrix(
Shinya Kitaoka 120a6e
        getCurrentObjectParentMatrix2());  // getCurrentObjectParentMatrix());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void drawText(const TPointD &p, double unit, std::string text);
shun-iwasawa d464a1
shun-iwasawa d464a1
  QString updateEnabled(int rowIndex, int columnIndex) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
EditTool::EditTool()
Shinya Kitaoka 120a6e
    : TTool("T_Edit")
Shinya Kitaoka 120a6e
    , m_active(false)
Shinya Kitaoka 120a6e
    , m_what(Translation)
Shinya Kitaoka 120a6e
    , m_highlightedDevice(None)
Shinya Kitaoka 120a6e
    , m_currentScaleFactor(1)
Shinya Kitaoka 120a6e
    , m_fxGadgetController(0)
Shinya Kitaoka 120a6e
    , m_keyFrameAdded(false)
Shinya Kitaoka 120a6e
    , m_scaleConstraint("Scale Constraint:")  // W_ToolOptions_ScaleConstraint
Shinya Kitaoka 120a6e
    , m_autoSelect("Auto Select Column")      // W_ToolOptions_AutoSelect
Shinya Kitaoka 120a6e
    , m_globalKeyframes("Global Key", false)  // W_ToolsOptions_GlobalKeyframes
c7649c
    , m_lockCenterX("Lock Center X", false)
c7649c
    , m_lockCenterY("Lock Center Y", false)
c7649c
    , m_lockPositionX("Lock Position X", false)
c7649c
    , m_lockPositionY("Lock Position Y", false)
Shinya Kitaoka 120a6e
    , m_lockRotation("Lock Rotation", false)
Shinya Kitaoka 120a6e
    , m_lockShearH("Lock Shear H", false)
Shinya Kitaoka 120a6e
    , m_lockShearV("Lock Shear V", false)
Shinya Kitaoka 120a6e
    , m_lockScaleH("Lock Scale H", false)
Shinya Kitaoka 120a6e
    , m_lockScaleV("Lock Scale V", false)
Shinya Kitaoka 120a6e
    , m_lockGlobalScale("Lock Global Scale", false)
c7649c
    , m_showEWNSposition("X and Y Positions", true)
Shinya Kitaoka 120a6e
    , m_showZposition("Z Position", true)
Shinya Kitaoka 120a6e
    , m_showSOposition("SO", true)
Shinya Kitaoka 120a6e
    , m_showRotation("Rotation", true)
Shinya Kitaoka 120a6e
    , m_showGlobalScale("Global Scale", true)
Shinya Kitaoka 120a6e
    , m_showHVscale("Horizontal and Vertical Scale", true)
Shinya Kitaoka 120a6e
    , m_showShear("Shear", true)
Shinya Kitaoka 120a6e
    , m_showCenterPosition("Center Position", true)
Shinya Kitaoka 120a6e
    , m_dragTool(0)
Shinya Kitaoka 120a6e
    , m_firstTime(true)
shun-iwasawa bce58d
    , m_activeAxis("Active Axis")
shun-iwasawa bce58d
    , m_isAltPressed(false) {
Shinya Kitaoka 120a6e
  bind(TTool::AllTargets);
Shinya Kitaoka 120a6e
  m_prop.bind(m_scaleConstraint);
Shinya Kitaoka 120a6e
  m_prop.bind(m_autoSelect);
Shinya Kitaoka 120a6e
  m_prop.bind(m_globalKeyframes);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_prop.bind(m_lockCenterX);
Shinya Kitaoka 120a6e
  m_prop.bind(m_lockCenterY);
Shinya Kitaoka 120a6e
  m_prop.bind(m_lockPositionX);
Shinya Kitaoka 120a6e
  m_prop.bind(m_lockPositionY);
Shinya Kitaoka 120a6e
  m_prop.bind(m_lockRotation);
Shinya Kitaoka 120a6e
  m_prop.bind(m_lockShearH);
Shinya Kitaoka 120a6e
  m_prop.bind(m_lockShearV);
Shinya Kitaoka 120a6e
  m_prop.bind(m_lockScaleH);
Shinya Kitaoka 120a6e
  m_prop.bind(m_lockScaleV);
Shinya Kitaoka 120a6e
  m_prop.bind(m_lockGlobalScale);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_prop.bind(m_showEWNSposition);
Shinya Kitaoka 120a6e
  m_prop.bind(m_showZposition);
Shinya Kitaoka 120a6e
  m_prop.bind(m_showSOposition);
Shinya Kitaoka 120a6e
  m_prop.bind(m_showRotation);
Shinya Kitaoka 120a6e
  m_prop.bind(m_showGlobalScale);
Shinya Kitaoka 120a6e
  m_prop.bind(m_showHVscale);
Shinya Kitaoka 120a6e
  m_prop.bind(m_showShear);
Shinya Kitaoka 120a6e
  m_prop.bind(m_showCenterPosition);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_scaleConstraint.addValue(L"None");
Shinya Kitaoka 120a6e
  m_scaleConstraint.addValue(L"A/R");
Shinya Kitaoka 120a6e
  m_scaleConstraint.addValue(L"Mass");
Shinya Kitaoka 120a6e
  m_scaleConstraint.setValue(L"None");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_autoSelect.addValue(L"None");
Shinya Kitaoka 120a6e
  m_autoSelect.addValue(L"Column");
Shinya Kitaoka 120a6e
  m_autoSelect.addValue(L"Pegbar");
Shinya Kitaoka 120a6e
  m_autoSelect.setValue(L"None");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_globalKeyframes.setId("GlobalKey");
Shinya Kitaoka 120a6e
  m_autoSelect.setId("AutoSelect");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_prop.bind(m_activeAxis);
shun-iwasawa df7bb0
  m_activeAxis.addValue(L"Position", "edit_position");
shun-iwasawa df7bb0
  m_activeAxis.addValue(L"Rotation", "edit_rotation");
shun-iwasawa df7bb0
  m_activeAxis.addValue(L"Scale", "edit_scale");
shun-iwasawa df7bb0
  m_activeAxis.addValue(L"Shear", "edit_shear");
shun-iwasawa df7bb0
  m_activeAxis.addValue(L"Center", "edit_center");
shun-iwasawa df7bb0
  m_activeAxis.addValue(L"All", "edit_all");
Shinya Kitaoka 120a6e
  m_activeAxis.setValue(L"Position");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_activeAxis.setId("EditToolActiveAxis");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
EditTool::~EditTool() {
Shinya Kitaoka 120a6e
  delete m_dragTool;
Shinya Kitaoka 120a6e
  delete m_fxGadgetController;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void EditTool::updateTranslation() {
Shinya Kitaoka 120a6e
  m_scaleConstraint.setQStringName(tr("Scale Constraint:"));
shun-iwasawa df7bb0
  m_scaleConstraint.setItemUIName(L"None", tr("None"));
shun-iwasawa df7bb0
  m_scaleConstraint.setItemUIName(L"A/R", tr("A/R"));
shun-iwasawa df7bb0
  m_scaleConstraint.setItemUIName(L"Mass", tr("Mass"));
shun-iwasawa df7bb0
Shinya Kitaoka 120a6e
  m_autoSelect.setQStringName(tr("Auto Select Column"));
shun-iwasawa df7bb0
  m_autoSelect.setItemUIName(L"None", tr("None"));
shun-iwasawa df7bb0
  m_autoSelect.setItemUIName(L"Column", tr("Column"));
shun-iwasawa df7bb0
  m_autoSelect.setItemUIName(L"Pegbar", tr("Pegbar"));
shun-iwasawa df7bb0
Shinya Kitaoka 120a6e
  m_globalKeyframes.setQStringName(tr("Global Key"));
c7649c
  m_lockCenterX.setQStringName(tr("Lock Center X"));
c7649c
  m_lockCenterY.setQStringName(tr("Lock Center Y"));
c7649c
  m_lockPositionX.setQStringName(tr("Lock Position X"));
c7649c
  m_lockPositionY.setQStringName(tr("Lock Position Y"));
Shinya Kitaoka 120a6e
  m_lockRotation.setQStringName(tr("Lock Rotation"));
Shinya Kitaoka 120a6e
  m_lockShearH.setQStringName(tr("Lock Shear H"));
Shinya Kitaoka 120a6e
  m_lockShearV.setQStringName(tr("Lock Shear V"));
Shinya Kitaoka 120a6e
  m_lockScaleH.setQStringName(tr("Lock Scale H"));
Shinya Kitaoka 120a6e
  m_lockScaleV.setQStringName(tr("Lock Scale V"));
Shinya Kitaoka 120a6e
  m_lockGlobalScale.setQStringName(tr("Lock Global Scale"));
c7649c
  m_showEWNSposition.setQStringName(tr("X and Y Positions"));
Shinya Kitaoka 120a6e
  m_showZposition.setQStringName(tr("Z Position"));
Shinya Kitaoka 120a6e
  m_showSOposition.setQStringName(tr("SO"));
Shinya Kitaoka 120a6e
  m_showRotation.setQStringName(tr("Rotation"));
Shinya Kitaoka 120a6e
  m_showGlobalScale.setQStringName(tr("Global Scale"));
Shinya Kitaoka 120a6e
  m_showHVscale.setQStringName(tr("Horizontal and Vertical Scale"));
Shinya Kitaoka 120a6e
  m_showShear.setQStringName(tr("Shear"));
Shinya Kitaoka 120a6e
  m_showCenterPosition.setQStringName(tr("Center Position"));
shun-iwasawa df7bb0
Shinya Kitaoka 120a6e
  m_activeAxis.setQStringName(tr("Active Axis"));
shun-iwasawa df7bb0
  m_activeAxis.setItemUIName(L"Position", tr("Position"));
shun-iwasawa df7bb0
  m_activeAxis.setItemUIName(L"Rotation", tr("Rotation"));
shun-iwasawa df7bb0
  m_activeAxis.setItemUIName(L"Scale", tr("Scale"));
shun-iwasawa df7bb0
  m_activeAxis.setItemUIName(L"Shear", tr("Shear"));
shun-iwasawa df7bb0
  m_activeAxis.setItemUIName(L"Center", tr("Center"));
shun-iwasawa e87e08
  m_activeAxis.setItemUIName(L"All", tr("All"));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool EditTool::doesApply() const {
Shinya Kitaoka 120a6e
  TXsheet *xsh = TTool::getApplication()->getCurrentXsheet()->getXsheet();
Shinya Kitaoka 120a6e
  assert(xsh);
Shinya Kitaoka 120a6e
  TStageObjectId objId =
Shinya Kitaoka 120a6e
      TTool::getApplication()->getCurrentObject()->getObjectId();
Shinya Kitaoka 120a6e
  if (objId.isColumn()) {
Shinya Kitaoka 120a6e
    TXshColumn *column = xsh->getColumn(objId.getIndex());
Shinya Kitaoka 120a6e
    if (column && column->getSoundColumn()) return false;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa d464a1
bool EditTool::transformEnabled() const {
shun-iwasawa d464a1
  // check if the column transformation is enabled
shun-iwasawa d464a1
  TXsheet *xsh = getXsheet();
shun-iwasawa d464a1
  TStageObjectId objId(getObjectId());
shun-iwasawa d464a1
  TStageObject *pegbar = xsh->getStageObject(objId);
shun-iwasawa d464a1
  return (!objId.isColumn() || hasVisibleChildColumn(pegbar, xsh));
shun-iwasawa d464a1
}
shun-iwasawa d464a1
shun-iwasawa d464a1
//-----------------------------------------------------------------------------
shun-iwasawa d464a1
Shinya Kitaoka 120a6e
const TStroke *EditTool::getSpline() const {
Shinya Kitaoka 120a6e
  TTool::Application *app    = TTool::getApplication();
Shinya Kitaoka 120a6e
  TXsheet *xsh               = app->getCurrentXsheet()->getXsheet();
Shinya Kitaoka 120a6e
  TStageObjectId objId       = app->getCurrentObject()->getObjectId();
Shinya Kitaoka 120a6e
  TStageObject *pegbar       = xsh->getStageObject(objId);
Shinya Kitaoka 120a6e
  TStageObjectSpline *spline = pegbar ? pegbar->getSpline() : 0;
Shinya Kitaoka 120a6e
  return spline ? spline->getStroke() : 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void EditTool::mouseMove(const TPointD &, const TMouseEvent &e) {
shun-iwasawa 59484b
  /*-- return while left dragging --*/
Shinya Kitaoka 120a6e
  if (e.isLeftButtonPressed()) return;
Shinya Kitaoka 120a6e
shun-iwasawa 59484b
  /*-- Pick screen only when the FxGadget is displayed or
shun-iwasawa 59484b
       when the "All" axis is selected. --*/
shun-iwasawa 59484b
  int selectedDevice = -1;
shun-iwasawa 59484b
  if (m_fxGadgetController->hasGadget() || m_activeAxis.getValue() == L"All")
shun-iwasawa 59484b
    selectedDevice = pick(e.m_pos);
Shinya Kitaoka 120a6e
shun-iwasawa 59484b
  if (selectedDevice <= 0) {
Shinya Kitaoka 120a6e
    selectedDevice = m_what;
Shinya Kitaoka 120a6e
    if (m_what == Translation && e.isCtrlPressed())
Shinya Kitaoka 120a6e
      selectedDevice = ZTranslation;
Shinya Kitaoka 120a6e
    else if (
Shinya Kitaoka 120a6e
        m_what == ZTranslation &&
Shinya Kitaoka 120a6e
        !e.isCtrlPressed()) /*--ここには、一度Z移動をした後に入る可能性がある--*/
Shinya Kitaoka 120a6e
      selectedDevice = Translation;
Shinya Kitaoka 120a6e
    else if (m_what == Scale && e.isCtrlPressed())
Shinya Kitaoka 120a6e
      selectedDevice = ScaleXY;
Shinya Kitaoka 120a6e
    else if (m_what == ScaleXY && !e.isCtrlPressed())
Shinya Kitaoka 120a6e
      selectedDevice = Scale;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (selectedDevice != m_highlightedDevice) {
Shinya Kitaoka 120a6e
    m_highlightedDevice = selectedDevice;
Shinya Kitaoka 120a6e
    m_fxGadgetController->selectById(selectedDevice);
Shinya Kitaoka 120a6e
    invalidate();
Shinya Kitaoka 120a6e
  }
shun-iwasawa bce58d
shun-iwasawa bce58d
  // for adding decoration to the cursor while pressing Alt key
shun-iwasawa bce58d
  m_isAltPressed = e.isAltPressed();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPoint ga, gb, gc;
Toshihiro Shimizu 890ddd
TPoint lastScreenPos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void EditTool::leftButtonDown(const TPointD &ppos, const TMouseEvent &e) {
Shinya Kitaoka 120a6e
  TPointD pos = ppos;
Shinya Kitaoka 120a6e
  /*-- Soundカラムの場合は何もしない --*/
Shinya Kitaoka 120a6e
  if (!doesApply()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_activeAxis.getValue() == L"Position")
Shinya Kitaoka 120a6e
    if (e.isCtrlPressed())
Shinya Kitaoka 120a6e
      m_what = ZTranslation;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      m_what = Translation;
Shinya Kitaoka 120a6e
  else if (m_activeAxis.getValue() == L"Scale")
Shinya Kitaoka 120a6e
    if (e.isCtrlPressed())
Shinya Kitaoka 120a6e
      m_what = ScaleXY;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      m_what = Scale;
shun-iwasawa 59484b
  else if (m_activeAxis.getValue() == L"All")
shun-iwasawa 59484b
    onEditAllLeftButtonDown(pos, e);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int scaleConstraint = 0;
Shinya Kitaoka 120a6e
  if (m_scaleConstraint.getValue() == L"A/R")
Shinya Kitaoka 120a6e
    scaleConstraint = ScaleConstraints::AspectRatio;
Shinya Kitaoka 120a6e
  else if (m_scaleConstraint.getValue() == L"Mass")
Shinya Kitaoka 120a6e
    scaleConstraint = ScaleConstraints::Mass;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(m_dragTool == 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_highlightedDevice >= 1000) {
Shinya Kitaoka 120a6e
    m_dragTool = m_fxGadgetController->createDragTool(m_highlightedDevice);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
shun-iwasawa d464a1
  if (!m_dragTool && transformEnabled()) {
Shinya Kitaoka 120a6e
    switch (m_what) {
Shinya Kitaoka 120a6e
    case Center:
Shinya Kitaoka 120a6e
      m_dragTool = new DragCenterTool(m_lockCenterX.getValue(),
Shinya Kitaoka 120a6e
                                      m_lockCenterY.getValue());
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    case Translation:
Shinya Kitaoka 120a6e
      if (const TStroke *spline = getSpline())
shun_iwasawa 1fbdc9
        m_dragTool = new DragSplinePositionTool(
shun_iwasawa 1fbdc9
            spline, m_globalKeyframes.getValue(), getPixelSize());
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        m_dragTool = new DragPositionTool(m_lockPositionX.getValue(),
Shinya Kitaoka 120a6e
                                          m_lockPositionY.getValue(),
Shinya Kitaoka 120a6e
                                          m_globalKeyframes.getValue());
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    case Rotation:
Shinya Kitaoka 120a6e
      m_dragTool = new DragRotationTool(m_lockRotation.getValue(),
Shinya Kitaoka 120a6e
                                        m_globalKeyframes.getValue());
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    case Scale:
Shinya Kitaoka 120a6e
      m_dragTool = new DragIsotropicScaleTool(m_lockGlobalScale.getValue(),
Shinya Kitaoka 120a6e
                                              m_globalKeyframes.getValue());
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    case ScaleXY:
Shinya Kitaoka 120a6e
      m_dragTool = new DragScaleTool(scaleConstraint, m_lockScaleH.getValue(),
Shinya Kitaoka 120a6e
                                     m_lockScaleV.getValue(),
Shinya Kitaoka 120a6e
                                     m_globalKeyframes.getValue());
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    case Shear:
Shinya Kitaoka 120a6e
      m_dragTool =
Shinya Kitaoka 120a6e
          new DragShearTool(m_lockShearH.getValue(), m_lockShearV.getValue(),
Shinya Kitaoka 120a6e
                            m_globalKeyframes.getValue());
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case ZTranslation:
Shinya Kitaoka 120a6e
      m_dragTool = new DragZTool(m_viewer, m_globalKeyframes.getValue());
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (m_dragTool) {
Shinya Kitaoka 120a6e
    m_dragTool->enableGlobalKeyframes(m_globalKeyframes.getValue());
Shinya Kitaoka 120a6e
    TUndoManager::manager()->beginBlock();
Shinya Kitaoka 120a6e
    m_dragTool->leftButtonDown(pos, e);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  invalidate();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 59484b
void EditTool::onEditAllLeftButtonDown(TPointD &pos, const TMouseEvent &e) {
shun-iwasawa 59484b
  int selectedDevice = pick(e.m_pos);
shun-iwasawa 59484b
  m_what             = selectedDevice >= 0 ? selectedDevice : Translation;
shun-iwasawa 59484b
shun-iwasawa 59484b
  if (selectedDevice < 0 && m_autoSelect.getValue() != L"None") {
shun-iwasawa 2d0135
    pos             = getMatrix() * pos;
shun-iwasawa 2d0135
    int columnIndex = getViewer()->posToColumnIndex(e.m_pos, 5.0, false);
shun-iwasawa 59484b
    if (columnIndex >= 0) {
shun-iwasawa 59484b
      TStageObjectId id      = TStageObjectId::ColumnId(columnIndex);
shun-iwasawa 59484b
      int currentColumnIndex = getColumnIndex();
shun-iwasawa 59484b
      TXsheet *xsh           = getXsheet();
shun-iwasawa 59484b
shun-iwasawa 59484b
      if (m_autoSelect.getValue() == L"Pegbar") {
shun-iwasawa 59484b
        TStageObjectId id2 = id;
shun-iwasawa 59484b
        while (!id2.isPegbar()) {
shun-iwasawa 59484b
          id2 = xsh->getStageObjectParent(id2);
shun-iwasawa 59484b
          if (!id2.isColumn() && !id2.isPegbar()) break;
shun-iwasawa 59484b
        }
shun-iwasawa 59484b
        if (id2.isPegbar()) id = id2;
shun-iwasawa 59484b
      }
shun-iwasawa 59484b
      if (id.isColumn()) {
shun-iwasawa 59484b
        if (columnIndex >= 0 && columnIndex != currentColumnIndex) {
shun-iwasawa 59484b
          if (e.isShiftPressed()) {
shun-iwasawa 59484b
            TXsheetHandle *xshHandle =
shun-iwasawa 59484b
                TTool::getApplication()->getCurrentXsheet();
shun-iwasawa 59484b
            TStageObjectId curColId =
shun-iwasawa 59484b
                TStageObjectId::ColumnId(currentColumnIndex);
shun-iwasawa 59484b
            TStageObjectId colId = TStageObjectId::ColumnId(columnIndex);
shun-iwasawa 59484b
            TStageObjectCmd::setParent(curColId, colId, "", xshHandle);
shun-iwasawa 59484b
            m_what = None;
shun-iwasawa 59484b
            xshHandle->notifyXsheetChanged();
shun-iwasawa 59484b
          } else {
shun-iwasawa 59484b
            TXshColumn *column = xsh->getColumn(columnIndex);
shun-iwasawa 59484b
            if (!column || !column->isLocked()) {
shun-iwasawa 59484b
              TTool::getApplication()->getCurrentColumn()->setColumnIndex(
shun-iwasawa 59484b
                  columnIndex);
shun-iwasawa 59484b
              updateMatrix();
shun-iwasawa 59484b
            }
shun-iwasawa 59484b
          }
shun-iwasawa 59484b
        }
shun-iwasawa 59484b
      } else {
shun-iwasawa 59484b
        TTool::getApplication()->getCurrentObject()->setObjectId(id);
shun-iwasawa 59484b
        updateMatrix();
shun-iwasawa 59484b
      }
shun-iwasawa 59484b
    }
shun-iwasawa 59484b
    pos = getMatrix().inv() * pos;
shun-iwasawa 59484b
  }
shun-iwasawa 59484b
}
shun-iwasawa 59484b
shun-iwasawa 59484b
//-----------------------------------------------------------------------------
shun-iwasawa 59484b
Shinya Kitaoka 120a6e
void EditTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
Shinya Kitaoka 120a6e
  if (!m_dragTool) return;
Shinya Kitaoka 120a6e
  m_dragTool->leftButtonDrag(pos, e);
Shinya Kitaoka 120a6e
  TTool::getApplication()->getCurrentObject()->notifyObjectIdChanged(true);
Shinya Kitaoka 120a6e
  invalidate();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void EditTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) {
Shinya Kitaoka 120a6e
  if (m_dragTool) {
Shinya Kitaoka 120a6e
    m_dragTool->leftButtonUp(pos, e);
Shinya Kitaoka 120a6e
    TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
    delete m_dragTool;
Shinya Kitaoka 120a6e
    m_dragTool = 0;
Shinya Kitaoka 120a6e
    TTool::getApplication()->getCurrentObject()->notifyObjectIdChanged(false);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_keyFrameAdded = false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void drawArrow(double r, bool filled) {
Shinya Kitaoka 120a6e
  double z0 = 0.25 * r;
Shinya Kitaoka 120a6e
  double z1 = 2 * r;
Shinya Kitaoka 120a6e
  double z2 = 4 * r;
Shinya Kitaoka 120a6e
  double x0 = r;
Shinya Kitaoka 120a6e
  double x1 = 2 * r;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (filled) {
Shinya Kitaoka 120a6e
    glBegin(GL_POLYGON);
Shinya Kitaoka 120a6e
    glVertex3d(x1, 0, z2);
Shinya Kitaoka 120a6e
    glVertex3d(-x1, 0, z2);
Shinya Kitaoka 120a6e
    glVertex3d(-x1, 0, -z2);
Shinya Kitaoka 120a6e
    glVertex3d(x1, 0, -z2);
Shinya Kitaoka 120a6e
    glVertex3d(x1, 0, z2);
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
    glVertex3d(x0, 0, z0);
Shinya Kitaoka 120a6e
    glVertex3d(x0, 0, z1);
Shinya Kitaoka 120a6e
    glVertex3d(x1, 0, z1);
Shinya Kitaoka 120a6e
    glVertex3d(0, 0, z2);
Shinya Kitaoka 120a6e
    glVertex3d(-x1, 0, z1);
Shinya Kitaoka 120a6e
    glVertex3d(-x0, 0, z1);
Shinya Kitaoka 120a6e
    glVertex3d(-x0, 0, z0);
Shinya Kitaoka 120a6e
    glVertex3d(-x0, 0, z0);
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
    glVertex3d(x0, 0, -z0);
Shinya Kitaoka 120a6e
    glVertex3d(x0, 0, -z1);
Shinya Kitaoka 120a6e
    glVertex3d(x1, 0, -z1);
Shinya Kitaoka 120a6e
    glVertex3d(0, 0, -z2);
Shinya Kitaoka 120a6e
    glVertex3d(-x1, 0, -z1);
Shinya Kitaoka 120a6e
    glVertex3d(-x0, 0, -z1);
Shinya Kitaoka 120a6e
    glVertex3d(-x0, 0, -z0);
Shinya Kitaoka 120a6e
    glVertex3d(-x0, 0, -z0);
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void drawCameraIcon() {
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  glVertex2i(5, 0);
Shinya Kitaoka 120a6e
  glVertex2i(16, 0);
Shinya Kitaoka 120a6e
  glVertex2i(16, 3);
Shinya Kitaoka 120a6e
  glVertex2i(16, 3);
Shinya Kitaoka 120a6e
  glVertex2i(22, 0);
Shinya Kitaoka 120a6e
  glVertex2i(22, 9);
Shinya Kitaoka 120a6e
  glVertex2i(16, 6);
Shinya Kitaoka 120a6e
  glVertex2i(16, 9);
Shinya Kitaoka 120a6e
  glVertex2i(14, 9);
Shinya Kitaoka 120a6e
  glVertex2i(16, 11);
Shinya Kitaoka 120a6e
  glVertex2i(16, 14);
Shinya Kitaoka 120a6e
  glVertex2i(14, 16);
Shinya Kitaoka 120a6e
  glVertex2i(11, 16);
Shinya Kitaoka 120a6e
  glVertex2i(9, 14);
Shinya Kitaoka 120a6e
  glVertex2i(9, 11);
Shinya Kitaoka 120a6e
  glVertex2i(11, 9);
Shinya Kitaoka 120a6e
  glVertex2i(7, 9);
Shinya Kitaoka 120a6e
  glVertex2i(7, 11);
Shinya Kitaoka 120a6e
  glVertex2i(5, 13);
Shinya Kitaoka 120a6e
  glVertex2i(2, 13);
Shinya Kitaoka 120a6e
  glVertex2i(0, 11);
Shinya Kitaoka 120a6e
  glVertex2i(0, 8);
Shinya Kitaoka 120a6e
  glVertex2i(2, 6);
Shinya Kitaoka 120a6e
  glVertex2i(5, 6);
Shinya Kitaoka 120a6e
  glVertex2i(5, 0);
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void drawZArrow() {
Shinya Kitaoka 120a6e
  /*--矢印--*/
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_LOOP);
Shinya Kitaoka 120a6e
  glVertex2i(0, 3);
Shinya Kitaoka 120a6e
  glVertex2i(2, 2);
Shinya Kitaoka 120a6e
  glVertex2i(1, 2);
Shinya Kitaoka 120a6e
  glVertex2i(2, -3);
Shinya Kitaoka 120a6e
  glVertex2i(4, -3);
Shinya Kitaoka 120a6e
  glVertex2i(0, -6);
Shinya Kitaoka 120a6e
  glVertex2i(-4, -3);
Shinya Kitaoka 120a6e
  glVertex2i(-2, -3);
Shinya Kitaoka 120a6e
  glVertex2i(-1, 2);
Shinya Kitaoka 120a6e
  glVertex2i(-2, 2);
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  /*--Zの文字--*/
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
  glVertex2i(3, 4);
Shinya Kitaoka 120a6e
  glVertex2i(5, 4);
Shinya Kitaoka 120a6e
  glVertex2i(3, 1);
Shinya Kitaoka 120a6e
  glVertex2i(5, 1);
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void EditTool::drawText(const TPointD &p, double unit, std::string text) {
Shinya Kitaoka 120a6e
  glPushMatrix();
Shinya Kitaoka 120a6e
  glTranslated(p.x, p.y, 0.0);
Shinya Kitaoka 120a6e
  double sc = unit * 1.6;
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
double w = sc * tglGetTextWidth(text, GLUT_STROKE_ROMAN);
Shinya Kitaoka 120a6e
double h = sc;
Shinya Kitaoka 120a6e
glEnable(GL_BLEND);
Shinya Kitaoka 120a6e
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Shinya Kitaoka 120a6e
glColor4d(0.9,0.9,0.1,0.5);
Shinya Kitaoka 120a6e
glRectd(0,0,w,h);
Shinya Kitaoka 120a6e
glDisable(GL_BLEND);
Shinya Kitaoka 120a6e
glColor3d(0,0,0);
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glScaled(sc, sc, 1);
Shinya Kitaoka 120a6e
  tglDrawText(TPointD(8, -3), text);
Shinya Kitaoka 120a6e
  glPopMatrix();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 59484b
void EditTool::drawMainHandle() {
shun-iwasawa 59484b
  const TPixel32 normalColor(250, 127, 240);
shun-iwasawa 59484b
  const TPixel32 highlightedColor(150, 255, 140);
shun-iwasawa 59484b
shun-iwasawa 59484b
  // collect information
shun-iwasawa 59484b
  TXsheet *xsh         = getXsheet();
shun-iwasawa 59484b
  TStageObjectId objId = getObjectId();
shun-iwasawa 59484b
  int frame            = getFrame();
shun-iwasawa 59484b
  TAffine parentAff    = xsh->getParentPlacement(objId, frame);
shun-iwasawa 59484b
  TAffine aff          = xsh->getPlacement(objId, frame);
shun-iwasawa 59484b
  TPointD center       = Stage::inch * xsh->getCenter(objId, frame);
manongjohn 75da26
  int devPixRatio      = getDevPixRatio();
shun-iwasawa 59484b
  // the gadget appears on the center of the level. orientation and dimension
shun-iwasawa 59484b
  // are independent of the movement of the level
shun-iwasawa 59484b
  glPushMatrix();
shun-iwasawa 59484b
shun-iwasawa 59484b
  tglMultMatrix(parentAff.inv() * TTranslation(aff * center));
shun-iwasawa 59484b
shun-iwasawa 59484b
  // so in the system of ref. of the gadget the center is always in the origin
shun-iwasawa 59484b
  center = TPointD();
shun-iwasawa 59484b
shun-iwasawa 59484b
  double unit = sqrt(tglGetPixelSize2());
Jeremy Bullock 63e8da
  unit *= devPixRatio;
shun-iwasawa 59484b
  bool dragging = m_dragTool != 0;
shun-iwasawa 59484b
shun-iwasawa 59484b
  // draw center
shun-iwasawa 59484b
  tglColor(m_highlightedDevice == Center ? highlightedColor : normalColor);
shun-iwasawa 59484b
  glPushName(Center);
shun-iwasawa 59484b
  if (isPicking())
shun-iwasawa 59484b
    tglDrawDisk(center, unit * 12);
shun-iwasawa 59484b
  else {
shun-iwasawa 59484b
    tglDrawCircle(center, unit * 10);
shun-iwasawa 59484b
    tglDrawCircle(center, unit * 8);
shun-iwasawa 59484b
    if (m_highlightedDevice == Center && !dragging)
shun-iwasawa 59484b
      drawText(center + TPointD(4 * unit, 0), unit, "Move center");
shun-iwasawa 59484b
  }
shun-iwasawa 59484b
  glPopName();
shun-iwasawa 59484b
shun-iwasawa 59484b
  // draw label (column/pegbar name; possibly camera icon)
shun-iwasawa 59484b
  tglColor(normalColor);
shun-iwasawa 59484b
  glPushMatrix();
shun-iwasawa 59484b
  glTranslated(center.x + unit * 10, center.y - unit * 20, 0);
shun-iwasawa 59484b
shun-iwasawa 59484b
  if (objId.isColumn() || objId.isPegbar()) {
shun-iwasawa 59484b
    TStageObject *pegbar = xsh->getStageObject(objId);
shun-iwasawa 59484b
    std::string name     = pegbar->getFullName();
shun-iwasawa 59484b
    glScaled(unit * 2, unit * 1.5, 1);
shun-iwasawa 59484b
    tglDrawText(TPointD(0, 0), name);
shun-iwasawa 59484b
  } else if (objId.isCamera()) {
shun-iwasawa 59484b
    glScaled(unit, unit, 1);
shun-iwasawa 59484b
    drawCameraIcon();
shun-iwasawa 59484b
  }
shun-iwasawa 59484b
  glPopMatrix();
shun-iwasawa 59484b
shun-iwasawa 59484b
  // draw rotation handle
shun-iwasawa 59484b
  const double delta = 30;
shun-iwasawa 59484b
  tglColor(m_highlightedDevice == Rotation ? highlightedColor : normalColor);
shun-iwasawa 59484b
  glPushName(Rotation);
shun-iwasawa 59484b
  TPointD p = center + unit * TPointD(0, delta);
shun-iwasawa 59484b
  if (isPicking())
shun-iwasawa 59484b
    tglDrawDisk(p, unit * 10);
shun-iwasawa 59484b
  else
shun-iwasawa 59484b
    tglDrawDisk(p, unit * 5);
shun-iwasawa 59484b
  glPopName();
shun-iwasawa 59484b
  if (m_highlightedDevice == Rotation && !dragging && !isPicking())
shun-iwasawa 59484b
    drawText(p, unit, "Rotate");
shun-iwasawa 59484b
  tglColor(normalColor);
shun-iwasawa 59484b
  tglDrawSegment(p, center);
shun-iwasawa 59484b
shun-iwasawa 59484b
  // draw scale handle
shun-iwasawa 59484b
  p        = center + m_currentScaleFactor * unit * delta * TPointD(-1, -1);
shun-iwasawa 59484b
  double r = unit * 3;
shun-iwasawa 59484b
  double f = 5;
shun-iwasawa 59484b
  TRectD hitRect;
shun-iwasawa 59484b
shun-iwasawa 59484b
  tglColor(m_highlightedDevice == Scale ? highlightedColor : normalColor);
shun-iwasawa 59484b
  glPushName(Scale);
shun-iwasawa 59484b
  hitRect =
shun-iwasawa 59484b
      TRectD(p.x - (f - 2) * r, p.y - (f - 2) * r, p.x + r * 2, p.y + r * 2);
shun-iwasawa 59484b
  // tglDrawRect(hitRect);
shun-iwasawa 59484b
  if (isPicking())
shun-iwasawa 59484b
    tglFillRect(hitRect);
shun-iwasawa 59484b
  else
shun-iwasawa 59484b
    tglDrawRect(p.x - r, p.y - r, p.x + r, p.y + r);
shun-iwasawa 59484b
  glPopName();
shun-iwasawa 59484b
  TPointD scaleTooltipPos = p + unit * TPointD(-16, -16);
shun-iwasawa 59484b
  if (m_highlightedDevice == Scale && !dragging && !isPicking())
shun-iwasawa 59484b
    drawText(scaleTooltipPos, unit, "Scale");
shun-iwasawa 59484b
shun-iwasawa 59484b
  tglColor(normalColor);
shun-iwasawa 59484b
  tglDrawSegment(p, center);
shun-iwasawa 59484b
shun-iwasawa 59484b
  TPointD q;
shun-iwasawa 59484b
  double dd = unit * 10;
shun-iwasawa 59484b
shun-iwasawa 59484b
  q = p + TPointD(dd, dd);
shun-iwasawa 59484b
  tglColor(m_highlightedDevice == ScaleXY ? highlightedColor : normalColor);
shun-iwasawa 59484b
  glPushName(ScaleXY);
shun-iwasawa 59484b
  hitRect =
shun-iwasawa 59484b
      TRectD(q.x - 2 * r, q.y - 2 * r, q.x + r * (f - 2), q.y + r * (f - 2));
shun-iwasawa 59484b
  // tglDrawRect(hitRect);
shun-iwasawa 59484b
  if (isPicking())
shun-iwasawa 59484b
    tglFillRect(hitRect);
shun-iwasawa 59484b
  else
shun-iwasawa 59484b
    tglDrawRect(q.x - r, q.y - r, q.x + r, q.y + r);
shun-iwasawa 59484b
  glPopName();
shun-iwasawa 59484b
  if (m_highlightedDevice == ScaleXY && !dragging && !isPicking())
shun-iwasawa 59484b
    drawText(scaleTooltipPos, unit, "Horizontal/Vertical scale");
shun-iwasawa 59484b
shun-iwasawa 59484b
  // draw shear handle
shun-iwasawa 59484b
  p = center + m_currentScaleFactor * unit * delta * TPointD(1, -1);
shun-iwasawa 59484b
  tglColor(m_highlightedDevice == Shear ? highlightedColor : normalColor);
shun-iwasawa 59484b
  glPushName(Shear);
shun-iwasawa 59484b
  if (isPicking()) {
shun-iwasawa 59484b
    glBegin(GL_POLYGON);
shun-iwasawa 59484b
    glVertex2d(p.x - unit * 6, p.y - unit * 3);
shun-iwasawa 59484b
    glVertex2d(p.x - unit * 3, p.y - unit * 3);
shun-iwasawa 59484b
    glVertex2d(p.x + unit * 6, p.y + unit * 3);
shun-iwasawa 59484b
    glVertex2d(p.x + unit * 3, p.y + unit * 3);
shun-iwasawa 59484b
    glVertex2d(p.x - unit * 6, p.y - unit * 3);
shun-iwasawa 59484b
    glEnd();
shun-iwasawa 59484b
  } else {
shun-iwasawa 59484b
    glBegin(GL_LINE_STRIP);
shun-iwasawa 59484b
    glVertex2d(p.x - unit * 6, p.y - unit * 3);
shun-iwasawa 59484b
    glVertex2d(p.x - unit * 3, p.y - unit * 3);
shun-iwasawa 59484b
    glVertex2d(p.x + unit * 6, p.y + unit * 3);
shun-iwasawa 59484b
    glVertex2d(p.x + unit * 3, p.y + unit * 3);
shun-iwasawa 59484b
    glVertex2d(p.x - unit * 6, p.y - unit * 3);
shun-iwasawa 59484b
    glEnd();
shun-iwasawa 59484b
  }
shun-iwasawa 59484b
  glPopName();
shun-iwasawa 59484b
  if (m_highlightedDevice == Shear && !dragging)
shun-iwasawa 59484b
    drawText(p + TPointD(0, -unit * 10), unit, "Shear");
shun-iwasawa 59484b
  tglColor(normalColor);
shun-iwasawa 59484b
  tglDrawSegment(p, center);
shun-iwasawa 59484b
shun-iwasawa 59484b
  //
shun-iwasawa 59484b
  if (objId.isCamera()) {
shun-iwasawa 59484b
    if (xsh->getStageObjectTree()->getCurrentCameraId() != objId) {
shun-iwasawa 59484b
      glEnable(GL_LINE_STIPPLE);
shun-iwasawa 59484b
      glColor3d(1.0, 0.0, 1.0);
shun-iwasawa 59484b
      glLineStipple(1, 0x1111);
shun-iwasawa 59484b
      TRectD cameraRect = TTool::getApplication()
shun-iwasawa 59484b
                              ->getCurrentScene()
shun-iwasawa 59484b
                              ->getScene()
shun-iwasawa 59484b
                              ->getCurrentCamera()
shun-iwasawa 59484b
                              ->getStageRect();
shun-iwasawa 59484b
shun-iwasawa 59484b
      glPushMatrix();
shun-iwasawa 59484b
      // tglMultMatrix(mat);
shun-iwasawa 59484b
      tglDrawRect(cameraRect);
shun-iwasawa 59484b
      glPopMatrix();
shun-iwasawa 59484b
      glDisable(GL_LINE_STIPPLE);
shun-iwasawa 59484b
    }
shun-iwasawa 59484b
  }
shun-iwasawa 59484b
shun-iwasawa 59484b
  glPopMatrix();
shun-iwasawa 59484b
}
shun-iwasawa 59484b
//-----------------------------------------------------------------------------
shun-iwasawa 59484b
Shinya Kitaoka 120a6e
void EditTool::draw() {
Shinya Kitaoka 120a6e
  // the tool is using the coordinate system of the parent object
Shinya Kitaoka 120a6e
  // glColor3d(1,0,1);
Shinya Kitaoka 120a6e
  // tglDrawCircle(crossHair,50);
Shinya Kitaoka 120a6e
shun-iwasawa 59484b
  /*-- Show nothing on Level Editing mode --*/
Shinya Kitaoka 120a6e
  if (TTool::getApplication()->getCurrentFrame()->isEditingLevel()) return;
shun-iwasawa d464a1
shun-iwasawa d464a1
  // if the column and its children are all hidden, only draw fx gadgets
shun-iwasawa d464a1
  if (!transformEnabled()) {
shun-iwasawa d464a1
    m_fxGadgetController->draw(isPicking());
shun-iwasawa d464a1
    return;
shun-iwasawa d464a1
  }
Shinya Kitaoka 120a6e
  const TPixel32 normalColor(250, 127, 240);
Shinya Kitaoka 120a6e
  const TPixel32 highlightedColor(150, 255, 140);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // collect information
Shinya Kitaoka 120a6e
  TXsheet *xsh = getXsheet();
shun-iwasawa 59484b
  /*-- Obtain ID of the current editing stage object --*/
Shinya Kitaoka 120a6e
  TStageObjectId objId = getObjectId();
shun-iwasawa d464a1
shun-iwasawa d464a1
  int frame         = getFrame();
shun-iwasawa d464a1
  TAffine parentAff = xsh->getParentPlacement(objId, frame);
shun-iwasawa d464a1
  TAffine aff       = xsh->getPlacement(objId, frame);
shun-iwasawa d464a1
  TPointD center    = Stage::inch * xsh->getCenter(objId, frame);
Shinya Kitaoka 120a6e
shun-iwasawa 59484b
  /*-- Enable Z translation on 3D view --*/
Shinya Kitaoka 120a6e
  if (getViewer()->is3DView()) {
Shinya Kitaoka 120a6e
    glPushMatrix();
Shinya Kitaoka 120a6e
    glPushName(ZTranslation);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    tglColor(m_highlightedDevice == ZTranslation ? highlightedColor
Shinya Kitaoka 120a6e
                                                 : normalColor);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    glPushMatrix();
Shinya Kitaoka 120a6e
    double z = xsh->getZ(objId, frame);
Shinya Kitaoka 120a6e
    glTranslated(0, -1, z);
Shinya Kitaoka 120a6e
    drawArrow(50, isPicking());
Shinya Kitaoka 120a6e
    glPopName();
Shinya Kitaoka 120a6e
    glPopMatrix();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    glPopMatrix();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
shun-iwasawa 59484b
  // Edit-all
shun-iwasawa 59484b
  if (m_activeAxis.getValue() == L"All") {
shun-iwasawa 59484b
    if (!m_fxGadgetController->isEditingNonZeraryFx()) drawMainHandle();
shun-iwasawa 59484b
    m_fxGadgetController->draw(isPicking());
shun-iwasawa 59484b
    return;
shun-iwasawa 59484b
  }
shun-iwasawa 59484b
shun_iwasawa 1fbdc9
  double unit = getPixelSize();
Shinya Kitaoka 120a6e
shun-iwasawa 59484b
  /*-- Obtain object's center position --*/
Shinya Kitaoka 120a6e
  glPushMatrix();
Shinya Kitaoka 120a6e
  tglMultMatrix(parentAff.inv() * TTranslation(aff * TPointD(0.0, 0.0)));
Shinya Kitaoka 120a6e
  tglColor(normalColor);
Shinya Kitaoka 120a6e
  tglDrawDisk(TPointD(0.0, 0.0), unit * 4);
Shinya Kitaoka 120a6e
  glPopMatrix();
Shinya Kitaoka 120a6e
shun-iwasawa 59484b
  /*-- Z translation : Draw arrow mark (placed at the camera center) --*/
Shinya Kitaoka 120a6e
  if (m_activeAxis.getValue() == L"Position" &&
Shinya Kitaoka 120a6e
      m_highlightedDevice == ZTranslation) {
Shinya Kitaoka 120a6e
    tglColor(normalColor);
Shinya Kitaoka 120a6e
    glPushMatrix();
Shinya Kitaoka 120a6e
    TStageObjectId currentCamId =
John Dancel c323ac
        TStageObjectId::CameraId(xsh->getCameraColumnIndex());
Shinya Kitaoka 120a6e
    TAffine camParentAff = xsh->getParentPlacement(currentCamId, frame);
Shinya Kitaoka 120a6e
    TAffine camAff       = xsh->getPlacement(currentCamId, frame);
Shinya Kitaoka 120a6e
    tglMultMatrix(camParentAff.inv() *
Shinya Kitaoka 120a6e
                  TTranslation(camAff * TPointD(0.0, 0.0)));
Shinya Kitaoka 120a6e
    glScaled(unit * 8, unit * 8, 1);
Shinya Kitaoka 120a6e
    drawZArrow();
Shinya Kitaoka 120a6e
    glPopMatrix();
Shinya Kitaoka 120a6e
  }
shun-iwasawa 59484b
  /*-- Rotation, Position : Draw vertical and horizontal lines --*/
shun-iwasawa 59484b
  else if (m_activeAxis.getValue() == L"Rotation" ||
shun-iwasawa 59484b
           m_activeAxis.getValue() == L"Position") {
Shinya Kitaoka 120a6e
    glPushMatrix();
Shinya Kitaoka 120a6e
    tglMultMatrix(parentAff.inv() * aff * TTranslation(center));
Shinya Kitaoka 120a6e
    glScaled(unit, unit, 1);
Shinya Kitaoka 120a6e
    tglColor(normalColor);
Shinya Kitaoka 120a6e
    glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
    glVertex2i(-800, 0);
Shinya Kitaoka 120a6e
    glVertex2i(800, 0);
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
    glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
    glVertex2i(0, -100);
Shinya Kitaoka 120a6e
    glVertex2i(0, 100);
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
    glPopMatrix();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glPushMatrix();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  tglMultMatrix(parentAff.inv() * TTranslation(aff * center));
Shinya Kitaoka 120a6e
  center = TPointD();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool dragging = m_dragTool != 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // draw center
Shinya Kitaoka 120a6e
  tglColor(normalColor);
Shinya Kitaoka 120a6e
  glPushName(Center);
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    tglDrawCircle(center, unit * 10);
Shinya Kitaoka 120a6e
    tglDrawCircle(center, unit * 8);
Shinya Kitaoka 120a6e
shun-iwasawa 59484b
    /*-- Draw crossed lines in the circle. It's already translated to the center
shun-iwasawa 59484b
     * position. --*/
Shinya Kitaoka 120a6e
    glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
    glVertex2d(-unit * 8, 0.0);
Shinya Kitaoka 120a6e
    glVertex2d(unit * 8, 0.0);
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
    glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
    glVertex2d(0.0, -unit * 8);
Shinya Kitaoka 120a6e
    glVertex2d(0.0, unit * 8);
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glPopName();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // draw label (column/pegbar name; possibly camera icon)
Shinya Kitaoka 120a6e
  tglColor(normalColor);
Shinya Kitaoka 120a6e
  glPushMatrix();
Shinya Kitaoka 120a6e
  glTranslated(center.x + unit * 10, center.y - unit * 20, 0);
Shinya Kitaoka 120a6e
shun-iwasawa 59484b
  /*-- Object name --*/
Shinya Kitaoka 120a6e
  TStageObject *pegbar = xsh->getStageObject(objId);
Shinya Kitaoka 120a6e
  std::string name     = pegbar->getFullName();
Shinya Kitaoka 120a6e
  if (objId.isColumn() || objId.isPegbar() || objId.isTable()) {
Shinya Kitaoka 120a6e
    glScaled(unit * 2, unit * 1.5, 1);
Shinya Kitaoka 120a6e
    tglDrawText(TPointD(0, 0), name);
Shinya Kitaoka 120a6e
  } else if (objId.isCamera()) {
Shinya Kitaoka 120a6e
    glPushMatrix();
Shinya Kitaoka 120a6e
    glScaled(unit * 2, unit * 1.5, 1);
Shinya Kitaoka 120a6e
    tglDrawText(TPointD(12, 0), name);
Shinya Kitaoka 120a6e
    glPopMatrix();
Shinya Kitaoka 120a6e
    glScaled(unit, unit, 1);
Shinya Kitaoka 120a6e
    drawCameraIcon();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  glPopMatrix();
Shinya Kitaoka 120a6e
shun-iwasawa 59484b
  /*--- When editing non-active camera, draw its camera frame ---*/
Shinya Kitaoka 120a6e
  if (objId.isCamera()) {
Shinya Kitaoka 120a6e
    if (xsh->getStageObjectTree()->getCurrentCameraId() != objId) {
Shinya Kitaoka 120a6e
      // TODO : glLineStipple has been deprecated in the OpenGL APIs. Need to be
Shinya Kitaoka 120a6e
      // replaced. 2016/1/20 shun_iwasawa
Shinya Kitaoka 120a6e
      glEnable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
      glColor3d(1.0, 0.0, 1.0);
Shinya Kitaoka 120a6e
      glLineStipple(1, 0x1111);
Shinya Kitaoka 120a6e
      TRectD cameraRect = TTool::getApplication()
Shinya Kitaoka 120a6e
                              ->getCurrentScene()
Shinya Kitaoka 120a6e
                              ->getScene()
Shinya Kitaoka 120a6e
                              ->getCurrentCamera()
Shinya Kitaoka 120a6e
                              ->getStageRect();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      glPushMatrix();
Shinya Kitaoka 120a6e
      tglDrawRect(cameraRect);
Shinya Kitaoka 120a6e
      glPopMatrix();
Shinya Kitaoka 120a6e
      glDisable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glPopMatrix();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_fxGadgetController->draw(isPicking());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void EditTool::onActivate() {
Shinya Kitaoka 120a6e
  if (m_firstTime) {
Shinya Kitaoka 120a6e
    m_lockCenterX.setValue(LockCenterX ? 1 : 0);
Shinya Kitaoka 120a6e
    m_lockCenterY.setValue(LockCenterY ? 1 : 0);
Shinya Kitaoka 120a6e
    m_lockPositionX.setValue(LockPositionX ? 1 : 0);
Shinya Kitaoka 120a6e
    m_lockPositionY.setValue(LockPositionY ? 1 : 0);
Shinya Kitaoka 120a6e
    m_lockRotation.setValue(LockRotation ? 1 : 0);
Shinya Kitaoka 120a6e
    m_lockShearH.setValue(LockShearH ? 1 : 0);
Shinya Kitaoka 120a6e
    m_lockShearV.setValue(LockShearV ? 1 : 0);
Shinya Kitaoka 120a6e
    m_lockScaleH.setValue(LockScaleH ? 1 : 0);
Shinya Kitaoka 120a6e
    m_lockScaleV.setValue(LockScaleV ? 1 : 0);
Shinya Kitaoka 120a6e
    m_lockGlobalScale.setValue(LockGlobalScale ? 1 : 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_showEWNSposition.setValue(ShowEWNSposition ? 1 : 0);
Shinya Kitaoka 120a6e
    m_showZposition.setValue(ShowZposition ? 1 : 0);
Shinya Kitaoka 120a6e
    m_showSOposition.setValue(ShowSOposition ? 1 : 0);
Shinya Kitaoka 120a6e
    m_showRotation.setValue(ShowRotation ? 1 : 0);
Shinya Kitaoka 120a6e
    m_showGlobalScale.setValue(ShowGlobalScale ? 1 : 0);
Shinya Kitaoka 120a6e
    m_showHVscale.setValue(ShowHVscale ? 1 : 0);
Shinya Kitaoka 120a6e
    m_showShear.setValue(ShowShear ? 1 : 0);
Shinya Kitaoka 120a6e
    m_showCenterPosition.setValue(ShowCenterPosition ? 1 : 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_fxGadgetController = new FxGadgetController(this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    /*
Shinya Kitaoka 120a6e
m_foo.setTool(this);
Shinya Kitaoka 120a6e
m_foo.setFxHandle(getApplication()->getCurrentFx());
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_firstTime = false;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TStageObjectId objId = getObjectId();
Shinya Kitaoka 120a6e
  if (objId == TStageObjectId::NoneId) {
John Dancel c323ac
    int index    = getColumnIndex();
John Dancel c323ac
    TXsheet *xsh = TTool::getApplication()->getCurrentXsheet()->getXsheet();
John Dancel c323ac
    if (index == -1)
John Dancel c323ac
      objId = TStageObjectId::CameraId(xsh->getCameraColumnIndex());
John Dancel c323ac
    else
John Dancel c323ac
      objId = TStageObjectId::ColumnId(index);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  TTool::getApplication()->getCurrentObject()->setObjectId(objId);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void EditTool::onDeactivate() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool EditTool::onPropertyChanged(std::string propertyName) {
Shinya Kitaoka 120a6e
  if (propertyName == m_lockCenterX.getName())
Shinya Kitaoka 120a6e
    LockCenterX = (int)m_lockCenterX.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_lockCenterY.getName())
Shinya Kitaoka 120a6e
    LockCenterY = (int)m_lockCenterY.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_lockPositionX.getName())
Shinya Kitaoka 120a6e
    LockPositionX = (int)m_lockPositionX.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_lockPositionY.getName())
Shinya Kitaoka 120a6e
    LockPositionY = (int)m_lockPositionY.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_lockRotation.getName())
Shinya Kitaoka 120a6e
    LockRotation = (int)m_lockRotation.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_lockShearH.getName())
Shinya Kitaoka 120a6e
    LockShearH = (int)m_lockShearH.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_lockShearV.getName())
Shinya Kitaoka 120a6e
    LockShearV = (int)m_lockShearV.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_lockScaleH.getName())
Shinya Kitaoka 120a6e
    LockScaleH = (int)m_lockScaleH.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_lockScaleV.getName())
Shinya Kitaoka 120a6e
    LockScaleV = (int)m_lockScaleV.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_lockGlobalScale.getName())
Shinya Kitaoka 120a6e
    LockGlobalScale = (int)m_lockGlobalScale.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_showEWNSposition.getName())
Shinya Kitaoka 120a6e
    ShowEWNSposition = (int)m_showEWNSposition.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_showZposition.getName())
Shinya Kitaoka 120a6e
    ShowZposition = (int)m_showZposition.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_showSOposition.getName())
Shinya Kitaoka 120a6e
    ShowSOposition = (int)m_showSOposition.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_showRotation.getName())
Shinya Kitaoka 120a6e
    ShowRotation = (int)m_showRotation.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_showGlobalScale.getName())
Shinya Kitaoka 120a6e
    ShowGlobalScale = (int)m_showGlobalScale.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_showHVscale.getName())
Shinya Kitaoka 120a6e
    ShowHVscale = (int)m_showHVscale.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_showShear.getName())
Shinya Kitaoka 120a6e
    ShowShear = (int)m_showShear.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  else if (propertyName == m_showCenterPosition.getName())
Shinya Kitaoka 120a6e
    ShowCenterPosition = (int)m_showCenterPosition.getValue();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*-- Active Axis の変更 --*/
Shinya Kitaoka 120a6e
  else if (propertyName == m_activeAxis.getName()) {
Shinya Kitaoka 120a6e
    std::wstring activeAxis = m_activeAxis.getValue();
Shinya Kitaoka 120a6e
    if (activeAxis == L"Position")
Shinya Kitaoka 120a6e
      m_what = Translation;
Shinya Kitaoka 120a6e
    else if (activeAxis == L"Rotation")
Shinya Kitaoka 120a6e
      m_what = Rotation;
Shinya Kitaoka 120a6e
    else if (activeAxis == L"Scale")
Shinya Kitaoka 120a6e
      m_what = Scale;
Shinya Kitaoka 120a6e
    else if (activeAxis == L"Shear")
Shinya Kitaoka 120a6e
      m_what = Shear;
Shinya Kitaoka 120a6e
    else if (activeAxis == L"Center")
Shinya Kitaoka 120a6e
      m_what = Center;
shun-iwasawa 59484b
    else if (activeAxis == L"All")
shun-iwasawa 59484b
      m_what = None;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int EditTool::getCursorId() const {
shun-iwasawa bce58d
  int ret;
shun-iwasawa bce58d
  // cursor for controling the fx gadget
shun-iwasawa bce58d
  if (m_highlightedDevice >= 1000)
shun-iwasawa bce58d
    ret = ToolCursor::FxGadgetCursor;
shun-iwasawa d464a1
  else if (transformEnabled()) {
shun-iwasawa bce58d
    // switch cursors depending on the active axis
shun-iwasawa bce58d
    std::wstring activeAxis = m_activeAxis.getValue();
shun-iwasawa bce58d
    if (activeAxis == L"Position") {
shun-iwasawa bce58d
      if (m_highlightedDevice == ZTranslation)
shun-iwasawa bce58d
        ret = ToolCursor::MoveZCursor;
shun-iwasawa bce58d
      else if (LockPositionX && LockPositionY)
Shinya Kitaoka 120a6e
        return ToolCursor::DisableCursor;
shun-iwasawa bce58d
      else if (LockPositionX)
shun-iwasawa bce58d
        ret = ToolCursor::MoveNSCursor;
shun-iwasawa bce58d
      else if (LockPositionY)
shun-iwasawa bce58d
        ret = ToolCursor::MoveEWCursor;
Shinya Kitaoka 120a6e
      else
shun-iwasawa bce58d
        ret = ToolCursor::MoveCursor;
shun-iwasawa bce58d
    } else if (activeAxis == L"Rotation") {
shun-iwasawa bce58d
      ret = ToolCursor::RotCursor;
shun-iwasawa bce58d
    } else if (activeAxis == L"Scale") {
shun-iwasawa bce58d
      if (m_highlightedDevice == ScaleXY) {
shun-iwasawa bce58d
        if (LockScaleH && LockScaleV)
shun-iwasawa bce58d
          return ToolCursor::DisableCursor;
shun-iwasawa bce58d
        else if (LockScaleH)
shun-iwasawa bce58d
          ret = ToolCursor::ScaleVCursor;
shun-iwasawa bce58d
        else if (LockScaleV)
shun-iwasawa bce58d
          ret = ToolCursor::ScaleHCursor;
shun-iwasawa bce58d
        else
shun-iwasawa bce58d
          ret = ToolCursor::ScaleHVCursor;
shun-iwasawa bce58d
      } else
shun-iwasawa bce58d
        ret = ToolCursor::ScaleGlobalCursor;
shun-iwasawa bce58d
    } else if (activeAxis == L"Shear") {
shun-iwasawa bce58d
      if (LockShearH && LockShearV)
shun-iwasawa bce58d
        return ToolCursor::DisableCursor;
shun-iwasawa bce58d
      else if (LockShearH)
shun-iwasawa bce58d
        ret = ToolCursor::ScaleVCursor;
shun-iwasawa bce58d
      else if (LockShearV)
shun-iwasawa bce58d
        ret = ToolCursor::ScaleHCursor;
shun-iwasawa bce58d
      else
shun-iwasawa bce58d
        ret = ToolCursor::ScaleCursor;
shun-iwasawa bce58d
    } else if (activeAxis == L"Center") {
shun-iwasawa bce58d
      if (LockCenterX && LockCenterY)
shun-iwasawa bce58d
        return ToolCursor::DisableCursor;
shun-iwasawa bce58d
      else if (LockCenterX)
shun-iwasawa bce58d
        ret = ToolCursor::MoveNSCursor;
shun-iwasawa bce58d
      else if (LockCenterY)
shun-iwasawa bce58d
        ret = ToolCursor::MoveEWCursor;
shun-iwasawa bce58d
      else
shun-iwasawa bce58d
        ret = ToolCursor::MoveCursor;
Shinya Kitaoka 120a6e
    } else
shun-iwasawa bce58d
      ret = ToolCursor::StrokeSelectCursor;
shun-iwasawa d464a1
  } else
shun-iwasawa d464a1
    return ToolCursor::DisableCursor;
shun-iwasawa bce58d
  // precise control with pressing Alt key
shun-iwasawa bce58d
  if (m_isAltPressed) ret = ret | ToolCursor::Ex_Precise;
shun-iwasawa bce58d
  return ret;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
shun-iwasawa d464a1
//-----------------------------------------------------------------------------
shun-iwasawa d464a1
// overriding TTool::updateEnabled()
shun-iwasawa d464a1
QString EditTool::updateEnabled(int rowIndex, int columnIndex) {
shun-iwasawa d464a1
  // toolType = TTool::ColumnTool
shun-iwasawa d464a1
  // targetType = TTool::AllTargets;
shun-iwasawa d464a1
shun-iwasawa d464a1
  // Disable every tool during playback
shun-iwasawa d464a1
  if (m_application->getCurrentFrame()->isPlaying())
shun-iwasawa d464a1
    return (enable(false), QString());
shun-iwasawa d464a1
shun-iwasawa d464a1
  // Disable in Level Strip
shun-iwasawa d464a1
  if (m_application->getCurrentFrame()->isEditingLevel())
shun-iwasawa d464a1
    return (
shun-iwasawa d464a1
        enable(false),
shun-iwasawa d464a1
        QObject::tr("The current tool cannot be used in Level Strip mode."));
shun-iwasawa d464a1
shun-iwasawa d464a1
  // if an object other than column is selected, then enable the tool
shun-iwasawa d464a1
  // regardless of the current column state
shun-iwasawa d464a1
  TStageObjectId objId = m_application->getCurrentObject()->getObjectId();
shun-iwasawa d464a1
  if (!objId.isColumn()) return (enable(true), QString());
shun-iwasawa d464a1
shun-iwasawa d464a1
  // Retrieve vars and view modes
shun-iwasawa d464a1
  TXsheet *xsh = m_application->getCurrentXsheet()->getXsheet();
shun-iwasawa d464a1
  // if a column object is selected, switch the inspected column to it
shun-iwasawa d464a1
  TXshColumn *column = xsh->getColumn(objId.getIndex());
shun-iwasawa d464a1
shun-iwasawa d464a1
  // disable if the column is empty
shun-iwasawa d464a1
  if (!column || column->isEmpty()) return (enable(false), QString());
shun-iwasawa d464a1
shun-iwasawa d464a1
  if (column->getSoundColumn())
shun-iwasawa d464a1
    return (enable(false),
shun-iwasawa d464a1
            QObject::tr("It is not possible to edit the audio column."));
shun-iwasawa d464a1
shun-iwasawa d464a1
  else if (column->getSoundTextColumn())
shun-iwasawa d464a1
    return (enable(false),
shun-iwasawa d464a1
            QObject::tr(
shun-iwasawa d464a1
                "Note columns can only be edited in the xsheet or timeline."));
shun-iwasawa d464a1
shun-iwasawa d464a1
  // Enable to control Fx gadgets even on the locked or hidden columns
shun-iwasawa d464a1
  if (m_fxGadgetController && m_fxGadgetController->hasGadget())
shun-iwasawa d464a1
    return (enable(true), QString());
shun-iwasawa d464a1
shun-iwasawa d464a1
  // Check against unplaced columns
shun-iwasawa d464a1
  if (column->isLocked())
shun-iwasawa d464a1
    return (enable(false), QObject::tr("The current column is locked."));
shun-iwasawa d464a1
shun-iwasawa d464a1
  // check if the current column and all of its child columns are hidden
shun-iwasawa d464a1
  if (!hasVisibleChildColumn(xsh->getStageObject(objId), xsh))
shun-iwasawa d464a1
    return (enable(false), QObject::tr("The current column is hidden."));
shun-iwasawa d464a1
shun-iwasawa d464a1
  return (enable(true), QString());
shun-iwasawa d464a1
}
shun-iwasawa d464a1
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
EditTool arrowTool;