public static void DrawString(this SpriteBatch sb, IFont font, string text,
                               Vector2 position, TextColor color,
                               FontStyle style, float rotation, Vector2 origin,
                               Vector2 scale,
                               float opacity         = 1f,
                               SpriteEffects effects = SpriteEffects.None, float layerDepth = 0f)
 {
     font.DrawString(sb, text, position, color, style, scale: scale, rotation: rotation, origin: origin, opacity: opacity, effects: effects, layerDepth: layerDepth);
 }
Ejemplo n.º 2
0
 public void DrawString(IFont font, string text,
                        Vector2 position, TextColor color, float scale = 1f,
                        FontStyle style  = FontStyle.None, float rotation = 0f,
                        Vector2?origin   = null,
                        float opacity    = 1f, SpriteEffects effects = SpriteEffects.None,
                        float layerDepth = 0f)
 {
     font.DrawString(SpriteBatch, text, position, color, style, scale: new Vector2(scale), rotation: rotation, origin: origin ?? Vector2.Zero, opacity: opacity, effects: effects, layerDepth: layerDepth);
 }
Ejemplo n.º 3
0
        public void DrawString(string text, IFont font, Color col, PointF pt, Color?backColor = null)
        {
            Point ptd = ImgToDisp(pt);

            if (backColor != null)
            {
                var size = font.MeasureString(text);
                Drawing.DrawRectangle(Buf, Bw, Bh, ptd.X, ptd.Y, ptd.X + size.Width, ptd.Y + size.Height, backColor.Value.ToArgb(), true);
            }
            font.DrawString(text, Buf, Bw, Bh, ptd.X, ptd.Y, col);
        }
