Exemplo n.º 1
0
Arquivo: text.cs Projeto: kwanboy/mcs
            // accessors

            //-------------------------------------------------
            //  line::xoffset
            //-------------------------------------------------
            public float xoffset()
            {
                float result;

                switch (justify())
                {
                case text_justify.LEFT:
                default:
                    result = 0;
                    break;

                case text_justify.CENTER:
                    result = (m_layout.width() - width()) / 2;
                    break;

                case text_justify.RIGHT:
                    result = m_layout.width() - width();
                    break;
                }
                return(result);
            }
Exemplo n.º 2
0
 // accessors
 public float xoffset(text_layout layout)
 {
     return((layout.width() * m_anchor_target) - (m_width * m_anchor_pos));
 }
Exemplo n.º 3
0
            public void align_text(text_layout layout)
            {
                assert(m_right_justify_start >= m_center_justify_start);

                if (m_characters.empty() || m_center_justify_start != 0)
                {
                    // at least some of the text is left-justified - anchor to left
                    m_anchor_pos    = 0.0f;
                    m_anchor_target = 0.0f;
                    if ((layout.width() > m_width) && (m_characters.size() > m_center_justify_start))
                    {
                        // at least some text is not left-justified
                        if (m_right_justify_start == m_center_justify_start)
                        {
                            // all text that isn't left-justified is right-justified
                            float right_offset = layout.width() - m_width;
                            for (size_t i = m_right_justify_start; m_characters.size() > i; ++i)
                            {
                                m_characters[i] = new positioned_char()
                                {
                                    character = m_characters[i].character, style = m_characters[i].style, source = m_characters[i].source, xoffset = m_characters[i].xoffset + right_offset, xwidth = m_characters[i].xwidth
                                }
                            }
                            ;                                                                                                                                                                                                                                          //m_characters[i].xoffset += right_offset;

                            m_width = layout.width();
                        }
                        else if (m_characters.size() <= m_right_justify_start)
                        {
                            // all text that isn't left-justified is center-justified
                            float center_width  = m_width - m_characters[m_center_justify_start].xoffset;
                            float center_offset = ((layout.width() - center_width) * 0.5f) - m_characters[m_center_justify_start].xoffset;
                            if (0.0f < center_offset)
                            {
                                for (size_t i = m_center_justify_start; m_characters.size() > i; ++i)
                                {
                                    m_characters[i] = new positioned_char()
                                    {
                                        character = m_characters[i].character, style = m_characters[i].style, source = m_characters[i].source, xoffset = m_characters[i].xoffset + center_offset, xwidth = m_characters[i].xwidth
                                    }
                                }
                                ;                                                                                                                                                                                                                                           //m_characters[i].xoffset += center_offset;

                                m_width += center_offset;
                            }
                        }
                        else
                        {
                            // left, right and center-justified parts
                            float center_width  = m_characters[m_right_justify_start].xoffset - m_characters[m_center_justify_start].xoffset;
                            float center_offset = ((layout.width() - center_width) * 0.5f) - m_characters[m_center_justify_start].xoffset;
                            float right_offset  = layout.width() - m_width;
                            if (center_offset > right_offset)
                            {
                                // right-justified text pushes centre-justified text to the left
                                for (size_t i = m_center_justify_start; m_right_justify_start > i; ++i)
                                {
                                    m_characters[i] = new positioned_char()
                                    {
                                        character = m_characters[i].character, style = m_characters[i].style, source = m_characters[i].source, xoffset = m_characters[i].xoffset + right_offset, xwidth = m_characters[i].xwidth
                                    }
                                }
                                ;                                                                                                                                                                                                                                          //m_characters[i].xoffset += right_offset;
                            }
                            else if (0.0f < center_offset)
                            {
                                // left-justified text doesn't push centre-justified text to the right
                                for (size_t i = m_center_justify_start; m_right_justify_start > i; ++i)
                                {
                                    m_characters[i] = new positioned_char()
                                    {
                                        character = m_characters[i].character, style = m_characters[i].style, source = m_characters[i].source, xoffset = m_characters[i].xoffset + center_offset, xwidth = m_characters[i].xwidth
                                    }
                                }
                                ;                                                                                                                                                                                                                                           //m_characters[i].xoffset += center_offset;
                            }

                            for (size_t i = m_right_justify_start; m_characters.size() > i; ++i)
                            {
                                m_characters[i] = new positioned_char()
                                {
                                    character = m_characters[i].character, style = m_characters[i].style, source = m_characters[i].source, xoffset = m_characters[i].xoffset + right_offset, xwidth = m_characters[i].xwidth
                                }
                            }
                            ;                                                                                                                                                                                                                                          //m_characters[i].xoffset += right_offset;

                            m_width = layout.width();
                        }
                    }
                }
                else if (m_characters.size() <= m_right_justify_start)
                {
                    // all text is center-justified - anchor to center
                    m_anchor_pos    = 0.5f;
                    m_anchor_target = 0.5f;
                }
                else
                {
                    // at least some text is right-justified - anchor to right
                    m_anchor_pos    = 1.0f;
                    m_anchor_target = 1.0f;
                    if ((layout.width() > m_width) && (m_right_justify_start > m_center_justify_start))
                    {
                        // mixed center-justified and right-justified text
                        float center_width  = m_characters[m_right_justify_start].xoffset;
                        float center_offset = (layout.width() - m_width + (center_width * 0.5f)) - (layout.width() * 0.5f);
                        if (0.0f < center_offset)
                        {
                            for (size_t i = m_right_justify_start; m_characters.size() > i; ++i)
                            {
                                m_characters[i] = new positioned_char()
                                {
                                    character = m_characters[i].character, style = m_characters[i].style, source = m_characters[i].source, xoffset = m_characters[i].xoffset + center_offset, xwidth = m_characters[i].xwidth
                                }
                            }
                            ;                                                                                                                                                                                                                                           //m_characters[i].xoffset += center_offset;

                            m_width += center_offset;
                        }
                    }
                }
            }