void multiAutocloseRegion(TStroke *stroke, const TMouseEvent &e) {
   TTool::Application *app = TTool::getApplication();
   if (m_firstStroke) {
     multiApplyAutoclose(m_firstFrameId, getFrameId(), TRectD(), TRectD(),
                         m_firstStroke, stroke);
     invalidate();
     if (e.isShiftPressed()) {
       delete m_firstStroke;
       m_firstStroke  = new TStroke(*stroke);
       m_firstFrameId = getFrameId();
     } else {
       if (m_isXsheetCell) {
         app->getCurrentColumn()->setColumnIndex(m_currCell.first);
         app->getCurrentFrame()->setFrame(m_currCell.second);
       } else
         app->getCurrentFrame()->setFid(m_veryFirstFrameId);
       resetMulti();
     }
   } else {
     m_isXsheetCell = app->getCurrentFrame()->isEditingScene();
     // if (m_isXsheetCell)
     m_currCell    = std::pair<int, int>(getColumnIndex(), getFrame());
     m_firstStroke = new TStroke(*stroke);
   }
   return;
 }
void TTextList::leftButtonDown(const TMouseEvent &e) {
  int i = m_data->posToItem(e.m_pos);
  if (i >= 0 && i < (int)m_data->m_items.size()) {
    if (!e.isShiftPressed()) unselectAll();
    select(i, !isSelected(i));
  }
}
Exemple #3
0
void TGrid::leftButtonDown(const TMouseEvent &e)
{
	m_data->m_colSeparatorDragged = false;
	int rowCount = getRowCount();

	int i = m_data->posToRow(e.m_pos);
	if (i == 0) {
		// la riga 0 e' l'header della tabella

		for (int j = 0; j < m_data->m_columnSet.getColumnCount(); ++j) {
			TGridColumnP col = m_data->m_columnSet.getColumn(j);
			int x0, x1;
			col->getCoords(x0, x1);
			if (x0 - 3 < e.m_pos.x && e.m_pos.x < x0 + 3) {
				m_data->m_colSeparatorDragged = true;
				m_data->m_colSeparatorX = x0;
				m_data->m_prevColSeparatorX = x0;
				m_data->m_colIndex = j;
			}
		}
	} else {
		i--;
		if (i >= 0 && i < (int)rowCount) {
			if (!e.isShiftPressed())
				unselectAll();
			select(i, !isSelected(i));
		}
	}
}
Exemple #4
0
void PinchTool::updateInterfaceStatus(const TMouseEvent &event)
{
	assert(getPixelSize() > 0 && "Pixel size is lower than 0!!!");

	m_status.isManual_ = m_autoOrManual.getValue();
	m_status.pixelSize_ = getPixelSize();
	m_status.cornerSize_ = (int)m_toolCornerSize.getValue();
	m_status.lengthOfAction_ = m_toolRange.getValue();
	m_status.deformerSensibility_ = 0.01 * getPixelSize();

	m_status.key_event_ = ContextStatus::NONE;

	// mutual exclusive
	if (event.isCtrlPressed())
		m_status.key_event_ = ContextStatus::CTRL;
	if (event.isShiftPressed())
		m_status.key_event_ = ContextStatus::SHIFT;

	// TODO:  **DEVE** essere fatto dentro la costruzione di TMouseEvent
	// nel codice di Toonz/Tab/ecc. **NON** ci devono essere ifdef MACOSX se e' possibile
	// evitarlo. Qua sotto ci deve essere solo if(event.isShiftPressed)
	/*#ifdef MACOSX
  if(event.isLockPressed() )
#else*/
	if (event.isAltPressed())
		//#endif
		m_status.key_event_ = ContextStatus::ALT;

	m_selector.setStroke(0);
	m_selector.setVisibility(m_status.isManual_ && m_showSelector);
	m_selector.setLength(m_status.lengthOfAction_);
}
void RasterSelectionTool::modifySelectionOnClick(TImageP image,
                                                 const TPointD &pos,
                                                 const TMouseEvent &e) {
  const TXshCell &imageCell = TTool::getImageCell();

  TToonzImageP ti  = (TToonzImageP)image;
  TRasterImageP ri = (TRasterImageP)image;
  if (!ti && !ri) return;
  m_rasterSelection.makeCurrent();
  updateAction(pos, e);

  m_firstPos = m_curPos = pos;
  if (!m_rasterSelection.isEmpty() && !m_rasterSelection.isFloating() &&
      e.isShiftPressed() && !m_rasterSelection.isTransformed()) {
    m_selectingRect.empty();
    m_transformationCount = 0;
    m_selecting           = true;
  } else if (!m_rasterSelection.isEmpty()) {
    m_selectingRect.empty();
    m_selecting = false;
    if (m_what == Outside && m_rasterSelection.isFloating()) {
      m_rasterSelection.pasteFloatingSelection();
    } else if (m_what == Outside && !m_rasterSelection.isFloating()) {
      m_rasterSelection.setCurrentImage(image, imageCell);
      m_rasterSelection.selectNone();
      m_bboxs.clear();
      m_selectingRect.empty();
      m_selecting = true;
    } else {
      if (!m_rasterSelection.isFloating() &&
          (m_what == Inside || m_what == ROTATION || m_what == SCALE ||
           m_what == SCALE_X || m_what == SCALE_Y)) {
        m_rasterSelection.makeFloating();
        m_transformationCount = 0;
        m_rasterSelection.setTransformationCount(0);
      }
    }
  } else {
    if (m_what == Outside) {
      m_rasterSelection.setCurrentImage(image, imageCell);
      m_rasterSelection.selectNone();
      m_bboxs.clear();
      m_selectingRect.empty();
      m_selecting = true;
    }
  }
  invalidate();
}
  void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override {
    TToonzImageP ti = TToonzImageP(getImage(true));
    if (!ti) return;

    /*-- Rectの座標の向きを揃える --*/
    if (m_selectingRect.x0 > m_selectingRect.x1)
      tswap(m_selectingRect.x1, m_selectingRect.x0);
    if (m_selectingRect.y0 > m_selectingRect.y1)
      tswap(m_selectingRect.y1, m_selectingRect.y0);

    TTool::Application *app = TTool::getApplication();

    m_selecting = false;
    TRasterCM32P ras;
    if (m_closeType.getValue() == RECT_CLOSE) {
      if (m_multi.getValue()) {
        if (m_firstFrameSelected) {
          multiApplyAutoclose(m_firstFrameId, getFrameId(), m_firstRect,
                              m_selectingRect);
          invalidate(m_selectingRect.enlarge(2));
          if (e.isShiftPressed()) {
            m_firstRect    = m_selectingRect;
            m_firstFrameId = getFrameId();
          } else {
            if (m_isXsheetCell) {
              app->getCurrentColumn()->setColumnIndex(m_currCell.first);
              app->getCurrentFrame()->setFrame(m_currCell.second);
            } else
              app->getCurrentFrame()->setFid(m_veryFirstFrameId);
            resetMulti();
          }
        } else {
          m_isXsheetCell = app->getCurrentFrame()->isEditingScene();
          // if (m_isXsheetCell)
          m_currCell = std::pair<int, int>(getColumnIndex(), this->getFrame());
        }
        return;
      }

      /*-- AutoCloseが実行されたか判定する --*/
      if (!applyAutoclose(ti, m_selectingRect)) {
        if (m_stroke) {
          delete m_stroke;
          m_stroke = 0;
        }
        invalidate();
        return;
      }

      invalidate();
      notifyImageChanged();
    } else if (m_closeType.getValue() == FREEHAND_CLOSE) {
      closeFreehand(pos);
      if (m_multi.getValue())
        multiAutocloseRegion(m_stroke, e);
      else
        applyAutoclose(ti, TRectD(), m_stroke);
      m_track.clear();
      invalidate();
    }
    if (m_stroke) {
      delete m_stroke;
      m_stroke = 0;
    }
  }
