Exemple #1
0
        public override string ToString()
        {
            string text = string.Empty;

            if (Ctrl)
            {
                text += "Ctrl";
            }
            if (Alt)
            {
                text += string.IsNullOrEmpty(text) ? "Alt" : " + Alt";
            }
            if (Shift)
            {
                text += string.IsNullOrEmpty(text) ? "Shift" : " + Shift";
            }
            if (Win)
            {
                text += string.IsNullOrEmpty(text) ? "Win" : " + Win";
            }
            if (!string.IsNullOrEmpty(CharKey.ToString()))
            {
                text += string.IsNullOrEmpty(text) ? CharKey.ToString() : " + " + CharKey;
            }

            return(text);
        }
Exemple #2
0
        public override string ToString()
        {
            string text = string.Empty;

            if (Ctrl)
            {
                text += "Ctrl + ";
            }
            if (Alt)
            {
                text += "Alt + ";
            }
            if (Shift)
            {
                text += "Shift + ";
            }
            if (Win)
            {
                text += "Win + ";
            }

            if (CharKey != Key.None)
            {
                text += specialSymbolDictionary.ContainsKey(CharKey)
                    ? specialSymbolDictionary[CharKey]
                    : CharKey.ToString();
            }
            else if (!string.IsNullOrEmpty(text))
            {
                text = text.Remove(text.Length - 3);
            }

            return(text);
        }
Exemple #3
0
        public float PrintChar(float lineHeight, float x, float y, char c, FontStyle style)
        {
            Initialize();
            if (!_isInitialized) return 0;

            GL.Begin(PrimitiveType.Quads);

            var charKey = new CharKey(c, style);
            var e = GetCharEntry(charKey);

            if (!char.IsWhiteSpace(c))
            {
                GL.TexCoord2(e.TextureX, e.TextureY);
                GL.Vertex2(x - e.BoxLeft * lineHeight, y);

                GL.TexCoord2(e.TextureX, e.TextureY + e.TextureHeight);
                GL.Vertex2(x - e.BoxLeft * lineHeight, y + lineHeight);

                GL.TexCoord2(e.TextureX + e.TextureWidth, e.TextureY + e.TextureHeight);
                GL.Vertex2(x + e.BoxRight * lineHeight, y + lineHeight);

                GL.TexCoord2(e.TextureX + e.TextureWidth, e.TextureY);
                GL.Vertex2(x + e.BoxRight * lineHeight, y);

                GL.End();
            }

            return e.InnerWidth * lineHeight;
        }
Exemple #4
0
        public float PrintChar(float lineHeight, float x, float y, char c, FontStyle style)
        {
            Initialize();
            if (!_isInitialized)
            {
                return(0);
            }

            GL.Begin(PrimitiveType.Quads);

            var charKey = new CharKey(c, style);
            var e       = GetCharEntry(charKey);

            if (!char.IsWhiteSpace(c))
            {
                GL.TexCoord2(e.TextureX, e.TextureY);
                GL.Vertex2(x - e.BoxLeft * lineHeight, y);

                GL.TexCoord2(e.TextureX, e.TextureY + e.TextureHeight);
                GL.Vertex2(x - e.BoxLeft * lineHeight, y + lineHeight);

                GL.TexCoord2(e.TextureX + e.TextureWidth, e.TextureY + e.TextureHeight);
                GL.Vertex2(x + e.BoxRight * lineHeight, y + lineHeight);

                GL.TexCoord2(e.TextureX + e.TextureWidth, e.TextureY);
                GL.Vertex2(x + e.BoxRight * lineHeight, y);

                GL.End();
            }

            return(e.InnerWidth * lineHeight);
        }
Exemple #5
0
        private CharEntry GetCharEntry(CharKey c)
        {
            CharEntry e;

            if (!_charEntries.TryGetValue(c, out e))
            {
                e = _charEntries[new CharKey('?', c.Style)];
            }

            return(e);
        }
