Example #1
0
 public LNLabel(string text, LNLabel.LabelType type, LFont spriteFont)
     : base()
 {
     this._spriteFont = spriteFont;
     this._type       = type;
     SetString(text);
     this.SetNodeSize(_spriteFont.StringWidth(text), _spriteFont.GetHeight());
 }
Example #2
0
 public static LImage CreateFontImage(LFont font, LColor color, string text)
 {
     LImage image = LImage.CreateImage(font.StringWidth(text), font.GetHeight());
     LGraphics g = image.GetLGraphics();
     g.SetFont(font);
     g.DrawString(text, 0, 0, color);
     g.Dispose();
     return image;
 }
Example #3
0
        public static LImage CreateFontImage(LFont font, LColor color, string text)
        {
            LImage    image = LImage.CreateImage(font.StringWidth(text), font.GetHeight());
            LGraphics g     = image.GetLGraphics();

            g.SetFont(font);
            g.DrawString(text, 0, 0, color);
            g.Dispose();
            return(image);
        }
Example #4
0
        private void DrawMessage(GLEx gl, LColor old)
        {
            if (!visible)
            {
                return;
            }
            if (!running)
            {
                return;
            }
            if (batch == null)
            {
                return;
            }
            if (strings.GetSize() > 25)
            {
                lock (showMessages)
                {
                    this.size = showMessages.Length;

                    this.fontSize = (isEnglish) ? strings.GetSize() / 2 : gl.GetFont()
                                    .GetSize();
                    this.fontHeight = strings.GetHeight();
                    this.tmp_left   = (isLeft) ? 0 : (width - (fontSize * messageLength))
                                      / 2 - (int)(fontSize * 1.5f);
                    this.left           = tmp_left;
                    this.index          = offset = font = tmp_font = 0;
                    this.fontSizeDouble = fontSize * 2;

                    batch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, gl.View);

                    fontColor = old;

                    for (int i = 0; i < size; i++)
                    {
                        text = showMessages[i];
                        if (text == '\0')
                        {
                            continue;
                        }

                        if (interceptCount < interceptMaxString)
                        {
                            interceptCount++;
                            continue;
                        }
                        else
                        {
                            interceptMaxString = 0;
                            interceptCount     = 0;
                        }
                        if (showMessages[i] == 'n' &&
                            showMessages[(i > 0) ? i - 1 : 0] == '\\')
                        {
                            index = 0;
                            left  = tmp_left;
                            offset++;
                            continue;
                        }
                        else if (text == '\n')
                        {
                            index = 0;
                            left  = tmp_left;
                            offset++;
                            continue;
                        }
                        else if (text == '<')
                        {
                            LColor color = GetColor(showMessages[(i < size - 1) ? i + 1
                                    : i]);
                            if (color != null)
                            {
                                interceptMaxString = 1;
                                fontColor          = color;
                            }
                            continue;
                        }
                        else if (showMessages[(i > 0) ? i - 1 : i] == '<' &&
                                 GetColor(text) != null)
                        {
                            continue;
                        }
                        else if (text == '/')
                        {
                            if (showMessages[(i < size - 1) ? i + 1 : i] == '>')
                            {
                                interceptMaxString = 1;
                                fontColor          = old;
                            }
                            continue;
                        }
                        else if (index > messageLength)
                        {
                            index = 0;
                            left  = tmp_left;
                            offset++;
                            newLine = false;
                        }
                        else if (text == '\\')
                        {
                            continue;
                        }
                        tmp_font = strings.CharWidth(text);
                        if (System.Char.IsLetter(text))
                        {
                            if (tmp_font < fontSize)
                            {
                                font = fontSize;
                            }
                            else
                            {
                                font = tmp_font;
                            }
                        }
                        else
                        {
                            font = fontSize;
                        }
                        left += font;
                        if (font <= 10 && StringUtils.IsSingle(text))
                        {
                            left += 12;
                        }
                        if (i != size - 1)
                        {
                            pos.X = vector.x + left + leftOffset;
                            pos.Y = (offset * fontHeight) + vector.y + fontSizeDouble
                                    + topOffset;
                            batch.DrawString(strings.Font, Convert.ToString(text), pos, fontColor.Color);
                        }
                        else if (!newLine)
                        {
                            pos.X = vector.x + left + leftOffset + iconWidth;
                            pos.Y = (offset * fontHeight) + vector.y + fontSize
                                    + topOffset + strings.GetAscent();
                            batch.Draw(creeseIcon.Texture, pos, Microsoft.Xna.Framework.Color.White);
                        }
                        index++;
                    }

                    batch.End();

                    if (messageCount == next)
                    {
                        onComplete = true;
                    }
                }
            }
            else
            {
                lock (showMessages)
                {
                    this.size = showMessages.Length;

                    this.fontSize = (isEnglish) ? ((int)(strings.GetSize() * 1.4f)) / 2 : (int)(gl.GetFont()
                                                                                                .GetSize() * 1.4f);
                    this.fontHeight = strings.GetHeight() + 10;
                    this.tmp_left   = isLeft ? 0 : (int)(((width - (fontSize * messageLength))
                                                          / 2 + (int)(fontSize * 4)));
                    this.left           = tmp_left;
                    this.index          = offset = font = tmp_font = 0;
                    this.fontSizeDouble = (int)(fontSize * 2 * 1.2f);

                    batch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

                    fontColor = old;

                    for (int i = 0; i < size; i++)
                    {
                        text = showMessages[i];

                        if (text == '\0')
                        {
                            continue;
                        }

                        if (interceptCount < interceptMaxString)
                        {
                            interceptCount++;
                            continue;
                        }
                        else
                        {
                            interceptMaxString = 0;
                            interceptCount     = 0;
                        }
                        if (showMessages[i] == 'n' &&
                            showMessages[(i > 0) ? i - 1 : 0] == '\\')
                        {
                            index = 0;
                            left  = tmp_left;
                            offset++;
                            continue;
                        }
                        else if (text == '\n')
                        {
                            index = 0;
                            left  = tmp_left;
                            offset++;
                            continue;
                        }
                        else if (text == '<')
                        {
                            LColor color = GetColor(showMessages[(i < size - 1) ? i + 1
                                    : i]);
                            if (color != null)
                            {
                                interceptMaxString = 1;
                                fontColor          = color;
                            }
                            continue;
                        }
                        else if (showMessages[(i > 0) ? i - 1 : i] == '<' &&
                                 GetColor(text) != null)
                        {
                            continue;
                        }
                        else if (text == '/')
                        {
                            if (showMessages[(i < size - 1) ? i + 1 : i] == '>')
                            {
                                interceptMaxString = 1;
                                fontColor          = old;
                            }
                            continue;
                        }
                        else if (index > messageLength)
                        {
                            index = 0;
                            left  = tmp_left;
                            offset++;
                            newLine = false;
                        }
                        else if (text == '\\')
                        {
                            continue;
                        }
                        tmp_font = strings.CharWidth(text);
                        font     = tmp_font;
                        if (System.Char.IsLetter(text))
                        {
                            if (tmp_font < fontSize)
                            {
                                font = fontSize;
                            }
                            else
                            {
                                font = tmp_font;
                            }
                        }
                        else
                        {
                            font = fontSize;
                        }
                        left += font;
                        if (font <= 10 && StringUtils.IsSingle(text))
                        {
                            left += 12;
                        }
                        if (i != size - 1)
                        {
                            pos.X = vector.x + left + leftOffset;
                            pos.Y = ((offset * fontHeight) + vector.y + fontSizeDouble
                                     + topOffset + strings.GetAscent() * 2.2f);
                            batch.DrawString(strings.Font, Convert.ToString(text), pos, fontColor.Color);
                        }
                        else if (!newLine)
                        {
                            pos.X = vector.x + left + leftOffset + iconWidth;
                            pos.Y = (offset * fontHeight) + vector.y + fontSize
                                    + topOffset + (strings.GetAscent() * 2.2f) + iconWidth;
                            batch.Draw(creeseIcon.Texture, pos, Microsoft.Xna.Framework.Color.White);
                        }
                        index++;
                    }

                    batch.End();

                    if (messageCount == next)
                    {
                        onComplete = true;
                    }
                }
            }
        }
