Example #1
0
// draw window shadow
void Widget::paintEvent(QPaintEvent *e)
{
    QPainter painter(this);

    QRect bottom(5, 136, 200, 7);
    QRect top(5, 0, 200, 3);
    QRect left(0, 3, 5, 133);
    QRect right(205, 3, 5, 133);
    QRect topRight(205, 0, 5, 3);
    QRect topLeft(0, 0, 5, 3);
    QRect bottomLeft(0, 136, 5, 7);
    QRect bottomRight(205, 136, 5, 7);

    QRect tBottom(5, this->height() - 7, this->width() - 10, 7);
    QRect tTop(5, 0, this->width() - 10, 3);
    QRect tLeft(0, 3, 5, this->height() - 10);
    QRect tRight(this->width() - 5, 3, 5, this->height() - 10);
    QRect tTopLeft(0, 0, 5, 3);
    QRect tTopRight(this->width() - 5, 0, 5, 3);
    QRect tBottomLeft(0, this->height() - 7, 5, 7);
    QRect tBottomRight(this->width() - 5, this->height() - 7, 5, 7);

    painter.drawPixmap(tBottom, m_shadow, bottom);
    painter.drawPixmap(tTop, m_shadow, top);
    painter.drawPixmap(tLeft, m_shadow, left);
    painter.drawPixmap(tRight, m_shadow, right);
    painter.drawPixmap(tTopRight, m_shadow, topRight);
    painter.drawPixmap(tTopLeft, m_shadow, topLeft);
    painter.drawPixmap(tBottomLeft, m_shadow, bottomLeft);
    painter.drawPixmap(tBottomRight, m_shadow, bottomRight);
}
QPainterPath DArrowRectangle::getBottomCornerPath()
{
    qreal delta = shadowBlurRadius() + shadowDistance();

    QRect rect = this->rect().marginsRemoved(QMargins(delta, delta, delta, delta));

    QPoint cornerPoint(rect.x() + (m_arrowX > 0 ? m_arrowX : rect.width() / 2), rect.y()  + rect.height());
    QPoint topLeft(rect.x(), rect.y());
    QPoint topRight(rect.x() + rect.width(), rect.y());
    QPoint bottomRight(rect.x() + rect.width(), rect.y() + rect.height() - m_arrowHeight);
    QPoint bottomLeft(rect.x(), rect.y() + rect.height() - m_arrowHeight);
    int radius = this->m_radius > (rect.height() / 2 - m_arrowHeight) ? rect.height() / 2 -m_arrowHeight : this->m_radius;

    QPainterPath border;
    border.moveTo(topLeft.x() + radius, topLeft.y());
    border.lineTo(topRight.x() - radius, topRight.y());
    border.arcTo(topRight.x() - 2 * radius, topRight.y(), 2 * radius, 2 * radius, 90, -90);
    border.lineTo(bottomRight.x(), bottomRight.y() - radius);
    border.arcTo(bottomRight.x() - 2 * radius, bottomRight.y() - 2 * radius, 2 * radius, 2 * radius, 0, -90);
    border.lineTo(cornerPoint.x() + m_arrowWidth / 2, cornerPoint.y() - m_arrowHeight);
    border.lineTo(cornerPoint);
    border.lineTo(cornerPoint.x() - m_arrowWidth / 2, cornerPoint.y() - m_arrowHeight);
    border.lineTo(bottomLeft.x() + radius, bottomLeft.y());
    border.arcTo(bottomLeft.x(), bottomLeft.y() - 2 * radius, 2 * radius, 2 * radius, -90, -90);
    border.lineTo(topLeft.x(), topLeft.y() + radius);
    border.arcTo(topLeft.x(), topLeft.y(), 2 * radius, 2 * radius, 180, -90);

    return border;
}
void tst_QOpenGL::textureblitterPartTargetRectTransform()
{
    QVector4D topLeft(-1.f, 1.f, 0.f, 1.f);
    QVector4D bottomLeft(-1.f, -1.f, 0.f, 1.f);
    QVector4D topRight(1.f, 1.f, 0.f, 1.f);
    QVector4D bottomRight(1.f, -1.f, 0.f, 1.f);

    QRectF targetRect(50,50,200,200);
    QRect viewport(0,0,400,400);

    //multiply by 2 since coordinate system goes from -1 -> 1;
    qreal x_point_ratio = (50. / 400.) * 2;
    qreal y_point_ratio = (50. / 400.) * 2;
    qreal width_ratio = (200. / 400.) * 2;
    qreal height_ratio = (200. / 400.) * 2;

    QMatrix4x4 targetMatrix = QOpenGLTextureBlitter::targetTransform(targetRect, viewport);

    QVector4D targetTopLeft = targetMatrix * topLeft;
    QVector4D expectedTopLeft(-1 + x_point_ratio, 1 - y_point_ratio, .0, 1.0);
    QCOMPARE(targetTopLeft, expectedTopLeft);

    QVector4D targetBottomLeft = targetMatrix * bottomLeft;
    QVector4D expectedBottomLeft(-1 + x_point_ratio, 1 - y_point_ratio  - height_ratio, 0.0, 1.0);
    QCOMPARE(targetBottomLeft, expectedBottomLeft);

    QVector4D targetTopRight = targetMatrix * topRight;
    QVector4D expectedTopRight(-1 + x_point_ratio + width_ratio, 1 - y_point_ratio, 0.0, 1.0);
    QCOMPARE(targetTopRight, expectedTopRight);

    QVector4D targetBottomRight = targetMatrix * bottomRight;
    QVector4D expectedBottomRight(-1 + x_point_ratio + width_ratio, 1 - y_point_ratio - height_ratio, 0.0, 1.0);
    QCOMPARE(targetBottomRight, expectedBottomRight);
}
TEST_F(TrapezoidTest, triangle_shaped_trapezoid_scales_to_a_triangle) {
    fuzzy::Trapezoid z {7,10,10,13};
    auto y = z.larsen(0.15);
    ASSERT_EQ(0.15, y.height());
    ASSERT_EQ(7, y.left());
    ASSERT_EQ(10, y.topLeft());
    ASSERT_EQ(10, y.topRight());
    ASSERT_EQ(13, y.right());
}
TEST_F(TrapezoidTest, triangle_shaped_trapezoid_clips_to_a_trapezoid) {
    fuzzy::Trapezoid z {7,10,10,13};
    auto y = z.mamdami(0.15);
    ASSERT_EQ(0.15, y.height());
    ASSERT_EQ(7, y.left());
    ASSERT_EQ(7.45, y.topLeft());
    ASSERT_EQ(12.55, y.topRight());
    ASSERT_EQ(13, y.right());
}
Example #6
0
QRectF GraphConnection::getBoundingRect(void) const
{
    QVector<QPointF> points = _impl->points;
    const auto arrowRect = _impl->arrowHead.boundingRect();
    points.push_back(arrowRect.topLeft());
    points.push_back(arrowRect.topRight());
    points.push_back(arrowRect.bottomRight());
    points.push_back(arrowRect.bottomLeft());
    return QPolygonF(points).boundingRect();
}
Example #7
0
	Rect GeomUtils::outside(const Rect& rect1, const Rect& rect2) {
		Point bottomLeft(MIN(rect1.getMinX(), rect2.getMinX()),
										 MIN(rect1.getMinY(), rect2.getMinY()));
		Point topRight(MAX(rect1.getMaxX(), rect2.getMaxX()),
									 MAX(rect1.getMaxY(), rect2.getMaxY()));
		return Rect(bottomLeft.x,
								bottomLeft.y,
								topRight.x - bottomLeft.x,
								topRight.y - bottomLeft.y);
	}
