/// <summary> /// Binds the corresponding event handler to the provided <see cref="DrawingSurfaceBackgroundGrid"/> /// </summary> /// <param name="grid">An instance of <see cref="DrawingSurfaceBackgroundGrid"/> whose events needs to be bound to</param> /// <exception cref="ArgumentNullException">Is thrown if <paramref name="grid"/> is null</exception> private void BindManipulationEvents(DrawingSurfaceBackgroundGrid grid) { if (grid == null) throw new ArgumentNullException("grid"); grid.SetBackgroundManipulationHandler(this); // TODO: review if we need to unbind the handlers to avoid memory leaks grid.Unloaded += (_, __) => grid.SetBackgroundManipulationHandler(null); Disposing += (_, __) => grid.SetBackgroundManipulationHandler(null); }
/// <summary> /// Binds the corresponding event handler to the provided <see cref="DrawingSurfaceBackgroundGrid"/> /// </summary> /// <param name="grid">An instance of <see cref="DrawingSurfaceBackgroundGrid"/> whose events needs to be bound to</param> /// <exception cref="ArgumentNullException">Is thrown if <paramref name="grid"/> is null</exception> private void BindManipulationEvents(DrawingSurfaceBackgroundGrid grid) { if (grid == null) { throw new ArgumentNullException("grid"); } grid.SetBackgroundManipulationHandler(this); // TODO: review if we need to unbind the handlers to avoid memory leaks grid.Unloaded += (_, __) => grid.SetBackgroundManipulationHandler(null); Disposing += (_, __) => grid.SetBackgroundManipulationHandler(null); }
/// <summary> /// Creates your Game class initializing it to worth within a XAML application window. /// </summary> /// <param name="launchParameters">The command line arguments from launch.</param> /// <param name="drawingSurface">The XAML drawing surface to which we render the scene and recieve input events.</param> /// <returns></returns> static public T Create(string launchParameters, DrawingSurfaceBackgroundGrid drawingSurface) { if (launchParameters == null) { throw new NullReferenceException("The launch parameters cannot be null!"); } if (drawingSurface == null) { throw new NullReferenceException("The drawing surface cannot be null!"); } WindowsPhoneGamePlatform.LaunchParameters = launchParameters; WindowsPhoneGameWindow.Width = drawingSurface.ActualWidth; WindowsPhoneGameWindow.Height = drawingSurface.ActualHeight; // Construct the game. var game = new T(); if (game.graphicsDeviceManager == null) { throw new NullReferenceException("You must create the GraphicsDeviceManager in the Game constructor!"); } // Hookup the handlers for updates and touch. drawingSurface.SetBackgroundContentProvider(new SurfaceUpdateHandler(game)); drawingSurface.SetBackgroundManipulationHandler(new SurfaceTouchHandler()); // Return the constructed, but not initialized game. return(game); }
/// <summary> /// Creates your Game class initializing it to worth within a XAML application window. /// </summary> /// <param name="launchParameters">The command line arguments from launch.</param> /// <param name="page">The XAML page containing the drawing surface to which we render the scene and recieve input events.</param> /// <returns></returns> /// static public T Create(string launchParameters, PhoneApplicationPage page) { if (launchParameters == null) { throw new NullReferenceException("The launch parameters cannot be null!"); } if (page == null) { throw new NullReferenceException("The page parameter cannot be null!"); } if (!(page.Content is DrawingSurfaceBackgroundGrid)) { throw new NullReferenceException("The drawing surface could not be found!"); } DrawingSurfaceBackgroundGrid drawingSurface = (DrawingSurfaceBackgroundGrid)page.Content; MediaElement mediaElement = null; for (int i = 0; i < VisualTreeHelper.GetChildrenCount(page.Content); i++) { var child = VisualTreeHelper.GetChild(page.Content, i); if (child is MediaElement) { mediaElement = (MediaElement)child; } } if (mediaElement == null) { throw new NullReferenceException("The media element could not be found! Add it to the GamePage."); } Microsoft.Xna.Framework.Media.MediaPlayer._mediaElement = mediaElement; WindowsPhoneGamePlatform.LaunchParameters = launchParameters; WindowsPhoneGameWindow.Width = drawingSurface.ActualWidth; WindowsPhoneGameWindow.Height = drawingSurface.ActualHeight; WindowsPhoneGameWindow.Page = page; page.BackKeyPress += Microsoft.Xna.Framework.Input.GamePad.GamePageWP8_BackKeyPress; // Construct the game. var game = new T(); if (game.graphicsDeviceManager == null) { throw new NullReferenceException("You must create the GraphicsDeviceManager in the Game constructor!"); } // Hookup the handlers for updates and touch. drawingSurface.SetBackgroundContentProvider(new SurfaceUpdateHandler(game)); drawingSurface.SetBackgroundManipulationHandler(new SurfaceTouchHandler()); // Return the constructed, but not initialized game. return(game); }
public void BindToControl(DrawingSurfaceBackgroundGrid backgroundGrid) { this.ThrowIfDisposed(); this.ThrowIfBound(); this.contentProvider = new DrawingSurfaceBackgroundContentProvider(this); this.manipulationHandler.ManipulationHostChanged += OnManipulationHostChanged; backgroundGrid.SetBackgroundContentProvider(this.contentProvider); backgroundGrid.SetBackgroundManipulationHandler(this.manipulationHandler); this.IsBound = true; }
/// <summary> /// Creates your Game class initializing it to worth within a XAML application window. /// </summary> /// <param name="launchParameters">The command line arguments from launch.</param> /// <param name="page">The XAML page containing the drawing surface to which we render the scene and recieve input events.</param> /// <returns></returns> /// static public T Create(string launchParameters, PhoneApplicationPage page) { if (launchParameters == null) { throw new NullReferenceException("The launch parameters cannot be null!"); } if (page == null) { throw new NullReferenceException("The page parameter cannot be null!"); } UIElement drawingSurface = page.Content as DrawingSurfaceBackgroundGrid; MediaElement mediaElement = null; for (int i = 0; i < VisualTreeHelper.GetChildrenCount(page.Content); i++) { var child = VisualTreeHelper.GetChild(page.Content, i); if (child is MediaElement) { mediaElement = (MediaElement)child; } else if (drawingSurface == null && child is DrawingSurface) { drawingSurface = (DrawingSurface)child; } } if (!(drawingSurface is DrawingSurfaceBackgroundGrid) && !(drawingSurface is DrawingSurface)) { throw new NullReferenceException("The drawing surface could not be found!"); } if (mediaElement == null) { throw new NullReferenceException("The media element could not be found! Add it to the GamePage."); } Microsoft.Xna.Framework.Media.MediaPlayer._mediaElement = mediaElement; WindowsPhoneGamePlatform.LaunchParameters = launchParameters; WindowsPhoneGameWindow.Width = ((FrameworkElement)drawingSurface).ActualWidth; WindowsPhoneGameWindow.Height = ((FrameworkElement)drawingSurface).ActualHeight; WindowsPhoneGameWindow.Page = page; Microsoft.Xna.Framework.Audio.SoundEffect.InitializeSoundEffect(); page.BackKeyPress += Microsoft.Xna.Framework.Input.GamePad.GamePageWP8_BackKeyPress; // Construct the game. var game = new T(); if (game.graphicsDeviceManager == null) { throw new NullReferenceException("You must create the GraphicsDeviceManager in the Game constructor!"); } SurfaceTouchHandler surfaceTouchHandler = new SurfaceTouchHandler(); if (drawingSurface is DrawingSurfaceBackgroundGrid) { // Hookup the handlers for updates and touch. DrawingSurfaceBackgroundGrid drawingSurfaceBackgroundGrid = (DrawingSurfaceBackgroundGrid)drawingSurface; drawingSurfaceBackgroundGrid.SetBackgroundContentProvider(new DrawingSurfaceBackgroundContentProvider(game)); drawingSurfaceBackgroundGrid.SetBackgroundManipulationHandler(surfaceTouchHandler); } else { var drawingSurfaceUpdateHandler = new DrawingSurfaceUpdateHandler(game); DrawingSurface ds = (DrawingSurface)drawingSurface; RoutedEventHandler onLoadedHandler = (object sender, RoutedEventArgs e) => { if (sender != ds) { return; } if (initializedSurfaces.ContainsKey(ds) == false) { // Hook-up native component to DrawingSurface ds.SetContentProvider(drawingSurfaceUpdateHandler.ContentProvider); ds.SetManipulationHandler(surfaceTouchHandler); // Make sure surface is not initialized twice... initializedSurfaces.Add(ds, true); } }; // Don't wait for loaded event here since control might // be loaded already. onLoadedHandler(ds, null); ds.Unloaded += OnDrawingSurfaceUnloaded; ds.Loaded += onLoadedHandler; } // Return the constructed, but not initialized game. return(game); }