Example #5
0
        private void DrawString(float x, float y, float sx, float sy, float ax,
                                float ay, float rotation, string chars, LColor c, int startIndex,
                                int endIndex)
        {
            if (displays.Count > LSystem.DEFAULT_MAX_CACHE_SIZE)
            {
                lock (displays)
                {
                    foreach (Loon.Core.Graphics.Opengl.LTextureBatch.GLCache cache in displays.Values)
                    {
                        if (cache != null)
                        {
                            cache.Dispose();
                        }
                    }
                }
                displays.Clear();
            }

            this.intObject   = null;
            this.charCurrent = 0;
            this.totalWidth  = 0;
            if (rotation != 0 && (ax == 0 && ay == 0))
            {
                ax = font.StringWidth(chars) / 2;
                ay = font.GetHeight();
            }
            if (useCache)
            {
                display = (Loon.Core.Graphics.Opengl.LTextureBatch.GLCache)CollectionUtils.Get(displays, chars);
                if (display == null)
                {
                    fontBatch.GLBegin();
                    char[] charList = chars.ToCharArray();
                    for (int i = 0; i < charList.Length; i++)
                    {
                        charCurrent = charList[i];
                        if (charCurrent < totalCharSet)
                        {
                            intObject = charArray[charCurrent];
                        }
                        else
                        {
                            intObject = (IntObject)CollectionUtils.Get(customChars,
                                                                       (char)charCurrent);
                        }

                        if (intObject != null)
                        {
                            if ((i >= startIndex) || (i <= endIndex))
                            {
                                if (antiAlias)
                                {
                                    fontBatch.DrawQuad(totalWidth * fontScale, 0,
                                                       (totalWidth + intObject.width) * fontScale,
                                                       (intObject.height * fontScale), intObject.storedX,
                                                       intObject.storedY, intObject.storedX
                                                       + intObject.width,
                                                       intObject.storedY + intObject.height);
                                }
                                else
                                {
                                    fontBatch.DrawQuad(totalWidth, 0,
                                                       (totalWidth + intObject.width),
                                                       intObject.height, intObject.storedX,
                                                       intObject.storedY, intObject.storedX
                                                       + intObject.width,
                                                       intObject.storedY + intObject.height);
                                }
                            }
                            totalWidth += intObject.width;
                        }
                    }
                    fontBatch.CommitQuad(c, x, y, sx, sy, ax, ay, rotation);
                    CollectionUtils.Put(displays, chars, display = fontBatch.NewGLCache());
                }
                else if (display != null && fontBatch != null &&
                         fontBatch.GetTexture() != null)
                {
                    LTextureBatch.CommitQuad(fontBatch.GetTexture(), display, c, x,
                                             y, sx, sy, ax, ay, rotation);
                }
            }
            else
            {
                fontBatch.GLBegin();
                char[] charList = chars.ToCharArray();
                for (int i = 0; i < charList.Length; i++)
                {
                    charCurrent = charList[i];
                    if (charCurrent < totalCharSet)
                    {
                        intObject = charArray[charCurrent];
                    }
                    else
                    {
                        intObject = (IntObject)CollectionUtils.Get(customChars,
                                                                   (char)charCurrent);
                    }
                    if (intObject != null)
                    {
                        if ((i >= startIndex) || (i <= endIndex))
                        {
                            if (antiAlias)
                            {
                                fontBatch.DrawQuad(totalWidth * fontScale, 0,
                                                   (totalWidth + intObject.width) * fontScale,
                                                   (intObject.height * fontScale), intObject.storedX,
                                                   intObject.storedY, intObject.storedX
                                                   + intObject.width, intObject.storedY
                                                   + intObject.height);
                            }
                            else
                            {
                                fontBatch.DrawQuad(totalWidth, 0,
                                                   (totalWidth + intObject.width),
                                                   intObject.height, intObject.storedX,
                                                   intObject.storedY, intObject.storedX
                                                   + intObject.width, intObject.storedY
                                                   + intObject.height);
                            }
                        }
                        totalWidth += intObject.width;
                    }
                }
                fontBatch.CommitQuad(c, x, y, sx, sy, ax, ay, rotation);
            }
        }
