Esempio n. 1
0
        public void DrawString(string text, RFont font, RBrush brush, int x, int y, StringFormat format, bool useStack = true)
        {
            if (useStack)
            {
                Bus.Publish(new DrawTextCommand(text, font, (RBrush)brush.Clone(), x, y, format));
            }
            else
            {
                var b = ((BrushAdapter)brush).Brush;
                // var color = default(SKColor);

                // if (b is SolidBrush)
                // {
                // var solid = b as SolidBrush;
                // color = new SKColor(solid.Color.R, solid.Color.G, solid.Color.B, solid.Color.A);
                // }

                var f     = ((FontAdapter)font).Font;
                var paint = PaintFromFont(f);
                paint.Color = b.Color;

                _c.DrawText(text, x, y, paint);

                if (GloablRenderSettings.IsDebug)
                {
                    var textSize = GetTextBound(text, paint);
                    _c.DrawRect(x, y - textSize.Height, textSize.Width, textSize.Height, new SKPaint
                    {
                        Style = SKPaintStyle.Stroke,
                        Color = SKColors.Coral
                    });
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Get cached font if it exists in cache or null if it is not.
        /// </summary>
        private RFont TryGetFont(string family, double size, RFontStyle style)
        {
            RFont font = null;

            if (this._fontsCache.ContainsKey(family))
            {
                var a = this._fontsCache[family];
                if (a.ContainsKey(size))
                {
                    var b = a[size];
                    if (b.ContainsKey(style))
                    {
                        font = b[style];
                    }
                }
                else
                {
                    this._fontsCache[family][size] = new Dictionary <RFontStyle, RFont>();
                }
            }
            else
            {
                this._fontsCache[family]       = new Dictionary <double, Dictionary <RFontStyle, RFont> >();
                this._fontsCache[family][size] = new Dictionary <RFontStyle, RFont>();
            }
            return(font);
        }
Esempio n. 3
0
        public override RSize MeasureString(string str, RFont font)
        {
            var text    = GetText(str, font);
            var measure = text.Measure();

            return(new RSize(measure.Width, measure.Height));
        }
Esempio n. 4
0
        public override void DrawString(string str, RFont font, RColor color, RPoint point, RSize size, bool rtl)
        {
            var pointConv = Utils.ConvertRound(point);
            var colorConv = Utils.Convert(color);

            if (color.A == 255)
            {
                // if (GloablRenderSettings.UseBus)
                // {
                _g.DrawString(str, font,
                              new BrushAdapter(new SKPaint
                {
                    Style = SKPaintStyle.Fill,
                    Color = colorConv
                }, false),
                              pointConv.X,
                              pointConv.Y, StringFormat.GenericTypographic);
                // }
                // else
                // {
                // SetFont(font);
                // SetTextColor(colorConv);
                // SkRendererAdapter.TextOut(_hdc, pointConv.X, pointConv.Y, str, str.Length);
                // }
            }
        }
Esempio n. 5
0
        public override void DrawString(string str, RFont font, RColor color, RPoint point, RSize size, bool rtl)
        {
            if (_useGdiPlusTextRendering)
            {
                ReleaseHdc();
                SetRtlAlignGdiPlus(rtl);
                var brush = ((BrushAdapter)_adapter.GetSolidBrush(color)).Brush;
                _g.DrawString(str, ((FontAdapter)font).Font, brush, (int)(Math.Round(point.X) + (rtl ? size.Width : 0)), (int)Math.Round(point.Y), _stringFormat2);
            }
            else
            {
#if !MONO
                var pointConv = Utils.ConvertRound(point);
                var colorConv = Utils.Convert(color);

                if (color.A == 255)
                {
                    SetFont(font);
                    SetTextColor(colorConv);
                    SetRtlAlignGdi(rtl);

                    Win32Utils.TextOut(_hdc, pointConv.X, pointConv.Y, str, str.Length);
                }
                else
                {
                    InitHdc();
                    SetRtlAlignGdi(rtl);
                    DrawTransparentText(_hdc, str, font, pointConv, Utils.ConvertRound(size), colorConv);
                }
#endif
            }
        }
Esempio n. 6
0
        public override void MeasureString(string str, RFont font, double maxWidth, out int charFit, out double charFitWidth)
        {
            var text       = GetText(str, font);
            var fullLength = text.Measure().Width;

            if (fullLength < maxWidth)
            {
                charFitWidth = fullLength;
                charFit      = str.Length;
                return;
            }

            int    lastLen     = 0;
            double lastMeasure = 0;

            BinarySearch(len =>
            {
                text        = GetText(str.Substring(0, len), font);
                var size    = text.Measure().Width;
                lastMeasure = size;
                lastLen     = len;
                if (size <= maxWidth)
                {
                    return(-1);
                }
                return(1);
            }, 0, str.Length);
            if (lastMeasure > maxWidth)
            {
                lastLen--;
                lastMeasure = GetText(str.Substring(0, lastLen), font).Measure().Width;
            }
            charFit      = lastLen;
            charFitWidth = lastMeasure;
        }
 public override void MeasureString(string str, RFont font, double maxWidth, out int charFit, out double charFitWidth)
 {
     using (var g = new GraphicsAdapter(_control.CreateGraphics(), _useGdiPlusTextRendering, true))
     {
         g.MeasureString(str, font, maxWidth, out charFit, out charFitWidth);
     }
 }
Esempio n. 8
0
        public override RSize MeasureString(string str, RFont font)
        {
            double        width         = 0;
            GlyphTypeface glyphTypeface = ((FontAdapter)font).GlyphTypeface;

            if (glyphTypeface != null)
            {
                for (int i = 0; i < str.Length; i++)
                {
                    if (glyphTypeface.CharacterToGlyphMap.ContainsKey(str[i]))
                    {
                        ushort glyph        = glyphTypeface.CharacterToGlyphMap[str[i]];
                        double advanceWidth = glyphTypeface.AdvanceWidths[glyph];
                        width += advanceWidth;
                    }
                    else
                    {
                        width = 0;
                        break;
                    }
                }
            }

            if (width <= 0)
            {
                var formattedText = new FormattedText(str, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, ((FontAdapter)font).Font, 96d / 72d * font.Size, Brushes.Red, GetDPI().PixelsPerDip);
                return(new RSize(formattedText.WidthIncludingTrailingWhitespace, formattedText.Height));
            }

            return(new RSize(width * font.Size * 96d / 72d, font.Height));
        }
        /// <summary>
        /// Draw the given string using the given font and foreground color at given location.
        /// </summary>
        /// <param name="str">the string to draw</param>
        /// <param name="font">the font to use to draw the string</param>
        /// <param name="color">the text color to set</param>
        /// <param name="point">the location to start string draw (top-left)</param>
        /// <param name="size">used to know the size of the rendered text for transparent text support</param>
        /// <param name="rtl">is to render the string right-to-left (true - RTL, false - LTR)</param>
        public override void DrawString(string str, RFont font, RColor color, RPoint point, RSize size, bool rtl)
        {
            var textSurface = SDL_ttf.TTF_RenderUTF8_Blended(font.ToTTF_Font(), str, color.ToSDL());

            if (textSurface.ShowSDLError("Graphics.DrawString: Unable to TTF_RenderUTF8_Blended!"))
            {
                return;
            }

            var texture_text = SDL.SDL_CreateTextureFromSurface(_renderer, textSurface);

            if (texture_text.ShowSDLError("Graphics.DrawString: Unable to CreateTextureFromSurface!"))
            {
                SDL.SDL_FreeSurface(textSurface);
                return;
            }

            var dst_rect = textSurface.As <SDL.SDL_Surface>().ToSDL_Rect().UpdatedByRPoint(point);

            if (SDL.SDL_RenderCopy(_renderer, texture_text, IntPtr.Zero, ref dst_rect) < 0)
            {
                Helpers.ShowSDLError("Graphics.DrawString:Unable to SDL_RenderCopy!");
            }

            SDL.SDL_DestroyTexture(texture_text);
            SDL.SDL_FreeSurface(textSurface);
        }
Esempio n. 10
0
        public override void DrawString(string str, RFont font, RColor color, RPoint point, RSize size, bool rtl)
        {
            var text = GetText(str, font);

            text.Constraint = Util.Convert(size);
            _g.DrawText(new SolidColorBrush(Util.Convert(color)), Util.Convert(point), text);
        }
Esempio n. 11
0
        /// <summary>
        /// Special draw logic to draw transparent text using GDI.<br/>
        /// 1. Create in-memory DC<br/>
        /// 2. Copy background to in-memory DC<br/>
        /// 3. Draw the text to in-memory DC<br/>
        /// 4. Copy the in-memory DC to the proper location with alpha blend<br/>
        /// </summary>
        private static void DrawTransparentText(IntPtr hdc, string str, RFont font, Point point, Size size, Color color)
        {
            IntPtr dib;
            var    memoryHdc = Win32Utils.CreateMemoryHdc(hdc, size.Width, size.Height, out dib);

            try
            {
                // copy target background to memory HDC so when copied back it will have the proper background
                Win32Utils.BitBlt(memoryHdc, 0, 0, size.Width, size.Height, hdc, point.X, point.Y, Win32Utils.BitBltCopy);

                // Create and select font
                Win32Utils.SelectObject(memoryHdc, ((FontAdapter)font).HFont);
                Win32Utils.SetTextColor(memoryHdc, (color.B & 0xFF) << 16 | (color.G & 0xFF) << 8 | color.R);

                // Draw text to memory HDC
                Win32Utils.TextOut(memoryHdc, 0, 0, str, str.Length);

                // copy from memory HDC to normal HDC with alpha blend so achieve the transparent text
                Win32Utils.AlphaBlend(hdc, point.X, point.Y, size.Width, size.Height, memoryHdc, 0, 0, size.Width, size.Height, new BlendFunction(color.A));
            }
            finally
            {
                Win32Utils.ReleaseMemoryHdc(memoryHdc, dib);
            }
        }
Esempio n. 12
0
        public RFont LoadFont(string path, int size)
        {
            RFont font = new RFont();

            font.Generate(RFileSystem.Instance.GetFilePath(path), size, (int)DPI.X);
            return(font);
        }
Esempio n. 13
0
 public override void MeasureString(string str, RFont font, double maxWidth, out int charFit, out double charFitWidth)
 {
     using (var g = new GraphicsAdapter())
     {
         g.MeasureString(str, font, maxWidth, out charFit, out charFitWidth);
     }
 }
Esempio n. 14
0
        public void RenderText(RFont font, Vector2 penPoint, string text, RColor color)
        {
            blendState.PlatformApplyState();
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Disable(EnableCap.CullFace);
            defaultShader.Bind();
            defaultShader.SetSamplerValue(RTextureLayer.DIFFUSE, font.Texture);


            defaultShader.SetUniformValue("projection", camera2d.Projection);
            defaultShader.SetUniformValue("view", camera2d.View);
            defaultShader.SetUniformValue("diffuse_color", color.ToVector4());
            defaultShader.SetUniformValue("model", Matrix.Identity);
            font.Render(ref defaultShader, ref vertexQuad2D, ref indexQuad2D, text, penPoint, color, Matrix.Identity);


            REngine.CheckGLError();

            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.DstAlpha);
            GL.Disable(EnableCap.Blend);

            defaultShader.Unbind();

            /*text = text.Replace("\r\n", "\n");
             * char lastChar = '\0';
             * Vector2 originalPoint = penPoint;
             * foreach(char c in text)
             * {
             *  if(c == ' ')
             *  {
             *      penPoint.X += font.Kerning(lastChar, c).X+font.SpaceWidth;
             *      lastChar = ' ';
             *      continue;
             *  }
             *  if(c == '\t')
             *  {
             *      penPoint.X += (font.Kerning(lastChar, c).X+(font.SpaceWidth * 2));
             *      continue;
             *  }
             *  if(c == '\r' || c=='\n')
             *  {
             *      penPoint.Y += font.LineHeight + (font.font.Height>>6);
             *      penPoint.X = originalPoint.X+font.Kerning(lastChar, c).X;
             *      continue;
             *  }
             *  penPoint.X += font.Kerning(lastChar, c).X;
             *  RTextureGlyph glyph = font.GetGlyph(c);
             *  int x0 = (int)(penPoint.X + (glyph.bitmapLeft));
             *  int y0 = (int)(penPoint.Y - (glyph.bitmapTop));
             *  //penPoint.X += glyph.Offset.X;
             *
             *  RenderTexture(glyph, new Rectangle(x0, y0, (int)glyph.Bounds.Width, (int)glyph.Bounds.Height), color, Matrix.Identity, true);
             *  penPoint.X += glyph.advance.X;
             *  lastChar = c;
             * }
             * //font.RenderText(defaultShader, text, penPoint.X, penPoint.Y, size, size);
             */
        }
Esempio n. 15
0
        public override RSize MeasureString(string str, RFont font)
        {
            var fontAdapter = (FontAdapter)font;
            var realFont    = fontAdapter.Font;
            var size        = _g.MeasureString(realFont, str);

            return(Utils.Convert(size));
        }
Esempio n. 16
0
 public DrawTextCommand(string text, RFont font, RBrush brush, int x, int y, StringFormat format)
 {
     Text   = text;
     Font   = font;
     Brush  = brush;
     X      = x;
     Y      = y;
     Format = format;
 }
Esempio n. 17
0
 public override void MeasureString(string str, RFont font, double maxWidth, out int charFit,
                                    out double charFitWidth)
 {
     // using (var g = new GraphicsAdapter(RendererFactory.FromControl(_control), _useGdiPlusTextRendering, true))
     // {
     // g.MeasureString(str, font, maxWidth, out charFit, out charFitWidth);
     // }
     charFit      = 1;
     charFitWidth = 1;
 }
        FormattedText GetText(string str, RFont font)
        {
            var f = ((FontAdapter)font);

            return(new FormattedText
            {
                Text = str,
                Typeface = new Typeface(f.Name, font.Size, f.FontStyle, f.Weight),
            });
        }
Esempio n. 19
0
        public RFont LoadTextureFont(string definitionPath, string texturePath)
        {
            RFont        font   = new RFont();
            BinaryReader reader = new BinaryReader(File.OpenRead(RFileSystem.Instance.GetFilePath(definitionPath)));

            font.Load(ref reader);
            font.Texture = new RTexture2D();
            font.Texture.LoadFromDisk(RFileSystem.Instance.GetFilePath(texturePath));
            return(font);
        }
    public void Add(string name, object obj, object tag = null)
    {
        var type = obj.GetType();

        if (type == typeof(Shader))
        {
            var item = new RShader();
            item.name  = name;
            item.value = obj as Shader;
            listShader.Add(item);
        }
        else if (type == typeof(Texture2D))
        {
            var item = new RTexture();
            item.name  = name;
            item.value = obj as Texture2D;
            listTexture.Add(item);
        }
        else if (type == typeof(Material))
        {
            var item = new RMaterial();
            item.name  = name;
            item.value = obj as Material;
            listMaterial.Add(item);
        }
        else if (type == typeof(GameObject))
        {
            var item = new RGameObject();
            item.name  = name;
            item.value = obj as GameObject;
            listGameObject.Add(item);
        }
        else if (type == typeof(GUISkin))
        {
            var item = new RGUISkin();
            item.name  = name;
            item.value = obj as GUISkin;
            listGUISkin.Add(item);
        }
        else if (type == typeof(Font))
        {
            var item = new RFont();
            item.name  = name;
            item.value = obj as Font;
            listFont.Add(item);
        }
        else
        {
            var item = new RUnknown();
            item.name  = name;
            item.type  = type.Name;
            item.value = obj.ToString();
            listUnknown.Add(item);
        }
    }
        public override void DrawString(string str, RFont font, RColor color, RPoint point, RSize size, bool rtl)
        {
            var colorConv = ((BrushAdapter)_adapter.GetSolidBrush(color)).Brush;

            bool          glyphRendered = false;
            GlyphTypeface glyphTypeface = ((FontAdapter)font).GlyphTypeface;

            if (glyphTypeface != null)
            {
                double   width  = 0;
                ushort[] glyphs = new ushort[str.Length];
                double[] widths = new double[str.Length];

                int i = 0;
                for (; i < str.Length; i++)
                {
                    ushort glyph;
                    if (!glyphTypeface.CharacterToGlyphMap.TryGetValue(str[i], out glyph))
                    {
                        break;
                    }

                    glyphs[i] = glyph;
                    width    += glyphTypeface.AdvanceWidths[glyph];
                    widths[i] = 96d / 72d * font.Size * glyphTypeface.AdvanceWidths[glyph];
                }

                if (i >= str.Length)
                {
                    point.Y += glyphTypeface.Baseline * font.Size * 96d / 72d;
                    point.X += rtl ? 96d / 72d * font.Size * width : 0;

                    glyphRendered = true;
                    var wpfPoint = Utils.ConvertRound(point);
                    var glyphRun = new GlyphRun(glyphTypeface, rtl ? 1 : 0,
                                                false, 96d / 72d * font.Size, glyphs,
                                                wpfPoint, widths, null, null, null, null, null, null);

                    var guidelines = new GuidelineSet();
                    guidelines.GuidelinesX.Add(wpfPoint.X);
                    guidelines.GuidelinesY.Add(wpfPoint.Y);
                    _g.PushGuidelineSet(guidelines);
                    _g.DrawGlyphRun(colorConv, glyphRun);
                    _g.Pop();
                }
            }

            if (!glyphRendered)
            {
                var formattedText = new FormattedText(str, CultureInfo.CurrentCulture, rtl ? FlowDirection.RightToLeft : FlowDirection.LeftToRight, ((FontAdapter)font).Font, 96d / 72d * font.Size, colorConv);
                point.X += rtl ? formattedText.Width : 0;
                _g.DrawText(formattedText, Utils.ConvertRound(point));
            }
        }
Esempio n. 22
0
        public override RSize MeasureString(string str, RFont font)
        {
            var fontAdapter = (FontAdapter)font;
            var realFont    = fontAdapter.Font;
            var size        = this._g.MeasureString(str, realFont, _stringFormat);

            if (font.Height < 0)
            {
                var height  = realFont.Height;
                var descent = realFont.Size * realFont.FontFamily.GetCellDescent(realFont.Style) / realFont.FontFamily.GetEmHeight(realFont.Style);
                fontAdapter.SetMetrics(height, (int)Math.Round((height - descent + 1f)));
            }

            return(Utils.Convert(size));
        }
Esempio n. 23
0
        public override void MeasureString(string str, RFont font, double maxWidth, out int charFit, out double charFitWidth)
        {
            var realFont = ((FontAdapter)font).Font;
            charFit = 0;
            charFitWidth = 0;

            var size = realFont.MeasureString(str);

            for (int i = 1; i <= str.Length; i++)
            {
                charFit = i - 1;
                var pSize = realFont.MeasureString(str.Substring(0, i));
                if (pSize.Height <= size.Height && pSize.Width < maxWidth)
                    charFitWidth = pSize.Width;
                else
                    break;
            }
        }
Esempio n. 24
0
        public override RSize MeasureString(string str, RFont font)
        {
            if (_useGdiPlusTextRendering)
            {
                ReleaseHdc();
                var fontAdapter = (FontAdapter)font;
                var realFont    = fontAdapter.Font;
                _characterRanges[0] = new CharacterRange(0, str.Length);
                _stringFormat.SetMeasurableCharacterRanges(_characterRanges);
                var size = _g.MeasureCharacterRanges(str, realFont, RectangleF.Empty, _stringFormat)[0].GetBounds(_g).Size;

                if (font.Height < 0)
                {
                    var height  = realFont.Height;
                    var descent = realFont.Size * realFont.FontFamily.GetCellDescent(realFont.Style) / realFont.FontFamily.GetEmHeight(realFont.Style);
#if !MONO
                    fontAdapter.SetMetrics(height, (int)Math.Round((height - descent + .5f)));
#else
                    fontAdapter.SetMetrics(height, (int)Math.Round((height - descent + 1f)));
#endif
                }

                return(Utils.Convert(size));
            }
            else
            {
#if !MONO
                SetFont(font);
                var size = new Size();
                Win32Utils.GetTextExtentPoint32(_hdc, str, str.Length, ref size);

                if (font.Height < 0)
                {
                    TextMetric lptm;
                    Win32Utils.GetTextMetrics(_hdc, out lptm);
                    ((FontAdapter)font).SetMetrics(size.Height, lptm.tmHeight - lptm.tmDescent + lptm.tmUnderlined + 1);
                }

                return(Utils.Convert(size));
#else
                throw new InvalidProgramException("Invalid Mono code");
#endif
            }
        }
Esempio n. 25
0
        public override void Init()
        {
            Engine.InitGameWindow(1920, 1080, RWindowStyle.Normal);
            GameWindow.VSync = OpenTK.VSyncMode.On;
            Engine.SetShowFPS(true);
            Engine.SetViewport(new RViewport(0, 0, 1920, 1080));
            //Engine.InitHDR();

            GameWindow.CursorVisible = true;
            GameWindow.Location      = new System.Drawing.Point(0, 0);
            sponza = Engine.Scene.Create <RMesh>("sponza");
            sponza.LoadSourceModel("/models/sponza.fbx");
            sponza.CullEnable  = false;
            sponza.CullMode    = RCullMode.None;
            sponza.Scale       = Vector3.One;
            sponza.Position    = Vector3.Zero;
            sponza.BlendEnable = false;
            var cam = Engine.GetCamera();

            //cam.LookAt(cam.Position - Vector3.UnitZ);
            cam.Position = new Vector3(0, 1.5f, 0);
            cam.Near     = 0.01f;
            cam.Far      = 10000f;
            //cam.ViewDirection = Vector3.Normalize(cam.Position - Vector3.UnitZ);
            cam.Update();

            font = RScreen.Instance.LoadFont("/vcr_osd_mono.ttf", 16);

            RTexture2D posX = (RTexture2D)Engine.Textures.CreateTexture <RTexture2D>("posX", "/textures/sky-posX.png");
            RTexture2D posY = (RTexture2D)Engine.Textures.CreateTexture <RTexture2D>("posY", "/textures/sky-posY.png");
            RTexture2D posZ = (RTexture2D)Engine.Textures.CreateTexture <RTexture2D>("posZ", "/textures/sky-posZ.png");
            RTexture2D negX = (RTexture2D)Engine.Textures.CreateTexture <RTexture2D>("negX", "/textures/sky-negX.png");
            RTexture2D negY = (RTexture2D)Engine.Textures.CreateTexture <RTexture2D>("negY", "/textures/sky-negY.png");
            RTexture2D negZ = (RTexture2D)Engine.Textures.CreateTexture <RTexture2D>("negZ", "/textures/sky-negZ.png");

            var skyboxTexture = new RTexture3D();

            skyboxTexture.Create(RPixelFormat.Rgb, ref posX, ref posY, ref posZ, ref negX, ref negY, ref negZ);

            Engine.Atmosphere.CreateSkyBox(skyboxTexture);
            GameWindow.Visible = true;
        }
Esempio n. 26
0
        public override void MeasureString(string str, RFont font, double maxWidth, out int charFit, out double charFitWidth)
        {
            charFit      = 0;
            charFitWidth = 0;
            bool          handled       = false;
            GlyphTypeface glyphTypeface = ((FontAdapter)font).GlyphTypeface;

            if (glyphTypeface != null)
            {
                handled = true;
                double width = 0;
                for (int i = 0; i < str.Length; i++)
                {
                    if (glyphTypeface.CharacterToGlyphMap.ContainsKey(str[i]))
                    {
                        ushort glyph        = glyphTypeface.CharacterToGlyphMap[str[i]];
                        double advanceWidth = glyphTypeface.AdvanceWidths[glyph] * font.Size * 96d / 72d;

                        if (!(width + advanceWidth < maxWidth))
                        {
                            charFit      = i;
                            charFitWidth = width;
                            break;
                        }
                        width += advanceWidth;
                    }
                    else
                    {
                        handled = false;
                        break;
                    }
                }
            }

            if (!handled)
            {
                var formattedText = new FormattedText(str, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, ((FontAdapter)font).Font, 96d / 72d * font.Size, Brushes.Red, GetDPI().PixelsPerDip);
                charFit      = str.Length;
                charFitWidth = formattedText.WidthIncludingTrailingWhitespace;
            }
        }
Esempio n. 27
0
        public override void MeasureString(string str, RFont font, double maxWidth, out int charFit, out double charFitWidth)
        {
            charFit      = 0;
            charFitWidth = 0;

            var size = MeasureString(str, font);

            for (int i = 1; i <= str.Length; i++)
            {
                charFit = i - 1;
                RSize pSize = MeasureString(str.Substring(0, i), font);
                if (pSize.Height <= size.Height && pSize.Width < maxWidth)
                {
                    charFitWidth = pSize.Width;
                }
                else
                {
                    break;
                }
            }
        }
Esempio n. 28
0
        public override void Init()
        {
            Engine.InitGameWindow(1280, 720, RWindowStyle.Normal);
            GameWindow.VSync = OpenTK.VSyncMode.On;
            Engine.SetShowFPS(true);
            Engine.SetViewport(new RViewport(0, 0, 1280, 720));
            Engine.InitHDR();
            GameWindow.CursorVisible = true;
            sponza = Engine.Scene.Create <RMesh>("sponza");
            sponza.LoadSourceModel("/models/sponza.fbx");
            sponza.CullEnable = false;
            sponza.CullMode   = RCullMode.None;
            sponza.SetScale(1f);
            sponza.SetPosition(0, 0, 0);
            sponza.BlendEnable = false;
            var cam = Engine.GetCamera();

            cam.SetPosition(0, 20, 1f);
            cam.LookAt(Vector3.Zero);
            cam.SetClipPlanes(0.01f, 10000f);

            font = RScreen.Instance.LoadFont("/vcr_osd_mono.ttf", 16);

            RTexture2D posX = (RTexture2D)Engine.Textures.CreateTexture <RTexture2D>("posX", "/textures/sky-posX.png");
            RTexture2D posY = (RTexture2D)Engine.Textures.CreateTexture <RTexture2D>("posY", "/textures/sky-posY.png");
            RTexture2D posZ = (RTexture2D)Engine.Textures.CreateTexture <RTexture2D>("posZ", "/textures/sky-posZ.png");
            RTexture2D negX = (RTexture2D)Engine.Textures.CreateTexture <RTexture2D>("negX", "/textures/sky-negX.png");
            RTexture2D negY = (RTexture2D)Engine.Textures.CreateTexture <RTexture2D>("negY", "/textures/sky-negY.png");
            RTexture2D negZ = (RTexture2D)Engine.Textures.CreateTexture <RTexture2D>("negZ", "/textures/sky-negZ.png");

            var skyboxTexture = new RTexture3D();

            skyboxTexture.Create(RPixelFormat.Rgb, ref posX, ref posY, ref posZ, ref negX, ref negY, ref negZ);

            Engine.Atmosphere.CreateSkyBox(skyboxTexture);
        }
Esempio n. 29
0
        public override void MeasureString(string str, RFont font, double maxWidth, out int charFit, out double charFitWidth)
        {
            charFit      = 0;
            charFitWidth = 0;
            if (_useGdiPlusTextRendering)
            {
                ReleaseHdc();

                var size = MeasureString(str, font);

                for (int i = 1; i <= str.Length; i++)
                {
                    charFit = i - 1;
                    RSize pSize = MeasureString(str.Substring(0, i), font);
                    if (pSize.Height <= size.Height && pSize.Width < maxWidth)
                    {
                        charFitWidth = pSize.Width;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
#if !MONO
                SetFont(font);

                var size = new Size();
                Win32Utils.GetTextExtentExPoint(_hdc, str, str.Length, (int)Math.Round(maxWidth), _charFit, _charFitWidth, ref size);
                charFit      = _charFit[0];
                charFitWidth = charFit > 0 ? _charFitWidth[charFit - 1] : 0;
#endif
            }
        }
Esempio n. 30
0
 public void RenderText(RFont font, Vector2 penPoint, string text)
 {
     RenderText(font, penPoint, text, RColor.White);
 }