2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using System.ComponentModel;
7 using Microsoft.Xna.Framework.Graphics;
20 public SizeParams(
int w,
int h,
bool f)
31 public delegate
void MoveEvent(
int oldX,
int oldY,
int newX,
int newY );
36 public delegate
void ResizeEvent(
int oldWidth,
int oldHeight,
int newWidth,
int newHeight);
39 System.Windows.Forms.Form form;
43 GraphicsDeviceManager gdm;
46 Point? desiredPosition = null;
48 SizeParams lastSize = null;
49 SizeParams desiredSize = null;
51 #region Events for XNA compatibility 56 [EditorBrowsable( EditorBrowsableState.Never )]
62 [EditorBrowsable( EditorBrowsableState.Never )]
68 [EditorBrowsable( EditorBrowsableState.Never )]
77 protected void OnXnaMethod( EventHandler<EventArgs> method,
object sender, EventArgs args )
80 method( sender, args );
115 get {
return gwin.AllowUserResizing; }
116 set { gwin.AllowUserResizing = value; }
124 get {
return gwin.CurrentOrientation; }
132 get {
return gwin.Title; }
133 set { gwin.Title = value; }
141 get {
return desiredSize != null ? desiredSize.Width : gwin.ClientBounds.Width; }
145 desiredSize.Width = Math.Max( 1, value );
146 OnResizing( desiredSize );
155 get {
return desiredSize != null ? desiredSize.Height : gwin.ClientBounds.Height; }
159 desiredSize.Height = Math.Max( 1, value );
160 OnResizing( desiredSize );
169 get {
return desiredSize != null ? desiredSize.Fullscreen : gdm.IsFullScreen; }
173 desiredSize.Fullscreen = value;
182 get {
return gwin.Handle; }
190 get {
return gwin.ScreenDeviceName; }
201 return desiredPosition.HasValue ? desiredPosition.Value.X : form.Left;
208 desiredPosition =
new Point( value,
Top );
221 return desiredPosition.HasValue ? desiredPosition.Value.Y : form.Top;
228 desiredPosition =
new Point(
Left, value );
275 internal JypeliWindow( GameWindow gameWindow, GraphicsDeviceManager graphicsDeviceManager )
277 this.gwin = gameWindow;
278 this.gdm = graphicsDeviceManager;
283 gameWindow.OrientationChanged += ( o, a ) =>
OnXnaMethod( this.OrientationChanged, o, a );
284 gameWindow.ScreenDeviceNameChanged += ( o, a ) =>
OnXnaMethod( this.ScreenDeviceNameChanged, o, a );
285 gameWindow.ClientSizeChanged += ( o, a ) => OnResized();
288 form = (
System.Windows.Forms.Form)
System.Windows.Forms.Control.FromHandle( gameWindow.Handle );
289 form.Move += (o, a) => OnMove();
293 private void MakeDesiredParams()
295 if ( desiredSize == null )
296 desiredSize =
new SizeParams( gwin.ClientBounds.Width, gwin.ClientBounds.Height, gdm.IsFullScreen );
299 private void OnMove( SizeParams newParams = null )
301 if ( Moved == null || !lastPosition.HasValue )
305 Moved( lastPosition.Value.X +
Width / 2, lastPosition.Value.Y -
Height / 2, form.Left + form.Width / 2, form.Top - form.Height / 2 );
309 private void OnResizing( SizeParams newParams )
311 if ( Resizing == null )
314 if ( newParams.Width != gwin.ClientBounds.Width || newParams.Height != gwin.ClientBounds.Height )
315 Resizing( gwin.ClientBounds.Width, gwin.ClientBounds.Height, newParams.Width, newParams.Height );
318 private void OnResized( SizeParams newParams = null )
320 if ( Resized == null )
323 int newWidth = newParams != null ? newParams.Width : gwin.ClientBounds.Width;
324 int newHeight = newParams != null ? newParams.Height : gwin.ClientBounds.Height;
326 if ( newWidth != lastSize.Width || newHeight != lastSize.Height )
327 Resized( lastSize.Width, lastSize.Height, newWidth, newHeight );
330 private void OnFullscreen( SizeParams newParams = null )
332 bool newFullscreen = newParams != null ? newParams.Fullscreen : gdm.IsFullScreen;
334 if ( EnterFullscreen != null && !lastSize.Fullscreen && newFullscreen )
337 else if ( ExitFullscreen != null && lastSize.Fullscreen && !newFullscreen )
341 #region Methods for XNA compatibility 348 get {
return gwin.ClientBounds; }
355 [EditorBrowsable( EditorBrowsableState.Never )]
358 gwin.BeginScreenDeviceChange( willBeFullScreen );
367 [EditorBrowsable( EditorBrowsableState.Never )]
370 gwin.EndScreenDeviceChange( screenDeviceName, clientWidth, clientHeight );
380 if ( lastSize == null )
381 lastSize =
new SizeParams( gwin.ClientBounds.Width, gwin.ClientBounds.Height, gdm.IsFullScreen );
384 lastSize.Width = gwin.ClientBounds.Width;
385 lastSize.Height = gwin.ClientBounds.Height;
386 lastSize.Fullscreen = gdm.IsFullScreen;
390 lastPosition =
new Point( form.Left, form.Top );
393 if ( desiredSize != null )
395 xnaSetWindowSize( desiredSize );
396 OnResized( desiredSize );
397 OnFullscreen( desiredSize );
402 if (desiredPosition.HasValue)
404 form.Left = this.
Left;
406 desiredPosition = null;
412 private void xnaSetWindowSize( SizeParams newParams )
414 gdm.PreferredBackBufferWidth = newParams.Width;
415 gdm.PreferredBackBufferHeight = newParams.Height;
416 gdm.IsFullScreen = newParams.Fullscreen;
421 public void CenterOnScreen()
426 int x = (Screen.PrimaryScreen.Bounds.Width - gwin.ClientBounds.Width) / 2;
427 int y = (Screen.PrimaryScreen.Bounds.Height - gwin.ClientBounds.Height) / 2;
429 Control formControl = Control.FromHandle(
Handle);
431 if (formControl == null)
434 Form form = (Form)formControl;
435 form.DesktopLocation =
new System.Drawing.Point(x, y);
void OnXnaMethod(EventHandler< EventArgs > method, object sender, EventArgs args)
Generic XNA event handler.
void Update()
Kutsutaan Jypelin päivityssilmukasta.
bool AllowUserResizing
Voiko käyttäjä muuttaa ikkunan kokoa ikkunan reunasta.
int Height
Ikkunan korkeus.
Action ExitFullscreen
Tapahtuu kun poistutaan koko ruudun tilasta
void EndScreenDeviceChange(string screenDeviceName, int clientWidth, int clientHeight)
DisplayOrientation
Puhelimen näytön asemointi.
int X
Ikkunan keskikohdan x-koordinaatti.
delegate void ResizeEvent(int oldWidth, int oldHeight, int newWidth, int newHeight)
Tapahtumatyyppi ikkunan koon muutokselle.
string ScreenDeviceName
Näyttölaitteen nimi.
delegate void MoveEvent(int oldX, int oldY, int newX, int newY)
Tapahtumatyyppi ikkunan paikan muutokselle.
int Y
Ikkunan keskikohdan y-koordinaatti. Huom. y kasvaa alaspäin!
EventHandler< EventArgs > ClientSizeChanged
ResizeEvent Resizing
Tapahtuu kun ikkunan kokoa ollaan muuttamassa.
string Title
Ikkunan otsikko.
int Bottom
Ikkunan alareunan y-koordinaatti. Huom. y kasvaa alaspäin!
void BeginScreenDeviceChange(bool willBeFullScreen)
int Right
Ikkunan oikean reunan x-koordinaatti.
DisplayOrientation CurrentOrientation
Ikkunan asento puhelimessa (pysty tai vaaka)
EventHandler< EventArgs > ScreenDeviceNameChanged
int Top
Ikkunan yläreunan y-koordinaatti. Huom. y kasvaa alaspäin!
bool Fullscreen
Onko ikkuna koko näytön kokoinen ilman reunoja.
IntPtr Handle
API-kahva ikkunaan.
Action EnterFullscreen
Tapahtuu kun mennään koko ruudun tilaan.
Microsoft.Xna.Framework.Rectangle ClientBounds
Ikkunan koko ja paikka xna-neliönä.
EventHandler< EventArgs > OrientationChanged
int Left
Ikkunan vasemman reunan x-koordinaatti.
MoveEvent Moved
Tapahtuu kun ikkunaa siirretään.
ResizeEvent Resized
Tapahtuu kun ikkunan kokoa on muutettu.