Exemplo n.º 1
0
	void SnakeLayer::testPick()
	{
		bool picked = false;
		int currentScore = score;

		LineNode* n = static_cast<LineNode*>(*lineGroup->getChildren().rbegin());
		Point end = n->getEnd();
		for (auto bonus : bonusGroup->getChildren())
		{
			if (end.getDistance(bonus->getPosition()) < bonus->getBoundingBox().size.width * 0.5f)
			{
				bonusPicked();
				picked = true;
				break;
			}
		}
		for (auto item : itemGroup->getChildren())
		{
			if (end.getDistance(item->getPosition()) < item->getBoundingBox().size.width * 0.5f)
			{
				itemPicked();
				picked = true;
				break;
			}
		}

		if (picked && score >= 100 && currentScore < 100)
		{
			GameSettings::ReportAchievement(ACHIEVEMENT_SCORE_SNAKE);
		}
	}
Exemplo n.º 2
0
void QgsMapToolPan::canvasReleaseEvent( QMouseEvent * e )
{
  if ( e->button() == Qt::LeftButton )
  {
    if ( mExtentRubberBand )
    {
      if ( e->modifiers() == Qt::ShiftModifier )
      {
        // set center and zoom
        QSize zoomRectSize = mExtentRect.normalized().size();
        QSize canvasSize = mCanvas->mapSettings().outputSize();
        double sfx = ( double )zoomRectSize.width() / canvasSize.width();
        double sfy = ( double )zoomRectSize.height() / canvasSize.height();
        double scaleFactor = qMax( sfx, sfy );

        QgsPoint c = mCanvas->getCoordinateTransform()->toMapCoordinates( mExtentRect.center() );
        QgsRectangle oe = mCanvas->mapSettings().extent();
        QgsRectangle e(
          c.x() - oe.width() / 2.0, c.y() - oe.height() / 2.0,
          c.x() + oe.width() / 2.0, c.y() + oe.height() / 2.0
        );
        e.scale( scaleFactor, &c );
        mCanvas->setExtent( e, true );
        mCanvas->refresh();
      }
      else if ( e->modifiers() == Qt::ControlModifier )
      {
        QgsMapToolDeleteItems( canvas() ).deleteItems( mExtentRubberBand->rect(), canvas()->mapSettings().destinationCrs() );
      }

      delete mExtentRubberBand;
      mExtentRubberBand = 0;
    }
    else if ( mDragging )
    {
      mCanvas->panActionEnd( e->pos() );
      mDragging = false;
      mCanvas->setCursor( mCursor );
    }
    else if ( mAllowItemInteraction && mPickClick )
    {
      QgsFeaturePicker::PickResult result = QgsFeaturePicker::pick( mCanvas, e->pos(), toMapCoordinates( e->pos() ), QGis::AnyGeometry );
      if ( !result.isEmpty() )
      {
        emit itemPicked( result );
      }
    }
  }
}