#region --- License --- /* Licensed under the MIT/X11 license. * Copyright (c) 2011 Xamarin Inc. * Copyright 2013 Xamarin Inc * This notice may not be removed from any source distribution. * See license.txt for licensing detailed licensing details. */ #endregion using System; using System.ComponentModel; using System.Drawing; using System.Timers; using OpenTK; using OpenTK.Graphics; using OpenTK.Platform; using OpenTK.Platform.Android; using Android.Content; using Android.Util; using Android.Views; using Android.Runtime; using Java.Util; using OpenTK.Input; namespace OpenTK { [Register ("opentk_1_1/GameViewBase")] public abstract class GameViewBase : SurfaceView, IGameWindow { private IGraphicsContext graphicsContext; [Register (".ctor", "(Landroid/content/Context;)V", "")] public GameViewBase (Context context) : base (context) { } [Register (".ctor", "(Landroid/content/Context;Landroid/util/AttributeSet;)V", "")] public GameViewBase (Context context, IAttributeSet attrs) : base (context, attrs) { } public GameViewBase (IntPtr handle, global::Android.Runtime.JniHandleOwnership transfer) : base (handle, transfer) { } /// /// Gets the instance /// bound to this /// instance. /// /// /// A instance bound /// to this /// instance. /// public IGraphicsContext GraphicsContext { get { return graphicsContext; } protected set { graphicsContext = value; OnContextSet (null); } } /// /// Controls whether the graphics context is recreated when the display /// size changes. /// /// /// public bool AutoResize { get; set; } protected virtual void CreateFrameBuffer () { } Point INativeWindow.PointToClient (Point point) { return point; } Point INativeWindow.PointToScreen (Point point) { return point; } #region IGameWindow implementation /// /// Occurs before the run loop starts. /// /// /// /// When using the run-loop processing architecture, events happen in /// the following order: /// /// /// /// /// Load /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// and /// , /// invoke /// /// before starting the /// / /// loop which is invoked for every rendered frame. /// /// /// /// ends the /// / /// loop processing, then invokes the /// /// event. /// /// public event EventHandler Load; /// /// An that contains the event data. /// /// /// Raises the /// /// event. /// protected virtual void OnLoad (EventArgs e) { if (Load != null) Load (this, e); } /// /// Occurs when the run-loop is terminated. /// /// /// /// When using the run-loop processing architecture, events happen in /// the following order: /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// Unload /// /// /// /// /// and /// , /// invoke /// /// before starting the /// / /// loop which is invoked for every rendered frame. /// /// /// /// ends the /// / /// loop processing, then invokes the /// /// event. /// /// public event EventHandler Unload; /// /// An that contains the event data. /// /// /// Raises the /// /// event. /// /// /// /// The OnUnload method also allows derived classes to handle /// the event without attaching a delegate. This is the preferred /// technique for handling the event in a derived class. /// /// /// When overriding OnUnload in a derived class, be sure to /// call the base class's OnUnload method so that registered /// delegates receive the event. /// /// protected virtual void OnUnload (EventArgs e) { if (Unload != null) Unload (this, e); } /// /// Occurs part of run-loop processing when a frame should be updated prior to rendering. /// /// /// /// When using the run-loop processing architecture, events happen in /// the following order: /// /// /// /// /// /// /// /// /// /// UpdateFrame /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// and /// , /// invoke /// /// before starting the /// / /// loop which is invoked for every rendered frame. /// /// /// /// ends the /// / /// loop processing, then invokes the /// /// event. /// /// public event EventHandler UpdateFrame; /// /// An that contains the event data. /// /// /// Raises the /// /// event. /// /// /// /// The OnUpdateFrame method also allows derived classes to handle /// the event without attaching a delegate. This is the preferred /// technique for handling the event in a derived class. /// /// /// When overriding OnUpdateFrame in a derived class, be sure to /// call the base class's OnUpdateFrame method so that registered /// delegates receive the event. /// /// protected virtual void OnUpdateFrame (FrameEventArgs e) { if (UpdateFrame != null) UpdateFrame (this, e); } /// /// Occurs part of run-loop processing when a frame should be rendered. /// /// /// /// When using the run-loop processing architecture, events happen in /// the following order: /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// RenderFrame /// /// /// /// /// /// /// /// /// /// and /// , /// invoke /// /// before starting the /// / /// loop which is invoked for every rendered frame. /// /// /// /// ends the /// / /// loop processing, then invokes the /// /// event. /// /// public event EventHandler RenderFrame; /// /// An that contains the event data. /// /// /// Raises the /// /// event. /// /// /// /// The OnRenderFrame method also allows derived classes to handle /// the event without attaching a delegate. This is the preferred /// technique for handling the event in a derived class. /// /// /// When overriding OnRenderFrame in a derived class, be sure to /// call the base class's OnRenderFrame method so that registered /// delegates receive the event. /// /// protected virtual void OnRenderFrame (FrameEventArgs e) { if (RenderFrame != null) RenderFrame (this, e); } /// /// Starts as-fast-as-possible run-loop processing. /// /// /// /// In this Run overload, there is no delay between raising of the /// /// event and the /// /// of the following frame; everything is executed as quickly as /// possible. This may not be desirable. /// /// /// /// The instance has had /// /// invoked on it. /// public abstract void Run (); /// /// A containing the number of frames per /// second that should be updated and rendered. /// /// /// Starts run-loop processing at a rate of /// frames per second. /// /// /// The instance has had /// /// invoked on it. /// public abstract void Run (double updateRate); /// /// Makes the /// /// current on the calling thread. /// /// /// /// This method is equivalent to calling: /// GraphicsContext.MakeCurrent(WindowInfo). /// /// /// /// The instance has had /// /// invoked on it. /// public abstract void MakeCurrent (); /// /// Swaps the front and back buffers of the current GraphicsContext, /// presenting the rendered scene to the user. /// /// /// /// This method rebinds /// /// to the OpenGL context's RenderbufferOes property, then /// invokes . /// /// /// /// The instance has had /// /// invoked on it. /// public abstract void SwapBuffers (); #endregion #region INativeWindow implementation /// This member is not supported. /// To be added. /// /// /// Throws a . /// /// public event EventHandler Move; /// /// Occurs when the view's /// /// changes. /// /// /// public event EventHandler Resize; /// /// An that contains the event data. /// /// /// Raises the /// /// event. /// /// /// /// The OnResize method also allows derived classes to handle /// the event without attaching a delegate. This is the preferred /// technique for handling the event in a derived class. /// /// /// When overriding OnResize in a derived class, be sure to /// call the base class's OnResize method so that registered /// delegates receive the event. /// /// protected virtual void OnResize (EventArgs e) { if (Resize != null) Resize (this, e); } /// This member is not supported. /// To be added. /// /// /// Throws a . /// /// public event EventHandler Closing; /// /// Occurs when the view has been closed. /// /// /// public event EventHandler Closed; /// /// An that contains the event data. /// /// /// Raises the /// /// event. /// /// /// /// The OnClosed method also allows derived classes to handle /// the event without attaching a delegate. This is the preferred /// technique for handling the event in a derived class. /// /// /// When overriding OnClosed in a derived class, be sure to /// call the base class's OnClosed method so that registered /// delegates receive the event. /// /// protected virtual void OnClosed (EventArgs e) { if (Closed != null) Closed (this, e); } /// /// Occurs when the view is disposed /// /// /// public event EventHandler Disposed; /// /// Raises the /// /// event. /// /// /// An that contains the event data. /// /// /// /// The OnDisposed method also allows derived classes to handle /// the event without attaching a delegate. This is the preferred /// technique for handling the event in a derived class. /// /// /// When overriding OnDisposed in a derived class, be sure to /// call the base class's OnDisposed method so that registered /// delegates receive the event. /// /// protected virtual void OnDisposed (EventArgs e) { if (Disposed != null) Disposed (this, e); } /// /// Occurs when the /// /// detects that the was lost. /// /// /// public event EventHandler ContextLost; /// /// An that contains the event data. /// /// /// Raises the /// /// event. /// /// /// /// The OnContextLost method also allows derived classes to handle /// the event without attaching a delegate. This is the preferred /// technique for handling the event in a derived class. /// /// /// When overriding OnContextLost in a derived class, be sure to /// call the base class's OnContextLost method so that registered /// delegates receive the event. /// /// protected virtual void OnContextLost (EventArgs e) { if (ContextLost != null) ContextLost (this, e); } /// /// Occurs when the /// /// is created. /// /// /// public event EventHandler ContextSet; /// /// An that contains the event data. /// /// /// Raises the /// /// event. /// /// /// /// The OnContextSet method also allows derived classes to handle /// the event without attaching a delegate. This is the preferred /// technique for handling the event in a derived class. /// /// /// When overriding OnContextSet in a derived class, be sure to /// call the base class's OnContextSet method so that registered /// delegates receive the event. /// /// /// It is convenient place to create context related data, ie. load textures. /// /// protected virtual void OnContextSet (EventArgs e) { if (ContextSet != null) ContextSet (this, e); } /// /// Occurs when the separate rendering thread exits without cancelation request. /// /// /// public event EventHandler RenderThreadExited; /// /// An that contains the event data. /// /// /// Raises the /// /// event. /// /// /// /// The OnRenderThreadExited method also allows derived classes to handle /// the event without attaching a delegate. This is the preferred /// technique for handling the event in a derived class. /// /// /// When overriding OnRenderThreadExited in a derived class, be sure to /// call the base class's OnRenderThreadExited method so that registered /// delegates receive the event. /// /// /// It is convenient place to handle errors. /// /// protected virtual void OnRenderThreadExited (EventArgs e) { if (RenderThreadExited != null) RenderThreadExited (this, e); } /// /// Occurs when the value of /// /// changes. /// /// /// public event EventHandler TitleChanged; /// /// An that contains the event data. /// /// /// Raises the /// /// event. /// /// /// /// The OnTitleChanged method also allows derived classes to handle /// the event without attaching a delegate. This is the preferred /// technique for handling the event in a derived class. /// /// /// When overriding OnTitleChanged in a derived class, be sure to /// call the base class's OnTitleChanged method so that registered /// delegates receive the event. /// /// protected virtual void OnTitleChanged (EventArgs e) { if (TitleChanged != null) TitleChanged (this, EventArgs.Empty); } /// /// Occurs when the value of /// /// changes. /// /// /// public event EventHandler VisibleChanged; /// /// An that contains the event data. /// /// /// Raises the /// /// event. /// /// /// /// The OnVisibleChanged method also allows derived classes to handle /// the event without attaching a delegate. This is the preferred /// technique for handling the event in a derived class. /// /// /// When overriding OnVisibleChanged in a derived class, be sure to /// call the base class's OnVisibleChanged method so that registered /// delegates receive the event. /// /// protected virtual void OnVisibleChanged (EventArgs e) { if (VisibleChanged != null) VisibleChanged (this, EventArgs.Empty); } /// This member is not supported. /// To be added. /// /// /// Throws a . /// /// public event EventHandler FocusedChanged; /// This member is not supported. /// To be added. /// /// /// Throws a . /// /// public event EventHandler WindowBorderChanged; /// /// Occurs when the value of /// /// changes. /// /// /// public event EventHandler WindowStateChanged; /// /// An that contains the event data. /// /// /// Raises the /// /// event. /// /// /// /// The OnWindowStateChanged method also allows derived classes to handle /// the event without attaching a delegate. This is the preferred /// technique for handling the event in a derived class. /// /// /// When overriding OnWindowStateChanged in a derived class, be sure to /// call the base class's OnWindowStateChanged method so that registered /// delegates receive the event. /// /// protected virtual void OnWindowStateChanged (EventArgs e) { if (WindowStateChanged != null) WindowStateChanged (this, EventArgs.Empty); } /// /// Invokes the /// /// event. /// /// /// This method only invokes the /// /// method. /// /// /// The instance has had /// /// invoked on it. /// public virtual void Close () { OnClosed (EventArgs.Empty); } /// This member is not supported. /// /// /// Throws a . /// /// event EventHandler INativeWindow.KeyPress { add { throw new NotSupportedException ();} remove { throw new NotSupportedException ();} } public virtual int Width { get; set; } public virtual int Height { get; set; } /// This member is not supported. /// /// /// Throws a . /// /// public event EventHandler MouseEnter { add { throw new NotSupportedException (); } remove { throw new NotSupportedException (); } } /// This member is not supported. /// /// /// Throws a . /// /// public event EventHandler MouseLeave { add { throw new NotSupportedException (); } remove { throw new NotSupportedException (); } } /// This member is not supported. /// /// /// Throws a . /// /// public void ProcessEvents () { throw new NotImplementedException (); } public Point PointToClient (Point point) { throw new NotImplementedException (); } public Point PointToScreen (Point point) { throw new NotImplementedException (); } public string Title { get { throw new NotImplementedException (); } set { throw new NotImplementedException (); } } /// This member is not supported. /// To be added. /// /// /// Throws a . /// /// public bool Focused { get { throw new NotSupportedException (); } } /// /// Gets or sets a value specifying whether the view is visible. /// /// /// A specifying whether the view is /// visible. /// /// /// /// /// The instance has had /// /// invoked on it. /// public bool Visible { get { throw new NotImplementedException (); } set { throw new NotImplementedException (); } } /// This member is not supported. /// To be added. /// /// /// Throws a . /// /// public bool Exists { get { throw new NotImplementedException (); } } /// /// Gets information about the containing window. /// /// /// A which provides /// information about the containing window. /// /// /// The instance has had /// /// invoked on it. /// public virtual IWindowInfo WindowInfo { get { throw new NotImplementedException (); } } /// /// Gets or states the state of the view. /// /// /// A value specifying the state of /// the window. /// /// /// /// is always returned. /// /// /// /// public virtual WindowState WindowState { get { throw new NotImplementedException (); } set { throw new NotImplementedException (); } } /// /// Always returns . /// /// /// A value controlling the border /// of the view. /// /// /// /// Always returns . /// /// /// The setter is ignored. /// /// /// /// public virtual WindowBorder WindowBorder { get { throw new NotImplementedException (); } set { throw new NotImplementedException (); } } /// This member is not supported. /// To be added. /// /// /// Throws a . /// /// public virtual Rectangle Bounds { get { throw new NotImplementedException (); } set { throw new NotImplementedException (); } } /// This member is not supported. /// To be added. /// /// /// Throws a . /// /// public virtual Point Location { get { throw new NotImplementedException (); } set { throw new NotImplementedException (); } } /// /// The size of the current view. /// /// /// A which is the size of the /// current view. /// /// /// public virtual Size Size { get { throw new NotImplementedException (); } set { throw new NotImplementedException (); } } /// This member is not supported. /// /// /// Throws a . /// /// public int X { get { throw new NotSupportedException (); } set { throw new NotSupportedException (); } } /// This member is not supported. /// /// /// Throws a . /// /// public int Y { get { throw new NotSupportedException (); } set { throw new NotSupportedException (); } } /// This member is not supported. /// /// /// Throws a . /// /// public Rectangle ClientRectangle { get { throw new NotSupportedException (); } set { throw new NotSupportedException (); } } /// This member is not supported. /// To be added. /// /// /// Throws a . /// /// public Size ClientSize { get { throw new NotSupportedException (); } set { throw new NotSupportedException (); } } public OpenTK.Input.IInputDriver InputDriver { get { throw new NotSupportedException (); } } MouseCursor INativeWindow.Cursor { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } bool INativeWindow.CursorVisible { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } Icon INativeWindow.Icon { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } event EventHandler INativeWindow.IconChanged { add { throw new NotSupportedException(); } remove { throw new NotSupportedException(); } } event EventHandler INativeWindow.KeyDown { add { throw new NotSupportedException(); } remove { throw new NotSupportedException(); } } event EventHandler INativeWindow.KeyUp { add { throw new NotSupportedException(); } remove { throw new NotSupportedException(); } } event EventHandler INativeWindow.MouseDown { add { throw new NotSupportedException(); } remove { throw new NotSupportedException(); } } event EventHandler INativeWindow.MouseMove { add { throw new NotSupportedException(); } remove { throw new NotSupportedException(); } } event EventHandler INativeWindow.MouseUp { add { throw new NotSupportedException(); } remove { throw new NotSupportedException(); } } event EventHandler INativeWindow.MouseWheel { add { throw new NotSupportedException(); } remove { throw new NotSupportedException(); } } #endregion } }