public TimeBar(TextureAtlas atlas)
            {
                Size  = new Vector2(WIDTH, HEIGHT);
                Child = Sprite = new Sprite();

                Sprite.Texture = atlas.Add(WIDTH, HEIGHT);
            }
Example #2
0
 protected override void setTexAtlas()
 {
     TextureAtlas.Add(0, new Rectangle(0, 0, 64, 64));
     TextureAtlas.Add(1, new Rectangle(64, 0, 64, 64));
     TextureAtlas.Add(2, new Rectangle(128, 0, 64, 64));
     TextureAtlas.Add(3, new Rectangle(192, 0, 64, 64));
     TextureAtlas.Add(4, new Rectangle(256, 0, 64, 64));
 }
            public TimeBar(TextureAtlas atlas)
            {
                Size     = new Vector2(width, height);
                Children = new[]
                {
                    Sprite = new Sprite()
                };

                Sprite.Texture = atlas.Add(width, height);
            }
Example #4
0
        public void TestAtlasSecondRowAddRespectsWhitePixelSize()
        {
            const int atlas_size = 1024;

            var atlas = new TextureAtlas(atlas_size, atlas_size);

            TextureGL texture = atlas.Add(atlas_size - 2 * TextureAtlas.PADDING, 64);

            RectangleF rect = texture.GetTextureRect(null);

            Assert.GreaterOrEqual(atlas_size * rect.X, TextureAtlas.PADDING, message: "Texture has insufficient padding");
            Assert.GreaterOrEqual(atlas_size * rect.Y, TextureAtlas.WHITE_PIXEL_SIZE + TextureAtlas.PADDING, message: "Texture is placed on top of the white pixel");
        }
Example #5
0
            protected override void Load(BaseGame game)
            {
                base.Load(game);

                Size = new Vector2(WIDTH, HEIGHT);

                Children = new[]
                {
                    Sprite = new Sprite
                    {
                        Texture = atlas.Add(WIDTH, HEIGHT)
                    }
                };
            }