Example #6
0
        private void Make(LFont font, char[] customCharsArray)
        {
            if (charArray == null)
            {
                charArray = new IntObject[totalCharSet];
            }
            if (customCharsArray != null && customCharsArray.Length > totalCharSet)
            {
                textureWidth *= 2;
            }
            try
            {
                LImage    imgTemp = LImage.CreateImage(textureWidth, textureHeight, true);
                LGraphics g       = imgTemp.GetLGraphics();
                g.SetFont(font);
                int rowHeight         = 0;
                int positionX         = 0;
                int positionY         = 0;
                int customCharsLength = (customCharsArray != null) ? customCharsArray.Length
                        : 0;
                this.totalCharSet = customCharsLength == 0 ? totalCharSet : 0;
                StringBuilder sbr = new StringBuilder(totalCharSet);
                for (int i = 0; i < totalCharSet + customCharsLength; i++)
                {
                    char ch = (i < totalCharSet) ? (char)i : customCharsArray[i
                                                                              - totalCharSet];

                    int charwidth = font.CharWidth(ch);
                    if (charwidth <= 0)
                    {
                        charwidth = 1;
                    }
                    int charheight = font.GetHeight();
                    if (charheight <= 0)
                    {
                        charheight = font.GetSize();
                    }

                    IntObject newIntObject = new IntObject();

                    newIntObject.width  = charwidth;
                    newIntObject.height = charheight;

                    if (positionX + newIntObject.width >= textureWidth)
                    {
                        g.DrawString(sbr.ToString(), 0, positionY);
                        sbr.Clear();
                        positionX  = 0;
                        positionY += rowHeight;
                        rowHeight  = 0;
                    }

                    newIntObject.storedX = positionX;
                    newIntObject.storedY = positionY;

                    if (newIntObject.height > fontHeight)
                    {
                        fontHeight = newIntObject.height;
                    }

                    if (newIntObject.height > rowHeight)
                    {
                        rowHeight = newIntObject.height;
                    }

                    sbr.Append(ch);

                    positionX += newIntObject.width;

                    if (i < totalCharSet)
                    {
                        charArray[i] = newIntObject;
                    }
                    else
                    {
                        CollectionUtils.Put(customChars, ch, newIntObject);
                    }
                }
                if (sbr.Length > 0)
                {
                    g.DrawString(sbr.ToString(), 0, positionY);
                    sbr = null;
                }
                g.Dispose();
                g = null;

                fontBatch = new LTextureBatch(imgTemp.GetTexture());
            }
            catch (Exception ex)
            {
                Loon.Utils.Debugging.Log.Exception(ex);
            }
        }
