123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- using System.Windows.Forms;
- using MonoMac.AppKit;
- using MonoMac.Foundation;
- namespace MouseGetStateAndIsMouseVisibleTester
- {
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- public TextManager aTm;
- public InputManager cIm;
- private SpriteFont sfStandard;
- public MouseState mousestatus;
- public Texture2D t2dUiCursor;
- public Object aObjects;
- bool bWindowIsCentered = false;
- bool bFullScreen = false;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- cIm = new InputManager(this);
- Window.AllowUserResizing = true;
- // Subscribe to the game window's ClientSizeChanged event.
- Window.ClientSizeChanged += Window_ClientSizeChanged;
- }
- void Window_ClientSizeChanged( object sender, EventArgs e )
- {
- // Make changes to handle the new window size.
- Console.WriteLine("Window size changed " + Window.ClientBounds);
- }
- protected override void Initialize()
- {
- // TODO: Add your initialization logic here
- base.Initialize();
- }
- protected override void LoadContent()
- {
- // Create a new SpriteBatch, which can be used to draw textures.
- spriteBatch = new SpriteBatch(GraphicsDevice);
- Services.AddService(typeof(SpriteBatch), spriteBatch);
- sfStandard = Content.Load<SpriteFont>("fntStandard");
- t2dUiCursor = Content.Load<Texture2D>("UiCursor");
- aTm = new TextManager(this, sfStandard);
- Components.Add(aTm);
- aObjects = new Object(this, ref t2dUiCursor);
- Components.Add(aObjects);
- aObjects.pos.X = 200;
- aObjects.pos.Y = 200;
- //this.Window.Window.StyleMask = this.Window.Window.StyleMask | NSWindowStyle.Miniaturizable;
- }
- protected override void UnloadContent()
- {
- // TODO: Unload any non ContentManager content here
- }
- public void Toggle()
- {
- graphics.ToggleFullScreen();
-
- if(bFullScreen)
- {
- bFullScreen = false;
- }//if
- else
- {
- bFullScreen = true;
- }//else
- }//Toggle
- public int GetBackBufferWidth()
- {
- return graphics.PreferredBackBufferWidth;
- }//GetBackBufferWidth
- public int GetBackBufferHeight()
- {
- return graphics.PreferredBackBufferHeight;
- }//GetBackBufferWidth
-
- public String GetStyleMask()
- {
- return this.Window.Window.StyleMask.ToString();
- }//GetStyleMask
- protected override void Update(GameTime gameTime)
- {
- mousestatus = Mouse.GetState();
- cIm.InputHandler(mousestatus, gameTime);
- aObjects.pos.X = mousestatus.X;
- aObjects.pos.Y = mousestatus.Y;
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
-
- GraphicsDevice.Clear(Color.CornflowerBlue);
- spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
- base.Draw(gameTime);
- spriteBatch.End();
-
- }
-
- public void CenterWindow()
- {
- if(bFullScreen) return;
-
-
- int index;
- int upperBound;
- float fScreenWidth, fScreenHeight, fNewX, fNewY, fWindowWidth, fWindowHeight, fTitleBarHeight;
- Screen[] screens = Screen.AllScreens;
-
- fScreenWidth = fScreenHeight = 0;
-
- upperBound = screens.GetUpperBound(0);
- for (index = 0; index <= upperBound; index++)
- {
- if (screens[index].Primary)
- {
- fScreenWidth = (float)screens[index].Bounds.Width;
- fScreenHeight = (float)screens[index].Bounds.Height;
- index = upperBound;
- }//if
- }//for
-
- fWindowWidth = graphics.PreferredBackBufferWidth;
- fWindowHeight = graphics.PreferredBackBufferHeight;
-
- fNewX = (fScreenWidth - fWindowWidth) / 2;
- fNewY = (fScreenHeight - fWindowHeight) / 2;
-
- fTitleBarHeight = this.Window.Window.Frame.Height - fWindowHeight;
-
- System.Drawing.PointF pfLocation = new System.Drawing.PointF(fNewX,fNewY);
- System.Drawing.PointF pfSize = new System.Drawing.PointF(fWindowWidth, fWindowHeight + fTitleBarHeight);
- System.Drawing.SizeF sfSize = new System.Drawing.SizeF(pfSize);
- System.Drawing.RectangleF rectTemp = new System.Drawing.RectangleF(pfLocation, sfSize);
- this.Window.Window.SetFrame(rectTemp, true);
- }//CenterWindow
- }
- }
|