Example #6
0
        private void testWithSize(int width, int height)
        {
            TextureAtlas atlas   = new TextureAtlas(1024, 1024);
            TextureGL    texture = atlas.Add(width, height);

            if (texture != null)
            {
                Assert.AreEqual(texture.Width, width, message: $"Width: {texture.Width} != {width} for texture {width}x{height}");
                Assert.AreEqual(texture.Height, height, message: $"Height: {texture.Height} != {height} for texture {width}x{height}");

                RectangleF rect = texture.GetTextureRect(null);
                Assert.LessOrEqual(rect.X + rect.Width, 1, message: $"Returned texture is wider than TextureAtlas for texture {width}x{height}");
                Assert.LessOrEqual(rect.Y + rect.Height, 1, message: $"Returned texture is taller than TextureAtlas for texture {width}x{height}");
            }
            else
            {
                Assert.True(width > 1024 - TextureAtlas.PADDING * 2 || height > 1024 - TextureAtlas.PADDING * 2 ||
                            (width > 1024 - TextureAtlas.PADDING * 2 - TextureAtlas.WHITE_PIXEL_SIZE &&
                             height > 1024 - TextureAtlas.PADDING * 2 - TextureAtlas.WHITE_PIXEL_SIZE),
                            message: $"Returned texture is null, but should have fit: {width}x{height}");
            }
        }
        public FrameStatisticsDisplay(GameThread thread, TextureAtlas atlas)
        {
            Name    = thread.Thread.Name;
            monitor = thread.Monitor;

            Origin       = Anchor.TopRight;
            AutoSizeAxes = Axes.Both;
            Alpha        = alpha_when_active;

            bool hasCounters = monitor.ActiveCounters.Any(b => b);

            Child = new Container
            {
                AutoSizeAxes = Axes.Both,
                Children     = new[]
                {
                    new Container
                    {
                        Origin           = Anchor.TopRight,
                        AutoSizeAxes     = Axes.X,
                        RelativeSizeAxes = Axes.Y,
                        Children         = new[]
                        {
                            labelText = new SpriteText
                            {
                                Text     = Name,
                                Origin   = Anchor.BottomCentre,
                                Anchor   = Anchor.CentreLeft,
                                Rotation = -90,
                            },
                            !hasCounters
                                ? new Container {
                                Width = 2
                            }
                                : new Container
                            {
                                Masking          = true,
                                CornerRadius     = 5,
                                AutoSizeAxes     = Axes.X,
                                RelativeSizeAxes = Axes.Y,
                                Margin           = new MarginPadding {
                                    Right = 2, Left = 2
                                },
                                Children = new Drawable[]
                                {
                                    counterBarBackground = new Sprite
                                    {
                                        Texture          = atlas.Add(1, HEIGHT),
                                        RelativeSizeAxes = Axes.Both,
                                        Size             = new Vector2(1, 1),
                                    },
                                    new FillFlowContainer
                                    {
                                        Direction          = FillDirection.Horizontal,
                                        AutoSizeAxes       = Axes.X,
                                        RelativeSizeAxes   = Axes.Y,
                                        ChildrenEnumerable =
                                            from StatisticsCounterType t in Enum.GetValues(typeof(StatisticsCounterType))
                                            where monitor.ActiveCounters[(int)t]
                                            select counterBars[t] = new CounterBar
                                        {
                                            Colour = getColour(t),
                                            Label  = t.ToString(),
                                        },
                                    },
                                }
                            }
                        }
                    },
                    mainContainer = new Container
                    {
                        Size     = new Vector2(WIDTH, HEIGHT),
                        Children = new[]
                        {
                            timeBarsContainer = new Container
                            {
                                Masking          = true,
                                CornerRadius     = 5,
                                RelativeSizeAxes = Axes.Both,
                                Children         = timeBars = new[]
                                {
                                    new TimeBar(atlas),
                                    new TimeBar(atlas),
                                },
                            },
                            fpsDisplay = new FpsDisplay(monitor.Clock)
                            {
                                Anchor = Anchor.BottomRight,
                                Origin = Anchor.BottomRight,
                            },
                            overlayContainer = new Container
                            {
                                RelativeSizeAxes = Axes.Both,
                                Alpha            = 0,
                                Children         = new[]
                                {
                                    new FillFlowContainer
                                    {
                                        Anchor       = Anchor.TopRight,
                                        Origin       = Anchor.TopRight,
                                        AutoSizeAxes = Axes.Both,
                                        Spacing      = new Vector2(5, 1),
                                        Padding      = new MarginPadding {
                                            Right = 5
                                        },
                                        ChildrenEnumerable =
                                            from PerformanceCollectionType t in Enum.GetValues(typeof(PerformanceCollectionType))
                                            select legendMapping[(int)t] = new SpriteText
                                        {
                                            Colour = getColour(t),
                                            Text   = t.ToString(),
                                            Alpha  = 0
                                        },
                                    },
                                    new SpriteText
                                    {
                                        Padding = new MarginPadding {
                                            Left = 4
                                        },
                                        Text = $@"{visible_ms_range}ms"
                                    },
                                    new SpriteText
                                    {
                                        Padding = new MarginPadding {
                                            Left = 4
                                        },
                                        Text   = @"0ms",
                                        Anchor = Anchor.BottomLeft,
                                        Origin = Anchor.BottomLeft
                                    }
                                }
                            }
                        }
                    }
                }
            };

            textureBufferStack = new BufferStack <byte>(timeBars.Length * WIDTH);
        }