Exemple #6
0
        private bool InitializeChar(System.Drawing.Graphics graphics, int bitmapWidth, int bitmapHeight, System.Drawing.Font font, int fontSize, float xWidth, float xHeight, char c, FontStyle style, ref float currentX, ref float currentY)
        {
            var    charKey = new CharKey(c, style);
            string s       = new string(c, 1);

            if (char.IsWhiteSpace(c))
            {
                _charEntries[charKey] = new CharEntry {
                    TextureWidth = graphics.MeasureString("X" + s + "X", font).Width - graphics.MeasureString("xx", font).Width
                };
                return(true);
            }

            RectangleF charRectangle = MeasureRectangle(graphics, fontSize, font, s);
            float      charWidth = charRectangle.Width, charHeight = charRectangle.Height;

            if (currentX + charWidth + xWidth > bitmapWidth)
            {
                currentX  = 0;
                currentY += xHeight;

                if (currentY + xHeight > bitmapHeight)
                {
                    // We have run out of space in our image for further characters. This means we need a larger image texture --
                    // though on the other hand, we can't properly handle most Unicode characters anyway, so the whole approach
                    // might need rethinking.
                    return(false);
                }
            }

            graphics.DrawString(s, font, Brushes.White, currentX + 0.5f * xWidth - charRectangle.Left, currentY);

            float measuredCharWidth = graphics.MeasureString("X" + s + "X", font).Width - graphics.MeasureString("XX", font).Width;

            _charEntries[charKey] = new CharEntry
            {
                TextureX      = currentX / bitmapWidth,
                TextureY      = currentY / bitmapHeight,
                TextureWidth  = (charWidth + xWidth) / bitmapWidth,
                TextureHeight = charHeight / bitmapHeight,

                BoxLeft    = 0.5f * xWidth / xHeight,
                BoxRight   = (charWidth + 0.5f * xWidth) / xHeight,
                InnerWidth = measuredCharWidth / xHeight,
            };

            currentX += charWidth + xWidth;
            return(true);
        }
Exemple #7
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            if (Ctrl)
            {
                sb.Append("Ctrl + ");
            }
            if (Shift)
            {
                sb.Append("Shift + ");
            }
            if (Alt)
            {
                sb.Append("Alt + ");
            }
            if (Win)
            {
                sb.Append("Win + ");
            }
            if (CharKey != Key.None)
            {
                if (CharKey == Key.Space)
                {
                    sb.Append("Space");
                }
                else
                {
                    sb.Append(CharKey.ToString());
                }
            }
            else
            {
                sb.Remove(sb.Length - 3, 3);
            }
            return(sb.ToString());
        }
Exemple #8
0
        private bool InitializeChar(System.Drawing.Graphics graphics, int bitmapWidth, int bitmapHeight, System.Drawing.Font font, int fontSize, float xWidth, float xHeight, char c, FontStyle style, ref float currentX, ref float currentY)
        {
            var charKey = new CharKey(c, style);
            string s = new string(c, 1);

            if (char.IsWhiteSpace(c))
            {
                _charEntries[charKey] = new CharEntry { TextureWidth = graphics.MeasureString("X" + s + "X", font).Width - graphics.MeasureString("xx", font).Width };
                return true;
            }

            RectangleF charRectangle = MeasureRectangle(graphics, fontSize, font, s);
            float charWidth = charRectangle.Width, charHeight = charRectangle.Height;

            if (currentX + charWidth + xWidth > bitmapWidth)
            {
                currentX = 0;
                currentY += xHeight;

                if (currentY + xHeight > bitmapHeight)
                {
                    // We have run out of space in our image for further characters. This means we need a larger image texture --
                    // though on the other hand, we can't properly handle most Unicode characters anyway, so the whole approach
                    // might need rethinking.
                    return false;
                }
            }

            graphics.DrawString(s, font, Brushes.White, currentX + 0.5f * xWidth - charRectangle.Left, currentY);

            float measuredCharWidth = graphics.MeasureString("X" + s + "X", font).Width - graphics.MeasureString("XX", font).Width;

            _charEntries[charKey] = new CharEntry
            {
                TextureX = currentX / bitmapWidth,
                TextureY = currentY / bitmapHeight,
                TextureWidth = (charWidth + xWidth) / bitmapWidth,
                TextureHeight = charHeight / bitmapHeight,

                BoxLeft = 0.5f * xWidth / xHeight,
                BoxRight = (charWidth + 0.5f * xWidth) / xHeight,
                InnerWidth = measuredCharWidth / xHeight,
            };

            currentX += charWidth + xWidth;
            return true;
        }
Exemple #9
0
        private CharEntry GetCharEntry(CharKey c)
        {
            CharEntry e;
            if (!_charEntries.TryGetValue(c, out e))
            {
                e = _charEntries[new CharKey('?', c.Style)];
            }

            return e;
        }