Beispiel #1
0
 public void add_text(string text, text_justify line_justify, rgb_t fgcolor, rgb_t bgcolor, float size = 1.0f)  //void add_text(std::string_view text, text_justify line_justify, rgb_t fgcolor = rgb_t::white(), rgb_t bgcolor = rgb_t::transparent(), float size = 1.0)
 {
     add_text(text, line_justify, new char_style()
     {
         fgcolor = fgcolor, bgcolor = bgcolor, size = size
     });
 }
Beispiel #2
0
 //-------------------------------------------------
 //  line::ctor
 //-------------------------------------------------
 public line(text_layout layout, text_justify justify, float yoffset, float height)
 {
     m_layout  = layout;
     m_justify = justify;
     m_yoffset = yoffset;
     m_width   = 0;
     m_height  = height;
 }
Beispiel #3
0
        // ctor/dtor
        //-------------------------------------------------
        //  ctor
        //-------------------------------------------------
        public text_layout(render_font font, float xscale, float yscale, float width, text_justify justify, word_wrapping wrap)
        {
            m_font          = font;
            m_xscale        = xscale;
            m_yscale        = yscale;
            m_width         = width;
            m_justify       = justify;
            m_wrap          = wrap;
            m_current_line  = null;
            m_last_break    = 0;
            m_text_position = 0;
            m_truncating    = false;


            invalidate_calculated_actual_width();
        }
Beispiel #4
0
        //-------------------------------------------------
        //  ctor (move)
        //-------------------------------------------------
        text_layout(text_layout that)
        {
            m_font   = that.m_font;
            m_xscale = that.m_xscale;
            m_yscale = that.m_yscale;
            m_width  = that.m_width;
            m_calculated_actual_width = that.m_calculated_actual_width;
            m_justify       = that.m_justify;
            m_wrap          = that.m_wrap;
            m_lines         = new std.vector <line>(that.m_lines);
            m_current_line  = that.m_current_line;
            m_last_break    = that.m_last_break;
            m_text_position = that.m_text_position;
            m_truncating    = false;


            that.invalidate_calculated_actual_width();
        }
Beispiel #5
0
            public void set_justification(text_justify justify)
            {
                switch (justify)
                {
                case text_justify.RIGHT:
                    if (npos == m_right_justify_start)
                    {
                        m_right_justify_start = m_characters.size();
                    }
                    goto case text_justify.CENTER;  //[[fallthrough]];

                case text_justify.CENTER:
                    if (npos == m_center_justify_start)
                    {
                        m_center_justify_start = m_characters.size();
                    }
                    break;

                case text_justify.LEFT:
                    break;
                }
            }
