Esempio n. 1
0
//    	AnimatedPath(Point const & start_point, Point const & end_point, int const & beginn, int const & duration,
//    			Fill const & fill = Fill(), Stroke const & stroke = Stroke())
//                : Shape(fill, stroke), start_point(start_point), end_point(end_point), beginn(beginn), duration(duration) { }
//    	AnimatedPath(Stroke const & stroke = Stroke()) : Shape(Color::Transparent, stroke) { }
//            Polygon & operator<<(Point const & point)
//            {
//                points.push_back(point);
//                return *this;
//            }
            std::string toString(Layout const & layout) const
            {
                std::stringstream ss;
                ss << elemStart("path");

                ss << "d=\"";
                std::stringstream  startPoint;
                std::stringstream  beforePoint;
                std::stringstream  afterPoint;
                startPoint << "M " << translateX(start_point.x, layout) << "," << translateY(start_point.y, layout) << " ";
                ss << startPoint.str();
                beforePoint << "L " << translateX(start_point.x, layout) << "," << translateY(start_point.y, layout) << "\"";
                afterPoint << "L " << translateX(end_point.x, layout) << "," << translateY(end_point.y, layout) << "\"";
                ss << beforePoint.str() << " "<< fill.toString(layout) << stroke.toString(layout)<< ">";
                ss << elemStart("animate");
                ss << " attributeType=\"XML\" attributeName=\"d\" fill=\"freeze\" ";
                ss << "from=\"" << startPoint.str() << " " << beforePoint.str() << " ";
                ss << "to=\"" << startPoint.str() << " " << afterPoint.str() << "";
                ss << " begin=\"" << beginn << "\" ";
                ss << "dur=\"" <<  duration << "\"";
                ss << emptyElemEnd();
                ss << elemEnd("path");
//                for (unsigned i = 0; i < points.size(); ++i)
//                    ss << translateX(points[i].x, layout) << "," << translateY(points[i].y, layout) << " ";


//                ss << fill.toString(layout) << stroke.toString(layout) << emptyElemEnd();
                return ss.str();
            }
Esempio n. 2
0
 std::string toString(Layout const & layout) const
 {
     std::stringstream ss;
     ss << elemStart("line") << attribute("x1", translateX(start_point.x, layout))
         << attribute("y1", translateY(start_point.y, layout))
         << attribute("x2", translateX(end_point.x, layout))
         << attribute("y2", translateY(end_point.y, layout))
         << stroke.toString(layout) << emptyElemEnd();
     return ss.str();
 }