Rectangle::operator Json() const
{
    Json j;
    cv::Point2f topleft = topLeft();
    j[top_left_x_Key] = topleft.x;
    j[top_left_y_Key] = topleft.y;

    cv::Point2f bottomRight = topRight();
    j[bottom_right_x_Key] = bottomRight.x;
    j[bottom_right_y_Key] = bottomRight.y;

    return j;
}
// 获取矩形范围内,所有四叉树的所有物体
// 如果这个矩形是完全处于一个四叉树中的,那么跟Retrieve返回的结果一样
// 如果这个矩形处于多个四叉树中,那么需要获取它所在的四叉树,以及它四个点所在四叉树的物体
void FixedQuadTree::RetrieveArea(const plane_shooting::Rectangle& rect, list<Object*>& objList) {
	Retrieve(rect, objList);

	// 左上顶点
	Rectangle topLeft(rect.x - rect.fWidth / 2, rect.y + rect.fHeight / 2, 0, 1);
	// 右上顶点
	Rectangle topRight(rect.x + rect.fWidth / 2, rect.y + rect.fHeight / 2, 0, 1);
	// 左下顶点
	Rectangle bottomLeft(rect.x - rect.fWidth / 2, rect.y - rect.fHeight / 2, 0, 1);
	// 右下顶点
	Rectangle bottomRight(rect.x + rect.fWidth / 2, rect.y - rect.fHeight / 2, 0, 1);

	// TODO , 改成直接返回list<Object*>列表指针
}
void TableSideSelector::paintEvent(QPaintEvent* event)
{
	double edgeWidth = 5;
	double inset = edgeWidth/2 + frameWidth()*2;

	QPointF topLeft(inset, inset);
	QPointF topRight(width() - inset, inset);
	QPointF bottomLeft(inset, height() - inset);
	QPointF bottomRight(width() - inset, height() - inset);

	m_left = QLineF(topLeft, bottomLeft);
	m_right = QLineF(topRight, bottomRight);
	m_top = QLineF(topRight, topLeft);
	m_bottom = QLineF(bottomRight, bottomLeft);

	QPainter painter(this);

	// Paint selection.
	painter.setPen(QPen(Qt::black, edgeWidth, Qt::SolidLine, Qt::RoundCap));
	if (m_selection & Left) painter.drawLine(m_left);
	if (m_selection & Right) painter.drawLine(m_right);
	if (m_selection & Top) painter.drawLine(m_top);
	if (m_selection & Bottom) painter.drawLine(m_bottom);

	// Paint the dotted grid.
	painter.setPen(QPen(Qt::gray, edgeWidth/4, Qt::DotLine));
	painter.drawRect(QRectF(topLeft, bottomRight));
	painter.drawLine(m_left.pointAt(0.5), m_right.pointAt(0.5));
	painter.drawLine(m_top.pointAt(0.5), m_bottom.pointAt(0.5));

	// Paint highlighting.
	painter.setPen(QPen(QColor(255, 255, 255, 60), edgeWidth, Qt::SolidLine, Qt::RoundCap));
	switch (m_highlighted)
	{
	case Left:
		painter.drawLine(m_left);
		break;
	case Right:
		painter.drawLine(m_right);
		break;
	case Top:
		painter.drawLine(m_top);
		break;
	case Bottom:
		painter.drawLine(m_bottom);
		break;
	default:
		break;
	}
}
Example #11
0
QPoint HintsWidgetPositioner::positionForSize(QSize size)
{
	auto availableGeometry = QApplication::desktop()->availableGeometry(m_hintsWidget);
	switch (m_hintsConfiguration->corner())
	{
		case HintsConfiguration::Corner::TopLeft:
			return availableGeometry.topLeft() + QPoint{8, 8};
		case HintsConfiguration::Corner::TopRight:
			return availableGeometry.topRight() + QPoint{-8 - size.width(), 8};
		case HintsConfiguration::Corner::BottomLeft:
			return availableGeometry.bottomLeft() + QPoint{8, -8 - size.height()};
		case HintsConfiguration::Corner::BottomRight:
		default:
			return availableGeometry.bottomRight() + QPoint{-8 - size.width(), -8 - size.height()};
	}
}
Example #12
0
void ScriptEditorCloseButton::paint(QPainter* p,
                                    const QStyleOptionGraphicsItem* o,
                                    QWidget* w)
{
    Q_UNUSED(o);
    Q_UNUSED(w);

    auto br = boundingRect();
    p->setPen(QPen(Colors::base06, 3));

    int offset = 6;
    p->drawLine(br.bottomLeft() + QPointF(offset, -offset),
                br.topRight() - QPointF(offset, -offset));
    p->drawLine(br.topLeft() + QPointF(offset, offset),
                br.bottomRight() - QPointF(offset, offset));
}
Example #13
0
bool TagsEditor::IsWindowRectValid(const wxRect *windowRect) const
{
   wxDisplay display;
   wxPoint topLeft(windowRect->GetTopLeft().x, windowRect->GetTopLeft().y);
   wxPoint topRight(windowRect->GetTopRight().x, windowRect->GetTopRight().y);
   wxPoint bottomLeft(windowRect->GetBottomLeft().x, windowRect->GetBottomLeft().y);
   wxPoint bottomRight(windowRect->GetBottomRight().x, windowRect->GetBottomRight().y);
   display.GetFromPoint(topLeft);
   if (display.GetFromPoint(topLeft) == -1 &&
       display.GetFromPoint(topRight) == -1 &&
       display.GetFromPoint(bottomLeft) == -1 &&
       display.GetFromPoint(bottomRight) == -1) {
      return false;
   }

   return true;
}
Example #14
0
void dftshift(cv::Mat_<float>& magnitude) {
  const int cx = magnitude.cols/2;
  const int cy = magnitude.rows/2;
  
  cv::Mat_<float> tmp;
  cv::Mat_<float> topLeft(magnitude, cv::Rect(0, 0, cx, cy));
  cv::Mat_<float> topRight(magnitude, cv::Rect(cx, 0, cx, cy));
  cv::Mat_<float> bottomLeft(magnitude, cv::Rect(0, cy, cx, cy));
  cv::Mat_<float> bottomRight(magnitude, cv::Rect(cx, cy, cx, cy));
  
  topLeft.copyTo(tmp);
  bottomRight.copyTo(topLeft);
  tmp.copyTo(bottomRight);
  
  topRight.copyTo(tmp);
  bottomLeft.copyTo(topRight);
  tmp.copyTo(bottomLeft);
}
Example #15
0
TEST_F(BoxTests, InitialiseWithTwoOppositeCorners)
{
	Point topLeft(2, 2), bottomRight(4, 0);

	expect(Box(topLeft, 2, 2));
	Box b(topLeft, bottomRight);
	compareBoxes(b);
	
	b = Box(bottomRight, topLeft);
	compareBoxes(b);

	Point topRight(4, 2), bottomLeft(2, 0);
	b = Box(topRight, bottomLeft);
	compareBoxes(b);

	b = Box(bottomLeft, topRight);
	compareBoxes(b);
}
Example #16
0
void TennisFieldCalibrator::renderCalibrationWindow(Mat calibrationFrame, double h, double basis_min, double basis_maj, double h_displacement)
{
	Point center = Point(calibrationFrame.cols/2, calibrationFrame.rows/2);

	Point bottomLeft(center.x-(basis_maj/2), center.y+(h/2)+h_displacement);
	Point bottomRight(center.x+(basis_maj/2), center.y+(h/2)+h_displacement);
	Point topLeft(center.x-(basis_min/2), center.y-(h/2)+h_displacement);
	Point topRight(center.x+(basis_min/2), center.y-(h/2)+h_displacement);

	line(calibrationFrame, bottomLeft, bottomRight, Scalar(0, 255, 0), 2);
	line(calibrationFrame, bottomRight, topRight, Scalar(0, 255, 0), 2);
	line(calibrationFrame, topRight, topLeft, Scalar(0, 255, 0), 2);
	line(calibrationFrame, topLeft, bottomLeft, Scalar(0, 255, 0), 2);

	char buffer[300];
	sprintf(buffer, "PARAM: h=%g m=%g M=%g h_displacement=%g", h, basis_min, basis_maj, h_displacement);
	putText(calibrationFrame, buffer, cvPoint(10,30), FONT_HERSHEY_SIMPLEX, 1.0, cvScalar(50, 205, 50), 1, CV_AA);
}
Example #17
0
void dftshift(ImgT& img) {
  const int cx = img.cols/2;
  const int cy = img.rows/2;
  
  ImgT tmp;
  ImgT topLeft(img, cv::Rect(0, 0, cx, cy));
  ImgT topRight(img, cv::Rect(cx, 0, cx, cy));
  ImgT bottomLeft(img, cv::Rect(0, cy, cx, cy));
  ImgT bottomRight(img, cv::Rect(cx, cy, cx, cy));
  
  topLeft.copyTo(tmp);
  bottomRight.copyTo(topLeft);
  tmp.copyTo(bottomRight);
  
  topRight.copyTo(tmp);
  bottomLeft.copyTo(topRight);
  tmp.copyTo(bottomLeft);
}
Example #18
0
void Sprite::changeTexturePosition()
{
	vector2f topLeft(sourceRectPosition.x, sourceRectPosition.y);
	vector2f bottomLeft(sourceRectPosition.x, sourceRectPosition.y + sourceRectSize.y);
	vector2f topRight(sourceRectPosition.x + sourceRectSize.x, sourceRectPosition.y);
	vector2f bottomRight(sourceRectPosition.x + sourceRectSize.x, sourceRectPosition.y + sourceRectSize.y);

	VERTEX_DATA[5] = topLeft.x;
	VERTEX_DATA[6] = topLeft.y;

	VERTEX_DATA[5 + 7] = bottomLeft.x;
	VERTEX_DATA[6 + 7] = bottomLeft.y;

	VERTEX_DATA[5 + 14] =  topRight.x;
	VERTEX_DATA[6 + 14] = topRight.y;

	VERTEX_DATA[5 + 21] =  bottomRight.x;
	VERTEX_DATA[6 + 21] =  bottomRight.y;

	texturePositionChanged = false;
}
static void draw ( IPresSpaceHandle hps,
                   IListBox *lb, 
                   const TgtLocation &target )
  {
  if ( target.index != nil )
    {
    // First, get offset from top of listbox:
    unsigned
      offset = target.index - lb->top() + 1,
      height = ListBoxItem::itemHeight( lb );
    // Next, adjust if before this item:
    if ( target.type == ListBoxItem::before )
      offset--;
    // Calculate that item's rectangle's bottom:
    unsigned
      bottom = lb->rect().height() - height * offset;
    // Lower 2 pels 'cause it looks better!
    bottom -= 2;
    // Draw line or box:
    IPoint
      origin( 0, bottom );
    if ( target.type == ListBoxItem::on )
      {
      IPoint
        topRight( lb->rect().width(), bottom + height );
      origin += 1;
      topRight -= IPoint( WinQuerySysValue( HWND_DESKTOP,
                                            SV_CXVSCROLL ) + 1, 1 );
      GpiMove( hps, PPOINTL( &origin ) );
      GpiBox( hps, DRO_OUTLINE, PPOINTL( &topRight ), 0, 0 );
      }
    else
      {
      IPoint
        end( lb->rect().width(), bottom );
      GpiMove( hps, PPOINTL( &origin ) );
      GpiLine( hps, PPOINTL( &end ) );
      }
    }
  }
