Sha256: 1711f47b885b89742f2b0008c71b8de89bdc2424a2769ccd3ddbf6b6e9d33cbf

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 KB

Contents

#pragma once

#include "GraphicsImpl.hpp"
#include "MarkupParser.hpp"
#include <vector>

namespace Gosu
{
    struct WordInfo
    {
        std::vector<FormattedString> parts;
        bool is_whitespace;
        bool is_end_of_line;
        double width;

        WordInfo(const std::string& font_name, double font_height,
                 std::vector<FormattedString> parts);
    };

    class TextBuilder
    {
        // Parameters.
        std::string m_font_name;
        double m_font_height;
        double m_line_spacing;
        Alignment m_align;

        enum EndOfLineReason
        {
            LINE_TOO_LONG,
            END_OF_PARAGRAPH,
            END_OF_TEXT
        };

        // Input.
        std::vector<WordInfo> m_current_line;
        int m_current_line_width = 0;
        void flush_current_line(EndOfLineReason reason);

        // Output.
        Bitmap m_result;
        int m_used_lines = 0;
        int m_allocated_lines = 0;
        void allocate_next_line();
        void resize_to_allocated_lines();

    public:
        TextBuilder(const std::string& font_name, int font_height, int line_spacing, int width,
                    Alignment align);

        void feed_word(std::vector<FormattedString>&& word);

        Bitmap move_into_bitmap() &&;
    };
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gosu-1.4.6 src/TextBuilder.hpp
gosu-1.4.5 src/TextBuilder.hpp
gosu-1.4.5.pre1 src/TextBuilder.hpp
gosu-1.4.4 src/TextBuilder.hpp
gosu-1.4.3 src/TextBuilder.hpp
gosu-1.4.1 src/TextBuilder.hpp
gosu-1.4.0 src/TextBuilder.hpp