void SceneGraphDeviceContext::DrawComplexBezierPath(vrv::Point bezier1[4], vrv::Point bezier2[4])
{
    // Note: No support for vertex antialiasing. Use a top-level QQuickView with multisample antialiasing.
    // TODO: Add vertex antialiasing, refer to
    // 1) Qt sources for "void QSGBasicInternalRectangleNode::updateGeometry()" in
    // qtdeclarative/src/quick/scenegraph/qsgbasicinternalrectanglenode.cpp
    // 2) https://stackoverflow.com/questions/28125425/smooth-painting-in-custom-qml-element

    vrv::Pen currentPen = m_penStack.top();

    int segmentCount = 16;

    QSGGeometryNode *node = new QSGGeometryNode;
    QSGGeometry *geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 2 * segmentCount);
    geometry->setDrawingMode(QSGGeometry::DrawTriangleStrip);
    node->setGeometry(geometry);
    node->setFlag(QSGNode::OwnsGeometry);

    QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
    material->setColor(static_cast<QRgb>(currentPen.GetColour()));
    node->setMaterial(material);
    node->setFlag(QSGNode::OwnsMaterial);

    auto calculateCubicBezierPoint = [](vrv::Point p[4], float t) -> std::tuple<float, float> {
        auto invt = 1 - t;
        auto x = invt * invt * invt * p[0].x + 3 * invt * invt * t * p[1].x + 3 * invt * t * t * p[2].x
            + t * t * t * p[3].x;
        auto y = invt * invt * invt * p[0].y + 3 * invt * invt * t * p[1].y + 3 * invt * t * t * p[2].y
            + t * t * t * p[3].y;
        return std::make_tuple(x, y);
    };

    // This loop calculates the bezier points for the inner and the outer line and add them as vertices. The list of
    // vertices is built so that points from the inner and outer line are alternating. This allows to draw a filled area
    // with DrawTriangleStrip.
    QSGGeometry::Point2D *vertices = geometry->vertexDataAsPoint2D();
    for (int i = 0; i < segmentCount; ++i) {
        float bezierPointX = 0;
        float bezierPointY = 0;
        float currentSegment = i / static_cast<float>(segmentCount - 1);

        // Calculate bezier point on bezier1
        std::tie(bezierPointX, bezierPointY) = calculateCubicBezierPoint(bezier1, currentSegment);
        vertices[i * 2].set(translateX(bezierPointX), translateY(bezierPointY));

        // Calculate bezier point on bezier2
        std::tie(bezierPointX, bezierPointY) = calculateCubicBezierPoint(bezier2, currentSegment);
        vertices[i * 2 + 1].set(translateX(bezierPointX), translateY(bezierPointY));
    }

    node->markDirty(QSGNode::DirtyGeometry);
    AddGeometryNode(node);
}
//----------------------------------------------------------
void ofRectangle::alignToHorz(const float& targetX,
                              ofAlignHorz thisHorzAnchor) {

    if(thisHorzAnchor != OF_ALIGN_HORZ_IGNORE) {
        translateX(targetX - getHorzAnchor(thisHorzAnchor));
    } else {
        ofLogVerbose("ofRectangle") << "alignToHorz(): thisHorzAnchor == OF_ALIGN_HORZ_IGNORE, no alignment applied";
    }
}
Esempio n. 5
0
 std::string toString(Layout const & layout) const
 {
     std::stringstream ss;
     ss << elemStart("text") << attribute("x", translateX(origin.x, layout))
         << attribute("y", translateY(origin.y, layout))
         << fill.toString(layout) << stroke.toString(layout) << font.toString(layout)
         << ">" << content << elemEnd("text");
     return ss.str();
 }
Esempio n. 6
0
 std::string toString(Layout const & layout) const
 {
     std::stringstream ss;
     ss << elemStart("circle") << attribute("cx", translateX(center.x, layout))
         << attribute("cy", translateY(center.y, layout))
         << attribute("r", translateScale(radius, layout)) << fill.toString(layout)
         << stroke.toString(layout) << emptyElemEnd();
     return ss.str();
 }
void SceneGraphDeviceContext::DrawPolygon(int n, vrv::Point points[], int xoffset, int yoffset, int)
{
    // Note: No support for vertex antialiasing. Use a top-level QQuickView with multisample antialiasing.
    // TODO: Add vertex antialiasing, refer to
    // 1) Qt sources for "void QSGBasicInternalRectangleNode::updateGeometry()" in
    // qtdeclarative/src/quick/scenegraph/qsgbasicinternalrectanglenode.cpp
    // 2) https://stackoverflow.com/questions/28125425/smooth-painting-in-custom-qml-element

    // TODO: This function only works for convex polygons. At the moment verovio calls this function only with n = 4.
    // Maybe this function should be renamed to DrawConvexPolygon

    vrv::Pen currentPen = m_penStack.top();

    QSGGeometry *geometry;
    geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), n);
    geometry->setDrawingMode(QSGGeometry::DrawTriangleStrip);

    QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
    material->setColor(static_cast<QRgb>(currentPen.GetColour()));

    // Reorder points so that they can be drawn with DrawTriangleStrip.
    int counter1 = 0;
    int counter2 = n - 1;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            geometry->vertexDataAsPoint2D()[i].set(
                translateX(points[counter1].x + xoffset), translateY(points[counter1].y + yoffset));
            counter1++;
        }
        else {
            geometry->vertexDataAsPoint2D()[i].set(
                translateX(points[counter2].x + xoffset), translateY(points[counter2].y + yoffset));
            counter2--;
        }
    }

    QSGGeometryNode *node = new QSGGeometryNode;
    node->setGeometry(geometry);
    node->setFlag(QSGNode::OwnsGeometry);
    node->setMaterial(material);
    node->setFlag(QSGNode::OwnsMaterial);

    AddGeometryNode(node);
}
Esempio n. 8
0
int translateXTest() 
{
    START_TEST_CASE;
    int x2;

    int x1 = 1;
    x2 = translateX(x1);
    SHOULD_BE(x2 == 5);

    x1 = -1;
    x2 = translateX(x1);
    SHOULD_BE(x2 == -3);

    x1 = 0;
    x2 = translateX(x1);
    SHOULD_BE(x2 == 1);

    END_TEST_CASE;
}
Esempio n. 9
0
 std::string toString(Layout const & layout) const
 {
     std::stringstream ss;
     ss << elemStart("rect") << attribute("x", translateX(edge.x, layout))
         << attribute("y", translateY(edge.y, layout))
         << attribute("width", translateScale(width, layout))
         << attribute("height", translateScale(height, layout))
         << fill.toString(layout) << stroke.toString(layout) << emptyElemEnd();
     return ss.str();
 }
