Ejemplo n.º 1
0
FloatRect RenderSVGText::strokeBoundingBox() const
{
    FloatRect strokeBoundaries = objectBoundingBox();
    const SVGRenderStyle& svgStyle = style().svgStyle();
    if (!svgStyle.hasStroke())
        return strokeBoundaries;

    SVGLengthContext lengthContext(&textElement());
    strokeBoundaries.inflate(svgStyle.strokeWidth().value(lengthContext));
    return strokeBoundaries;
}
Ejemplo n.º 2
0
void GuiElement::drawText(sf::RenderTarget& window, sf::FloatRect rect, string text, EGuiAlign align, float font_size, sf::Font* font, sf::Color color)
{
    sf::Text textElement(text, *font, font_size);
    float y = 0;
    float x = 0;
    
    //The "base line" of the text draw is the "Y position where the text is drawn" + font_size.
    //The height of normal text is 70% of the font_size.
    //So use those properties to align the text. Depending on the localbounds does not work.
    switch(align)
    {
    case ATopLeft:
    case ATopRight:
    case ATopCenter:
        y = rect.top - 0.3 * font_size;
        break;
    case ABottomLeft:
    case ABottomRight:
    case ABottomCenter:
        y = rect.top + rect.height - font_size;
        break;
    case ACenterLeft:
    case ACenterRight:
    case ACenter:
        y = rect.top + rect.height / 2.0 - font_size + font_size * 0.35;
        break;
    }
    
    switch(align)
    {
    case ATopLeft:
    case ABottomLeft:
    case ACenterLeft:
        x = rect.left - textElement.getLocalBounds().left;
        break;
    case ATopRight:
    case ABottomRight:
    case ACenterRight:
        x = rect.left + rect.width - textElement.getLocalBounds().width - textElement.getLocalBounds().left;
        break;
    case ATopCenter:
    case ABottomCenter:
    case ACenter:
        x = rect.left + rect.width / 2.0 - textElement.getLocalBounds().width / 2.0 - textElement.getLocalBounds().left;
        break;
    }
    textElement.setPosition(x, y);
    textElement.setColor(color);
    window.draw(textElement);
}
Ejemplo n.º 3
0
void ScriptErrorRenderer::render(sf::RenderTarget& window)
{
    P<ScriptObject> script = engine->getObject("scenario");
    if (!script)
    {
        destroy();
        return;
    }

    string error = script->getError();
    if (error != "")
    {
        sf::Text textElement(error, *bold_font, 25);
        textElement.setColor(sf::Color::Red);
        textElement.setPosition(0, 0);
        window.draw(textElement);
    }
}
Ejemplo n.º 4
0
void DebugRenderer::render(sf::RenderTarget& window)
{
    fps_counter++;
    if (fps_counter > 30)
    {
        fps = fps_counter / fps_timer.restart().asSeconds();
        fps_counter = 0;
    }
    string text = "";
    if (show_fps)
        text = text + "FPS: " + string(fps) + "\n";
    
    if (show_datarate && game_server)
    {
        text = text + string(game_server->getSendDataRate() / 1000, 1) + " kb per second\n";
        text = text + string(game_server->getSendDataRatePerClient() / 1000, 1) + " kb per client\n";
    }

    sf::Text textElement(text, *mainFont, 18);
    textElement.setPosition(0, 0);
    window.draw(textElement);
}
Ejemplo n.º 5
0
void SkSVGDevice::drawTextOnPath(const SkDraw&, const void* text, size_t len, const SkPath& path,
                                 const SkMatrix* matrix, const SkPaint& paint) {
    SkString pathID = fResourceBucket->addPath();

    {
        AutoElement defs("defs", fWriter);
        AutoElement pathElement("path", fWriter);
        pathElement.addAttribute("id", pathID);
        pathElement.addPathAttributes(path);

    }

    {
        AutoElement textElement("text", fWriter);
        textElement.addTextAttributes(paint);

        if (matrix && !matrix->isIdentity()) {
            textElement.addAttribute("transform", svg_transform(*matrix));
        }

        {
            AutoElement textPathElement("textPath", fWriter);
            textPathElement.addAttribute("xlink:href", SkStringPrintf("#%s", pathID.c_str()));

            if (paint.getTextAlign() != SkPaint::kLeft_Align) {
                SkASSERT(paint.getTextAlign() == SkPaint::kCenter_Align ||
                         paint.getTextAlign() == SkPaint::kRight_Align);
                textPathElement.addAttribute("startOffset",
                    paint.getTextAlign() == SkPaint::kCenter_Align ? "50%" : "100%");
            }

            SVGTextBuilder builder(text, len, paint, SkPoint::Make(0, 0), 0);
            textPathElement.addText(builder.text());
        }
    }
}
Ejemplo n.º 6
0
void RenderSVGText::layout()
{
    StackStats::LayoutCheckPoint layoutCheckPoint;
    ASSERT(needsLayout());
    LayoutRepainter repainter(*this, SVGRenderSupport::checkForSVGRepaintDuringLayout(*this));

    bool updateCachedBoundariesInParents = false;
    if (m_needsTransformUpdate) {
        m_localTransform = textElement().animatedLocalTransform();
        m_needsTransformUpdate = false;
        updateCachedBoundariesInParents = true;
    }

    if (!everHadLayout()) {
        // When laying out initially, collect all layout attributes, build the character data map,
        // and propogate resulting SVGLayoutAttributes to all RenderSVGInlineText children in the subtree.
        ASSERT(m_layoutAttributes.isEmpty());
        collectLayoutAttributes(this, m_layoutAttributes);
        updateFontInAllDescendants(this);
        m_layoutAttributesBuilder.buildLayoutAttributesForForSubtree(*this);

        m_needsReordering = true;
        m_needsTextMetricsUpdate = false;
        m_needsPositioningValuesUpdate = false;
        updateCachedBoundariesInParents = true;
    } else if (m_needsPositioningValuesUpdate) {
        // When the x/y/dx/dy/rotate lists change, recompute the layout attributes, and eventually
        // update the on-screen font objects as well in all descendants.
        if (m_needsTextMetricsUpdate) {
            updateFontInAllDescendants(this);
            m_needsTextMetricsUpdate = false;
        }

        m_layoutAttributesBuilder.buildLayoutAttributesForForSubtree(*this);
        m_needsReordering = true;
        m_needsPositioningValuesUpdate = false;
        updateCachedBoundariesInParents = true;
    } else if (m_needsTextMetricsUpdate || SVGRenderSupport::findTreeRootObject(*this).isLayoutSizeChanged()) {
        // If the root layout size changed (eg. window size changes) or the transform to the root
        // context has changed then recompute the on-screen font size.
        updateFontInAllDescendants(this, &m_layoutAttributesBuilder);

        ASSERT(!m_needsReordering);
        ASSERT(!m_needsPositioningValuesUpdate);
        m_needsTextMetricsUpdate = false;
        updateCachedBoundariesInParents = true;
    }

    checkLayoutAttributesConsistency(this, m_layoutAttributes);

    // Reduced version of RenderBlock::layoutBlock(), which only takes care of SVG text.
    // All if branches that could cause early exit in RenderBlocks layoutBlock() method are turned into assertions.
    ASSERT(!isInline());
    ASSERT(!simplifiedLayout());
    ASSERT(!scrollsOverflow());
    ASSERT(!hasControlClip());
    ASSERT(!multiColumnFlowThread());
    ASSERT(!positionedObjects());
    ASSERT(!m_overflow);
    ASSERT(!isAnonymousBlock());

    if (!firstChild())
        setChildrenInline(true);

    // FIXME: We need to find a way to only layout the child boxes, if needed.
    FloatRect oldBoundaries = objectBoundingBox();
    ASSERT(childrenInline());
    LayoutUnit repaintLogicalTop = 0;
    LayoutUnit repaintLogicalBottom = 0;
    rebuildFloatingObjectSetFromIntrudingFloats();
    layoutInlineChildren(true, repaintLogicalTop, repaintLogicalBottom);

    if (m_needsReordering)
        m_needsReordering = false;

    if (!updateCachedBoundariesInParents)
        updateCachedBoundariesInParents = oldBoundaries != objectBoundingBox();

    // Invalidate all resources of this client if our layout changed.
    if (everHadLayout() && selfNeedsLayout())
        SVGResourcesCache::clientLayoutChanged(*this);

    // If our bounds changed, notify the parents.
    if (updateCachedBoundariesInParents)
        RenderSVGBlock::setNeedsBoundariesUpdate();

    repainter.repaintAfterLayout();
    clearNeedsLayout();
}
Ejemplo n.º 7
0
void DebugRenderer::render(sf::RenderTarget& window)
{
    fps_counter++;
    if (fps_counter > 30)
    {
        fps = fps_counter / fps_timer.restart().asSeconds();
        fps_counter = 0;
    }
    string text = "";
    if (show_fps)
        text = text + "FPS: " + string(fps) + "\n";
    
    if (show_datarate && game_server)
    {
        text = text + string(game_server->getSendDataRate() / 1000, 1) + " kb per second\n";
        text = text + string(game_server->getSendDataRatePerClient() / 1000, 1) + " kb per client\n";
    }
    if (show_timing_graph)
    {
        if (timing_graph_points.size() > window.getView().getSize().x)
            timing_graph_points.clear();
        timing_graph_points.push_back(engine->getEngineTiming());
        sf::VertexArray update_points(sf::LinesStrip, timing_graph_points.size());
        sf::VertexArray collision_points(sf::LinesStrip, timing_graph_points.size());
        sf::VertexArray render_points(sf::LinesStrip, timing_graph_points.size());
        for(unsigned int n=0; n<timing_graph_points.size(); n++)
        {
            update_points[n].position.x = float(n);
            update_points[n].position.y = window.getView().getSize().y - timing_graph_points[n].update * 10000;
            collision_points[n].position.x = float(n);
            collision_points[n].position.y = window.getView().getSize().y - (timing_graph_points[n].update + timing_graph_points[n].collision) * 10000;
            render_points[n].position.x = float(n);
            render_points[n].position.y = window.getView().getSize().y - (timing_graph_points[n].render + timing_graph_points[n].update + timing_graph_points[n].collision) * 10000;
            
            update_points[n].color = sf::Color::Red;
            collision_points[n].color = sf::Color::Cyan;
            render_points[n].color = sf::Color::Green;
        }
        window.draw(update_points);
        window.draw(collision_points);
        window.draw(render_points);
        
        sf::Text text_update("Update: " + string(timing_graph_points.back().update * 1000) + "ms", *mainFont, 18);
        sf::Text text_collision("Collision: " + string(timing_graph_points.back().collision * 1000) + "ms", *mainFont, 18);
        sf::Text text_render("Render: " + string(timing_graph_points.back().render * 1000) + "ms", *mainFont, 18);

        sf::VertexArray fps60_line(sf::LinesStrip, 2);
        fps60_line[0].position = sf::Vector2f(0, window.getView().getSize().y - 166);
        fps60_line[1].position = sf::Vector2f(window.getView().getSize().x, window.getView().getSize().y - 166);
        fps60_line[0].color = sf::Color(255, 255, 255, 128);
        fps60_line[1].color = sf::Color(255, 255, 255, 128);
        window.draw(fps60_line);
        
        text_update.setPosition(0, window.getView().getSize().y - 18 * 3 - 170);
        text_collision.setPosition(0, window.getView().getSize().y - 18 * 2 - 170);
        text_render.setPosition(0, window.getView().getSize().y - 18 - 170);
        text_update.setColor(sf::Color::Red);
        text_collision.setColor(sf::Color::Cyan);
        text_render.setColor(sf::Color::Green);
        window.draw(text_update);
        window.draw(text_collision);
        window.draw(text_render);
    }

    sf::Text textElement(text, *mainFont, 18);
    textElement.setPosition(0, 0);
    window.draw(textElement);
}
Ejemplo n.º 8
0
std::shared_ptr<XMLElement> FormSerializer::textToXML(std::shared_ptr<FormText> text) const {
    std::shared_ptr<XMLElement> textElement (new XMLElement("text"));
    textElement->addNode(std::make_shared<XMLTextNode>(text->getTextString()));
    return textElement;
}