Example #1
0
        protected override void RenderContent(RenderComposer composer)
        {
            ImGui.InputInt("Font Size", ref _size);

            if (ImGui.Button("Select Font"))
            {
                var explorer = new FileExplorer <FontAsset>(f => { _font = f; });
                Parent.AddWindow(explorer);
            }

            if (_font == null)
            {
                return;
            }

            ImGui.Text($"Font: {_font.Font.FullName}");
            ImGui.Text($"Asset Name: {_font.Name}");
            if (ImGui.Checkbox("Emotion Renderer", ref _emotionRenderer))
            {
                FontAsset.GlyphRasterizer = _emotionRenderer ? GlyphRasterizer.Emotion : GlyphRasterizer.StbTrueType;
            }
            ImGui.InputTextMultiline("Test Text", ref _testText, 200, new Vector2(200, 100));

            composer.RenderString(new Vector3(0, 100, 0), Color.Black, _testText, _font.GetAtlas(_size));
        }
Example #2
0
        protected override void RenderContent(RenderComposer composer)
        {
            Vector2 offset = ImGui.GetWindowPos();

            offset.Y   += ImGui.GetWindowHeight();
            _lastOffset = offset;
            composer.RenderSprite(new Vector3(offset, 0), _anim.Texture.Size * _parent.Scale, Color.White, _anim.Texture);
            for (var i = 0; i < _anim.Frames.Length; i++)
            {
                composer.RenderOutline(new Vector3(offset + _anim.Frames[i].Position * _parent.Scale, 1), _anim.Frames[i].Size * _parent.Scale, _holdingIdx == i ? Color.Green : Color.Red);
                var stringPos           = new Vector3(offset + _anim.Frames[i].Position * _parent.Scale, 1);
                DrawableFontAtlas atlas = _font.GetAtlas(15 * _parent.Scale);
                composer.RenderString(stringPos + new Vector3(1), Color.Black, i.ToString(), atlas);
                composer.RenderString(stringPos, Color.Red, i.ToString(), atlas);
            }

            ImGui.Text(_holdingIdx == -1 ? "Click on a rectangle to change it's position." : $"Select new position for frame {_holdingIdx}!");
        }
Example #3
0
        public override void Draw(RenderComposer composer)
        {
            DrawableFontAtlas atlas = _font.GetAtlas(30);
            var    l = new TextLayouter(atlas.Atlas);
            string text;

            if (!_myPaddle.Ready)
            {
                text = "Press 'Space' when ready!";
            }
            else if (_pad1 == _myPaddle && !_pad2.Ready || _pad2 == _myPaddle && !_pad1.Ready)
            {
                text = "Waiting for other player.";
            }
            else
            {
                text = $"{_pad1.Score}/{_pad2.Score}";
            }

            Vector2 textSize = l.MeasureString(text);
            float   screenHorizontalCenter = Engine.Configuration.RenderSize.X / 2;

            composer.RenderString(new Vector3(screenHorizontalCenter - textSize.X / 2, 10, 0), Color.White, text, atlas);

            composer.RenderSprite(_pad1.VisualPosition, _pad1.Size, _pad1.Ready ? Color.White : Color.Red);
            composer.RenderSprite(_pad2.VisualPosition, _pad2.Size, _pad2.Ready ? Color.White : Color.Red);

            // Uncomment to view paddle collisions.
            //LineSegment[] padCol = _pad2.GetPaddleCollision();
            //for (var i = 0; i < padCol.Length; i++)
            //{
            //    composer.RenderLine(ref padCol[i], Color.Red);
            //}

            NetworkTransform ball = IdToObject["Ball"];

            composer.RenderSprite(ball.VisualPosition, ball.Size, Color.White);

            NetworkTransform upperWall = IdToObject["UpperWall"];
            NetworkTransform lowerWall = IdToObject["LowerWall"];

            composer.RenderSprite(upperWall.VisualPosition, upperWall.Size, Color.White);
            composer.RenderSprite(lowerWall.VisualPosition, lowerWall.Size, Color.White);
        }
Example #4
0
 public void Draw(RenderComposer composer)
 {
     composer.SetUseViewMatrix(false);
     composer.RenderString(Vector3.Zero, Color.White, "Connecting...", _font.GetAtlas(30));
     composer.SetUseViewMatrix(true);
 }
