void Location::CutsceneView::CameraManipulatable::UpdateCore() { if (pOutsideCameraPathItem != NULL) { QRectF gameWindowPosition = windowRect.ToQRectF(); QPainterPath outsidePath; outsidePath.addRect( 0, 0, backgroundSize.GetX(), gameWindowPosition.top()); outsidePath.addRect( 0, gameWindowPosition.top(), gameWindowPosition.left(), gameWindowPosition.height()); outsidePath.addRect( gameWindowPosition.right(), gameWindowPosition.top(), backgroundSize.GetX() - gameWindowPosition.right(), gameWindowPosition.height()); outsidePath.addRect( 0, gameWindowPosition.bottom(), backgroundSize.GetX(), backgroundSize.GetY() - gameWindowPosition.bottom()); pOutsideCameraPathItem->setPath(outsidePath); pOutsideCameraPathItem->setZValue(99 * 1000000); QLine horizontalLine( gameWindowPosition.center().x() - 10, gameWindowPosition.center().y(), gameWindowPosition.center().x() + 10, gameWindowPosition.center().y()); QLine verticalLine( gameWindowPosition.center().x(), gameWindowPosition.center().y() - 10, gameWindowPosition.center().x(), gameWindowPosition.center().y() + 10); pCameraCenterHorizontalOuterLineItem->setLine(horizontalLine); pCameraCenterVerticalOuterLineItem->setLine(verticalLine); pCameraCenterHorizontalInnerLineItem->setLine(horizontalLine); pCameraCenterVerticalInnerLineItem->setLine(verticalLine); pCameraCenterHorizontalOuterLineItem->setZValue(1); pCameraCenterVerticalOuterLineItem->setZValue(1); pCameraCenterHorizontalInnerLineItem->setZValue(2); pCameraCenterVerticalInnerLineItem->setZValue(2); pCameraCenterGraphicsItemGroup->setZValue(99 * 1000000); pCameraCenterOpacityEffect->setOpacity(IsEnabled() ? 1.0 : 0.0); } }
void QgsTextDiagram::renderDiagram( const QgsFeature& feature, QgsRenderContext& c, const QgsDiagramSettings& s, QPointF position ) { QPainter* p = c.painter(); if ( !p ) { return; } //convert from mm / map units to painter units QSizeF spu = sizePainterUnits( s.size, s, c ); double w = spu.width(); double h = spu.height(); double baseX = position.x(); double baseY = position.y() - h; QVector<QPointF> textPositions; //midpoints for text placement int nCategories = s.categoryAttributes.size(); for ( int i = 0; i < nCategories; ++i ) { if ( mOrientation == Horizontal ) { textPositions.push_back( QPointF( baseX + ( w / nCategories ) * i + w / nCategories / 2.0, baseY + h / 2.0 ) ); } else //vertical { textPositions.push_back( QPointF( baseX + w / 2.0, baseY + h / nCategories * i + w / nCategories / 2.0 ) ); } } mPen.setColor( s.penColor ); setPenWidth( mPen, s, c ); p->setPen( mPen ); mBrush.setColor( s.backgroundColor ); p->setBrush( mBrush ); //draw shapes and separator lines first if ( mShape == Circle ) { p->drawEllipse( baseX, baseY, w, h ); //draw separator lines QList<QPointF> intersect; //intersections between shape and separation lines QPointF center( baseX + w / 2.0, baseY + h / 2.0 ); double r1 = w / 2.0; double r2 = h / 2.0; for ( int i = 1; i < nCategories; ++i ) { if ( mOrientation == Horizontal ) { lineEllipseIntersection( QPointF( baseX + w / nCategories * i, baseY ), QPointF( baseX + w / nCategories * i, baseY + h ), center, r1, r2, intersect ); } else //vertical { lineEllipseIntersection( QPointF( baseX, baseY + h / nCategories * i ), QPointF( baseX + w, baseY + h / nCategories * i ), center, r1, r2, intersect ); } if ( intersect.size() > 1 ) { p->drawLine( intersect.at( 0 ), intersect.at( 1 ) ); } } } else if ( mShape == Rectangle ) { p->drawRect( QRectF( baseX, baseY, w, h ) ); for ( int i = 1; i < nCategories; ++i ) { if ( mOrientation == Horizontal ) { p->drawLine( QPointF( baseX + w / nCategories * i, baseY ), QPointF( baseX + w / nCategories * i, baseY + h ) ); } else { p->drawLine( QPointF( baseX, baseY + h / nCategories * i ), QPointF( baseX + w, baseY + h / nCategories * i ) ); } } } else //triangle { QPolygonF triangle; triangle << QPointF( baseX, baseY + h ) << QPointF( baseX + w, baseY + h ) << QPointF( baseX + w / 2.0, baseY ); p->drawPolygon( triangle ); QLineF triangleEdgeLeft( baseX + w / 2.0, baseY, baseX, baseY + h ); QLineF triangleEdgeRight( baseX + w, baseY + h, baseX + w / 2.0, baseY ); QPointF intersectionPoint1, intersectionPoint2; for ( int i = 1; i < nCategories; ++i ) { if ( mOrientation == Horizontal ) { QLineF verticalLine( baseX + w / nCategories * i, baseY + h, baseX + w / nCategories * i, baseY ); if ( baseX + w / nCategories * i < baseX + w / 2.0 ) { verticalLine.intersect( triangleEdgeLeft, &intersectionPoint1 ); } else { verticalLine.intersect( triangleEdgeRight, &intersectionPoint1 ); } p->drawLine( QPointF( baseX + w / nCategories * i, baseY + h ), intersectionPoint1 ); } else //vertical { QLineF horizontalLine( baseX, baseY + h / nCategories * i, baseX + w, baseY + h / nCategories * i ); horizontalLine.intersect( triangleEdgeLeft, &intersectionPoint1 ); horizontalLine.intersect( triangleEdgeRight, &intersectionPoint2 ); p->drawLine( intersectionPoint1, intersectionPoint2 ); } } } //draw text QFont sFont = scaledFont( s, c ); QFontMetricsF fontMetrics( sFont ); p->setFont( sFont ); QgsExpressionContext expressionContext = c.expressionContext(); expressionContext.setFeature( feature ); if ( feature.fields() ) expressionContext.setFields( *feature.fields() ); for ( int i = 0; i < textPositions.size(); ++i ) { QgsExpression* expression = getExpression( s.categoryAttributes.at( i ), expressionContext ); QString val = expression->evaluate( &expressionContext ).toString(); //find out dimesions double textWidth = fontMetrics.width( val ); double textHeight = fontMetrics.height(); mPen.setColor( s.categoryColors.at( i ) ); p->setPen( mPen ); QPointF position = textPositions.at( i ); // Calculate vertical placement double xOffset = 0; switch ( s.labelPlacementMethod ) { case QgsDiagramSettings::Height: xOffset = textHeight / 2.0; break; case QgsDiagramSettings::XHeight: xOffset = fontMetrics.xHeight(); break; } p->drawText( QPointF( position.x() - textWidth / 2.0, position.y() + xOffset ), val ); } }
void draw() { // update the mouse position and add it to the broadphase auto mousePosition = static_cast<sf::Vector2f>(sf::Mouse::getPosition(window)); const auto mouseSize = mouseObject.getSize(); mouseObject.setPosition(mousePosition); mousePosition -= mouseObject.getOrigin(); broadphase.addRectangle( mousePosition.x, mousePosition.y, mouseSize.x, mouseSize.y, &mouseObject); // move the rectangles around and add them to the broadphase for (const auto& object : objects) { object->setPosition(randb(0, window.getSize().x), randb(0, window.getSize().y)); const auto objectPosition = object->getPosition() - object->getOrigin(); const auto objectSize = object->getSize(); broadphase.addRectangle( objectPosition.x, objectPosition.y, objectSize.x, objectSize.y, object); object->setFillColor(sf::Color(0x00, 0x8B, 0x8B)); object->setOutlineColor(sf::Color::White); } // now query the collision pairs and change the color of objects that hit the mouse object to red const auto &collisionPairs = broadphase.getCollisionPairs(); for (const auto &pair : collisionPairs) { sf::RectangleShape *other = nullptr; if (pair.first == &mouseObject) other = (sf::RectangleShape*)pair.second; else if (pair.second == &mouseObject) other = (sf::RectangleShape*)pair.first; else { ((sf::RectangleShape*)pair.first)->setOutlineColor(sf::Color::Cyan); ((sf::RectangleShape*)pair.second)->setOutlineColor(sf::Color::Cyan); } if (other != nullptr) other->setFillColor(sf::Color(200, 0, 0)); } // clear out the broadphase for the next run broadphase.clear(); // clear the window with black color window.clear(sf::Color::Black); for (const auto& object : objects) window.draw(*object); window.draw(mouseObject); // draw a grid to outline the buckets const float lineThickness = 5; const sf::Color lineColor(150, 150, 150); sf::RectangleShape verticalLine(sf::Vector2f(lineThickness, window.getSize().y)); verticalLine.setFillColor(lineColor); for (size_t i = 1; i < (window.getSize().x / broadphase.getCellWidth()); ++i) { verticalLine.setPosition(i * broadphase.getCellWidth(), 0); window.draw(verticalLine); } sf::RectangleShape horizontalLine(sf::Vector2f(window.getSize().x, lineThickness)); horizontalLine.setFillColor(lineColor); for (size_t i = 1; i < (window.getSize().y / broadphase.getCellHeight()); ++i) { horizontalLine.setPosition(0, i * broadphase.getCellHeight()); window.draw(horizontalLine); } }