Ejemplo n.º 4
0
        protected override void OnRender()
        {
            base.OnRender();
            AlphaBlending(true);

            _guiRenderer.Render(_gui);
            _consoleRenderer.Render();

            if (_gui.HoverWidget != null)
            {
                var widgetPosition = new Vector2(_mousePosition.X, _mousePosition.Y) - _gui.HoverWidget.GetAbsolutePosition();
                var widgetName     = _gui.HoverWidget.UniqueName;

                _font.DrawString("Screen: " + _mousePosition + "  Widget[" + widgetName + "]:" + widgetPosition, 0, 0, Colours.Yellow);
            }
            else
            {
                _font.DrawString("Screen: " + _mousePosition, 0, 0, Colours.Yellow);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates the initial font bitmap. This is simply a long thin strip of all glyphs in a row
        /// </summary>
        /// <param name="font">The <see cref="IFont"/> object to build the initial bitmap from</param>
        /// <param name="maxSize">The maximum glyph size of the font</param>
        /// <param name="initialMargin">The initial bitmap margin (used for all four sides)</param>
        /// <param name="glyphs">A collection of <see cref="QFontGlyph"/>s corresponding to the initial bitmap</param>
        /// <param name="renderHint">The font rendering hint to use</param>
        /// <returns></returns>
        private Bitmap CreateInitialBitmap(IFont font, SizeF maxSize, int initialMargin, out QFontGlyph[] glyphs, TextGenerationRenderHint renderHint)
        {
            glyphs = new QFontGlyph[_charSet.Length];

            int      spacing = (int)Math.Ceiling(maxSize.Width) + 2 * initialMargin;
            Bitmap   bmp     = new Bitmap(spacing * _charSet.Length, (int)Math.Ceiling(maxSize.Height) + 2 * initialMargin, PixelFormat.Format24bppRgb);
            Graphics graph   = Graphics.FromImage(bmp);

            switch (renderHint)
            {
            case TextGenerationRenderHint.SizeDependent:
                graph.TextRenderingHint = font.Size <= 12.0f  ? TextRenderingHint.ClearTypeGridFit : TextRenderingHint.AntiAlias;
                break;

            case TextGenerationRenderHint.AntiAlias:
                graph.TextRenderingHint = TextRenderingHint.AntiAlias;
                break;

            case TextGenerationRenderHint.AntiAliasGridFit:
                graph.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                break;

            case TextGenerationRenderHint.ClearTypeGridFit:
                graph.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                break;

            case TextGenerationRenderHint.SystemDefault:
                graph.TextRenderingHint = TextRenderingHint.SystemDefault;
                break;
            }

            // enable high quality graphics
            graph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            graph.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            graph.CompositingMode    = System.Drawing.Drawing2D.CompositingMode.SourceOver;

            int xOffset = initialMargin;

            for (int i = 0; i < _charSet.Length; i++)
            {
                var offset   = font.DrawString("" + _charSet[i], graph, Brushes.White, xOffset, initialMargin);
                var charSize = font.MeasureString("" + _charSet[i], graph);
                glyphs[i] = new QFontGlyph(0, new Rectangle(xOffset - initialMargin + offset.X, initialMargin + offset.Y, (int)charSize.Width + initialMargin * 2, (int)charSize.Height + initialMargin * 2), 0, _charSet[i]);
                xOffset  += (int)charSize.Width + initialMargin * 2;
            }

            graph.Flush();
            graph.Dispose();

            return(bmp);
        }
Ejemplo n.º 6
0
        public static Bitmap CreateBitmapFromString(RuntimeFont font, Bitmap pngBitmap, string testString, int startX, int startY, IFont comparisonFont = null)
        {
            // Get the character positions.
            FontLayout.CharacterLayout[] layouts = FontLayout.LayoutCharacters(font, testString, 0, 0);

            // Draw the character.
            int extraLineSpacing = 5;

            int width  = 1;
            int height = 1;

            if (layouts.Length > 0)
            {
                width  = layouts[layouts.Length - 1].XOffset + font.LineHeight * 2;
                height = layouts[layouts.Length - 1].YOffset + font.LineHeight;
            }

            if (comparisonFont != null)
            {
                height += font.LineHeight + extraLineSpacing;
            }

            Color textColor = Color.White;

            Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.Clear(Color.Transparent);

                foreach (FontLayout.CharacterLayout layout in layouts)
                {
                    int       sfi      = layout.SudoFontIndex;
                    Rectangle srcRect  = new Rectangle(font.Characters[sfi].PackedX, font.Characters[sfi].PackedY, font.Characters[sfi].PackedWidth, font.Characters[sfi].PackedHeight);
                    Rectangle destRect = new Rectangle(layout.XOffset, layout.YOffset, srcRect.Width, srcRect.Height);
                    g.DrawImage(pngBitmap, destRect, srcRect, GraphicsUnit.Pixel);
                }

                int curY = startY + font.LineHeight + extraLineSpacing;
                if (comparisonFont != null)
                {
                    comparisonFont.DrawString(g, testString, new SolidBrush(textColor), new Point(0, curY));
                    curY += font.LineHeight + extraLineSpacing;
                }
            }

            return(bitmap);
        }
Ejemplo n.º 7
0
        public static Bitmap CreateBitmapFromString( RuntimeFont font, Bitmap pngBitmap, string testString, int startX, int startY, IFont comparisonFont=null )
        {
            // Get the character positions.
            FontLayout.CharacterLayout[] layouts = FontLayout.LayoutCharacters( font, testString, 0, 0 );

            // Draw the character.
            int extraLineSpacing = 5;

            int width = 1;
            int height = 1;

            if ( layouts.Length > 0 )
            {
                width = layouts[ layouts.Length - 1 ].XOffset + font.LineHeight * 2;
                height = layouts[ layouts.Length - 1 ].YOffset + font.LineHeight;
            }

            if ( comparisonFont != null )
            {
                height += font.LineHeight + extraLineSpacing;
            }

            Color textColor = Color.White;

            Bitmap bitmap = new Bitmap( width, height, PixelFormat.Format32bppArgb );
            using ( Graphics g = Graphics.FromImage( bitmap ) )
            {
                g.Clear( Color.Transparent );

                foreach ( FontLayout.CharacterLayout layout in layouts )
                {
                    int sfi = layout.SudoFontIndex;
                    Rectangle srcRect = new Rectangle( font.Characters[sfi].PackedX, font.Characters[sfi].PackedY, font.Characters[sfi].PackedWidth, font.Characters[sfi].PackedHeight );
                    Rectangle destRect = new Rectangle( layout.XOffset, layout.YOffset, srcRect.Width, srcRect.Height );
                    g.DrawImage( pngBitmap, destRect, srcRect, GraphicsUnit.Pixel );
                }

                int curY = startY + font.LineHeight + extraLineSpacing;
                if ( comparisonFont != null )
                {
                    comparisonFont.DrawString( g, testString, new SolidBrush( textColor ), new Point( 0, curY ) );
                    curY += font.LineHeight + extraLineSpacing;
                }
            }

            return bitmap;
        }
Ejemplo n.º 8
0
 public void DrawString(Vector2 position, string text, IFont font, TextColor color, FontStyle style, Vector2?scale = null,
                        float rotation = 0f, Vector2?rotationOrigin = null, float opacity = 1f)
 {
     font?.DrawString(SpriteBatch, text, position, color, style, scale, opacity, rotation, rotationOrigin);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Update framebuffer.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ObjectsControl_Render(object sender, GlControlEventArgs e)
        {
            GlControl senderControl     = (GlControl)sender;
            float     senderAspectRatio = (float)senderControl.Width / senderControl.Height;

            // Clear
            Gl.Viewport(0, 0, senderControl.Width, senderControl.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _CubeScene.CurrentView.LocalModel.SetIdentity();
            _CubeScene.CurrentView.LocalModel.Translate(_ViewStrideLat, _ViewStrideAlt, 0.0f);
            _CubeScene.CurrentView.LocalModel.RotateY(_ViewAzimuth);
            _CubeScene.CurrentView.LocalModel.RotateX(_ViewElevation);
            _CubeScene.CurrentView.LocalModel.Translate(0.0f, 0.0f, _ViewLever);

            _CubeScene.CurrentView.ProjectionMatrix = new PerspectiveProjectionMatrix(45.0f, senderAspectRatio, 0.5f, 10000.0f);

            _CubeScene.Draw(_Context);

            // Overlay
            ProjectionMatrix overlayProjection = new OrthoProjectionMatrix(0.0f, ClientSize.Width, 0.0f, ClientSize.Height);
            ModelMatrix      overlayModel      = new ModelMatrix();

            overlayModel.Translate(0.375f, 0.375f);

            Gl.Clear(ClearBufferMask.DepthBufferBit);

            ColorRGBAF fpsColor = ColorRGBAF.ColorGreen;
            int        fps      = senderControl.Fps;

            if (fps >= 59)
            {
                fpsColor = ColorRGBAF.ColorGreen;
            }
            else if (fps >= 29)
            {
                fpsColor = ColorRGBAF.ColorBlue;
            }
            else if (fps >= 24)
            {
                fpsColor = ColorRGBAF.ColorYellow;
            }
            else
            {
                fpsColor = ColorRGBAF.ColorRed;
            }

            fontPatch.DrawString(
                _Context, overlayProjection * overlayModel, fpsColor,
                String.Format("FPS: {0}", senderControl.Fps)
                );

            overlayModel.SetIdentity();
            overlayModel.Translate(0.375f, ClientSize.Height - 64 + 0.375f);
            fontTitle.DrawString(
                _Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen,
                "Hello Objects example ~(^.^)~"
                );

            overlayModel.SetIdentity();
            overlayModel.Translate(0.375f, ClientSize.Height - 128 + 0.375f);
            fontTitleV.DrawString(_Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen,
                                  "Hello Objects example ~(^.^)~"
                                  );
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Update framebuffer.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ObjectsControl_Render(object sender, GlControlEventArgs e)
        {
            GlControl senderControl     = (GlControl)sender;
            float     senderAspectRatio = (float)senderControl.Width / senderControl.Height;

            KhronosApi.LogEnabled = false;
            KhronosApi.LogComment("--------------------------------------------------");
            KhronosApi.LogComment("*** Draw");

            // Clear
            Gl.Viewport(0, 0, senderControl.Width, senderControl.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _CubeScene.CurrentView.ProjectionMatrix = new PerspectiveProjectionMatrix(45.0f, senderAspectRatio, 0.1f, 100.0f);
            _CubeScene.CurrentView.LocalModel.SetIdentity();
            _CubeScene.CurrentView.LocalModel.Translate(_ViewStrideLat, _ViewStrideAlt, 0.0f);
            _CubeScene.CurrentView.LocalModel.RotateY(_ViewAzimuth);
            _CubeScene.CurrentView.LocalModel.RotateX(_ViewElevation);
            _CubeScene.CurrentView.LocalModel.Translate(0.0f, 0.0f, _ViewLever);
            _CubeScene.UpdateViewMatrix();

            _CubeScene.Draw(_Context);

            KhronosApi.LogEnabled = false;

            return;

            // Overlay
            ProjectionMatrix overlayProjection = new OrthoProjectionMatrix(0.0f, ClientSize.Width, 0.0f, ClientSize.Height);
            ModelMatrix      overlayModel      = new ModelMatrix();

            overlayModel.Translate(0.375f, 0.375f);

            Gl.Clear(ClearBufferMask.DepthBufferBit);

            ColorRGBAF fpsColor = ColorRGBAF.ColorGreen;
            int        fps      = (int)Math.Floor(1000.0 / senderControl.FrameSwapTime.TotalMilliseconds);

            if (fps >= 59)
            {
                fpsColor = ColorRGBAF.ColorGreen;
            }
            else if (fps >= 29)
            {
                fpsColor = ColorRGBAF.ColorBlue;
            }
            else if (fps >= 24)
            {
                fpsColor = ColorRGBAF.ColorYellow;
            }
            else
            {
                fpsColor = ColorRGBAF.ColorRed;
            }

            fontPatch.DrawString(
                _Context, overlayProjection * overlayModel, fpsColor,
                String.Format("FPS: {0}", fps)
                );

            overlayModel.SetIdentity();
            overlayModel.Translate(0.375f, ClientSize.Height - 64 + 0.375f);
            fontTitle.DrawString(
                _Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen,
                "Hello Objects example ~(^.^)~"
                );

            overlayModel.SetIdentity();
            overlayModel.Translate(0.375f, ClientSize.Height - 128 + 0.375f);
            fontTitleV.DrawString(_Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen,
                                  "Hello Objects example ~(^.^)~"
                                  );

            // Release resources
            _Context.DisposeResources();
        }