Example #8
0
        public FrameStatisticsDisplay(string name, PerformanceMonitor monitor, TextureAtlas atlas)
        {
            Name         = name;
            this.monitor = monitor;

            Origin       = Anchor.TopRight;
            AutoSizeAxes = Axes.Both;
            Alpha        = alpha_when_inactive;

            bool hasCounters = false;

            for (int i = 0; i < (int)StatisticsCounterType.AmountTypes; ++i)
            {
                if (monitor.Counters[i] != null)
                {
                    hasCounters = true;
                }
            }

            Children = new Drawable[]
            {
                new Container
                {
                    AutoSizeAxes = Axes.Both,
                    Children     = new[]
                    {
                        new Container
                        {
                            Origin           = Anchor.TopRight,
                            AutoSizeAxes     = Axes.X,
                            RelativeSizeAxes = Axes.Y,
                            Position         = new Vector2(-2, 0),
                            Children         = new[]
                            {
                                labelText = new SpriteText
                                {
                                    Text     = Name,
                                    Origin   = Anchor.BottomCentre,
                                    Anchor   = Anchor.CentreLeft,
                                    Rotation = -90,
                                    Position = new Vector2(-2, 0),
                                },
                                !hasCounters ? new Container() : new Container
                                {
                                    Masking          = true,
                                    CornerRadius     = 5,
                                    AutoSizeAxes     = Axes.X,
                                    RelativeSizeAxes = Axes.Y,
                                    Children         = new Drawable[]
                                    {
                                        counterBarBackground = new Sprite
                                        {
                                            Texture          = atlas.Add(1, HEIGHT),
                                            RelativeSizeAxes = Axes.Both,
                                            Size             = new Vector2(1, 1),
                                        },
                                        new FlowContainer
                                        {
                                            Direction        = FlowDirection.HorizontalOnly,
                                            AutoSizeAxes     = Axes.X,
                                            RelativeSizeAxes = Axes.Y,
                                            Children         = from StatisticsCounterType t in Enum.GetValues(typeof(StatisticsCounterType))
                                                               where t < StatisticsCounterType.AmountTypes && monitor.Counters[(int)t] != null
                                                               select counterBars[t] = new CounterBar
                                            {
                                                Colour = getColour(t),
                                                Label  = t.ToString(),
                                            },
                                        },
                                    }
                                }
                            }
                        },
                        mainContainer = new Container
                        {
                            Size     = new Vector2(WIDTH, HEIGHT),
                            Children = new[]
                            {
                                timeBarsContainer = new Container
                                {
                                    Masking          = true,
                                    CornerRadius     = 5,
                                    RelativeSizeAxes = Axes.Both,
                                    Children         = timeBars = new[]
                                    {
                                        new TimeBar(atlas),
                                        new TimeBar(atlas),
                                    },
                                },
                                fpsDisplay = new FpsDisplay(monitor.Clock)
                                {
                                    Anchor = Anchor.BottomRight,
                                    Origin = Anchor.BottomRight,
                                },
                                overlayContainer = new Container
                                {
                                    RelativeSizeAxes = Axes.Both,
                                    Alpha            = 0,
                                    Children         = new []
                                    {
                                        new FlowContainer
                                        {
                                            Anchor       = Anchor.TopRight,
                                            Origin       = Anchor.TopRight,
                                            AutoSizeAxes = Axes.Both,
                                            Spacing      = new Vector2(5, 1),
                                            Padding      = new MarginPadding {
                                                Right = 5
                                            },
                                            Children = from PerformanceCollectionType t in Enum.GetValues(typeof(PerformanceCollectionType))
                                                       where t < PerformanceCollectionType.Empty
                                                       select legendMapping[(int)t] = new SpriteText
                                            {
                                                Colour = getColour(t),
                                                Text   = t.ToString(),
                                                Alpha  = 0
                                            },
                                        },
                                        new SpriteText
                                        {
                                            Padding = new MarginPadding {
                                                Left = 4
                                            },
                                            Text = $@"{VISIBLE_MS_RANGE}ms"
                                        },
                                        new SpriteText
                                        {
                                            Padding = new MarginPadding {
                                                Left = 4
                                            },
                                            Text   = @"0ms",
                                            Anchor = Anchor.BottomLeft,
                                            Origin = Anchor.BottomLeft
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
            };

            textureBufferStack = new BufferStack <byte>(timeBars.Length * WIDTH);
        }