Example #7
0
        private void Make(LFont font, char[] customCharsArray)
        {
            if (charArray == null)
            {
                charArray = new IntObject[totalCharSet];
            }
            if (customCharsArray != null && customCharsArray.Length > totalCharSet)
            {
                textureWidth *= 2;
            }
            try
            {
                LImage imgTemp = LImage.CreateImage(textureWidth, textureHeight, true);
                LGraphics g = imgTemp.GetLGraphics();
                g.SetFont(font);
                int rowHeight = 0;
                int positionX = 0;
                int positionY = 0;
                int customCharsLength = (customCharsArray != null) ? customCharsArray.Length
                        : 0;
                this.totalCharSet = customCharsLength == 0 ? totalCharSet : 0;
                StringBuilder sbr = new StringBuilder(totalCharSet);
                for (int i = 0; i < totalCharSet + customCharsLength; i++)
                {
                    char ch = (i < totalCharSet) ? (char)i : customCharsArray[i
                            - totalCharSet];

                    int charwidth = font.CharWidth(ch);
                    if (charwidth <= 0)
                    {
                        charwidth = 1;
                    }
                    int charheight = font.GetHeight();
                    if (charheight <= 0)
                    {
                        charheight = font.GetSize();
                    }

                    IntObject newIntObject = new IntObject();

                    newIntObject.width = charwidth;
                    newIntObject.height = charheight;

                    if (positionX + newIntObject.width >= textureWidth)
                    {
                        g.DrawString(sbr.ToString(), 0, positionY);
                        sbr.Clear();
                        positionX = 0;
                        positionY += rowHeight;
                        rowHeight = 0;
                    }

                    newIntObject.storedX = positionX;
                    newIntObject.storedY = positionY;

                    if (newIntObject.height > fontHeight)
                    {
                        fontHeight = newIntObject.height;

                    }

                    if (newIntObject.height > rowHeight)
                    {
                        rowHeight = newIntObject.height;
                    }

                    sbr.Append(ch);

                    positionX += newIntObject.width;

                    if (i < totalCharSet)
                    {
                        charArray[i] = newIntObject;

                    }
                    else
                    {

                        CollectionUtils.Put(customChars, ch, newIntObject);
                    }

                }
                if (sbr.Length > 0)
                {
                    g.DrawString(sbr.ToString(), 0, positionY);
                    sbr = null;
                }
                g.Dispose();
                g = null;

                fontBatch = new LTextureBatch(imgTemp.GetTexture());

            }
            catch (Exception ex)
            {
                Loon.Utils.Debug.Log.Exception(ex);
            }
        }
