ScrollingPanelControl.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //-----------------------------------------------------------------------------
  2. // ScrollingPanelControl.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using Microsoft.Xna.Framework;
  8. namespace UserInterfaceSample.Controls
  9. {
  10. public class ScrollingPanelControl : PanelControl
  11. {
  12. private ScrollTracker scrollTracker = new ScrollTracker();
  13. public override void Update(GameTime gametime)
  14. {
  15. Vector2 size = ComputeSize();
  16. scrollTracker.CanvasRect.Width = (int)size.X;
  17. scrollTracker.CanvasRect.Height = (int)size.Y;
  18. scrollTracker.Update(gametime);
  19. base.Update(gametime);
  20. }
  21. public override void HandleInput(InputState input)
  22. {
  23. scrollTracker.HandleInput(input);
  24. base.HandleInput(input);
  25. }
  26. public override void Draw(DrawContext context)
  27. {
  28. // To render the scrolled panel, we just adjust our offset before rendering our child controls as
  29. // a normal PanelControl
  30. context.DrawOffset.Y = -scrollTracker.ViewRect.Y;
  31. base.Draw(context);
  32. }
  33. }
  34. }