Example #20
0
    /**
     * @brief Entity::drawResizeCorner
     * @param painter
     */
    void Entity::drawResizeCorner(QPainter *painter)
    {
        painter->save();

        painter->setRenderHint(QPainter::Antialiasing);

        painter->setPen(typeColor());

        QRectF rect(resizeCornerRect());
        QPointF bottomLeft(rect.bottomLeft());
        QPointF topRight(rect.topRight());

        // Draw hypotenuse
        painter->drawLine(bottomLeft, topRight);

        // Draw middle line
        bottomLeft.rx() += rect.width() / 2;
        topRight.ry() += rect.height() / 2;
        painter->drawLine(bottomLeft, topRight);

        painter->restore();
    }
Example #21
0
QPainterPath CornersInWipeStrategy::clipPath(int step, const QRect &area)
{
    int width_2 = area.width() >> 1;
    int height_2 = area.height() >> 1;

    qreal percent = static_cast<qreal>(step) / static_cast<qreal>(StepCount);
    int stepx = static_cast<int>(width_2 * percent);
    int stepy = static_cast<int>(height_2 * percent);

    QPainterPath path;

    if(! reverse())
    {
        QSize rectSize(stepx, stepy);

        QRect topLeft(area.topLeft(), rectSize);
        QRect topRight(area.topRight() - QPoint(stepx, 0), rectSize);
        QRect bottomRight(area.bottomRight() - QPoint(stepx, stepy), rectSize);
        QRect bottomLeft(area.bottomLeft() - QPoint(0, stepy), rectSize);

        path.addRect(topLeft);
        path.addRect(topRight);
        path.addRect(bottomRight);
        path.addRect(bottomLeft);
    }
    else
    {
        QRect horzRect(QPoint(0, 0), QSize(2 * stepx, area.height()));
        horzRect.moveCenter(area.center());
        QRect vertRect(QPoint(0, 0), QSize(area.width(), 2 * stepy));
        vertRect.moveCenter(area.center());

        path.addRect(horzRect);
        path.addRect(vertRect);
        path.setFillRule(Qt::WindingFill);
    }

    return path;
}
void tst_QOpenGL::textureblitterFullTargetRectTransform()
{
    QVector4D topLeft(-1.f, 1.f, 0.f, 1.f);
    QVector4D bottomLeft(-1.f, -1.f, 0.f, 1.f);
    QVector4D topRight(1.f, 1.f, 0.f, 1.f);
    QVector4D bottomRight(1.f, -1.f, 0.f, 1.f);

    QRectF rect(0,0,200,200);
    QMatrix4x4 targetMatrix = QOpenGLTextureBlitter::targetTransform(rect,rect.toRect());

    QVector4D translatedTopLeft = targetMatrix * topLeft;
    QCOMPARE(translatedTopLeft, topLeft);

    QVector4D translatedBottomLeft = targetMatrix * bottomLeft;
    QCOMPARE(translatedBottomLeft, bottomLeft);

    QVector4D translatedTopRight = targetMatrix * topRight;
    QCOMPARE(translatedTopRight, topRight);

    QVector4D translatedBottomRight = targetMatrix * bottomRight;
    QCOMPARE(translatedBottomRight, bottomRight);
}
Example #23
0
BOOL CCircleView::IntersectsWithRect(const Rect& rectangle)
{
	Point center(position);

	double edgeCenterDistance = INT_MAX;
	std::vector<Point> rectCorners;
	Point topLeft(rectangle.GetLeft(), rectangle.GetTop());
	Point topRight(rectangle.GetRight(), rectangle.GetTop());
	Point bottomLeft(rectangle.GetLeft(), rectangle.GetBottom());
	Point bottomRight(rectangle.GetRight(), rectangle.GetBottom());

	rectCorners.push_back(topLeft);
	rectCorners.push_back(topRight);
	rectCorners.push_back(bottomLeft);
	rectCorners.push_back(bottomRight);

	//Le centre du cercle est-il dans le rectangle ?
	if(rectangle.Contains(center)) return TRUE;

	//Un coin du rectangle est-il dans le cercle ?
	for(auto it=rectCorners.begin(); it!=rectCorners.end(); ++it)
		if(Geometry::Distance(*it, center) < radius) return TRUE;

	//Un côté du rectangle coupe-t-il dans le cercle ?
	if(topLeft.X < center.X && center.X < topRight.X
		&& Geometry::LinePointDistance(topLeft, topRight, center) < radius)
		return TRUE;
	if(topLeft.Y < center.Y && center.Y < bottomLeft.Y
		&& Geometry::LinePointDistance(topLeft, bottomLeft, center) < radius)
		return TRUE;
	if(bottomLeft.X < center.X && center.X < bottomRight.X
		&& Geometry::LinePointDistance(bottomLeft, bottomRight, center) < radius)
		return TRUE;
	if(topRight.Y < center.Y && center.Y < bottomRight.Y
		&& Geometry::LinePointDistance(topRight, bottomRight, center) < radius)
		return TRUE;

	return FALSE;
}
Example #24
0
void HitEffect::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext) {
    assert(renderContext->args);
    assert(renderContext->args->hasViewFrustum());
    RenderArgs* args = renderContext->args;

    gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {

        glm::mat4 projMat;
        Transform viewMat;
        args->getViewFrustum().evalProjectionMatrix(projMat);
        args->getViewFrustum().evalViewTransform(viewMat);
        batch.setProjectionTransform(projMat);
        batch.setViewTransform(viewMat);
        batch.setModelTransform(Transform());

        batch.setPipeline(getHitEffectPipeline());

        glm::vec4 color(0.0f, 0.0f, 0.0f, 1.0f);
        glm::vec2 bottomLeft(-1.0f, -1.0f);
        glm::vec2 topRight(1.0f, 1.0f);
        DependencyManager::get<GeometryCache>()->renderQuad(batch, bottomLeft, topRight, color);
    });
}
Example #25
0
void ApplicationOverlay::renderRearView(RenderArgs* renderArgs) {
    if (!qApp->isHMDMode() && Menu::getInstance()->isOptionChecked(MenuOption::MiniMirror) &&
        !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {
        gpu::Batch& batch = *renderArgs->_batch;

        auto geometryCache = DependencyManager::get<GeometryCache>();

        auto framebuffer = DependencyManager::get<FramebufferCache>();
        auto selfieTexture = framebuffer->getSelfieFramebuffer()->getRenderBuffer(0);

        int width = renderArgs->_viewport.z;
        int height = renderArgs->_viewport.w;
        mat4 legacyProjection = glm::ortho<float>(0, width, height, 0, ORTHO_NEAR_CLIP, ORTHO_FAR_CLIP);
        batch.setProjectionTransform(legacyProjection);
        batch.setModelTransform(Transform());
        batch.setViewTransform(Transform());
        
        float screenRatio = ((float)qApp->getDevicePixelRatio());
        float renderRatio = ((float)qApp->getRenderResolutionScale());
        
        auto viewport = qApp->getMirrorViewRect();
        glm::vec2 bottomLeft(viewport.left(), viewport.top() + viewport.height());
        glm::vec2 topRight(viewport.left() + viewport.width(), viewport.top());
        bottomLeft *= screenRatio;
        topRight *= screenRatio;
        glm::vec2 texCoordMinCorner(0.0f, 0.0f);
        glm::vec2 texCoordMaxCorner(viewport.width() * renderRatio / float(selfieTexture->getWidth()), viewport.height() * renderRatio / float(selfieTexture->getHeight()));


        geometryCache->useSimpleDrawPipeline(batch, true);
        batch.setResourceTexture(0, selfieTexture);
        geometryCache->renderQuad(batch, bottomLeft, topRight, texCoordMinCorner, texCoordMaxCorner, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)); 

        batch.setResourceTexture(0, renderArgs->_whiteTexture);
        geometryCache->useSimpleDrawPipeline(batch, false);
    }
}
void tst_QOpenGL::textureblitterPartOriginTopLeftSourceRectTransform()
{
    TestVertex3D topLeft(uv_top_left);
    TestVertex3D bottomLeft(uv_bottom_left);
    TestVertex3D topRight(uv_top_right);
    TestVertex3D bottomRight(uv_bottom_right);

    QRectF sourceRect(50,190,170,170);
    QSize textureSize(400,400);

    QMatrix3x3 sourceMatrix = QOpenGLTextureBlitter::sourceTransform(sourceRect, textureSize, QOpenGLTextureBlitter::OriginTopLeft);

    const float x_point_ratio = sourceRect.topLeft().x() / textureSize.width();
    const float y_point_ratio = sourceRect.topLeft().y() / textureSize.height();
    const float width_ratio = sourceRect.width() / textureSize.width();
    const float height_ratio = sourceRect.height() / textureSize.height();

    TestVertex3D uvTopLeft = sourceMatrix * topLeft;
    const float expected_top_left[] = { x_point_ratio, 1 - y_point_ratio - height_ratio, 1 };
    TestVertex3D expectedTopLeft(expected_top_left);
    QVERIFY(q_fuzzy_compare(uvTopLeft, expectedTopLeft));

    TestVertex3D uvBottomLeft = sourceMatrix * bottomLeft;
    const float expected_bottom_left[] = { x_point_ratio, 1 - y_point_ratio, 1 };
    TestVertex3D expectedBottomLeft(expected_bottom_left);
    QVERIFY(q_fuzzy_compare(uvBottomLeft, expectedBottomLeft));

    TestVertex3D uvTopRight = sourceMatrix * topRight;
    const float expected_top_right[] = { x_point_ratio + width_ratio, 1 - y_point_ratio - height_ratio, 1 };
    TestVertex3D expectedTopRight(expected_top_right);
    QVERIFY(q_fuzzy_compare(uvTopRight, expectedTopRight));

    TestVertex3D uvBottomRight = sourceMatrix * bottomRight;
    const float expected_bottom_right[] = { x_point_ratio + width_ratio, 1 - y_point_ratio, 1 };
    TestVertex3D expectedBottomRight(expected_bottom_right);
    QVERIFY(q_fuzzy_compare(uvBottomRight, expectedBottomRight));
}
void tst_QOpenGL::textureblitterFullSourceRectTransform()
{
    TestVertex3D topLeft(uv_top_left);
    TestVertex3D bottomLeft(uv_bottom_left);
    TestVertex3D topRight(uv_top_right);
    TestVertex3D bottomRight(uv_bottom_right);

    QRectF rect(0,0,1,1);
    QMatrix3x3 flippedMatrix = QOpenGLTextureBlitter::sourceTransform(rect, rect.size().toSize(), QOpenGLTextureBlitter::OriginTopLeft);

    TestVertex3D flippedTopLeft = flippedMatrix * topLeft;
    QCOMPARE(flippedTopLeft, bottomLeft);

    TestVertex3D flippedBottomLeft = flippedMatrix * bottomLeft;
    QCOMPARE(flippedBottomLeft, topLeft);

    TestVertex3D flippedTopRight = flippedMatrix * topRight;
    QCOMPARE(flippedTopRight, bottomRight);

    TestVertex3D flippedBottomRight = flippedMatrix * bottomRight;
    QCOMPARE(flippedBottomRight, topRight);

    QMatrix3x3 identityMatrix = QOpenGLTextureBlitter::sourceTransform(rect, rect.size().toSize(), QOpenGLTextureBlitter::OriginBottomLeft);

    TestVertex3D notFlippedTopLeft = identityMatrix * topLeft;
    QCOMPARE(notFlippedTopLeft, topLeft);

    TestVertex3D notFlippedBottomLeft = identityMatrix * bottomLeft;
    QCOMPARE(notFlippedBottomLeft, bottomLeft);

    TestVertex3D notFlippedTopRight = identityMatrix * topRight;
    QCOMPARE(notFlippedTopRight, topRight);

    TestVertex3D notFlippedBottomRight = identityMatrix * bottomRight;
    QCOMPARE(notFlippedBottomRight, bottomRight);
}
Example #28
0
void RectTool::updateHandles()
{
	if (d->selectedLayerInfos.size() == 1 && d->mode == NoOperation)
	{
		auto rectLayer = d->selectedLayerInfos.at(0).rectLayer;
		if (rectLayer)
		{
			for (auto handle : d->handles)
				handle->setVisible(true);
			
			auto rect = rectLayer->rect();
			
			// get vertices in scene coordinates
			auto transformToWindow = canvas()->transforms()->sceneToWindow;
			auto topLeft = rect.topLeft() * transformToWindow;
			auto topRight = rect.topRight() * transformToWindow;
			auto bottomLeft = rect.bottomLeft() * transformToWindow;
			auto bottomRight = rect.bottomRight() * transformToWindow;
			
			d->findHandle(Left)->setPos( (topLeft + bottomLeft) * 0.5 );
			d->findHandle(Right)->setPos( (topRight + bottomRight) * 0.5 );
			d->findHandle(Top)->setPos( (topLeft + topRight) * 0.5 );
			d->findHandle(Bottom)->setPos( (bottomLeft + bottomRight) * 0.5 );
			
			d->findHandle(Left | Top)->setPos(topLeft);
			d->findHandle(Left | Bottom)->setPos(bottomLeft);
			d->findHandle(Right | Top)->setPos(topRight);
			d->findHandle(Right | Bottom)->setPos(bottomRight);
			
			return;
		}
	}
	
	for (auto handle : d->handles)
		handle->setVisible(false);
}
void TemporalConstraintView::paint(
        QPainter* painter,
        const QStyleOptionGraphicsItem*,
        QWidget*)
{
    qreal min_w = minWidth();
    qreal max_w = maxWidth();
    qreal def_w = defaultWidth();
    qreal play_w = playWidth();

    // Draw the stuff present if there is a rack *in the model* ?
    if(presenter().rack())
    {
        // Background
        auto rect = boundingRect();
        rect.adjust(0,15,0,-10);
        rect.setWidth(this->defaultWidth());
        painter->fillRect(rect, m_bgColor);

        // Fake timenode continuation
        auto color = ScenarioStyle::instance().RackSideBorder;
        QPen pen{color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin};
        painter->setPen(pen);
        painter->drawLine(rect.topLeft(), rect.bottomLeft());
        painter->drawLine(rect.topRight(), rect.bottomRight());
    }


    QPainterPath solidPath, dashedPath, leftBrace, rightBrace;

    // Paths
    if(infinite())
    {
        if(min_w != 0.)
        {
            solidPath.lineTo(min_w, 0);

            leftBrace.moveTo(min_w, -10);
            leftBrace.arcTo(min_w - 10, -10, 20, 20, 90, 180);
        }

        // TODO end state should be hidden
        dashedPath.moveTo(min_w, 0);
        dashedPath.lineTo(def_w, 0);
    }
    else if(min_w == max_w) // TODO rigid()
    {
        solidPath.lineTo(def_w, 0);
    }
    else
    {
        if(min_w != 0.)
            solidPath.lineTo(min_w, 0);

        dashedPath.moveTo(min_w, 0);
        dashedPath.lineTo(max_w, 0);

        leftBrace.moveTo(min_w + 10, -10);
        leftBrace.arcTo(min_w, -10, 20, 20, 90, 180);
        leftBrace.closeSubpath();

        rightBrace.moveTo(max_w, 10);
        rightBrace.arcTo(max_w - 10, -10, 20, 20, 270, 180);
        rightBrace.closeSubpath();
        rightBrace.translate(-10, 0); // TODO bleh.
    }

    QPainterPath playedPath;
    if(play_w != 0.)
    {
        playedPath.lineTo(play_w, 0);
    }

    // Colors
    QColor constraintColor;
    // TODO make a switch instead
    if(isSelected())
    {
        constraintColor = ScenarioStyle::instance().ConstraintSelected;
    }
    else if(warning())
    {
        constraintColor = ScenarioStyle::instance().ConstraintWarning;
    }
    else
    {
        constraintColor = ScenarioStyle::instance().ConstraintBase;
    }
    if(! isValid())
    {
        constraintColor = ScenarioStyle::instance().ConstraintInvalid;
        this->setZValue(this->zValue()+ 1);
    }
    else
    {
        this->setZValue(parentObject()->zValue() + 3);
    }

    m_solidPen.setColor(constraintColor);
    m_dashPen.setColor(constraintColor);

    // Drawing
    painter->setPen(m_solidPen);
    if(!solidPath.isEmpty())
        painter->drawPath(solidPath);
    if(!leftBrace.isEmpty())
        painter->drawPath(leftBrace);
    if(!rightBrace.isEmpty())
        painter->drawPath(rightBrace);

    painter->setPen(m_dashPen);
    if(!dashedPath.isEmpty())
        painter->drawPath(dashedPath);

    leftBrace.closeSubpath();
    rightBrace.closeSubpath();

    QPen anotherPen(Qt::transparent, 4);
    painter->setPen(anotherPen);
    QColor blueish = m_solidPen.color().lighter();
    blueish.setAlphaF(0.3);
    painter->setBrush(blueish);
    painter->drawPath(leftBrace);
    painter->drawPath(rightBrace);

    static const QPen playedPen{
        QBrush{ScenarioStyle::instance().ConstraintPlayFill},
        4,
        Qt::SolidLine,
                Qt::RoundCap,
                Qt::RoundJoin
    };

    painter->setPen(playedPen);
    if(!playedPath.isEmpty())
        painter->drawPath(playedPath);


    static const int fontSize = 12;
    QRectF labelRect{0,0, defaultWidth(), (-fontSize - 2.)};
    auto f = ProcessFonts::Sans();
    f.setPointSize(fontSize);

    painter->setFont(f);
    painter->setPen(m_labelColor);
    painter->drawText(labelRect, Qt::AlignCenter, m_label);

#if defined(ISCORE_SCENARIO_DEBUG_RECTS)
    painter->setPen(Qt::darkRed);
    painter->setBrush(Qt::NoBrush);
    painter->drawRect(boundingRect());
#endif
}
void TemporalConstraintHeader::paint(
        QPainter *painter,
        const QStyleOptionGraphicsItem *option,
        QWidget *widget)
{
    if(m_state == State::RackHidden)
    {
        auto rect = boundingRect();
        painter->fillRect(rect, ScenarioStyle::instance().ConstraintHeaderRackHidden.getBrush());

        // Fake timenode continuation
        auto color = ScenarioStyle::instance().ConstraintHeaderSideBorder.getColor();
        QPen pen{color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin};
        painter->setPen(pen);
        painter->drawLine(rect.topLeft(), rect.bottomLeft());
        painter->drawLine(rect.topRight(), rect.bottomRight());
        painter->drawLine(rect.bottomLeft(), rect.bottomRight());
    }

    // Header
    auto font = Skin::instance().SansFont;
    font.setPointSize(10);
    font.setBold(true);

    painter->setFont(font);
    painter->setPen(ScenarioStyle::instance().ConstraintHeaderText.getColor());

    QFontMetrics fm(font);
    int textWidth = fm.width(m_text);

    // If the centered text is hidden, we put it at the left so that it's on the view.
    // We have to compute the visible part of the header
    auto view = scene()->views().first();
    int text_left = view->mapFromScene(mapToScene({m_width / 2. - textWidth / 2., 0})).x();
    int text_right = view->mapFromScene(mapToScene({m_width / 2. + textWidth / 2., 0})).x();
    double x = (m_width - textWidth) / 2.;
    double min_x = 10;
    double max_x = view->width() - 30;

    if(text_left <= min_x)
    {
        // Compute the pixels needed to add to have top-left at 0
        x = x - text_left + min_x;
    }
    else if(text_right >= max_x)
    {
        // Compute the pixels needed to add to have top-right at max
        x = x - text_right + max_x;
    }

    x = std::max(x, 10.);
    double y = 2.5;
    double w = m_width - x;
    double h = ConstraintHeader::headerHeight();


    if(std::abs(m_previous_x - x) > 1)
    {
        m_previous_x = x;
    }
    painter->drawText(m_previous_x,y,w,h, Qt::AlignLeft, m_text);

    if(m_width > 20)
    {
        painter->setPen(ScenarioStyle::instance().ConstraintHeaderBottomLine.getColor());
        painter->drawLine(
                    boundingRect().bottomLeft(),
                    boundingRect().bottomRight());
    }
}