Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "edittoolgadgets.h"
Toshihiro Shimizu 890ddd
#include "tgl.h"
Toshihiro Shimizu 890ddd
#include "toonz/tfxhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tobjecthandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage.h"
Toshihiro Shimizu 890ddd
#include "tools/tool.h"
Toshihiro Shimizu 890ddd
#include "tfx.h"
Toshihiro Shimizu 890ddd
#include "tparamcontainer.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfx.h"
Toshihiro Shimizu 890ddd
#include "tdoubleparam.h"
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
#include "tundo.h"
Toshihiro Shimizu 890ddd
#include "tparamuiconcept.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "historytypes.h"
Toshihiro Shimizu 890ddd
shun_iwasawa 1fbdc9
#include <qapplication></qapplication>
shun_iwasawa 1fbdc9
#include <qdesktopwidget></qdesktopwidget>
shun_iwasawa 1fbdc9
Toshihiro Shimizu 890ddd
using namespace EditToolGadgets;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
GLdouble FxGadget::m_selectedColor[3] = {0.2, 0.8, 0.1};
Toshihiro Shimizu 890ddd
shun_iwasawa 1fbdc9
namespace {
shun_iwasawa 1fbdc9
int getDevPixRatio() {
shun_iwasawa 1fbdc9
  static int devPixRatio = QApplication::desktop()->devicePixelRatio();
shun_iwasawa 1fbdc9
  return devPixRatio;
shun_iwasawa 1fbdc9
}
shun_iwasawa 1fbdc9
}
shun_iwasawa 1fbdc9
Toshihiro Shimizu 890ddd
//*************************************************************************************
Toshihiro Shimizu 890ddd
//    FxGadgetUndo  definition
Toshihiro Shimizu 890ddd
//*************************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class FxGadgetUndo final : public TUndo {
Shinya Kitaoka 120a6e
  struct ParamData {
Shinya Kitaoka 120a6e
    TDoubleParamP m_param;
Shinya Kitaoka 120a6e
    double m_oldValue, m_newValue;
Shinya Kitaoka 120a6e
    bool m_wasKeyframe;
Shinya Kitaoka 120a6e
  };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  std::vector<paramdata> m_params;</paramdata>
Shinya Kitaoka 120a6e
  int m_frame;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FxGadgetUndo(const std::vector<tdoubleparamp> ¶ms, int frame)</tdoubleparamp>