Example #8
0
        protected override void CreateCustomUI(GLEx g, int x, int y, int w, int h)
        {
            if (!visible)
            {
                return;
            }
            if (batch == null)
            {
                return;
            }
            sizeFont = messageFont.GetSize();
            if (sizeFont > 25)
            {
                sizeFont       = messageFont.GetSize();
                doubleSizeFont = sizeFont * 2;
                if (doubleSizeFont == 0)
                {
                    doubleSizeFont = 20;
                }
                messageLeft = (x + doubleSizeFont + sizeFont / 2) + tmpOffset + left
                              + doubleSizeFont;

                batch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, GLEx.Device.RasterizerState, null, GLEx.cemera.viewMatrix);

                if (message != null)
                {
                    messageTop = y + doubleSizeFont + top - 10;
                    batch.DrawString(messageFont.Font, message, new Vector2(messageLeft, messageTop), fontColor.Color);
                }
                else
                {
                    messageTop = y + top;
                }
                nTop = messageTop;
                if (selects != null)
                {
                    nLeft = messageLeft - sizeFont / 4;

                    for (int i = 0; i < selects.Length; i++)
                    {
                        nTop    += messageFont.GetHeight();
                        type     = i + 1;
                        isSelect = (type == ((selectFlag > 0) ? selectFlag : 1));
                        if ((buoyage != null) && isSelect)
                        {
                            g.SetAlpha(autoAlpha);
                            g.DrawTexture(buoyage, nLeft,
                                          nTop - (int)(buoyage.GetHeight() / 1.5f));
                            g.SetAlpha(1.0F);
                        }
                        batch.DrawString(messageFont.Font, selects[i], new Vector2(messageLeft, nTop), fontColor.Color);
                        if ((cursor != null) && isSelect)
                        {
                            batch.Draw(cursor.Texture, new Vector2(nLeft, nTop - cursor.GetHeight() / 4), Color.White);
                        }
                    }
                    batch.End();
                }
            }
            else
            {
                doubleSizeFont = (int)(sizeFont * 1.4f * 2);
                if (doubleSizeFont == 0)
                {
                    doubleSizeFont = 20;
                }
                messageLeft = (x + doubleSizeFont + sizeFont / 2) + tmpOffset + left
                              + doubleSizeFont;
                batch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

                if (message != null)
                {
                    messageTop = y + doubleSizeFont + top + (int)(messageFont.GetAscent() * 2) + 10;
                    batch.DrawString(messageFont.Font, message, new Vector2(messageLeft, messageTop), fontColor.Color);
                }
                else
                {
                    messageTop = y + top + (int)(messageFont.GetAscent() * 2) + 10;
                }
                nTop = messageTop;
                if (selects != null)
                {
                    nLeft = messageLeft - sizeFont / 4;

                    for (int i = 0; i < selects.Length; i++)
                    {
                        nTop    += (int)((messageFont.GetHeight() + messageFont.GetAscent()) * 1.2f);
                        type     = i + 1;
                        isSelect = (type == ((selectFlag > 0) ? selectFlag : 1));
                        if ((buoyage != null) && isSelect)
                        {
                            g.SetAlpha(autoAlpha);
                            g.DrawTexture(buoyage, nLeft,
                                          nTop - (int)(buoyage.GetHeight() / 1.5f));
                            g.SetAlpha(1.0F);
                        }
                        batch.DrawString(messageFont.Font, selects[i], new Vector2(messageLeft, nTop), fontColor.Color);
                        if ((cursor != null) && isSelect)
                        {
                            batch.Draw(cursor.Texture, new Vector2(nLeft, (nTop - cursor.GetHeight() / 4)), Color.White);
                        }
                    }
                    batch.End();
                }
            }
        }