InputReporterGame.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // InputReporterGame.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using Microsoft.Xna.Framework;
  12. using Microsoft.Xna.Framework.Content;
  13. using Microsoft.Xna.Framework.Graphics;
  14. using Microsoft.Xna.Framework.Input;
  15. #endregion
  16. namespace InputReporter
  17. {
  18. /// <summary>
  19. /// Displays live input values for all connected controllers.
  20. /// </summary>
  21. partial class InputReporterGame : Microsoft.Xna.Framework.Game
  22. {
  23. #region Image Positions
  24. private static readonly Vector2[] connectedControllerPositions = new Vector2[4]
  25. {
  26. new Vector2(606f, 60f),
  27. new Vector2(656f, 60f),
  28. new Vector2(606f, 110f),
  29. new Vector2(656f, 110f),
  30. };
  31. private static readonly Vector2[] selectedControllerPositions = new Vector2[4]
  32. {
  33. new Vector2(594f, 36f),
  34. new Vector2(686f, 36f),
  35. new Vector2(594f, 137f),
  36. new Vector2(686f, 137f),
  37. };
  38. #endregion
  39. #region Text Positions
  40. private static readonly Vector2 titlePosition =
  41. new Vector2(180f, 73f);
  42. private static readonly Vector2 typeCenterPosition =
  43. new Vector2(660f, 270f);
  44. private static readonly Vector2 descriptionColumn1Position =
  45. new Vector2(65f, 135f);
  46. private static readonly Vector2 valueColumn1Position =
  47. new Vector2(220f, 135f);
  48. private static readonly Vector2 descriptionColumn2Position =
  49. new Vector2(310f, 135f);
  50. private static readonly Vector2 valueColumn2Position =
  51. new Vector2(472f, 135f);
  52. private static readonly Vector2 deadZoneInstructionsPosition =
  53. new Vector2(570f, 380f);
  54. private static readonly Vector2 exitInstructionsPosition =
  55. new Vector2(618f, 425f);
  56. #endregion
  57. #region Text Colors
  58. private static readonly Color titleColor = new Color(60, 134, 11);
  59. private static readonly Color typeColor = new Color(38, 108, 87);
  60. private static readonly Color descriptionColor = new Color(33, 89, 15);
  61. private static readonly Color valueColor = new Color(38, 108, 87);
  62. private static readonly Color disabledColor = new Color(171, 171, 171);
  63. private static readonly Color instructionsColor = new Color(127, 130, 127);
  64. #endregion
  65. #region ChargeSwitch Durations
  66. private const float deadZoneChargeSwitchDuration = 2f;
  67. private const float exitChargeSwitchDuration = 2f;
  68. #endregion
  69. #region Input Data
  70. private int selectedPlayer;
  71. private GamePadState[] gamePadStates = new GamePadState[4];
  72. private GamePadCapabilities[] gamePadCapabilities = new GamePadCapabilities[4];
  73. private KeyboardState lastKeyboardState;
  74. #endregion
  75. #region Dead Zone Data
  76. private GamePadDeadZone deadZone = GamePadDeadZone.IndependentAxes;
  77. public GamePadDeadZone DeadZone
  78. {
  79. get { return deadZone; }
  80. set
  81. {
  82. deadZone = value;
  83. deadZoneString = "(" + deadZone.ToString() + ")";
  84. if (dataFont != null)
  85. {
  86. Vector2 deadZoneStringSize =
  87. dataFont.MeasureString(deadZoneString);
  88. deadZoneStringPosition = new Vector2(
  89. (float)Math.Floor(deadZoneStringCenterPosition.X -
  90. deadZoneStringSize.X / 2f),
  91. (float)Math.Floor(deadZoneStringCenterPosition.Y -
  92. deadZoneStringSize.Y / 2f));
  93. }
  94. }
  95. }
  96. private string deadZoneString;
  97. private Vector2 deadZoneStringPosition;
  98. private Vector2 deadZoneStringCenterPosition;
  99. #endregion
  100. #region ChargeSwitches
  101. private ChargeSwitchExit exitSwitch =
  102. new ChargeSwitchExit(exitChargeSwitchDuration);
  103. private ChargeSwitchDeadZone deadZoneSwitch =
  104. new ChargeSwitchDeadZone(deadZoneChargeSwitchDuration);
  105. #endregion
  106. #region Graphics Data
  107. private GraphicsDeviceManager graphics;
  108. private SpriteBatch spriteBatch;
  109. private SpriteFont titleFont;
  110. private SpriteFont dataFont;
  111. private SpriteFont dataActiveFont;
  112. private SpriteFont typeFont;
  113. private SpriteFont instructionsFont;
  114. private SpriteFont instructionsActiveFont;
  115. private Texture2D backgroundTexture;
  116. private Texture2D[] connectedControllerTextures = new Texture2D[4];
  117. private Texture2D[] selectedControllerTextures = new Texture2D[4];
  118. private float dataSpacing;
  119. #endregion
  120. #region Initialization
  121. /// <summary>
  122. /// Primary constructor.
  123. /// </summary>
  124. public InputReporterGame()
  125. {
  126. graphics = new GraphicsDeviceManager(this);
  127. graphics.PreferredBackBufferWidth = 853;
  128. graphics.PreferredBackBufferHeight = 480;
  129. Content.RootDirectory = "Content";
  130. exitSwitch.Fire += new ChargeSwitch.FireDelegate(exitSwitch_Fire);
  131. deadZoneSwitch.Fire += new ChargeSwitch.FireDelegate(ToggleDeadZone);
  132. }
  133. /// <summary>
  134. /// Allows the game to perform any initialization it needs to before starting
  135. /// to run. This is where it can query for any required services and load any
  136. /// non-graphic related content. Calling base.Initialize will enumerate through
  137. /// any components and initialize them as well.
  138. /// </summary>
  139. protected override void Initialize()
  140. {
  141. selectedPlayer = 0;
  142. exitSwitch.Reset(exitChargeSwitchDuration);
  143. deadZoneSwitch.Reset(deadZoneChargeSwitchDuration);
  144. base.Initialize();
  145. DeadZone = GamePadDeadZone.IndependentAxes;
  146. }
  147. #endregion
  148. #region Graphics Load/Unload
  149. /// <summary>
  150. /// Load your graphics content.
  151. /// </summary>
  152. /// <param name="loadAllContent">Which type of content to load.</param>
  153. protected override void LoadContent()
  154. {
  155. spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
  156. titleFont = Content.Load<SpriteFont>("Fonts\\TitleFont");
  157. dataFont = Content.Load<SpriteFont>("Fonts\\DataFont");
  158. dataActiveFont = Content.Load<SpriteFont>("Fonts\\DataActiveFont");
  159. typeFont = Content.Load<SpriteFont>("Fonts\\TypeFont");
  160. instructionsFont = Content.Load<SpriteFont>("Fonts\\InstructionsFont");
  161. instructionsActiveFont =
  162. Content.Load<SpriteFont>("Fonts\\InstructionsActiveFont");
  163. dataSpacing = (float)Math.Floor(dataFont.LineSpacing * 1.3f);
  164. deadZoneStringCenterPosition = new Vector2(687f,
  165. (float)Math.Floor(deadZoneInstructionsPosition.Y +
  166. dataFont.LineSpacing * 1.7f));
  167. backgroundTexture = Content.Load<Texture2D>("Textures\\background");
  168. connectedControllerTextures[0] =
  169. Content.Load<Texture2D>("Textures\\connected_controller1");
  170. connectedControllerTextures[1] =
  171. Content.Load<Texture2D>("Textures\\connected_controller2");
  172. connectedControllerTextures[2] =
  173. Content.Load<Texture2D>("Textures\\connected_controller3");
  174. connectedControllerTextures[3] =
  175. Content.Load<Texture2D>("Textures\\connected_controller4");
  176. selectedControllerTextures[0] =
  177. Content.Load<Texture2D>("Textures\\select_controller1");
  178. selectedControllerTextures[1] =
  179. Content.Load<Texture2D>("Textures\\select_controller2");
  180. selectedControllerTextures[2] =
  181. Content.Load<Texture2D>("Textures\\select_controller3");
  182. selectedControllerTextures[3] =
  183. Content.Load<Texture2D>("Textures\\select_controller4");
  184. }
  185. #endregion
  186. #region Updating
  187. /// <summary>
  188. /// Allows the game to run logic such as updating the world,
  189. /// checking for collisions, gathering input and playing audio.
  190. /// </summary>
  191. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  192. protected override void Update(GameTime gameTime)
  193. {
  194. KeyboardState keyboardState = Keyboard.GetState();
  195. if (keyboardState.IsKeyDown(Keys.Escape))
  196. {
  197. this.Exit();
  198. }
  199. if (keyboardState.IsKeyDown(Keys.Space) &&
  200. !lastKeyboardState.IsKeyDown(Keys.Space))
  201. {
  202. ToggleDeadZone();
  203. }
  204. bool setSelectedPlayer = false; // give preference to earlier controllers
  205. for (int i = 0; i < 4; i++)
  206. {
  207. gamePadStates[i] = GamePad.GetState((PlayerIndex)i, deadZone);
  208. gamePadCapabilities[i] = GamePad.GetCapabilities((PlayerIndex)i);
  209. if (!setSelectedPlayer && IsActiveGamePad(ref gamePadStates[i]))
  210. {
  211. selectedPlayer = i;
  212. setSelectedPlayer = true;
  213. }
  214. }
  215. deadZoneSwitch.Update(gameTime, ref gamePadStates[selectedPlayer]);
  216. exitSwitch.Update(gameTime, ref gamePadStates[selectedPlayer]);
  217. base.Update(gameTime);
  218. lastKeyboardState = keyboardState;
  219. }
  220. /// <summary>
  221. /// Determines if the provided GamePadState is "active".
  222. /// </summary>
  223. /// <param name="gamePadState">The GamePadState that is checked.</param>
  224. /// <remarks>
  225. /// "Active" currently means that at least one of the buttons is being pressed.
  226. /// </remarks>
  227. /// <returns>True if "active".</returns>
  228. private static bool IsActiveGamePad(ref GamePadState gamePadState)
  229. {
  230. return (gamePadState.IsConnected &&
  231. ((gamePadState.Buttons.A == ButtonState.Pressed) ||
  232. (gamePadState.Buttons.B == ButtonState.Pressed) ||
  233. (gamePadState.Buttons.X == ButtonState.Pressed) ||
  234. (gamePadState.Buttons.Y == ButtonState.Pressed) ||
  235. (gamePadState.Buttons.Start == ButtonState.Pressed) ||
  236. (gamePadState.Buttons.Back == ButtonState.Pressed) ||
  237. (gamePadState.Buttons.LeftShoulder == ButtonState.Pressed) ||
  238. (gamePadState.Buttons.RightShoulder == ButtonState.Pressed) ||
  239. (gamePadState.Buttons.LeftStick == ButtonState.Pressed) ||
  240. (gamePadState.Buttons.RightStick == ButtonState.Pressed) ||
  241. (gamePadState.DPad.Up == ButtonState.Pressed) ||
  242. (gamePadState.DPad.Left == ButtonState.Pressed) ||
  243. (gamePadState.DPad.Right == ButtonState.Pressed) ||
  244. (gamePadState.DPad.Down == ButtonState.Pressed)));
  245. }
  246. #endregion
  247. #region Drawing
  248. /// <summary>
  249. /// This is called when the game should draw itself.
  250. /// </summary>
  251. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  252. protected override void Draw(GameTime gameTime)
  253. {
  254. graphics.GraphicsDevice.Clear(Color.Black);
  255. base.Draw(gameTime);
  256. spriteBatch.Begin();
  257. // draw the background
  258. spriteBatch.Draw(backgroundTexture, Vector2.Zero, Color.White);
  259. // draw the connected-controller images
  260. for (int i = 0; i < 4; i++)
  261. {
  262. if (gamePadStates[i].IsConnected)
  263. {
  264. spriteBatch.Draw(connectedControllerTextures[i],
  265. connectedControllerPositions[i], Color.White);
  266. }
  267. }
  268. // draw the selected-player texture (numeral)
  269. spriteBatch.Draw(selectedControllerTextures[selectedPlayer],
  270. selectedControllerPositions[selectedPlayer], Color.White);
  271. // draw controller title
  272. string text = InputReporterResources.Title +
  273. ((PlayerIndex)selectedPlayer).ToString();
  274. spriteBatch.DrawString(titleFont, text, titlePosition,
  275. titleColor);
  276. // draw controller type
  277. text = gamePadCapabilities[selectedPlayer].GamePadType.ToString();
  278. Vector2 textSize = typeFont.MeasureString(text);
  279. spriteBatch.DrawString(typeFont, text, new Vector2(
  280. (float)Math.Floor(typeCenterPosition.X -
  281. textSize.X / 2f),
  282. (float)Math.Floor(typeCenterPosition.Y -
  283. textSize.Y / 2f)),
  284. typeColor);
  285. // draw the data
  286. DrawData(ref gamePadStates[selectedPlayer],
  287. ref gamePadCapabilities[selectedPlayer]);
  288. // draw the instructions
  289. spriteBatch.DrawString(deadZoneSwitch.Active ? instructionsActiveFont :
  290. instructionsFont, InputReporterResources.DeadZoneInstructions,
  291. deadZoneInstructionsPosition, instructionsColor);
  292. spriteBatch.DrawString(instructionsFont, deadZoneString,
  293. deadZoneStringPosition, instructionsColor);
  294. spriteBatch.DrawString(exitSwitch.Active ? instructionsActiveFont :
  295. instructionsFont, InputReporterResources.ExitInstructions,
  296. exitInstructionsPosition, instructionsColor);
  297. spriteBatch.End();
  298. }
  299. /// <summary>
  300. /// Draw all data for a set of GamePad data and capabilities.
  301. /// </summary>
  302. /// <param name="gamePadState">The GamePad data.</param>
  303. /// <param name="gamePadCapabilities">The GamePad capabilities.</param>
  304. /// <remarks>
  305. /// The GamePad structures are passed by reference for speed. They are not
  306. /// modified in this method.
  307. /// </remarks>
  308. private void DrawData(ref GamePadState gamePadState,
  309. ref GamePadCapabilities gamePadCapabilities)
  310. {
  311. //
  312. // Draw the first column of data
  313. //
  314. Vector2 descriptionPosition = descriptionColumn1Position;
  315. Vector2 valuePosition = valueColumn1Position;
  316. // draw left thumbstick data
  317. DrawValue(InputReporterResources.LeftThumbstickX, ref descriptionPosition,
  318. gamePadState.ThumbSticks.Left.X.ToString("0.000"), ref valuePosition,
  319. gamePadCapabilities.HasLeftXThumbStick,
  320. gamePadState.ThumbSticks.Left.X != 0f);
  321. DrawValue(InputReporterResources.LeftThumbstickY, ref descriptionPosition,
  322. gamePadState.ThumbSticks.Left.Y.ToString("0.000"), ref valuePosition,
  323. gamePadCapabilities.HasLeftYThumbStick,
  324. gamePadState.ThumbSticks.Left.Y != 0f);
  325. // draw the right thumbstick data
  326. DrawValue(InputReporterResources.RightThumbstickX, ref descriptionPosition,
  327. gamePadState.ThumbSticks.Right.X.ToString("0.000"), ref valuePosition,
  328. gamePadCapabilities.HasRightXThumbStick,
  329. gamePadState.ThumbSticks.Right.X != 0f);
  330. DrawValue(InputReporterResources.RightThumbstickY, ref descriptionPosition,
  331. gamePadState.ThumbSticks.Right.Y.ToString("0.000"), ref valuePosition,
  332. gamePadCapabilities.HasRightYThumbStick,
  333. gamePadState.ThumbSticks.Right.Y != 0f);
  334. descriptionPosition.Y += dataSpacing;
  335. valuePosition.Y += dataSpacing;
  336. // draw the trigger data
  337. DrawValue(InputReporterResources.LeftTrigger, ref descriptionPosition,
  338. gamePadState.Triggers.Left.ToString("0.000"), ref valuePosition,
  339. gamePadCapabilities.HasLeftTrigger,
  340. gamePadState.Triggers.Left != 0f);
  341. DrawValue(InputReporterResources.RightTrigger, ref descriptionPosition,
  342. gamePadState.Triggers.Right.ToString("0.000"), ref valuePosition,
  343. gamePadCapabilities.HasRightTrigger,
  344. gamePadState.Triggers.Right != 0f);
  345. descriptionPosition.Y += dataSpacing;
  346. valuePosition.Y += dataSpacing;
  347. // draw the directional pad data
  348. DrawValue(InputReporterResources.DPadUp, ref descriptionPosition,
  349. (gamePadState.DPad.Up == ButtonState.Pressed ?
  350. InputReporterResources.ButtonPressed :
  351. InputReporterResources.ButtonReleased), ref valuePosition,
  352. gamePadCapabilities.HasDPadUpButton,
  353. gamePadState.DPad.Up == ButtonState.Pressed);
  354. DrawValue(InputReporterResources.DPadDown, ref descriptionPosition,
  355. (gamePadState.DPad.Down == ButtonState.Pressed ?
  356. InputReporterResources.ButtonPressed :
  357. InputReporterResources.ButtonReleased), ref valuePosition,
  358. gamePadCapabilities.HasDPadDownButton,
  359. gamePadState.DPad.Down == ButtonState.Pressed);
  360. DrawValue(InputReporterResources.DPadLeft, ref descriptionPosition,
  361. (gamePadState.DPad.Left == ButtonState.Pressed ?
  362. InputReporterResources.ButtonPressed :
  363. InputReporterResources.ButtonReleased), ref valuePosition,
  364. gamePadCapabilities.HasDPadLeftButton,
  365. gamePadState.DPad.Left == ButtonState.Pressed);
  366. DrawValue(InputReporterResources.DPadRight, ref descriptionPosition,
  367. (gamePadState.DPad.Right == ButtonState.Pressed ?
  368. InputReporterResources.ButtonPressed :
  369. InputReporterResources.ButtonReleased), ref valuePosition,
  370. gamePadCapabilities.HasDPadRightButton,
  371. gamePadState.DPad.Right == ButtonState.Pressed);
  372. descriptionPosition.Y += dataSpacing;
  373. valuePosition.Y += dataSpacing;
  374. // draw the vibration data
  375. if (gamePadCapabilities.HasLeftVibrationMotor)
  376. {
  377. if (gamePadCapabilities.HasRightVibrationMotor)
  378. {
  379. spriteBatch.DrawString(dataFont,
  380. InputReporterResources.BothVibrationMotors, descriptionPosition,
  381. descriptionColor);
  382. }
  383. else
  384. {
  385. spriteBatch.DrawString(dataFont,
  386. InputReporterResources.LeftVibrationMotor, descriptionPosition,
  387. descriptionColor);
  388. }
  389. }
  390. else if (gamePadCapabilities.HasRightVibrationMotor)
  391. {
  392. spriteBatch.DrawString(dataFont,
  393. InputReporterResources.RightVibrationMotor, descriptionPosition,
  394. descriptionColor);
  395. }
  396. else
  397. {
  398. spriteBatch.DrawString(dataFont, InputReporterResources.NoVibration,
  399. descriptionPosition, descriptionColor);
  400. }
  401. //
  402. // Draw the second column of data
  403. //
  404. descriptionPosition = descriptionColumn2Position;
  405. valuePosition = valueColumn2Position;
  406. // draw the button data
  407. DrawValue(InputReporterResources.A, ref descriptionPosition,
  408. (gamePadState.Buttons.A == ButtonState.Pressed ?
  409. InputReporterResources.ButtonPressed :
  410. InputReporterResources.ButtonReleased), ref valuePosition,
  411. gamePadCapabilities.HasAButton,
  412. gamePadState.Buttons.A == ButtonState.Pressed);
  413. DrawValue(InputReporterResources.B, ref descriptionPosition,
  414. (gamePadState.Buttons.B == ButtonState.Pressed ?
  415. InputReporterResources.ButtonPressed :
  416. InputReporterResources.ButtonReleased), ref valuePosition,
  417. gamePadCapabilities.HasBButton,
  418. gamePadState.Buttons.B == ButtonState.Pressed);
  419. DrawValue(InputReporterResources.X, ref descriptionPosition,
  420. (gamePadState.Buttons.X == ButtonState.Pressed ?
  421. InputReporterResources.ButtonPressed :
  422. InputReporterResources.ButtonReleased), ref valuePosition,
  423. gamePadCapabilities.HasXButton,
  424. gamePadState.Buttons.X == ButtonState.Pressed);
  425. DrawValue(InputReporterResources.Y, ref descriptionPosition,
  426. (gamePadState.Buttons.Y == ButtonState.Pressed ?
  427. InputReporterResources.ButtonPressed :
  428. InputReporterResources.ButtonReleased), ref valuePosition,
  429. gamePadCapabilities.HasYButton,
  430. gamePadState.Buttons.Y == ButtonState.Pressed);
  431. DrawValue(InputReporterResources.LeftShoulder, ref descriptionPosition,
  432. (gamePadState.Buttons.LeftShoulder == ButtonState.Pressed ?
  433. InputReporterResources.ButtonPressed :
  434. InputReporterResources.ButtonReleased), ref valuePosition,
  435. gamePadCapabilities.HasLeftShoulderButton,
  436. gamePadState.Buttons.LeftShoulder == ButtonState.Pressed);
  437. DrawValue(InputReporterResources.RightShoulder, ref descriptionPosition,
  438. (gamePadState.Buttons.RightShoulder == ButtonState.Pressed ?
  439. InputReporterResources.ButtonPressed :
  440. InputReporterResources.ButtonReleased), ref valuePosition,
  441. gamePadCapabilities.HasRightShoulderButton,
  442. gamePadState.Buttons.RightShoulder == ButtonState.Pressed);
  443. DrawValue(InputReporterResources.LeftStick, ref descriptionPosition,
  444. (gamePadState.Buttons.LeftStick == ButtonState.Pressed ?
  445. InputReporterResources.ButtonPressed :
  446. InputReporterResources.ButtonReleased), ref valuePosition,
  447. gamePadCapabilities.HasLeftStickButton,
  448. gamePadState.Buttons.LeftStick == ButtonState.Pressed);
  449. DrawValue(InputReporterResources.RightStick, ref descriptionPosition,
  450. (gamePadState.Buttons.RightStick == ButtonState.Pressed ?
  451. InputReporterResources.ButtonPressed :
  452. InputReporterResources.ButtonReleased), ref valuePosition,
  453. gamePadCapabilities.HasRightStickButton,
  454. gamePadState.Buttons.RightStick == ButtonState.Pressed);
  455. DrawValue(InputReporterResources.Start, ref descriptionPosition,
  456. (gamePadState.Buttons.Start == ButtonState.Pressed ?
  457. InputReporterResources.ButtonPressed :
  458. InputReporterResources.ButtonReleased), ref valuePosition,
  459. gamePadCapabilities.HasStartButton,
  460. gamePadState.Buttons.Start == ButtonState.Pressed);
  461. DrawValue(InputReporterResources.Back, ref descriptionPosition,
  462. (gamePadState.Buttons.Back == ButtonState.Pressed ?
  463. InputReporterResources.ButtonPressed :
  464. InputReporterResources.ButtonReleased), ref valuePosition,
  465. gamePadCapabilities.HasBackButton,
  466. gamePadState.Buttons.Back == ButtonState.Pressed);
  467. descriptionPosition.Y += dataSpacing;
  468. valuePosition.Y += dataSpacing;
  469. // draw the packet number data
  470. DrawValue(InputReporterResources.PacketNumber, ref descriptionPosition,
  471. gamePadState.PacketNumber.ToString(), ref valuePosition,
  472. gamePadCapabilities.IsConnected, false);
  473. }
  474. /// <summary>
  475. /// Draw a single description/value pair.
  476. /// </summary>
  477. /// <param name="description">The description of the value.</param>
  478. /// <param name="descriptionPosition">The position of the description.</param>
  479. /// <param name="value">The value itself.</param>
  480. /// <param name="valuePosition">The position of the value.</param>
  481. /// <param name="enabled">If true, the value type is supported.</param>
  482. /// <param name="active">If true, the value type is active right now.</param>
  483. /// <remarks>
  484. /// The positions are modified by this function, moving down one line.
  485. /// </remarks>
  486. private void DrawValue(string description, ref Vector2 descriptionPosition,
  487. string value, ref Vector2 valuePosition, bool enabled, bool active)
  488. {
  489. spriteBatch.DrawString(dataFont, description, descriptionPosition,
  490. enabled ? descriptionColor : disabledColor);
  491. descriptionPosition.Y += dataSpacing;
  492. spriteBatch.DrawString(active ? dataActiveFont : dataFont,
  493. value, valuePosition, enabled ? valueColor : disabledColor);
  494. valuePosition.Y += dataSpacing;
  495. }
  496. #endregion
  497. #region ChargeSwitch Event Handlers
  498. /// <summary>
  499. /// Handles the dead-zone ChargeSwitch fire event. Toggles dead zone types.
  500. /// </summary>
  501. private void ToggleDeadZone()
  502. {
  503. switch (DeadZone)
  504. {
  505. case GamePadDeadZone.IndependentAxes:
  506. DeadZone = GamePadDeadZone.Circular;
  507. break;
  508. case GamePadDeadZone.Circular:
  509. DeadZone = GamePadDeadZone.None;
  510. break;
  511. case GamePadDeadZone.None:
  512. DeadZone = GamePadDeadZone.IndependentAxes;
  513. break;
  514. }
  515. }
  516. /// <summary>
  517. /// Handles the exit ChargeSwitch fire event. Exits the application.
  518. /// </summary>
  519. private void exitSwitch_Fire()
  520. {
  521. this.Exit();
  522. }
  523. #endregion
  524. // #region Entry Point
  525. // /// <summary>
  526. // /// The main entry point for the application.
  527. // /// </summary>
  528. // static void Main()
  529. // {
  530. // using (InputReporterGame game = new InputReporterGame())
  531. // {
  532. // game.Run();
  533. // }
  534. // }
  535. // #endregion
  536. }
  537. }