Esempio n. 1
0
        public override void Draw(SpaceGame target)
        {
            base.Draw(target);
            AABB contentRect = GetContentAABB();

            int runningHeight = padding;

            runningHeight -= (int)(scrollLocation / bounds.Height * contentRect.Height);

            foreach (UIElement element in contents)
            {
                AABB bounds = element.bounds.AtOrigin;
                element.bounds.topLeft     = topLeft + (padding, runningHeight);
                element.bounds.bottomRight = element.bounds.topLeft + bounds.bottomRight;
                runningHeight += (int)element.bounds.Height + padding;
            }

            // use back buffer for clipping
            target.DrawTarget = backBuffer;
            target.Clear(PixelEngine.Pixel.Empty);

            foreach (UIElement element in contents)
            {
                element.Update(target);

                if (bounds.Overlaps(element.bounds))
                {
                    element.Draw(target);
                }
            }

            scrollbarHeight = bounds.Height / contentRect.Height * bounds.Height;
            AABB scrollbarRect = new AABB(topRight + (-10, scrollLocation), topRight + (0, scrollbarHeight + scrollLocation));

            scrollBar.bounds = scrollbarRect;

            // only draw scrollbar if scrolling is required
            if (scrollbarHeight != size.y)
            {
                scrollBar.Update(target);
                scrollBar.Draw(target);
            }

            // switch back to main buffer
            PixelEngine.Sprite scrollContainerSurface = target.DrawTarget;
            target.DrawTarget = null;

            target.DrawPartialSprite(topLeft, scrollContainerSurface, topLeft, (int)bounds.Width, (int)bounds.Height);
        }
Esempio n. 2
0
        public ScrollContainer(Vector2 position, Vector2 size) : base(position, size)
        {
            contents       = new List <UIElement>();
            scrollLocation = 0;

            backBuffer             = new PixelEngine.Sprite(SpaceGame.Instance.ScreenWidth, SpaceGame.Instance.ScreenHeight);
            scrollBar              = new TextButton((0, 0), (1, 1), "");
            scrollBar.OnMouseHeld += HandleScroll;

            Random rng = new Random();

            for (int i = 0; i < 100; i++)
            {
                contents.Add(new TextButton((position.x, position.y /*+ (i * 10)*/), $"{i}")
                {
                    currentColours = UIColourCollection.DefaultUp
                });