Exemplo n.º 1
0
        float getTextWidth(string text)
        {
            mCursorPositions.Clear();
            // Store first cursor position
            mCursorPositions.Add(0);

            if (string.Empty.Equals(text))
            {
                return(0.0f);
            }

            FontManager fm    = FontManager.Singleton;
            FontPtr     f     = (FontPtr)fm.GetByName(mFont);
            float       width = 0.0f;

            for (int index = 0; index < text.Length; ++index)
            {
                if (text[index] == ' ')
                {
                    width += (f.GetGlyphAspectRatio('0') * mPixelDimensions.w);
                }
                else
                {
                    width += (f.GetGlyphAspectRatio(text[index]) * mPixelDimensions.w);
                }
                mCursorPositions.Add((int)width);
            }

            // now we know the text width in pixels, and have index positions at the start/end of each character.

            return(width);
        }
Exemplo n.º 2
0
        protected override List <PositionedMessage> buildMessages()
        {
            float y = 2 * GetTextVSpacing();
            List <PositionedMessage> ret = new List <PositionedMessage>();

            ret.Add(
                new PositionedMessage(20, y, Viewport.ActualWidth / 2, GetTextVSpacing(),
                                      LanguageResources.GetString(LanguageKey.LanguageDebugMode)));

            //  y += GetTextVSpacing();
            ret.Add(
                new PositionedMessage(20, y, Viewport.ActualWidth / 2, GetTextVSpacing(),
                                      LanguageResources.GetString(LanguageKey.LanguageID)));


            /* y += GetTextVSpacing();
             * ret.Add(
             * new PositionedMessage(20, y, Viewport.ActualWidth / 2, GetTextVSpacing(),
             *                    LanguageResources.GetString(LanguageKey.LanguageID)));*/

            FontPtr font = (FontPtr)Mogre.FontManager.Singleton.GetByName(FontManager.CurrentFont);

            //  y += GetTextVSpacing();
            ret.Add(
                new PositionedMessage(20, y, Viewport.ActualWidth / 2, GetTextVSpacing(),
                                      font.Name));

            ret.Add(new PositionedMessage(20, GetTextVSpacing(), Viewport.ActualWidth / 2, GetTextVSpacing(), String.Format(LanguageResources.GetString(LanguageKey.TranslationCompleteness), translatedStrings, totalStrings), ColourValue.Green, ColourValue.Green));
            ret.Add(new PositionedMessage(20, GetTextVSpacing(), Viewport.ActualWidth / 2, GetTextVSpacing(), ""));
            //     font.g

            foreach (string s in names)
            {
                if ("!!!".Equals(s))
                {
                    ret.Add(new PositionedMessage(20, GetTextVSpacing(), Viewport.ActualWidth / 2, GetTextVSpacing(), s, ColourValue.Red, ColourValue.Red));
                }
                else
                {
                    ret.Add(new PositionedMessage(20, GetTextVSpacing(), Viewport.ActualWidth / 2, GetTextVSpacing(), s));
                }
            }

            return(ret);
        }
Exemplo n.º 3
0
        public float GetTextWidth()
        {
            FontPtr font      = FontManager.Singleton.GetByName(TextArea.FontName);
            float   textWidth = 0;

            for (int i = 0; i < TextArea.Caption.Length; i++)
            {
                if (TextArea.Caption[i] == 32)
                {
                    textWidth += 0.5f;
                }
                else
                {
                    textWidth += font.GetGlyphAspectRatio(TextArea.Caption[i]);
                }
            }

            return((float)textWidth * (float)TextArea.CharHeight / (float)Engine.Singleton.Camera.AspectRatio);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets text box content. Most of this method is for wordwrap.
        /// </summary>
        /// <param name="text"></param>
        public void setText(string text)
        {
            originalText = text;
            lines.Clear();

            //Mogre.Font font = (Mogre.Font)Mogre.FontManager.Singleton.getByName(mTextArea.FontName).getPointer();
            FontPtr font = null;

            if (FontManager.Singleton.ResourceExists(textArea.FontName))
            {
                font = (FontPtr)FontManager.Singleton.GetByName(textArea.FontName);
                if (!font.IsLoaded)
                {
                    font.Load();
                }
            }
            else
            {
                OGRE_EXCEPT("this font:", textArea.FontName, "is not exist");
            }

            string current       = DisplayStringToString(text);
            bool   firstWord     = true;
            int    lastSpace     = 0;
            int    lineBegin     = 0;
            float  lineWidth     = 0;
            float  rightBoundary = element.Width - 2 * contentPadding + scrollTrack.Left + 10f;

            for (int i = 0; i < current.Length; i++)
            {
                if (current[i] == ' ')
                {
                    if (textArea.SpaceWidth != 0)
                    {
                        lineWidth += textArea.SpaceWidth;
                    }
                    else
                    {
                        lineWidth += font.GetGlyphAspectRatio(' ') * textArea.CharHeight;
                    }
                    firstWord = false;
                    lastSpace = i;
                }
                else if (current[i] == '\n')
                {
                    firstWord = true;
                    lineWidth = 0;
                    lines.Add(current.Substring(lineBegin, i - lineBegin));
                    lineBegin = i + 1;
                }
                else
                {
                    // use glyph information to calculate line width
                    lineWidth += font.GetGlyphAspectRatio(current[i]) * textArea.CharHeight;
                    if (lineWidth > rightBoundary)
                    {
                        if (firstWord)
                        {
                            current.Insert(i, "\n");
                            i = i - 1;
                        }
                        else
                        {
                            //current[lastSpace] = '\n';
                            //i = lastSpace - 1;

                            char[] str = current.ToCharArray();
                            str[lastSpace] = '\n';
                            current        = new string(str).ToString();
                            i = lastSpace - 1;
                        }
                    }
                }
            }

            lines.Add(current.Substring(lineBegin));

            uint maxLines = getHeightInLines();

            if (lines.Count > maxLines)             // if too much text, filter based on scroll percentage
            {
                scrollHandle.Show();
                filterLines();
            }
            else             // otherwise just show all the text
            {
                textArea.Caption = (current);
                scrollHandle.Hide();
                scrollPercentage = 0f;
                scrollHandle.Top = (0f);
            }
        }