Example #5
0
        protected override bool RenderInternal(RenderComposer c)
        {
            var open = true;

            ImGui.SetNextWindowPos(new Vector2(0, 20), ImGuiCond.Always);
            ImGui.SetNextWindowSize(c.CurrentTarget.Size - new Vector2(0, 20));
            ImGui.Begin(Title, ref open, ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove);

            RenderImGui();

            ImGui.End();

            Position = Vector3.Zero;
            Size     = c.CurrentTarget.Size;
            if (!open)
            {
                Parent?.RemoveChild(this);
                return(false);
            }

            if (_textureFb?.ColorAttachment == null)
            {
                return(true);                                     // Disposed or uninitialized fb
            }
            if (_currentAssetTexture == null)
            {
                return(true);
            }

            _textureFb.ColorAttachment.Smooth = false;
            c.RenderToAndClear(_textureFb);
            c.RenderSprite(Vector3.Zero, _currentAssetTexture.Size, _currentAssetTexture);

            // Render meta overlay on the spritesheet texture.
            if (_currentAsset != null)
            {
                AnimatedSprite             currentFileContext = _currentAsset.Content !;
                SpriteAnimationFrameSource frameSource        = currentFileContext.FrameSource;
                if (frameSource != null)
                {
                    for (var i = 0; i < frameSource.GetFrameCount(); i++)
                    {
                        Rectangle frameUv = frameSource.GetFrameUV(i);
                        c.RenderOutline(frameUv, _selectedFrame == i ? Color.Green : Color.Red);

                        if (_showFrameIdx && frameSource is SpriteArrayFrameSource)
                        {
                            Vector3           stringPos = frameUv.Position.ToVec3();
                            DrawableFontAtlas atlas     = _debugFont.GetAtlas(20);
                            c.RenderString(stringPos + new Vector3(1), Color.Black, i.ToString(), atlas);
                            c.RenderString(stringPos, Color.Red, i.ToString(), atlas);
                        }
                    }
                }
            }

            c.RenderTo(null);

            RenderAnimationPreview(c);

            return(true);
        }
Example #6
0
        public override void Draw(RenderComposer composer)
        {
            Color textCol = new Color(32, 32, 32);

            int    size = 20;
            string text = "The quick brown fox jumped over the lazy dog.";

            composer.SetUseViewMatrix(false);

            composer.RenderSprite(new Vector3(0, 0, 0), Engine.Renderer.CurrentTarget.Size, new Color(240, 240, 240));

            composer.PushModelMatrix(Matrix4x4.CreateScale(1, 1, 1) * Matrix4x4.CreateTranslation(100, 100, 0));

            FontAsset.GlyphRasterizer = GlyphRasterizer.Emotion;
            composer.RenderLine(new Vector3(0, 0, 0), new Vector3(500, 0, 0), Color.Red);
            composer.RenderString(new Vector3(0, 0, 0), textCol, "Emotion Renderer:\n" + text, _font.GetAtlas(size));

            FontAsset.GlyphRasterizer = GlyphRasterizer.EmotionSDFVer3;
            composer.RenderLine(new Vector3(0, 140, 0), new Vector3(500, 140, 0), Color.Red);
            composer.RenderString(new Vector3(0, 140, 0), textCol, "EmotionSDFVer3:\n" + text, _font.GetAtlas(size));

            FontAsset.GlyphRasterizer = GlyphRasterizer.EmotionSDFVer4;
            composer.RenderLine(new Vector3(0, 300, 0), new Vector3(500, 300, 0), Color.Red);
            composer.RenderString(new Vector3(0, 300, 0), textCol, "EmotionSDFVer4:\n" + text, _font.GetAtlas(size));

            FontAsset.GlyphRasterizer = GlyphRasterizer.StbTrueType;
            composer.RenderLine(new Vector3(0, 450, 0), new Vector3(500, 450, 0), Color.Red);
            composer.RenderString(new Vector3(0, 450, 0), textCol, "StbTrueType:\n" + text, _font.GetAtlas(size));

            composer.PopModelMatrix();

            composer.SetUseViewMatrix(true);
        }