Combined Stage and Window class, and removed Stage class
[platform/core/uifw/dali-toolkit.git] / plugins / dali-sharp / sharp / internal / Window.cs
index a53e14c..196cd47 100644 (file)
@@ -31,9 +31,11 @@ namespace Dali {
 
 public class Window : BaseHandle {
   private global::System.Runtime.InteropServices.HandleRef swigCPtr;
+  private global::System.Runtime.InteropServices.HandleRef stageCPtr;
 
   internal Window(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Window_SWIGUpcast(cPtr), cMemoryOwn) {
     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
+    stageCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.Stage_GetCurrent());
   }
 
   internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Window obj) {
@@ -45,7 +47,7 @@ public class Window : BaseHandle {
   }
 
   public override void Dispose() {
-    if (!Stage.IsInstalled()) {
+    if (!Window.IsInstalled()) {
       DisposeQueue.Instance.Add(this);
       return;
     }
@@ -55,6 +57,7 @@ public class Window : BaseHandle {
         if (swigCMemOwn) {
           swigCMemOwn = false;
           NDalicPINVOKE.delete_Window(swigCPtr);
+          NDalicPINVOKE.delete_Stage(stageCPtr);
         }
         swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
       }
@@ -64,7 +67,11 @@ public class Window : BaseHandle {
   }
 
 
-
+  public static bool IsInstalled() {
+    bool ret = NDalicPINVOKE.Stage_IsInstalled();
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
     public void SetAcceptFocus( bool accept )
     {
       NDalicPINVOKE.SetAcceptFocus(swigCPtr, accept);
@@ -251,6 +258,160 @@ public class Window : BaseHandle {
     return ret;
   }
 
+  public Layer GetDefaultLayer()
+  {
+    return this.GetRootLayer();
+  }
+
+  public void Add(Layer layer)
+  {
+    NDalicPINVOKE.Stage_Add(stageCPtr, Layer.getCPtr(layer));
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+  }
+
+  public void Remove(Layer layer)
+  {
+    NDalicPINVOKE.Stage_Remove(stageCPtr, Layer.getCPtr(layer));
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+  }
+
+  public void Add(View view) {
+    NDalicPINVOKE.Stage_Add(stageCPtr, View.getCPtr(view));
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+  }
+
+  public void Remove(View view) {
+    NDalicPINVOKE.Stage_Remove(stageCPtr, View.getCPtr(view));
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+  }
+
+  public Vector2 GetSize() {
+    Vector2 ret = new Vector2(NDalicPINVOKE.Stage_GetSize(stageCPtr), true);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public RenderTaskList GetRenderTaskList() {
+    RenderTaskList ret = new RenderTaskList(NDalicPINVOKE.Stage_GetRenderTaskList(stageCPtr), true);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public uint GetLayerCount() {
+    uint ret = NDalicPINVOKE.Stage_GetLayerCount(stageCPtr);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public Layer GetLayer(uint depth) {
+    Layer ret = new Layer(NDalicPINVOKE.Stage_GetLayer(stageCPtr, depth), true);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public Layer GetRootLayer() {
+    Layer ret = new Layer(NDalicPINVOKE.Stage_GetRootLayer(stageCPtr), true);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public void SetBackgroundColor(Vector4 color) {
+    NDalicPINVOKE.Stage_SetBackgroundColor(stageCPtr, Vector4.getCPtr(color));
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+  }
+
+  public Vector4 GetBackgroundColor() {
+    Vector4 ret = new Vector4(NDalicPINVOKE.Stage_GetBackgroundColor(stageCPtr), true);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public Vector2 GetDpi() {
+    Vector2 ret = new Vector2(NDalicPINVOKE.Stage_GetDpi(stageCPtr), true);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public ObjectRegistry GetObjectRegistry() {
+    ObjectRegistry ret = new ObjectRegistry(NDalicPINVOKE.Stage_GetObjectRegistry(stageCPtr), true);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public void KeepRendering(float durationSeconds) {
+    NDalicPINVOKE.Stage_KeepRendering(stageCPtr, durationSeconds);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+  }
+
+  public KeyEventSignal KeyEventSignal() {
+    KeyEventSignal ret = new KeyEventSignal(NDalicPINVOKE.Stage_KeyEventSignal(stageCPtr), false);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public VoidSignal EventProcessingFinishedSignal() {
+    VoidSignal ret = new VoidSignal(NDalicPINVOKE.Stage_EventProcessingFinishedSignal(stageCPtr), false);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public TouchSignal TouchSignal() {
+    TouchSignal ret = new TouchSignal(NDalicPINVOKE.Stage_TouchSignal(stageCPtr), false);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  private StageWheelSignal WheelEventSignal() {
+    StageWheelSignal ret = new StageWheelSignal(NDalicPINVOKE.Stage_WheelEventSignal(stageCPtr), false);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public VoidSignal ContextLostSignal() {
+    VoidSignal ret = new VoidSignal(NDalicPINVOKE.Stage_ContextLostSignal(stageCPtr), false);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public VoidSignal ContextRegainedSignal() {
+    VoidSignal ret = new VoidSignal(NDalicPINVOKE.Stage_ContextRegainedSignal(stageCPtr), false);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public VoidSignal SceneCreatedSignal() {
+    VoidSignal ret = new VoidSignal(NDalicPINVOKE.Stage_SceneCreatedSignal(stageCPtr), false);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public static Vector4 DEFAULT_BACKGROUND_COLOR {
+    get {
+      global::System.IntPtr cPtr = NDalicPINVOKE.Stage_DEFAULT_BACKGROUND_COLOR_get();
+      Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false);
+      if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+      return ret;
+    }
+  }
+
+  public static Vector4 DEBUG_BACKGROUND_COLOR {
+    get {
+      global::System.IntPtr cPtr = NDalicPINVOKE.Stage_DEBUG_BACKGROUND_COLOR_get();
+      Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false);
+      if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+      return ret;
+    }
+  }
+
+  private static readonly Window instance = Application.Instance.GetWindow();
+  public static Window Instance
+  {
+    get
+    {
+      return instance;
+    }
+  }
+
   public enum WindowOrientation {
     PORTRAIT = 0,
     LANDSCAPE = 90,
@@ -270,6 +431,422 @@ public class Window : BaseHandle {
     AUTO = 2
   }
 
+
+
+  /**
+    * @brief Event arguments that passed via Touch signal
+    *
+    */
+  public class TouchEventArgs : EventArgs
+  {
+     private Touch _touch;
+
+     /**
+       * @brief Touch - contains the information of touch points
+       *
+       */
+     public Touch Touch
+     {
+        get
+        {
+           return _touch;
+        }
+        set
+        {
+           _touch = value;
+        }
+     }
+  }
+
+  private event EventHandler<TouchEventArgs> _stageTouchHandler;
+  private EventCallbackDelegateType1<IntPtr> _stageTouchCallbackDelegate;
+
+  /**
+    * @brief Event for TouchEvent signal which can be used to subscribe/unsubscribe the event handler
+    * TouchEvent signal is emitted when the screen is touched and when the touch ends
+    * (i.e. the down & up touch events only).
+    *
+    */
+  public event EventHandler<TouchEventArgs> Touch
+  {
+     add
+     {
+        lock(this)
+        {
+          _stageTouchHandler += value;
+          _stageTouchCallbackDelegate = OnStageTouch;
+          this.TouchSignal().Connect(_stageTouchCallbackDelegate);
+        }
+     }
+     remove
+     {
+        lock(this)
+        {
+           if (_stageTouchHandler != null)
+           {
+              this.TouchSignal().Disconnect(_stageTouchCallbackDelegate);
+           }
+           _stageTouchHandler -= value;
+        }
+     }
+  }
+
+  private void OnStageTouch(IntPtr data)
+  {
+    TouchEventArgs e = new TouchEventArgs();
+
+    if( data != null )
+    {
+      e.Touch = Dali.Touch.GetTouchFromPtr( data );
+    }
+
+    if (_stageTouchHandler != null)
+    {
+      _stageTouchHandler(this, e);
+    }
+  }
+
+  /**
+    * @brief Wheel arguments that passed via Wheel signal
+    *
+    */
+  public class WheelEventArgs : EventArgs
+  {
+     private Wheel _wheel;
+
+     /**
+       * @brief Wheel - store a wheel rolling type MOUSE_WHEEL or CUSTOM_WHEEL
+       *
+       */
+     public Wheel Wheel
+     {
+        get
+        {
+           return _wheel;
+        }
+        set
+        {
+           _wheel = value;
+        }
+     }
+  }
+
+  private event EventHandler<WheelEventArgs> _stageWheelHandler;
+  private EventCallbackDelegateType1<IntPtr> _stageWheelCallbackDelegate;
+
+  /**
+    * @brief Event for Wheel signal which can be used to subscribe/unsubscribe the event handler
+    * Wheel signal is emitted is emitted when wheel event is received.
+    *
+    */
+  public event EventHandler<WheelEventArgs> Wheel
+  {
+     add
+     {
+        lock(this)
+        {
+          _stageWheelHandler += value;
+          _stageWheelCallbackDelegate = OnStageWheel;
+          this.WheelEventSignal().Connect(_stageWheelCallbackDelegate);
+        }
+     }
+     remove
+     {
+        lock(this)
+        {
+           if (_stageWheelHandler != null)
+           {
+              this.WheelEventSignal().Disconnect(_stageWheelCallbackDelegate);
+           }
+           _stageWheelHandler -= value;
+        }
+     }
+  }
+
+  private void OnStageWheel(IntPtr data)
+  {
+    WheelEventArgs e = new WheelEventArgs();
+
+    if( data != null )
+    {
+      e.Wheel = Dali.Wheel.GetWheelFromPtr( data );
+    }
+
+    if (_stageWheelHandler != null)
+    {
+      _stageWheelHandler(this, e);
+    }
+  }
+
+  /**
+    * @brief Event arguments that passed via Key signal
+    *
+    */
+  public class KeyEventArgs : EventArgs
+  {
+     private Key _key;
+
+     /**
+       * @brief Key - is the keyevent sent to Stage.
+       *
+       */
+     public Key Key
+     {
+        get
+        {
+           return _key;
+        }
+        set
+        {
+           _key = value;
+        }
+     }
+  }
+
+  private event EventHandler<KeyEventArgs> _stageKeyHandler;
+  private EventCallbackDelegateType1<IntPtr> _stageKeyCallbackDelegate;
+
+  /**
+    * @brief Event for Key signal which can be used to subscribe/unsubscribe the event handler
+    * Key signal is emitted is emitted when key event is received.
+    *
+    */
+  public event EventHandler<KeyEventArgs> Key
+  {
+     add
+     {
+        lock(this)
+        {
+            _stageKeyHandler += value;
+            _stageKeyCallbackDelegate = OnStageKey;
+            this.KeyEventSignal().Connect(_stageKeyCallbackDelegate);
+        }
+     }
+     remove
+     {
+        lock(this)
+        {
+           if (_stageKeyHandler != null)
+           {
+              this.KeyEventSignal().Disconnect(_stageKeyCallbackDelegate);
+           }
+           _stageKeyHandler -= value;
+        }
+     }
+  }
+
+  // Callback for Stage KeyEventsignal
+  private void OnStageKey(IntPtr data)
+  {
+    KeyEventArgs e = new KeyEventArgs();
+
+    if( data != null )
+    {
+      e.Key = Dali.Key.GetKeyFromPtr( data );
+    }
+
+    if (_stageKeyHandler != null)
+    {
+      //here we send all data to user event handlers
+      _stageKeyHandler(this, e);
+    }
+  }
+
+
+  private event EventHandler _stageEventProcessingFinishedEventHandler;
+  private EventCallbackDelegateType0 _stageEventProcessingFinishedEventCallbackDelegate;
+
+  /**
+    * @brief Event for EventProcessingFinished signal which can be used to subscribe/unsubscribe the event handler
+    * provided by the user. EventProcessingFinished signal is emitted just after the event processing is finished.
+    *
+    */
+  public event EventHandler EventProcessingFinished
+  {
+     add
+     {
+        lock(this)
+        {
+          _stageEventProcessingFinishedEventHandler += value;
+          _stageEventProcessingFinishedEventCallbackDelegate = OnEventProcessingFinished;
+          this.EventProcessingFinishedSignal().Connect(_stageEventProcessingFinishedEventCallbackDelegate);
+        }
+     }
+     remove
+     {
+        lock(this)
+        {
+           if (_stageEventProcessingFinishedEventHandler != null)
+           {
+              this.EventProcessingFinishedSignal().Disconnect(_stageEventProcessingFinishedEventCallbackDelegate);
+           }
+           _stageEventProcessingFinishedEventHandler -= value;
+        }
+     }
+  }
+
+  // Callback for Stage EventProcessingFinishedSignal
+  private void OnEventProcessingFinished()
+  {
+     if (_stageEventProcessingFinishedEventHandler != null)
+     {
+        _stageEventProcessingFinishedEventHandler(this, null);
+     }
+  }
+
+
+  private EventHandler _stageContextLostEventHandler;
+  private EventCallbackDelegateType0 _stageContextLostEventCallbackDelegate;
+
+  /**
+    * @brief Event for ContextLost signal which can be used to subscribe/unsubscribe the event handler
+    * ContextLost signal is emitted when the GL context is lost (Platform specific behaviour).
+    *
+    */
+  public event EventHandler ContextLost
+  {
+     add
+     {
+        lock(this)
+        {
+            _stageContextLostEventHandler += value;
+            _stageContextLostEventCallbackDelegate = OnContextLost;
+            this.ContextLostSignal().Connect(_stageContextLostEventCallbackDelegate);
+        }
+     }
+     remove
+     {
+        lock(this)
+        {
+           if (_stageContextLostEventHandler != null)
+           {
+              this.ContextLostSignal().Disconnect(_stageContextLostEventCallbackDelegate);
+           }
+
+           _stageContextLostEventHandler -= value;
+        }
+     }
+  }
+
+  // Callback for Stage ContextLostSignal
+  private void OnContextLost()
+  {
+     if (_stageContextLostEventHandler != null)
+     {
+        _stageContextLostEventHandler(this, null);
+     }
+  }
+
+
+  private EventHandler _stageContextRegainedEventHandler;
+  private EventCallbackDelegateType0 _stageContextRegainedEventCallbackDelegate;
+
+  /**
+    * @brief Event for ContextRegained signal which can be used to subscribe/unsubscribe the event handler
+    * provided by the user. ContextRegained signal is emitted when the GL context is regained (Platform specific
+    * behaviour).
+    *
+    */
+  public event EventHandler ContextRegained
+  {
+     add
+     {
+        lock(this)
+        {
+            _stageContextRegainedEventHandler += value;
+            _stageContextRegainedEventCallbackDelegate = OnContextRegained;
+            this.ContextRegainedSignal().Connect(_stageContextRegainedEventCallbackDelegate);
+        }
+     }
+     remove
+     {
+        lock(this)
+        {
+           if (_stageContextRegainedEventHandler != null)
+           {
+              this.ContextRegainedSignal().Disconnect(_stageContextRegainedEventCallbackDelegate);
+           }
+
+           _stageContextRegainedEventHandler -= value;
+        }
+     }
+  }
+
+  // Callback for Stage ContextRegainedSignal
+  private void OnContextRegained()
+  {
+     if (_stageContextRegainedEventHandler != null)
+     {
+        _stageContextRegainedEventHandler(this, null);
+     }
+  }
+
+
+  private EventHandler _stageSceneCreatedEventHandler;
+  private EventCallbackDelegateType0 _stageSceneCreatedEventCallbackDelegate;
+
+  /**
+    * @brief Event for SceneCreated signal which can be used to subscribe/unsubscribe the event handler
+    * SceneCreated signal is emitted after the initial scene is created.
+    *
+    */
+  public event EventHandler SceneCreated
+  {
+     add
+     {
+        lock(this)
+        {
+            _stageSceneCreatedEventHandler += value;
+            _stageSceneCreatedEventCallbackDelegate = OnSceneCreated;
+            this.SceneCreatedSignal().Connect(_stageSceneCreatedEventCallbackDelegate);
+        }
+     }
+     remove
+     {
+        lock(this)
+        {
+           if (_stageSceneCreatedEventHandler != null)
+           {
+              this.SceneCreatedSignal().Disconnect(_stageSceneCreatedEventCallbackDelegate);
+           }
+
+           _stageSceneCreatedEventHandler -= value;
+        }
+     }
+  }
+
+  // Callback for Stage SceneCreatedSignal
+  private void OnSceneCreated()
+  {
+     if (_stageSceneCreatedEventHandler != null)
+     {
+        _stageSceneCreatedEventHandler(this, null);
+     }
+  }
+
+
+  public Vector2 Size
+  {
+     get
+     {
+        Vector2 ret = GetSize();
+        return ret;
+     }
+  }
+
+  public Vector4 BackgroundColor
+  {
+     set
+     {
+        SetBackgroundColor(value);
+     }
+     get
+     {
+        Vector4 ret = GetBackgroundColor();
+        return ret;
+     }
+   }
+
 }
 
 }