Exemple #7
0
void SkeletonTool::leftButtonDown(const TPointD &ppos, const TMouseEvent &e)
{
	m_otherColumn = -1;
	m_otherColumnBBox = TRectD();
	m_otherColumnBBoxAff = TAffine();
	m_labelPos = TPointD(0, 0);
	m_label = "";

	TUndoManager::manager()->beginBlock();
	if (!doesApply())
		return;

	assert(m_dragTool == 0);
	m_dragTool = 0;

	TTool::Application *app = TTool::getApplication();
	int currentColumnIndex = app->getCurrentColumn()->getColumnIndex();
	TXsheet *xsh = app->getCurrentScene()->getScene()->getXsheet();
	TPointD pos = ppos;

	int selectedDevice = pick(e.m_pos);

	// cambio drawing
	if (selectedDevice == TD_ChangeDrawing ||
		selectedDevice == TD_IncrementDrawing ||
		selectedDevice == TD_DecrementDrawing) {
		int d = 0;
		if (selectedDevice == TD_IncrementDrawing)
			d = 1;
		else if (selectedDevice == TD_DecrementDrawing)
			d = -1;
		m_dragTool = new ChangeDrawingTool(this, d);
		m_dragTool->leftButtonDown(ppos, e);
		return;
	}

	// click su un hook: attacca la colonna corrente tramite quell'hook
	if (TD_Hook <= selectedDevice && selectedDevice < TD_Hook + 50) {
		TXsheet *xsh = app->getCurrentXsheet()->getXsheet();
		TStageObjectId objId = TStageObjectId::ColumnId(currentColumnIndex);
		TPointD p0 = getCurrentColumnMatrix() * TPointD(0, 0);
		HookData hook(xsh, currentColumnIndex, selectedDevice - TD_Hook, p0);
		TStageObjectCmd::setHandle(objId, hook.getHandle(), app->getCurrentXsheet());
		app->getCurrentXsheet()->notifyXsheetChanged();
		invalidate();
		return;
	}

	// magic link
	if (TD_MagicLink <= selectedDevice && selectedDevice < TD_MagicLink + (int)m_magicLinks.size()) {
		magicLink(selectedDevice - TD_MagicLink);
		app->getCurrentXsheet()->notifyXsheetChanged();
		return;
	}

	m_device = selectedDevice;
	bool justSelected = false;

	if (m_device < 0) {
		// nessun gadget cliccato. Eventualmente seleziono la colonna
		std::vector<int> columnIndexes;
		getViewer()->posToColumnIndexes(e.m_pos, columnIndexes, getPixelSize() * 5, false);
		if (!columnIndexes.empty()) {
			int columnIndex;
			columnIndex = columnIndexes.back();

			if (columnIndex >= 0 && columnIndex != currentColumnIndex) {
				if (!isColumnLocked(columnIndex)) {
					pos = getMatrix() * pos;
					app->getCurrentColumn()->setColumnIndex(columnIndex);
					updateMatrix();
					currentColumnIndex = columnIndex;
					justSelected = true;
					pos = getMatrix().inv() * pos;
				} else {
					m_label = "Column is locked";
					m_labelPos = pos;
				}
			}
		}
	}

	if (m_device < 0) {
		if (m_mode.getValue() == INVERSE_KINEMATICS)
			m_device = TD_InverseKinematics;
		else if (m_mode.getValue() == ANIMATE)
			m_device = TD_Rotation;
	}

	// lock/unlock: modalita IK
	if (TD_LockStageObject <= m_device && m_device < TD_LockStageObject + 1000) {
		int columnIndex = m_device - TD_LockStageObject;
		int frame = app->getCurrentFrame()->getFrame();
		togglePinnedStatus(columnIndex, frame, e.isShiftPressed());
		invalidate();
		m_dragTool = 0;
		return;
	}

	switch (m_device) {
	case TD_Center:
		m_dragTool = new DragCenterTool(this);
		break;
	case TD_Translation:
		m_dragTool = new DragPositionTool(this);
		break;
	case TD_Rotation:
		m_dragTool = new DragRotationTool(this, justSelected);
		break;
	case TD_ChangeParent:
		m_dragTool = new ParentChangeTool(this, getViewer());
		break;
	case TD_InverseKinematics: {
		Skeleton *skeleton = new Skeleton();
		buildSkeleton(*skeleton, currentColumnIndex);
		m_dragTool = new IKTool(this, getViewer(), skeleton, currentColumnIndex);
		break;
	}
	}

	if (m_dragTool) {
		m_dragTool->leftButtonDown(pos, e);
		invalidate();
	}
}
void CameraTestTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
  m_dragged = true;
  CleanupParameters *cp =
      CleanupSettingsModel::instance()->getCurrentParameters();

  TPointD dp(pos - m_lastPos);
  if (m_scaling != eNoScale) {
    TDimensionD dim(cp->m_camera.getSize());
    TPointD delta;

    // Mid-edge cases
    if (m_scaling == e1M)
      delta = TPointD(dp.x / Stage::inch, 0);
    else if (m_scaling == e0M)
      delta = TPointD(-dp.x / Stage::inch, 0);
    else if (m_scaling == eM1)
      delta = TPointD(0, dp.y / Stage::inch);
    else if (m_scaling == eM0)
      delta = TPointD(0, -dp.y / Stage::inch);
    else {
      // Corner cases
      if (e.isShiftPressed()) {
        // Free adjust
        if (m_scaling == e11)
          delta = TPointD(dp.x / Stage::inch, dp.y / Stage::inch);
        else if (m_scaling == e00)
          delta = TPointD(-dp.x / Stage::inch, -dp.y / Stage::inch);
        else if (m_scaling == e10)
          delta = TPointD(dp.x / Stage::inch, -dp.y / Stage::inch);
        else if (m_scaling == e01)
          delta = TPointD(-dp.x / Stage::inch, dp.y / Stage::inch);
      } else {
        // A/R conservative
        bool xMaximalDp = (fabs(dp.x) > fabs(dp.y));

        if (m_scaling == e11)
          delta.x = (xMaximalDp ? dp.x : dp.y) / Stage::inch;
        else if (m_scaling == e00)
          delta.x = (xMaximalDp ? -dp.x : -dp.y) / Stage::inch;
        else if (m_scaling == e10)
          delta.x = (xMaximalDp ? dp.x : -dp.y) / Stage::inch;
        else if (m_scaling == e01)
          delta.x = (xMaximalDp ? -dp.x : dp.y) / Stage::inch;

        // Keep A/R
        delta.y = delta.x * dim.ly / dim.lx;
      }
    }

    TDimensionD newDim(dim.lx + 2.0 * delta.x, dim.ly + 2.0 * delta.y);
    if (newDim.lx < 2.0 || newDim.ly < 2.0) return;

    cp->m_camera.setSize(newDim,
                         true,    // Preserve DPI
                         false);  // A/R imposed above in corner cases
  } else {
    if (e.isShiftPressed()) {
      TPointD delta = pos - m_firstPos;
      cp->m_offx    = m_firstCameraOffset.x;
      cp->m_offy    = m_firstCameraOffset.y;
      if (fabs(delta.x) > fabs(delta.y)) {
        if (!cp->m_offx_lock) cp->m_offx += -delta.x * (2.0 / Stage::inch);
      } else {
        if (!cp->m_offy_lock) cp->m_offy += -delta.y * (2.0 / Stage::inch);
      }
    } else {
      if (!cp->m_offx_lock) cp->m_offx += -dp.x * (2.0 / Stage::inch);
      if (!cp->m_offy_lock) cp->m_offy += -dp.y * (2.0 / Stage::inch);
    }
  }

  m_lastPos = pos;

  CleanupSettingsModel::instance()->commitChanges();
  invalidate();
}