Advertisement
Guest User

Wut?

a guest
Aug 26th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.22 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4.  
  5. namespace TestEnterSb
  6. {
  7.     public class Game1 : Microsoft.Xna.Framework.Game
  8.     {
  9.         GraphicsDeviceManager mGraphics;
  10.         SpriteBatch mSpriteBatch;
  11.  
  12.         Texture2D mRedSq;
  13.         Texture2D mBlueSq;
  14.  
  15.         BoundingBox mFirstSq;
  16.         Texture2D mFirstTexSq;
  17.  
  18.         BoundingBox mSecondSq;
  19.         Texture2D mSecondTexSq;
  20.  
  21.         MouseState mPreviosMouseState;
  22.         MouseState mNewMouseState;
  23.         Vector2 mMousePos;
  24.  
  25.         int W;
  26.         int H;
  27.  
  28.         int mResSizeNum = 0;
  29.  
  30.         public Game1()
  31.         {
  32.             mGraphics = new GraphicsDeviceManager(this);
  33.             Content.RootDirectory = "Content";
  34.  
  35.             this.IsMouseVisible = true;
  36.  
  37.             W = 1024; // GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
  38.             H = 768; // GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
  39.  
  40.             mGraphics.PreferredBackBufferWidth = W;
  41.             mGraphics.PreferredBackBufferHeight = H;
  42.             //mGraphics.IsFullScreen = true;
  43.  
  44.             Mouse.WindowHandle = Window.Handle;
  45.         }
  46.  
  47.         protected override void Initialize()
  48.         {
  49.             mFirstSq = new BoundingBox(new Vector3(100, 100, 0), new Vector3(200, 200, 0));
  50.             mSecondSq = new BoundingBox(new Vector3(W - 100, H - 100, 0), new Vector3(W, H, 0));
  51.  
  52.             base.Initialize();
  53.         }
  54.  
  55.         protected override void LoadContent()
  56.         {
  57.             mSpriteBatch = new SpriteBatch(GraphicsDevice);
  58.  
  59.             mRedSq = Content.Load<Texture2D>("RedSq");
  60.             mBlueSq = Content.Load<Texture2D>("BlueSq");
  61.  
  62.             mFirstTexSq = mBlueSq;
  63.             mSecondTexSq = mBlueSq;
  64.         }
  65.  
  66.         protected override void Update(GameTime Time)
  67.         {
  68.             mPreviosMouseState = mNewMouseState;
  69.             mNewMouseState = Mouse.GetState();
  70.  
  71.             mMousePos = new Vector2(mNewMouseState.X, mNewMouseState.Y);
  72.  
  73.             ChangeScrSize();
  74.  
  75.             if (CheckMouseEnter(mFirstSq)) mFirstTexSq = mRedSq;
  76.             else mFirstTexSq = mBlueSq;
  77.  
  78.             if (CheckMouseEnter(mSecondSq)) mSecondTexSq = mRedSq;
  79.             else mSecondTexSq = mBlueSq;
  80.  
  81.             base.Update(Time);
  82.         }
  83.  
  84.         private void ChangeScrSize()
  85.         {
  86.             if ((mPreviosMouseState.RightButton == ButtonState.Pressed) &&
  87.                 (mNewMouseState.RightButton == ButtonState.Released))
  88.             {
  89.                 mResSizeNum++;
  90.                 if (mResSizeNum > 2) mResSizeNum = 0;
  91.  
  92.                 if (mResSizeNum == 0)
  93.                 {
  94.                     mGraphics.PreferredBackBufferHeight = 768;
  95.                     mGraphics.PreferredBackBufferWidth = 1024;
  96.                 }
  97.                 if (mResSizeNum == 1)
  98.                 {
  99.                     mGraphics.PreferredBackBufferHeight = 600;
  100.                     mGraphics.PreferredBackBufferWidth = 800;
  101.                 }
  102.                 if (mResSizeNum == 2)
  103.                 {
  104.                     mGraphics.PreferredBackBufferHeight = 300;
  105.                     mGraphics.PreferredBackBufferWidth = 400;
  106.                 }
  107.  
  108.                 mGraphics.ApplyChanges();
  109.  
  110.                 // второй прямоугольник в угол - может вьюпорт надо брать?
  111.                 int W = Window.ClientBounds.Width;
  112.                 int H = Window.ClientBounds.Height;
  113.                 mSecondSq = new BoundingBox(new Vector3(W - 100, H - 100, 0), new Vector3(W, H, 0));
  114.             }
  115.         }
  116.  
  117.  
  118.         protected override void Draw(GameTime Time)
  119.         {
  120.             GraphicsDevice.Clear(Color.TransparentBlack);
  121.  
  122.             mSpriteBatch.Begin();
  123.             mSpriteBatch.Draw(mFirstTexSq, new Vector2(mFirstSq.Min.X, mFirstSq.Min.Y), Color.White);
  124.             mSpriteBatch.Draw(mSecondTexSq, new Vector2(mSecondSq.Min.X, mSecondSq.Min.Y), Color.White);
  125.             mSpriteBatch.End();
  126.  
  127.             base.Draw(Time);
  128.         }
  129.  
  130.         private bool CheckMouseEnter(BoundingBox B)
  131.         {
  132.             return (B.Contains(new Vector3(mMousePos.X, mMousePos.Y, 0)) == ContainmentType.Contains);
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement