SingleControlScreen.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //-----------------------------------------------------------------------------
  2. // SingleControlScreen.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using Microsoft.Xna.Framework;
  8. using Microsoft.Xna.Framework.Input;
  9. using UserInterfaceSample.Controls;
  10. namespace UserInterfaceSample
  11. {
  12. /// <summary>
  13. /// A screen containing single Control. This class serves as a bridge between the 'Controls'
  14. /// UI system and the 'ScreenManager' UI system.
  15. /// </summary>
  16. public class SingleControlScreen : GameScreen
  17. {
  18. /// <summary>
  19. /// The sole Control in this screen. Derived classes can do what they like with it.
  20. /// </summary>
  21. protected Control RootControl;
  22. public override void Draw(GameTime gameTime)
  23. {
  24. if (RootControl != null)
  25. {
  26. Control.BatchDraw(RootControl, ScreenManager.GraphicsDevice, ScreenManager.SpriteBatch, Vector2.Zero, gameTime);
  27. }
  28. base.Draw(gameTime);
  29. }
  30. public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
  31. {
  32. RootControl.Update(gameTime);
  33. base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
  34. }
  35. public override void HandleInput(InputState input)
  36. {
  37. // cancel the current screen if the user presses the back button
  38. PlayerIndex player;
  39. if (input.IsNewButtonPress(Buttons.Back, null, out player))
  40. {
  41. ExitScreen();
  42. }
  43. RootControl.HandleInput(input);
  44. base.HandleInput(input);
  45. }
  46. }
  47. }