Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- namespace TestEnterSb
- {
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager mGraphics;
- SpriteBatch mSpriteBatch;
- Texture2D mRedSq;
- Texture2D mBlueSq;
- BoundingBox mFirstSq;
- Texture2D mFirstTexSq;
- BoundingBox mSecondSq;
- Texture2D mSecondTexSq;
- MouseState mPreviosMouseState;
- MouseState mNewMouseState;
- Vector2 mMousePos;
- int W;
- int H;
- int mResSizeNum = 0;
- public Game1()
- {
- mGraphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- this.IsMouseVisible = true;
- W = 1024; // GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
- H = 768; // GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
- mGraphics.PreferredBackBufferWidth = W;
- mGraphics.PreferredBackBufferHeight = H;
- //mGraphics.IsFullScreen = true;
- Mouse.WindowHandle = Window.Handle;
- }
- protected override void Initialize()
- {
- mFirstSq = new BoundingBox(new Vector3(100, 100, 0), new Vector3(200, 200, 0));
- mSecondSq = new BoundingBox(new Vector3(W - 100, H - 100, 0), new Vector3(W, H, 0));
- base.Initialize();
- }
- protected override void LoadContent()
- {
- mSpriteBatch = new SpriteBatch(GraphicsDevice);
- mRedSq = Content.Load<Texture2D>("RedSq");
- mBlueSq = Content.Load<Texture2D>("BlueSq");
- mFirstTexSq = mBlueSq;
- mSecondTexSq = mBlueSq;
- }
- protected override void Update(GameTime Time)
- {
- mPreviosMouseState = mNewMouseState;
- mNewMouseState = Mouse.GetState();
- mMousePos = new Vector2(mNewMouseState.X, mNewMouseState.Y);
- ChangeScrSize();
- if (CheckMouseEnter(mFirstSq)) mFirstTexSq = mRedSq;
- else mFirstTexSq = mBlueSq;
- if (CheckMouseEnter(mSecondSq)) mSecondTexSq = mRedSq;
- else mSecondTexSq = mBlueSq;
- base.Update(Time);
- }
- private void ChangeScrSize()
- {
- if ((mPreviosMouseState.RightButton == ButtonState.Pressed) &&
- (mNewMouseState.RightButton == ButtonState.Released))
- {
- mResSizeNum++;
- if (mResSizeNum > 2) mResSizeNum = 0;
- if (mResSizeNum == 0)
- {
- mGraphics.PreferredBackBufferHeight = 768;
- mGraphics.PreferredBackBufferWidth = 1024;
- }
- if (mResSizeNum == 1)
- {
- mGraphics.PreferredBackBufferHeight = 600;
- mGraphics.PreferredBackBufferWidth = 800;
- }
- if (mResSizeNum == 2)
- {
- mGraphics.PreferredBackBufferHeight = 300;
- mGraphics.PreferredBackBufferWidth = 400;
- }
- mGraphics.ApplyChanges();
- // второй прямоугольник в угол - может вьюпорт надо брать?
- int W = Window.ClientBounds.Width;
- int H = Window.ClientBounds.Height;
- mSecondSq = new BoundingBox(new Vector3(W - 100, H - 100, 0), new Vector3(W, H, 0));
- }
- }
- protected override void Draw(GameTime Time)
- {
- GraphicsDevice.Clear(Color.TransparentBlack);
- mSpriteBatch.Begin();
- mSpriteBatch.Draw(mFirstTexSq, new Vector2(mFirstSq.Min.X, mFirstSq.Min.Y), Color.White);
- mSpriteBatch.Draw(mSecondTexSq, new Vector2(mSecondSq.Min.X, mSecondSq.Min.Y), Color.White);
- mSpriteBatch.End();
- base.Draw(Time);
- }
- private bool CheckMouseEnter(BoundingBox B)
- {
- return (B.Contains(new Vector3(mMousePos.X, mMousePos.Y, 0)) == ContainmentType.Contains);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement