示例#1
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 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;
 }
示例#3
0
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));
  }
}
示例#4
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));
		}
	}
}
void ShiftTraceTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {
  m_gadget = m_highlightedGadget;
  m_oldPos = m_startPos = pos;

  if (m_gadget == NoGadget) {
    int row = getViewer()->posToRow(e.m_pos, 5 * getPixelSize(), false);
    if (row >= 0) {
      int currentRow = getFrame();
      int index      = -1;
      if (m_row[0] >= 0 && row <= currentRow)
        index = 0;
      else if (m_row[1] >= 0 && row > currentRow)
        index = 1;
      if (index >= 0) {
        m_ghostIndex = index;
        updateBox();
      }
    }

    if (!e.isCtrlPressed()) {
      m_gadget = TranslateGadget;
      // m_curveStatus = NoCurve;
    }
  }
  invalidate();
}
示例#6
0
void PinchTool::mouseMove(const TPointD &pos,
						  const TMouseEvent &event)
{
	if (m_active)
		return;

	if (!m_draw)
		m_draw = true;

	ContextStatus *status = &m_status;
	m_curr = pos;

	const int pixelRange = 3;
	if (abs(m_lastMouseEvent.m_pos.x - event.m_pos.x) < pixelRange &&
		abs(m_lastMouseEvent.m_pos.y - event.m_pos.y) < pixelRange &&
		m_lastMouseEvent.getModifiersMask() == event.getModifiersMask())
		return;

	m_lastMouseEvent = event;
	double w = 0;
	TStroke *stroke = getClosestStroke(pos, w);
	if (stroke) {
		// set parameters from sliders
		updateInterfaceStatus(event);

		// update information about current stroke
		updateStrokeStatus(stroke, w);

		// retrieve the currect m_deformation and
		// prepare to design and modify
		if (m_deformation)
			m_deformation->check(status);

		m_selector.setStroke(stroke);
		m_selector.mouseMove(m_curr);
	} else {
		m_status.stroke2change_ = 0;
		m_selector.setStroke(0);
		return;
	}

	m_prev = m_curr;
	m_cursorEnabled = moveCursor(pos);

	if (m_cursorEnabled)
		invalidate();

	//  TNotifier::instance()->notify(TToolChange());
}
示例#7
0
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 FullColorBrushTool::mouseMove(const TPointD &pos, const TMouseEvent &e)
{
	struct Locals {
		FullColorBrushTool *m_this;

		void setValue(TIntPairProperty &prop, const TIntPairProperty::Value &value)
		{
			prop.setValue(value);

			m_this->onPropertyChanged(prop.getName());
			TTool::getApplication()->getCurrentTool()->notifyToolChanged();
		}

		void addMinMax(TIntPairProperty &prop, double add)
		{
			const TIntPairProperty::Range &range = prop.getRange();

			TIntPairProperty::Value value = prop.getValue();
			value.second = tcrop<double>(value.second + add, range.first, range.second);
			value.first = tcrop<double>(value.first + add, range.first, range.second);

			setValue(prop, value);
		}

	} locals = {this};

	switch (e.getModifiersMask()) {
	/*-- Altキー+マウス移動で、ブラシサイズ(Min/Maxとも)を変える(CtrlやShiftでは誤操作の恐れがある) --*/
	case TMouseEvent::ALT_KEY: {
		// User wants to alter the minimum brush size
		const TPointD &diff = pos - m_mousePos;
		double add = (fabs(diff.x) > fabs(diff.y)) ? diff.x : diff.y;

		locals.addMinMax(m_thickness, int(add));
	}

	DEFAULT:
		m_brushPos = pos;
	}

	m_mousePos = pos;
	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;
    }
  }
示例#10
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();
	}
}
示例#11
0
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();
}
示例#12
0
void CHIDEventMonitor::RunL()
    {
    THIDEvent hidEvent;
    iHIDClient->GetEvent( hidEvent );
    switch (hidEvent.Type())
        {
        case THIDEvent::EMouseEvent:
            {
            qboolean down = qfalse;
            TMouseEvent* mouse = hidEvent.Mouse();
            switch (mouse->Type())
                {
                case EEventRelativeXY:
                    currentPosition += mouse->iPosition;
                    break;
                case EEventButtonDown:
                    down = qtrue;
                case EEventButtonUp:
                    switch(mouse->iValue)
                        {
                        case EMouseButtonLeft:
                            Key_Event(K_MOUSE1, down);
                            break;
                        case EMouseButtonRight:
                            Key_Event(K_MOUSE1+1, down);
                            break;
                        case EMouseButtonMiddle:
                            Key_Event(K_MOUSE1+2, down);
                            break;
                        default:
                            break;
                        }
                    break;
                case EEventRelativeWheel:
                    if (mouse->iValue > 0)
                        {
                        Key_Event( K_MWHEELUP, qtrue);
                        Key_Event( K_MWHEELUP, qfalse );
                        }
                    else
                        {
                        Key_Event( K_MWHEELDOWN, qtrue);
                        Key_Event( K_MWHEELDOWN, qfalse );
                        }
                    break;
                default:
                    break;
                }
            }
            break;
        case THIDEvent::EKeyEvent:
            {
            THIDKeyEvent* key = hidEvent.Key();
            int hid_code = hid_to_quake[key->ScanCode()];
            switch (key->Type())
                {
                case EEventHIDKeyUp:
                    if (shift_down)
                        {
                        hid_code = hid_to_quake_shifted[key->ScanCode()];
                        }
                    if (hid_code == K_SHIFT)
                        {
                        shift_down = qfalse;
                        }
                    Key_Event(hid_code, qfalse);
                    
                    break;
                case EEventHIDKeyDown:
//                    Com_Printf( "EEventHIDKeyDown, code %d\n",key->ScanCode());
                    if (hid_code == K_SHIFT)
                        {
                        shift_down = qtrue;
                        }
                    if (shift_down)
                        {
                        hid_code = hid_to_quake_shifted[key->ScanCode()];
                        }
                    Key_Event(hid_code, qtrue);
                    break;
                default:
                    break;
                }
            }
            break;
        case THIDEvent::EConsumerEvent:
            {
            THIDConsumerEvent* consumer = hidEvent.Consumer();
            //Com_Printf( "consumer, code %d\n",consumer->ButtonCode());
            break;
            }
        default:
            break;
        }
    iHIDClient->EventReady( &iStatus );
    SetActive();
    }