This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Stephen M Bennett

By: a guest on Jan 14th, 2009  |  syntax: None  |  size: 5.10 KB  |  views: 227  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // A very quick test to see how much my TV screen shows (or loses)
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Audio;
  8. using Microsoft.Xna.Framework.Content;
  9. using Microsoft.Xna.Framework.GamerServices;
  10. using Microsoft.Xna.Framework.Graphics;
  11. using Microsoft.Xna.Framework.Input;
  12. using Microsoft.Xna.Framework.Media;
  13. using Microsoft.Xna.Framework.Net;
  14. using Microsoft.Xna.Framework.Storage;
  15.  
  16. namespace TestScreenSize
  17. {
  18.     public class Game1 : Microsoft.Xna.Framework.Game
  19.     {
  20.         GraphicsDeviceManager graphics;
  21.         SpriteBatch spriteBatch;
  22.         SpriteFont spriteFont;
  23.         Texture2D textureWhite;
  24.         GamePadState prevGamePadState, currGamePadState;
  25.         int x, y, w, h;
  26.         int current;
  27.  
  28.         public Game1()
  29.         {
  30.             graphics = new GraphicsDeviceManager(this);
  31.             Content.RootDirectory = "Content";
  32.  
  33.             // go to 1280 x 720
  34.             graphics.PreferredBackBufferWidth = 1280;
  35.             graphics.PreferredBackBufferHeight = 720;
  36.         }
  37.  
  38.  
  39.         protected override void Initialize()
  40.         {
  41.             // initial values
  42.             x = 50;
  43.             y = 50;
  44.             w = 1180;
  45.             h = 620;
  46.             current = 0;
  47.  
  48.             base.Initialize();
  49.         }
  50.  
  51.  
  52.         protected override void LoadContent()
  53.         {
  54.             spriteBatch = new SpriteBatch(GraphicsDevice);
  55.             spriteFont = Content.Load<SpriteFont>("SpriteFont1");
  56.  
  57.             // create my own white pixel
  58.             textureWhite = new Texture2D(GraphicsDevice, 1, 1, 1, TextureUsage.None, SurfaceFormat.Color);
  59.             textureWhite.SetData(new Color[] { Color.White });
  60.         }
  61.  
  62.  
  63.         protected override void UnloadContent()
  64.         {
  65.         }
  66.  
  67.  
  68.         protected override void Update(GameTime gameTime)
  69.         {
  70.             prevGamePadState = currGamePadState;
  71.             currGamePadState = GamePad.GetState(PlayerIndex.One);
  72.  
  73.             if (wasButtonPressed(Buttons.Back))
  74.             {
  75.                 Exit();
  76.             }
  77.  
  78.             if (wasButtonPressed(Buttons.DPadDown))
  79.             {
  80.                 current++;
  81.                 if (current > 3) current = 3;
  82.             }
  83.  
  84.             if (wasButtonPressed(Buttons.DPadUp))
  85.             {
  86.                 current--;
  87.                 if (current < 0) current = 0;
  88.             }
  89.  
  90.             if (wasButtonPressed(Buttons.DPadLeft))
  91.             {
  92.                 if (current == 0) x--;
  93.                 if (current == 1) y--;
  94.                 if (current == 2) w--;
  95.                 if (current == 3) h--;
  96.             }
  97.  
  98.             if (wasButtonPressed(Buttons.DPadRight))
  99.             {
  100.                 if (current == 0) x++;
  101.                 if (current == 1) y++;
  102.                 if (current == 2) w++;
  103.                 if (current == 3) h++;
  104.             }
  105.  
  106.             base.Update(gameTime);
  107.         }
  108.  
  109.  
  110.         private bool wasButtonPressed(Buttons button)
  111.         {
  112.             return (currGamePadState.IsButtonDown(button) && prevGamePadState.IsButtonUp(button));
  113.         }
  114.  
  115.  
  116.         protected override void Draw(GameTime gameTime)
  117.         {
  118.             GraphicsDevice.Clear(Color.CornflowerBlue);
  119.  
  120.             spriteBatch.Begin();
  121.  
  122.             spriteBatch.Draw(textureWhite, new Rectangle(x, y, w, h), Color.Red);
  123.             spriteBatch.Draw(textureWhite, new Rectangle(x + 2, y + 2, w - 4, h - 4), Color.CornflowerBlue);
  124.  
  125.             int tx = 100;
  126.             int ty = 80;
  127.             int tyd = 44;
  128.  
  129.             String s = "x = " + x;
  130.             Color c = Color.Black;
  131.             if (current == 0) c = Color.Red;
  132.             spriteBatch.DrawString(spriteFont, s, new Vector2(tx, ty), c);
  133.             ty += tyd;
  134.  
  135.             s = "y = " + y;
  136.             c = Color.Black;
  137.             if (current == 1) c = Color.Red;
  138.             spriteBatch.DrawString(spriteFont, s, new Vector2(tx, ty), c);
  139.             ty += tyd;
  140.  
  141.             s = "w = " + w + " which is "+(w*100.0/1280.0)+"%";
  142.             c = Color.Black;
  143.             if (current == 2) c = Color.Red;
  144.             spriteBatch.DrawString(spriteFont, s, new Vector2(tx, ty), c);
  145.             ty += tyd;
  146.  
  147.             s = "h = " + h + " which is "+(h*100.0/720.0)+"%";;
  148.             c = Color.Black;
  149.             if (current == 3) c = Color.Red;
  150.             spriteBatch.DrawString(spriteFont, s, new Vector2(tx, ty), c);
  151.             ty += tyd;
  152.             ty += tyd;
  153.             ty += tyd;
  154.  
  155.             s = "DPad Up/Down to select a dimensional attribute.";
  156.             spriteBatch.DrawString(spriteFont, s, new Vector2(tx, ty), Color.Black);
  157.             ty += tyd;
  158.  
  159.             s = "DPad Left/Right to decrease/increase that attribute.";
  160.             spriteBatch.DrawString(spriteFont, s, new Vector2(tx, ty), Color.Black);
  161.             ty += tyd;
  162.  
  163.             s = "Get the red border to the edge of your TV screen";
  164.             spriteBatch.DrawString(spriteFont, s, new Vector2(tx, ty), Color.Black);
  165.  
  166.             spriteBatch.End();
  167.  
  168.             base.Draw(gameTime);
  169.         }
  170.     }
  171. }
clone this paste RAW Paste Data