示例#1
0
文件: Mode.cpp 项目: adh38/T4TAppV3
bool Mode::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex) {
    //GP_WARN("mode %s touch at %d,%d - index %d", _id.c_str(), x, y, contactIndex);
	_x = (int)(x /*+ getX() + _container->getX() + app->_stage->getX()*/);
	_y = (int)(y /*+ getY() + _container->getY() + app->_stage->getY()*/);
    if(isSelecting() || _subMode == 1) {
        _touchPt.set(evt, _x, _y, true);
    }
	else _touchPt.set(evt, _x, _y, _plane);
    _touchPt._lastEvent = evt;
	_camera->pickRay(app->getViewport(), _x, _y, &_ray);
	switch(evt) {
		case Touch::TOUCH_PRESS: {
			if(!isSelecting()) {
				_cameraBase->getNode()->set(*_camera->getNode());
				_viewportBase = app->getViewport();
				app->_cameraState->copy(_cameraStateBase);
			}
			break;
		} case Touch::TOUCH_MOVE: {
			if(isTouching() && app->_navMode >= 0) {
				//placeCamera();
			}
			break;
		} case Touch::TOUCH_RELEASE: {
			break;
		}
	}
	return true;
}
示例#2
0
文件: Mode.cpp 项目: adh38/T4TApp
bool Mode::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex) {
	_x = (int)(x + getX() + _container->getX() + app->_stage->getX());
	_y = (int)(y + getY() + _container->getY() + app->_stage->getY());
	if(isSelecting()) _touchPt.set(evt, _x, _y, true);
	else _touchPt.set(evt, _x, _y, _plane);
	_camera->pickRay(app->getViewport(), _x, _y, &_ray);
	switch(evt) {
		case Touch::TOUCH_PRESS: {
			cout << "mode ray: " << app->pv(_ray.getOrigin()) << " => " << app->pv(_ray.getDirection()) << endl;
			MyNode *node = getTouchNode();
			if(node) node->updateTransform();
			if(isSelecting()) {
				Vector3 point = getTouchPoint();
				if(node) node->setBase();
				setSelectedNode(node, point);
				if(node) cout << "selected: " << node->getId() << " at " << app->pv(point) << endl;
			} else {
				_cameraBase->getNode()->set(*_camera->getNode());
				_viewportBase = app->getViewport();
				app->copyCameraState(app->_cameraState, _cameraStateBase);
				cout << "touched: camera at " << app->pcam(_cameraStateBase) << endl;
			}
			break;
		} case Touch::TOUCH_MOVE: {
			if(isTouching() && app->_navMode >= 0) {
				placeCamera();
			}
			break;
		} case Touch::TOUCH_RELEASE: {
			break;
		}
	}
	return true;
}
示例#3
0
MStatus customAttrCtx::doRelease( MEvent & event )
//
// Description
//     This method is called when a mouse button is released while this context is
//    the current context.
//
{
	// Let the parent class handle the event.
	MStatus stat = MPxSelectionContext::doRelease( event );

	// If an object is selected, process the event if the middle mouse button
	// was lifted.
	if ( !isSelecting() ) {
		if (event.mouseButton() == MEvent::kMiddleMouse)
		{
			event.getPosition( endPos_x, endPos_y );

			// Delete the move command if we have moved less then 2 pixels
			// otherwise call finalize to set up the journal and add the
			// command to the undo queue.
			//
			if ( abs(startPos_x - endPos_x) < 2 ) {
				delete cmd;
				view.refresh( true );
			}
			else {
				stat = cmd->finalize();
				view.refresh( true );
			}
			setCursor(MCursor::defaultCursor);
		}
	}

	return stat;
}
示例#4
0
MStatus customAttrCtx::doDrag( MEvent & event )
//
// Description
//     This method is called when a mouse button is dragged while this context is
//    the current context.
//
{
	MStatus stat;

	// If an object has been selected, then process the drag.  Otherwise, pass the
    // event on up to the parent class.
	if ((!isSelecting()) && (event.mouseButton() == MEvent::kMiddleMouse)) {

		event.getPosition( endPos_x, endPos_y );

		// Undo the command to erase the previously set delta value from the
		// node, set a new delta value in the command and redo the command to
		// set the values in the node.
		cmd->undoIt();
		cmd->setDelta(endPos_x - startPos_x);
		stat = cmd->redoIt();
		view.refresh( true );
	}
	else
		stat = MPxSelectionContext::doDrag( event );

	return stat;
}
示例#5
0
bool FormulaCursor::performMovement ( FormulaCursor& oldcursor )
{
    //handle selecting and not selecting case separately, which makes more clear
    if (isSelecting()) {
        while ( m_currentElement ) {
            if ( m_currentElement->moveCursor( *this, oldcursor ) ) {
                if (isAccepted()) {
                    return true;
                }
            } else {
                if ( m_currentElement->parentElement() ) {
                    bool ltr=m_mark<=m_position;
                    //update the starting point of the selection
                    m_mark=m_currentElement->parentElement()->positionOfChild(m_currentElement);
                    //move the cursor to the parent and place it before the old element
                    m_position=m_currentElement->parentElement()->positionOfChild(m_currentElement);
                    m_currentElement=m_currentElement->parentElement();
                    if (ltr) {
                        m_position++; //place the cursor behind
                    } else {
                        m_mark++; //place the selection beginning behind 
                    }
                    if (isAccepted()) {
                        return true;
                    }
                } else {
                    //we arrived at the toplevel element
                    return false;
                }
            }
        }
    } else {
        while ( m_currentElement ) {
            if ( m_currentElement->moveCursor( *this, oldcursor ) ) {
                if (isAccepted()) {
                    return true;
                }
            } else {
                if ( m_currentElement->parentElement() ) {
                    //move the cursor to the parent and place it before the old element
                    m_position=m_currentElement->parentElement()->positionOfChild(m_currentElement);
                    m_currentElement=m_currentElement->parentElement();
                    if (m_direction==MoveRight || m_direction==MoveDown) {
                        m_position++; //place the cursor behin
                    }
                    if (m_direction==MoveRight || m_direction==MoveLeft) {
                        if (isAccepted()) {
                            return true;
                        }
                    }   
                } else {
                    //We arrived at the top level element
                    return false;
                }
            }
        }
    }
    return false;
}
示例#6
0
文件: Mode.cpp 项目: adh38/T4TAppV3
void Mode::gestureEvent(Gesture::GestureEvent evt, int x, int y, ...)
{
    if(app->hasOverlay()) return;
    va_list arguments;
    va_start(arguments, y);
    switch(evt) {
        case Gesture::GESTURE_TAP: {
            if(isSelecting()) {
                MyNode *node = getTouchNode();
                Vector3 point = getTouchPoint();
                if(node) {
                    node->updateTransform();
                    node->setBase();
                }
                setSelectedNode(node, point);
                if(node) GP_WARN("selected %s at %s", node->getId(), app->pv(point).c_str());
            }
            break;
        }
        case Gesture::GESTURE_LONG_TAP:
            break;
        case Gesture::GESTURE_PINCH: {
            float scale = (float) va_arg(arguments, double);
            if(app->_navMode >= 0) {
                float baseRadius = _cameraStateBase->radius;
                app->setCameraZoom(fminf(300.0f, fmaxf(3.0f, baseRadius / fmaxf(scale, 0.01f))));
            }
            break;
        }
        case Gesture::GESTURE_DRAG: {
            if(app->_navMode >= 0) {
                Vector2 touch = getTouchPix(), delta(x - touch.x, y - touch.y);
                float radius = _cameraStateBase->radius, theta = _cameraStateBase->theta, phi = _cameraStateBase->phi;
                GP_WARN("drag delta %f, %f", delta.x, delta.y);
                GP_WARN("camera from %f, %f, %f", radius, theta, phi);
                float deltaPhi = delta.y * M_PI / 400.0f, deltaTheta = delta.x * M_PI / 400.0f;
                phi = fmin(89.9f * M_PI/180, fmax(-89.9f * M_PI/180, phi + deltaPhi));
                theta += deltaTheta;
                GP_WARN("to %f, %f, %f", radius, theta, phi);
                app->setCameraEye(radius, theta, phi);
            }
            break;
        }
        case Gesture::GESTURE_DROP: {
            break;
        }
        case Gesture::GESTURE_ROTATE: {
            float rotation = (float) va_arg(arguments, double), velocity = (float) va_arg(arguments, double);
            if(app->_navMode >= 0) {
                float theta = _cameraStateBase->theta;
                app->setCameraTheta(theta - rotation);
            }
            break;
        }
        default: break;
    }
    va_end(arguments);
}
示例#7
0
MStatus customAttrCtx::doPress( MEvent & event )
//
// Description
//     This method is called when a mouse button is pressed while this context is
//    the current context.
//
{
	// Let the parent class handle the event first in case there is no object
	// selected yet.  The parent class will perform any necessary selection.
	MStatus stat = MPxSelectionContext::doPress( event );

	// If an object has been selected, then process the event.  Otherwise,
	// ignore it as there is nothing to do.
	if ( !isSelecting() ) {
		if (event.mouseButton() == MEvent::kMiddleMouse)
		{
			setCursor(MCursor::handCursor);
			view = M3dView::active3dView();

			// Create an instance of the customAttrCmd tool command and initialize
			// its delta value to 0.  As the mouse drags, the delta value will change.
			// when the mouse is lifted, a final command will be constructed with the
			// most recently set delta value and axis specifications.
			cmd = (customAttrCmd *)newToolCommand();
			cmd->setDelta(0.0);

			event.getPosition( startPos_x, startPos_y );

			// Determine the channel box attribute which will be operated on by the
			// dragging motion and set the state of the command accordingly.
			unsigned int i;
			MStringArray result;
			MGlobal::executeCommand(
					"channelBox -q -selectedMainAttributes $gChannelBoxName", result);
			for (i=0; i<result.length(); i++)
			{
				if (result[i] == customAttributeString)
				{
					cmd->setDragX();
					break;
				}
			}
		}
	}

	return stat;
}
示例#8
0
MStatus moveContext::doPress( MEvent & event )
{
	MStatus stat = MPxSelectionContext::doPress( event );
	MSpace::Space spc = MSpace::kWorld;

	// If we are not in selecting mode (i.e. an object has been selected)
	// then set up for the translation.
	//
	if ( !isSelecting() ) {
		event.getPosition( startPos_x, startPos_y );
		view = M3dView::active3dView();

		MDagPath camera;
		stat = view.getCamera( camera );
		if ( stat != MS::kSuccess ) {
			cerr << "Error: M3dView::getCamera" << endl;
			return stat;
		}
		MFnCamera fnCamera( camera );
		MVector upDir = fnCamera.upDirection( spc );
		MVector rightDir = fnCamera.rightDirection( spc );

		// Determine the camera used in the current view
		//
		if ( fnCamera.isOrtho() ) {
			if ( upDir.isEquivalent(MVector::zNegAxis,kVectorEpsilon) ) {
				currWin = TOP;
			} else if ( rightDir.isEquivalent(MVector::xAxis,kVectorEpsilon) ) {
				currWin = FRONT;
			} else  {
				currWin = SIDE;
			}
		}
		else {
			currWin = PERSP;
		}

		// Create an instance of the move tool command.
		//
		cmd = (moveCmd*)newToolCommand();

		cmd->setVector( 0.0, 0.0, 0.0 );
	}
	return stat;
}
示例#9
0
MStatus moveContext::doRelease( MEvent & event )
{
	MStatus stat = MPxSelectionContext::doRelease( event );
	if ( !isSelecting() ) {
		event.getPosition( endPos_x, endPos_y );

		// Delete the move command if we have moved less then 2 pixels
		// otherwise call finalize to set up the journal and add the
		// command to the undo queue.
		//
		if ( abs(startPos_x - endPos_x) < 2 && abs(startPos_y - endPos_y) < 2 ) {
			delete cmd;
			view.refresh( true );
		}
		else {
			stat = cmd->finalize();
			view.refresh( true );
		}
	}
	return stat;
}
示例#10
0
void FormulaCursor::paint( QPainter& painter ) const
{
    debugFormula << "Drawing cursor with selecting: "<< isSelecting() << " from "
    << mark()<<" to " << position() << " in "<<ElementFactory::elementName(m_currentElement->elementType());
    if( !m_currentElement )
        return;
    painter.save();
    QPointF origin=m_currentElement->absoluteBoundingRect().topLeft();
    qreal baseline=m_currentElement->baseLine();
    QPen pen;
    pen.setWidthF( 0.5 );
    pen.setColor(Qt::black);
    painter.setPen( pen );
    painter.drawLine(m_currentElement->cursorLine( m_position ));
    pen.setWidth( 0.1);
    pen.setColor(Qt::blue);
    pen.setStyle(Qt::DashLine);
    painter.setPen( pen );
    painter.drawLine( origin+QPointF(0.0,baseline),origin+QPointF(m_currentElement->width(), baseline) );
    pen.setStyle(Qt::DotLine);
    //Only here for debug purpose for now
    switch(m_currentElement->elementType()) {
    case Number:
        pen.setColor(Qt::red);
        break;
    case Identifier:
        pen.setColor(Qt::darkRed);
        break;
    case Row:
        pen.setColor(Qt::yellow);
        break;
    case Fraction:
        pen.setColor(Qt::blue);
        break;
    case Table:
        pen.setColor(Qt::darkGreen);
        break;
    case TableRow:
        pen.setColor(Qt::green);
        break;
    default:
        pen.setColor(Qt::darkGray);
        break;
    }
    painter.setPen(pen);
    painter.drawRect( m_currentElement->absoluteBoundingRect() );
    //draw the selection rectangle
    if ( m_selecting ) {
        QBrush brush;
        QColor color(Qt::blue);
        color.setAlpha(128);
        brush.setColor(color);
        brush.setStyle(Qt::SolidPattern);
        painter.setBrush(brush);
        painter.setPen(Qt::NoPen);
        int p1=position()<mark()? position() : mark();
        int p2=position()<mark()? mark() : position() ;
        painter.drawPath(m_currentElement->selectionRegion(p1,p2));
    }
    painter.restore();
}
示例#11
0
MStatus moveContext::doDrag( MEvent & event )
{
	MStatus stat;
	stat = MPxSelectionContext::doDrag( event );

	// If we are not in selecting mode (i.e. an object has been selected)
	// then do the translation.
	//
	if ( !isSelecting() ) {
		event.getPosition( endPos_x, endPos_y );
		MPoint endW, startW;
		MVector vec;
		view.viewToWorld( startPos_x, startPos_y, startW, vec );
		view.viewToWorld( endPos_x, endPos_y, endW, vec );
		downButton = event.mouseButton();

		// We reset the the move vector each time a drag event occurs 
		// and then recalculate it based on the start position. 
		//
		cmd->undoIt();

		switch( currWin )
		{
			case TOP:
				switch ( downButton )
				{
					case MEvent::kMiddleMouse :
						cmd->setVector( endW.x - startW.x, 0.0, 0.0 );
						break;
					case MEvent::kLeftMouse :
					default:
						cmd->setVector( endW.x - startW.x, 0.0,
											   endW.z - startW.z );
						break;
				}
				break;	

			case FRONT:
				switch ( downButton )
				{
					case MEvent::kMiddleMouse :
						cmd->setVector( endW.x - startW.x, 0.0, 0.0 );
						break;
					case MEvent::kLeftMouse :
					default:
						cmd->setVector( endW.x - startW.x,
											   endW.y - startW.y, 0.0 );
						break;
				}
				break;	

			case SIDE:
				switch ( downButton )
				{
					case MEvent::kMiddleMouse :
						cmd->setVector( 0.0, 0.0, endW.z - startW.z );
						break;
					case MEvent::kLeftMouse :
					default:
						cmd->setVector( 0.0, endW.y - startW.y,
											   endW.z - startW.z );
						break;
				}
				break;	

			case PERSP:
				break;
		}

		stat = cmd->redoIt();
		view.refresh( true );
	}
	return stat;
}