Shinya Kitaoka 120a6e
      : m_frame(frame) {
Shinya Kitaoka 120a6e
    m_params.resize(params.size());
Shinya Kitaoka 120a6e
    for (int i = 0; i < (int)params.size(); i++) {
Shinya Kitaoka 120a6e
      m_params[i].m_param       = params[i];
Shinya Kitaoka 120a6e
      m_params[i].m_oldValue    = params[i]->getValue(frame);
Shinya Kitaoka 120a6e
      m_params[i].m_newValue    = m_params[i].m_oldValue;
Shinya Kitaoka 120a6e
      m_params[i].m_wasKeyframe = m_params[i].m_param->isKeyframe(frame);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void onAdd() override {
Shinya Kitaoka 120a6e
    for (int i = 0; i < (int)m_params.size(); i++) {
Shinya Kitaoka 120a6e
      m_params[i].m_newValue = m_params[i].m_param->getValue(m_frame);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void undo() const override {
Shinya Kitaoka 120a6e
    for (int i = 0; i < (int)m_params.size(); i++) {
Shinya Kitaoka 120a6e
      if (!m_params[i].m_wasKeyframe)
Shinya Kitaoka 120a6e
        m_params[i].m_param->deleteKeyframe(m_frame);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        m_params[i].m_param->setValue(m_frame, m_params[i].m_oldValue);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void redo() const override {
Shinya Kitaoka 120a6e
    for (int i = 0; i < (int)m_params.size(); i++) {
Shinya Kitaoka 120a6e
      m_params[i].m_param->setValue(m_frame, m_params[i].m_newValue);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  int getSize() const override {
Shinya Kitaoka 120a6e
    return sizeof(*this) + m_params.size() * sizeof(ParamData);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  QString getHistoryString() override {
Shinya Kitaoka 120a6e
    QString str = QObject::tr("Modify Fx Gadget  ");
Shinya Kitaoka 120a6e
    for (int i = 0; i < (int)m_params.size(); i++) {
Shinya Kitaoka 120a6e
      str += QString::fromStdString(m_params[i].m_param->getName());
Shinya Kitaoka 120a6e
      if (i != (int)m_params.size() - 1) str += QString::fromStdString(", ");
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    str += QString("  Frame : %1").arg(QString::number(m_frame + 1));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    return str;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  int getHistoryType() override { return HistoryType::Fx; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*************************************************************************************
Toshihiro Shimizu 890ddd
//    GadgetDragTool  definition
Toshihiro Shimizu 890ddd
//*************************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class GadgetDragTool final : public DragTool {
Shinya Kitaoka 120a6e
  FxGadgetController *m_controller;
Shinya Kitaoka 120a6e
  FxGadget *m_gadget;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  GadgetDragTool(FxGadgetController *controller, FxGadget *gadget)
Shinya Kitaoka 120a6e
      : m_controller(controller), m_gadget(gadget) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TAffine getMatrix() const { return m_controller->getMatrix().inv(); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override {
Shinya Kitaoka 120a6e
    m_gadget->createUndo();
Shinya Kitaoka 120a6e
    m_gadget->leftButtonDown(getMatrix() * pos, e);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override {
Shinya Kitaoka 120a6e
    m_gadget->leftButtonDrag(getMatrix() * pos, e);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override {
Shinya Kitaoka 120a6e
    m_gadget->leftButtonUp(getMatrix() * pos, e);
Shinya Kitaoka 120a6e
    m_gadget->commitUndo();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*************************************************************************************
Toshihiro Shimizu 890ddd
//    FxGadget  implementation
Toshihiro Shimizu 890ddd
//*************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FxGadget::FxGadget(FxGadgetController *controller)
Shinya Kitaoka 120a6e
    : m_id(-1)
Shinya Kitaoka 120a6e
    , m_selected(false)
Shinya Kitaoka 120a6e
    , m_controller(controller)
Shinya Kitaoka 120a6e
    , m_pixelSize(1)
Shinya Kitaoka 120a6e
    , m_undo(0)
Shinya Kitaoka 120a6e
    , m_scaleFactor(1) {
Shinya Kitaoka 120a6e
  controller->assignId(this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FxGadget::~FxGadget() {
Shinya Kitaoka 120a6e
  for (int i = 0; i < (int)m_params.size(); i++)
Shinya Kitaoka 120a6e
    m_params[i]->removeObserver(this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxGadget::addParam(const TDoubleParamP ¶m) {
Shinya Kitaoka 120a6e
  m_params.push_back(param);
Shinya Kitaoka 120a6e
  param->addObserver(this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double FxGadget::getValue(const TDoubleParamP ¶m) const {
Shinya Kitaoka 120a6e
  return param->getValue(m_controller->getCurrentFrame());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxGadget::setValue(const TDoubleParamP ¶m, double value) {
Shinya Kitaoka 120a6e
  param->setValue(m_controller->getCurrentFrame(), value);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPointD FxGadget::getValue(const TPointParamP ¶m) const {
Shinya Kitaoka 120a6e
  return param->getValue(m_controller->getCurrentFrame());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxGadget::setValue(const TPointParamP ¶m, const TPointD &pos) {
Shinya Kitaoka 120a6e
  param->setValue(m_controller->getCurrentFrame(), pos);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun_iwasawa 1fbdc9
void FxGadget::setPixelSize() {
shun_iwasawa 1fbdc9
  setPixelSize(sqrt(tglGetPixelSize2()) * getDevPixRatio());
shun_iwasawa 1fbdc9
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxGadget::drawTooltip(const TPointD &tooltipPos,
Shinya Kitaoka 120a6e
                           std::string tooltipPosText) {
shun_iwasawa 1fbdc9
  double unit = sqrt(tglGetPixelSize2()) * getDevPixRatio();
Shinya Kitaoka 120a6e
  glPushMatrix();
Shinya Kitaoka 120a6e
  glTranslated(tooltipPos.x, tooltipPos.y, 0.0);
Shinya Kitaoka 120a6e
  double sc = unit * 1.6;
Shinya Kitaoka 120a6e
  glScaled(sc, sc, 1);
Shinya Kitaoka 120a6e
  tglDrawText(TPointD(8, -3), tooltipPosText);
Shinya Kitaoka 120a6e
  glPopMatrix();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxGadget::drawDot(const TPointD &pos) {
Shinya Kitaoka 120a6e
  double r = getPixelSize() * 3;
Shinya Kitaoka 120a6e
  tglDrawRect(pos.x - r, pos.y - r, pos.x + r, pos.y + r);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxGadget::onChange(const TParamChange &) {
Shinya Kitaoka 120a6e
  m_controller->invalidateViewer();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxGadget::createUndo() {
Shinya Kitaoka 120a6e
  assert(m_undo == 0);
Shinya Kitaoka 120a6e
  m_undo = new FxGadgetUndo(m_params, m_controller->getCurrentFrame());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxGadget::commitUndo() {
Shinya Kitaoka 120a6e
  assert(m_undo);
Shinya Kitaoka 120a6e
  TUndoManager::manager()->add(m_undo);
Shinya Kitaoka 120a6e
  m_undo = 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*************************************************************************************
Toshihiro Shimizu 890ddd
//    Specific Gadget Concepts  definition
Toshihiro Shimizu 890ddd
//*************************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class PointFxGadget final : public FxGadget {
Shinya Kitaoka 120a6e
  TPointD m_pos;
Shinya Kitaoka 120a6e
  TDoubleParamP m_xParam, m_yParam;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  PointFxGadget(FxGadgetController *controller, const TPointParamP ¶m)
Shinya Kitaoka 120a6e
      : FxGadget(controller), m_xParam(param->getX()), m_yParam(param->getY()) {
Shinya Kitaoka 120a6e
    addParam(m_xParam);
Shinya Kitaoka 120a6e
    addParam(m_yParam);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  PointFxGadget(FxGadgetController *controller, const TDoubleParamP &xParam,
Shinya Kitaoka 120a6e
                const TDoubleParamP &yParam)
Shinya Kitaoka 120a6e
      : FxGadget(controller), m_xParam(xParam), m_yParam(yParam) {
Shinya Kitaoka 120a6e
    addParam(m_xParam);
Shinya Kitaoka 120a6e
    addParam(m_yParam);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void draw(bool picking) override;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPointD getPoint() const {
Shinya Kitaoka 120a6e
    return TPointD(getValue(m_xParam), getValue(m_yParam));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
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
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PointFxGadget::draw(bool picking) {
Shinya Kitaoka 120a6e
  setPixelSize();
Shinya Kitaoka 120a6e
  if (isSelected())
Shinya Kitaoka 120a6e
    glColor3dv(m_selectedColor);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    glColor3d(0, 0, 1);
Shinya Kitaoka 120a6e
  glPushName(getId());
Shinya Kitaoka 120a6e
  TPointD pos(getPoint());
Shinya Kitaoka 120a6e
  double unit = getPixelSize();
Shinya Kitaoka 120a6e
  glPushMatrix();
Shinya Kitaoka 120a6e
  glTranslated(pos.x, pos.y, 0);
Shinya Kitaoka 120a6e
  double r = unit * 3;
Shinya Kitaoka 120a6e
  double d = unit * 6;
Shinya Kitaoka 120a6e
  glBegin(GL_LINES);
Shinya Kitaoka 120a6e
  glVertex2d(-d, 0);
Shinya Kitaoka 120a6e
  glVertex2d(-r, 0);
Shinya Kitaoka 120a6e
  glVertex2d(d, 0);
Shinya Kitaoka 120a6e
  glVertex2d(r, 0);
Shinya Kitaoka 120a6e
  glVertex2d(0, -d);
Shinya Kitaoka 120a6e
  glVertex2d(0, -r);
Shinya Kitaoka 120a6e
  glVertex2d(0, d);
Shinya Kitaoka 120a6e
  glVertex2d(0, r);
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  tglDrawRect(-r, -r, r, r);
Shinya Kitaoka 120a6e
  glPopMatrix();
Shinya Kitaoka 120a6e
  glPopName();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (isSelected()) {
Shinya Kitaoka 120a6e
    drawTooltip(pos + TPointD(7, 3) * unit, getLabel());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PointFxGadget::leftButtonDown(const TPointD &pos, const TMouseEvent &) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PointFxGadget::leftButtonDrag(const TPointD &pos, const TMouseEvent &) {
Shinya Kitaoka 120a6e
  if (m_xParam) setValue(m_xParam, pos.x);
Shinya Kitaoka 120a6e
  if (m_yParam) setValue(m_yParam, pos.y);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PointFxGadget::leftButtonUp(const TPointD &pos, const TMouseEvent &) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class RadiusFxGadget final : public FxGadget {
Shinya Kitaoka 120a6e
  TDoubleParamP m_radius;
Shinya Kitaoka 120a6e
  TPointParamP m_center;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RadiusFxGadget(FxGadgetController *controller, const TDoubleParamP &radius,
Shinya Kitaoka 120a6e
                 const TPointParamP ¢er)
Shinya Kitaoka 120a6e
      : FxGadget(controller), m_radius(radius), m_center(center) {
Shinya Kitaoka 120a6e
    addParam(radius);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPointD getCenter() const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void draw(bool picking) override;
Shinya Kitaoka 120a6e
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
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPointD RadiusFxGadget::getCenter() const {
Shinya Kitaoka 120a6e
  return m_center ? getValue(m_center) : TPointD();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RadiusFxGadget::draw(bool picking) {
Shinya Kitaoka 120a6e
  if (!m_radius) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  setPixelSize();
Shinya Kitaoka 120a6e
  if (isSelected())
Shinya Kitaoka 120a6e
    glColor3dv(m_selectedColor);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    glColor3d(0, 0, 1);
Shinya Kitaoka 120a6e
  glPushName(getId());
Shinya Kitaoka 120a6e
  double radius  = getValue(m_radius);
Shinya Kitaoka 120a6e
  TPointD center = getCenter();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glLineStipple(1, 0xAAAA);
Shinya Kitaoka 120a6e
  glEnable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
  tglDrawCircle(center, radius);
Shinya Kitaoka 120a6e
  glDisable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
  drawDot(center + TPointD(0.707, 0.707) * radius);
Shinya Kitaoka 120a6e
  glPopName();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (isSelected()) {
Shinya Kitaoka 120a6e
    drawTooltip(center + TPointD(0.707, 0.707) * radius, getLabel());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RadiusFxGadget::leftButtonDown(const TPointD &pos, const TMouseEvent &) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RadiusFxGadget::leftButtonDrag(const TPointD &pos, const TMouseEvent &) {
Shinya Kitaoka 120a6e
  setValue(m_radius, norm(pos - getCenter()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RadiusFxGadget::leftButtonUp(const TPointD &pos, const TMouseEvent &) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DistanceFxGadget final : public FxGadget {
Shinya Kitaoka 120a6e
  TDoubleParamP m_distance, m_angle;
Shinya Kitaoka 120a6e
  int m_grabPos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DistanceFxGadget(FxGadgetController *controller,
Shinya Kitaoka 120a6e
                   const TDoubleParamP &distance, const TDoubleParamP &angle)
Shinya Kitaoka 120a6e
      : FxGadget(controller)
Shinya Kitaoka 120a6e
      , m_distance(distance)
Shinya Kitaoka 120a6e
      , m_angle(angle)
Shinya Kitaoka 120a6e
      , m_grabPos(1) {
Shinya Kitaoka 120a6e
    addParam(distance);
Shinya Kitaoka 120a6e
    if (angle) addParam(angle);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPointD getDirection() const {
Shinya Kitaoka 120a6e
    if (!m_angle) return TPointD(1.0, 0.0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    double angle = getValue(m_angle);
Shinya Kitaoka 120a6e
    return TPointD(cos(angle), sin(angle));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void draw(bool picking) override;
Shinya Kitaoka 120a6e
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
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DistanceFxGadget::draw(bool picking) {
Shinya Kitaoka 120a6e
  if (!m_distance) return;
Shinya Kitaoka 120a6e
  setPixelSize();
Shinya Kitaoka 120a6e
  glColor3d(0, 0, 1);
Shinya Kitaoka 120a6e
  double d = getValue(m_distance) * getScaleFactor();
Shinya Kitaoka 120a6e
  TPointD dir(getDirection());
Shinya Kitaoka 120a6e
  TPointD u = rotate90(dir) * (getPixelSize() * 10);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tglDrawSegment(-u, u);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glPushName(getId());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPointD b, c;
Shinya Kitaoka 120a6e
  b = dir * (d * 0.5);
Shinya Kitaoka 120a6e
  c = b - dir * d;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tglDrawSegment(b - u, b + u);
Shinya Kitaoka 120a6e
  tglDrawCircle(b, getPixelSize() * 5);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tglDrawSegment(c - u, c + u);
Shinya Kitaoka 120a6e
  tglDrawCircle(c, getPixelSize() * 5);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glPopName();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  glLineStipple(1, 0xAAAA);
Shinya Kitaoka 120a6e
  glEnable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
  tglDrawSegment(b, c);
Shinya Kitaoka 120a6e
  glDisable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
  if (isSelected()) {
Shinya Kitaoka 120a6e
    drawTooltip(b + TPointD(5, 5) * getPixelSize(), getLabel());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DistanceFxGadget::leftButtonDown(const TPointD &pos, const TMouseEvent &) {
Shinya Kitaoka 120a6e
  m_grabPos = (pos.x > 0.0) ? 1 : -1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DistanceFxGadget::leftButtonDrag(const TPointD &pos, const TMouseEvent &) {
Shinya Kitaoka 120a6e
  double v = (pos * getDirection()) / getScaleFactor();
Shinya Kitaoka 120a6e
  v        = v * 2 * m_grabPos;
Shinya Kitaoka 120a6e
  setValue(m_distance, v);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DistanceFxGadget::leftButtonUp(const TPointD &pos, const TMouseEvent &) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class AngleFxGadget final : public FxGadget {
Shinya Kitaoka 120a6e
  TDoubleParamP m_param;
Shinya Kitaoka 120a6e
  TPointD m_pos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  AngleFxGadget(FxGadgetController *controller, const TDoubleParamP ¶m,
Shinya Kitaoka 120a6e
                const TPointD &pos);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void draw(bool picking) 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
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
AngleFxGadget::AngleFxGadget(FxGadgetController *controller,
Shinya Kitaoka 120a6e
                             const TDoubleParamP ¶m, const TPointD &pos)
Shinya Kitaoka 120a6e
    : FxGadget(controller), m_param(param), m_pos(pos) {
Shinya Kitaoka 120a6e
  addParam(param);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void AngleFxGadget::draw(bool picking) {
Shinya Kitaoka 120a6e
  if (isSelected())
Shinya Kitaoka 120a6e
    glColor3dv(m_selectedColor);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    glColor3d(0, 0, 1);
Shinya Kitaoka 120a6e
  glPushName(getId());
shun_iwasawa 1fbdc9
  double pixelSize = sqrt(tglGetPixelSize2()) * getDevPixRatio();
Shinya Kitaoka 120a6e
  double r         = pixelSize * 40;
Shinya Kitaoka 120a6e
  double a = pixelSize * 10, b = pixelSize * 5;
Shinya Kitaoka 120a6e
  tglDrawCircle(m_pos, r);
Shinya Kitaoka 120a6e
  double phi = getValue(m_param);
Shinya Kitaoka 120a6e
  glPushMatrix();
Shinya Kitaoka 120a6e
  glTranslated(m_pos.x, m_pos.y, 0);
Shinya Kitaoka 120a6e
  glRotated(phi, 0, 0, 1);
Shinya Kitaoka 120a6e
  glBegin(GL_LINES);
Shinya Kitaoka 120a6e
  glVertex2d(0, 0);
Shinya Kitaoka 120a6e
  glVertex2d(r, 0);
Shinya Kitaoka 120a6e
  glVertex2d(r, 0);
Shinya Kitaoka 120a6e
  glVertex2d(r - a, b);
Shinya Kitaoka 120a6e
  glVertex2d(r, 0);
Shinya Kitaoka 120a6e
  glVertex2d(r - a, -b);
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  glPopMatrix();
Shinya Kitaoka 120a6e
  glPopName();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (isSelected()) {
Shinya Kitaoka 120a6e
    drawTooltip(m_pos + TPointD(0.707, 0.707) * r, getLabel());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void AngleFxGadget::leftButtonDown(const TPointD &pos, const TMouseEvent &) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void AngleFxGadget::leftButtonDrag(const TPointD &pos, const TMouseEvent &) {
Shinya Kitaoka 120a6e
  TPointD d  = pos - m_pos;
Shinya Kitaoka 120a6e
  double phi = atan2(d.y, d.x);
Shinya Kitaoka 120a6e
  setValue(m_param, phi * M_180_PI);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void AngleFxGadget::leftButtonUp(const TPointD &pos, const TMouseEvent &) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DiamondFxGadget final : public FxGadget {
Shinya Kitaoka 120a6e
  TDoubleParamP m_param;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DiamondFxGadget(FxGadgetController *controller, const TDoubleParamP ¶m)
Shinya Kitaoka 120a6e
      : FxGadget(controller), m_param(param) {
Shinya Kitaoka 120a6e
    addParam(param);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void draw(bool picking) 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
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DiamondFxGadget::draw(bool picking) {
Shinya Kitaoka 120a6e
  setPixelSize();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (isSelected())
Shinya Kitaoka 120a6e
    glColor3dv(m_selectedColor);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    glColor3d(0, 0, 1);
Shinya Kitaoka 120a6e
  glPushName(getId());
Shinya Kitaoka 120a6e
  double size = getValue(m_param);
Shinya Kitaoka 120a6e
  double r    = 3 * getPixelSize();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glLineStipple(1, 0xAAAA);
Shinya Kitaoka 120a6e
  glEnable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
  glBegin(GL_LINES);
Shinya Kitaoka 120a6e
  glVertex2d(-size + r, r);
Shinya Kitaoka 120a6e
  glVertex2d(-r, size - r);
Shinya Kitaoka 120a6e
  glVertex2d(r, size - r);
Shinya Kitaoka 120a6e
  glVertex2d(size - r, r);
Shinya Kitaoka 120a6e
  glVertex2d(size - r, -r);
Shinya Kitaoka 120a6e
  glVertex2d(r, -size + r);
Shinya Kitaoka 120a6e
  glVertex2d(-r, -size + r);
Shinya Kitaoka 120a6e
  glVertex2d(-size + r, -r);
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  glDisable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
  drawDot(-size, 0);
Shinya Kitaoka 120a6e
  drawDot(size, 0);
Shinya Kitaoka 120a6e
  drawDot(0, -size);
Shinya Kitaoka 120a6e
  drawDot(0, size);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double d = getPixelSize() * 3;
Shinya Kitaoka 120a6e
  glPopName();
Shinya Kitaoka 120a6e
  if (isSelected()) {
Shinya Kitaoka 120a6e
    drawTooltip(TPointD(d, size - d), getLabel());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DiamondFxGadget::leftButtonDrag(const TPointD &pos, const TMouseEvent &) {
Shinya Kitaoka 120a6e
  double sz        = fabs(pos.x) + fabs(pos.y);
Shinya Kitaoka 120a6e
  if (sz < 0.1) sz = 0.1;
Shinya Kitaoka 120a6e
  setValue(m_param, sz);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class SizeFxGadget final : public FxGadget {
Shinya Kitaoka 120a6e
  TDoubleParamP m_lx, m_ly;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  SizeFxGadget(FxGadgetController *controller, const TDoubleParamP &lx,
Shinya Kitaoka 120a6e
               const TDoubleParamP &ly)
Shinya Kitaoka 120a6e
      : FxGadget(controller), m_lx(lx), m_ly(ly) {
Shinya Kitaoka 120a6e
    addParam(lx);
Shinya Kitaoka 120a6e
    if (ly) addParam(ly);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void draw(bool picking) override;
Shinya Kitaoka 120a6e
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
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SizeFxGadget::draw(bool picking) {
Shinya Kitaoka 120a6e
  setPixelSize();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (isSelected())
Shinya Kitaoka 120a6e
    glColor3dv(m_selectedColor);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    glColor3d(0, 0, 1);
Shinya Kitaoka 120a6e
  glPushName(getId());
Shinya Kitaoka 120a6e
  double lx = getValue(m_lx), ly = m_ly ? getValue(m_ly) : lx;
Shinya Kitaoka 120a6e
  double r = getPixelSize() * 3;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glLineStipple(1, 0xCCCC);
Shinya Kitaoka 120a6e
  glEnable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
  glBegin(GL_LINES);
Shinya Kitaoka 120a6e
  glVertex2d(0, 0);
Shinya Kitaoka 120a6e
  glVertex2d(lx, 0);
Shinya Kitaoka 120a6e
  glVertex2d(0, 0);
Shinya Kitaoka 120a6e
  glVertex2d(0, ly);
Shinya Kitaoka 120a6e
  glVertex2d(lx, 0);
Shinya Kitaoka 120a6e
  glVertex2d(lx, ly - r);
Shinya Kitaoka 120a6e
  glVertex2d(0, ly);
Shinya Kitaoka 120a6e
  glVertex2d(lx - r, ly);
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  glDisable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
  drawDot(lx, ly);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double d = getPixelSize() * 3;
Shinya Kitaoka 120a6e
  glPopName();
Shinya Kitaoka 120a6e
  if (isSelected()) {
Shinya Kitaoka 120a6e
    drawTooltip(TPointD(lx, ly), getLabel());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SizeFxGadget::leftButtonDrag(const TPointD &pos, const TMouseEvent &) {
Shinya Kitaoka 120a6e
  if (m_ly)
Shinya Kitaoka 120a6e
    setValue(m_lx, std::max(pos.x, 0.1)), setValue(m_ly, std::max(pos.y, 0.1));
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    setValue(m_lx, std::max({pos.x, pos.y, 0.1}));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class RectFxGadget final : public FxGadget {
Shinya Kitaoka 120a6e
  TDoubleParamP m_width, m_height;
Shinya Kitaoka 120a6e
  TPointParamP m_center;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int m_picked;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  enum { None, Corner, HorizontalSide, VerticalSide };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RectFxGadget(FxGadgetController *controller, const TDoubleParamP &width,
Shinya Kitaoka 120a6e
               const TDoubleParamP &height, const TPointParamP ¢er)
Shinya Kitaoka 120a6e
      : FxGadget(controller)
Shinya Kitaoka 120a6e
      , m_width(width)
Shinya Kitaoka 120a6e
      , m_height(height)
Shinya Kitaoka 120a6e
      , m_center(center)
Shinya Kitaoka 120a6e
      , m_picked(None) {
Shinya Kitaoka 120a6e
    addParam(width);
Shinya Kitaoka 120a6e
    addParam(height);
Shinya Kitaoka 120a6e
    if (center) addParam(center->getX()), addParam(center->getY());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPointD getCenter() const {
Shinya Kitaoka 120a6e
    return m_center ? getValue(m_center) : TPointD();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void draw(bool picking) override;
Shinya Kitaoka 120a6e
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
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RectFxGadget::draw(bool picking) {
Shinya Kitaoka 120a6e
  setPixelSize();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (isSelected())
Shinya Kitaoka 120a6e
    glColor3dv(m_selectedColor);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    glColor3d(0, 0, 1);
Shinya Kitaoka 120a6e
  glPushName(getId());
Shinya Kitaoka 120a6e
  glPushMatrix();
Shinya Kitaoka 120a6e
  TPointD center = getCenter();
Shinya Kitaoka 120a6e
  glTranslated(center.x, center.y, 0);
Shinya Kitaoka 120a6e
  double w_2 = 0.5 * getValue(m_width);
Shinya Kitaoka 120a6e
  double h_2 = 0.5 * getValue(m_height);
Shinya Kitaoka 120a6e
  double r   = getPixelSize() * 3;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glLineStipple(1, 0xCCCC);
Shinya Kitaoka 120a6e
  glEnable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
  glBegin(GL_LINES);
Shinya Kitaoka 120a6e
  glVertex2d(-w_2 + r, -h_2);
Shinya Kitaoka 120a6e
  glVertex2d(w_2 - r, -h_2);
Shinya Kitaoka 120a6e
  glVertex2d(-w_2 + r, h_2);
Shinya Kitaoka 120a6e
  glVertex2d(w_2 - r, h_2);
Shinya Kitaoka 120a6e
  glVertex2d(-w_2, -h_2 + r);
Shinya Kitaoka 120a6e
  glVertex2d(-w_2, h_2 - r);
Shinya Kitaoka 120a6e
  glVertex2d(w_2, -h_2 + r);
Shinya Kitaoka 120a6e
  glVertex2d(w_2, h_2 - r);
Shinya Kitaoka 120a6e
  glEnd();
Shinya Kitaoka 120a6e
  glDisable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
  drawDot(w_2, h_2);
Shinya Kitaoka 120a6e
  drawDot(-w_2, h_2);
Shinya Kitaoka 120a6e
  drawDot(w_2, -h_2);
Shinya Kitaoka 120a6e
  drawDot(-w_2, -h_2);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  glPopMatrix();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RectFxGadget::leftButtonDown(const TPointD &ppos, const TMouseEvent &) {
Shinya Kitaoka 120a6e
  TPointD pos = ppos - getCenter();
Shinya Kitaoka 120a6e
  m_picked    = None;
Shinya Kitaoka 120a6e
  double w_2  = 0.5 * getValue(m_width);
Shinya Kitaoka 120a6e
  double h_2  = 0.5 * getValue(m_height);
Shinya Kitaoka 120a6e
  double x    = fabs(pos.x);
Shinya Kitaoka 120a6e
  double y    = fabs(pos.y);
Shinya Kitaoka 120a6e
  double r    = getPixelSize() * 15;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (fabs(w_2 - x) < r && fabs(y - h_2) < r)
Shinya Kitaoka 120a6e
    m_picked = Corner;
Shinya Kitaoka 120a6e
  else if (fabs(w_2 - x) < r && y < h_2)
Shinya Kitaoka 120a6e
    m_picked = VerticalSide;
Shinya Kitaoka 120a6e
  else if (fabs(h_2 - y) < r && x < w_2)
Shinya Kitaoka 120a6e
    m_picked = HorizontalSide;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RectFxGadget::leftButtonDrag(const TPointD &ppos, const TMouseEvent &) {
Shinya Kitaoka 120a6e
  TPointD pos = ppos - getCenter();
Shinya Kitaoka 120a6e
  double w = fabs(pos.x), h = fabs(pos.y);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_picked == Corner || m_picked == VerticalSide)
Shinya Kitaoka 120a6e
    setValue(m_width, 2.0 * w);
Shinya Kitaoka 120a6e
  if (m_picked == Corner || m_picked == HorizontalSide)
Shinya Kitaoka 120a6e
    setValue(m_height, 2.0 * h);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class PolarFxGadget final : public FxGadget {
Shinya Kitaoka 120a6e
  TPointD m_pos;
Shinya Kitaoka 120a6e
  TDoubleParamP m_phiParam, m_lengthParam;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  PolarFxGadget(FxGadgetController *controller, const TPointD &pos,
Shinya Kitaoka 120a6e
                const TDoubleParamP &phiParam, const TDoubleParamP &lengthParam)
Shinya Kitaoka 120a6e
      : FxGadget(controller)
Shinya Kitaoka 120a6e
      , m_pos(pos)
Shinya Kitaoka 120a6e
      , m_phiParam(phiParam)
Shinya Kitaoka 120a6e
      , m_lengthParam(lengthParam) {
Shinya Kitaoka 120a6e
    addParam(phiParam);
Shinya Kitaoka 120a6e
    addParam(lengthParam);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void draw(bool picking) override {
Shinya Kitaoka 120a6e
    setPixelSize();
Shinya Kitaoka 120a6e
    if (isSelected())
Shinya Kitaoka 120a6e
      glColor3dv(m_selectedColor);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      glColor3d(0, 0, 1);
Shinya Kitaoka 120a6e
    glPushName(getId());
Shinya Kitaoka 120a6e
    double pixelSize = getPixelSize();
Shinya Kitaoka 120a6e
    double r         = getValue(m_lengthParam);
Shinya Kitaoka 120a6e
    double a = pixelSize * 10, b = pixelSize * 5, c = pixelSize * 4;
Shinya Kitaoka 120a6e
    // tglDrawCircle(m_pos, r);
Shinya Kitaoka 120a6e
    double phi = getValue(m_phiParam);
Shinya Kitaoka 120a6e
    glPushMatrix();
Shinya Kitaoka 120a6e
    glTranslated(m_pos.x, m_pos.y, 0);
Shinya Kitaoka 120a6e
    glRotated(phi, 0, 0, 1);
Shinya Kitaoka 120a6e
    double rr = r - c;
Shinya Kitaoka 120a6e
    if (rr > 0) {
Shinya Kitaoka 120a6e
      glLineStipple(1, 0xAAAA);
Shinya Kitaoka 120a6e
      glEnable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
      glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
      glVertex2d(0, 0);
Shinya Kitaoka 120a6e
      glVertex2d(rr, 0);
Shinya Kitaoka 120a6e
      glEnd();
Shinya Kitaoka 120a6e
      glDisable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    glBegin(GL_LINES);
Shinya Kitaoka 120a6e
    glVertex2d(rr, 0);
Shinya Kitaoka 120a6e
    glVertex2d(rr - a, b);
Shinya Kitaoka 120a6e
    glVertex2d(rr, 0);
Shinya Kitaoka 120a6e
    glVertex2d(rr - a, -b);
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
    glTranslated(r, 0, 0);
Shinya Kitaoka 120a6e
    glRotated(-phi, 0, 0, 1);
Shinya Kitaoka 120a6e
    drawDot(0, 0);
Shinya Kitaoka 120a6e
    glPopMatrix();
Shinya Kitaoka 120a6e
    glPopName();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (isSelected()) {
Shinya Kitaoka 120a6e
      double phiRad      = phi * M_PI_180;
Shinya Kitaoka 120a6e
      TPointD toolTipPos = m_pos + r * TPointD(cos(phiRad), sin(phiRad));
Shinya Kitaoka 120a6e
      drawTooltip(toolTipPos, getLabel());
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &) override {}
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &) override {
Shinya Kitaoka 120a6e
    TPointD d     = pos - m_pos;
Shinya Kitaoka 120a6e
    double phi    = atan2(d.y, d.x);
Shinya Kitaoka 120a6e
    double length = norm(d);
Shinya Kitaoka 120a6e
    setValue(m_phiParam, phi * M_180_PI);
Shinya Kitaoka 120a6e
    setValue(m_lengthParam, length);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  void leftButtonUp(const TPointD &pos, const TMouseEvent &) override {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class VectorFxGadget final : public FxGadget {
Shinya Kitaoka 120a6e
  TPointParamP m_pa, m_pb;
Shinya Kitaoka 120a6e
  int m_selected;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  VectorFxGadget(FxGadgetController *controller, const TPointParamP &pa,
Shinya Kitaoka 120a6e
                 const TPointParamP &pb)
Shinya Kitaoka 120a6e
      : FxGadget(controller), m_pa(pa), m_pb(pb), m_selected(0) {
Shinya Kitaoka 120a6e
    addParam(pa->getX());
Shinya Kitaoka 120a6e
    addParam(pa->getY());
Shinya Kitaoka 120a6e
    addParam(pb->getX());
Shinya Kitaoka 120a6e
    addParam(pb->getY());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void draw(bool picking) override {
Shinya Kitaoka 120a6e
    setPixelSize();
Shinya Kitaoka 120a6e
    if (isSelected())
Shinya Kitaoka 120a6e
      glColor3dv(m_selectedColor);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      glColor3d(0, 0, 1);
Shinya Kitaoka 120a6e
    glPushName(getId());
Shinya Kitaoka 120a6e
    double pixelSize = getPixelSize();
Shinya Kitaoka 120a6e
    TPointD pa       = getValue(m_pa);
Shinya Kitaoka 120a6e
    TPointD pb       = getValue(m_pb);
Shinya Kitaoka 120a6e
    TPointD dab      = pb - pa;
Shinya Kitaoka 120a6e
    double ab2       = norm2(dab);
Shinya Kitaoka 120a6e
    if (ab2 > 0.0001) {
Shinya Kitaoka 120a6e
      double ab = sqrt(ab2);
Shinya Kitaoka 120a6e
      TPointD u = dab * (1.0 / ab);
Shinya Kitaoka 120a6e
      TPointD v = rotate90(u);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      double a = pixelSize * 10, b = pixelSize * 5;
Shinya Kitaoka 120a6e
      double c = pixelSize * 4;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      TPointD pbb = pb - u * c;
Shinya Kitaoka 120a6e
      if (ab - c > 0) {
Shinya Kitaoka 120a6e
        glLineStipple(1, 0xAAAA);
Shinya Kitaoka 120a6e
        glEnable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
        tglDrawSegment(pa, pbb);
Shinya Kitaoka 120a6e
        glDisable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      tglDrawSegment(pbb, pbb - u * a + v * b);
Shinya Kitaoka 120a6e
      tglDrawSegment(pbb, pbb - u * a - v * b);
Shinya Kitaoka 120a6e
      drawDot(pa);
Shinya Kitaoka 120a6e
      drawDot(pb);
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      drawDot(pa);
Shinya Kitaoka 120a6e
    glPopName();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
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
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class QuadFxGadget final : public FxGadget {
Shinya Kitaoka 120a6e
  TPointParamP m_pa, m_pb, m_pc, m_pd;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  QuadFxGadget(FxGadgetController *controller, const TPointParamP &pa,
Shinya Kitaoka 120a6e
               const TPointParamP &pb, const TPointParamP &pc,
Shinya Kitaoka 120a6e
               const TPointParamP &pd)
Shinya Kitaoka 120a6e
      : FxGadget(controller), m_pa(pa), m_pb(pb), m_pc(pc), m_pd(pd) {
Shinya Kitaoka 120a6e
    addParam(pa->getX());
Shinya Kitaoka 120a6e
    addParam(pa->getY());
Shinya Kitaoka 120a6e
    addParam(pb->getX());
Shinya Kitaoka 120a6e
    addParam(pb->getY());
Shinya Kitaoka 120a6e
    addParam(pc->getX());
Shinya Kitaoka 120a6e
    addParam(pc->getY());
Shinya Kitaoka 120a6e
    addParam(pd->getX());
Shinya Kitaoka 120a6e
    addParam(pd->getY());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void draw(bool picking) override {
Shinya Kitaoka 120a6e
    setPixelSize();
Shinya Kitaoka 120a6e
    if (isSelected())
Shinya Kitaoka 120a6e
      glColor3dv(m_selectedColor);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      glColor3d(0, 0, 1);
Shinya Kitaoka 120a6e
    // glPushName(getId());
Shinya Kitaoka 120a6e
    double pixelSize = getPixelSize();
Shinya Kitaoka 120a6e
    TPointD pa       = getValue(m_pa);
Shinya Kitaoka 120a6e
    TPointD pb       = getValue(m_pb);
Shinya Kitaoka 120a6e
    TPointD pc       = getValue(m_pc);
Shinya Kitaoka 120a6e
    TPointD pd       = getValue(m_pd);
Shinya Kitaoka 120a6e
    glLineStipple(1, 0xCCCC);
Shinya Kitaoka 120a6e
    glEnable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
    glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
    tglVertex(pa);
Shinya Kitaoka 120a6e
    tglVertex(pb);
Shinya Kitaoka 120a6e
    tglVertex(pc);
Shinya Kitaoka 120a6e
    tglVertex(pd);
Shinya Kitaoka 120a6e
    tglVertex(pa);
Shinya Kitaoka 120a6e
    glEnd();
Shinya Kitaoka 120a6e
    glDisable(GL_LINE_STIPPLE);
Shinya Kitaoka 120a6e
    // glPopName();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
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
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*************************************************************************************
Toshihiro Shimizu 890ddd
//    FxGadgetController  implementation
Toshihiro Shimizu 890ddd
//*************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FxGadgetController::FxGadgetController(TTool *tool)
Shinya Kitaoka 120a6e
    : m_tool(tool)
Shinya Kitaoka 120a6e
    , m_fxHandle(tool->getApplication()->getCurrentFx())
Shinya Kitaoka 120a6e
    , m_idBase(0)
Shinya Kitaoka 120a6e
    , m_nextId(0)
Shinya Kitaoka 120a6e
    , m_selectedGadget(0)
Shinya Kitaoka 120a6e
    , m_editingNonZeraryFx(false) {
Shinya Kitaoka 120a6e
  m_idBase = m_nextId = 5000;
Shinya Kitaoka 120a6e
  connect(m_fxHandle, SIGNAL(fxSwitched()), this, SLOT(onFxSwitched()));
Shinya Kitaoka 120a6e
  connect(tool->getApplication()->getCurrentXsheet(), SIGNAL(xsheetChanged()),
Shinya Kitaoka 120a6e
          this, SLOT(onFxSwitched()));
Shinya Kitaoka 120a6e
  onFxSwitched();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FxGadgetController::~FxGadgetController() { clearGadgets(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxGadgetController::clearGadgets() {
Shinya Kitaoka 120a6e
  std::vector<fxgadget *="">::iterator it;</fxgadget>
Shinya Kitaoka 120a6e
  for (it = m_gadgets.begin(); it != m_gadgets.end(); ++it) delete (*it);
Shinya Kitaoka 120a6e
  m_gadgets.clear();
Shinya Kitaoka 120a6e
  m_idTable.clear();
Shinya Kitaoka 120a6e
  m_selectedGadget = 0;
Shinya Kitaoka 120a6e
  m_nextId         = m_idBase;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxGadgetController::assignId(FxGadget *gadget) {
Shinya Kitaoka 120a6e
  gadget->setId(m_nextId);
Shinya Kitaoka 120a6e
  m_idTable[m_nextId] = gadget;
Shinya Kitaoka 120a6e
  ++m_nextId;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxGadgetController::addGadget(FxGadget *gadget) {
Shinya Kitaoka 120a6e
  m_gadgets.push_back(gadget);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxGadgetController::draw(bool picking) {
Shinya Kitaoka 120a6e
  glPushMatrix();
Shinya Kitaoka 120a6e
  tglMultMatrix(getMatrix());
Shinya Kitaoka 120a6e
  std::vector<fxgadget *="">::iterator it;</fxgadget>
Shinya Kitaoka 120a6e
  for (it = m_gadgets.begin(); it != m_gadgets.end(); ++it)
Shinya Kitaoka 120a6e
    (*it)->draw(picking);
Shinya Kitaoka 120a6e
  glPopMatrix();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxGadgetController::selectById(unsigned int id) {
Shinya Kitaoka 120a6e
  std::map<gluint, *="" fxgadget="">::iterator it;</gluint,>
Shinya Kitaoka 120a6e
  it                       = m_idTable.find(id);
Shinya Kitaoka 120a6e
  FxGadget *selectedGadget = it != m_idTable.end() ? it->second : 0;
Shinya Kitaoka 120a6e
  if (selectedGadget != m_selectedGadget) {
Shinya Kitaoka 120a6e
    if (m_selectedGadget) m_selectedGadget->select(false);
Shinya Kitaoka 120a6e
    m_selectedGadget = selectedGadget;
Shinya Kitaoka 120a6e
    if (m_selectedGadget) m_selectedGadget->select(true);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FxGadget *FxGadgetController::allocateGadget(const TParamUIConcept &uiConcept) {
Shinya Kitaoka 120a6e
  FxGadget *gadget = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  switch (uiConcept.m_type) {
Shinya Kitaoka 120a6e
  case TParamUIConcept::RADIUS: {
Shinya Kitaoka 120a6e
    assert(uiConcept.m_params.size() >= 1 && uiConcept.m_params.size() <= 2);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TPointParamP center((uiConcept.m_params.size() >= 2)
Shinya Kitaoka 120a6e
                            ? (TPointParamP)uiConcept.m_params[1]
Shinya Kitaoka 120a6e
                            : TPointParamP());
Shinya Kitaoka 120a6e
    gadget = new RadiusFxGadget(this, uiConcept.m_params[0], center);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case TParamUIConcept::WIDTH: {
Shinya Kitaoka 120a6e
    assert(uiConcept.m_params.size() >= 1 && uiConcept.m_params.size() <= 2);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TDoubleParamP angle((uiConcept.m_params.size() >= 2)
Shinya Kitaoka 120a6e
                            ? (TDoubleParamP)uiConcept.m_params[1]
Shinya Kitaoka 120a6e
                            : TDoubleParamP());
Shinya Kitaoka 120a6e
    gadget = new DistanceFxGadget(this, uiConcept.m_params[0], angle);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case TParamUIConcept::ANGLE: {
Shinya Kitaoka 120a6e
    assert(uiConcept.m_params.size() == 1);
Shinya Kitaoka 120a6e
    gadget = new AngleFxGadget(this, uiConcept.m_params[0], TPointD());
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case TParamUIConcept::POINT: {
Shinya Kitaoka 120a6e
    assert(uiConcept.m_params.size() == 1);
Shinya Kitaoka 120a6e
    gadget = new PointFxGadget(this, uiConcept.m_params[0]);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case TParamUIConcept::POINT_2: {
Shinya Kitaoka 120a6e
    assert(uiConcept.m_params.size() == 2);
Shinya Kitaoka 120a6e
    gadget =
Shinya Kitaoka 120a6e
        new PointFxGadget(this, uiConcept.m_params[0], uiConcept.m_params[1]);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case TParamUIConcept::VECTOR: {
Shinya Kitaoka 120a6e
    assert(uiConcept.m_params.size() == 2);
Shinya Kitaoka 120a6e
    gadget =
Shinya Kitaoka 120a6e
        new VectorFxGadget(this, uiConcept.m_params[0], uiConcept.m_params[1]);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case TParamUIConcept::POLAR: {
Shinya Kitaoka 120a6e
    assert(uiConcept.m_params.size() == 2);
Shinya Kitaoka 120a6e
    gadget = new PolarFxGadget(this, TPointD(), uiConcept.m_params[0],
Shinya Kitaoka 120a6e
                               uiConcept.m_params[1]);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case TParamUIConcept::SIZE: {
Shinya Kitaoka 120a6e
    assert(uiConcept.m_params.size() >= 1 && uiConcept.m_params.size() <= 2);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TDoubleParamP y((uiConcept.m_params.size() >= 2)
Shinya Kitaoka 120a6e
                        ? (TDoubleParamP)uiConcept.m_params[1]
Shinya Kitaoka 120a6e
                        : TDoubleParamP());
Shinya Kitaoka 120a6e
    gadget = new SizeFxGadget(this, uiConcept.m_params[0], y);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case TParamUIConcept::QUAD: {
Shinya Kitaoka 120a6e
    assert(uiConcept.m_params.size() == 4);
Shinya Kitaoka 120a6e
    gadget =
Shinya Kitaoka 120a6e
        new QuadFxGadget(this, uiConcept.m_params[0], uiConcept.m_params[1],
Shinya Kitaoka 120a6e
                         uiConcept.m_params[2], uiConcept.m_params[3]);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case TParamUIConcept::RECT: {
Shinya Kitaoka 120a6e
    assert(uiConcept.m_params.size() >= 2 && uiConcept.m_params.size() <= 3);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TPointParamP center((uiConcept.m_params.size() >= 3)
Shinya Kitaoka 120a6e
                            ? (TPointParamP)uiConcept.m_params[2]
Shinya Kitaoka 120a6e
                            : TPointParamP());
Shinya Kitaoka 120a6e
    gadget = new RectFxGadget(this, uiConcept.m_params[0],
Shinya Kitaoka 120a6e
                              uiConcept.m_params[1], center);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case TParamUIConcept::DIAMOND: {
Shinya Kitaoka 120a6e
    assert(uiConcept.m_params.size() == 1);
Shinya Kitaoka 120a6e
    gadget = new DiamondFxGadget(this, uiConcept.m_params[0]);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (gadget) gadget->setLabel(uiConcept.m_label);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return gadget;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxGadgetController::onFxSwitched() {
Shinya Kitaoka 120a6e
  clearGadgets();
Shinya Kitaoka 120a6e
  bool enabled = false;
Shinya Kitaoka 120a6e
  TFx *fx      = m_fxHandle ? m_fxHandle->getFx() : 0;
Shinya Kitaoka 120a6e
  if (fx) {
Shinya Kitaoka 120a6e
    int referenceColumnIndex = fx->getReferenceColumnIndex();
Shinya Kitaoka 120a6e
    if (referenceColumnIndex == -1) {
Shinya Kitaoka 120a6e
      TObjectHandle *oh = m_tool->getApplication()->getCurrentObject();
Shinya Kitaoka 120a6e
      if (!oh->getObjectId().isCamera()) {
John Dancel c323ac
        TXsheet *xsh = m_tool->getXsheet();
John Dancel c323ac
        oh->setObjectId(TStageObjectId::CameraId(xsh->getCameraColumnIndex()));
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      enabled = true;
Shinya Kitaoka 120a6e
    } else if (referenceColumnIndex == m_tool->getColumnIndex())
Shinya Kitaoka 120a6e
      enabled = true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (fx && enabled) {
Shinya Kitaoka 120a6e
    m_editingNonZeraryFx = true;
Shinya Kitaoka 120a6e
    TZeraryColumnFx *zfx = 0;
Shinya Kitaoka 120a6e
    if ((zfx = dynamic_cast<tzerarycolumnfx *="">(fx)) ||</tzerarycolumnfx>
Shinya Kitaoka 120a6e
        dynamic_cast<tlevelcolumnfx *="">(fx))</tlevelcolumnfx>
Shinya Kitaoka 120a6e
    // WARNING! quick patch for huge bug:  I added the || with TLevelColumnFx;
Shinya Kitaoka 120a6e
    // before, the levels were considered as nonZeraryFx and the edit tool
Shinya Kitaoka 120a6e
    // gadget was not displayed! Vinz
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      if (zfx) fx          = zfx->getZeraryFx();
Shinya Kitaoka 120a6e
      m_editingNonZeraryFx = false;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // Parse the UI Concepts returned by the fx
Shinya Kitaoka 120a6e
    TParamUIConcept *uiConcepts = 0;
Shinya Kitaoka 120a6e
    int i, count;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    fx->getParamUIs(uiConcepts, count);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    for (i = 0; i < count; ++i) {
Shinya Kitaoka 120a6e
      FxGadget *gadget = allocateGadget(uiConcepts[i]);
Shinya Kitaoka 120a6e
      if (gadget) addGadget(gadget);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    delete[] uiConcepts;
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    m_editingNonZeraryFx = false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_tool->invalidate();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
EditToolGadgets::DragTool *FxGadgetController::createDragTool(int gadgetId) {
Shinya Kitaoka 120a6e
  selectById(gadgetId);
Shinya Kitaoka 120a6e
  if (m_selectedGadget)
Shinya Kitaoka 120a6e
    return new GadgetDragTool(this, m_selectedGadget);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TAffine FxGadgetController::getMatrix() {
Shinya Kitaoka 120a6e
  return m_tool->getMatrix().inv() * m_tool->getCurrentColumnMatrix();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int FxGadgetController::getCurrentFrame() const { return m_tool->getFrame(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxGadgetController::invalidateViewer() { m_tool->invalidate(); }