Beispiel #6
0
        // methods

        //-------------------------------------------------
        //  add_text
        //-------------------------------------------------
        void add_text(string text, char_style style)
        {
            UInt32 position    = 0;
            UInt32 text_length = (UInt32)text.Length;

            while (position < text_length)
            {
                // adding a character - we might change the width
                invalidate_calculated_actual_width();

                // do we need to create a new line?
                if (m_current_line == null)
                {
                    // get the current character
                    char schar;                                                                                                                //char32_t schar;
                    int  scharcount = unicode_global.uchar_from_utf8(out schar, text.Substring((int)position), (int)(text_length - position)); //  &text[position]
                    if (scharcount < 0)
                    {
                        break;
                    }

                    // if the line starts with a tab character, center it regardless
                    text_justify line_justify = justify();
                    if (schar == '\t')
                    {
                        position    += (UInt32)scharcount;
                        line_justify = text_justify.CENTER;
                    }

                    // start a new line
                    start_new_line(line_justify, style.size);
                }

                {
                    // get the current character
                    char ch;                                                                                                                //char32_t ch;
                    int  scharcount = unicode_global.uchar_from_utf8(out ch, text.Substring((int)position), (int)(text_length - position)); // &text[position], text_length - position);
                    if (scharcount < 0)
                    {
                        break;
                    }
                    position += (UInt32)scharcount;

                    // set up source information
                    source_info source;
                    source.start     = m_text_position;
                    source.span      = (UInt32)scharcount;
                    m_text_position += (UInt32)scharcount;

                    // is this an endline?
                    if (ch == '\n')
                    {
                        // first, start a line if we have not already
                        if (m_current_line == null)
                        {
                            start_new_line(text_justify.LEFT, style.size);
                        }

                        // and then close up the current line
                        m_current_line = null;
                    }
                    else if (!m_truncating)
                    {
                        // if we hit a space, remember the location and width *without* the space
                        if (is_space_character(ch))
                        {
                            m_last_break = m_current_line.character_count();
                        }

                        // append the character
                        m_current_line.add_character(ch, style, source);

                        // do we have to wrap?
                        if (wrap() != word_wrapping.NEVER && m_current_line.width() > m_width)
                        {
                            switch (wrap())
                            {
                            case word_wrapping.TRUNCATE:
                                truncate_wrap();
                                break;

                            case word_wrapping.WORD:
                                word_wrap();
                                break;

                            default:
                                fatalerror("invalid word wrapping value");
                                break;
                            }
                        }
                        else
                        {
                            // we didn't wrap - if we hit any non-space breakable character, remember the location and width
                            // *with* the breakable character
                            if (ch != ' ' && is_breakable_char(ch))
                            {
                                m_last_break = m_current_line.character_count();
                            }
                        }
                    }
                }
            }
        }
Beispiel #7
0
        //-------------------------------------------------
        //  add_text
        //-------------------------------------------------
        void add_text(string text, text_justify line_justify, char_style style)
        {
            while (!text.empty())
            {
                // adding a character - we might change the width
                invalidate_calculated_actual_width();

                // do we need to create a new line?
                if (m_current_line == null)
                {
                    start_new_line(style.size);
                }

                m_current_line.set_justification(line_justify);

                // get the current character
                char ch;  //char32_t ch;
                int  scharcount = uchar_from_utf8(out ch, text);
                if (scharcount < 0)
                {
                    break;
                }

                text = text.remove_prefix_((size_t)scharcount);

                // set up source information
                source_info source = new source_info()
                {
                    start = 0, span = 0
                };
                source.start     = m_text_position;
                source.span      = (size_t)scharcount;
                m_text_position += (size_t)scharcount;

                // is this an endline?
                if (ch == '\n')
                {
                    // close up the current line
                    m_current_line.align_text(this);
                    m_current_line = null;
                }
                else if (!m_truncating)
                {
                    // if we hit a space, remember the location and width *without* the space
                    bool is_space = is_space_character(ch);
                    if (is_space)
                    {
                        m_last_break = m_current_line.character_count();
                    }

                    // append the character
                    m_current_line.add_character(this, ch, style, source);

                    // do we have to wrap?
                    if ((wrap() != word_wrapping.NEVER) && (m_current_line.width() > m_width))
                    {
                        switch (wrap())
                        {
                        case word_wrapping.TRUNCATE:
                            truncate_wrap();
                            break;

                        case word_wrapping.WORD:
                            word_wrap();
                            break;

                        case word_wrapping.NEVER:
                            // can't happen due to if condition, but compile warns about it
                            break;
                        }
                    }
                    else
                    {
                        // we didn't wrap - if we hit any non-space breakable character,
                        // remember the location and width *with* the breakable character
                        if (!is_space && is_breakable_char(ch))
                        {
                            m_last_break = m_current_line.character_count();
                        }
                    }
                }
            }
        }
Beispiel #8
0
 public void add_text(string text, text_justify line_justify, rgb_t fgcolor)
 {
     add_text(text, line_justify, fgcolor, rgb_t.transparent());
 }
Beispiel #9
0
 public void add_text(string text, text_justify line_justify)
 {
     add_text(text, line_justify, rgb_t.white(), rgb_t.transparent());
 }