public void ResizeItemWidths() { for (int i = 0; i < scrollItems.Count; i++) { ScrollContainer sContainer = scrollItems[i]; sContainer.Width = fixedSize.X - ScrollBoxSize.X; sContainer.ResetWidth(); } }
public void RefreshRT() { RenderTarget2D rt = UI2D.Shared.RenderTarget1024_768; if (dirty || hackFrame == Time.FrameCounter || rt.IsContentLost) { // Force another refresh 4 frames after dirty is set. // Yes, this is an utterly absurd hack. But for some reason at startup // the rt isn't fully rendered. By waiting 4 or more frames and then // refreshing again, it works. No clue why. if (dirty) { hackFrame = Time.FrameCounter + 4; } GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; device.SetRenderTarget(rt); SetViewPort(false, rt); device.Clear(Color.White); Vector2 pos = new Vector2(0.0f, 0.0f); ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance(); SpriteBatch batch = UI2D.Shared.SpriteBatch; Vector2 baseSize = FixedSize; Vector4 drawColor = GetDrawColor(); Texture2D buttonTexture = UI2D.Shared.BlackButtonTexture; // Render rectangular baseplate of scroller (maybe a transparent texture...). ssquad.Render(color_bgCurr, pos, baseSize - new Vector2(ScrollBoxSize.X, 0.0f)); // Render scroll bar if (TotalContainerHeight > FixedSize.Y) { Vector2 barpos = GetBoxPos(); barpos.Y += pos.Y; ssquad.Render(color_BarBase, new Vector2(barpos.X + (ScrollBoxSize.X / 2.2f), 0.0f), new Vector2(ScrollBoxSize.X / 9.0f, baseSize.Y)); ssquad.Render(color_Bar, barpos, ScrollBoxSize); } Vector2 seperatorSize = fixedSize; seperatorSize.X -= ScrollBoxSize.X; seperatorSize.Y = seperatorHeight; float pastScrollDist = 0.0f; indexFirstVisibleItem = -1; indexLastVisibleItem = -1; float prevContainerHeight = 0.0f; for (int i = 0; i < scrollItems.Count; i++) { ScrollContainer sContainer = scrollItems[i]; Vector2 itemPos = pos; itemPos.Y -= scrollOffset - pastScrollDist - seperatorHeight * i; if (sContainer.Height >= ((scrollOffset - pastScrollDist) - sContainer.Height - prevContainerHeight)) { if (indexFocusedItem == i) { ssquad.Render(color_FocusItemBase, itemPos, new Vector2(sContainer.Width, sContainer.Height)); } sContainer.ResetWidth(); sContainer.Render(itemPos); if (indexFirstVisibleItem < 0) { indexFirstVisibleItem = i; } if (itemPos.Y + 60 < (FixedSize.Y + relativePosition.Y)) { indexLastVisibleItem = i; } } scrollItems[i].UpdatePosition(itemPos); prevContainerHeight = sContainer.Height; pastScrollDist += sContainer.Height; Vector2 seperatorOffset = pos; seperatorOffset.Y += pastScrollDist - scrollOffset; ssquad.Render(color_seperator, seperatorOffset, seperatorSize); } RestoreViewport(); device.SetRenderTarget(null); dirty = false; } // end if dirty } // end of RefreshRT()