Esempio n. 10
0
void Transform::applyAnimationValueTranslationX(float tx)
{
    if ((_animationPropertyBitFlag & ANIMATION_TRANSLATION_X_BIT) != ANIMATION_TRANSLATION_X_BIT)
    {
        _animationPropertyBitFlag |= ANIMATION_TRANSLATION_X_BIT;
        setTranslationX(tx);
    }
    else
    {
        translateX(tx);
    }
}
void SceneGraphDeviceContext::DrawLine(int x1, int y1, int x2, int y2)
{
    vrv::Pen currentPen = m_penStack.top();

    QSGGeometry *geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 2);
    geometry->setDrawingMode(GL_LINES);
    geometry->setLineWidth(translate(currentPen.GetWidth()));
    geometry->vertexDataAsPoint2D()[0].set(translateX(x1), translateY(y1));
    geometry->vertexDataAsPoint2D()[1].set(translateX(x2), translateY(y2));

    QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
    material->setColor(static_cast<QRgb>(currentPen.GetColour()));

    QSGGeometryNode *node = new QSGGeometryNode;
    node->setGeometry(geometry);
    node->setFlag(QSGNode::OwnsGeometry);
    node->setMaterial(material);
    node->setFlag(QSGNode::OwnsMaterial);

    AddGeometryNode(node);
}
void SceneGraphDeviceContext::SetTextPositionAndAlignment(int x, int y, vrv::data_HORIZONTALALIGNMENT alignment)
{
    m_currentTextQuickItem->setX(static_cast<double>(translateX(x)));
    m_currentTextQuickItem->setY(static_cast<double>(translateY(y)));

    switch (alignment) {
        case vrv::HORIZONTALALIGNMENT_left: m_currentTextQuickItem->setAlignment(Qt::AlignLeft); break;
        case vrv::HORIZONTALALIGNMENT_right: m_currentTextQuickItem->setAlignment(Qt::AlignRight); break;
        case vrv::HORIZONTALALIGNMENT_center: m_currentTextQuickItem->setAlignment(Qt::AlignHCenter); break;
        case vrv::HORIZONTALALIGNMENT_justify: m_currentTextQuickItem->setAlignment(Qt::AlignJustify); break;
        default: break;
    }
}
Esempio n. 13
0
        std::string toString(Layout const & layout) const
        {
            std::stringstream ss;
            ss << elemStart("polyline");

            ss << "points=\"";
            for (unsigned i = 0; i < points.size(); ++i)
                ss << translateX(points[i].x, layout) << "," << translateY(points[i].y, layout) << " ";
            ss << "\" ";

            ss << fill.toString(layout) << stroke.toString(layout) << emptyElemEnd();
            return ss.str();
        }
