Beispiel #1
0
        internal Vector2 MeasureText(int startIndex, int length, Vector2 customBounds)
        {
            float size = (TextRenderSpecific ? (float)GameBase.WindowManager.Height / 768 : 1) * TextSize;

            if (Text.Length == 0)
            {
                return(Vector2.Zero);
            }

            if (length == 0)
            {
                return(Vector2.Zero);
            }

            Vector2 bounds = (TextRenderSpecific ? GameBase.WindowManager.Ratio : 1) * customBounds;

            System.Drawing.RectangleF[] regions;
            Vector2 measure;

            NativeText.CreateText(Text, size, bounds, TextColour, Shadow, TextBold, TextItalic, TextUnderline, TextAlignment, TextAa, out measure, out regions, BackgroundColour, BorderColour, BorderWidth, true, false, fontFace, Vector4.Zero, Vector2.Zero, localTexture, startIndex, length);
            if (TextRenderSpecific)
            {
                return(measure / GameBase.WindowManager.Ratio);
            }

            return(measure * 0.625f);
        }
Beispiel #2
0
        internal System.Drawing.RectangleF[] MeasureCharacters()
        {
            float size = (TextRenderSpecific ? (float)GameBase.WindowManager.Height / 768 : 1) * TextSize;

            if (Text.Length == 0)
            {
                return(null);
            }

            Vector2 bounds = (TextRenderSpecific ? GameBase.WindowManager.Ratio : 1) * TextBounds;

            System.Drawing.RectangleF[] regions;
            Vector2 measure;

            NativeText.CreateText(Text, size, bounds, TextColour, Shadow, TextBold, TextItalic, TextUnderline, TextAlignment, TextAa, out measure, out regions, BackgroundColour, BorderColour, BorderWidth, true, true, fontFace, Vector4.Zero, Vector2.Zero, localTexture);

            if (TextRenderSpecific)
            {
                for (int i = 0; i < Text.Length; ++i)
                {
                    regions[i].X      /= GameBase.WindowManager.Ratio;
                    regions[i].Y      /= GameBase.WindowManager.Ratio;
                    regions[i].Width  /= GameBase.WindowManager.Ratio;
                    regions[i].Height /= GameBase.WindowManager.Ratio;
                }

                return(regions);
            }

            for (int i = 0; i < Text.Length; ++i)
            {
                regions[i].X      *= 0.625f;
                regions[i].Y      *= 0.625f;
                regions[i].Width  *= 0.625f;
                regions[i].Height *= 0.625f;
            }

            return(regions);
        }
Beispiel #3
0
        internal Texture2D refreshTexture()
        {
            if (localTexture != null && !localTexture.IsDisposed)
            {
                localTexture.Dispose();
            }

            renderingResolution = GameBase.WindowWidth;

            textChanged = false;

            //Console.WriteLine("Text render @ " + GameBase.Time);

            float   size   = (TextRenderSpecific ? (float)GameBase.WindowWidth / 1024 : 1) * TextSize;
            Vector2 bounds = (TextRenderSpecific ? GameBase.WindowRatio : 1) * TextBounds;

            localTexture =
                NativeText.CreateText(Text, size, bounds, TextColour, TextShadow, TextBold, TextUnderline, TextAlignment,
                                      TextAa, out lastMeasure, BackgroundColour, BorderColour, BorderWidth, false);
            UpdateTextureSize();
            UpdateTextureAlignment();
            return(localTexture);
        }
Beispiel #4
0
        internal Vector2 MeasureText(int startIndex, int length)
        {
            float   size   = (TextRenderSpecific ? (float)GameBase.WindowWidth / 1024 : 1) * TextSize;
            Vector2 bounds = (TextRenderSpecific ? GameBase.WindowRatio : 1) * TextBounds;

            if (Text.Length == 0)
            {
                return(Vector2.Zero);
            }

            Vector2 measure;

            NativeText.CreateText(Text.Substring(startIndex, length), size, bounds, TextColour, TextShadow, TextBold,
                                  TextUnderline, TextAlignment,
                                  TextAa, out measure, BackgroundColour, BorderColour, BorderWidth, true);
            if (TextRenderSpecific)
            {
                return(measure / GameBase.WindowRatio);
            }
            else
            {
                return(measure * 0.625f);
            }
        }
Beispiel #5
0
        protected virtual pTexture refreshTexture()
        {
            bool existed = false;

            pTexture old = localTexture;

            TextChanged = false;

            if (string.IsNullOrEmpty(Text) && TextBounds.X == 0)
            {
                lastMeasure = TextBounds;
                return(null);
            }

            renderingResolution = GameBase.WindowManager.Height;

            float   size   = (TextRenderSpecific ? (float)GameBase.WindowManager.Height / 768 : 1) * TextSize;
            Vector2 bounds = (TextRenderSpecific ? GameBase.WindowManager.Ratio : 1) * TextBounds;

            Vector4 corners = CornerBounds;
            Vector2 padding = Padding;

            if (corners != Vector4.Zero && TextRenderSpecific)
            {
                corners *= (float)GameBase.WindowManager.Height / 768;
            }

            if (Padding != Vector2.Zero)
            {
                padding *= (float)GameBase.WindowManager.Height / 768;
            }

            float borderWidth = BorderWidth;

            if (borderWidth > 0)
            {
                borderWidth *= (float)GameBase.WindowManager.Height / 768;
            }

            System.Drawing.RectangleF[] regions;
            localTexture = NativeText.CreateText(Text, size, bounds, TextColour, Shadow, TextBold, TextItalic, TextUnderline, TextAlignment,
                                                 TextAa, out lastMeasure, out regions, BackgroundColour, BorderColour, (int)Math.Round(borderWidth), false, false, fontFace, corners, padding, localTexture);

            if (old != null && localTexture != old)
            {
                old.Dispose();
            }

            if (aggressiveCleanup)
            {
                if (localTexture != null)
                {
                    localTexture.TrackAccessTime = true;
                }
                if (old != localTexture)
                {
                    DynamicSpriteCache.Load(this, true);
                }
            }

            DrawWidth  = (int)Math.Round(lastMeasure.X);
            DrawHeight = (int)Math.Round(lastMeasure.Y);

            UpdateTextureSize();
            UpdateTextureAlignment();

            if (OnRefreshTexture != null)
            {
                OnRefreshTexture(this, null);
            }

            return(localTexture);
        }