예제 #1
0
bool WindowManager::mousePressEvent(QObject *object, QEvent *event)
{
    // cast event and check buttons/modifiers
    QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
    if (!(Qt::NoModifier==mouseEvent->modifiers() && Qt::LeftButton==mouseEvent->button())) {
        return false;
    }

    // check lock
    if (isLocked()) {
        return false;
    } else {
        setLocked(true);
    }

    // cast to widget
    QWidget *widget = static_cast<QWidget*>(object);

    // check if widget can be dragged from current position
    if (isBlackListed(widget) || !canDrag(widget)) {
        return false;
    }

    // retrieve widget's child at event position
    QPoint position(mouseEvent->pos());
    QWidget *child = widget->childAt(position);
    if (!canDrag(widget, child, position)) {
        return false;
    }

    // save target and drag point
    _target = widget;
    _dragPoint = position;
    _globalDragPoint = mouseEvent->globalPos();
    _dragAboutToStart = true;

    // send a move event to the current child with same position
    // if received, it is caught to actually start the drag
    QPoint localPoint(_dragPoint);
    if (child) {
        localPoint = child->mapFrom(widget, localPoint);
    } else {
        child = widget;
    }
    QMouseEvent localMouseEvent(QEvent::MouseMove, localPoint, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    qApp->sendEvent(child, &localMouseEvent);
    // never eat event
    return false;
}
예제 #2
0
파일: game.cpp 프로젝트: ricky26/ld29
bool Game::onMouseDown(const SDL_MouseButtonEvent &_event)
{
	if(m_grab && (_event.button != 1))
	{
		m_isRotating = true;
		return true;
	}

	if(m_grab || (_event.button != 1))
		return false;
	
	b2Vec2 worldPos = b2Vec2(_event.x, _event.y + m_cameraOffset);

	PickObject picker;
	b2AABB aabb;
	picker.position = aabb.lowerBound = aabb.upperBound = worldToPhysics(worldPos);
	m_world.QueryAABB(&picker, aabb);

	if(!picker.fixture)
		return false;

	b2Body *body = picker.fixture->GetBody();
	if(body->GetType() != b2_dynamicBody)
		return false;

	Renderable *renderable = static_cast<Renderable*>(body->GetUserData());
	if(!canDrag(renderable))
		return false;

	Entities::Box *box = dynamic_cast<Entities::Box*>(renderable);

	if(box && box->dragJoint())
	{
		m_grab = static_cast<b2MouseJoint*>(box->dragJoint());
	}
	else
	{
		b2MouseJointDef jointDef;
		jointDef.maxForce = 100;
		jointDef.collideConnected = true;
		jointDef.bodyB = body;
		jointDef.bodyA = m_ground;

		jointDef.target = aabb.lowerBound;

		m_grab = static_cast<b2MouseJoint*>(m_world.CreateJoint(&jointDef));
	}

	m_wasFixed = body->IsFixedRotation();
	m_grabbed = renderable;
	m_grabbedBody = body;
	body->SetFixedRotation(true);
	return true;
}