void SceneGraphDeviceContext::DrawRectangle(int x, int y, int width, int height)
{
    vrv::Pen currentPen = m_penStack.top();

    QSGSimpleRectNode *node = new QSGSimpleRectNode;
    node->setColor(static_cast<QRgb>(currentPen.GetColour()));
    qreal rectX = static_cast<qreal>(translateX(x));
    qreal rectY = static_cast<qreal>(translateY(y));
    qreal rectWidth = static_cast<qreal>(translate(width));
    qreal rectHeight = static_cast<qreal>(translate(height));
    node->setRect(rectX, rectY, rectWidth, rectHeight);
    AddGeometryNode(node);
}
void SceneGraphDeviceContext::DrawCircle(int x, int y, int radius)
{
    // Note: No support for vertex antialiasing. Use a top-level QQuickView with multisample antialiasing.
    // TODO: Add vertex antialiasing, refer to
    // 1) Qt sources for "void QSGBasicInternalRectangleNode::updateGeometry()" in
    // qtdeclarative/src/quick/scenegraph/qsgbasicinternalrectanglenode.cpp
    // 2) https://stackoverflow.com/questions/28125425/smooth-painting-in-custom-qml-element

    vrv::Pen currentPen = m_penStack.top();

    int segmentCount = 16;

    QSGGeometryNode *node = new QSGGeometryNode();
    QSGGeometry *geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), segmentCount);
    geometry->setDrawingMode(QSGGeometry::DrawTriangleFan);
    node->setGeometry(geometry);
    node->setFlag(QSGNode::OwnsGeometry);

    QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
    material->setColor(static_cast<QRgb>(currentPen.GetColour()));
    node->setMaterial(material);
    node->setFlag(QSGNode::OwnsMaterial);

    // This draws individual triangles from the first point (center) to every outer point by using DrawTriangleFan.
    QSGGeometry::Point2D *vertices = geometry->vertexDataAsPoint2D();
    int numPoints = geometry->vertexCount();
    vertices[0].x = translateX(x);
    vertices[0].y = translateY(y);
    for (int i = 1; i < numPoints; ++i) {
        double theta = i * 2 * M_PI / (numPoints - 2);
        vertices[i].x = translateX(x + radius * static_cast<float>(std::cos(theta)));
        vertices[i].y = translateY(y - radius * static_cast<float>(std::sin(theta)));
    }

    node->markDirty(QSGNode::DirtyGeometry);
    AddGeometryNode(node);
}
void callMotionFunc(int x, int y) {
    switch(g_mouseCurrentButton) {
    case LEFT :
        rotateHead  ((g_mousePreviousX - x) / 10.0);
        nodHead     ((g_mousePreviousY - y) / 10.0);
        break;
    case MIDDLE :
        rotateZ     ((g_mousePreviousX - x) / 10.0);
        zoom        ((g_mousePreviousY - y) / 10.0);
        break;
    case RIGHT :
        translateY  ((g_mousePreviousX - x) / 10.0);
        translateX  ((g_mousePreviousY - y) / 10.0);
        break;
    default:
        break;
    }

    g_mousePreviousX = x;
    g_mousePreviousY = y;
}
void SceneGraphDeviceContext::DrawMusicText(const std::wstring &text, int x, int y, bool)
{
    Q_ASSERT(m_fontStack.top());

    QFont font(QString::fromStdString(m_fontStack.top()->GetFaceName()));

    // Note: Verovio calls it point size but it is actually pixel size. Qt can only handle pixel size in int, thus it
    // would be better to use point size.
    int pixelSize = static_cast<int>(translate(m_fontStack.top()->GetPointSize()));
    font.setPixelSize(pixelSize);

    // Memory management is handled by m_quickItem (set in AddQuickItem)
    auto musicTextQuickItem = new TextQuickItem();

    musicTextQuickItem->appendText(QString::fromStdWString(text), font);

    musicTextQuickItem->setX(static_cast<double>(translateX(x)));
    musicTextQuickItem->setY(static_cast<double>(translateY(y)));
    musicTextQuickItem->calcPos();

    AddQuickItem(musicTextQuickItem);
}
//----------------------------------------------------------
void ofRectangle::translate(float dx, float dy) {
    translateX(dx);
    translateY(dy);
}
Esempio n. 19
0
	void Point2f::translate(const Vector2f &tv)
	{
		translateX(tv.getX());
		translateY(tv.getY());
	}
//----------------------------------------------------------
void ofRectangle::translate(const ofPoint& dp) {
    translateX(dp.x);
    translateY(dp.y);
}
Esempio n. 21
0
	void Point2f::translate(float xt, float yt)
	{
		translateX(xt);
		translateY(yt);
	}